Skip to content

Commit ce60f27

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
mm: abstract moving to the next PFN
In order to fix the L1TF vulnerability, x86 can invert the PTE bits for PROT_NONE VMAs, which means we cannot move from one PTE to the next by adding 1 to the PFN field of the PTE. This results in the BUG reported at [1]. Abstract advancing the PTE to the next PFN through a pte_next_pfn() function/macro. Link: https://lkml.kernel.org/r/[email protected] Fixes: bcc6cc8 ("mm: add default definition of set_ptes()") Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reported-by: [email protected] Closes: https://lkml.kernel.org/r/[email protected] [1] Reviewed-by: Yin Fengwei <[email protected]> Cc: Dave Hansen <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent a501a07 commit ce60f27

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

arch/x86/include/asm/pgtable.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,14 @@ static inline int pte_same(pte_t a, pte_t b)
955955
return a.pte == b.pte;
956956
}
957957

958+
static inline pte_t pte_next_pfn(pte_t pte)
959+
{
960+
if (__pte_needs_invert(pte_val(pte)))
961+
return __pte(pte_val(pte) - (1UL << PFN_PTE_SHIFT));
962+
return __pte(pte_val(pte) + (1UL << PFN_PTE_SHIFT));
963+
}
964+
#define pte_next_pfn pte_next_pfn
965+
958966
static inline int pte_present(pte_t a)
959967
{
960968
return pte_flags(a) & (_PAGE_PRESENT | _PAGE_PROTNONE);

include/linux/pgtable.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ static inline int pmd_young(pmd_t pmd)
206206
#endif
207207

208208
#ifndef set_ptes
209+
210+
#ifndef pte_next_pfn
211+
static inline pte_t pte_next_pfn(pte_t pte)
212+
{
213+
return __pte(pte_val(pte) + (1UL << PFN_PTE_SHIFT));
214+
}
215+
#endif
216+
209217
/**
210218
* set_ptes - Map consecutive pages to a contiguous range of addresses.
211219
* @mm: Address space to map the pages into.
@@ -231,7 +239,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
231239
if (--nr == 0)
232240
break;
233241
ptep++;
234-
pte = __pte(pte_val(pte) + (1UL << PFN_PTE_SHIFT));
242+
pte = pte_next_pfn(pte);
235243
}
236244
arch_leave_lazy_mmu_mode();
237245
}

0 commit comments

Comments
 (0)