From nobody Fri Jun 19 13:30:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F05FC433F5 for ; Mon, 4 Apr 2022 03:18:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376985AbiDDDU2 (ORCPT ); Sun, 3 Apr 2022 23:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242146AbiDDDUY (ORCPT ); Sun, 3 Apr 2022 23:20:24 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F169A2DA9C for ; Sun, 3 Apr 2022 20:18:25 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B3122D6E; Sun, 3 Apr 2022 20:18:25 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.36.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 948093F73B; Sun, 3 Apr 2022 20:18:23 -0700 (PDT) From: Anshuman Khandual To: linux-mm@kvack.org Cc: Anshuman Khandual , linux-kernel@vger.kernel.org, Christoph Hellwig , Andrew Morton Subject: [PATCH 1/2] mm/debug_vm_pgtable: Drop protection_map[] usage Date: Mon, 4 Apr 2022 08:48:39 +0530 Message-Id: <20220404031840.588321-2-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220404031840.588321-1-anshuman.khandual@arm.com> References: <20220404031840.588321-1-anshuman.khandual@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual Reviewed-by: Christoph Hellwig --- 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 { =20 static void __init pte_basic_tests(struct pgtable_debug_args *args, int id= x) { - pgprot_t prot =3D protection_map[idx]; + pgprot_t prot =3D vm_get_page_prot(idx); pte_t pte =3D pfn_pte(args->fixed_pte_pfn, prot); unsigned long val =3D idx, *ptr =3D &val; =20 @@ -101,7 +101,7 @@ static void __init pte_basic_tests(struct pgtable_debug= _args *args, int idx) =20 /* * 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 id= x) { - pgprot_t prot =3D protection_map[idx]; + pgprot_t prot =3D vm_get_page_prot(idx); unsigned long val =3D idx, *ptr =3D &val; pmd_t pmd; =20 @@ -202,7 +202,7 @@ static void __init pmd_basic_tests(struct pgtable_debug= _args *args, int idx) =20 /* * 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 id= x) { - pgprot_t prot =3D protection_map[idx]; + pgprot_t prot =3D vm_get_page_prot(idx); unsigned long val =3D idx, *ptr =3D &val; pud_t pud; =20 @@ -337,7 +337,7 @@ static void __init pud_basic_tests(struct pgtable_debug= _args *args, int idx) =20 /* * 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_ar= gs *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 =3D get_random_vaddr(); args->page_prot =3D vm_get_page_prot(VMFLAGS); - args->page_prot_none =3D protection_map[0]; + args->page_prot_none =3D vm_get_page_prot(VM_NONE); args->is_contiguous_page =3D false; args->pud_pfn =3D ULONG_MAX; args->pmd_pfn =3D ULONG_MAX; @@ -1248,12 +1248,19 @@ static int __init debug_vm_pgtable(void) return ret; =20 /* - * 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 =3D 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 =3D VM_FLAGS_START; idx <=3D VM_FLAGS_END; idx++) { pte_basic_tests(&args, idx); pmd_basic_tests(&args, idx); pud_basic_tests(&args, idx); --=20 2.25.1 From nobody Fri Jun 19 13:30:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72A2EC433F5 for ; Mon, 4 Apr 2022 03:18:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377002AbiDDDUd (ORCPT ); Sun, 3 Apr 2022 23:20:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376986AbiDDDU0 (ORCPT ); Sun, 3 Apr 2022 23:20:26 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E42F1B24 for ; Sun, 3 Apr 2022 20:18:28 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 41A9A1FB; Sun, 3 Apr 2022 20:18:28 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.36.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4222D3F73B; Sun, 3 Apr 2022 20:18:25 -0700 (PDT) From: Anshuman Khandual To: linux-mm@kvack.org Cc: Anshuman Khandual , linux-kernel@vger.kernel.org, Christoph Hellwig , Andrew Morton Subject: [PATCH 2/2] mm/mmap: Clarify protection_map[] indices Date: Mon, 4 Apr 2022 08:48:40 +0530 Message-Id: <20220404031840.588321-3-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220404031840.588321-1-anshuman.khandual@arm.com> References: <20220404031840.588321-1-anshuman.khandual@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Christoph Hellwig Signed-off-by: Anshuman Khandual --- 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 =3D { - __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111, - __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111 + [VM_NONE] =3D __P000, + [VM_READ] =3D __P001, + [VM_WRITE] =3D __P010, + [VM_WRITE | VM_READ] =3D __P011, + [VM_EXEC] =3D __P100, + [VM_EXEC | VM_READ] =3D __P101, + [VM_EXEC | VM_WRITE] =3D __P110, + [VM_EXEC | VM_WRITE | VM_READ] =3D __P111, + [VM_SHARED] =3D __S000, + [VM_SHARED | VM_READ] =3D __S001, + [VM_SHARED | VM_WRITE] =3D __S010, + [VM_SHARED | VM_WRITE | VM_READ] =3D __S011, + [VM_SHARED | VM_EXEC] =3D __S100, + [VM_SHARED | VM_EXEC | VM_READ] =3D __S101, + [VM_SHARED | VM_EXEC | VM_WRITE] =3D __S110, + [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] =3D __S111 }; =20 #ifndef CONFIG_ARCH_HAS_FILTER_PGPROT --=20 2.25.1