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

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 <christophe.leroy@c-s.fr>
Cc: stable@vger.kernel.org
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/9f33f44b9cd741c4a02b3dce7b8ef9438fe2cd2a.1566382750.git.christophe.leroy@c-s.fr

authored by

Christophe Leroy and committed by
Michael Ellerman
4c0f5d1e 13c7bb3c

+13 -8
+13 -8
arch/powerpc/mm/kasan/kasan_init_32.c
··· 12 12 #include <asm/code-patching.h> 13 13 #include <mm/mmu_decl.h> 14 14 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 + 15 23 static void kasan_populate_pte(pte_t *ptep, pgprot_t prot) 16 24 { 17 25 unsigned long va = (unsigned long)kasan_early_shadow_page; ··· 34 26 { 35 27 pmd_t *pmd; 36 28 unsigned long k_cur, k_next; 29 + pgprot_t prot = kasan_prot_ro(); 37 30 38 31 pmd = pmd_offset(pud_offset(pgd_offset_k(k_start), k_start), k_start); 39 32 ··· 52 43 53 44 if (!new) 54 45 return -ENOMEM; 55 - if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) 56 - kasan_populate_pte(new, PAGE_READONLY); 57 - else 58 - kasan_populate_pte(new, PAGE_KERNEL_RO); 46 + kasan_populate_pte(new, prot); 59 47 60 48 smp_wmb(); /* See comment in __pte_alloc */ 61 49 ··· 109 103 110 104 static void __init kasan_remap_early_shadow_ro(void) 111 105 { 112 - if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) 113 - kasan_populate_pte(kasan_early_shadow_pte, PAGE_READONLY); 114 - else 115 - kasan_populate_pte(kasan_early_shadow_pte, PAGE_KERNEL_RO); 106 + pgprot_t prot = kasan_prot_ro(); 107 + 108 + kasan_populate_pte(kasan_early_shadow_pte, prot); 116 109 117 110 flush_tlb_kernel_range(KASAN_SHADOW_START, KASAN_SHADOW_END); 118 111 }