Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc: Refactor __kernel_map_pages()

__kernel_map_pages() is almost identical for PPC32 and RADIX.

Refactor it.

On PPC32 it is not needed for KFENCE, but to keep it simple
just make it similar to PPC64.

Move the prototype of hash__kernel_map_pages() into mmu_decl.h to allow
IS_ENABLED() to work on 32-bit.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/3656d47c53bff577739dac536dbae31fff52f6d8.1708078640.git.christophe.leroy@csgroup.eu

authored by

Christophe Leroy and committed by
Michael Ellerman
3c8016e6 f7f18e30

+22 -43
-2
arch/powerpc/include/asm/book3s/64/hash.h
··· 269 269 int nid, pgprot_t prot); 270 270 int hash__remove_section_mapping(unsigned long start, unsigned long end); 271 271 272 - void hash__kernel_map_pages(struct page *page, int numpages, int enable); 273 - 274 272 #endif /* !__ASSEMBLY__ */ 275 273 #endif /* __KERNEL__ */ 276 274 #endif /* _ASM_POWERPC_BOOK3S_64_HASH_H */
-10
arch/powerpc/include/asm/book3s/64/pgtable.h
··· 1027 1027 } 1028 1028 #endif 1029 1029 1030 - #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KFENCE) 1031 - static inline void __kernel_map_pages(struct page *page, int numpages, int enable) 1032 - { 1033 - if (radix_enabled()) 1034 - radix__kernel_map_pages(page, numpages, enable); 1035 - else 1036 - hash__kernel_map_pages(page, numpages, enable); 1037 - } 1038 - #endif 1039 - 1040 1030 static inline pte_t pmd_pte(pmd_t pmd) 1041 1031 { 1042 1032 return __pte_raw(pmd_raw(pmd));
-2
arch/powerpc/include/asm/book3s/64/radix.h
··· 362 362 int radix__remove_section_mapping(unsigned long start, unsigned long end); 363 363 #endif /* CONFIG_MEMORY_HOTPLUG */ 364 364 365 - void radix__kernel_map_pages(struct page *page, int numpages, int enable); 366 - 367 365 #ifdef CONFIG_ARCH_WANT_OPTIMIZE_DAX_VMEMMAP 368 366 #define vmemmap_can_optimize vmemmap_can_optimize 369 367 bool vmemmap_can_optimize(struct vmem_altmap *altmap, struct dev_pagemap *pgmap);
-14
arch/powerpc/mm/book3s64/radix_pgtable.c
··· 1339 1339 #endif 1340 1340 #endif 1341 1341 1342 - #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KFENCE) 1343 - void radix__kernel_map_pages(struct page *page, int numpages, int enable) 1344 - { 1345 - unsigned long addr; 1346 - 1347 - addr = (unsigned long)page_address(page); 1348 - 1349 - if (enable) 1350 - set_memory_p(addr, numpages); 1351 - else 1352 - set_memory_np(addr, numpages); 1353 - } 1354 - #endif 1355 - 1356 1342 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 1357 1343 1358 1344 unsigned long radix__pmd_hugepage_update(struct mm_struct *mm, unsigned long addr,
+2
arch/powerpc/mm/mmu_decl.h
··· 186 186 int create_section_mapping(unsigned long start, unsigned long end, 187 187 int nid, pgprot_t prot); 188 188 #endif 189 + 190 + void hash__kernel_map_pages(struct page *page, int numpages, int enable);
+20
arch/powerpc/mm/pageattr.c
··· 14 14 #include <asm/page.h> 15 15 #include <asm/pgtable.h> 16 16 17 + #include <mm/mmu_decl.h> 17 18 18 19 static pte_basic_t pte_update_delta(pte_t *ptep, unsigned long addr, 19 20 unsigned long old, unsigned long new) ··· 102 101 return apply_to_existing_page_range(&init_mm, start, size, 103 102 change_page_attr, (void *)action); 104 103 } 104 + 105 + #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KFENCE) 106 + #ifdef CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC 107 + void __kernel_map_pages(struct page *page, int numpages, int enable) 108 + { 109 + unsigned long addr = (unsigned long)page_address(page); 110 + 111 + if (PageHighMem(page)) 112 + return; 113 + 114 + if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && !radix_enabled()) 115 + hash__kernel_map_pages(page, numpages, enable); 116 + else if (enable) 117 + set_memory_p(addr, numpages); 118 + else 119 + set_memory_np(addr, numpages); 120 + } 121 + #endif 122 + #endif
-15
arch/powerpc/mm/pgtable_32.c
··· 171 171 ptdump_check_wx(); 172 172 } 173 173 #endif 174 - 175 - #if defined(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC) && defined(CONFIG_DEBUG_PAGEALLOC) 176 - void __kernel_map_pages(struct page *page, int numpages, int enable) 177 - { 178 - unsigned long addr = (unsigned long)page_address(page); 179 - 180 - if (PageHighMem(page)) 181 - return; 182 - 183 - if (enable) 184 - set_memory_p(addr, numpages); 185 - else 186 - set_memory_np(addr, numpages); 187 - } 188 - #endif /* CONFIG_DEBUG_PAGEALLOC */