diff mbox series

[RFC,V1,01/31] mm/debug_vm_pgtable: Directly use vm_get_page_prot()

Message ID 1643029028-12710-2-git-send-email-anshuman.khandual@arm.com (mailing list archive)
State New
Headers show
Series mm/mmap: Drop protection_map[] and platform's __SXXX/__PXXX requirements | expand

Commit Message

Anshuman Khandual Jan. 24, 2022, 12:56 p.m. UTC
Although protection_map[] contains the platform defined page protection map
, vm_get_page_prot() is the right interface to call for page protection for
a given vm_flags. Hence lets use it directly instead. This will also reduce
dependency on protection_map[].

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 | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

Comments

Christoph Hellwig Jan. 26, 2022, 7:15 a.m. UTC | #1
> +	 *
> +	 * Protection based vm_flags combinatins are always linear
> +	 * and increasing i.e VM_NONE ..[VM_SHARED|READ|WRITE|EXEC].
>  	 */
> -	for (idx = 0; idx < ARRAY_SIZE(protection_map); idx++) {
> +	for (i = VM_NONE; i <= (VM_SHARED | VM_READ | VM_WRITE | VM_EXEC); ix++) {
>  		pte_basic_tests(&args, idx);
>  		pmd_basic_tests(&args, idx);
>  		pud_basic_tests(&args, idx);

This looks rather convoluted.  I'd prefer to add a helper for the body
of this loop, and then explicitly call it for all the valid
combinations.  Right now all are valid, so this dosn't change a thing
except for generating larger code due to the explicit loop unrolling,
but I think it is much easier to follow and maintain.
Anshuman Khandual Jan. 27, 2022, 4:16 a.m. UTC | #2
On 1/26/22 12:45 PM, Christoph Hellwig wrote:
>> +	 *
>> +	 * Protection based vm_flags combinatins are always linear
>> +	 * and increasing i.e VM_NONE ..[VM_SHARED|READ|WRITE|EXEC].
>>  	 */
>> -	for (idx = 0; idx < ARRAY_SIZE(protection_map); idx++) {
>> +	for (i = VM_NONE; i <= (VM_SHARED | VM_READ | VM_WRITE | VM_EXEC); ix++) {
>>  		pte_basic_tests(&args, idx);
>>  		pmd_basic_tests(&args, idx);
>>  		pud_basic_tests(&args, idx);
> 
> This looks rather convoluted.  I'd prefer to add a helper for the body
> of this loop, and then explicitly call it for all the valid
> combinations.  Right now all are valid, so this dosn't change a thing
> except for generating larger code due to the explicit loop unrolling,
> but I think it is much easier to follow and maintain.

IIUC, then will just keep this unchanged.
diff mbox series

Patch

diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c
index a7ac97c76762..07593eb79338 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.
@@ -188,7 +188,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;
 
@@ -200,7 +200,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.
@@ -323,7 +323,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;
 
@@ -335,7 +335,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.
@@ -1104,14 +1104,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;
@@ -1246,12 +1246,15 @@  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 VM_NONE ..[VM_SHARED|READ|WRITE|EXEC].
 	 */
-	for (idx = 0; idx < ARRAY_SIZE(protection_map); idx++) {
+	for (idx = VM_NONE; idx <= (VM_SHARED | VM_READ | VM_WRITE | VM_EXEC); idx++) {
 		pte_basic_tests(&args, idx);
 		pmd_basic_tests(&args, idx);
 		pud_basic_tests(&args, idx);