powerpc/mm: Cleanup handling of execute permission v2
PATCH 1/1 powerpc/mm: Cleanup handling of execute permission v2
This is an attempt at cleaning up a bit the way we handle execute permission on powerpc. _PAGE_HWEXEC is gone, _PAGE_EXEC is now only defined by CPUs that can do something with it, and the myriad of #ifdef's in the I$/D$ coherency code is reduced to 2 cases that hopefully should cover everything.
The logic on BookE is a little bit different than what it was though not by much. Since now, _PAGE_EXEC will be set by the generic code for executable pages, we need to filter out if they are unclean and recover it. However, I don't expect the code to be more bloated than it already was in that area due to that change.
I could boast that this brings proper enforcing of per-page execute permissions to all BookE and 40x but in fact, we've had that now for some time as a side effect of my previous rework in that area (and I didn't even know it :-) We would only enable execute permission if the page was cache clean and we would only cache clean it if we took and exec fault. Since we now enforce that the later only work if VM_EXEC is part of the VMA flags, we de-fact already enforce per-page execute permissions... Unless I missed something
---
This version restores the missing (oops) cache flush in ptep_set_access_flags() which broke BookE.
arch/powerpc/include/asm/pgtable-ppc32.h +3 -4
@@ -186,7 +186,7 @@ static inline unsigned long pte_update(pte_t *p,#endif /* !PTE_ATOMIC_UPDATES */ #ifdef CONFIG_44x -if ((old & _PAGE_USER) && (old & _PAGE_HWEXEC)) +if ((old & _PAGE_USER) && (old & _PAGE_EXEC)) icache_44x_need_flush =1 ;#endif return old;
@@ -217,7 +217,7 @@ static inline unsigned long long pte_update(pte_t *p,#endif /* !PTE_ATOMIC_UPDATES */ #ifdef CONFIG_44x -if ((old & _PAGE_USER) && (old & _PAGE_HWEXEC)) +if ((old & _PAGE_USER) && (old & _PAGE_EXEC)) icache_44x_need_flush =1 ;#endif return old;
@@ -267,8 +267,7 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,static inline void __ptep_set_access_flags (pte_t *ptep,pte_t entry) {unsigned long bits =pte_val (entry) & - (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | - _PAGE_HWEXEC | _PAGE_EXEC); + (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);pte_update (ptep,0 , bits); }
arch/powerpc/include/asm/pgtable-ppc64.h +1 -2
@@ -313,8 +313,7 @@ static inline void pte_clear(struct mm_struct *mm, unsigned long addr,static inline void __ptep_set_access_flags (pte_t *ptep,pte_t entry) {unsigned long bits =pte_val (entry) & - (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | - _PAGE_EXEC | _PAGE_HWEXEC); + (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);#ifdef PTE_ATOMIC_UPDATES unsigned long old, tmp;
arch/powerpc/include/asm/pte-40x.h +1 -1
@@ -46,7 +46,7 @@#define _PAGE_RW 0x040/* software: Writes permitted */ #define _PAGE_DIRTY 0x080/* software: dirty page */ #define _PAGE_HWWRITE 0x100/* hardware: Dirty & RW, set in exception */ -#define _PAGE_HWEXEC 0x200/* hardware: EX permission */ +#define _PAGE_EXEC 0x200/* hardware: EX permission */ #define _PAGE_ACCESSED 0x400/* software: R: page referenced */ #define _PMD_PRESENT 0x400/* PMD points to page of PTEs */
arch/powerpc/include/asm/pte-44x.h +1 -1
@@ -78,7 +78,7 @@#define _PAGE_PRESENT 0x00000001/* S: PTE valid */ #define _PAGE_RW 0x00000002/* S: Write permission */ #define _PAGE_FILE 0x00000004/* S: nonlinear file mapping */ -#define _PAGE_HWEXEC 0x00000004/* H: Execute permission */ +#define _PAGE_EXEC 0x00000004/* H: Execute permission */ #define _PAGE_ACCESSED 0x00000008/* S: Page referenced */ #define _PAGE_DIRTY 0x00000010/* S: Page dirty */ #define _PAGE_SPECIAL 0x00000020/* S: Special page */
arch/powerpc/include/asm/pte-8xx.h +0 -1
@@ -36,7 +36,6 @@/* These five software bits must be masked out when the entry is loaded * into the TLB. */ -#define _PAGE_EXEC 0x0008/* software: i-cache coherency required */ #define _PAGE_GUARDED 0x0010/* software: guarded access */ #define _PAGE_DIRTY 0x0020/* software: page changed */ #define _PAGE_RW 0x0040/* software: user write access allowed */
arch/powerpc/include/asm/pte-book3e.h +7 -6
@@ -37,12 +37,13 @@#define _PAGE_WRITETHRU 0x800000/* W: cache write-through */ /* "Higher level" linux bit combinations */ -#define _PAGE_EXEC _PAGE_BAP_SX/* Can be executed from potentially */ -#define _PAGE_HWEXEC _PAGE_BAP_UX/* .. and was cache cleaned */ -#define _PAGE_RW (_PAGE_BAP_SW | _PAGE_BAP_UW)/* User write permission */ -#define _PAGE_KERNEL_RW (_PAGE_BAP_SW | _PAGE_BAP_SR | _PAGE_DIRTY) -#define _PAGE_KERNEL_RO (_PAGE_BAP_SR) -#define _PAGE_USER (_PAGE_BAP_UR | _PAGE_BAP_SR)/* Can be read */ +#define _PAGE_EXEC _PAGE_BAP_UX/* .. and was cache cleaned */ +#define _PAGE_RW (_PAGE_BAP_SW | _PAGE_BAP_UW)/* User write permission */ +#define _PAGE_KERNEL_RW (_PAGE_BAP_SW | _PAGE_BAP_SR | _PAGE_DIRTY) +#define _PAGE_KERNEL_RO (_PAGE_BAP_SR) +#define _PAGE_KERNEL_RWX (_PAGE_BAP_SW | _PAGE_BAP_SR | _PAGE_DIRTY | _PAGE_BAP_SX) +#define _PAGE_KERNEL_ROX (_PAGE_BAP_SR | _PAGE_BAP_SX) +#define _PAGE_USER (_PAGE_BAP_UR | _PAGE_BAP_SR)/* Can be read */ #define _PAGE_HASHPTE 0#define _PAGE_BUSY 0
arch/powerpc/include/asm/pte-common.h +11 -11
@@ -13,9 +13,6 @@#ifndef _PAGE_HWWRITE#define _PAGE_HWWRITE 0#endif -#ifndef _PAGE_HWEXEC -#define _PAGE_HWEXEC 0 -#endif #ifndef _PAGE_EXEC#define _PAGE_EXEC 0#endif
@@ -48,10 +45,16 @@#define PMD_PAGE_SIZE (pmd) bad_call_to_PMD_PAGE_SIZE()#endif #ifndef _PAGE_KERNEL_RO -#define _PAGE_KERNEL_RO 0 +#define _PAGE_KERNEL_RO 0 +#endif +#ifndef _PAGE_KERNEL_ROX +#define _PAGE_KERNEL_ROX (_PAGE_EXEC)#endif #ifndef _PAGE_KERNEL_RW -#define _PAGE_KERNEL_RW (_PAGE_DIRTY | _PAGE_RW | _PAGE_HWWRITE) +#define _PAGE_KERNEL_RW (_PAGE_DIRTY | _PAGE_RW | _PAGE_HWWRITE) +#endif +#ifndef _PAGE_KERNEL_RWX +#define _PAGE_KERNEL_RWX (_PAGE_DIRTY | _PAGE_RW | _PAGE_HWWRITE | _PAGE_EXEC)#endif #ifndef _PAGE_HPTEFLAGS#define _PAGE_HPTEFLAGS _PAGE_HASHPTE
@@ -96,8 +99,7 @@ extern unsigned long bad_call_to_PMD_PAGE_SIZE(void);#define PAGE_PROT_BITS (_PAGE_GUARDED | _PAGE_COHERENT | _PAGE_NO_CACHE | \ _PAGE_WRITETHRU | _PAGE_ENDIAN | _PAGE_4K_PFN | \ _PAGE_USER | _PAGE_ACCESSED | \ - _PAGE_RW | _PAGE_HWWRITE | _PAGE_DIRTY | \ - _PAGE_EXEC | _PAGE_HWEXEC) + _PAGE_RW | _PAGE_HWWRITE | _PAGE_DIRTY | _PAGE_EXEC)/* * We define 2 sets of base prot bits, one for basic pages (ie,
@@ -154,11 +156,9 @@ extern unsigned long bad_call_to_PMD_PAGE_SIZE(void); _PAGE_NO_CACHE)#define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \ _PAGE_NO_CACHE | _PAGE_GUARDED) -#define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW | _PAGE_EXEC | \ - _PAGE_HWEXEC) +#define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RWX)#define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO) -#define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO | _PAGE_EXEC | \ - _PAGE_HWEXEC) +#define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX)/* Protection used for kernel text. We want the debuggers to be able to * set breakpoints anywhere, so don't write protect the kernel text
arch/powerpc/include/asm/pte-fsl-booke.h +1 -1
@@ -23,7 +23,7 @@#define _PAGE_FILE 0x00002/* S: when !present: nonlinear file mapping */ #define _PAGE_RW 0x00004/* S: Write permission (SW) */ #define _PAGE_DIRTY 0x00008/* S: Page dirty */ -#define _PAGE_HWEXEC 0x00010/* H: SX permission */ +#define _PAGE_EXEC 0x00010/* H: SX permission */ #define _PAGE_ACCESSED 0x00020/* S: Page referenced */ #define _PAGE_ENDIAN 0x00040/* H: E bit */
arch/powerpc/include/asm/pte-hash32.h +0 -1
@@ -26,7 +26,6 @@#define _PAGE_WRITETHRU 0x040/* W: cache write-through */ #define _PAGE_DIRTY 0x080/* C: page changed */ #define _PAGE_ACCESSED 0x100/* R: page referenced */ -#define _PAGE_EXEC 0x200/* software: i-cache coherency required */ #define _PAGE_RW 0x400/* software: user write access allowed */ #define _PAGE_SPECIAL 0x800/* software: Special page */
arch/powerpc/kernel/head_44x.S +1 -1
@@ -497,7 +497,7 @@ tlb_44x_patch_hwater_D: mtspr SPRN_MMUCR,r12 /* Make up the required permissions */ - li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_HWEXEC + li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC /* Compute pgdir/pmd offset */ rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29
arch/powerpc/kernel/head_fsl_booke.S +2 -2
@@ -643,7 +643,7 @@ interrupt_base: 4: /* Make up the required permissions */ - li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_HWEXEC + li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC FIND_PTE andc. r13,r13,r11 /* Check permission */
@@ -742,7 +742,7 @@ finish_tlb_load: #endif mtspr SPRN_MAS2, r12 - li r10, (_PAGE_HWEXEC | _PAGE_PRESENT) + li r10, (_PAGE_EXEC | _PAGE_PRESENT) rlwimi r10, r11, 31, 29, 29 /* extract _PAGE_DIRTY into SW */ and r12, r11, r10 andi. r10, r11, _PAGE_USER /* Test for _PAGE_USER */
arch/powerpc/mm/40x_mmu.c +2 -2
@@ -105,7 +105,7 @@ unsigned long __init mmu_mapin_ram(void)while (s >=LARGE_PAGE_SIZE_16M ) {pmd_t *pmdp; -unsigned long val = p | _PMD_SIZE_16M | _PAGE_HWEXEC | _PAGE_HWWRITE; +unsigned long val = p | _PMD_SIZE_16M | _PAGE_EXEC | _PAGE_HWWRITE; pmdp =pmd_offset (pud_offset (pgd_offset_k (v), v), v);pmd_val (*pmdp++) = val;
@@ -120,7 +120,7 @@ unsigned long __init mmu_mapin_ram(void)while (s >=LARGE_PAGE_SIZE_4M ) {pmd_t *pmdp; -unsigned long val = p | _PMD_SIZE_4M | _PAGE_HWEXEC | _PAGE_HWWRITE; +unsigned long val = p | _PMD_SIZE_4M | _PAGE_EXEC | _PAGE_HWWRITE; pmdp =pmd_offset (pud_offset (pgd_offset_k (v), v), v);pmd_val (*pmdp) = val;
arch/powerpc/mm/pgtable.c +116 -51
210 lines not on this page · raw message
arch/powerpc/mm/pgtable_32.c +1 -1
@@ -142,7 +142,7 @@ ioremap_flags(phys_addr_t addr, unsigned long size, unsigned long flags) flags |= _PAGE_DIRTY | _PAGE_HWWRITE;/* we don't want to let _PAGE_USER and _PAGE_EXEC leak out */ - flags &= ~(_PAGE_USER | _PAGE_EXEC | _PAGE_HWEXEC); + flags &= ~(_PAGE_USER | _PAGE_EXEC);return __ioremap_caller (addr, size, flags,__builtin_return_address (0 )); }
arch/powerpc/mm/tlb_low_64e.S +2 -2
@@ -133,7 +133,7 @@ /* We do the user/kernel test for the PID here along with the RW test */ - li r11,_PAGE_PRESENT|_PAGE_HWEXEC /* Base perm */ + li r11,_PAGE_PRESENT|_PAGE_EXEC /* Base perm */ oris r11,r11,_PAGE_ACCESSED@h cmpldi cr0,r15,0 /* Check for user region */
@@ -256,7 +256,7 @@ normal_tlb_miss_done: normal_tlb_miss_access_fault: /* We need to check if it was an instruction miss */ - andi. r10,r11,_PAGE_HWEXEC + andi. r10,r11,_PAGE_EXEC bne 1f ld r14,EX_TLB_DEAR(r12) ld r15,EX_TLB_ESR(r12)
Signature · 1 line
1.6.1.2.14.gf26b5
Quoted 21 lines · Benjamin Herrenschmidt
This is an attempt at cleaning up a bit the way we handle execute permission on powerpc.
_PAGE_HWEXECis gone,_PAGE_EXECis now only defined by CPUs that can do something with it, and the myriad of #ifdef's in the I$/D$ coherency code is reduced to 2 cases that hopefully should cover everything.The logic on BookE is a little bit different than what it was though not by much. Since now,
_PAGE_EXECwill be set by the generic code for executable pages, we need to filter out if they are unclean and recover it. However, I don't expect the code to be more bloated than it already was in that area due to that change.I could boast that this brings proper enforcing of per-page execute permissions to all BookE and 40x but in fact, we've had that now for some time as a side effect of my previous rework in that area (and I didn't even know it :-) We would only enable execute permission if the page was cache clean and we would only cache clean it if we took and exec fault. Since we now enforce that the later only work if
VM_EXECis part of the VMA flags, we de-fact already enforce per-page execute permissions... Unless I missed something
Quoted 1 line
Signed-off-by Benjamin Herrenschmidt <[email protected]>
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson