Skip to content

Commit de8c8e5

Browse files
Tong Tiangenakpm00
authored andcommitted
mm: page_table_check: add hooks to public helpers
Move ptep_clear() to the include/linux/pgtable.h and add page table check relate hooks to some helpers, it's prepare for support page table check feature on new architecture. Optimize the implementation of ptep_clear(), page table hooks added page table check stubs, the interface control should be at stubs, there is no rationale for doing a IS_ENABLED() check here. For architectures that do not enable CONFIG_PAGE_TABLE_CHECK, they will call a fallback page table check stubs[1] when getting their page table helpers[2] in include/linux/pgtable.h. [1] page table check stubs defined in include/linux/page_table_check.h [2] ptep_clear() ptep_get_and_clear() pmdp_huge_get_and_clear() pudp_huge_get_and_clear() Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Tong Tiangen <[email protected]> Acked-by: Pasha Tatashin <[email protected]> Cc: Anshuman Khandual <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Dave Hansen <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Kefeng Wang <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent e5a5540 commit de8c8e5

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

arch/x86/include/asm/pgtable.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,16 +1072,6 @@ static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
10721072
return pte;
10731073
}
10741074

1075-
#define __HAVE_ARCH_PTEP_CLEAR
1076-
static inline void ptep_clear(struct mm_struct *mm, unsigned long addr,
1077-
pte_t *ptep)
1078-
{
1079-
if (IS_ENABLED(CONFIG_PAGE_TABLE_CHECK))
1080-
ptep_get_and_clear(mm, addr, ptep);
1081-
else
1082-
pte_clear(mm, addr, ptep);
1083-
}
1084-
10851075
#define __HAVE_ARCH_PTEP_SET_WRPROTECT
10861076
static inline void ptep_set_wrprotect(struct mm_struct *mm,
10871077
unsigned long addr, pte_t *ptep)

include/linux/pgtable.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/bug.h>
1313
#include <linux/errno.h>
1414
#include <asm-generic/pgtable_uffd.h>
15+
#include <linux/page_table_check.h>
1516

1617
#if 5 - defined(__PAGETABLE_P4D_FOLDED) - defined(__PAGETABLE_PUD_FOLDED) - \
1718
defined(__PAGETABLE_PMD_FOLDED) != CONFIG_PGTABLE_LEVELS
@@ -259,25 +260,26 @@ static inline int pmdp_clear_flush_young(struct vm_area_struct *vma,
259260
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
260261
#endif
261262

262-
#ifndef __HAVE_ARCH_PTEP_CLEAR
263-
static inline void ptep_clear(struct mm_struct *mm, unsigned long addr,
264-
pte_t *ptep)
265-
{
266-
pte_clear(mm, addr, ptep);
267-
}
268-
#endif
269-
270263
#ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR
271264
static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
272265
unsigned long address,
273266
pte_t *ptep)
274267
{
275268
pte_t pte = *ptep;
276269
pte_clear(mm, address, ptep);
270+
page_table_check_pte_clear(mm, address, pte);
277271
return pte;
278272
}
279273
#endif
280274

275+
#ifndef __HAVE_ARCH_PTEP_CLEAR
276+
static inline void ptep_clear(struct mm_struct *mm, unsigned long addr,
277+
pte_t *ptep)
278+
{
279+
ptep_get_and_clear(mm, addr, ptep);
280+
}
281+
#endif
282+
281283
#ifndef __HAVE_ARCH_PTEP_GET
282284
static inline pte_t ptep_get(pte_t *ptep)
283285
{
@@ -347,7 +349,10 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
347349
pmd_t *pmdp)
348350
{
349351
pmd_t pmd = *pmdp;
352+
350353
pmd_clear(pmdp);
354+
page_table_check_pmd_clear(mm, address, pmd);
355+
351356
return pmd;
352357
}
353358
#endif /* __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR */
@@ -359,6 +364,8 @@ static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm,
359364
pud_t pud = *pudp;
360365

361366
pud_clear(pudp);
367+
page_table_check_pud_clear(mm, address, pud);
368+
362369
return pud;
363370
}
364371
#endif /* __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR */

0 commit comments

Comments
 (0)