Skip to content

Commit 4c0f5d1

Browse files
chleroympe
authored andcommitted
powerpc/mm: Add a helper to select PAGE_KERNEL_RO or PAGE_READONLY
In a couple of places there is a need to select whether read-only protection of shadow pages is performed with PAGE_KERNEL_RO or with PAGE_READONLY. Add a helper to avoid duplicating the choice. Signed-off-by: Christophe Leroy <[email protected]> Cc: [email protected] Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/9f33f44b9cd741c4a02b3dce7b8ef9438fe2cd2a.1566382750.git.christophe.leroy@c-s.fr
1 parent 13c7bb3 commit 4c0f5d1

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

arch/powerpc/mm/kasan/kasan_init_32.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
#include <asm/code-patching.h>
1313
#include <mm/mmu_decl.h>
1414

15+
static pgprot_t kasan_prot_ro(void)
16+
{
17+
if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE))
18+
return PAGE_READONLY;
19+
20+
return PAGE_KERNEL_RO;
21+
}
22+
1523
static void kasan_populate_pte(pte_t *ptep, pgprot_t prot)
1624
{
1725
unsigned long va = (unsigned long)kasan_early_shadow_page;
@@ -26,6 +34,7 @@ static int __ref kasan_init_shadow_page_tables(unsigned long k_start, unsigned l
2634
{
2735
pmd_t *pmd;
2836
unsigned long k_cur, k_next;
37+
pgprot_t prot = kasan_prot_ro();
2938

3039
pmd = pmd_offset(pud_offset(pgd_offset_k(k_start), k_start), k_start);
3140

@@ -43,10 +52,7 @@ static int __ref kasan_init_shadow_page_tables(unsigned long k_start, unsigned l
4352

4453
if (!new)
4554
return -ENOMEM;
46-
if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE))
47-
kasan_populate_pte(new, PAGE_READONLY);
48-
else
49-
kasan_populate_pte(new, PAGE_KERNEL_RO);
55+
kasan_populate_pte(new, prot);
5056

5157
smp_wmb(); /* See comment in __pte_alloc */
5258

@@ -103,10 +109,9 @@ static int __ref kasan_init_region(void *start, size_t size)
103109

104110
static void __init kasan_remap_early_shadow_ro(void)
105111
{
106-
if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE))
107-
kasan_populate_pte(kasan_early_shadow_pte, PAGE_READONLY);
108-
else
109-
kasan_populate_pte(kasan_early_shadow_pte, PAGE_KERNEL_RO);
112+
pgprot_t prot = kasan_prot_ro();
113+
114+
kasan_populate_pte(kasan_early_shadow_pte, prot);
110115

111116
flush_tlb_kernel_range(KASAN_SHADOW_START, KASAN_SHADOW_END);
112117
}

0 commit comments

Comments
 (0)