Skip to content

Commit 3c8016e

Browse files
chleroympe
authored andcommitted
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
1 parent f7f18e3 commit 3c8016e

7 files changed

Lines changed: 22 additions & 43 deletions

File tree

arch/powerpc/include/asm/book3s/64/hash.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,6 @@ int hash__create_section_mapping(unsigned long start, unsigned long end,
269269
int nid, pgprot_t prot);
270270
int hash__remove_section_mapping(unsigned long start, unsigned long end);
271271

272-
void hash__kernel_map_pages(struct page *page, int numpages, int enable);
273-
274272
#endif /* !__ASSEMBLY__ */
275273
#endif /* __KERNEL__ */
276274
#endif /* _ASM_POWERPC_BOOK3S_64_HASH_H */

arch/powerpc/include/asm/book3s/64/pgtable.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,16 +1027,6 @@ static inline void vmemmap_remove_mapping(unsigned long start,
10271027
}
10281028
#endif
10291029

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-
10401030
static inline pte_t pmd_pte(pmd_t pmd)
10411031
{
10421032
return __pte_raw(pmd_raw(pmd));

arch/powerpc/include/asm/book3s/64/radix.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,6 @@ int radix__create_section_mapping(unsigned long start, unsigned long end,
362362
int radix__remove_section_mapping(unsigned long start, unsigned long end);
363363
#endif /* CONFIG_MEMORY_HOTPLUG */
364364

365-
void radix__kernel_map_pages(struct page *page, int numpages, int enable);
366-
367365
#ifdef CONFIG_ARCH_WANT_OPTIMIZE_DAX_VMEMMAP
368366
#define vmemmap_can_optimize vmemmap_can_optimize
369367
bool vmemmap_can_optimize(struct vmem_altmap *altmap, struct dev_pagemap *pgmap);

arch/powerpc/mm/book3s64/radix_pgtable.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,20 +1339,6 @@ void __ref radix__vmemmap_free(unsigned long start, unsigned long end,
13391339
#endif
13401340
#endif
13411341

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-
13561342
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
13571343

13581344
unsigned long radix__pmd_hugepage_update(struct mm_struct *mm, unsigned long addr,

arch/powerpc/mm/mmu_decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,5 @@ static inline bool debug_pagealloc_enabled_or_kfence(void)
186186
int create_section_mapping(unsigned long start, unsigned long end,
187187
int nid, pgprot_t prot);
188188
#endif
189+
190+
void hash__kernel_map_pages(struct page *page, int numpages, int enable);

arch/powerpc/mm/pageattr.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <asm/page.h>
1515
#include <asm/pgtable.h>
1616

17+
#include <mm/mmu_decl.h>
1718

1819
static pte_basic_t pte_update_delta(pte_t *ptep, unsigned long addr,
1920
unsigned long old, unsigned long new)
@@ -101,3 +102,22 @@ int change_memory_attr(unsigned long addr, int numpages, long action)
101102
return apply_to_existing_page_range(&init_mm, start, size,
102103
change_page_attr, (void *)action);
103104
}
105+
106+
#if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KFENCE)
107+
#ifdef CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC
108+
void __kernel_map_pages(struct page *page, int numpages, int enable)
109+
{
110+
unsigned long addr = (unsigned long)page_address(page);
111+
112+
if (PageHighMem(page))
113+
return;
114+
115+
if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && !radix_enabled())
116+
hash__kernel_map_pages(page, numpages, enable);
117+
else if (enable)
118+
set_memory_p(addr, numpages);
119+
else
120+
set_memory_np(addr, numpages);
121+
}
122+
#endif
123+
#endif

arch/powerpc/mm/pgtable_32.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,3 @@ void mark_rodata_ro(void)
171171
ptdump_check_wx();
172172
}
173173
#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 */

0 commit comments

Comments
 (0)