2022-02-14 19:41:38

by Anshuman Khandual

[permalink] [raw]
Subject: [PATCH 00/30] 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-rc3 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]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

Changes in V1:

- 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
extensa/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 | 18 ----
arch/arm/mm/mmu.c | 44 +++++++--
arch/arm64/Kconfig | 1 -
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 | 22 -----
arch/m68k/include/asm/sun3_pgtable.h | 22 -----
arch/m68k/mm/init.c | 104 ++++++++++++++++++++++
arch/m68k/mm/motorola.c | 48 +++++++++-
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 | 16 ----
arch/nios2/mm/init.c | 45 ++++++++++
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 | 4 -
arch/x86/mm/pgprot.c | 71 +++++++++++++++
arch/xtensa/include/asm/pgtable.h | 18 ----
arch/xtensa/mm/init.c | 35 ++++++++
include/linux/mm.h | 6 --
include/linux/mman.h | 4 -
mm/Kconfig | 3 -
mm/debug_vm_pgtable.c | 31 ++++---
mm/mmap.c | 22 -----
64 files changed, 1140 insertions(+), 683 deletions(-)
create mode 100644 arch/x86/mm/pgprot.c

--
2.25.1


2022-02-14 19:45:45

by Anshuman Khandual

[permalink] [raw]
Subject: [PATCH 22/30] openrisc/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT

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.

Cc: Jonas Bonn <[email protected]>
Cc: [email protected]
Cc: [email protected]
Acked-by: Stafford Horne <[email protected]>
Signed-off-by: Anshuman Khandual <[email protected]>
---
arch/openrisc/Kconfig | 1 +
arch/openrisc/include/asm/pgtable.h | 18 -------------
arch/openrisc/mm/init.c | 41 +++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig
index f724b3f1aeed..842a61426816 100644
--- a/arch/openrisc/Kconfig
+++ b/arch/openrisc/Kconfig
@@ -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
diff --git a/arch/openrisc/include/asm/pgtable.h b/arch/openrisc/include/asm/pgtable.h
index cdd657f80bfa..fe686c4b7065 100644
--- a/arch/openrisc/include/asm/pgtable.h
+++ b/arch/openrisc/include/asm/pgtable.h
@@ -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))
diff --git a/arch/openrisc/mm/init.c b/arch/openrisc/mm/init.c
index 97305bde1b16..0d06e3ebef5d 100644
--- a/arch/openrisc/mm/init.c
+++ b/arch/openrisc/mm/init.c
@@ -210,3 +210,44 @@ void __init mem_init(void)
mem_init_done = 1;
return;
}
+
+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_X;
+ case VM_WRITE:
+ return PAGE_COPY;
+ case VM_WRITE | VM_READ:
+ return PAGE_COPY_X;
+ case VM_EXEC:
+ return PAGE_READONLY;
+ case VM_EXEC | VM_READ:
+ return PAGE_READONLY_X;
+ case VM_EXEC | VM_WRITE:
+ return PAGE_COPY;
+ case VM_EXEC | VM_WRITE | VM_READ:
+ return PAGE_COPY_X;
+ case VM_SHARED:
+ return PAGE_NONE;
+ case VM_SHARED | VM_READ:
+ return PAGE_READONLY_X;
+ case VM_SHARED | VM_WRITE:
+ return PAGE_SHARED;
+ case VM_SHARED | VM_WRITE | VM_READ:
+ return PAGE_SHARED_X;
+ case VM_SHARED | VM_EXEC:
+ return PAGE_READONLY;
+ case VM_SHARED | VM_EXEC | VM_READ:
+ return PAGE_READONLY_X;
+ case VM_SHARED | VM_EXEC | VM_WRITE:
+ return PAGE_SHARED;
+ case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
+ return PAGE_SHARED_X;
+ default:
+ BUILD_BUG();
+ }
+}
+EXPORT_SYMBOL(vm_get_page_prot);
--
2.25.1

2022-02-14 19:55:34

by Anshuman Khandual

[permalink] [raw]
Subject: [PATCH 11/30] mm/mmap: Drop protection_map[]

There 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.

Cc: Andrew Morton <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Anshuman Khandual <[email protected]>
---
include/linux/mm.h | 6 -----
mm/mmap.c | 61 +++++++++++++++++++++++++++++++---------------
2 files changed, 41 insertions(+), 26 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 213cc569b192..ff74bd2d7850 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -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.
diff --git a/mm/mmap.c b/mm/mmap.c
index ffd70a0c8ddf..f61f74a61f62 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -102,24 +102,6 @@ static void unmap_region(struct mm_struct *mm,
* w: (no) no
* x: (yes) yes
*/
-pgprot_t protection_map[16] __ro_after_init = {
- [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
static inline pgprot_t arch_filter_pgprot(pgprot_t prot)
@@ -128,10 +110,49 @@ static inline pgprot_t arch_filter_pgprot(pgprot_t 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)) {
+ 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();
+ }
+}
+
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_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);
--
2.25.1

2022-02-14 20:25:42

by Anshuman Khandual

[permalink] [raw]
Subject: [PATCH 05/30] arm64/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT

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 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().

Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Anshuman Khandual <[email protected]>
---
arch/arm64/Kconfig | 2 +-
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 +++++++++++++++++++++++++++
5 files changed, 79 insertions(+), 54 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index e2540419ca12..7e36bb32351e 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -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
diff --git a/arch/arm64/include/asm/mman.h b/arch/arm64/include/asm/mman.h
index e3e28f7daf62..5966ee4a6154 100644
--- a/arch/arm64/include/asm/mman.h
+++ b/arch/arm64/include/asm/mman.h
@@ -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)
{
diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h
index 7032f04c8ac6..d8ee0aa7886d 100644
--- a/arch/arm64/include/asm/pgtable-prot.h
+++ b/arch/arm64/include/asm/pgtable-prot.h
@@ -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 */
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index c4ba047a82d2..94e147e5456c 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -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;
diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c
index a38f54cd638c..bd0233d376a2 100644
--- a/arch/arm64/mm/mmap.c
+++ b/arch/arm64/mm/mmap.c
@@ -10,6 +10,7 @@
#include <linux/types.h>

#include <asm/page.h>
+#include <asm/mman.h>

/*
* You really shouldn't be using read() or write() on /dev/mem. This might go
@@ -38,3 +39,80 @@ int valid_mmap_phys_addr_range(unsigned long pfn, size_t size)
{
return !(((pfn << PAGE_SHIFT) + size) & ~PHYS_MASK);
}
+
+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();
+ }
+}
+
+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)
+{
+ 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);
+}
+EXPORT_SYMBOL(vm_get_page_prot);
--
2.25.1

2022-02-14 20:50:52

by Anshuman Khandual

[permalink] [raw]
Subject: [PATCH 25/30] nios2/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT

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.

Cc: Dinh Nguyen <[email protected]>
Cc: [email protected]
Signed-off-by: Anshuman Khandual <[email protected]>
Acked-by: Dinh Nguyen <[email protected]>
---
arch/nios2/Kconfig | 1 +
arch/nios2/include/asm/pgtable.h | 16 ------------
arch/nios2/mm/init.c | 45 ++++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
index 33fd06f5fa41..85a58a357a3b 100644
--- a/arch/nios2/Kconfig
+++ b/arch/nios2/Kconfig
@@ -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
diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h
index 4a995fa628ee..2678dad58a63 100644
--- a/arch/nios2/include/asm/pgtable.h
+++ b/arch/nios2/include/asm/pgtable.h
@@ -40,24 +40,8 @@ struct mm_struct;
*/

/* 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 | \
diff --git a/arch/nios2/mm/init.c b/arch/nios2/mm/init.c
index 613fcaa5988a..311b2146a248 100644
--- a/arch/nios2/mm/init.c
+++ b/arch/nios2/mm/init.c
@@ -124,3 +124,48 @@ const char *arch_vma_name(struct vm_area_struct *vma)
{
return (vma->vm_start == KUSER_BASE) ? "[kuser]" : NULL;
}
+
+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 MKP(0, 0, 0);
+ case VM_READ:
+ return MKP(0, 0, 1);
+ /* COW */
+ case VM_WRITE:
+ return MKP(0, 0, 0);
+ /* COW */
+ case VM_WRITE | VM_READ:
+ return MKP(0, 0, 1);
+ case VM_EXEC:
+ return MKP(1, 0, 0);
+ case VM_EXEC | VM_READ:
+ return MKP(1, 0, 1);
+ /* COW */
+ case VM_EXEC | VM_WRITE:
+ return MKP(1, 0, 0);
+ /* COW */
+ case VM_EXEC | VM_WRITE | VM_READ:
+ return MKP(1, 0, 1);
+ case VM_SHARED:
+ return MKP(0, 0, 0);
+ case VM_SHARED | VM_READ:
+ return MKP(0, 0, 1);
+ case VM_SHARED | VM_WRITE:
+ return MKP(0, 1, 0);
+ case VM_SHARED | VM_WRITE | VM_READ:
+ return MKP(0, 1, 1);
+ case VM_SHARED | VM_EXEC:
+ return MKP(1, 0, 0);
+ case VM_SHARED | VM_EXEC | VM_READ:
+ return MKP(1, 0, 1);
+ case VM_SHARED | VM_EXEC | VM_WRITE:
+ return MKP(1, 1, 0);
+ case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
+ return MKP(1, 1, 1);
+ default:
+ BUILD_BUG();
+ }
+}
+EXPORT_SYMBOL(vm_get_page_prot);
--
2.25.1

2022-02-14 20:54:20

by Anshuman Khandual

[permalink] [raw]
Subject: [PATCH 26/30] hexagon/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT

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.

Cc: Brian Cain <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Anshuman Khandual <[email protected]>
---
arch/hexagon/Kconfig | 1 +
arch/hexagon/include/asm/pgtable.h | 24 -----------
arch/hexagon/mm/init.c | 67 ++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+), 24 deletions(-)

diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig
index 15dd8f38b698..cdc5df32a1e3 100644
--- a/arch/hexagon/Kconfig
+++ b/arch/hexagon/Kconfig
@@ -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.
diff --git a/arch/hexagon/include/asm/pgtable.h b/arch/hexagon/include/asm/pgtable.h
index 18cd6ea9ab23..5eceddfe013d 100644
--- a/arch/hexagon/include/asm/pgtable.h
+++ b/arch/hexagon/include/asm/pgtable.h
@@ -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 */

diff --git a/arch/hexagon/mm/init.c b/arch/hexagon/mm/init.c
index f01e91e10d95..b53595fc4103 100644
--- a/arch/hexagon/mm/init.c
+++ b/arch/hexagon/mm/init.c
@@ -236,3 +236,70 @@ void __init setup_arch_memory(void)
* which is called by start_kernel() later on in the process
*/
}
+
+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 __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ CACHEDEF);
+ case VM_READ:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ _PAGE_READ | CACHEDEF);
+ /* Write-only copy-on-write */
+ case VM_WRITE:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ CACHEDEF);
+ /* Read/Write copy-on-write */
+ case VM_WRITE | VM_READ:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ _PAGE_READ | CACHEDEF);
+ case VM_EXEC:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ _PAGE_EXECUTE | CACHEDEF);
+ case VM_EXEC | VM_READ:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ _PAGE_EXECUTE | _PAGE_READ |
+ CACHEDEF);
+ /* Write/execute copy-on-write */
+ case VM_EXEC | VM_WRITE:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ _PAGE_EXECUTE | CACHEDEF);
+ /* Read/Write/Execute, copy-on-write */
+ case VM_EXEC | VM_WRITE | VM_READ:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ _PAGE_EXECUTE | _PAGE_READ |
+ CACHEDEF);
+ case VM_SHARED:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ CACHEDEF);
+ case VM_SHARED | VM_READ:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ _PAGE_READ | CACHEDEF);
+ case VM_SHARED | VM_WRITE:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ _PAGE_WRITE | CACHEDEF);
+ case VM_SHARED | VM_WRITE | VM_READ:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ _PAGE_READ | _PAGE_WRITE |
+ CACHEDEF);
+ case VM_SHARED | VM_EXEC:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ _PAGE_EXECUTE | CACHEDEF);
+ case VM_SHARED | VM_EXEC | VM_READ:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ _PAGE_EXECUTE | _PAGE_READ |
+ CACHEDEF);
+ case VM_SHARED | VM_EXEC | VM_WRITE:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ _PAGE_EXECUTE | _PAGE_WRITE |
+ CACHEDEF);
+ case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
+ return __pgprot(_PAGE_PRESENT | _PAGE_USER |
+ _PAGE_READ | _PAGE_EXECUTE |
+ _PAGE_WRITE | CACHEDEF);
+ default:
+ BUILD_BUG();
+ }
+}
+EXPORT_SYMBOL(vm_get_page_prot);
--
2.25.1

2022-02-17 13:44:39

by Anshuman Khandual

[permalink] [raw]
Subject: Re: [PATCH 00/30] mm/mmap: Drop protection_map[] and platform's __SXXX/__PXXX requirements



On 2/14/22 8:00 AM, Anshuman Khandual wrote:
> 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-rc3 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]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
>
> Changes in V1:
>
> - 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]/


Hello,

Just a gentle ping. I am planning to respin the series earlier next week
on v5.17-rc5 with the build failure fixes and also accommodating a review
comment from Geert. But will really appreciate some more reviews/comments/
suggestions as the series changes code in every platform.

Although all individual patches copy required reviewers and mailing lists,
I am wondering should they all be included in the cover letter and copied
for individual patches as well via cc-cover. But previously, patches with
many emails copied, faced problems while being delivered to mailing lists.

- Anshuman

2022-02-25 03:47:29

by Dinh Nguyen

[permalink] [raw]
Subject: Re: [PATCH 25/30] nios2/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT

Hi Anshuman,

On 2/13/22 20:30, Anshuman Khandual wrote:
> 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.
>
> Cc: Dinh Nguyen <[email protected]>
> Cc: [email protected]
> Signed-off-by: Anshuman Khandual <[email protected]>
> Acked-by: Dinh Nguyen <[email protected]>
> ---
> arch/nios2/Kconfig | 1 +
> arch/nios2/include/asm/pgtable.h | 16 ------------
> arch/nios2/mm/init.c | 45 ++++++++++++++++++++++++++++++++
> 3 files changed, 46 insertions(+), 16 deletions(-)
>
> diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
> index 33fd06f5fa41..85a58a357a3b 100644
> --- a/arch/nios2/Kconfig
> +++ b/arch/nios2/Kconfig
> @@ -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
> diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h
> index 4a995fa628ee..2678dad58a63 100644
> --- a/arch/nios2/include/asm/pgtable.h
> +++ b/arch/nios2/include/asm/pgtable.h
> @@ -40,24 +40,8 @@ struct mm_struct;
> */
>
> /* 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 | \
> diff --git a/arch/nios2/mm/init.c b/arch/nios2/mm/init.c
> index 613fcaa5988a..311b2146a248 100644
> --- a/arch/nios2/mm/init.c
> +++ b/arch/nios2/mm/init.c
> @@ -124,3 +124,48 @@ const char *arch_vma_name(struct vm_area_struct *vma)
> {
> return (vma->vm_start == KUSER_BASE) ? "[kuser]" : NULL;
> }
> +
> +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 MKP(0, 0, 0);
> + case VM_READ:
> + return MKP(0, 0, 1);
> + /* COW */
> + case VM_WRITE:
> + return MKP(0, 0, 0);
> + /* COW */
> + case VM_WRITE | VM_READ:
> + return MKP(0, 0, 1);
> + case VM_EXEC:
> + return MKP(1, 0, 0);
> + case VM_EXEC | VM_READ:
> + return MKP(1, 0, 1);
> + /* COW */
> + case VM_EXEC | VM_WRITE:
> + return MKP(1, 0, 0);
> + /* COW */
> + case VM_EXEC | VM_WRITE | VM_READ:
> + return MKP(1, 0, 1);
> + case VM_SHARED:
> + return MKP(0, 0, 0);
> + case VM_SHARED | VM_READ:
> + return MKP(0, 0, 1);
> + case VM_SHARED | VM_WRITE:
> + return MKP(0, 1, 0);
> + case VM_SHARED | VM_WRITE | VM_READ:
> + return MKP(0, 1, 1);
> + case VM_SHARED | VM_EXEC:
> + return MKP(1, 0, 0);
> + case VM_SHARED | VM_EXEC | VM_READ:
> + return MKP(1, 0, 1);
> + case VM_SHARED | VM_EXEC | VM_WRITE:
> + return MKP(1, 1, 0);
> + case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
> + return MKP(1, 1, 1);
> + default:
> + BUILD_BUG();
> + }
> +}
> +EXPORT_SYMBOL(vm_get_page_prot);

I'm getting this compile error after applying this patch when build NIOS2:


mm/mmap.c:105:2: error: ‘__P000’ undeclared here (not in a function)

105 | __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,

| ^~~~~~

mm/mmap.c:105:10: error: ‘__P001’ undeclared here (not in a function)

105 | __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,

| ^~~~~~

mm/mmap.c:105:18: error: ‘__P010’ undeclared here (not in a function)

105 | __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,

| ^~~~~~

AR fs/devpts/built-in.a

mm/mmap.c:105:26: error: ‘__P011’ undeclared here (not in a function)

105 | __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,

| ^~~~~~

mm/mmap.c:105:34: error: ‘__P100’ undeclared here (not in a function)

105 | __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,

| ^~~~~~

mm/mmap.c:105:42: error: ‘__P101’ undeclared here (not in a function)

105 | __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,

| ^~~~~~

mm/mmap.c:105:50: error: ‘__P110’ undeclared here (not in a function)

105 | __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,

| ^~~~~~

mm/mmap.c:105:58: error: ‘__P111’ undeclared here (not in a function)

105 | __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,

| ^~~~~~

mm/mmap.c:106:2: error: ‘__S000’ undeclared here (not in a function)

106 | __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111

| ^~~~~~

mm/mmap.c:106:10: error: ‘__S001’ undeclared here (not in a function)

106 | __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111



Dinh

2022-02-25 10:28:24

by Anshuman Khandual

[permalink] [raw]
Subject: Re: [PATCH 25/30] nios2/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT



On 2/25/22 2:22 PM, Anshuman Khandual wrote:
>
> On 2/25/22 7:01 AM, Dinh Nguyen wrote:
>> Hi Anshuman,
>>
>> On 2/13/22 20:30, Anshuman Khandual wrote:
>>> 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.
>>>
>>> Cc: Dinh Nguyen <[email protected]>
>>> Cc: [email protected]
>>> Signed-off-by: Anshuman Khandual <[email protected]>
>>> Acked-by: Dinh Nguyen <[email protected]>
>>> ---
>>>   arch/nios2/Kconfig               |  1 +
>>>   arch/nios2/include/asm/pgtable.h | 16 ------------
>>>   arch/nios2/mm/init.c             | 45 ++++++++++++++++++++++++++++++++
>>>   3 files changed, 46 insertions(+), 16 deletions(-)
>>>
>>> diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
>>> index 33fd06f5fa41..85a58a357a3b 100644
>>> --- a/arch/nios2/Kconfig
>>> +++ b/arch/nios2/Kconfig
>>> @@ -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
>>> diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h
>>> index 4a995fa628ee..2678dad58a63 100644
>>> --- a/arch/nios2/include/asm/pgtable.h
>>> +++ b/arch/nios2/include/asm/pgtable.h
>>> @@ -40,24 +40,8 @@ struct mm_struct;
>>>    */
>>>     /* 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 | \
>>> diff --git a/arch/nios2/mm/init.c b/arch/nios2/mm/init.c
>>> index 613fcaa5988a..311b2146a248 100644
>>> --- a/arch/nios2/mm/init.c
>>> +++ b/arch/nios2/mm/init.c
>>> @@ -124,3 +124,48 @@ const char *arch_vma_name(struct vm_area_struct *vma)
>>>   {
>>>       return (vma->vm_start == KUSER_BASE) ? "[kuser]" : NULL;
>>>   }
>>> +
>>> +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 MKP(0, 0, 0);
>>> +    case VM_READ:
>>> +        return MKP(0, 0, 1);
>>> +    /* COW */
>>> +    case VM_WRITE:
>>> +        return MKP(0, 0, 0);
>>> +    /* COW */
>>> +    case VM_WRITE | VM_READ:
>>> +        return MKP(0, 0, 1);
>>> +    case VM_EXEC:
>>> +        return MKP(1, 0, 0);
>>> +    case VM_EXEC | VM_READ:
>>> +        return MKP(1, 0, 1);
>>> +    /* COW */
>>> +    case VM_EXEC | VM_WRITE:
>>> +        return MKP(1, 0, 0);
>>> +    /* COW */
>>> +    case VM_EXEC | VM_WRITE | VM_READ:
>>> +        return MKP(1, 0, 1);
>>> +    case VM_SHARED:
>>> +        return MKP(0, 0, 0);
>>> +    case VM_SHARED | VM_READ:
>>> +        return MKP(0, 0, 1);
>>> +    case VM_SHARED | VM_WRITE:
>>> +        return MKP(0, 1, 0);
>>> +    case VM_SHARED | VM_WRITE | VM_READ:
>>> +        return MKP(0, 1, 1);
>>> +    case VM_SHARED | VM_EXEC:
>>> +        return MKP(1, 0, 0);
>>> +    case VM_SHARED | VM_EXEC | VM_READ:
>>> +        return MKP(1, 0, 1);
>>> +    case VM_SHARED | VM_EXEC | VM_WRITE:
>>> +        return MKP(1, 1, 0);
>>> +    case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
>>> +        return MKP(1, 1, 1);
>>> +    default:
>>> +        BUILD_BUG();
>>> +    }
>>> +}
>>> +EXPORT_SYMBOL(vm_get_page_prot);
>> I'm getting this compile error after applying this patch when build NIOS2:
> Hmm, that is strange.
>
> Did you apply the entire series or atleast upto the nios2 patch ? Generic
> vm_get_page_prot() should not be called (which is build complaining here)
> when ARCH_HAS_VM_GET_PAGE_PROT is already enabled on nios2 platform.
>
> Ran a quick build test on nios2 for the entire series and also just upto
> this particular patch, build was successful.
>

Please refer to the latest version V2 instead.

https://lore.kernel.org/linux-mm/[email protected]/

2022-02-25 12:23:09

by Anshuman Khandual

[permalink] [raw]
Subject: Re: [PATCH 25/30] nios2/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT



On 2/25/22 7:01 AM, Dinh Nguyen wrote:
> Hi Anshuman,
>
> On 2/13/22 20:30, Anshuman Khandual wrote:
>> 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.
>>
>> Cc: Dinh Nguyen <[email protected]>
>> Cc: [email protected]
>> Signed-off-by: Anshuman Khandual <[email protected]>
>> Acked-by: Dinh Nguyen <[email protected]>
>> ---
>>   arch/nios2/Kconfig               |  1 +
>>   arch/nios2/include/asm/pgtable.h | 16 ------------
>>   arch/nios2/mm/init.c             | 45 ++++++++++++++++++++++++++++++++
>>   3 files changed, 46 insertions(+), 16 deletions(-)
>>
>> diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
>> index 33fd06f5fa41..85a58a357a3b 100644
>> --- a/arch/nios2/Kconfig
>> +++ b/arch/nios2/Kconfig
>> @@ -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
>> diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h
>> index 4a995fa628ee..2678dad58a63 100644
>> --- a/arch/nios2/include/asm/pgtable.h
>> +++ b/arch/nios2/include/asm/pgtable.h
>> @@ -40,24 +40,8 @@ struct mm_struct;
>>    */
>>     /* 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 | \
>> diff --git a/arch/nios2/mm/init.c b/arch/nios2/mm/init.c
>> index 613fcaa5988a..311b2146a248 100644
>> --- a/arch/nios2/mm/init.c
>> +++ b/arch/nios2/mm/init.c
>> @@ -124,3 +124,48 @@ const char *arch_vma_name(struct vm_area_struct *vma)
>>   {
>>       return (vma->vm_start == KUSER_BASE) ? "[kuser]" : NULL;
>>   }
>> +
>> +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 MKP(0, 0, 0);
>> +    case VM_READ:
>> +        return MKP(0, 0, 1);
>> +    /* COW */
>> +    case VM_WRITE:
>> +        return MKP(0, 0, 0);
>> +    /* COW */
>> +    case VM_WRITE | VM_READ:
>> +        return MKP(0, 0, 1);
>> +    case VM_EXEC:
>> +        return MKP(1, 0, 0);
>> +    case VM_EXEC | VM_READ:
>> +        return MKP(1, 0, 1);
>> +    /* COW */
>> +    case VM_EXEC | VM_WRITE:
>> +        return MKP(1, 0, 0);
>> +    /* COW */
>> +    case VM_EXEC | VM_WRITE | VM_READ:
>> +        return MKP(1, 0, 1);
>> +    case VM_SHARED:
>> +        return MKP(0, 0, 0);
>> +    case VM_SHARED | VM_READ:
>> +        return MKP(0, 0, 1);
>> +    case VM_SHARED | VM_WRITE:
>> +        return MKP(0, 1, 0);
>> +    case VM_SHARED | VM_WRITE | VM_READ:
>> +        return MKP(0, 1, 1);
>> +    case VM_SHARED | VM_EXEC:
>> +        return MKP(1, 0, 0);
>> +    case VM_SHARED | VM_EXEC | VM_READ:
>> +        return MKP(1, 0, 1);
>> +    case VM_SHARED | VM_EXEC | VM_WRITE:
>> +        return MKP(1, 1, 0);
>> +    case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
>> +        return MKP(1, 1, 1);
>> +    default:
>> +        BUILD_BUG();
>> +    }
>> +}
>> +EXPORT_SYMBOL(vm_get_page_prot);
>
> I'm getting this compile error after applying this patch when build NIOS2:

Hmm, that is strange.

Did you apply the entire series or atleast upto the nios2 patch ? Generic
vm_get_page_prot() should not be called (which is build complaining here)
when ARCH_HAS_VM_GET_PAGE_PROT is already enabled on nios2 platform.

Ran a quick build test on nios2 for the entire series and also just upto
this particular patch, build was successful.

>
>
> mm/mmap.c:105:2: error: ‘__P000’ undeclared here (not in a function)
>
>   105 |  __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
>
>       |  ^~~~~~
>
> mm/mmap.c:105:10: error: ‘__P001’ undeclared here (not in a function)
>
>   105 |  __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
>
>       |          ^~~~~~
>
> mm/mmap.c:105:18: error: ‘__P010’ undeclared here (not in a function)
>
>   105 |  __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
>
>       |                  ^~~~~~
>
>   AR      fs/devpts/built-in.a
>
> mm/mmap.c:105:26: error: ‘__P011’ undeclared here (not in a function)
>
>   105 |  __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
>
>       |                          ^~~~~~
>
> mm/mmap.c:105:34: error: ‘__P100’ undeclared here (not in a function)
>
>   105 |  __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
>
>       |                                  ^~~~~~
>
> mm/mmap.c:105:42: error: ‘__P101’ undeclared here (not in a function)
>
>   105 |  __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
>
>       |                                          ^~~~~~
>
> mm/mmap.c:105:50: error: ‘__P110’ undeclared here (not in a function)
>
>   105 |  __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
>
>       |                                                  ^~~~~~
>
> mm/mmap.c:105:58: error: ‘__P111’ undeclared here (not in a function)
>
>   105 |  __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
>
>       |                                                          ^~~~~~
>
> mm/mmap.c:106:2: error: ‘__S000’ undeclared here (not in a function)
>
>   106 |  __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
>
>       |  ^~~~~~
>
> mm/mmap.c:106:10: error: ‘__S001’ undeclared here (not in a function)
>
>   106 |  __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
>
>
>
> Dinh
>

2022-02-25 16:03:06

by Dinh Nguyen

[permalink] [raw]
Subject: Re: [PATCH 25/30] nios2/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT



On 2/25/22 02:52, Anshuman Khandual wrote:
>
>
> On 2/25/22 7:01 AM, Dinh Nguyen wrote:
>> Hi Anshuman,
>>
>> On 2/13/22 20:30, Anshuman Khandual wrote:
>>> 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.
>>>
>>> Cc: Dinh Nguyen <[email protected]>
>>> Cc: [email protected]
>>> Signed-off-by: Anshuman Khandual <[email protected]>
>>> Acked-by: Dinh Nguyen <[email protected]>
>>> ---
>>>   arch/nios2/Kconfig               |  1 +
>>>   arch/nios2/include/asm/pgtable.h | 16 ------------
>>>   arch/nios2/mm/init.c             | 45 ++++++++++++++++++++++++++++++++
>>>   3 files changed, 46 insertions(+), 16 deletions(-)
>>>
>>> diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
>>> index 33fd06f5fa41..85a58a357a3b 100644
>>> --- a/arch/nios2/Kconfig
>>> +++ b/arch/nios2/Kconfig
>>> @@ -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
>>> diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h
>>> index 4a995fa628ee..2678dad58a63 100644
>>> --- a/arch/nios2/include/asm/pgtable.h
>>> +++ b/arch/nios2/include/asm/pgtable.h
>>> @@ -40,24 +40,8 @@ struct mm_struct;
>>>    */
>>>     /* 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 | \
>>> diff --git a/arch/nios2/mm/init.c b/arch/nios2/mm/init.c
>>> index 613fcaa5988a..311b2146a248 100644
>>> --- a/arch/nios2/mm/init.c
>>> +++ b/arch/nios2/mm/init.c
>>> @@ -124,3 +124,48 @@ const char *arch_vma_name(struct vm_area_struct *vma)
>>>   {
>>>       return (vma->vm_start == KUSER_BASE) ? "[kuser]" : NULL;
>>>   }
>>> +
>>> +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 MKP(0, 0, 0);
>>> +    case VM_READ:
>>> +        return MKP(0, 0, 1);
>>> +    /* COW */
>>> +    case VM_WRITE:
>>> +        return MKP(0, 0, 0);
>>> +    /* COW */
>>> +    case VM_WRITE | VM_READ:
>>> +        return MKP(0, 0, 1);
>>> +    case VM_EXEC:
>>> +        return MKP(1, 0, 0);
>>> +    case VM_EXEC | VM_READ:
>>> +        return MKP(1, 0, 1);
>>> +    /* COW */
>>> +    case VM_EXEC | VM_WRITE:
>>> +        return MKP(1, 0, 0);
>>> +    /* COW */
>>> +    case VM_EXEC | VM_WRITE | VM_READ:
>>> +        return MKP(1, 0, 1);
>>> +    case VM_SHARED:
>>> +        return MKP(0, 0, 0);
>>> +    case VM_SHARED | VM_READ:
>>> +        return MKP(0, 0, 1);
>>> +    case VM_SHARED | VM_WRITE:
>>> +        return MKP(0, 1, 0);
>>> +    case VM_SHARED | VM_WRITE | VM_READ:
>>> +        return MKP(0, 1, 1);
>>> +    case VM_SHARED | VM_EXEC:
>>> +        return MKP(1, 0, 0);
>>> +    case VM_SHARED | VM_EXEC | VM_READ:
>>> +        return MKP(1, 0, 1);
>>> +    case VM_SHARED | VM_EXEC | VM_WRITE:
>>> +        return MKP(1, 1, 0);
>>> +    case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
>>> +        return MKP(1, 1, 1);
>>> +    default:
>>> +        BUILD_BUG();
>>> +    }
>>> +}
>>> +EXPORT_SYMBOL(vm_get_page_prot);
>>
>> I'm getting this compile error after applying this patch when build NIOS2:
>
> Hmm, that is strange.
>
> Did you apply the entire series or atleast upto the nios2 patch ? Generic
> vm_get_page_prot() should not be called (which is build complaining here)
> when ARCH_HAS_VM_GET_PAGE_PROT is already enabled on nios2 platform.
>
> Ran a quick build test on nios2 for the entire series and also just upto
> this particular patch, build was successful.
>

Ok, I did not apply the whole series, just this patch.

Dinh

2022-02-25 18:46:39

by Dinh Nguyen

[permalink] [raw]
Subject: Re: [PATCH 25/30] nios2/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT



On 2/25/22 08:29, Dinh Nguyen wrote:
>
>
> On 2/25/22 02:52, Anshuman Khandual wrote:
>>
>>
>> On 2/25/22 7:01 AM, Dinh Nguyen wrote:
>>> Hi Anshuman,
>>>
>>> On 2/13/22 20:30, Anshuman Khandual wrote:
>>>> 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.
>>>>
>>>> Cc: Dinh Nguyen <[email protected]>
>>>> Cc: [email protected]
>>>> Signed-off-by: Anshuman Khandual <[email protected]>
>>>> Acked-by: Dinh Nguyen <[email protected]>
>>>> ---
>>>>    arch/nios2/Kconfig               |  1 +
>>>>    arch/nios2/include/asm/pgtable.h | 16 ------------
>>>>    arch/nios2/mm/init.c             | 45
>>>> ++++++++++++++++++++++++++++++++
>>>>    3 files changed, 46 insertions(+), 16 deletions(-)
>>>>
>>>> diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
>>>> index 33fd06f5fa41..85a58a357a3b 100644
>>>> --- a/arch/nios2/Kconfig
>>>> +++ b/arch/nios2/Kconfig
>>>> @@ -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
>>>> diff --git a/arch/nios2/include/asm/pgtable.h
>>>> b/arch/nios2/include/asm/pgtable.h
>>>> index 4a995fa628ee..2678dad58a63 100644
>>>> --- a/arch/nios2/include/asm/pgtable.h
>>>> +++ b/arch/nios2/include/asm/pgtable.h
>>>> @@ -40,24 +40,8 @@ struct mm_struct;
>>>>     */
>>>>      /* 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 | \
>>>> diff --git a/arch/nios2/mm/init.c b/arch/nios2/mm/init.c
>>>> index 613fcaa5988a..311b2146a248 100644
>>>> --- a/arch/nios2/mm/init.c
>>>> +++ b/arch/nios2/mm/init.c
>>>> @@ -124,3 +124,48 @@ const char *arch_vma_name(struct vm_area_struct
>>>> *vma)
>>>>    {
>>>>        return (vma->vm_start == KUSER_BASE) ? "[kuser]" : NULL;
>>>>    }
>>>> +
>>>> +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 MKP(0, 0, 0);
>>>> +    case VM_READ:
>>>> +        return MKP(0, 0, 1);
>>>> +    /* COW */
>>>> +    case VM_WRITE:
>>>> +        return MKP(0, 0, 0);
>>>> +    /* COW */
>>>> +    case VM_WRITE | VM_READ:
>>>> +        return MKP(0, 0, 1);
>>>> +    case VM_EXEC:
>>>> +        return MKP(1, 0, 0);
>>>> +    case VM_EXEC | VM_READ:
>>>> +        return MKP(1, 0, 1);
>>>> +    /* COW */
>>>> +    case VM_EXEC | VM_WRITE:
>>>> +        return MKP(1, 0, 0);
>>>> +    /* COW */
>>>> +    case VM_EXEC | VM_WRITE | VM_READ:
>>>> +        return MKP(1, 0, 1);
>>>> +    case VM_SHARED:
>>>> +        return MKP(0, 0, 0);
>>>> +    case VM_SHARED | VM_READ:
>>>> +        return MKP(0, 0, 1);
>>>> +    case VM_SHARED | VM_WRITE:
>>>> +        return MKP(0, 1, 0);
>>>> +    case VM_SHARED | VM_WRITE | VM_READ:
>>>> +        return MKP(0, 1, 1);
>>>> +    case VM_SHARED | VM_EXEC:
>>>> +        return MKP(1, 0, 0);
>>>> +    case VM_SHARED | VM_EXEC | VM_READ:
>>>> +        return MKP(1, 0, 1);
>>>> +    case VM_SHARED | VM_EXEC | VM_WRITE:
>>>> +        return MKP(1, 1, 0);
>>>> +    case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
>>>> +        return MKP(1, 1, 1);
>>>> +    default:
>>>> +        BUILD_BUG();
>>>> +    }
>>>> +}
>>>> +EXPORT_SYMBOL(vm_get_page_prot);
>>>
>>> I'm getting this compile error after applying this patch when build
>>> NIOS2:
>>
>> Hmm, that is strange.
>>
>> Did you apply the entire series or atleast upto the nios2 patch ? Generic
>> vm_get_page_prot() should not be called (which is build complaining here)
>> when ARCH_HAS_VM_GET_PAGE_PROT is already enabled on nios2 platform.
>>
>> Ran a quick build test on nios2 for the entire series and also just upto
>> this particular patch, build was successful.
>>
>
> Ok, I did not apply the whole series, just this patch.
>


Is someone taking this whole series or should I just take this patch?

Dinh

2022-02-28 02:40:49

by Anshuman Khandual

[permalink] [raw]
Subject: Re: [PATCH 25/30] nios2/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT



On 2/25/22 8:08 PM, Dinh Nguyen wrote:
>
>
> On 2/25/22 08:29, Dinh Nguyen wrote:
>>
>>
>> On 2/25/22 02:52, Anshuman Khandual wrote:
>>>
>>>
>>> On 2/25/22 7:01 AM, Dinh Nguyen wrote:
>>>> Hi Anshuman,
>>>>
>>>> On 2/13/22 20:30, Anshuman Khandual wrote:
>>>>> 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.
>>>>>
>>>>> Cc: Dinh Nguyen <[email protected]>
>>>>> Cc: [email protected]
>>>>> Signed-off-by: Anshuman Khandual <[email protected]>
>>>>> Acked-by: Dinh Nguyen <[email protected]>
>>>>> ---
>>>>>    arch/nios2/Kconfig               |  1 +
>>>>>    arch/nios2/include/asm/pgtable.h | 16 ------------
>>>>>    arch/nios2/mm/init.c             | 45 ++++++++++++++++++++++++++++++++
>>>>>    3 files changed, 46 insertions(+), 16 deletions(-)
>>>>>
>>>>> diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
>>>>> index 33fd06f5fa41..85a58a357a3b 100644
>>>>> --- a/arch/nios2/Kconfig
>>>>> +++ b/arch/nios2/Kconfig
>>>>> @@ -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
>>>>> diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h
>>>>> index 4a995fa628ee..2678dad58a63 100644
>>>>> --- a/arch/nios2/include/asm/pgtable.h
>>>>> +++ b/arch/nios2/include/asm/pgtable.h
>>>>> @@ -40,24 +40,8 @@ struct mm_struct;
>>>>>     */
>>>>>      /* 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 | \
>>>>> diff --git a/arch/nios2/mm/init.c b/arch/nios2/mm/init.c
>>>>> index 613fcaa5988a..311b2146a248 100644
>>>>> --- a/arch/nios2/mm/init.c
>>>>> +++ b/arch/nios2/mm/init.c
>>>>> @@ -124,3 +124,48 @@ const char *arch_vma_name(struct vm_area_struct *vma)
>>>>>    {
>>>>>        return (vma->vm_start == KUSER_BASE) ? "[kuser]" : NULL;
>>>>>    }
>>>>> +
>>>>> +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 MKP(0, 0, 0);
>>>>> +    case VM_READ:
>>>>> +        return MKP(0, 0, 1);
>>>>> +    /* COW */
>>>>> +    case VM_WRITE:
>>>>> +        return MKP(0, 0, 0);
>>>>> +    /* COW */
>>>>> +    case VM_WRITE | VM_READ:
>>>>> +        return MKP(0, 0, 1);
>>>>> +    case VM_EXEC:
>>>>> +        return MKP(1, 0, 0);
>>>>> +    case VM_EXEC | VM_READ:
>>>>> +        return MKP(1, 0, 1);
>>>>> +    /* COW */
>>>>> +    case VM_EXEC | VM_WRITE:
>>>>> +        return MKP(1, 0, 0);
>>>>> +    /* COW */
>>>>> +    case VM_EXEC | VM_WRITE | VM_READ:
>>>>> +        return MKP(1, 0, 1);
>>>>> +    case VM_SHARED:
>>>>> +        return MKP(0, 0, 0);
>>>>> +    case VM_SHARED | VM_READ:
>>>>> +        return MKP(0, 0, 1);
>>>>> +    case VM_SHARED | VM_WRITE:
>>>>> +        return MKP(0, 1, 0);
>>>>> +    case VM_SHARED | VM_WRITE | VM_READ:
>>>>> +        return MKP(0, 1, 1);
>>>>> +    case VM_SHARED | VM_EXEC:
>>>>> +        return MKP(1, 0, 0);
>>>>> +    case VM_SHARED | VM_EXEC | VM_READ:
>>>>> +        return MKP(1, 0, 1);
>>>>> +    case VM_SHARED | VM_EXEC | VM_WRITE:
>>>>> +        return MKP(1, 1, 0);
>>>>> +    case VM_SHARED | VM_EXEC | VM_WRITE | VM_READ:
>>>>> +        return MKP(1, 1, 1);
>>>>> +    default:
>>>>> +        BUILD_BUG();
>>>>> +    }
>>>>> +}
>>>>> +EXPORT_SYMBOL(vm_get_page_prot);
>>>>
>>>> I'm getting this compile error after applying this patch when build NIOS2:
>>>
>>> Hmm, that is strange.
>>>
>>> Did you apply the entire series or atleast upto the nios2 patch ? Generic
>>> vm_get_page_prot() should not be called (which is build complaining here)
>>> when ARCH_HAS_VM_GET_PAGE_PROT is already enabled on nios2 platform.
>>>
>>> Ran a quick build test on nios2 for the entire series and also just upto
>>> this particular patch, build was successful.
>>>
>>
>> Ok, I did not apply the whole series, just this patch.
>>
>
>
> Is someone taking this whole series or should I just take this patch?

I expect the series (latest instead) will go via the mm tree, but will
really appreciate your tags if you find the series acceptable.