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

um/mm: enable ARCH_HAS_VM_GET_PAGE_PROT

This enables ARCH_HAS_VM_GET_PAGE_PROT on the platform and exports
standard vm_get_page_prot() implementation via DECLARE_VM_GET_PAGE_PROT,
which looks up a private and static protection_map[] array. Subsequently
all __SXXX and __PXXX macros can be dropped which are no longer needed.

Link: https://lkml.kernel.org/r/20220711070600.2378316-25-anshuman.khandual@arm.com
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Brian Cain <bcain@quicinc.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Chris Zankel <chris@zankel.net>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Dinh Nguyen <dinguyen@kernel.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Guo Ren <guoren@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Rich Felker <dalias@libc.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Stafford Horne <shorne@gmail.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vineet Gupta <vgupta@kernel.org>
Cc: WANG Xuerui <kernel@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Anshuman Khandual and committed by
akpm
91a8da02 ca26f936

+22 -18
+1
arch/um/Kconfig
··· 10 10 select ARCH_HAS_KCOV 11 11 select ARCH_HAS_STRNCPY_FROM_USER 12 12 select ARCH_HAS_STRNLEN_USER 13 + select ARCH_HAS_VM_GET_PAGE_PROT 13 14 select ARCH_NO_PREEMPT 14 15 select HAVE_ARCH_AUDITSYSCALL 15 16 select HAVE_ARCH_SECCOMP_FILTER
-17
arch/um/include/asm/pgtable.h
··· 68 68 * Also, write permissions imply read permissions. This is the closest we can 69 69 * get.. 70 70 */ 71 - #define __P000 PAGE_NONE 72 - #define __P001 PAGE_READONLY 73 - #define __P010 PAGE_COPY 74 - #define __P011 PAGE_COPY 75 - #define __P100 PAGE_READONLY 76 - #define __P101 PAGE_READONLY 77 - #define __P110 PAGE_COPY 78 - #define __P111 PAGE_COPY 79 - 80 - #define __S000 PAGE_NONE 81 - #define __S001 PAGE_READONLY 82 - #define __S010 PAGE_SHARED 83 - #define __S011 PAGE_SHARED 84 - #define __S100 PAGE_READONLY 85 - #define __S101 PAGE_READONLY 86 - #define __S110 PAGE_SHARED 87 - #define __S111 PAGE_SHARED 88 71 89 72 /* 90 73 * ZERO_PAGE is a global shared page that is always zero: used
+20
arch/um/kernel/mem.c
··· 197 197 { 198 198 return kmalloc(size, flags); 199 199 } 200 + 201 + static const pgprot_t protection_map[16] = { 202 + [VM_NONE] = PAGE_NONE, 203 + [VM_READ] = PAGE_READONLY, 204 + [VM_WRITE] = PAGE_COPY, 205 + [VM_WRITE | VM_READ] = PAGE_COPY, 206 + [VM_EXEC] = PAGE_READONLY, 207 + [VM_EXEC | VM_READ] = PAGE_READONLY, 208 + [VM_EXEC | VM_WRITE] = PAGE_COPY, 209 + [VM_EXEC | VM_WRITE | VM_READ] = PAGE_COPY, 210 + [VM_SHARED] = PAGE_NONE, 211 + [VM_SHARED | VM_READ] = PAGE_READONLY, 212 + [VM_SHARED | VM_WRITE] = PAGE_SHARED, 213 + [VM_SHARED | VM_WRITE | VM_READ] = PAGE_SHARED, 214 + [VM_SHARED | VM_EXEC] = PAGE_READONLY, 215 + [VM_SHARED | VM_EXEC | VM_READ] = PAGE_READONLY, 216 + [VM_SHARED | VM_EXEC | VM_WRITE] = PAGE_SHARED, 217 + [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] = PAGE_SHARED 218 + }; 219 + DECLARE_VM_GET_PAGE_PROT
+1 -1
arch/x86/um/mem_32.c
··· 17 17 gate_vma.vm_start = FIXADDR_USER_START; 18 18 gate_vma.vm_end = FIXADDR_USER_END; 19 19 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC; 20 - gate_vma.vm_page_prot = __P101; 20 + gate_vma.vm_page_prot = PAGE_READONLY; 21 21 22 22 return 0; 23 23 }