mm/mmap: Drop protection_map[] and platform's __SXXX/__PXXX requirements
Subsystems (29)
v3 cover mm/mmap: Drop protection_map[] and platform's __SXXX/__PXXX requirements
protection_map[] is an array based construct that translates given vm_flags combination. This array contains page protection map, which is populated by the platform via [__S000 .. __S111] and [__P000 .. __P111] exported macros. Primary usage for protection_map[] is for vm_get_page_prot(), which is used to determine page protection value for a given vm_flags. vm_get_page_prot() implementation, could again call platform overrides arch_vm_get_page_prot() and arch_filter_pgprot(). Some platforms override protection_map[] that was originally built with __SXXX/__PXXX with different runtime values.
Currently there are multiple layers of abstraction i.e __SXXX/__PXXX macros , protection_map[], arch_vm_get_page_prot() and arch_filter_pgprot() built between the platform and generic MM, finally defining vm_get_page_prot().
Hence this series proposes to drop all these abstraction levels and instead just move the responsibility of defining vm_get_page_prot() to the platform itself making it clean and simple.
This first introduces ARCH_HAS_VM_GET_PAGE_PROT which enables the platforms to define custom vm_get_page_prot(). This starts converting platforms that either change protection_map[] or define the overrides arch_filter_pgprot() or arch_vm_get_page_prot() which enables for those constructs to be dropped off completely. This series then converts remaining platforms which enables for __SXXX/__PXXX constructs to be dropped off completely. Finally it drops the generic vm_get_page_prot() and then ARCH_HAS_VM_GET_PAGE_PROT as every platform now defines their own vm_get_page_prot().
The series has been inspired from an earlier discuss with Christoph Hellwig
https://lore.kernel.org/all/[email protected]/
This series applies on 5.17-rc6 after the following patch.
https://lore.kernel.org/all/[email protected]/
This series has been cross built for multiple platforms.
- Anshuman
Changes in V3:
- Dropped variable 'i' from sme_early_init() on x86 platform
- Moved CONFIG_COLDFIRE vm_get_page_prot() inside arch/m68k/mm/mcfmmu.c
- Moved CONFIG_SUN3 vm_get_page_prot() inside arch/m68k/mm/sun3mmu.c
- Dropped cachebits for vm_get_page_prot() inside arch/m68k/mm/motorola.c
- Dropped PAGE_XXX_C definitions from arch/m68k/include/asm/motorola_pgtable.h
- Used PAGE_XXX instead for vm_get_page_prot() inside arch/m68k/mm/motorola.c
- Dropped all references to protection_map[] in the tree
- Replaced s/extensa/xtensa/ on the patch title
- Moved left over comments from pgtable.h into init.c on nios2 platform
Changes in V2:
https://lore.kernel.org/all/[email protected]/
- Dropped the entire comment block in [PATCH 30/30] per Geert
- Replaced __P010 (although commented) with __PAGE_COPY on arm platform
- Replaced __P101 with PAGE_READONLY on um platform
Changes in V1:
https://lore.kernel.org/all/[email protected]/
- Add white spaces around the | operators
- Moved powerpc_vm_get_page_prot() near vm_get_page_prot() on powerpc
- Moved arm64_vm_get_page_prot() near vm_get_page_prot() on arm64
- Moved sparc_vm_get_page_prot() near vm_get_page_prot() on sparc
- Compacted vm_get_page_prot() switch cases on all platforms
- _PAGE_CACHE040 inclusion is dependent on CPU_IS_040_OR_060
- VM_SHARED case should return PAGE_NONE (not PAGE_COPY) on SH platform
- Reorganized VM_SHARED, VM_EXEC, VM_WRITE, VM_READ
- Dropped the last patch [RFC V1 31/31] which added macros for vm_flags combinations
https://lore.kernel.org/all/[email protected]/
Changes in RFC:
https://lore.kernel.org/all/[email protected]/
Anshuman Khandual (29):
mm/debug_vm_pgtable: Drop protection_map[] usage mm/mmap: Clarify protection_map[] indices mm/mmap: Add new config ARCH_HAS_VM_GET_PAGE_PROT powerpc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT arm64/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT sparc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT mips/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT m68k/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT mm/mmap: Drop protection_map[]
mm/mmap: Drop arch_filter_pgprot() mm/mmap: Drop arch_vm_get_page_pgprot() s390/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT riscv/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT alpha/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT sh/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT arc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT csky/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT xtensa/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT parisc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT openrisc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT um/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT microblaze/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT nios2/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT hexagon/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT nds32/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT ia64/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT mm/mmap: Drop generic vm_get_page_prot() mm/mmap: Drop ARCH_HAS_VM_GET_PAGE_PROT
Christoph Hellwig (1):
x86/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
arch/alpha/include/asm/pgtable.h | 17 ----- arch/alpha/mm/init.c | 37 +++++++++++ arch/arc/include/asm/pgtable-bits-arcv2.h | 17 ----- arch/arc/mm/mmap.c | 41 ++++++++++++ arch/arm/include/asm/pgtable.h | 20 +----- arch/arm/lib/uaccess_with_memcpy.c | 2 +- arch/arm/mm/mmu.c | 44 +++++++++++-- arch/arm64/Kconfig | 1 - arch/arm64/include/asm/memory.h | 3 +- arch/arm64/include/asm/mman.h | 24 ------- arch/arm64/include/asm/pgtable-prot.h | 18 ------ arch/arm64/include/asm/pgtable.h | 11 ---- arch/arm64/mm/mmap.c | 78 +++++++++++++++++++++++ arch/csky/include/asm/pgtable.h | 18 ------ arch/csky/mm/init.c | 32 ++++++++++ arch/hexagon/include/asm/pgtable.h | 24 ------- arch/hexagon/mm/init.c | 67 +++++++++++++++++++ arch/ia64/include/asm/pgtable.h | 17 ----- arch/ia64/mm/init.c | 41 +++++++++++- arch/m68k/include/asm/mcf_pgtable.h | 59 ----------------- arch/m68k/include/asm/motorola_pgtable.h | 29 --------- arch/m68k/include/asm/sun3_pgtable.h | 22 ------- arch/m68k/mm/mcfmmu.c | 59 +++++++++++++++++ arch/m68k/mm/motorola.c | 43 ++++++++++++- arch/m68k/mm/sun3mmu.c | 39 ++++++++++++ arch/microblaze/include/asm/pgtable.h | 17 ----- arch/microblaze/mm/init.c | 41 ++++++++++++ arch/mips/include/asm/pgtable.h | 22 ------- arch/mips/mm/cache.c | 60 +++++++++-------- arch/nds32/include/asm/pgtable.h | 17 ----- arch/nds32/mm/mmap.c | 37 +++++++++++ arch/nios2/include/asm/pgtable.h | 24 ------- arch/nios2/mm/init.c | 47 ++++++++++++++ arch/openrisc/include/asm/pgtable.h | 18 ------ arch/openrisc/mm/init.c | 41 ++++++++++++ arch/parisc/include/asm/pgtable.h | 20 ------ arch/parisc/mm/init.c | 40 ++++++++++++ arch/powerpc/include/asm/mman.h | 12 ---- arch/powerpc/include/asm/pgtable.h | 19 ------ arch/powerpc/mm/mmap.c | 59 +++++++++++++++++ arch/riscv/include/asm/pgtable.h | 16 ----- arch/riscv/mm/init.c | 42 ++++++++++++ arch/s390/include/asm/pgtable.h | 17 ----- arch/s390/mm/mmap.c | 33 ++++++++++ arch/sh/include/asm/pgtable.h | 17 ----- arch/sh/mm/mmap.c | 38 +++++++++++ arch/sparc/include/asm/mman.h | 6 -- arch/sparc/include/asm/pgtable_32.h | 19 ------ arch/sparc/include/asm/pgtable_64.h | 19 ------ arch/sparc/mm/init_32.c | 35 ++++++++++ arch/sparc/mm/init_64.c | 70 ++++++++++++++------ arch/um/include/asm/pgtable.h | 17 ----- arch/um/kernel/mem.c | 35 ++++++++++ arch/x86/Kconfig | 1 - arch/x86/include/asm/pgtable.h | 5 -- arch/x86/include/asm/pgtable_types.h | 19 ------ arch/x86/include/uapi/asm/mman.h | 14 ---- arch/x86/mm/Makefile | 2 +- arch/x86/mm/mem_encrypt_amd.c | 6 -- arch/x86/mm/pgprot.c | 71 +++++++++++++++++++++ arch/x86/um/mem_32.c | 2 +- arch/xtensa/include/asm/pgtable.h | 19 ------ arch/xtensa/mm/init.c | 35 ++++++++++ drivers/gpu/drm/drm_vm.c | 4 +- include/linux/mm.h | 6 -- include/linux/mman.h | 4 -- mm/Kconfig | 3 - mm/debug_vm_pgtable.c | 31 +++++---- mm/mmap.c | 44 +------------ 69 files changed, 1138 insertions(+), 729 deletions(-) create mode 100644 arch/x86/mm/pgprot.c
Signature · 1 line
2.25.1
PATCH v3 1/30 mm/debug_vm_pgtable: Drop protection_map[] usage
Although protection_map[] contains the platform defined page protection map for a given vm_flags combination, vm_get_page_prot() is the right interface to use. This will also reduce dependency on protection_map[] which is going to be dropped off completely later on.
--- mm/debug_vm_pgtable.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-)
mm/debug_vm_pgtable.c +19 -12
@@ -93,7 +93,7 @@ struct pgtable_debug_args {static void __init pte_basic_tests (struct pgtable_debug_args *args,int idx) { -pgprot_t prot = protection_map[idx]; +pgprot_t prot =vm_get_page_prot (idx);pte_t pte =pfn_pte (args->fixed_pte_pfn, prot);unsigned long val = idx, *ptr = &val;
@@ -101,7 +101,7 @@ static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx)/* * This test needs to be executed after the given page table entry -* is created with pfn_pte() to make sure that protection_map[idx] +* is created with pfn_pte() to make sure that vm_get_page_prot(idx) * does not have the dirty bit enabled from the beginning. This is * important for platforms like arm64 where (!PTE_RDONLY) indicate * dirty bit being set.
@@ -190,7 +190,7 @@ static void __init pte_savedwrite_tests(struct pgtable_debug_args *args)#ifdef CONFIG_TRANSPARENT_HUGEPAGE static void __init pmd_basic_tests (struct pgtable_debug_args *args,int idx) { -pgprot_t prot = protection_map[idx]; +pgprot_t prot =vm_get_page_prot (idx);unsigned long val = idx, *ptr = &val;pmd_t pmd;
@@ -202,7 +202,7 @@ static void __init pmd_basic_tests(struct pgtable_debug_args *args, int idx)/* * This test needs to be executed after the given page table entry -* is created with pfn_pmd() to make sure that protection_map[idx] +* is created with pfn_pmd() to make sure that vm_get_page_prot(idx) * does not have the dirty bit enabled from the beginning. This is * important for platforms like arm64 where (!PTE_RDONLY) indicate * dirty bit being set.
@@ -325,7 +325,7 @@ static void __init pmd_savedwrite_tests(struct pgtable_debug_args *args)#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD static void __init pud_basic_tests (struct pgtable_debug_args *args,int idx) { -pgprot_t prot = protection_map[idx]; +pgprot_t prot =vm_get_page_prot (idx);unsigned long val = idx, *ptr = &val;pud_t pud;
@@ -337,7 +337,7 @@ static void __init pud_basic_tests(struct pgtable_debug_args *args, int idx)/* * This test needs to be executed after the given page table entry -* is created with pfn_pud() to make sure that protection_map[idx] +* is created with pfn_pud() to make sure that vm_get_page_prot(idx) * does not have the dirty bit enabled from the beginning. This is * important for platforms like arm64 where (!PTE_RDONLY) indicate * dirty bit being set.
@@ -1106,14 +1106,14 @@ static int __init init_args(struct pgtable_debug_args *args)/* * Initialize the debugging data. * -* protection_map[0] (or even protection_map[8]) will help create -* page table entries with PROT_NONE permission as required for -* pxx_protnone_tests(). +* vm_get_page_prot(VM_NONE) or vm_get_page_prot(VM_SHARED|VM_NONE) +* will help create page table entries with PROT_NONE permission as +* required for pxx_protnone_tests(). */ memset (args,0 ,sizeof (*args)); args->vaddr =get_random_vaddr (); args->page_prot =vm_get_page_prot (VMFLAGS ); - args->page_prot_none = protection_map[0 ]; + args->page_prot_none =vm_get_page_prot (VM_NONE ); args->is_contiguous_page = false; args->pud_pfn =ULONG_MAX ; args->pmd_pfn =ULONG_MAX ;
@@ -1248,12 +1248,19 @@ static int __init debug_vm_pgtable(void)return ret;/* -* Iterate over the protection_map[] to make sure that all +* Iterate over each possible vm_flags to make sure that all * the basic page table transformation validations just hold * true irrespective of the starting protection value for a * given page table entry. +* +* Protection based vm_flags combinatins are always linear +* and increasing i.e starting from VM_NONE and going upto +* (VM_SHARED | READ | WRITE | EXEC). */ -for (idx =0 ; idx <ARRAY_SIZE (protection_map); idx++) { +#define VM_FLAGS_START (VM_NONE) +#define VM_FLAGS_END (VM_SHARED | VM_EXEC | VM_WRITE | VM_READ) + +for (idx =VM_FLAGS_START ; idx <=VM_FLAGS_END ; idx++) {pte_basic_tests (&args, idx);pmd_basic_tests (&args, idx);pud_basic_tests (&args, idx);
Signature · 1 line
2.25.1
PATCH v3 2/30 mm/mmap: Clarify protection_map[] indices
In reply to Anshuman Khandualprotection_map[] maps vm_flags access combinations into page protection value as defined by the platform via __PXXX and __SXXX macros. The array indices in protection_map[], represents vm_flags access combinations but it's not very intuitive to derive. This makes it clear and explicit.
--- mm/mmap.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
mm/mmap.c +16 -2
@@ -102,8 +102,22 @@ static void unmap_region(struct mm_struct *mm,* x: (yes) yes */ pgprot_t protection_map[16 ]__ro_after_init = { - __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111, - __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111 + [VM_NONE ] = __P000, + [VM_READ ] = __P001, + [VM_WRITE ] = __P010, + [VM_WRITE |VM_READ ] = __P011, + [VM_EXEC ] = __P100, + [VM_EXEC |VM_READ ] = __P101, + [VM_EXEC |VM_WRITE ] = __P110, + [VM_EXEC |VM_WRITE |VM_READ ] = __P111, + [VM_SHARED ] = __S000, + [VM_SHARED |VM_READ ] = __S001, + [VM_SHARED |VM_WRITE ] = __S010, + [VM_SHARED |VM_WRITE |VM_READ ] = __S011, + [VM_SHARED |VM_EXEC ] = __S100, + [VM_SHARED |VM_EXEC |VM_READ ] = __S101, + [VM_SHARED |VM_EXEC |VM_WRITE ] = __S110, + [VM_SHARED |VM_EXEC |VM_WRITE |VM_READ ] = __S111 };#ifndef CONFIG_ARCH_HAS_FILTER_PGPROT
Signature · 1 line
2.25.1
PATCH v3 3/30 mm/mmap: Add new config ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualAdd a new config ARCH_HAS_VM_GET_PAGE_PROT, which when subscribed enables a given platform to define its own vm_get_page_prot(). This framework will help remove protection_map[] dependency going forward.
--- mm/Kconfig | 3 +++ mm/mmap.c | 2 ++ 2 files changed, 5 insertions(+)
mm/Kconfig +3 -0
@@ -747,6 +747,9 @@ config ARCH_HAS_CACHE_LINE_SIZE config ARCH_HAS_FILTER_PGPROT bool +config ARCH_HAS_VM_GET_PAGE_PROT + bool + config ARCH_HAS_PTE_DEVMAP bool
mm/mmap.c +2 -0
@@ -81,6 +81,7 @@ static void unmap_region(struct mm_struct *mm, struct vm_area_struct *vma, struct vm_area_struct *prev, unsigned long start, unsigned long end); +#ifndef CONFIG_ARCH_HAS_VM_GET_PAGE_PROT /* description of effects of mapping type and prot in current implementation. * this is due to the limited x86 page protection hardware. The expected * behavior is in parens:
@@ -136,6 +137,7 @@ pgprot_t vm_get_page_prot(unsigned long vm_flags) return arch_filter_pgprot(ret); }EXPORT_SYMBOL (vm_get_page_prot); +#endif /* CONFIG_ARCH_HAS_VM_GET_PAGE_PROT */ static pgprot_t vm_pgprot_modify (pgprot_t oldprot,unsigned long vm_flags) {
Signature · 1 line
2.25.1
PATCH v3 4/30 powerpc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed. While here, this also localizes arch_vm_get_page_prot() as powerpc_vm_get_page_prot() and moves it near vm_get_page_prot().
--- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/mman.h | 12 ------ arch/powerpc/include/asm/pgtable.h | 19 ---------- arch/powerpc/mm/mmap.c | 59 ++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 31 deletions(-)
arch/powerpc/Kconfig +1 -0
@@ -135,6 +135,7 @@ config PPC select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAS_UACCESS_FLUSHCACHE select ARCH_HAS_UBSAN_SANITIZE_ALL + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_KEEP_MEMBLOCK select ARCH_MIGHT_HAVE_PC_PARPORT
arch/powerpc/include/asm/mman.h +0 -12
@@ -24,18 +24,6 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, }#define arch_calc_vm_prot_bits (prot, pkey) arch_calc_vm_prot_bits(prot, pkey) -static inline pgprot_t arch_vm_get_page_prot (unsigned long vm_flags) -{ -#ifdef CONFIG_PPC_MEM_KEYS -return (vm_flags &VM_SAO ) ? -__pgprot (_PAGE_SAO |vmflag_to_pte_pkey_bits (vm_flags)) : -__pgprot (0 |vmflag_to_pte_pkey_bits (vm_flags)); -#else -return (vm_flags &VM_SAO ) ?__pgprot (_PAGE_SAO) :__pgprot (0 ); -#endif -} -#define arch_vm_get_page_prot (vm_flags) arch_vm_get_page_prot(vm_flags) -static inline bool arch_validate_prot (unsigned long prot,unsigned long addr) {if (prot & ~(PROT_READ |PROT_WRITE |PROT_EXEC |PROT_SEM |PROT_SAO ))
arch/powerpc/include/asm/pgtable.h +0 -19
@@ -20,25 +20,6 @@ struct mm_struct;#include <asm/nohash/pgtable.h> #endif /* !CONFIG_PPC_BOOK3S */ -/* Note due to the way vm flags are laid out, the bits are XWR */ -#define __P000 PAGE_NONE -#define __P001 PAGE_READONLY -#define __P010 PAGE_COPY -#define __P011 PAGE_COPY -#define __P100 PAGE_READONLY_X -#define __P101 PAGE_READONLY_X -#define __P110 PAGE_COPY_X -#define __P111 PAGE_COPY_X - -#define __S000 PAGE_NONE -#define __S001 PAGE_READONLY -#define __S010 PAGE_SHARED -#define __S011 PAGE_SHARED -#define __S100 PAGE_READONLY_X -#define __S101 PAGE_READONLY_X -#define __S110 PAGE_SHARED_X -#define __S111 PAGE_SHARED_X -#ifndef __ASSEMBLY__#ifndef MAX_PTRS_PER_PGD
arch/powerpc/mm/mmap.c +59 -0
62 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH V3 04/30] powerpc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Quoted 11 lines · Anshuman Khandual
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed. While here, this also localizesarch_vm_get_page_prot()aspowerpc_vm_get_page_prot()and moves it nearvm_get_page_prot().Cc Michael Ellerman <[email protected]>Cc Paul Mackerras <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>
Quoted 6 lines
--- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/mman.h | 12 ------ arch/powerpc/include/asm/pgtable.h | 19 ---------- arch/powerpc/mm/mmap.c | 59 ++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 31 deletions(-)
cheers
PATCH v3 5/30 arm64/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed. This also localizes both arch_filter_pgprot and arch_vm_get_page_prot() helpers, unsubscribing from ARCH_HAS_FILTER_PGPROT as well. Moved both these localized functions near vm_get_page_prot().
--- arch/arm64/Kconfig | 2 +- arch/arm64/include/asm/memory.h | 3 +- arch/arm64/include/asm/mman.h | 24 --------- arch/arm64/include/asm/pgtable-prot.h | 18 ------- arch/arm64/include/asm/pgtable.h | 11 ---- arch/arm64/mm/mmap.c | 78 +++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 56 deletions(-)
arch/arm64/Kconfig +1 -1
@@ -23,7 +23,6 @@ config ARM64 select ARCH_HAS_DMA_PREP_COHERENT select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI select ARCH_HAS_FAST_MULTIPLIER - select ARCH_HAS_FILTER_PGPROT select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE
@@ -44,6 +43,7 @@ config ARM64 select ARCH_HAS_SYSCALL_WRAPPER select ARCH_HAS_TEARDOWN_DMA_OPS if IOMMU_SUPPORT select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HAS_ZONE_DMA_SET if EXPERT select ARCH_HAVE_ELF_PROT select ARCH_HAVE_NMI_SAFE_CMPXCHG
arch/arm64/include/asm/memory.h +1 -2
@@ -126,8 +126,7 @@* Memory types available. * * IMPORTANT: MT_NORMAL must be index 0 since vm_get_page_prot() may 'or' in -* the MT_NORMAL_TAGGED memory type for PROT_MTE mappings. Note -* that protection_map[] only contains MT_NORMAL attributes. +* the MT_NORMAL_TAGGED memory type for PROT_MTE mappings. */ #define MT_NORMAL 0#define MT_NORMAL_TAGGED 1
arch/arm64/include/asm/mman.h +0 -24
@@ -35,30 +35,6 @@ static inline unsigned long arch_calc_vm_flag_bits(unsigned long flags) }#define arch_calc_vm_flag_bits (flags) arch_calc_vm_flag_bits(flags) -static inline pgprot_t arch_vm_get_page_prot (unsigned long vm_flags) -{ -pteval_t prot =0 ; - -if (vm_flags &VM_ARM64_BTI ) - prot |=PTE_GP ; - -/* -* There are two conditions required for returning a Normal Tagged -* memory type: (1) the user requested it via PROT_MTE passed to -* mmap() or mprotect() and (2) the corresponding vma supports MTE. We -* register (1) as VM_MTE in the vma->vm_flags and (2) as -* VM_MTE_ALLOWED. Note that the latter can only be set during the -* mmap() call since mprotect() does not accept MAP_* flags. -* Checking for VM_MTE only is sufficient since arch_validate_flags() -* does not permit (VM_MTE & !VM_MTE_ALLOWED). -*/ -if (vm_flags &VM_MTE ) - prot |=PTE_ATTRINDX (MT_NORMAL_TAGGED ); - -return __pgprot (prot); -} -#define arch_vm_get_page_prot (vm_flags) arch_vm_get_page_prot(vm_flags) -static inline bool arch_validate_prot (unsigned long prot,unsigned long addr__always_unused ) {
arch/arm64/include/asm/pgtable-prot.h +0 -18
@@ -88,24 +88,6 @@ extern bool arm64_use_ng_mappings;#define PAGE_READONLY_EXEC __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN)#define PAGE_EXECONLY __pgprot(_PAGE_DEFAULT | PTE_RDONLY | PTE_NG | PTE_PXN) -#define __P000 PAGE_NONE -#define __P001 PAGE_READONLY -#define __P010 PAGE_READONLY -#define __P011 PAGE_READONLY -#define __P100 PAGE_EXECONLY -#define __P101 PAGE_READONLY_EXEC -#define __P110 PAGE_READONLY_EXEC -#define __P111 PAGE_READONLY_EXEC - -#define __S000 PAGE_NONE -#define __S001 PAGE_READONLY -#define __S010 PAGE_SHARED -#define __S011 PAGE_SHARED -#define __S100 PAGE_EXECONLY -#define __S101 PAGE_READONLY_EXEC -#define __S110 PAGE_SHARED_EXEC -#define __S111 PAGE_SHARED_EXEC -#endif /* __ASSEMBLY__ */ #endif /* __ASM_PGTABLE_PROT_H */
arch/arm64/include/asm/pgtable.h +0 -11
@@ -1017,17 +1017,6 @@ static inline bool arch_wants_old_prefaulted_pte(void) }#define arch_wants_old_prefaulted_pte arch_wants_old_prefaulted_pte -static inline pgprot_t arch_filter_pgprot (pgprot_t prot) -{ -if (cpus_have_const_cap (ARM64_HAS_EPAN )) -return prot; - -if (pgprot_val (prot) !=pgprot_val (PAGE_EXECONLY )) -return prot; - -return PAGE_READONLY_EXEC ; -} -static inline bool pud_sect_supported (void ) {return PAGE_SIZE ==SZ_4K ;
arch/arm64/mm/mmap.c +78 -0
87 lines not on this page · raw message
Signature · 1 line
2.25.1
Catalin Marinas
maintainerRe: [PATCH V3 05/30] arm64/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Hi Anshuman,
Quoted 23 lines · Anshuman Khandual
arch/arm64/mm/mmap.c +23
-0+static inline pgprot_t __vm_get_page_prot (unsigned long vm_flags) +{ +switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { +case VM_NONE : +return PAGE_NONE ; +case VM_READ : +case VM_WRITE : +case VM_WRITE |VM_READ : +return PAGE_READONLY ; +case VM_EXEC : +return PAGE_EXECONLY ; +case VM_EXEC |VM_READ : +case VM_EXEC |VM_WRITE : +case VM_EXEC |VM_WRITE |VM_READ : +return PAGE_READONLY_EXEC ; +case VM_SHARED : +return PAGE_NONE ; +case VM_SHARED |VM_READ : +return PAGE_READONLY ; +case VM_SHARED |VM_WRITE : +case VM_SHARED |VM_WRITE |VM_READ : +return PAGE_SHARED ; +case VM_SHARED |VM_EXEC :
arch/arm64/mm/mmap.c int valid_mmap_phys_addr_range(unsigned long pfn, size_t size) · line 75
Quoted 10 lines
arch/arm64/mm/mmap.c +10
-0+return PAGE_EXECONLY ; +case VM_SHARED |VM_EXEC |VM_READ : +return PAGE_READONLY_EXEC ; +case VM_SHARED |VM_EXEC |VM_WRITE : +case VM_SHARED |VM_EXEC |VM_WRITE |VM_READ : +return PAGE_SHARED_EXEC ; +default : +BUILD_BUG (); + } +}
I'd say ack for trying to get of the extra arch_vm_get_page_prot() and arch_filter_pgprot() but, TBH, I'm not so keen on the outcome. I haven't built the code to see what's generated but I suspect it's no significant improvement. As for the code readability, the arm64 parts don't look much better either. The only advantage with this patch is that all functions have been moved under arch/arm64.
I'd keep most architectures that don't have own arch_vm_get_page_prot() or arch_filter_pgprot() unchanged and with a generic protection_map[] array. For architectures that need fancier stuff, add a CONFIG_ARCH_HAS_VM_GET_PAGE_PROT (as you do) and allow them to define vm_get_page_prot() while getting rid of arch_vm_get_page_prot() and arch_filter_pgprot(). I think you could also duplicate protection_map[] for architectures with own vm_get_page_prot() (make it static) and #ifdef it out in mm/mmap.c.
If later you have more complex needs or a switch statement generates better code, go for it, but for this series I'd keep things simple, only focus on getting rid of arch_vm_get_page_prot() and arch_filter_pgprot().
If I grep'ed correctly, there are only 4 architectures that have own arch_vm_get_page_prot() (arm64, powerpc, sparc, x86) and 2 that have own arch_filter_pgprot() (arm64, x86). Try to only change these for the time being, together with the other generic mm cleanups you have in this series. I think there are a couple more that touch protection_map[] (arm, m68k). You can leave the generic protection_map[] global if the arch does not select ARCH_HAS_VM_GET_PAGE_PROT.
Quoted 31 lines
arch/arm64/mm/mmap.c +31
-0+static pgprot_t arm64_arch_filter_pgprot (pgprot_t prot) +{ +if (cpus_have_const_cap (ARM64_HAS_EPAN )) +return prot; + +if (pgprot_val (prot) !=pgprot_val (PAGE_EXECONLY )) +return prot; + +return PAGE_READONLY_EXEC ; +} + +static pgprot_t arm64_arch_vm_get_page_prot (unsigned long vm_flags) +{ +pteval_t prot =0 ; + +if (vm_flags &VM_ARM64_BTI ) + prot |=PTE_GP ; + +/* +* There are two conditions required for returning a Normal Tagged +* memory type: (1) the user requested it via PROT_MTE passed to +* mmap() or mprotect() and (2) the corresponding vma supports MTE. We +* register (1) as VM_MTE in the vma->vm_flags and (2) as +* VM_MTE_ALLOWED. Note that the latter can only be set during the +* mmap() call since mprotect() does not accept MAP_* flags. +* Checking for VM_MTE only is sufficient since arch_validate_flags() +* does not permit (VM_MTE & !VM_MTE_ALLOWED). +*/ +if (vm_flags &VM_MTE ) + prot |=PTE_ATTRINDX (MT_NORMAL_TAGGED ); +
arch/arm64/mm/mmap.c int valid_mmap_phys_addr_range(unsigned long pfn, size_t size) · line 117
Quoted 10 lines
arch/arm64/mm/mmap.c +10
-0+return __pgprot (prot); +} + +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{ +pgprot_t ret =__pgprot (pgprot_val (__vm_get_page_prot (vm_flags)) | +pgprot_val (arm64_arch_vm_get_page_prot (vm_flags))); + +return arm64_arch_filter_pgprot (ret); +}
If we kept the array, we can have everything in a single function (untested and with my own comments for future changes):
pgprot_t vm_get_page_prot(unsigned long vm_flags)
{
pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
(VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]));
/*
* We could get rid of this test if we updated protection_map[]
* to turn exec-only into read-exec during boot.
*/
if (!cpus_have_const_cap(ARM64_HAS_EPAN) &&
pgprot_val(prot) == pgprot_val(PAGE_EXECONLY))
prot = PAGE_READONLY_EXEC;
if (vm_flags & VM_ARM64_BTI)
prot != PTE_GP;
/*
* We can get rid of the requirement for PROT_NORMAL to be 0
* since here we can mask out PTE_ATTRINDX_MASK.
*/
if (vm_flags & VM_MTE) {
prot &= ~PTE_ATTRINDX_MASK;
prot |= PTE_ATTRINDX(MT_NORMAL_TAGGED);
}
return prot;
}Signature · 1 line
Catalin
Re: [PATCH V3 05/30] arm64/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Quoted 35 lines · Catalin Marinas
Hi Anshuman,
Quoted 32 lines · Anshuman Khandual
arch/arm64/mm/mmap.c +32
-0+static inline pgprot_t __vm_get_page_prot (unsigned long vm_flags) +{ +switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { +case VM_NONE : +return PAGE_NONE ; +case VM_READ : +case VM_WRITE : +case VM_WRITE |VM_READ : +return PAGE_READONLY ; +case VM_EXEC : +return PAGE_EXECONLY ; +case VM_EXEC |VM_READ : +case VM_EXEC |VM_WRITE : +case VM_EXEC |VM_WRITE |VM_READ : +return PAGE_READONLY_EXEC ; +case VM_SHARED : +return PAGE_NONE ; +case VM_SHARED |VM_READ : +return PAGE_READONLY ; +case VM_SHARED |VM_WRITE : +case VM_SHARED |VM_WRITE |VM_READ : +return PAGE_SHARED ; +case VM_SHARED |VM_EXEC : +return PAGE_EXECONLY ; +case VM_SHARED |VM_EXEC |VM_READ : +return PAGE_READONLY_EXEC ; +case VM_SHARED |VM_EXEC |VM_WRITE : +case VM_SHARED |VM_EXEC |VM_WRITE |VM_READ : +return PAGE_SHARED_EXEC ; +default : +BUILD_BUG (); + }
Quoted 8 lines
Quoted 1 line
+}
I'd say ack for trying to get of the extra
arch_vm_get_page_prot()andarch_filter_pgprot()but, TBH, I'm not so keen on the outcome. I haven't built the code to see what's generated but I suspect it's no significant improvement. As for the code readability, the arm64 parts don't look much better either. The only advantage with this patch is that all functions have been moved underarch/arm64.
Got it.
Quoted 10 lines
I'd keep most architectures that don't have own
arch_vm_get_page_prot()orarch_filter_pgprot()unchanged and with a generic protection_map[] array. For architectures that need fancier stuff, add aCONFIG_ARCH_HAS_VM_GET_PAGE_PROT(as you do) and allow them to definevm_get_page_prot()while getting rid ofarch_vm_get_page_prot()andarch_filter_pgprot(). I think you could also duplicate protection_map[] for architectures with ownvm_get_page_prot()(make it static) and #ifdef it out inmm/mmap.c.
Quoted 4 lines
If later you have more complex needs or a switch statement generates better code, go for it, but for this series I'd keep things simple, only focus on getting rid of
arch_vm_get_page_prot()andarch_filter_pgprot().
Got it.
Quoted 8 lines
If I grep'ed correctly, there are only 4 architectures that have own
arch_vm_get_page_prot()(arm64, powerpc, sparc, x86) and 2 that have ownarch_filter_pgprot()(arm64, x86). Try to only change these for the time being, together with the other generic mm cleanups you have in this series. I think there are a couple more that touch protection_map[] (arm, m68k). You can leave the generic protection_map[] global if the arch does not selectARCH_HAS_VM_GET_PAGE_PROT.
Okay, I will probably split the series into two parts.
- Drop arch_vm_get_page_prot() and arch_filter_pgprot() on relevant platforms i.e arm64, powerpc, sparc and x86 via this new config ARCH_HAS_VM_GET_PAGE_PROT, keeping the generic protection_map[] since platform __SXXX/__PXX macros would be still around.
- Drop __SXXX/__PXXX across all platforms via just initializing protection_map[] early during boot in the platform OR moving both vm_get_page_prot() via ARCH_HAS_VM_GET_PAGE_PROT and the generic protection_map[] inside the platform.
There were some objections with respect to switch case code in comparison to the array based table look up.
Quoted 37 lines
Quoted 37 lines
arch/arm64/mm/mmap.c +36
-0+static pgprot_t arm64_arch_filter_pgprot (pgprot_t prot) +{ +if (cpus_have_const_cap (ARM64_HAS_EPAN )) +return prot; + +if (pgprot_val (prot) !=pgprot_val (PAGE_EXECONLY )) +return prot; + +return PAGE_READONLY_EXEC ; +} + +static pgprot_t arm64_arch_vm_get_page_prot (unsigned long vm_flags) +{ +pteval_t prot =0 ; + +if (vm_flags &VM_ARM64_BTI ) + prot |=PTE_GP ; + +/* +* There are two conditions required for returning a Normal Tagged +* memory type: (1) the user requested it via PROT_MTE passed to +* mmap() or mprotect() and (2) the corresponding vma supports MTE. We +* register (1) as VM_MTE in the vma->vm_flags and (2) as +* VM_MTE_ALLOWED. Note that the latter can only be set during the +* mmap() call since mprotect() does not accept MAP_* flags. +* Checking for VM_MTE only is sufficient since arch_validate_flags() +* does not permit (VM_MTE & !VM_MTE_ALLOWED). +*/ +if (vm_flags &VM_MTE ) + prot |=PTE_ATTRINDX (MT_NORMAL_TAGGED ); + +return __pgprot (prot); +} + +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{
Quoted 8 lines
arch/arm64/mm/mmap.c int valid_mmap_phys_addr_range(unsigned long pfn, size_t size) · line 117
Quoted 5 lines
arch/arm64/mm/mmap.c +5
-0+pgprot_t ret =__pgprot (pgprot_val (__vm_get_page_prot (vm_flags)) | +pgprot_val (arm64_arch_vm_get_page_prot (vm_flags))); + +return arm64_arch_filter_pgprot (ret); +}If we kept the array, we can have everything in a single function (untested and with my own comments for future changes):
Got it.
Quoted 29 lines
pgprot_tvm_get_page_prot(unsigned long vm_flags){ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)])); /* * We could get rid of this test if we updated protection_map[] * to turn exec-only into read-exec during boot. */ if (!cpus_have_const_cap(ARM64_HAS_EPAN) && pgprot_val(prot) == pgprot_val(PAGE_EXECONLY)) prot = PAGE_READONLY_EXEC; if (vm_flags & VM_ARM64_BTI) prot != PTE_GP; /* * We can get rid of the requirement for PROT_NORMAL to be 0 * since here we can mask out PTE_ATTRINDX_MASK. */ if (vm_flags & VM_MTE) { prot &= ~PTE_ATTRINDX_MASK; prot |= PTE_ATTRINDX(MT_NORMAL_TAGGED); } return prot; }
PATCH v3 6/30 sparc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed. This also localizes the helper arch_vm_get_page_prot() as sparc_vm_get_page_prot() and moves near vm_get_page_prot().
--- arch/sparc/Kconfig | 2 + arch/sparc/include/asm/mman.h | 6 --- arch/sparc/include/asm/pgtable_32.h | 19 -------- arch/sparc/include/asm/pgtable_64.h | 19 -------- arch/sparc/mm/init_32.c | 35 +++++++++++++++ arch/sparc/mm/init_64.c | 70 +++++++++++++++++++++-------- 6 files changed, 88 insertions(+), 63 deletions(-)
arch/sparc/Kconfig +2 -0
@@ -59,6 +59,7 @@ config SPARC32 select HAVE_UID16 select OLD_SIGACTION select ZONE_DMA + select ARCH_HAS_VM_GET_PAGE_PROT config SPARC64 def_bool 64BIT
@@ -84,6 +85,7 @@ config SPARC64 select PERF_USE_VMALLOC select ARCH_HAVE_NMI_SAFE_CMPXCHG select HAVE_C_RECORDMCOUNT + select ARCH_HAS_VM_GET_PAGE_PROT select HAVE_ARCH_AUDITSYSCALL select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_DEBUG_PAGEALLOC
arch/sparc/include/asm/mman.h +0 -6
@@ -46,12 +46,6 @@ static inline unsigned long sparc_calc_vm_prot_bits(unsigned long prot) } } -#define arch_vm_get_page_prot (vm_flags) sparc_vm_get_page_prot(vm_flags) -static inline pgprot_t sparc_vm_get_page_prot (unsigned long vm_flags) -{ -return (vm_flags &VM_SPARC_ADI ) ?__pgprot (_PAGE_MCD_4V) :__pgprot (0 ); -} -#define arch_validate_prot (prot, addr) sparc_validate_prot(prot, addr)static inline int sparc_validate_prot (unsigned long prot,unsigned long addr) {
arch/sparc/include/asm/pgtable_32.h +0 -19
@@ -64,25 +64,6 @@ void paging_init(void);extern unsigned long ptr_in_current_pgd; -/* xwr */ -#define __P000 PAGE_NONE -#define __P001 PAGE_READONLY -#define __P010 PAGE_COPY -#define __P011 PAGE_COPY -#define __P100 PAGE_READONLY -#define __P101 PAGE_READONLY -#define __P110 PAGE_COPY -#define __P111 PAGE_COPY - -#define __S000 PAGE_NONE -#define __S001 PAGE_READONLY -#define __S010 PAGE_SHARED -#define __S011 PAGE_SHARED -#define __S100 PAGE_READONLY -#define __S101 PAGE_READONLY -#define __S110 PAGE_SHARED -#define __S111 PAGE_SHARED -/* First physical page can be anywhere, the following is needed so that * va-->pa and vice versa conversions work properly without performance * hit for all __pa()/__va() operations.
arch/sparc/include/asm/pgtable_64.h +0 -19
@@ -187,25 +187,6 @@ bool kern_addr_valid(unsigned long addr);#define _PAGE_SZHUGE_4U _PAGE_SZ4MB_4U#define _PAGE_SZHUGE_4V _PAGE_SZ4MB_4V -/* These are actually filled in at boot time by sun4{u,v}_pgprot_init() */ -#define __P000 __pgprot(0) -#define __P001 __pgprot(0) -#define __P010 __pgprot(0) -#define __P011 __pgprot(0) -#define __P100 __pgprot(0) -#define __P101 __pgprot(0) -#define __P110 __pgprot(0) -#define __P111 __pgprot(0) - -#define __S000 __pgprot(0) -#define __S001 __pgprot(0) -#define __S010 __pgprot(0) -#define __S011 __pgprot(0) -#define __S100 __pgprot(0) -#define __S101 __pgprot(0) -#define __S110 __pgprot(0) -#define __S111 __pgprot(0) -#ifndef __ASSEMBLY__pte_t mk_pte_io (unsigned long ,pgprot_t ,int ,unsigned long );
arch/sparc/mm/init_32.c +35 -0
@@ -302,3 +302,38 @@ void sparc_flush_page_to_ram(struct page *page)__flush_page_to_ram (vaddr); }EXPORT_SYMBOL (sparc_flush_page_to_ram); + +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{ +switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { +case VM_NONE : +return PAGE_NONE ; +case VM_READ : +return PAGE_READONLY ; +case VM_WRITE : +case VM_WRITE |VM_READ : +return PAGE_COPY ; +case VM_EXEC : +case VM_EXEC |VM_READ : +return PAGE_READONLY ; +case VM_EXEC |VM_WRITE : +case VM_EXEC |VM_WRITE |VM_READ : +return PAGE_COPY ; +case VM_SHARED : +return PAGE_NONE ; +case VM_SHARED |VM_READ : +return PAGE_READONLY ; +case VM_SHARED |VM_WRITE : +case VM_SHARED |VM_WRITE |VM_READ : +return PAGE_SHARED ; +case VM_SHARED |VM_EXEC : +case VM_SHARED |VM_EXEC |VM_READ : +return PAGE_READONLY ; +case VM_SHARED |VM_EXEC |VM_WRITE : +case VM_SHARED |VM_EXEC |VM_WRITE |VM_READ : +return PAGE_SHARED ; +default : +BUILD_BUG (); + } +} +EXPORT_SYMBOL (vm_get_page_prot);
arch/sparc/mm/init_64.c +51 -19
89 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 7/30 mips/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/mips/Kconfig | 1 + arch/mips/include/asm/pgtable.h | 22 ------------ arch/mips/mm/cache.c | 60 +++++++++++++++++++-------------- 3 files changed, 36 insertions(+), 47 deletions(-)
arch/mips/Kconfig +1 -0
@@ -13,6 +13,7 @@ config MIPS select ARCH_HAS_STRNLEN_USER select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAS_UBSAN_SANITIZE_ALL + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_KEEP_MEMBLOCK select ARCH_SUPPORTS_UPROBES
arch/mips/include/asm/pgtable.h +0 -22
@@ -41,28 +41,6 @@ struct vm_area_struct;* by reasonable means.. */ -/* -* Dummy values to fill the table in mmap.c -* The real values will be generated at runtime -*/ -#define __P000 __pgprot(0) -#define __P001 __pgprot(0) -#define __P010 __pgprot(0) -#define __P011 __pgprot(0) -#define __P100 __pgprot(0) -#define __P101 __pgprot(0) -#define __P110 __pgprot(0) -#define __P111 __pgprot(0) - -#define __S000 __pgprot(0) -#define __S001 __pgprot(0) -#define __S010 __pgprot(0) -#define __S011 __pgprot(0) -#define __S100 __pgprot(0) -#define __S101 __pgprot(0) -#define __S110 __pgprot(0) -#define __S111 __pgprot(0) -extern unsigned long _page_cachable_default;extern void __update_cache (unsigned long address,pte_t pte);
arch/mips/mm/cache.c +35 -25
71 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 8/30 m68k/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/m68k/Kconfig | 1 + arch/m68k/include/asm/mcf_pgtable.h | 59 ------------------------ arch/m68k/include/asm/motorola_pgtable.h | 29 ------------ arch/m68k/include/asm/sun3_pgtable.h | 22 --------- arch/m68k/mm/mcfmmu.c | 59 ++++++++++++++++++++++++ arch/m68k/mm/motorola.c | 43 +++++++++++++++-- arch/m68k/mm/sun3mmu.c | 39 ++++++++++++++++ 7 files changed, 139 insertions(+), 113 deletions(-)
arch/m68k/Kconfig +1 -0
@@ -11,6 +11,7 @@ config M68K select ARCH_NO_PREEMPT if !COLDFIRE select ARCH_USE_MEMTEST if MMU_MOTOROLA select ARCH_WANT_IPC_PARSE_VERSION + select ARCH_HAS_VM_GET_PAGE_PROT select BINFMT_FLAT_ARGVP_ENVP_ON_STACK select DMA_DIRECT_REMAP if HAS_DMA && MMU && !COLDFIRE select GENERIC_ATOMIC64
arch/m68k/include/asm/mcf_pgtable.h +0 -59
65 lines not on this page · raw message
arch/m68k/include/asm/motorola_pgtable.h +0 -29
@@ -76,35 +76,6 @@ extern unsigned long mm_cachebits;#define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_RONLY | _PAGE_ACCESSED | mm_cachebits)#define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_DIRTY | _PAGE_ACCESSED | mm_cachebits) -/* Alternate definitions that are compile time constants, for -initializing protection_map. The cachebits are fixed later. */ -#define PAGE_NONE_C __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED) -#define PAGE_SHARED_C __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED) -#define PAGE_COPY_C __pgprot(_PAGE_PRESENT | _PAGE_RONLY | _PAGE_ACCESSED) -#define PAGE_READONLY_C __pgprot(_PAGE_PRESENT | _PAGE_RONLY | _PAGE_ACCESSED) - -/* -* The m68k can't do page protection for execute, and considers that the same are read. -* Also, write permissions imply read permissions. This is the closest we can get.. -*/ -#define __P000 PAGE_NONE_C -#define __P001 PAGE_READONLY_C -#define __P010 PAGE_COPY_C -#define __P011 PAGE_COPY_C -#define __P100 PAGE_READONLY_C -#define __P101 PAGE_READONLY_C -#define __P110 PAGE_COPY_C -#define __P111 PAGE_COPY_C - -#define __S000 PAGE_NONE_C -#define __S001 PAGE_READONLY_C -#define __S010 PAGE_SHARED_C -#define __S011 PAGE_SHARED_C -#define __S100 PAGE_READONLY_C -#define __S101 PAGE_READONLY_C -#define __S110 PAGE_SHARED_C -#define __S111 PAGE_SHARED_C -#define pmd_pgtable (pmd) ((pgtable_t)pmd_page_vaddr(pmd))/*
arch/m68k/include/asm/sun3_pgtable.h +0 -22
@@ -66,28 +66,6 @@ | SUN3_PAGE_SYSTEM \ | SUN3_PAGE_NOCACHE) -/* -* Page protections for initialising protection_map. The sun3 has only two -* protection settings, valid (implying read and execute) and writeable. These -* are as close as we can get... -*/ -#define __P000 PAGE_NONE -#define __P001 PAGE_READONLY -#define __P010 PAGE_COPY -#define __P011 PAGE_COPY -#define __P100 PAGE_READONLY -#define __P101 PAGE_READONLY -#define __P110 PAGE_COPY -#define __P111 PAGE_COPY - -#define __S000 PAGE_NONE -#define __S001 PAGE_READONLY -#define __S010 PAGE_SHARED -#define __S011 PAGE_SHARED -#define __S100 PAGE_READONLY -#define __S101 PAGE_READONLY -#define __S110 PAGE_SHARED -#define __S111 PAGE_SHARED/* Use these fake page-protections on PMDs. */ #define SUN3_PMD_VALID (0x00000001)
arch/m68k/mm/mcfmmu.c +59 -0
62 lines not on this page · raw message
arch/m68k/mm/motorola.c +40 -3
55 lines not on this page · raw message
arch/m68k/mm/sun3mmu.c +39 -0
@@ -95,3 +95,42 @@ void __init paging_init(void) } + +/* +* The sun3 has only two protection settings, valid (implying read and execute) +* and writeable. These are as close as we can get... +*/ +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{ +switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { +case VM_NONE : +return PAGE_NONE ; +case VM_READ : +return PAGE_READONLY ; +case VM_WRITE : +case VM_WRITE |VM_READ : +return PAGE_COPY ; +case VM_EXEC : +case VM_EXEC |VM_READ : +return PAGE_READONLY ; +case VM_EXEC |VM_WRITE : +case VM_EXEC |VM_WRITE |VM_READ : +return PAGE_COPY ; +case VM_SHARED : +return PAGE_NONE ; +case VM_SHARED |VM_READ : +return PAGE_READONLY ; +case VM_SHARED |VM_WRITE : +case VM_SHARED |VM_WRITE |VM_READ : +return PAGE_SHARED ; +case VM_SHARED |VM_EXEC : +case VM_SHARED |VM_EXEC |VM_READ : +return PAGE_READONLY ; +case VM_SHARED |VM_EXEC |VM_WRITE : +case VM_SHARED |VM_EXEC |VM_WRITE |VM_READ : +return PAGE_SHARED ; +default : +BUILD_BUG (); + } +} +EXPORT_SYMBOL (vm_get_page_prot);
Signature · 1 line
2.25.1
PATCH v3 9/30 arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/arm/Kconfig | 1 + arch/arm/include/asm/pgtable.h | 20 +------------- arch/arm/lib/uaccess_with_memcpy.c | 2 +- arch/arm/mm/mmu.c | 44 ++++++++++++++++++++++++++---- 4 files changed, 41 insertions(+), 26 deletions(-)
arch/arm/Kconfig +1 -0
@@ -23,6 +23,7 @@ config ARM select ARCH_HAS_SYNC_DMA_FOR_CPU if SWIOTLB || !MMU select ARCH_HAS_TEARDOWN_DMA_OPS if MMU select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HAVE_CUSTOM_GPIO_H select ARCH_HAVE_NMI_SAFE_CMPXCHG if CPU_V7 || CPU_V7M || CPU_V6K select ARCH_HAS_GCOV_PROFILE_ALL
arch/arm/include/asm/pgtable.h +1 -19
@@ -70,7 +70,7 @@ extern void __pgd_error(const char *file, int line, pgd_t);#endif /* -* The pgprot_* and protection_map entries will be fixed up in runtime +* The pgprot_* entries will be fixed up in runtime in vm_get_page_prot() * to include the cachable and bufferable bits based on memory policy, * as well as any architecture dependent bits like global/ASID and SMP * shared mapping bits.
@@ -137,24 +137,6 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,* 2) If we could do execute protection, then read is implied * 3) write implies read permissions */ -#define __P000 __PAGE_NONE -#define __P001 __PAGE_READONLY -#define __P010 __PAGE_COPY -#define __P011 __PAGE_COPY -#define __P100 __PAGE_READONLY_EXEC -#define __P101 __PAGE_READONLY_EXEC -#define __P110 __PAGE_COPY_EXEC -#define __P111 __PAGE_COPY_EXEC - -#define __S000 __PAGE_NONE -#define __S001 __PAGE_READONLY -#define __S010 __PAGE_SHARED -#define __S011 __PAGE_SHARED -#define __S100 __PAGE_READONLY_EXEC -#define __S101 __PAGE_READONLY_EXEC -#define __S110 __PAGE_SHARED_EXEC -#define __S111 __PAGE_SHARED_EXEC -#ifndef __ASSEMBLY__/* * ZERO_PAGE is a global shared page that is always zero: used
arch/arm/lib/uaccess_with_memcpy.c +1 -1
@@ -247,7 +247,7 @@ static int __init test_size_treshold(void)if (!dst_page) goto no_dst; kernel_ptr =page_address (src_page); - user_ptr =vmap (&dst_page,1 ,VM_IOREMAP ,__pgprot (__P010)); + user_ptr =vmap (&dst_page,1 ,VM_IOREMAP ,__pgprot (__PAGE_COPY));if (!user_ptr) goto no_vmap;
arch/arm/mm/mmu.c +38 -6
68 lines not on this page · raw message
Signature · 1 line
2.25.1
Russell King (Oracle)
maintainerRe: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Quoted 3 lines · Anshuman Khandual
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.
What I would really like to know is why having to run _code_ to work out what the page protections need to be is better than looking it up in a table.
Not only is this more expensive in terms of CPU cycles, it also brings additional code size with it.
I'm struggling to see what the benefit is.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Geert Uytterhoeven
maintainerRe: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Hi Russell,
Quoted 5 lines · Russell King (Oracle)
Quoted 3 lines · Anshuman Khandual
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.
Quoted 8 lines
What I would really like to know is why having to run _code_ to work out what the page protections need to be is better than looking it up in a table.
Not only is this more expensive in terms of CPU cycles, it also brings additional code size with it.
I'm struggling to see what the benefit is.
I was wondering about that as well. But at least for code size on m68k, this didn't have much impact. Looking at the generated code, the increase due to using code for the (few different) cases is offset by a 16-bit jump table (which is to be credited to the compiler).
In terms of CPU cycles, it's indeed worse than before.
Gr{oetje,eeting}s,
Geert
Re: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Russell King (Oracle)Quoted 5 lines · Russell King (Oracle)
Quoted 3 lines · Anshuman Khandual
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.
Quoted 9 lines
What I would really like to know is why having to run _code_ to work out what the page protections need to be is better than looking it up in a table.
Not only is this more expensive in terms of CPU cycles, it also brings additional code size with it.
I'm struggling to see what the benefit is.
Currently vm_get_page_prot() is also being _run_ to fetch required page protection values. Although that is being run in the core MM and from a platform perspective __SXXX, __PXXX are just being exported for a table. Looking it up in a table (and applying more constructs there after) is not much different than a clean switch case statement in terms of CPU usage. So this is not more expensive in terms of CPU cycles.
--------------------------
pgprot_t protection_map[16] __ro_after_init = {
__P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
__S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
};#ifndef CONFIG_ARCH_HAS_FILTER_PGPROT
static inline pgprot_t arch_filter_pgprot(pgprot_t prot)
{
return prot;
}#endif
pgprot_t vm_get_page_prot(unsigned long vm_flags)
{
pgprot_t ret = __pgprot(pgprot_val(protection_map[vm_flags &
(VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
pgprot_val(arch_vm_get_page_prot(vm_flags)));
return arch_filter_pgprot(ret);
}EXPORT_SYMBOL(vm_get_page_prot)
----------------------------
There will be a single vm_get_page_prot() instance on a given platform just like before. So this also does not bring any additional code size with it.
As mentioned earlier on a previous version.
Remove multiple 'core MM <--> platform' abstraction layers to map vm_flags access permission combination into page protection.
From the cover letter ......
----------
Currently there are multiple layers of abstraction i.e __SXXX/__PXXX macros , protection_map[], arch_vm_get_page_prot() and arch_filter_pgprot() built between the platform and generic MM, finally defining vm_get_page_prot().
Hence this series proposes to drop all these abstraction levels and instead just move the responsibility of defining vm_get_page_prot() to the platform itself making it clean and simple.
----------
Benefits
1. For platforms using arch_vm_get_page_prot() and/or arch_filter_pgprot()
- A simplified vm_get_page_prot()
- Dropped arch_vm_get_page_prot() and arch_filter_pgprot()
- Dropped __SXXX, __PXXX macros
2. For platforms which just exported __SXXX, __PXXX
- A simplified vm_get_page_prot()
- Dropped __SXXX, __PXXX macros
3. For core MM
- Dropped a complex vm_get_page_prot() with multiple layers of abstraction i.e __SXXX/__PXXX macros, protection_map[], arch_vm_get_page_prot(), arch_filter_pgprot() etc.
- Anshuman
Russell King (Oracle)
maintainerRe: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Quoted 13 lines · Anshuman Khandual
Quoted 12 lines · Russell King (Oracle)
Quoted 3 lines · Anshuman Khandual
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.What I would really like to know is why having to run _code_ to work out what the page protections need to be is better than looking it up in a table.
Not only is this more expensive in terms of CPU cycles, it also brings additional code size with it.
Quoted 8 lines
Quoted 1 line
I'm struggling to see what the benefit is.
Currently
vm_get_page_prot()is also being _run_ to fetch required page protection values. Although that is being run in the core MM and from a platform perspective__SXXX,__PXXXare just being exported for a table. Looking it up in a table (and applying more constructs there after) is not much different than a clean switch case statement in terms of CPU usage. So this is not more expensive in terms of CPU cycles.
I disagree.
However, let's base this disagreement on some evidence. Here is the present 32-bit ARM implementation:
00000048 <vm_get_page_prot>:
48: e200000f and r0, r0, #15
4c: e3003000 movw r3, #0 4c: R_ARM_MOVW_ABS_NC .LANCHOR1
50: e3403000 movt r3, #0
50: R_ARM_MOVT_ABS .LANCHOR1
54: e7930100 ldr r0, [r3, r0, lsl #2]
58: e12fff1e bx lr
That is five instructions long.
Please show that your new implementation is not more expensive on 32-bit ARM. Please do so by building a 32-bit kernel, and providing the disassembly.
I think you will find way more than five instructions in your version - the compiler will have to issue code to decode the protection bits, probably using a table of branches or absolute PC values, or possibly the worst case of using multiple comparisons and branches. It then has to load constants that may be moved using movw on ARMv7, but on older architectures would have to be created from multiple instructions or loaded from the literal pool. Then there'll be instructions to load the address of "user_pgprot", retrieve its value, and bitwise or that.
Therefore, I fail to see how your approach of getting rid of the table is somehow "better" than what we currently have in terms of the effect on the resulting code.
If you don't like the __P and __S stuff and two arch_* hooks, you could move the table into arch code along with vm_get_page_prot() without the additional unnecessary hooks, while keeping all the benefits of the table lookup.
Thanks.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Le 01/03/2022 à 01:31, Russell King (Oracle) a écrit :
Quoted 16 lines · Anshuman Khandual
Quoted 15 lines · Russell King (Oracle)
Quoted 13 lines · Anshuman Khandual
Quoted 3 lines
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.What I would really like to know is why having to run _code_ to work out what the page protections need to be is better than looking it up in a table.
Not only is this more expensive in terms of CPU cycles, it also brings additional code size with it.
I'm struggling to see what the benefit is.
Quoted 8 lines
Quoted 6 lines
Currently
vm_get_page_prot()is also being _run_ to fetch required page protection values. Although that is being run in the core MM and from a platform perspective__SXXX,__PXXXare just being exported for a table. Looking it up in a table (and applying more constructs there after) is not much different than a clean switch case statement in terms of CPU usage. So this is not more expensive in terms of CPU cycles.I disagree.
So do I.
Quoted 7 lines
However, let's base this disagreement on some evidence. Here is the present 32-bit ARM implementation:
00000048 <
vm_get_page_prot>:48: e200000f and r0, r0, #15 4c: e3003000 movw r3, #0
Quoted 7 lines
4c:
R_ARM_MOVW_ABS_NC.LANCHOR1
50:e3403000movt r3, #0
50:R_ARM_MOVT_ABS.LANCHOR1
54:e7930100ldr r0, [r3, r0, lsl #2]
58:e12fff1ebx lrThat is five instructions long.
On ppc32 I get:
00000094 <vm_get_page_prot>:
94: 3d 20 00 00 lis r9,0
96: R_PPC_ADDR16_HA .data..ro_after_init
98: 54 84 16 ba rlwinm r4,r4,2,26,29
9c: 39 29 00 00 addi r9,r9,0
9e: R_PPC_ADDR16_LO .data..ro_after_init
a0: 7d 29 20 2e lwzx r9,r9,r4
a4: 91 23 00 00 stw r9,0(r3)
a8: 4e 80 00 20 blrQuoted 4 lines
Please show that your new implementation is not more expensive on 32-bit ARM. Please do so by building a 32-bit kernel, and providing the disassembly.
With your series I get:
00000000 <vm_get_page_prot>:
0: 3d 20 00 00 lis r9,0
2: R_PPC_ADDR16_HA .rodata
4: 39 29 00 00 addi r9,r9,0
6: R_PPC_ADDR16_LO .rodata
8: 54 84 16 ba rlwinm r4,r4,2,26,29
c: 7d 49 20 2e lwzx r10,r9,r4 10: 7d 4a 4a 14 add r10,r10,r9
14: 7d 49 03 a6 mtctr r10
18: 4e 80 04 20 bctr
1c: 39 20 03 15 li r9,789
20: 91 23 00 00 stw r9,0(r3)
24: 4e 80 00 20 blr
28: 39 20 01 15 li r9,277
2c: 91 23 00 00 stw r9,0(r3)
30: 4e 80 00 20 blr
34: 39 20 07 15 li r9,1813
38: 91 23 00 00 stw r9,0(r3)
3c: 4e 80 00 20 blr
40: 39 20 05 15 li r9,1301
44: 91 23 00 00 stw r9,0(r3)
48: 4e 80 00 20 blr
4c: 39 20 01 11 li r9,273
50: 4b ff ff d0 b 20 <vm_get_page_prot+0x20>
That is definitely more expensive, it implements a table of branches.
Christophe
Re: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Quoted 91 lines · Christophe Leroy
Le 01/03/2022 à 01:31, Russell King (Oracle) a écrit :
Quoted 16 lines · Anshuman Khandual
Quoted 15 lines · Russell King (Oracle)
Quoted 13 lines · Anshuman Khandual
Quoted 3 lines
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.What I would really like to know is why having to run _code_ to work out what the page protections need to be is better than looking it up in a table.
Not only is this more expensive in terms of CPU cycles, it also brings additional code size with it.
I'm struggling to see what the benefit is.
Quoted 8 lines
Quoted 6 lines
Currently
vm_get_page_prot()is also being _run_ to fetch required page protection values. Although that is being run in the core MM and from a platform perspective__SXXX,__PXXXare just being exported for a table. Looking it up in a table (and applying more constructs there after) is not much different than a clean switch case statement in terms of CPU usage. So this is not more expensive in terms of CPU cycles.I disagree.
So do I.
Quoted 7 lines
However, let's base this disagreement on some evidence. Here is the present 32-bit ARM implementation:
00000048 <
vm_get_page_prot>:48: e200000f and r0, r0, #15 4c: e3003000 movw r3, #0Quoted 7 lines
4c:
R_ARM_MOVW_ABS_NC.LANCHOR1
50:e3403000movt r3, #0
50:R_ARM_MOVT_ABS.LANCHOR1
54:e7930100ldr r0, [r3, r0, lsl #2]
58:e12fff1ebx lrThat is five instructions long.
On ppc32 I get:
00000094 <
vm_get_page_prot>:94: 3d 20 00 00 lis r9,0 96: R_PPC_ADDR16_HA .data..ro_after_init 98: 54 84 16 ba rlwinm r4,r4,2,26,29 9c: 39 29 00 00 addi r9,r9,0 9e: R_PPC_ADDR16_LO .data..ro_after_init a0: 7d 29 20 2e lwzx r9,r9,r4 a4: 91 23 00 00 stw r9,0(r3) a8: 4e 80 00 20 blrQuoted 4 lines
Please show that your new implementation is not more expensive on 32-bit ARM. Please do so by building a 32-bit kernel, and providing the disassembly.
With your series I get:
00000000 <
vm_get_page_prot>:0: 3d 20 00 00 lis r9,0 2: R_PPC_ADDR16_HA .rodata 4: 39 29 00 00 addi r9,r9,0 6: R_PPC_ADDR16_LO .rodata 8: 54 84 16 ba rlwinm r4,r4,2,26,29 c: 7d 49 20 2e lwzx r10,r9,r410: 7d 4a 4a 14 add r10,r10,r9
14: 7d 49 03 a6 mtctr r10
18: 4e 80 04 20 bctr
1c: 39 20 03 15 li r9,789
20: 91 23 00 00 stw r9,0(r3)
24: 4e 80 00 20 blr
28: 39 20 01 15 li r9,277
2c: 91 23 00 00 stw r9,0(r3)
30: 4e 80 00 20 blr
34: 39 20 07 15 li r9,1813
38: 91 23 00 00 stw r9,0(r3)
3c: 4e 80 00 20 blr
40: 39 20 05 15 li r9,1301
44: 91 23 00 00 stw r9,0(r3)
48: 4e 80 00 20 blr
4c: 39 20 01 11 li r9,273
50: 4b ff ff d0 b 20 <vm_get_page_prot+0x20>
Quoted 1 line
That is definitely more expensive, it implements a table of branches.
Okay, will split out the PPC32 implementation that retains existing table look up method. Also planning to keep that inside same file (arch/powerpc/mm/mmap.c), unless you have a difference preference.
Re: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Le 02/03/2022 à 04:22, Anshuman Khandual a écrit :
Quoted 94 lines · Christophe Leroy
Quoted 91 lines
Le 01/03/2022 à 01:31, Russell King (Oracle) a écrit :
Quoted 16 lines · Anshuman Khandual
Quoted 15 lines · Russell King (Oracle)
Quoted 13 lines · Anshuman Khandual
Quoted 3 lines
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.What I would really like to know is why having to run _code_ to work out what the page protections need to be is better than looking it up in a table.
Not only is this more expensive in terms of CPU cycles, it also brings additional code size with it.
I'm struggling to see what the benefit is.
Quoted 8 lines
Quoted 6 lines
Currently
vm_get_page_prot()is also being _run_ to fetch required page protection values. Although that is being run in the core MM and from a platform perspective__SXXX,__PXXXare just being exported for a table. Looking it up in a table (and applying more constructs there after) is not much different than a clean switch case statement in terms of CPU usage. So this is not more expensive in terms of CPU cycles.I disagree.
So do I.
Quoted 7 lines
However, let's base this disagreement on some evidence. Here is the present 32-bit ARM implementation:
00000048 <
vm_get_page_prot>:48: e200000f and r0, r0, #15 4c: e3003000 movw r3, #0Quoted 7 lines
4c:
R_ARM_MOVW_ABS_NC.LANCHOR1
50:e3403000movt r3, #0
50:R_ARM_MOVT_ABS.LANCHOR1
54:e7930100ldr r0, [r3, r0, lsl #2]
58:e12fff1ebx lrThat is five instructions long.
On ppc32 I get:
00000094 <
vm_get_page_prot>:94: 3d 20 00 00 lis r9,0 96: R_PPC_ADDR16_HA .data..ro_after_init 98: 54 84 16 ba rlwinm r4,r4,2,26,29 9c: 39 29 00 00 addi r9,r9,0 9e: R_PPC_ADDR16_LO .data..ro_after_init a0: 7d 29 20 2e lwzx r9,r9,r4 a4: 91 23 00 00 stw r9,0(r3) a8: 4e 80 00 20 blrQuoted 4 lines
Please show that your new implementation is not more expensive on 32-bit ARM. Please do so by building a 32-bit kernel, and providing the disassembly.
With your series I get:
00000000 <
vm_get_page_prot>:0: 3d 20 00 00 lis r9,0 2: R_PPC_ADDR16_HA .rodata 4: 39 29 00 00 addi r9,r9,0 6: R_PPC_ADDR16_LO .rodata 8: 54 84 16 ba rlwinm r4,r4,2,26,29 c: 7d 49 20 2e lwzx r10,r9,r4 10: 7d 4a 4a 14 add r10,r10,r9 14: 7d 49 03 a6 mtctr r10 18: 4e 80 04 20 bctr 1c: 39 20 03 15 li r9,789 20: 91 23 00 00 stw r9,0(r3) 24: 4e 80 00 20 blr 28: 39 20 01 15 li r9,277 2c: 91 23 00 00 stw r9,0(r3) 30: 4e 80 00 20 blr 34: 39 20 07 15 li r9,1813 38: 91 23 00 00 stw r9,0(r3) 3c: 4e 80 00 20 blr 40: 39 20 05 15 li r9,1301 44: 91 23 00 00 stw r9,0(r3) 48: 4e 80 00 20 blr 4c: 39 20 01 11 li r9,273 50: 4b ff ff d0 b 20 <vm_get_page_prot+0x20>
Quoted 5 lines
Quoted 1 line
That is definitely more expensive, it implements a table of branches.
Okay, will split out the PPC32 implementation that retains existing table look up method. Also planning to keep that inside same file (
arch/powerpc/mm/mmap.c), unless you have a difference preference.
My point was not to get something specific for PPC32, but to amplify on Russell's objection.
As this is bad for ARM and bad for PPC32, do we have any evidence that your change is good for any other architecture ?
I checked PPC64 and there is exactly the same drawback. With the current implementation it is a small function performing table read then a few adjustment. After your change it is a bigger function implementing a table of branches.
So, as requested by Russell, could you look at the disassembly for other architectures and show us that ARM and POWERPC are the only ones for which your change is not optimal ?
See below the difference for POWERPC64.
Current implementation:
0000000000000a60 <.vm_get_page_prot>:
a60: 3d 42 00 00 addis r10,r2,0
a62: R_PPC64_TOC16_HA .data..ro_after_init
a64: 78 89 1e 68 rldic r9,r4,3,57
a68: 39 4a 00 00 addi r10,r10,0
a6a: R_PPC64_TOC16_LO .data..ro_after_init
a6c: 74 88 01 00 andis. r8,r4,256
a70: 7d 2a 48 2a ldx r9,r10,r9
a74: 41 82 00 1c beq a90 <.vm_get_page_prot+0x30>
a78: 60 00 00 00 nop
a7c: 60 00 00 00 nop
a80: 48 00 00 18 b a98 <.vm_get_page_prot+0x38>
a84: 60 00 00 00 nop
a88: 60 00 00 00 nop
a8c: 60 00 00 00 nop
a90: 60 00 00 00 nop
a94: 60 00 00 00 nop
a98: 0f e0 00 00 twui r0,0
a9c: 60 00 00 00 nop
aa0: 38 80 00 10 li r4,16
aa4: 7d 29 23 78 or r9,r9,r4
aa8: f9 23 00 00 std r9,0(r3)
aac: 4e 80 00 20 blr
ab0: 78 84 d9 04 rldicr r4,r4,27,4
ab4: 78 84 e8 c2 rldicl r4,r4,61,3
ab8: 60 84 00 10 ori r4,r4,16
abc: 4b ff ff e8 b aa4 <.vm_get_page_prot+0x44>
ac0: 78 84 d9 04 rldicr r4,r4,27,4
ac4: 78 84 e8 c2 rldicl r4,r4,61,3
ac8: 4b ff ff dc b aa4 <.vm_get_page_prot+0x44>With your series:
00000000000005b0 <.vm_get_page_prot>:
5b0: 3d 22 00 00 addis r9,r2,0
5b2: R_PPC64_TOC16_HA .toc+0x10 5b4: e9 49 00 00 ld r10,0(r9) 5b6: R_PPC64_TOC16_LO_DS .toc+0x10 5b8: 78 89 16 a8 rldic r9,r4,2,58 5bc: 7d 2a 4a aa lwax r9,r10,r9 5c0: 7d 29 52 14 add r9,r9,r10 5c4: 7d 29 03 a6 mtctr r9 5c8: 3d 20 80 00 lis r9,-32768 5cc: 79 29 07 c6 rldicr r9,r9,32,31 5d0: 4e 80 04 20 bctr 5d4: 00 00 00 ec .long 0xec 5d8: 00 00 00 6c .long 0x6c 5dc: 00 00 00 6c .long 0x6c 5e0: 00 00 00 6c .long 0x6c 5e4: 00 00 00 4c .long 0x4c 5e8: 00 00 00 4c .long 0x4c 5ec: 00 00 00 4c .long 0x4c 5f0: 00 00 00 4c .long 0x4c 5f4: 00 00 00 ec .long 0xec 5f8: 00 00 00 6c .long 0x6c 5fc: 00 00 00 cc .long 0xcc 600: 00 00 00 cc .long 0xcc 604: 00 00 00 4c .long 0x4c 608: 00 00 00 4c .long 0x4c 60c: 00 00 00 dc .long 0xdc 610: 00 00 00 dc .long 0xdc 614: 60 00 00 00 nop 618: 60 00 00 00 nop 61c: 60 00 00 00 nop 620: 61 29 01 05 ori r9,r9,261 624: 74 8a 01 00 andis. r10,r4,256 628: 41 82 00 24 beq 64c <.vm_get_page_prot+0x9c> 62c: 60 00 00 00 nop 630: 60 00 00 00 nop 634: 0f e0 00 00 twui r0,0 638: 60 00 00 00 nop 63c: 60 00 00 00 nop 640: 74 8a 01 00 andis. r10,r4,256 644: 61 29 01 04 ori r9,r9,260 648: 40 82 ff e4 bne 62c <.vm_get_page_prot+0x7c> 64c: 60 00 00 00 nop 650: 60 00 00 00 nop 654: 4b ff ff e0 b 634 <.vm_get_page_prot+0x84> 658: 60 00 00 00 nop 65c: 60 00 00 00 nop 660: 78 84 d9 04 rldicr r4,r4,27,4 664: 78 84 e8 c2 rldicl r4,r4,61,3 668: 7d 29 23 78 or r9,r9,r4 66c: f9 23 00 00 std r9,0(r3) 670: 4e 80 00 20 blr 674: 60 00 00 00 nop 678: 60 00 00 00 nop 67c: 60 00 00 00 nop 680: 38 80 00 10 li r4,16 684: 4b ff ff e4 b 668 <.vm_get_page_prot+0xb8> 688: 60 00 00 00 nop 68c: 60 00 00 00 nop 690: 78 84 d9 04 rldicr r4,r4,27,4 694: 78 84 e8 c2 rldicl r4,r4,61,3 698: 60 84 00 10 ori r4,r4,16 69c: 4b ff ff cc b 668 <.vm_get_page_prot+0xb8> 6a0: 61 29 01 06 ori r9,r9,262 6a4: 4b ff ff 80 b 624 <.vm_get_page_prot+0x74>
6a8: 60 00 00 00 nop
6ac: 60 00 00 00 nop
6b0: 61 29 01 07 ori r9,r9,263
6b4: 4b ff ff 70 b 624 <.vm_get_page_prot+0x74>
6b8: 60 00 00 00 nop
6bc: 60 00 00 00 nop
6c0: 61 29 01 08 ori r9,r9,264
6c4: 4b ff ff 60 b 624 <.vm_get_page_prot+0x74>
Thanks
Christophe
Re: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Quoted 106 lines · Christophe Leroy
Le 02/03/2022 à 04:22, Anshuman Khandual a écrit :
Quoted 94 lines · Christophe Leroy
Quoted 91 lines
Le 01/03/2022 à 01:31, Russell King (Oracle) a écrit :
Quoted 16 lines · Anshuman Khandual
Quoted 15 lines · Russell King (Oracle)
Quoted 13 lines · Anshuman Khandual
Quoted 3 lines
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.What I would really like to know is why having to run _code_ to work out what the page protections need to be is better than looking it up in a table.
Not only is this more expensive in terms of CPU cycles, it also brings additional code size with it.
I'm struggling to see what the benefit is.
Quoted 8 lines
Quoted 6 lines
Currently
vm_get_page_prot()is also being _run_ to fetch required page protection values. Although that is being run in the core MM and from a platform perspective__SXXX,__PXXXare just being exported for a table. Looking it up in a table (and applying more constructs there after) is not much different than a clean switch case statement in terms of CPU usage. So this is not more expensive in terms of CPU cycles.I disagree.
So do I.
Quoted 7 lines
However, let's base this disagreement on some evidence. Here is the present 32-bit ARM implementation:
00000048 <
vm_get_page_prot>:48: e200000f and r0, r0, #15 4c: e3003000 movw r3, #0Quoted 7 lines
4c:
R_ARM_MOVW_ABS_NC.LANCHOR1
50:e3403000movt r3, #0
50:R_ARM_MOVT_ABS.LANCHOR1
54:e7930100ldr r0, [r3, r0, lsl #2]
58:e12fff1ebx lrThat is five instructions long.
On ppc32 I get:
00000094 <
vm_get_page_prot>:94: 3d 20 00 00 lis r9,0 96: R_PPC_ADDR16_HA .data..ro_after_init 98: 54 84 16 ba rlwinm r4,r4,2,26,29 9c: 39 29 00 00 addi r9,r9,0 9e: R_PPC_ADDR16_LO .data..ro_after_init a0: 7d 29 20 2e lwzx r9,r9,r4 a4: 91 23 00 00 stw r9,0(r3) a8: 4e 80 00 20 blrQuoted 4 lines
Please show that your new implementation is not more expensive on 32-bit ARM. Please do so by building a 32-bit kernel, and providing the disassembly.
With your series I get:
00000000 <
vm_get_page_prot>:0: 3d 20 00 00 lis r9,0 2: R_PPC_ADDR16_HA .rodata 4: 39 29 00 00 addi r9,r9,0 6: R_PPC_ADDR16_LO .rodata 8: 54 84 16 ba rlwinm r4,r4,2,26,29 c: 7d 49 20 2e lwzx r10,r9,r4 10: 7d 4a 4a 14 add r10,r10,r9 14: 7d 49 03 a6 mtctr r10 18: 4e 80 04 20 bctr 1c: 39 20 03 15 li r9,789 20: 91 23 00 00 stw r9,0(r3) 24: 4e 80 00 20 blr 28: 39 20 01 15 li r9,277 2c: 91 23 00 00 stw r9,0(r3) 30: 4e 80 00 20 blr 34: 39 20 07 15 li r9,1813 38: 91 23 00 00 stw r9,0(r3) 3c: 4e 80 00 20 blr 40: 39 20 05 15 li r9,1301 44: 91 23 00 00 stw r9,0(r3) 48: 4e 80 00 20 blr 4c: 39 20 01 11 li r9,273 50: 4b ff ff d0 b 20 <vm_get_page_prot+0x20>Quoted 5 lines
Quoted 1 line
That is definitely more expensive, it implements a table of branches.
Okay, will split out the PPC32 implementation that retains existing table look up method. Also planning to keep that inside same file (
arch/powerpc/mm/mmap.c), unless you have a difference preference.My point was not to get something specific for PPC32, but to amplify on Russell's objection.
Quoted 7 lines
As this is bad for ARM and bad for PPC32, do we have any evidence that your change is good for any other architecture ?
I checked PPC64 and there is exactly the same drawback. With the current implementation it is a small function performing table read then a few adjustment. After your change it is a bigger function implementing a table of branches.
I am wondering if this would not be the case for any other switch case statement on the platform ? Is there something specific/different just on vm_get_page_prot() implementation ? Are you suggesting that switch case statements should just be avoided instead ?
Quoted 4 lines
So, as requested by Russell, could you look at the disassembly for other architectures and show us that ARM and POWERPC are the only ones for which your change is not optimal ?
But the primary purpose of this series is not to guarantee optimized code on platform by platform basis, while migrating from a table based look up method into a switch case statement.
But instead, the purposes is to remove current levels of unnecessary abstraction while converting a vm_flags access combination into page protection. The switch case statement for platform implementation of vm_get_page_prot() just seemed logical enough. Christoph's original suggestion patch for x86 had the same implementation as well.
But if the table look up is still better/preferred method on certain platforms like arm or ppc32, will be happy to preserve that.
- Anshuman
Geert Uytterhoeven
maintainerRe: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Hi Anshuman,
Quoted 123 lines · Anshuman Khandual
Quoted 100 lines · Christophe Leroy
Quoted 90 lines · Anshuman Khandual
Quoted 89 lines · Christophe Leroy
Quoted 16 lines · Russell King (Oracle)
Quoted 15 lines · Anshuman Khandual
Quoted 13 lines · Russell King (Oracle)
Quoted 3 lines · Anshuman Khandual
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.What I would really like to know is why having to run _code_ to work out what the page protections need to be is better than looking it up in a table.
Not only is this more expensive in terms of CPU cycles, it also brings additional code size with it.
I'm struggling to see what the benefit is.
Quoted 8 lines
Quoted 6 lines
Currently
vm_get_page_prot()is also being _run_ to fetch required page protection values. Although that is being run in the core MM and from a platform perspective__SXXX,__PXXXare just being exported for a table. Looking it up in a table (and applying more constructs there after) is not much different than a clean switch case statement in terms of CPU usage. So this is not more expensive in terms of CPU cycles.I disagree.
So do I.
Quoted 7 lines
However, let's base this disagreement on some evidence. Here is the present 32-bit ARM implementation:
00000048 <
vm_get_page_prot>:48: e200000f and r0, r0, #15 4c: e3003000 movw r3, #0Quoted 7 lines
4c:
R_ARM_MOVW_ABS_NC.LANCHOR1
50:e3403000movt r3, #0
50:R_ARM_MOVT_ABS.LANCHOR1
54:e7930100ldr r0, [r3, r0, lsl #2]
58:e12fff1ebx lrThat is five instructions long.
On ppc32 I get:
00000094 <
vm_get_page_prot>:94: 3d 20 00 00 lis r9,0 96: R_PPC_ADDR16_HA .data..ro_after_init 98: 54 84 16 ba rlwinm r4,r4,2,26,29 9c: 39 29 00 00 addi r9,r9,0 9e: R_PPC_ADDR16_LO .data..ro_after_init a0: 7d 29 20 2e lwzx r9,r9,r4 a4: 91 23 00 00 stw r9,0(r3) a8: 4e 80 00 20 blrQuoted 4 lines
Please show that your new implementation is not more expensive on 32-bit ARM. Please do so by building a 32-bit kernel, and providing the disassembly.
With your series I get:
00000000 <
vm_get_page_prot>:0: 3d 20 00 00 lis r9,0 2: R_PPC_ADDR16_HA .rodata 4: 39 29 00 00 addi r9,r9,0 6: R_PPC_ADDR16_LO .rodata 8: 54 84 16 ba rlwinm r4,r4,2,26,29 c: 7d 49 20 2e lwzx r10,r9,r4 10: 7d 4a 4a 14 add r10,r10,r9 14: 7d 49 03 a6 mtctr r10 18: 4e 80 04 20 bctr 1c: 39 20 03 15 li r9,789 20: 91 23 00 00 stw r9,0(r3) 24: 4e 80 00 20 blr 28: 39 20 01 15 li r9,277 2c: 91 23 00 00 stw r9,0(r3) 30: 4e 80 00 20 blr 34: 39 20 07 15 li r9,1813 38: 91 23 00 00 stw r9,0(r3) 3c: 4e 80 00 20 blr 40: 39 20 05 15 li r9,1301 44: 91 23 00 00 stw r9,0(r3) 48: 4e 80 00 20 blr 4c: 39 20 01 11 li r9,273 50: 4b ff ff d0 b 20 <vm_get_page_prot+0x20>Quoted 5 lines
Quoted 1 line
That is definitely more expensive, it implements a table of branches.
Okay, will split out the PPC32 implementation that retains existing table look up method. Also planning to keep that inside same file (
arch/powerpc/mm/mmap.c), unless you have a difference preference.My point was not to get something specific for PPC32, but to amplify on Russell's objection.
Quoted 7 lines
As this is bad for ARM and bad for PPC32, do we have any evidence that your change is good for any other architecture ?
I checked PPC64 and there is exactly the same drawback. With the current implementation it is a small function performing table read then a few adjustment. After your change it is a bigger function implementing a table of branches.
I am wondering if this would not be the case for any other switch case statement on the platform ? Is there something specific/different just on
vm_get_page_prot()implementation ? Are you suggesting that switch case statements should just be avoided instead ?Quoted 4 lines
So, as requested by Russell, could you look at the disassembly for other architectures and show us that ARM and POWERPC are the only ones for which your change is not optimal ?
But the primary purpose of this series is not to guarantee optimized code on platform by platform basis, while migrating from a table based look up method into a switch case statement.
Quoted 8 lines
But instead, the purposes is to remove current levels of unnecessary abstraction while converting a
vm_flagsaccess combination into page protection. The switch case statement for platform implementation ofvm_get_page_prot()just seemed logical enough. Christoph's original suggestion patch for x86 had the same implementation as well.But if the table look up is still better/preferred method on certain platforms like arm or ppc32, will be happy to preserve that.
I doubt the switch() variant would give better code on any platform.
What about using tables everywhere, using designated initializers to improve readability?
Gr{oetje,eeting}s,
Geert
Re: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Quoted 133 lines · Geert Uytterhoeven
Hi Anshuman,
Quoted 129 lines · Anshuman Khandual
Quoted 100 lines · Christophe Leroy
Quoted 90 lines · Anshuman Khandual
Quoted 89 lines · Christophe Leroy
Quoted 16 lines · Russell King (Oracle)
Quoted 15 lines · Anshuman Khandual
Quoted 13 lines · Russell King (Oracle)
Quoted 3 lines · Anshuman Khandual
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.What I would really like to know is why having to run _code_ to work out what the page protections need to be is better than looking it up in a table.
Not only is this more expensive in terms of CPU cycles, it also brings additional code size with it.
I'm struggling to see what the benefit is.
Quoted 8 lines
Quoted 6 lines
Currently
vm_get_page_prot()is also being _run_ to fetch required page protection values. Although that is being run in the core MM and from a platform perspective__SXXX,__PXXXare just being exported for a table. Looking it up in a table (and applying more constructs there after) is not much different than a clean switch case statement in terms of CPU usage. So this is not more expensive in terms of CPU cycles.I disagree.
So do I.
Quoted 7 lines
However, let's base this disagreement on some evidence. Here is the present 32-bit ARM implementation:
00000048 <
vm_get_page_prot>:48: e200000f and r0, r0, #15 4c: e3003000 movw r3, #0Quoted 7 lines
4c:
R_ARM_MOVW_ABS_NC.LANCHOR1
50:e3403000movt r3, #0
50:R_ARM_MOVT_ABS.LANCHOR1
54:e7930100ldr r0, [r3, r0, lsl #2]
58:e12fff1ebx lrThat is five instructions long.
On ppc32 I get:
00000094 <
vm_get_page_prot>:94: 3d 20 00 00 lis r9,0 96: R_PPC_ADDR16_HA .data..ro_after_init 98: 54 84 16 ba rlwinm r4,r4,2,26,29 9c: 39 29 00 00 addi r9,r9,0 9e: R_PPC_ADDR16_LO .data..ro_after_init a0: 7d 29 20 2e lwzx r9,r9,r4 a4: 91 23 00 00 stw r9,0(r3) a8: 4e 80 00 20 blrQuoted 4 lines
Please show that your new implementation is not more expensive on 32-bit ARM. Please do so by building a 32-bit kernel, and providing the disassembly.
With your series I get:
00000000 <
vm_get_page_prot>:0: 3d 20 00 00 lis r9,0 2: R_PPC_ADDR16_HA .rodata 4: 39 29 00 00 addi r9,r9,0 6: R_PPC_ADDR16_LO .rodata 8: 54 84 16 ba rlwinm r4,r4,2,26,29 c: 7d 49 20 2e lwzx r10,r9,r4 10: 7d 4a 4a 14 add r10,r10,r9 14: 7d 49 03 a6 mtctr r10 18: 4e 80 04 20 bctr 1c: 39 20 03 15 li r9,789 20: 91 23 00 00 stw r9,0(r3) 24: 4e 80 00 20 blr 28: 39 20 01 15 li r9,277 2c: 91 23 00 00 stw r9,0(r3) 30: 4e 80 00 20 blr 34: 39 20 07 15 li r9,1813 38: 91 23 00 00 stw r9,0(r3) 3c: 4e 80 00 20 blr 40: 39 20 05 15 li r9,1301 44: 91 23 00 00 stw r9,0(r3) 48: 4e 80 00 20 blr 4c: 39 20 01 11 li r9,273 50: 4b ff ff d0 b 20 <vm_get_page_prot+0x20>Quoted 5 lines
Quoted 1 line
That is definitely more expensive, it implements a table of branches.
Okay, will split out the PPC32 implementation that retains existing table look up method. Also planning to keep that inside same file (
arch/powerpc/mm/mmap.c), unless you have a difference preference.My point was not to get something specific for PPC32, but to amplify on Russell's objection.
Quoted 7 lines
As this is bad for ARM and bad for PPC32, do we have any evidence that your change is good for any other architecture ?
I checked PPC64 and there is exactly the same drawback. With the current implementation it is a small function performing table read then a few adjustment. After your change it is a bigger function implementing a table of branches.
I am wondering if this would not be the case for any other switch case statement on the platform ? Is there something specific/different just on
vm_get_page_prot()implementation ? Are you suggesting that switch case statements should just be avoided instead ?Quoted 4 lines
So, as requested by Russell, could you look at the disassembly for other architectures and show us that ARM and POWERPC are the only ones for which your change is not optimal ?
But the primary purpose of this series is not to guarantee optimized code on platform by platform basis, while migrating from a table based look up method into a switch case statement.
But instead, the purposes is to remove current levels of unnecessary abstraction while converting a
vm_flagsaccess combination into page protection. The switch case statement for platform implementation ofvm_get_page_prot()just seemed logical enough. Christoph's original suggestion patch for x86 had the same implementation as well.
Quoted 7 lines
Quoted 2 lines
But if the table look up is still better/preferred method on certain platforms like arm or ppc32, will be happy to preserve that.
I doubt the
switch()variant would give better code on any platform.What about using tables everywhere, using designated initializers to improve readability?
Designated initializers ? Could you please be more specific. A table look up on arm platform would be something like this and arm_protection_map[] needs to be updated with user_pgprot like before. Just wondering how a designated initializer will help here.
static pgprot_t arm_protection_map[16] __ro_after_init = {
[VM_NONE] = __PAGE_NONE,
[VM_READ] = __PAGE_READONLY,
[VM_WRITE] = __PAGE_COPY,
[VM_WRITE | VM_READ] = __PAGE_COPY,
[VM_EXEC] = __PAGE_READONLY_EXEC,
[VM_EXEC | VM_READ] = __PAGE_READONLY_EXEC,
[VM_EXEC | VM_WRITE] = __PAGE_COPY_EXEC,
[VM_EXEC | VM_WRITE | VM_READ] = __PAGE_COPY_EXEC,
[VM_SHARED] = __PAGE_NONE,
[VM_SHARED | VM_READ] = __PAGE_READONLY,
[VM_SHARED | VM_WRITE] = __PAGE_SHARED,
[VM_SHARED | VM_WRITE | VM_READ] = __PAGE_SHARED,
[VM_SHARED | VM_EXEC] = __PAGE_READONLY_EXEC,
[VM_SHARED | VM_EXEC | VM_READ] = __PAGE_READONLY_EXEC,
[VM_SHARED | VM_EXEC | VM_WRITE] = __PAGE_SHARED_EXEC,
[VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] = __PAGE_SHARED_EXEC};
pgprot_t vm_get_page_prot(unsigned long vm_flags)
{
return __pgprot(pgprot_val(arm_protection_map[vm_flags &
(VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]));
}EXPORT_SYMBOL(vm_get_page_prot);
Geert Uytterhoeven
maintainerRe: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Hi Anshuman,
Quoted 137 lines · Anshuman Khandual
Quoted 136 lines · Geert Uytterhoeven
Quoted 123 lines · Anshuman Khandual
Quoted 100 lines · Christophe Leroy
Quoted 90 lines · Anshuman Khandual
Quoted 89 lines · Christophe Leroy
Quoted 16 lines · Russell King (Oracle)
Quoted 15 lines · Anshuman Khandual
Quoted 13 lines · Russell King (Oracle)
Quoted 3 lines · Anshuman Khandual
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.What I would really like to know is why having to run _code_ to work out what the page protections need to be is better than looking it up in a table.
Not only is this more expensive in terms of CPU cycles, it also brings additional code size with it.
I'm struggling to see what the benefit is.
Quoted 8 lines
Quoted 6 lines
Currently
vm_get_page_prot()is also being _run_ to fetch required page protection values. Although that is being run in the core MM and from a platform perspective__SXXX,__PXXXare just being exported for a table. Looking it up in a table (and applying more constructs there after) is not much different than a clean switch case statement in terms of CPU usage. So this is not more expensive in terms of CPU cycles.I disagree.
So do I.
Quoted 7 lines
However, let's base this disagreement on some evidence. Here is the present 32-bit ARM implementation:
00000048 <
vm_get_page_prot>:48: e200000f and r0, r0, #15 4c: e3003000 movw r3, #0Quoted 7 lines
4c:
R_ARM_MOVW_ABS_NC.LANCHOR1
50:e3403000movt r3, #0
50:R_ARM_MOVT_ABS.LANCHOR1
54:e7930100ldr r0, [r3, r0, lsl #2]
58:e12fff1ebx lrThat is five instructions long.
On ppc32 I get:
00000094 <
vm_get_page_prot>:94: 3d 20 00 00 lis r9,0 96: R_PPC_ADDR16_HA .data..ro_after_init 98: 54 84 16 ba rlwinm r4,r4,2,26,29 9c: 39 29 00 00 addi r9,r9,0 9e: R_PPC_ADDR16_LO .data..ro_after_init a0: 7d 29 20 2e lwzx r9,r9,r4 a4: 91 23 00 00 stw r9,0(r3) a8: 4e 80 00 20 blrQuoted 4 lines
Please show that your new implementation is not more expensive on 32-bit ARM. Please do so by building a 32-bit kernel, and providing the disassembly.
With your series I get:
00000000 <
vm_get_page_prot>:0: 3d 20 00 00 lis r9,0 2: R_PPC_ADDR16_HA .rodata 4: 39 29 00 00 addi r9,r9,0 6: R_PPC_ADDR16_LO .rodata 8: 54 84 16 ba rlwinm r4,r4,2,26,29 c: 7d 49 20 2e lwzx r10,r9,r4 10: 7d 4a 4a 14 add r10,r10,r9 14: 7d 49 03 a6 mtctr r10 18: 4e 80 04 20 bctr 1c: 39 20 03 15 li r9,789 20: 91 23 00 00 stw r9,0(r3) 24: 4e 80 00 20 blr 28: 39 20 01 15 li r9,277 2c: 91 23 00 00 stw r9,0(r3) 30: 4e 80 00 20 blr 34: 39 20 07 15 li r9,1813 38: 91 23 00 00 stw r9,0(r3) 3c: 4e 80 00 20 blr 40: 39 20 05 15 li r9,1301 44: 91 23 00 00 stw r9,0(r3) 48: 4e 80 00 20 blr 4c: 39 20 01 11 li r9,273 50: 4b ff ff d0 b 20 <vm_get_page_prot+0x20>Quoted 5 lines
Quoted 1 line
That is definitely more expensive, it implements a table of branches.
Okay, will split out the PPC32 implementation that retains existing table look up method. Also planning to keep that inside same file (
arch/powerpc/mm/mmap.c), unless you have a difference preference.My point was not to get something specific for PPC32, but to amplify on Russell's objection.
Quoted 7 lines
As this is bad for ARM and bad for PPC32, do we have any evidence that your change is good for any other architecture ?
I checked PPC64 and there is exactly the same drawback. With the current implementation it is a small function performing table read then a few adjustment. After your change it is a bigger function implementing a table of branches.
I am wondering if this would not be the case for any other switch case statement on the platform ? Is there something specific/different just on
vm_get_page_prot()implementation ? Are you suggesting that switch case statements should just be avoided instead ?Quoted 4 lines
So, as requested by Russell, could you look at the disassembly for other architectures and show us that ARM and POWERPC are the only ones for which your change is not optimal ?
But the primary purpose of this series is not to guarantee optimized code on platform by platform basis, while migrating from a table based look up method into a switch case statement.
Quoted 8 lines
But instead, the purposes is to remove current levels of unnecessary abstraction while converting a
vm_flagsaccess combination into page protection. The switch case statement for platform implementation ofvm_get_page_prot()just seemed logical enough. Christoph's original suggestion patch for x86 had the same implementation as well.But if the table look up is still better/preferred method on certain platforms like arm or ppc32, will be happy to preserve that.
I doubt the
switch()variant would give better code on any platform.
Quoted 7 lines
Quoted 2 lines
What about using tables everywhere, using designated initializers to improve readability?
Designated initializers ? Could you please be more specific. A table look up on arm platform would be something like this and arm_protection_map[] needs to be updated with
user_pgprotlike before. Just wondering how a designated initializer will help here.
It's more readable than the original:
pgprot_t protection_map[16] __ro_after_init = {
__P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
__S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
};Quoted 18 lines
static
pgprot_tarm_protection_map[16]__ro_after_init= {[VM_NONE] = __PAGE_NONE, [VM_READ] = __PAGE_READONLY, [VM_WRITE] = __PAGE_COPY, [VM_WRITE | VM_READ] = __PAGE_COPY, [VM_EXEC] = __PAGE_READONLY_EXEC, [VM_EXEC | VM_READ] = __PAGE_READONLY_EXEC, [VM_EXEC | VM_WRITE] = __PAGE_COPY_EXEC, [VM_EXEC | VM_WRITE | VM_READ] = __PAGE_COPY_EXEC, [VM_SHARED] = __PAGE_NONE, [VM_SHARED | VM_READ] = __PAGE_READONLY, [VM_SHARED | VM_WRITE] = __PAGE_SHARED, [VM_SHARED | VM_WRITE | VM_READ] = __PAGE_SHARED, [VM_SHARED | VM_EXEC] = __PAGE_READONLY_EXEC, [VM_SHARED | VM_EXEC | VM_READ] = __PAGE_READONLY_EXEC, [VM_SHARED | VM_EXEC | VM_WRITE] = __PAGE_SHARED_EXEC, [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] = __PAGE_SHARED_EXEC
Quoted 1 line
};
Yeah, like that.
Seems like you already made such a conversion in
https://lore.kernel.org/all/[email protected]/
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Quoted 176 lines · Geert Uytterhoeven
Hi Anshuman,
Quoted 137 lines · Anshuman Khandual
Quoted 136 lines · Geert Uytterhoeven
Quoted 123 lines · Anshuman Khandual
Quoted 100 lines · Christophe Leroy
Quoted 90 lines · Anshuman Khandual
Quoted 89 lines · Christophe Leroy
Quoted 16 lines · Russell King (Oracle)
Quoted 15 lines · Anshuman Khandual
Quoted 13 lines · Russell King (Oracle)
Quoted 3 lines · Anshuman Khandual
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.What I would really like to know is why having to run _code_ to work out what the page protections need to be is better than looking it up in a table.
Not only is this more expensive in terms of CPU cycles, it also brings additional code size with it.
I'm struggling to see what the benefit is.
Quoted 8 lines
Quoted 6 lines
Currently
vm_get_page_prot()is also being _run_ to fetch required page protection values. Although that is being run in the core MM and from a platform perspective__SXXX,__PXXXare just being exported for a table. Looking it up in a table (and applying more constructs there after) is not much different than a clean switch case statement in terms of CPU usage. So this is not more expensive in terms of CPU cycles.I disagree.
So do I.
Quoted 7 lines
However, let's base this disagreement on some evidence. Here is the present 32-bit ARM implementation:
00000048 <
vm_get_page_prot>:48: e200000f and r0, r0, #15 4c: e3003000 movw r3, #0Quoted 7 lines
4c:
R_ARM_MOVW_ABS_NC.LANCHOR1
50:e3403000movt r3, #0
50:R_ARM_MOVT_ABS.LANCHOR1
54:e7930100ldr r0, [r3, r0, lsl #2]
58:e12fff1ebx lrThat is five instructions long.
On ppc32 I get:
00000094 <
vm_get_page_prot>:94: 3d 20 00 00 lis r9,0 96: R_PPC_ADDR16_HA .data..ro_after_init 98: 54 84 16 ba rlwinm r4,r4,2,26,29 9c: 39 29 00 00 addi r9,r9,0 9e: R_PPC_ADDR16_LO .data..ro_after_init a0: 7d 29 20 2e lwzx r9,r9,r4 a4: 91 23 00 00 stw r9,0(r3) a8: 4e 80 00 20 blrQuoted 4 lines
Please show that your new implementation is not more expensive on 32-bit ARM. Please do so by building a 32-bit kernel, and providing the disassembly.
With your series I get:
00000000 <
vm_get_page_prot>:0: 3d 20 00 00 lis r9,0 2: R_PPC_ADDR16_HA .rodata 4: 39 29 00 00 addi r9,r9,0 6: R_PPC_ADDR16_LO .rodata 8: 54 84 16 ba rlwinm r4,r4,2,26,29 c: 7d 49 20 2e lwzx r10,r9,r4 10: 7d 4a 4a 14 add r10,r10,r9 14: 7d 49 03 a6 mtctr r10 18: 4e 80 04 20 bctr 1c: 39 20 03 15 li r9,789 20: 91 23 00 00 stw r9,0(r3) 24: 4e 80 00 20 blr 28: 39 20 01 15 li r9,277 2c: 91 23 00 00 stw r9,0(r3) 30: 4e 80 00 20 blr 34: 39 20 07 15 li r9,1813 38: 91 23 00 00 stw r9,0(r3) 3c: 4e 80 00 20 blr 40: 39 20 05 15 li r9,1301 44: 91 23 00 00 stw r9,0(r3) 48: 4e 80 00 20 blr 4c: 39 20 01 11 li r9,273 50: 4b ff ff d0 b 20 <vm_get_page_prot+0x20>Quoted 5 lines
Quoted 1 line
That is definitely more expensive, it implements a table of branches.
Okay, will split out the PPC32 implementation that retains existing table look up method. Also planning to keep that inside same file (
arch/powerpc/mm/mmap.c), unless you have a difference preference.My point was not to get something specific for PPC32, but to amplify on Russell's objection.
Quoted 7 lines
As this is bad for ARM and bad for PPC32, do we have any evidence that your change is good for any other architecture ?
I checked PPC64 and there is exactly the same drawback. With the current implementation it is a small function performing table read then a few adjustment. After your change it is a bigger function implementing a table of branches.
I am wondering if this would not be the case for any other switch case statement on the platform ? Is there something specific/different just on
vm_get_page_prot()implementation ? Are you suggesting that switch case statements should just be avoided instead ?Quoted 4 lines
So, as requested by Russell, could you look at the disassembly for other architectures and show us that ARM and POWERPC are the only ones for which your change is not optimal ?
But the primary purpose of this series is not to guarantee optimized code on platform by platform basis, while migrating from a table based look up method into a switch case statement.
Quoted 8 lines
But instead, the purposes is to remove current levels of unnecessary abstraction while converting a
vm_flagsaccess combination into page protection. The switch case statement for platform implementation ofvm_get_page_prot()just seemed logical enough. Christoph's original suggestion patch for x86 had the same implementation as well.But if the table look up is still better/preferred method on certain platforms like arm or ppc32, will be happy to preserve that.
I doubt the
switch()variant would give better code on any platform.Quoted 7 lines
Quoted 2 lines
What about using tables everywhere, using designated initializers to improve readability?
Designated initializers ? Could you please be more specific. A table look up on arm platform would be something like this and arm_protection_map[] needs to be updated with
user_pgprotlike before. Just wondering how a designated initializer will help here.It's more readable than the original:
pgprot_t protection_map[16] __ro_after_init = { __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111, __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111 };Quoted 18 lines
static
pgprot_tarm_protection_map[16]__ro_after_init= {[VM_NONE] = __PAGE_NONE, [VM_READ] = __PAGE_READONLY, [VM_WRITE] = __PAGE_COPY, [VM_WRITE | VM_READ] = __PAGE_COPY, [VM_EXEC] = __PAGE_READONLY_EXEC, [VM_EXEC | VM_READ] = __PAGE_READONLY_EXEC, [VM_EXEC | VM_WRITE] = __PAGE_COPY_EXEC, [VM_EXEC | VM_WRITE | VM_READ] = __PAGE_COPY_EXEC, [VM_SHARED] = __PAGE_NONE, [VM_SHARED | VM_READ] = __PAGE_READONLY, [VM_SHARED | VM_WRITE] = __PAGE_SHARED, [VM_SHARED | VM_WRITE | VM_READ] = __PAGE_SHARED, [VM_SHARED | VM_EXEC] = __PAGE_READONLY_EXEC, [VM_SHARED | VM_EXEC | VM_READ] = __PAGE_READONLY_EXEC, [VM_SHARED | VM_EXEC | VM_WRITE] = __PAGE_SHARED_EXEC, [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] = __PAGE_SHARED_EXECQuoted 1 line
};
Quoted 4 lines
Yeah, like that.
Seems like you already made such a conversion in
https://lore.kernel.org/all/[email protected]/
Will rework the series in two different phases as mentioned on the other thread.
Russell King (Oracle)
maintainerRe: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualQuoted 9 lines · Anshuman Khandual
Quoted 4 lines · Geert Uytterhoeven
I doubt the
switch()variant would give better code on any platform.What about using tables everywhere, using designated initializers to improve readability?
Designated initializers ? Could you please be more specific. A table look up on arm platform would be something like this and arm_protection_map[] needs to be updated with
user_pgprotlike before.
There is *absolutely* nothing wrong with that. Updating it once during boot is way more efficient than having to compute the value each time vm_get_page_prot() gets called.
Thanks.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Russell King (Oracle)Quoted 49 lines · Russell King (Oracle)
Quoted 12 lines · Anshuman Khandual
Quoted 11 lines · Russell King (Oracle)
Quoted 3 lines · Anshuman Khandual
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.What I would really like to know is why having to run _code_ to work out what the page protections need to be is better than looking it up in a table.
Not only is this more expensive in terms of CPU cycles, it also brings additional code size with it.
Quoted 7 lines
Quoted 1 line
I'm struggling to see what the benefit is.
Currently
vm_get_page_prot()is also being _run_ to fetch required page protection values. Although that is being run in the core MM and from a platform perspective__SXXX,__PXXXare just being exported for a table. Looking it up in a table (and applying more constructs there after) is not much different than a clean switch case statement in terms of CPU usage. So this is not more expensive in terms of CPU cycles.I disagree.
However, let's base this disagreement on some evidence. Here is the present 32-bit ARM implementation:
00000048 <
vm_get_page_prot>:48: e200000f and r0, r0, #15 4c: e3003000 movw r3, #04c:
R_ARM_MOVW_ABS_NC.LANCHOR1
50:e3403000movt r3, #0
50:R_ARM_MOVT_ABS.LANCHOR1
54:e7930100ldr r0, [r3, r0, lsl #2]
58:e12fff1ebx lrThat is five instructions long.
Please show that your new implementation is not more expensive on 32-bit ARM. Please do so by building a 32-bit kernel, and providing the disassembly.
I think you will find way more than five instructions in your version - the compiler will have to issue code to decode the protection bits, probably using a table of branches or absolute PC values, or possibly the worst case of using multiple comparisons and branches. It then has to load constants that may be moved using movw on ARMv7, but on older architectures would have to be created from multiple instructions or loaded from the literal pool. Then there'll be instructions to load the address of "
user_pgprot", retrieve its value, and bitwise or that.
Quoted 8 lines
Therefore, I fail to see how your approach of getting rid of the table is somehow "better" than what we currently have in terms of the effect on the resulting code.
If you don't like the
__Pand__Sstuff and two arch_* hooks, you could move the table into arch code along withvm_get_page_prot()without the additional unnecessary hooks, while keeping all the benefits of the table lookup.
Okay, will change the arm's vm_get_page_prot() implementation as suggested.
PATCH v3 10/30 x86/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualFrom: Christoph Hellwig <[email protected]>
This defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed. This also unsubscribes from ARCH_HAS_FILTER_PGPROT, after dropping off arch_filter_pgprot() and arch_vm_get_page_prot().
--- arch/x86/Kconfig | 2 +- arch/x86/include/asm/pgtable.h | 5 -- arch/x86/include/asm/pgtable_types.h | 19 -------- arch/x86/include/uapi/asm/mman.h | 14 ------ arch/x86/mm/Makefile | 2 +- arch/x86/mm/mem_encrypt_amd.c | 6 --- arch/x86/mm/pgprot.c | 71 ++++++++++++++++++++++++++++ 7 files changed, 73 insertions(+), 46 deletions(-) create mode 100644 arch/x86/mm/pgprot.c
arch/x86/Kconfig +1 -1
@@ -75,7 +75,6 @@ config X86 select ARCH_HAS_EARLY_DEBUG if KGDB select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_FAST_MULTIPLIER - select ARCH_HAS_FILTER_PGPROT select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_KCOV if X86_64
@@ -94,6 +93,7 @@ config X86 select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE select ARCH_HAS_SYSCALL_WRAPPER select ARCH_HAS_UBSAN_SANITIZE_ALL + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HAS_DEBUG_WX select ARCH_HAS_ZONE_DMA_SET if EXPERT select ARCH_HAVE_NMI_SAFE_CMPXCHG
arch/x86/include/asm/pgtable.h +0 -5
@@ -648,11 +648,6 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)#define canon_pgprot (p) __pgprot(massage_pgprot(p)) -static inline pgprot_t arch_filter_pgprot (pgprot_t prot) -{ -return canon_pgprot (prot); -} -static inline int is_new_memtype_allowed (u64 paddr,unsigned long size,enum page_cache_mode pcm,enum page_cache_mode new_pcm)
arch/x86/include/asm/pgtable_types.h +0 -19
@@ -228,25 +228,6 @@ enum page_cache_mode {#endif /* __ASSEMBLY__ */ -/* xwr */ -#define __P000 PAGE_NONE -#define __P001 PAGE_READONLY -#define __P010 PAGE_COPY -#define __P011 PAGE_COPY -#define __P100 PAGE_READONLY_EXEC -#define __P101 PAGE_READONLY_EXEC -#define __P110 PAGE_COPY_EXEC -#define __P111 PAGE_COPY_EXEC - -#define __S000 PAGE_NONE -#define __S001 PAGE_READONLY -#define __S010 PAGE_SHARED -#define __S011 PAGE_SHARED -#define __S100 PAGE_READONLY_EXEC -#define __S101 PAGE_READONLY_EXEC -#define __S110 PAGE_SHARED_EXEC -#define __S111 PAGE_SHARED_EXEC -/* * early identity mapping pte attrib macros. */
arch/x86/include/uapi/asm/mman.h +0 -14
@@ -5,20 +5,6 @@#define MAP_32BIT 0x40/* only give out 32bit addresses */ #ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS -/* -* Take the 4 protection key bits out of the vma->vm_flags -* value and turn them in to the bits that we can put in -* to a pte. -* -* Only override these if Protection Keys are available -* (which is only on 64-bit). -*/ -#define arch_vm_get_page_prot (vm_flags) __pgprot( \ - ((vm_flags) & VM_PKEY_BIT0 ? _PAGE_PKEY_BIT0 : 0) | \ - ((vm_flags) & VM_PKEY_BIT1 ? _PAGE_PKEY_BIT1 : 0) | \ - ((vm_flags) & VM_PKEY_BIT2 ? _PAGE_PKEY_BIT2 : 0) | \ - ((vm_flags) & VM_PKEY_BIT3 ? _PAGE_PKEY_BIT3 : 0)) -#define arch_calc_vm_prot_bits (prot, key) ( \ ((key) & 0x1 ? VM_PKEY_BIT0 : 0) | \ ((key) & 0x2 ? VM_PKEY_BIT1 : 0) | \
arch/x86/mm/Makefile +1 -1
@@ -20,7 +20,7 @@ CFLAGS_REMOVE_mem_encrypt_identity.o = -pg endif obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o mmap.o \ - pgtable.o physaddr.o setup_nx.o tlb.o cpu_entry_area.o maccess.o + pgtable.o physaddr.o setup_nx.o tlb.o cpu_entry_area.o maccess.o pgprot.o obj-y += pat/
arch/x86/mm/mem_encrypt_amd.c +0 -6
@@ -179,8 +179,6 @@ void __init sme_map_bootdata(char *real_mode_data)void __init sme_early_init (void ) { -unsigned int i; -if (!sme_me_mask)return ;
@@ -188,10 +186,6 @@ void __init sme_early_init(void) __supported_pte_mask =__sme_set (__supported_pte_mask); -/* Update the protection map with memory encryption mask */ -for (i =0 ; i <ARRAY_SIZE (protection_map); i++) - protection_map[i] =pgprot_encrypted (protection_map[i]); -if (cc_platform_has (CC_ATTR_GUEST_MEM_ENCRYPT )) swiotlb_force =SWIOTLB_FORCE ; }
arch/x86/mm/pgprot.c new file +71 -0
71 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 11/30 mm/mmap: Drop protection_map[]
In reply to Anshuman KhandualThere are no other users for protection_map[]. Hence just drop this array construct and instead define __vm_get_page_prot() which will provide page protection map based on vm_flags combination switch.
--- drivers/gpu/drm/drm_vm.c | 4 +-- include/linux/mm.h | 6 ---- mm/mmap.c | 63 ++++++++++++++++++++++++++-------------- 3 files changed, 44 insertions(+), 29 deletions(-)
drivers/gpu/drm/drm_vm.c +2 -2
@@ -482,7 +482,7 @@ static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)#else /* Ye gads this is ugly. With more thought we could move this up higher and use -`protection_map' instead. */ +`vm_get_page_prot()' instead. */ vma->vm_page_prot = __pgprot(pte_val (pte_wrprotect
@@ -566,7 +566,7 @@ static int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma)#else /* Ye gads this is ugly. With more thought we could move this up higher and use -`protection_map' instead. */ +`vm_get_page_prot()' instead. */ vma->vm_page_prot = __pgprot(pte_val (pte_wrprotect
include/linux/mm.h +0 -6
@@ -418,12 +418,6 @@ extern unsigned int kobjsize(const void *objp);#endif #define VM_FLAGS_CLEAR (ARCH_VM_PKEY_FLAGS | VM_ARCH_CLEAR) -/* -* mapping from the currently active vm_flags protection bits (the -* low four bits) to a page protection mask.. -*/ -extern pgprot_t protection_map[16 ]; -/* * The default fault flags that should be used by most of the * arch-specific page fault handlers.
mm/mmap.c +42 -21
83 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 12/30 mm/mmap: Drop arch_filter_pgprot()
In reply to Anshuman KhandualThere are no platforms left which subscribe ARCH_HAS_FILTER_PGPROT. Hence just drop arch_filter_pgprot() and also the config ARCH_HAS_FILTER_PGPROT.
--- mm/Kconfig | 3 --- mm/mmap.c | 10 +--------- 2 files changed, 1 insertion(+), 12 deletions(-)
mm/Kconfig +0 -3
@@ -744,9 +744,6 @@ config IDLE_PAGE_TRACKING config ARCH_HAS_CACHE_LINE_SIZE bool -config ARCH_HAS_FILTER_PGPROT - bool - config ARCH_HAS_VM_GET_PAGE_PROT bool
mm/mmap.c +1 -9
@@ -102,14 +102,6 @@ static void unmap_region(struct mm_struct *mm,* w: (no) no * x: (yes) yes */ - -#ifndef CONFIG_ARCH_HAS_FILTER_PGPROT -static inline pgprot_t arch_filter_pgprot (pgprot_t prot) -{ -return prot; -} -#endif -static inline pgprot_t __vm_get_page_prot (unsigned long vm_flags) {switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) {
@@ -155,7 +147,7 @@ pgprot_t vm_get_page_prot(unsigned long vm_flags)pgprot_t ret =__pgprot (pgprot_val (__vm_get_page_prot (vm_flags)) |pgprot_val (arch_vm_get_page_prot (vm_flags))); - return arch_filter_pgprot(ret); + return ret; }EXPORT_SYMBOL (vm_get_page_prot);#endif /* CONFIG_ARCH_HAS_VM_GET_PAGE_PROT */
Signature · 1 line
2.25.1
PATCH v3 13/30 mm/mmap: Drop arch_vm_get_page_pgprot()
In reply to Anshuman KhandualThere are no platforms left which use arch_vm_get_page_prot(). Just drop arch_vm_get_page_prot() construct and simplify remaining code.
--- include/linux/mman.h | 4 ---- mm/mmap.c | 10 +--------- 2 files changed, 1 insertion(+), 13 deletions(-)
include/linux/mman.h +0 -4
@@ -93,10 +93,6 @@ static inline void vm_unacct_memory(long pages)#define arch_calc_vm_flag_bits (flags) 0#endif -#ifndef arch_vm_get_page_prot -#define arch_vm_get_page_prot (vm_flags) __pgprot(0) -#endif -#ifndef arch_validate_prot/* * This is called from mprotect(). PROT_GROWSDOWN and PROT_GROWSUP have
mm/mmap.c +1 -6
@@ -102,7 +102,7 @@ static void unmap_region(struct mm_struct *mm,* w: (no) no * x: (yes) yes */ -static inline pgprot_t __vm_get_page_prot (unsigned long vm_flags) +pgprot_t vm_get_page_prot (unsigned long vm_flags) {switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) {case VM_NONE :
@@ -141,14 +141,6 @@ static inline pgprot_t __vm_get_page_prot(unsigned long vm_flags)BUILD_BUG (); } } - -pgprot_t vm_get_page_prot (unsigned long vm_flags) -{ -pgprot_t ret =__pgprot (pgprot_val (__vm_get_page_prot (vm_flags)) | -pgprot_val (arch_vm_get_page_prot (vm_flags)));
PATCH v3 14/30 s390/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/s390/Kconfig | 1 + arch/s390/include/asm/pgtable.h | 17 ----------------- arch/s390/mm/mmap.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 17 deletions(-)
arch/s390/Kconfig +1 -0
@@ -78,6 +78,7 @@ config S390 select ARCH_HAS_SYSCALL_WRAPPER select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAS_VDSO_DATA + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_INLINE_READ_LOCK select ARCH_INLINE_READ_LOCK_BH
arch/s390/include/asm/pgtable.h +0 -17
@@ -422,23 +422,6 @@ static inline int is_module_addr(void *addr)* implies read permission. */ /*xwr*/ -#define __P000 PAGE_NONE -#define __P001 PAGE_RO -#define __P010 PAGE_RO -#define __P011 PAGE_RO -#define __P100 PAGE_RX -#define __P101 PAGE_RX -#define __P110 PAGE_RX -#define __P111 PAGE_RX - -#define __S000 PAGE_NONE -#define __S001 PAGE_RO -#define __S010 PAGE_RW -#define __S011 PAGE_RW -#define __S100 PAGE_RX -#define __S101 PAGE_RX -#define __S110 PAGE_RWX -#define __S111 PAGE_RWX/* * Segment entry (large page) protection definitions.
arch/s390/mm/mmap.c +33 -0
@@ -188,3 +188,36 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) mm->get_unmapped_area = arch_get_unmapped_area_topdown; } } + +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{ +switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { +case VM_NONE : +return PAGE_NONE ; +case VM_READ : +case VM_WRITE : +case VM_WRITE |VM_READ : +return PAGE_RO ; +case VM_EXEC : +case VM_EXEC |VM_READ : +case VM_EXEC |VM_WRITE : +case VM_EXEC |VM_WRITE |VM_READ : +return PAGE_RX ; +case VM_SHARED : +return PAGE_NONE ; +case VM_SHARED |VM_READ : +return PAGE_RO ; +case VM_SHARED |VM_WRITE : +case VM_SHARED |VM_WRITE |VM_READ : +return PAGE_RW ; +case VM_SHARED |VM_EXEC : +case VM_SHARED |VM_EXEC |VM_READ : +return PAGE_RX ; +case VM_SHARED |VM_EXEC |VM_WRITE : +case VM_SHARED |VM_EXEC |VM_WRITE |VM_READ : +return PAGE_RWX ; +default : +BUILD_BUG (); + } +} +EXPORT_SYMBOL (vm_get_page_prot);
Signature · 1 line
2.25.1
PATCH v3 15/30 riscv/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/pgtable.h | 16 ------------ arch/riscv/mm/init.c | 42 ++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 16 deletions(-)
arch/riscv/Kconfig +1 -0
@@ -31,6 +31,7 @@ config RISCV select ARCH_HAS_STRICT_MODULE_RWX if MMU && !XIP_KERNEL select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAS_UBSAN_SANITIZE_ALL + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT select ARCH_STACKWALK
arch/riscv/include/asm/pgtable.h +0 -16
@@ -183,24 +183,8 @@ extern struct pt_alloc_ops pt_ops __initdata;extern pgd_t swapper_pg_dir[];/* MAP_PRIVATE permissions: xwr (copy-on-write) */ -#define __P000 PAGE_NONE -#define __P001 PAGE_READ -#define __P010 PAGE_COPY -#define __P011 PAGE_COPY -#define __P100 PAGE_EXEC -#define __P101 PAGE_READ_EXEC -#define __P110 PAGE_COPY_EXEC -#define __P111 PAGE_COPY_READ_EXEC/* MAP_SHARED permissions: xwr */ -#define __S000 PAGE_NONE -#define __S001 PAGE_READ -#define __S010 PAGE_SHARED -#define __S011 PAGE_SHARED -#define __S100 PAGE_EXEC -#define __S101 PAGE_READ_EXEC -#define __S110 PAGE_SHARED_EXEC -#define __S111 PAGE_SHARED_EXEC#ifdef CONFIG_TRANSPARENT_HUGEPAGE static inline int pmd_present (pmd_t pmd)
arch/riscv/mm/init.c +42 -0
45 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 16/30 alpha/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/alpha/Kconfig | 1 + arch/alpha/include/asm/pgtable.h | 17 --------------- arch/alpha/mm/init.c | 37 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 17 deletions(-)
arch/alpha/Kconfig +1 -0
@@ -2,6 +2,7 @@ config ALPHA bool default y + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_32BIT_USTAT_F_TINODE select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO
arch/alpha/include/asm/pgtable.h +0 -17
@@ -116,23 +116,6 @@ struct vm_area_struct;* arch/alpha/mm/fault.c) */ /* xwr */ -#define __P000 _PAGE_P(_PAGE_FOE | _PAGE_FOW | _PAGE_FOR) -#define __P001 _PAGE_P(_PAGE_FOE | _PAGE_FOW) -#define __P010 _PAGE_P(_PAGE_FOE) -#define __P011 _PAGE_P(_PAGE_FOE) -#define __P100 _PAGE_P(_PAGE_FOW | _PAGE_FOR) -#define __P101 _PAGE_P(_PAGE_FOW) -#define __P110 _PAGE_P(0) -#define __P111 _PAGE_P(0) - -#define __S000 _PAGE_S(_PAGE_FOE | _PAGE_FOW | _PAGE_FOR) -#define __S001 _PAGE_S(_PAGE_FOE | _PAGE_FOW) -#define __S010 _PAGE_S(_PAGE_FOE) -#define __S011 _PAGE_S(_PAGE_FOE) -#define __S100 _PAGE_S(_PAGE_FOW | _PAGE_FOR) -#define __S101 _PAGE_S(_PAGE_FOW) -#define __S110 _PAGE_S(0) -#define __S111 _PAGE_S(0)/* * pgprot_noncached() is only for infiniband pci support, and a real
arch/alpha/mm/init.c +37 -0
@@ -280,3 +280,40 @@ mem_init(void) high_memory = (void *)__va (max_low_pfn *PAGE_SIZE );memblock_free_all (); } + +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{ +switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { +case VM_NONE : +return _PAGE_P (_PAGE_FOE | _PAGE_FOW | _PAGE_FOR); +case VM_READ : +return _PAGE_P (_PAGE_FOE | _PAGE_FOW); +case VM_WRITE : +case VM_WRITE |VM_READ : +return _PAGE_P (_PAGE_FOE); +case VM_EXEC : +return _PAGE_P (_PAGE_FOW | _PAGE_FOR); +case VM_EXEC |VM_READ : +return _PAGE_P (_PAGE_FOW); +case VM_EXEC |VM_WRITE : +case VM_EXEC |VM_WRITE |VM_READ : +return _PAGE_P (0 ); +case VM_SHARED : +return _PAGE_S (_PAGE_FOE | _PAGE_FOW | _PAGE_FOR); +case VM_SHARED |VM_READ : +return _PAGE_S (_PAGE_FOE | _PAGE_FOW); +case VM_SHARED |VM_WRITE : +case VM_SHARED |VM_WRITE |VM_READ : +return _PAGE_S (_PAGE_FOE); +case VM_SHARED |VM_EXEC : +return _PAGE_S (_PAGE_FOW | _PAGE_FOR); +case VM_SHARED |VM_EXEC |VM_READ : +return _PAGE_S (_PAGE_FOW); +case VM_SHARED |VM_EXEC |VM_WRITE : +case VM_SHARED |VM_EXEC |VM_WRITE |VM_READ : +return _PAGE_S (0 ); +default : +BUILD_BUG (); + } +} +EXPORT_SYMBOL (vm_get_page_prot);
Signature · 1 line
2.25.1
PATCH v3 17/30 sh/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/sh/Kconfig | 1 + arch/sh/include/asm/pgtable.h | 17 ---------------- arch/sh/mm/mmap.c | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 17 deletions(-)
arch/sh/Kconfig +1 -0
@@ -11,6 +11,7 @@ config SUPERH select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HIBERNATION_POSSIBLE if MMU select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_WANT_IPC_PARSE_VERSION
arch/sh/include/asm/pgtable.h +0 -17
@@ -89,23 +89,6 @@ static inline unsigned long phys_addr_mask(void)* completely separate permission bits for user and kernel space. */ /*xwr*/ -#define __P000 PAGE_NONE -#define __P001 PAGE_READONLY -#define __P010 PAGE_COPY -#define __P011 PAGE_COPY -#define __P100 PAGE_EXECREAD -#define __P101 PAGE_EXECREAD -#define __P110 PAGE_COPY -#define __P111 PAGE_COPY - -#define __S000 PAGE_NONE -#define __S001 PAGE_READONLY -#define __S010 PAGE_WRITEONLY -#define __S011 PAGE_SHARED -#define __S100 PAGE_EXECREAD -#define __S101 PAGE_EXECREAD -#define __S110 PAGE_RWX -#define __S111 PAGE_RWXtypedef pte_t *pte_addr_t ;
arch/sh/mm/mmap.c +38 -0
@@ -162,3 +162,41 @@ int valid_mmap_phys_addr_range(unsigned long pfn, size_t size) {return 1 ; } + +#ifdef CONFIG_MMU +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{ +switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { +case VM_NONE : +return PAGE_NONE ; +case VM_READ : +return PAGE_READONLY ; +case VM_WRITE : +case VM_WRITE |VM_READ : +return PAGE_COPY ; +case VM_EXEC : +case VM_EXEC |VM_READ : +return PAGE_EXECREAD ; +case VM_EXEC |VM_WRITE : +case VM_EXEC |VM_WRITE |VM_READ : +return PAGE_COPY ; +case VM_SHARED : +return PAGE_NONE ; +case VM_SHARED |VM_READ : +return PAGE_READONLY ; +case VM_SHARED |VM_WRITE : +return PAGE_WRITEONLY ; +case VM_SHARED |VM_WRITE |VM_READ : +return PAGE_SHARED ; +case VM_SHARED |VM_EXEC : +case VM_SHARED |VM_EXEC |VM_READ : +return PAGE_EXECREAD ; +case VM_SHARED |VM_EXEC |VM_WRITE : +case VM_SHARED |VM_EXEC |VM_WRITE |VM_READ : +return PAGE_RWX ; +default : +BUILD_BUG (); + } +} +EXPORT_SYMBOL (vm_get_page_prot); +#endif
Signature · 1 line
2.25.1
PATCH v3 18/30 arc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/arc/Kconfig | 1 + arch/arc/include/asm/pgtable-bits-arcv2.h | 17 ---------- arch/arc/mm/mmap.c | 41 +++++++++++++++++++++++ 3 files changed, 42 insertions(+), 17 deletions(-)
arch/arc/Kconfig +1 -0
@@ -13,6 +13,7 @@ config ARC select ARCH_HAS_SETUP_DMA_OPS select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_SUPPORTS_ATOMIC_RMW if ARC_HAS_LLSC select ARCH_32BIT_OFF_T select BUILDTIME_TABLE_SORT
arch/arc/include/asm/pgtable-bits-arcv2.h +0 -17
@@ -72,23 +72,6 @@* This is to enable COW mechanism */ /* xwr */ -#define __P000 PAGE_U_NONE -#define __P001 PAGE_U_R -#define __P010 PAGE_U_R/* Pvt-W => !W */ -#define __P011 PAGE_U_R/* Pvt-W => !W */ -#define __P100 PAGE_U_X_R/* X => R */ -#define __P101 PAGE_U_X_R -#define __P110 PAGE_U_X_R/* Pvt-W => !W and X => R */ -#define __P111 PAGE_U_X_R/* Pvt-W => !W */ - -#define __S000 PAGE_U_NONE -#define __S001 PAGE_U_R -#define __S010 PAGE_U_W_R/* W => R */ -#define __S011 PAGE_U_W_R -#define __S100 PAGE_U_X_R/* X => R */ -#define __S101 PAGE_U_X_R -#define __S110 PAGE_U_X_W_R/* X => R */ -#define __S111 PAGE_U_X_W_R#ifndef __ASSEMBLY__
arch/arc/mm/mmap.c +41 -0
44 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 19/30 csky/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/csky/Kconfig | 1 + arch/csky/include/asm/pgtable.h | 18 ------------------ arch/csky/mm/init.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 18 deletions(-)
arch/csky/Kconfig +1 -0
@@ -6,6 +6,7 @@ config CSKY select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_QUEUED_RWLOCKS select ARCH_WANT_FRAME_POINTERS if !CPU_CK610 && $(cc-option,-mbacktrace)
arch/csky/include/asm/pgtable.h +0 -18
@@ -76,24 +76,6 @@#define MAX_SWAPFILES_CHECK () \ BUILD_BUG_ON(MAX_SWAPFILES_SHIFT != 5) -#define __P000 PAGE_NONE -#define __P001 PAGE_READ -#define __P010 PAGE_READ -#define __P011 PAGE_READ -#define __P100 PAGE_READ -#define __P101 PAGE_READ -#define __P110 PAGE_READ -#define __P111 PAGE_READ - -#define __S000 PAGE_NONE -#define __S001 PAGE_READ -#define __S010 PAGE_WRITE -#define __S011 PAGE_WRITE -#define __S100 PAGE_READ -#define __S101 PAGE_READ -#define __S110 PAGE_WRITE -#define __S111 PAGE_WRITE -extern unsigned long empty_zero_page[PAGE_SIZE /sizeof (unsigned long )];#define ZERO_PAGE (vaddr) (virt_to_page(empty_zero_page))
arch/csky/mm/init.c +32 -0
@@ -197,3 +197,35 @@ void __init fixaddr_init(void) vaddr =__fix_to_virt (__end_of_fixed_addresses -1 ) &PMD_MASK ;fixrange_init (vaddr, vaddr +PMD_SIZE , swapper_pg_dir); } + +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{ +switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { +case VM_NONE : +return PAGE_NONE ; +case VM_READ : +case VM_WRITE : +case VM_WRITE |VM_READ : +case VM_EXEC : +case VM_EXEC |VM_READ : +case VM_EXEC |VM_WRITE : +case VM_EXEC |VM_WRITE |VM_READ : +return PAGE_READ ; +case VM_SHARED : +return PAGE_NONE ; +case VM_SHARED |VM_READ : +return PAGE_READ ; +case VM_SHARED |VM_WRITE : +case VM_SHARED |VM_WRITE |VM_READ : +return PAGE_WRITE ; +case VM_SHARED |VM_EXEC : +case VM_SHARED |VM_EXEC |VM_READ : +return PAGE_READ ; +case VM_SHARED |VM_EXEC |VM_WRITE : +case VM_SHARED |VM_EXEC |VM_WRITE |VM_READ : +return PAGE_WRITE ; +default : +BUILD_BUG (); + } +} +EXPORT_SYMBOL (vm_get_page_prot);
Signature · 1 line
2.25.1
Re: [PATCH V3 19/30] csky/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
Quoted 99 lines · Anshuman Khandual
This defines and exports a platform specific custom
vm_get_page_prot()via subscribingARCH_HAS_VM_GET_PAGE_PROT. Subsequently all__SXXXand__PXXXmacros can be dropped which are no longer needed.Cc Geert Uytterhoeven <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>--- arch/csky/Kconfig | 1 + arch/csky/include/asm/pgtable.h | 18 ------------------ arch/csky/mm/init.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 18 deletions(-)arch/csky/Kconfig +1
-0@@ -6,6 +6,7 @@ config CSKY select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_QUEUED_RWLOCKS select ARCH_WANT_FRAME_POINTERS if !CPU_CK610 && $(cc-option,-mbacktrace)arch/csky/include/asm/pgtable.h +0
-18@@ -76,24 +76,6 @@#define MAX_SWAPFILES_CHECK () \ BUILD_BUG_ON(MAX_SWAPFILES_SHIFT != 5) -#define __P000 PAGE_NONE -#define __P001 PAGE_READ -#define __P010 PAGE_READ -#define __P011 PAGE_READ -#define __P100 PAGE_READ -#define __P101 PAGE_READ -#define __P110 PAGE_READ -#define __P111 PAGE_READ - -#define __S000 PAGE_NONE -#define __S001 PAGE_READ -#define __S010 PAGE_WRITE -#define __S011 PAGE_WRITE -#define __S100 PAGE_READ -#define __S101 PAGE_READ -#define __S110 PAGE_WRITE -#define __S111 PAGE_WRITE -extern unsigned long empty_zero_page[PAGE_SIZE /sizeof (unsigned long )];#define ZERO_PAGE (vaddr) (virt_to_page(empty_zero_page))arch/csky/mm/init.c +32
-1@@ -197,3 +197,35 @@ void __init fixaddr_init(void) vaddr =__fix_to_virt (__end_of_fixed_addresses -1 ) &PMD_MASK ;fixrange_init (vaddr, vaddr +PMD_SIZE , swapper_pg_dir); } + +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{ +switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { +case VM_NONE : +return PAGE_NONE ; +case VM_READ : +case VM_WRITE : +case VM_WRITE |VM_READ : +case VM_EXEC : +case VM_EXEC |VM_READ : +case VM_EXEC |VM_WRITE : +case VM_EXEC |VM_WRITE |VM_READ : +return PAGE_READ ; +case VM_SHARED : +return PAGE_NONE ; +case VM_SHARED |VM_READ : +return PAGE_READ ; +case VM_SHARED |VM_WRITE : +case VM_SHARED |VM_WRITE |VM_READ : +return PAGE_WRITE ; +case VM_SHARED |VM_EXEC : +case VM_SHARED |VM_EXEC |VM_READ : +return PAGE_READ ; +case VM_SHARED |VM_EXEC |VM_WRITE : +case VM_SHARED |VM_EXEC |VM_WRITE |VM_READ : +return PAGE_WRITE ; +default : +BUILD_BUG (); + } +} +EXPORT_SYMBOL (vm_get_page_prot); --2.25.1
Signature · 4 lines
Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/
PATCH v3 20/30 xtensa/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/xtensa/Kconfig | 1 + arch/xtensa/include/asm/pgtable.h | 19 ----------------- arch/xtensa/mm/init.c | 35 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 19 deletions(-)
arch/xtensa/Kconfig +1 -0
@@ -9,6 +9,7 @@ config XTENSA select ARCH_HAS_DMA_SET_UNCACHED if MMU select ARCH_HAS_STRNCPY_FROM_USER if !KASAN select ARCH_HAS_STRNLEN_USER + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS
arch/xtensa/include/asm/pgtable.h +0 -19
@@ -198,26 +198,7 @@* the MMU can't do page protection for execute, and considers that the same as * read. Also, write permissions may imply read permissions. * What follows is the closest we can get by reasonable means.. -* See linux/mm/mmap.c for protection_map[] array that uses these definitions. */ -#define __P000 PAGE_NONE/* private --- */ -#define __P001 PAGE_READONLY/* private --r */ -#define __P010 PAGE_COPY/* private -w- */ -#define __P011 PAGE_COPY/* private -wr */ -#define __P100 PAGE_READONLY_EXEC/* private x-- */ -#define __P101 PAGE_READONLY_EXEC/* private x-r */ -#define __P110 PAGE_COPY_EXEC/* private xw- */ -#define __P111 PAGE_COPY_EXEC/* private xwr */ - -#define __S000 PAGE_NONE/* shared --- */ -#define __S001 PAGE_READONLY/* shared --r */ -#define __S010 PAGE_SHARED/* shared -w- */ -#define __S011 PAGE_SHARED/* shared -wr */ -#define __S100 PAGE_READONLY_EXEC/* shared x-- */ -#define __S101 PAGE_READONLY_EXEC/* shared x-r */ -#define __S110 PAGE_SHARED_EXEC/* shared xw- */ -#define __S111 PAGE_SHARED_EXEC/* shared xwr */ -#ifndef __ASSEMBLY__#define pte_ERROR (e) \
arch/xtensa/mm/init.c +35 -0
@@ -216,3 +216,38 @@ static int __init parse_memmap_opt(char *str)return 0 ; }early_param ("memmap" , parse_memmap_opt); + +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{ +switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { +case VM_NONE : +return PAGE_NONE ; +case VM_READ : +return PAGE_READONLY ; +case VM_WRITE : +case VM_WRITE |VM_READ : +return PAGE_COPY ; +case VM_EXEC : +case VM_EXEC |VM_READ : +return PAGE_READONLY_EXEC ; +case VM_EXEC |VM_WRITE : +case VM_EXEC |VM_WRITE |VM_READ : +return PAGE_COPY_EXEC ; +case VM_SHARED : +return PAGE_NONE ; +case VM_SHARED |VM_READ : +return PAGE_READONLY ; +case VM_SHARED |VM_WRITE : +case VM_SHARED |VM_WRITE |VM_READ : +return PAGE_SHARED ; +case VM_SHARED |VM_EXEC : +case VM_SHARED |VM_EXEC |VM_READ : +return PAGE_READONLY_EXEC ; +case VM_SHARED |VM_EXEC |VM_WRITE : +case VM_SHARED |VM_EXEC |VM_WRITE |VM_READ : +return PAGE_SHARED_EXEC ; +default : +BUILD_BUG (); + } +} +EXPORT_SYMBOL (vm_get_page_prot);
Signature · 1 line
2.25.1
PATCH v3 21/30 parisc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/parisc/Kconfig | 1 + arch/parisc/include/asm/pgtable.h | 20 ---------------- arch/parisc/mm/init.c | 40 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 20 deletions(-)
arch/parisc/Kconfig +1 -0
@@ -10,6 +10,7 @@ config PARISC select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_UBSAN_SANITIZE_ALL + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_NO_SG_CHAIN select ARCH_SUPPORTS_HUGETLBFS if PA20 select ARCH_SUPPORTS_MEMORY_FAILURE
arch/parisc/include/asm/pgtable.h +0 -20
@@ -269,26 +269,6 @@ extern void __update_cache(pte_t pte);* pages. */ -/*xwr*/ -#define __P000 PAGE_NONE -#define __P001 PAGE_READONLY -#define __P010 __P000/* copy on write */ -#define __P011 __P001/* copy on write */ -#define __P100 PAGE_EXECREAD -#define __P101 PAGE_EXECREAD -#define __P110 __P100/* copy on write */ -#define __P111 __P101/* copy on write */ - -#define __S000 PAGE_NONE -#define __S001 PAGE_READONLY -#define __S010 PAGE_WRITEONLY -#define __S011 PAGE_SHARED -#define __S100 PAGE_EXECREAD -#define __S101 PAGE_EXECREAD -#define __S110 PAGE_RWX -#define __S111 PAGE_RWX - -extern pgd_t swapper_pg_dir[];/* declared in init_task.c */ /* initial page tables for 0-8MB for kernel */
arch/parisc/mm/init.c +40 -0
@@ -865,3 +865,43 @@ void flush_tlb_all(void)spin_unlock (&sid_lock); }#endif + +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{ +switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { +case VM_NONE : +return PAGE_NONE ; +case VM_READ : +return PAGE_READONLY ; +/* copy on write */ +case VM_WRITE : +return PAGE_NONE ; +/* copy on write */ +case VM_WRITE |VM_READ : +return PAGE_READONLY ; +case VM_EXEC : +case VM_EXEC |VM_READ : +/* copy on write */ +case VM_EXEC |VM_WRITE : +/* copy on write */ +case VM_EXEC |VM_WRITE |VM_READ : +return PAGE_EXECREAD ; +case VM_SHARED : +return PAGE_NONE ; +case VM_SHARED |VM_READ : +return PAGE_READONLY ; +case VM_SHARED |VM_WRITE : +return PAGE_WRITEONLY ; +case VM_SHARED |VM_WRITE |VM_READ : +return PAGE_SHARED ; +case VM_SHARED |VM_EXEC : +case VM_SHARED |VM_EXEC |VM_READ : +return PAGE_EXECREAD ; +case VM_SHARED |VM_EXEC |VM_WRITE : +case VM_SHARED |VM_EXEC |VM_WRITE |VM_READ : +return PAGE_RWX ; +default : +BUILD_BUG (); + } +} +EXPORT_SYMBOL (vm_get_page_prot);
Signature · 1 line
2.25.1
PATCH v3 22/30 openrisc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/openrisc/Kconfig | 1 + arch/openrisc/include/asm/pgtable.h | 18 ------------- arch/openrisc/mm/init.c | 41 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 18 deletions(-)
arch/openrisc/Kconfig +1 -0
@@ -10,6 +10,7 @@ config OPENRISC select ARCH_HAS_DMA_SET_UNCACHED select ARCH_HAS_DMA_CLEAR_UNCACHED select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select ARCH_HAS_VM_GET_PAGE_PROT select COMMON_CLK select OF select OF_EARLY_FLATTREE
arch/openrisc/include/asm/pgtable.h +0 -18
@@ -176,24 +176,6 @@ extern void paging_init(void);__pgprot (_PAGE_ALL | _PAGE_SRE | _PAGE_SWE \ | _PAGE_SHARED | _PAGE_DIRTY | _PAGE_EXEC | _PAGE_CI) -#define __P000 PAGE_NONE -#define __P001 PAGE_READONLY_X -#define __P010 PAGE_COPY -#define __P011 PAGE_COPY_X -#define __P100 PAGE_READONLY -#define __P101 PAGE_READONLY_X -#define __P110 PAGE_COPY -#define __P111 PAGE_COPY_X - -#define __S000 PAGE_NONE -#define __S001 PAGE_READONLY_X -#define __S010 PAGE_SHARED -#define __S011 PAGE_SHARED_X -#define __S100 PAGE_READONLY -#define __S101 PAGE_READONLY_X -#define __S110 PAGE_SHARED -#define __S111 PAGE_SHARED_X - /* zero page used for uninitialized stuff */extern unsigned long empty_zero_page[2048 ];#define ZERO_PAGE (vaddr) (virt_to_page(empty_zero_page))
arch/openrisc/mm/init.c +41 -0
44 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 23/30 um/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/um/Kconfig | 1 + arch/um/include/asm/pgtable.h | 17 ----------------- arch/um/kernel/mem.c | 35 +++++++++++++++++++++++++++++++++++ arch/x86/um/mem_32.c | 2 +- 4 files changed, 37 insertions(+), 18 deletions(-)
arch/um/Kconfig +1 -0
@@ -9,6 +9,7 @@ config UML select ARCH_HAS_KCOV select ARCH_HAS_STRNCPY_FROM_USER select ARCH_HAS_STRNLEN_USER + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_NO_PREEMPT select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_SECCOMP_FILTER
arch/um/include/asm/pgtable.h +0 -17
@@ -68,23 +68,6 @@ extern unsigned long end_iomem;* Also, write permissions imply read permissions. This is the closest we can * get.. */ -#define __P000 PAGE_NONE -#define __P001 PAGE_READONLY -#define __P010 PAGE_COPY -#define __P011 PAGE_COPY -#define __P100 PAGE_READONLY -#define __P101 PAGE_READONLY -#define __P110 PAGE_COPY -#define __P111 PAGE_COPY - -#define __S000 PAGE_NONE -#define __S001 PAGE_READONLY -#define __S010 PAGE_SHARED -#define __S011 PAGE_SHARED -#define __S100 PAGE_READONLY -#define __S101 PAGE_READONLY -#define __S110 PAGE_SHARED -#define __S111 PAGE_SHARED/* * ZERO_PAGE is a global shared page that is always zero: used
arch/um/kernel/mem.c +35 -0
@@ -197,3 +197,38 @@ void *uml_kmalloc(int size, int flags) {return kmalloc (size, flags); } + +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{ +switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { +case VM_NONE : +return PAGE_NONE ; +case VM_READ : +return PAGE_READONLY ; +case VM_WRITE : +case VM_WRITE |VM_READ : +return PAGE_COPY ; +case VM_EXEC : +case VM_EXEC |VM_READ : +return PAGE_READONLY ; +case VM_EXEC |VM_WRITE : +case VM_EXEC |VM_WRITE |VM_READ : +return PAGE_COPY ; +case VM_SHARED : +return PAGE_NONE ; +case VM_SHARED |VM_READ : +return PAGE_READONLY ; +case VM_SHARED |VM_WRITE : +case VM_SHARED |VM_WRITE |VM_READ : +return PAGE_SHARED ; +case VM_SHARED |VM_EXEC : +case VM_SHARED |VM_EXEC |VM_READ : +return PAGE_READONLY ; +case VM_SHARED |VM_EXEC |VM_WRITE : +case VM_SHARED |VM_EXEC |VM_WRITE |VM_READ : +return PAGE_SHARED ; +default : +BUILD_BUG (); + } +} +EXPORT_SYMBOL (vm_get_page_prot);
arch/x86/um/mem_32.c +1 -1
@@ -17,7 +17,7 @@ static int __init gate_vma_init(void) gate_vma.vm_start =FIXADDR_USER_START ; gate_vma.vm_end =FIXADDR_USER_END ; gate_vma.vm_flags =VM_READ |VM_MAYREAD |VM_EXEC |VM_MAYEXEC ; - gate_vma.vm_page_prot = __P101; + gate_vma.vm_page_prot =PAGE_READONLY ;return 0 ; }
Signature · 1 line
2.25.1
PATCH v3 24/30 microblaze/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/microblaze/Kconfig | 1 + arch/microblaze/include/asm/pgtable.h | 17 ----------- arch/microblaze/mm/init.c | 41 +++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 17 deletions(-)
arch/microblaze/Kconfig +1 -0
@@ -7,6 +7,7 @@ config MICROBLAZE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_WANT_IPC_PARSE_VERSION select BUILDTIME_TABLE_SORT
arch/microblaze/include/asm/pgtable.h +0 -17
@@ -204,23 +204,6 @@ extern pte_t *va_to_pte(unsigned long address);* We consider execute permission the same as read. * Also, write permissions imply read permissions. */ -#define __P000 PAGE_NONE -#define __P001 PAGE_READONLY_X -#define __P010 PAGE_COPY -#define __P011 PAGE_COPY_X -#define __P100 PAGE_READONLY -#define __P101 PAGE_READONLY_X -#define __P110 PAGE_COPY -#define __P111 PAGE_COPY_X - -#define __S000 PAGE_NONE -#define __S001 PAGE_READONLY_X -#define __S010 PAGE_SHARED -#define __S011 PAGE_SHARED_X -#define __S100 PAGE_READONLY -#define __S101 PAGE_READONLY_X -#define __S110 PAGE_SHARED -#define __S111 PAGE_SHARED_X#ifndef __ASSEMBLY__/*
arch/microblaze/mm/init.c +41 -0
44 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 25/30 nios2/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/nios2/Kconfig | 1 + arch/nios2/include/asm/pgtable.h | 24 ---------------- arch/nios2/mm/init.c | 47 ++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 24 deletions(-)
arch/nios2/Kconfig +1 -0
@@ -6,6 +6,7 @@ config NIOS2 select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_HAS_DMA_SET_UNCACHED + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_NO_SWAP select COMMON_CLK select TIMER_OF
arch/nios2/include/asm/pgtable.h +0 -24
@@ -34,30 +34,6 @@ struct mm_struct; ((x) ? _PAGE_EXEC : 0) | \ ((r) ? _PAGE_READ : 0) | \ ((w) ? _PAGE_WRITE : 0)) -/* -* These are the macros that generic kernel code needs -* (to populate protection_map[]) -*/ - -/* Remove W bit on private pages for COW support */ -#define __P000 MKP(0, 0, 0) -#define __P001 MKP(0, 0, 1) -#define __P010 MKP(0, 0, 0)/* COW */ -#define __P011 MKP(0, 0, 1)/* COW */ -#define __P100 MKP(1, 0, 0) -#define __P101 MKP(1, 0, 1) -#define __P110 MKP(1, 0, 0)/* COW */ -#define __P111 MKP(1, 0, 1)/* COW */ - -/* Shared pages can have exact HW mapping */ -#define __S000 MKP(0, 0, 0) -#define __S001 MKP(0, 0, 1) -#define __S010 MKP(0, 1, 0) -#define __S011 MKP(0, 1, 1) -#define __S100 MKP(1, 0, 0) -#define __S101 MKP(1, 0, 1) -#define __S110 MKP(1, 1, 0) -#define __S111 MKP(1, 1, 1)/* Used all over the kernel */ #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_CACHED | _PAGE_READ | \
arch/nios2/mm/init.c +47 -0
50 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 26/30 hexagon/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/hexagon/Kconfig | 1 + arch/hexagon/include/asm/pgtable.h | 24 ----------- arch/hexagon/mm/init.c | 67 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 24 deletions(-)
arch/hexagon/Kconfig +1 -0
@@ -6,6 +6,7 @@ config HEXAGON def_bool y select ARCH_32BIT_OFF_T select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_NO_PREEMPT select DMA_GLOBAL_POOL # Other pending projects/to-do items.
arch/hexagon/include/asm/pgtable.h +0 -24
@@ -127,31 +127,7 @@ extern unsigned long _dflt_cache_att;#define CACHEDEF (CACHE_DEFAULT << 6)/* Private (copy-on-write) page protections. */ -#define __P000 __pgprot(_PAGE_PRESENT | _PAGE_USER | CACHEDEF) -#define __P001 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | CACHEDEF) -#define __P010 __P000/* Write-only copy-on-write */ -#define __P011 __P001/* Read/Write copy-on-write */ -#define __P100 __pgprot(_PAGE_PRESENT | _PAGE_USER | \ - _PAGE_EXECUTE | CACHEDEF) -#define __P101 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_EXECUTE | \ - _PAGE_READ | CACHEDEF) -#define __P110 __P100/* Write/execute copy-on-write */ -#define __P111 __P101/* Read/Write/Execute, copy-on-write */ -/* Shared page protections. */ -#define __S000 __P000 -#define __S001 __P001 -#define __S010 __pgprot(_PAGE_PRESENT | _PAGE_USER | \ - _PAGE_WRITE | CACHEDEF) -#define __S011 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | \ - _PAGE_WRITE | CACHEDEF) -#define __S100 __pgprot(_PAGE_PRESENT | _PAGE_USER | \ - _PAGE_EXECUTE | CACHEDEF) -#define __S101 __P101 -#define __S110 __pgprot(_PAGE_PRESENT | _PAGE_USER | \ - _PAGE_EXECUTE | _PAGE_WRITE | CACHEDEF) -#define __S111 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | \ - _PAGE_EXECUTE | _PAGE_WRITE | CACHEDEF)extern pgd_t swapper_pg_dir[PTRS_PER_PGD ];/* located in head.S */
arch/hexagon/mm/init.c +67 -0
70 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 27/30 nds32/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/nds32/Kconfig | 1 + arch/nds32/include/asm/pgtable.h | 17 --------------- arch/nds32/mm/mmap.c | 37 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 17 deletions(-)
arch/nds32/Kconfig +1 -0
@@ -10,6 +10,7 @@ config NDS32 select ARCH_HAS_DMA_PREP_COHERENT select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_WANT_FRAME_POINTERS if FTRACE select CLKSRC_MMIO select CLONE_BACKWARDS
arch/nds32/include/asm/pgtable.h +0 -17
@@ -152,23 +152,6 @@ extern void __pgd_error(const char *file, int line, unsigned long val);#endif /* __ASSEMBLY__ */ /* xwr */ -#define __P000 (PAGE_NONE | _PAGE_CACHE_SHRD) -#define __P001 (PAGE_READ | _PAGE_CACHE_SHRD) -#define __P010 (PAGE_COPY | _PAGE_CACHE_SHRD) -#define __P011 (PAGE_COPY | _PAGE_CACHE_SHRD) -#define __P100 (PAGE_EXEC | _PAGE_CACHE_SHRD) -#define __P101 (PAGE_READ | _PAGE_E | _PAGE_CACHE_SHRD) -#define __P110 (PAGE_COPY | _PAGE_E | _PAGE_CACHE_SHRD) -#define __P111 (PAGE_COPY | _PAGE_E | _PAGE_CACHE_SHRD) - -#define __S000 (PAGE_NONE | _PAGE_CACHE_SHRD) -#define __S001 (PAGE_READ | _PAGE_CACHE_SHRD) -#define __S010 (PAGE_RDWR | _PAGE_CACHE_SHRD) -#define __S011 (PAGE_RDWR | _PAGE_CACHE_SHRD) -#define __S100 (PAGE_EXEC | _PAGE_CACHE_SHRD) -#define __S101 (PAGE_READ | _PAGE_E | _PAGE_CACHE_SHRD) -#define __S110 (PAGE_RDWR | _PAGE_E | _PAGE_CACHE_SHRD) -#define __S111 (PAGE_RDWR | _PAGE_E | _PAGE_CACHE_SHRD)#ifndef __ASSEMBLY__/*
arch/nds32/mm/mmap.c +37 -0
@@ -71,3 +71,40 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, info.align_offset = pgoff <<PAGE_SHIFT ;return vm_unmapped_area (&info); } + +pgprot_t vm_get_page_prot (unsigned long vm_flags) +{ +switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { +case VM_NONE : +return (PAGE_NONE | _PAGE_CACHE_SHRD); +case VM_READ : +return (PAGE_READ | _PAGE_CACHE_SHRD); +case VM_WRITE : +case VM_WRITE |VM_READ : +return (PAGE_COPY | _PAGE_CACHE_SHRD); +case VM_EXEC : +return (PAGE_EXEC | _PAGE_CACHE_SHRD); +case VM_EXEC |VM_READ : +return (PAGE_READ | _PAGE_E | _PAGE_CACHE_SHRD); +case VM_EXEC |VM_WRITE : +case VM_EXEC |VM_WRITE |VM_READ : +return (PAGE_COPY | _PAGE_E | _PAGE_CACHE_SHRD); +case VM_SHARED : +return (PAGE_NONE | _PAGE_CACHE_SHRD); +case VM_SHARED |VM_READ : +return (PAGE_READ | _PAGE_CACHE_SHRD); +case VM_SHARED |VM_WRITE : +case VM_SHARED |VM_WRITE |VM_READ : +return (PAGE_RDWR | _PAGE_CACHE_SHRD); +case VM_SHARED |VM_EXEC : +return (PAGE_EXEC | _PAGE_CACHE_SHRD); +case VM_SHARED |VM_EXEC |VM_READ : +return (PAGE_READ | _PAGE_E | _PAGE_CACHE_SHRD); +case VM_SHARED |VM_EXEC |VM_WRITE : +case VM_SHARED |VM_EXEC |VM_WRITE |VM_READ : +return (PAGE_RDWR | _PAGE_E | _PAGE_CACHE_SHRD); +default : +BUILD_BUG (); + } +} +EXPORT_SYMBOL (vm_get_page_prot);
Signature · 1 line
2.25.1
PATCH v3 28/30 ia64/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualThis defines and exports a platform specific custom vm_get_page_prot() via subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX macros can be dropped which are no longer needed.
--- arch/ia64/Kconfig | 1 + arch/ia64/include/asm/pgtable.h | 17 -------------- arch/ia64/mm/init.c | 41 ++++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 18 deletions(-)
arch/ia64/Kconfig +1 -0
@@ -11,6 +11,7 @@ config IA64 select ARCH_HAS_DMA_MARK_CLEAN select ARCH_HAS_STRNCPY_FROM_USER select ARCH_HAS_STRNLEN_USER + select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO select ACPI
arch/ia64/include/asm/pgtable.h +0 -17
@@ -161,23 +161,6 @@* attempts to write to the page. */ /* xwr */ -#define __P000 PAGE_NONE -#define __P001 PAGE_READONLY -#define __P010 PAGE_READONLY/* write to priv pg -> copy & make writable */ -#define __P011 PAGE_READONLY/* ditto */ -#define __P100 __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_X_RX) -#define __P101 __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX) -#define __P110 PAGE_COPY_EXEC -#define __P111 PAGE_COPY_EXEC - -#define __S000 PAGE_NONE -#define __S001 PAGE_READONLY -#define __S010 PAGE_SHARED/* we don't have (and don't need) write-only */ -#define __S011 PAGE_SHARED -#define __S100 __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_X_RX) -#define __S101 __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX) -#define __S110 __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RWX) -#define __S111 __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RWX)#define pgd_ERROR (e) printk("%s:%d: bad pgd %016lx.\n", __FILE__, __LINE__, pgd_val(e))#if CONFIG_PGTABLE_LEVELS ==4
arch/ia64/mm/init.c +40 -1
50 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 29/30 mm/mmap: Drop generic vm_get_page_prot()
In reply to Anshuman KhandualAll available platforms export their own vm_get_page_prot() implementation via ARCH_HAS_VM_GET_PAGE_PROT. Hence a generic implementation is no longer needed.
--- mm/mmap.c | 40 ---------------------------------------- 1 file changed, 40 deletions(-)
mm/mmap.c +0 -40
@@ -102,46 +102,6 @@ static void unmap_region(struct mm_struct *mm,* w: (no) no * x: (yes) yes */ -pgprot_t vm_get_page_prot (unsigned long vm_flags) -{ -switch (vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) { -case VM_NONE : -return __P000; -case VM_READ : -return __P001; -case VM_WRITE : -return __P010; -case VM_READ |VM_WRITE : -return __P011; -case VM_EXEC : -return __P100; -case VM_EXEC |VM_READ : -return __P101; -case VM_EXEC |VM_WRITE : -return __P110; -case VM_EXEC |VM_READ |VM_WRITE : -return __P111; -case VM_SHARED : -return __S000; -case VM_SHARED |VM_READ : -return __S001; -case VM_SHARED |VM_WRITE : -return __S010; -case VM_SHARED |VM_READ |VM_WRITE : -return __S011; -case VM_SHARED |VM_EXEC : -return __S100; -case VM_SHARED |VM_EXEC |VM_READ : -return __S101; -case VM_SHARED |VM_EXEC |VM_WRITE : -return __S110; -case VM_SHARED |VM_EXEC |VM_READ |VM_WRITE : -return __S111; -default : -BUILD_BUG (); - } -} -EXPORT_SYMBOL (vm_get_page_prot);#endif /* CONFIG_ARCH_HAS_VM_GET_PAGE_PROT */ static pgprot_t vm_pgprot_modify (pgprot_t oldprot,unsigned long vm_flags)
Signature · 1 line
2.25.1
PATCH v3 30/30 mm/mmap: Drop ARCH_HAS_VM_GET_PAGE_PROT
In reply to Anshuman KhandualAll platforms now define their own vm_get_page_prot() and also there is no generic version left to fallback on. Hence drop ARCH_HAS_GET_PAGE_PROT.
--- arch/alpha/Kconfig | 1 - arch/arc/Kconfig | 1 - arch/arm/Kconfig | 1 - arch/arm64/Kconfig | 1 - arch/csky/Kconfig | 1 - arch/hexagon/Kconfig | 1 - arch/ia64/Kconfig | 1 - arch/m68k/Kconfig | 1 - arch/microblaze/Kconfig | 1 - arch/mips/Kconfig | 1 - arch/nds32/Kconfig | 1 - arch/nios2/Kconfig | 1 - arch/openrisc/Kconfig | 1 - arch/parisc/Kconfig | 1 - arch/powerpc/Kconfig | 1 - arch/riscv/Kconfig | 1 - arch/s390/Kconfig | 1 - arch/sh/Kconfig | 1 - arch/sparc/Kconfig | 2 -- arch/um/Kconfig | 1 - arch/x86/Kconfig | 1 - arch/xtensa/Kconfig | 1 - mm/Kconfig | 3 --- mm/mmap.c | 23 ----------------------- 24 files changed, 49 deletions(-)
arch/alpha/Kconfig +0 -1
@@ -2,7 +2,6 @@ config ALPHA bool default y - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_32BIT_USTAT_F_TINODE select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO
arch/arc/Kconfig +0 -1
@@ -13,7 +13,6 @@ config ARC select ARCH_HAS_SETUP_DMA_OPS select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_SUPPORTS_ATOMIC_RMW if ARC_HAS_LLSC select ARCH_32BIT_OFF_T select BUILDTIME_TABLE_SORT
arch/arm/Kconfig +0 -1
@@ -23,7 +23,6 @@ config ARM select ARCH_HAS_SYNC_DMA_FOR_CPU if SWIOTLB || !MMU select ARCH_HAS_TEARDOWN_DMA_OPS if MMU select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HAVE_CUSTOM_GPIO_H select ARCH_HAVE_NMI_SAFE_CMPXCHG if CPU_V7 || CPU_V7M || CPU_V6K select ARCH_HAS_GCOV_PROFILE_ALL
arch/arm64/Kconfig +0 -1
@@ -43,7 +43,6 @@ config ARM64 select ARCH_HAS_SYSCALL_WRAPPER select ARCH_HAS_TEARDOWN_DMA_OPS if IOMMU_SUPPORT select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HAS_ZONE_DMA_SET if EXPERT select ARCH_HAVE_ELF_PROT select ARCH_HAVE_NMI_SAFE_CMPXCHG
arch/csky/Kconfig +0 -1
@@ -6,7 +6,6 @@ config CSKY select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_QUEUED_RWLOCKS select ARCH_WANT_FRAME_POINTERS if !CPU_CK610 && $(cc-option,-mbacktrace)
arch/hexagon/Kconfig +0 -1
@@ -6,7 +6,6 @@ config HEXAGON def_bool y select ARCH_32BIT_OFF_T select ARCH_HAS_SYNC_DMA_FOR_DEVICE - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_NO_PREEMPT select DMA_GLOBAL_POOL # Other pending projects/to-do items.
arch/ia64/Kconfig +0 -1
@@ -11,7 +11,6 @@ config IA64 select ARCH_HAS_DMA_MARK_CLEAN select ARCH_HAS_STRNCPY_FROM_USER select ARCH_HAS_STRNLEN_USER - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO select ACPI
arch/m68k/Kconfig +0 -1
@@ -11,7 +11,6 @@ config M68K select ARCH_NO_PREEMPT if !COLDFIRE select ARCH_USE_MEMTEST if MMU_MOTOROLA select ARCH_WANT_IPC_PARSE_VERSION - select ARCH_HAS_VM_GET_PAGE_PROT select BINFMT_FLAT_ARGVP_ENVP_ON_STACK select DMA_DIRECT_REMAP if HAS_DMA && MMU && !COLDFIRE select GENERIC_ATOMIC64
arch/microblaze/Kconfig +0 -1
@@ -7,7 +7,6 @@ config MICROBLAZE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_WANT_IPC_PARSE_VERSION select BUILDTIME_TABLE_SORT
arch/mips/Kconfig +0 -1
@@ -13,7 +13,6 @@ config MIPS select ARCH_HAS_STRNLEN_USER select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAS_UBSAN_SANITIZE_ALL - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_KEEP_MEMBLOCK select ARCH_SUPPORTS_UPROBES
arch/nds32/Kconfig +0 -1
@@ -10,7 +10,6 @@ config NDS32 select ARCH_HAS_DMA_PREP_COHERENT select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_WANT_FRAME_POINTERS if FTRACE select CLKSRC_MMIO select CLONE_BACKWARDS
arch/nios2/Kconfig +0 -1
@@ -6,7 +6,6 @@ config NIOS2 select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_HAS_DMA_SET_UNCACHED - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_NO_SWAP select COMMON_CLK select TIMER_OF
arch/openrisc/Kconfig +0 -1
@@ -10,7 +10,6 @@ config OPENRISC select ARCH_HAS_DMA_SET_UNCACHED select ARCH_HAS_DMA_CLEAR_UNCACHED select ARCH_HAS_SYNC_DMA_FOR_DEVICE - select ARCH_HAS_VM_GET_PAGE_PROT select COMMON_CLK select OF select OF_EARLY_FLATTREE
arch/parisc/Kconfig +0 -1
@@ -10,7 +10,6 @@ config PARISC select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_UBSAN_SANITIZE_ALL - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_NO_SG_CHAIN select ARCH_SUPPORTS_HUGETLBFS if PA20 select ARCH_SUPPORTS_MEMORY_FAILURE
arch/powerpc/Kconfig +0 -1
@@ -135,7 +135,6 @@ config PPC select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAS_UACCESS_FLUSHCACHE select ARCH_HAS_UBSAN_SANITIZE_ALL - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_KEEP_MEMBLOCK select ARCH_MIGHT_HAVE_PC_PARPORT
arch/riscv/Kconfig +0 -1
@@ -31,7 +31,6 @@ config RISCV select ARCH_HAS_STRICT_MODULE_RWX if MMU && !XIP_KERNEL select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAS_UBSAN_SANITIZE_ALL - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT select ARCH_STACKWALK
arch/s390/Kconfig +0 -1
@@ -78,7 +78,6 @@ config S390 select ARCH_HAS_SYSCALL_WRAPPER select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAS_VDSO_DATA - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_INLINE_READ_LOCK select ARCH_INLINE_READ_LOCK_BH
arch/sh/Kconfig +0 -1
@@ -11,7 +11,6 @@ config SUPERH select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HIBERNATION_POSSIBLE if MMU select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_WANT_IPC_PARSE_VERSION
arch/sparc/Kconfig +0 -2
@@ -59,7 +59,6 @@ config SPARC32 select HAVE_UID16 select OLD_SIGACTION select ZONE_DMA - select ARCH_HAS_VM_GET_PAGE_PROT config SPARC64 def_bool 64BIT
@@ -85,7 +84,6 @@ config SPARC64 select PERF_USE_VMALLOC select ARCH_HAVE_NMI_SAFE_CMPXCHG select HAVE_C_RECORDMCOUNT - select ARCH_HAS_VM_GET_PAGE_PROT select HAVE_ARCH_AUDITSYSCALL select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_DEBUG_PAGEALLOC
arch/um/Kconfig +0 -1
@@ -9,7 +9,6 @@ config UML select ARCH_HAS_KCOV select ARCH_HAS_STRNCPY_FROM_USER select ARCH_HAS_STRNLEN_USER - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_NO_PREEMPT select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_SECCOMP_FILTER
arch/x86/Kconfig +0 -1
@@ -93,7 +93,6 @@ config X86 select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE select ARCH_HAS_SYSCALL_WRAPPER select ARCH_HAS_UBSAN_SANITIZE_ALL - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_HAS_DEBUG_WX select ARCH_HAS_ZONE_DMA_SET if EXPERT select ARCH_HAVE_NMI_SAFE_CMPXCHG
arch/xtensa/Kconfig +0 -1
@@ -9,7 +9,6 @@ config XTENSA select ARCH_HAS_DMA_SET_UNCACHED if MMU select ARCH_HAS_STRNCPY_FROM_USER if !KASAN select ARCH_HAS_STRNLEN_USER - select ARCH_HAS_VM_GET_PAGE_PROT select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS
mm/Kconfig +0 -3
@@ -744,9 +744,6 @@ config IDLE_PAGE_TRACKING config ARCH_HAS_CACHE_LINE_SIZE bool -config ARCH_HAS_VM_GET_PAGE_PROT - bool - config ARCH_HAS_PTE_DEVMAP bool
mm/mmap.c +0 -23
@@ -81,29 +81,6 @@ static void unmap_region(struct mm_struct *mm, struct vm_area_struct *vma, struct vm_area_struct *prev, unsigned long start, unsigned long end); -#ifndef CONFIG_ARCH_HAS_VM_GET_PAGE_PROT -/* description of effects of mapping type and prot in current implementation. -* this is due to the limited x86 page protection hardware. The expected -* behavior is in parens: -* -* map_type prot -* PROT_NONE PROT_READ PROT_WRITE PROT_EXEC -* MAP_SHARED r: (no) no r: (yes) yes r: (no) yes r: (no) yes -* w: (no) no w: (no) no w: (yes) yes w: (no) no -* x: (no) no x: (no) yes x: (no) yes x: (yes) yes -* -* MAP_PRIVATE r: (no) no r: (yes) yes r: (no) yes r: (no) yes -* w: (no) no w: (no) no w: (copy) copy w: (no) no -* x: (no) no x: (no) yes x: (no) yes x: (yes) yes -* -* On arm64, PROT_EXEC has the following behaviour for both MAP_SHARED and -* MAP_PRIVATE (with Enhanced PAN supported): -* r: (no) no -* w: (no) no -* x: (yes) yes -*/ -#endif /* CONFIG_ARCH_HAS_VM_GET_PAGE_PROT */ -static pgprot_t vm_pgprot_modify (pgprot_t oldprot,unsigned long vm_flags) {return pgprot_modify (oldprot,vm_get_page_prot (vm_flags));
Signature · 1 line
2.25.1
Quoted 96 lines · Anshuman Khandual
protection_map[] is an array based construct that translates given
vm_flagscombination. This array contains page protection map, which is populated by the platform via [__S000..__S111] and [__P000..__P111] exported macros. Primary usage for protection_map[] is forvm_get_page_prot(), which is used to determine page protection value for a givenvm_flags.vm_get_page_prot()implementation, could again call platform overridesarch_vm_get_page_prot()andarch_filter_pgprot(). Some platforms override protection_map[] that was originally built with __SXXX/__PXXX with different runtime values.Currently there are multiple layers of abstraction i.e __SXXX/__PXXX macros , protection_map[],
arch_vm_get_page_prot()andarch_filter_pgprot()built between the platform and generic MM, finally definingvm_get_page_prot().Hence this series proposes to drop all these abstraction levels and instead just move the responsibility of defining
vm_get_page_prot()to the platform itself making it clean and simple.This first introduces
ARCH_HAS_VM_GET_PAGE_PROTwhich enables the platforms to define customvm_get_page_prot(). This starts converting platforms that either change protection_map[] or define the overridesarch_filter_pgprot()orarch_vm_get_page_prot()which enables for those constructs to be dropped off completely. This series then converts remaining platforms which enables for __SXXX/__PXXX constructs to be dropped off completely. Finally it drops the genericvm_get_page_prot()and thenARCH_HAS_VM_GET_PAGE_PROTas every platform now defines their ownvm_get_page_prot().The series has been inspired from an earlier discuss with Christoph Hellwig
https://lore.kernel.org/all/[email protected]/
This series applies on 5.17-rc6 after the following patch.
https://lore.kernel.org/all/[email protected]/
This series has been cross built for multiple platforms.
- Anshuman
Cc Christoph Hellwig <[email protected]>Cc Andrew Morton <[email protected]>Changes in V3:
- Dropped variable 'i' from
sme_early_init()on x86 platform
- MovedCONFIG_COLDFIREvm_get_page_prot()insidearch/m68k/mm/mcfmmu.c
- MovedCONFIG_SUN3vm_get_page_prot()insidearch/m68k/mm/sun3mmu.c
- Dropped cachebits forvm_get_page_prot()insidearch/m68k/mm/motorola.c
- DroppedPAGE_XXX_Cdefinitions fromarch/m68k/include/asm/motorola_pgtable.h
- UsedPAGE_XXXinstead forvm_get_page_prot()insidearch/m68k/mm/motorola.c
- Dropped all references to protection_map[] in the tree
- Replaced s/extensa/xtensa/ on the patch title
- Moved left over comments frompgtable.hintoinit.con nios2 platformChanges in V2:
https://lore.kernel.org/all/[email protected]/
- Dropped the entire comment block in [PATCH 30/30] per Geert
- Replaced__P010(although commented) with__PAGE_COPYon arm platform
- Replaced__P101withPAGE_READONLYon um platformChanges in V1:
https://lore.kernel.org/all/[email protected]/
- Add white spaces around the | operators
- Movedpowerpc_vm_get_page_prot()nearvm_get_page_prot()on powerpc
- Movedarm64_vm_get_page_prot()nearvm_get_page_prot()on arm64
- Movedsparc_vm_get_page_prot()nearvm_get_page_prot()on sparc
- Compactedvm_get_page_prot()switch cases on all platforms
-_PAGE_CACHE040inclusion is dependent onCPU_IS_040_OR_060
-VM_SHAREDcase should returnPAGE_NONE(notPAGE_COPY) on SH platform
- ReorganizedVM_SHARED,VM_EXEC,VM_WRITE,VM_READ
- Dropped the last patch [RFC V1 31/31] which added macros forvm_flagscombinations
https://lore.kernel.org/all/[email protected]/
Quoted 7 lines
Changes in RFC:
https://lore.kernel.org/all/[email protected]/
Anshuman Khandual (29):
mm/debug_vm_pgtable: Drop protection_map[] usage mm/mmap: Clarify protection_map[] indices
Hello Andrew,
I am planning to rework this series later, as it is already some what late for the next merge window. I am wondering if you could consider just these above two independent patches for v5.18-rc1 ?
- Anshuman