]> git.baikalelectronics.ru Git - kernel.git/commitdiff
loongarch/mm: enable ARCH_HAS_VM_GET_PAGE_PROT
authorAnshuman Khandual <anshuman.khandual@arm.com>
Mon, 11 Jul 2022 07:05:43 +0000 (12:35 +0530)
committerakpm <akpm@linux-foundation.org>
Mon, 18 Jul 2022 00:14:38 +0000 (17:14 -0700)
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-10-anshuman.khandual@arm.com
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: WANG Xuerui <kernel@xen0n.name>
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: Ingo Molnar <mingo@redhat.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Jeff Dike <jdike@addtoit.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: Will Deacon <will@kernel.org>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/loongarch/Kconfig
arch/loongarch/include/asm/pgtable-bits.h
arch/loongarch/mm/cache.c

index db2838cf8c02fca44f04dc76017300a441e7e75a..adf8cf6ec5d5a800d9d378518f0faeb778645217 100644 (file)
@@ -9,6 +9,7 @@ config LOONGARCH
        select ARCH_HAS_ACPI_TABLE_UPGRADE      if ACPI
        select ARCH_HAS_PHYS_TO_DMA
        select ARCH_HAS_PTE_SPECIAL
+       select ARCH_HAS_VM_GET_PAGE_PROT
        select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
        select ARCH_INLINE_READ_LOCK if !PREEMPTION
        select ARCH_INLINE_READ_LOCK_BH if !PREEMPTION
index 3badd112d9ab2158d364dc42af341b00143ee822..9ca147a29bab81040e7f9322c2331ca4c25c43b4 100644 (file)
                                 _PAGE_GLOBAL | _PAGE_KERN |  _CACHE_SUC)
 #define PAGE_KERNEL_WUC __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \
                                 _PAGE_GLOBAL | _PAGE_KERN |  _CACHE_WUC)
-
-#define __P000 __pgprot(_CACHE_CC | _PAGE_USER | _PAGE_PROTNONE | _PAGE_NO_EXEC | _PAGE_NO_READ)
-#define __P001 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_NO_EXEC)
-#define __P010 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_NO_EXEC)
-#define __P011 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_NO_EXEC)
-#define __P100 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT)
-#define __P101 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT)
-#define __P110 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT)
-#define __P111 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT)
-
-#define __S000 __pgprot(_CACHE_CC | _PAGE_USER | _PAGE_PROTNONE | _PAGE_NO_EXEC | _PAGE_NO_READ)
-#define __S001 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_NO_EXEC)
-#define __S010 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_NO_EXEC | _PAGE_WRITE)
-#define __S011 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_NO_EXEC | _PAGE_WRITE)
-#define __S100 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT)
-#define __S101 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT)
-#define __S110 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_WRITE)
-#define __S111 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_WRITE)
-
 #ifndef __ASSEMBLY__
 
 #define pgprot_noncached pgprot_noncached
index 9e5ce5aa73f740f181e4ea779527a71c7234ba43..e8c68dcf6ab20bb2d5000912534229343e8ea187 100644 (file)
@@ -139,3 +139,49 @@ void cpu_cache_init(void)
 
        shm_align_mask = PAGE_SIZE - 1;
 }
+
+static const pgprot_t protection_map[16] = {
+       [VM_NONE]                                       = __pgprot(_CACHE_CC | _PAGE_USER |
+                                                                  _PAGE_PROTNONE | _PAGE_NO_EXEC |
+                                                                  _PAGE_NO_READ),
+       [VM_READ]                                       = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT |
+                                                                  _PAGE_NO_EXEC),
+       [VM_WRITE]                                      = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT |
+                                                                  _PAGE_NO_EXEC),
+       [VM_WRITE | VM_READ]                            = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT |
+                                                                  _PAGE_NO_EXEC),
+       [VM_EXEC]                                       = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT),
+       [VM_EXEC | VM_READ]                             = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT),
+       [VM_EXEC | VM_WRITE]                            = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT),
+       [VM_EXEC | VM_WRITE | VM_READ]                  = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT),
+       [VM_SHARED]                                     = __pgprot(_CACHE_CC | _PAGE_USER |
+                                                                  _PAGE_PROTNONE | _PAGE_NO_EXEC |
+                                                                  _PAGE_NO_READ),
+       [VM_SHARED | VM_READ]                           = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT |
+                                                                  _PAGE_NO_EXEC),
+       [VM_SHARED | VM_WRITE]                          = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT |
+                                                                  _PAGE_NO_EXEC | _PAGE_WRITE),
+       [VM_SHARED | VM_WRITE | VM_READ]                = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT |
+                                                                  _PAGE_NO_EXEC | _PAGE_WRITE),
+       [VM_SHARED | VM_EXEC]                           = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT),
+       [VM_SHARED | VM_EXEC | VM_READ]                 = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT),
+       [VM_SHARED | VM_EXEC | VM_WRITE]                = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT |
+                                                                  _PAGE_WRITE),
+       [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ]      = __pgprot(_CACHE_CC | _PAGE_VALID |
+                                                                  _PAGE_USER | _PAGE_PRESENT |
+                                                                  _PAGE_WRITE)
+};
+DECLARE_VM_GET_PAGE_PROT