forked from mirrors/linux
		
	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/20220507110114.4128854-4-tongtiangen@huawei.com Signed-off-by: Tong Tiangen <tongtiangen@huawei.com> Acked-by: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Kefeng Wang <wangkefeng.wang@huawei.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Paul Walmsley <paul.walmsley@sifive.com> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									e5a5540146
								
							
						
					
					
						commit
						de8c8e5283
					
				
					 2 changed files with 15 additions and 18 deletions
				
			
		|  | @ -1072,16 +1072,6 @@ static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, | ||||||
| 	return pte; | 	return pte; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #define __HAVE_ARCH_PTEP_CLEAR |  | ||||||
| static inline void ptep_clear(struct mm_struct *mm, unsigned long addr, |  | ||||||
| 			      pte_t *ptep) |  | ||||||
| { |  | ||||||
| 	if (IS_ENABLED(CONFIG_PAGE_TABLE_CHECK)) |  | ||||||
| 		ptep_get_and_clear(mm, addr, ptep); |  | ||||||
| 	else |  | ||||||
| 		pte_clear(mm, addr, ptep); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #define __HAVE_ARCH_PTEP_SET_WRPROTECT | #define __HAVE_ARCH_PTEP_SET_WRPROTECT | ||||||
| static inline void ptep_set_wrprotect(struct mm_struct *mm, | static inline void ptep_set_wrprotect(struct mm_struct *mm, | ||||||
| 				      unsigned long addr, pte_t *ptep) | 				      unsigned long addr, pte_t *ptep) | ||||||
|  |  | ||||||
|  | @ -12,6 +12,7 @@ | ||||||
| #include <linux/bug.h> | #include <linux/bug.h> | ||||||
| #include <linux/errno.h> | #include <linux/errno.h> | ||||||
| #include <asm-generic/pgtable_uffd.h> | #include <asm-generic/pgtable_uffd.h> | ||||||
|  | #include <linux/page_table_check.h> | ||||||
| 
 | 
 | ||||||
| #if 5 - defined(__PAGETABLE_P4D_FOLDED) - defined(__PAGETABLE_PUD_FOLDED) - \ | #if 5 - defined(__PAGETABLE_P4D_FOLDED) - defined(__PAGETABLE_PUD_FOLDED) - \ | ||||||
| 	defined(__PAGETABLE_PMD_FOLDED) != CONFIG_PGTABLE_LEVELS | 	defined(__PAGETABLE_PMD_FOLDED) != CONFIG_PGTABLE_LEVELS | ||||||
|  | @ -259,14 +260,6 @@ static inline int pmdp_clear_flush_young(struct vm_area_struct *vma, | ||||||
| #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifndef __HAVE_ARCH_PTEP_CLEAR |  | ||||||
| static inline void ptep_clear(struct mm_struct *mm, unsigned long addr, |  | ||||||
| 			      pte_t *ptep) |  | ||||||
| { |  | ||||||
| 	pte_clear(mm, addr, ptep); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR | #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR | ||||||
| static inline pte_t ptep_get_and_clear(struct mm_struct *mm, | static inline pte_t ptep_get_and_clear(struct mm_struct *mm, | ||||||
| 				       unsigned long address, | 				       unsigned long address, | ||||||
|  | @ -274,10 +267,19 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, | ||||||
| { | { | ||||||
| 	pte_t pte = *ptep; | 	pte_t pte = *ptep; | ||||||
| 	pte_clear(mm, address, ptep); | 	pte_clear(mm, address, ptep); | ||||||
|  | 	page_table_check_pte_clear(mm, address, pte); | ||||||
| 	return pte; | 	return pte; | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  | #ifndef __HAVE_ARCH_PTEP_CLEAR | ||||||
|  | static inline void ptep_clear(struct mm_struct *mm, unsigned long addr, | ||||||
|  | 			      pte_t *ptep) | ||||||
|  | { | ||||||
|  | 	ptep_get_and_clear(mm, addr, ptep); | ||||||
|  | } | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| #ifndef __HAVE_ARCH_PTEP_GET | #ifndef __HAVE_ARCH_PTEP_GET | ||||||
| static inline pte_t ptep_get(pte_t *ptep) | static inline pte_t ptep_get(pte_t *ptep) | ||||||
| { | { | ||||||
|  | @ -347,7 +349,10 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, | ||||||
| 					    pmd_t *pmdp) | 					    pmd_t *pmdp) | ||||||
| { | { | ||||||
| 	pmd_t pmd = *pmdp; | 	pmd_t pmd = *pmdp; | ||||||
|  | 
 | ||||||
| 	pmd_clear(pmdp); | 	pmd_clear(pmdp); | ||||||
|  | 	page_table_check_pmd_clear(mm, address, pmd); | ||||||
|  | 
 | ||||||
| 	return pmd; | 	return pmd; | ||||||
| } | } | ||||||
| #endif /* __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR */ | #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, | ||||||
| 	pud_t pud = *pudp; | 	pud_t pud = *pudp; | ||||||
| 
 | 
 | ||||||
| 	pud_clear(pudp); | 	pud_clear(pudp); | ||||||
|  | 	page_table_check_pud_clear(mm, address, pud); | ||||||
|  | 
 | ||||||
| 	return pud; | 	return pud; | ||||||
| } | } | ||||||
| #endif /* __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR */ | #endif /* __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR */ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Tong Tiangen
						Tong Tiangen