* [PATCH 0/2] mm: protection_map[] cleanups
@ 2022-04-04 3:18 Anshuman Khandual
2022-04-04 3:18 ` [PATCH 1/2] mm/debug_vm_pgtable: Drop protection_map[] usage Anshuman Khandual
2022-04-04 3:18 ` [PATCH 2/2] mm/mmap: Clarify protection_map[] indices Anshuman Khandual
0 siblings, 2 replies; 5+ messages in thread
From: Anshuman Khandual @ 2022-04-04 3:18 UTC (permalink / raw)
To: linux-mm
Cc: Anshuman Khandual, linux-kernel, Christoph Hellwig, Andrew Morton
This is a split series from an earlier work which tried to drop the array
protection_map[] on various platforms. This series applies on v5.18-rc1.
https://lore.kernel.org/all/1646045273-9343-1-git-send-email-anshuman.khandual@arm.com/
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Cc: Christoph Hellwig <hch@lst.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Anshuman Khandual (2):
mm/debug_vm_pgtable: Drop protection_map[] usage
mm/mmap: Clarify protection_map[] indices
mm/debug_vm_pgtable.c | 31 +++++++++++++++++++------------
mm/mmap.c | 18 ++++++++++++++++--
2 files changed, 35 insertions(+), 14 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] mm/debug_vm_pgtable: Drop protection_map[] usage
2022-04-04 3:18 [PATCH 0/2] mm: protection_map[] cleanups Anshuman Khandual
@ 2022-04-04 3:18 ` Anshuman Khandual
2022-04-07 9:43 ` Christoph Hellwig
2022-04-04 3:18 ` [PATCH 2/2] mm/mmap: Clarify protection_map[] indices Anshuman Khandual
1 sibling, 1 reply; 5+ messages in thread
From: Anshuman Khandual @ 2022-04-04 3:18 UTC (permalink / raw)
To: linux-mm
Cc: Anshuman Khandual, linux-kernel, Christoph Hellwig, Andrew Morton
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.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
mm/debug_vm_pgtable.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c
index db2abd9e415b..30fd11a2ed32 100644
--- a/mm/debug_vm_pgtable.c
+++ b/mm/debug_vm_pgtable.c
@@ -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);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] mm/mmap: Clarify protection_map[] indices
2022-04-04 3:18 [PATCH 0/2] mm: protection_map[] cleanups Anshuman Khandual
2022-04-04 3:18 ` [PATCH 1/2] mm/debug_vm_pgtable: Drop protection_map[] usage Anshuman Khandual
@ 2022-04-04 3:18 ` Anshuman Khandual
2022-04-07 9:44 ` Christoph Hellwig
1 sibling, 1 reply; 5+ messages in thread
From: Anshuman Khandual @ 2022-04-04 3:18 UTC (permalink / raw)
To: linux-mm
Cc: Anshuman Khandual, linux-kernel, Christoph Hellwig, Andrew Morton
protection_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.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
mm/mmap.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index 3aa839f81e63..4b8ee3fd03ad 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -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
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] mm/debug_vm_pgtable: Drop protection_map[] usage
2022-04-04 3:18 ` [PATCH 1/2] mm/debug_vm_pgtable: Drop protection_map[] usage Anshuman Khandual
@ 2022-04-07 9:43 ` Christoph Hellwig
0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2022-04-07 9:43 UTC (permalink / raw)
To: Anshuman Khandual
Cc: linux-mm, linux-kernel, Christoph Hellwig, Andrew Morton
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] mm/mmap: Clarify protection_map[] indices
2022-04-04 3:18 ` [PATCH 2/2] mm/mmap: Clarify protection_map[] indices Anshuman Khandual
@ 2022-04-07 9:44 ` Christoph Hellwig
0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2022-04-07 9:44 UTC (permalink / raw)
To: Anshuman Khandual
Cc: linux-mm, linux-kernel, Christoph Hellwig, Andrew Morton
On Mon, Apr 04, 2022 at 08:48:40AM +0530, Anshuman Khandual wrote:
> protection_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.
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-04-07 9:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-04 3:18 [PATCH 0/2] mm: protection_map[] cleanups Anshuman Khandual
2022-04-04 3:18 ` [PATCH 1/2] mm/debug_vm_pgtable: Drop protection_map[] usage Anshuman Khandual
2022-04-07 9:43 ` Christoph Hellwig
2022-04-04 3:18 ` [PATCH 2/2] mm/mmap: Clarify protection_map[] indices Anshuman Khandual
2022-04-07 9:44 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).