linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: debug_vm_pgtable: Don't use __P000 directly
@ 2021-09-21 20:18 guoren
  2021-09-24  3:31 ` Anshuman Khandual
  0 siblings, 1 reply; 5+ messages in thread
From: guoren @ 2021-09-21 20:18 UTC (permalink / raw)
  To: guoren, akpm; +Cc: linux-mm, linux-kernel, Guo Ren

From: Guo Ren <guoren@linux.alibaba.com>

The __Pxxx/__Sxxx macros are only for init protection_map[]. All
usage of them in linux should come from protection_map array.

Becasue a lot of architectures would re-initilize protection_map[]
array, eg: x86-mem_encrypt, m68k-motorola, mips, arm, sparc.

Using __P000 maybe won't cause bug because hw would deny access
with PROT_NONE permission, but it's not rigorous.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 mm/debug_vm_pgtable.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c
index 1403639302e4..a6ebbf6e53dd 100644
--- a/mm/debug_vm_pgtable.c
+++ b/mm/debug_vm_pgtable.c
@@ -1104,13 +1104,13 @@ static int __init init_args(struct pgtable_debug_args *args)
 	/*
 	 * Initialize the debugging data.
 	 *
-	 * __P000 (or even __S000) will help create page table entries with
+	 * __P000 (protection_map[0]) 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     = __P000;
+	args->page_prot_none     = protection_map[0];
 	args->is_contiguous_page = false;
 	args->pud_pfn            = ULONG_MAX;
 	args->pmd_pfn            = ULONG_MAX;
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: debug_vm_pgtable: Don't use __P000 directly
  2021-09-21 20:18 [PATCH] mm: debug_vm_pgtable: Don't use __P000 directly guoren
@ 2021-09-24  3:31 ` Anshuman Khandual
  2021-09-24  5:11   ` Guo Ren
  0 siblings, 1 reply; 5+ messages in thread
From: Anshuman Khandual @ 2021-09-24  3:31 UTC (permalink / raw)
  To: guoren, akpm; +Cc: linux-mm, linux-kernel, Guo Ren

Hello Guo,

On 9/22/21 1:48 AM, guoren@kernel.org wrote:
> From: Guo Ren <guoren@linux.alibaba.com>
> 
> The __Pxxx/__Sxxx macros are only for init protection_map[]. All

s/init protection_map[]/protection_map[] int/

Or rephrase with something similar.

> usage of them in linux should come from protection_map array.

Agreed.

> 
> Becasue a lot of architectures would re-initilize protection_map[]

s/Becasue/Because/

./scripts/checkpatch.pl ./0001-mm-debug_vm_pgtable-Don-t-use-__P000-directly.patch 
WARNING: 'Becasue' may be misspelled - perhaps 'Because'?
#9: 
Becasue a lot of architectures would re-initilize protection_map[]
^^^^^^^

total: 0 errors, 1 warnings, 15 lines checked

> array, eg: x86-mem_encrypt, m68k-motorola, mips, arm, sparc.
> 
> Using __P000 maybe won't cause bug because hw would deny access

Not very clear. Could you please rephrase.

> with PROT_NONE permission, but it's not rigorous.

Agreed.

> 
> Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> ---
>  mm/debug_vm_pgtable.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c
> index 1403639302e4..a6ebbf6e53dd 100644
> --- a/mm/debug_vm_pgtable.c
> +++ b/mm/debug_vm_pgtable.c
> @@ -1104,13 +1104,13 @@ static int __init init_args(struct pgtable_debug_args *args)
>  	/*
>  	 * Initialize the debugging data.
>  	 *
> -	 * __P000 (or even __S000) will help create page table entries with
> +	 * __P000 (protection_map[0]) will help create page table entries with

Please just replace __P000 and __S000 with protection_map[0] and
protection_map[8] respectively. Also reformat this comment section
if required.

>  	 * 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     = __P000;
> +	args->page_prot_none     = protection_map[0];
>  	args->is_contiguous_page = false;
>  	args->pud_pfn            = ULONG_MAX;
>  	args->pmd_pfn            = ULONG_MAX;
> 

With the above changes in place.

Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: debug_vm_pgtable: Don't use __P000 directly
  2021-09-24  3:31 ` Anshuman Khandual
@ 2021-09-24  5:11   ` Guo Ren
  0 siblings, 0 replies; 5+ messages in thread
From: Guo Ren @ 2021-09-24  5:11 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: Andrew Morton, Linux-MM, Linux Kernel Mailing List, Guo Ren

On Fri, Sep 24, 2021 at 11:30 AM Anshuman Khandual
<anshuman.khandual@arm.com> wrote:
>
> Hello Guo,
>
> On 9/22/21 1:48 AM, guoren@kernel.org wrote:
> > From: Guo Ren <guoren@linux.alibaba.com>
> >
> > The __Pxxx/__Sxxx macros are only for init protection_map[]. All
>
> s/init protection_map[]/protection_map[] int/
                                                                   ^^^
Okay, protection_map[] init

>
> Or rephrase with something similar.
>
> > usage of them in linux should come from protection_map array.
>
> Agreed.
>
> >
> > Becasue a lot of architectures would re-initilize protection_map[]
>
> s/Becasue/Because/
>
> ./scripts/checkpatch.pl ./0001-mm-debug_vm_pgtable-Don-t-use-__P000-directly.patch
> WARNING: 'Becasue' may be misspelled - perhaps 'Because'?
> #9:
> Becasue a lot of architectures would re-initilize protection_map[]
> ^^^^^^^
>
> total: 0 errors, 1 warnings, 15 lines checked
I would use checkpatch.pl next time, thx.

>
> > array, eg: x86-mem_encrypt, m68k-motorola, mips, arm, sparc.
> >
> > Using __P000 maybe won't cause bug because hw would deny access
>
> Not very clear. Could you please rephrase.
Using __P000 directly wouldn't equal protection_map[0] in many arches,
but the reason why it didn't cause the problem is the hardware ignores
the other bits when prot-attribute is denied.

>
> > with PROT_NONE permission, but it's not rigorous.
>
> Agreed.
>
> >
> > Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > ---
> >  mm/debug_vm_pgtable.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c
> > index 1403639302e4..a6ebbf6e53dd 100644
> > --- a/mm/debug_vm_pgtable.c
> > +++ b/mm/debug_vm_pgtable.c
> > @@ -1104,13 +1104,13 @@ static int __init init_args(struct pgtable_debug_args *args)
> >       /*
> >        * Initialize the debugging data.
> >        *
> > -      * __P000 (or even __S000) will help create page table entries with
> > +      * __P000 (protection_map[0]) will help create page table entries with
>
> Please just replace __P000 and __S000 with protection_map[0] and
> protection_map[8] respectively. Also reformat this comment section
> if required.
>
> >        * 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     = __P000;
> > +     args->page_prot_none     = protection_map[0];
> >       args->is_contiguous_page = false;
> >       args->pud_pfn            = ULONG_MAX;
> >       args->pmd_pfn            = ULONG_MAX;
> >
>
> With the above changes in place.
>
> Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>



-- 
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: debug_vm_pgtable: Don't use __P000 directly
  2021-09-24  6:06 guoren
@ 2021-09-24  6:09 ` Guo Ren
  0 siblings, 0 replies; 5+ messages in thread
From: Guo Ren @ 2021-09-24  6:09 UTC (permalink / raw)
  To: Guo Ren, Andrew Morton; +Cc: Linux-MM, Linux Kernel Mailing List, Guo Ren

Sorry, the patch forgets to add --prefix PATCH V2, abandon.

Review the V2, thx.

On Fri, Sep 24, 2021 at 2:07 PM <guoren@kernel.org> wrote:
>
> From: Guo Ren <guoren@linux.alibaba.com>
>
> The __Pxxx/__Sxxx macros are only for protection_map[] init. All
> usage of them in linux should come from protection_map array.
>
> Because a lot of architectures would re-initilize protection_map[]
> array, eg: x86-mem_encrypt, m68k-motorola, mips, arm, sparc.
>
> Using __P000 is not rigorous.
>
> Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
> Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
>
> ---
>
> Changes since V2:
>  - s/init protection_map[]/protection_map[] init/
>  - s/Becasue/Because/
>  - Remove unclear part
>  - Replace __P000 and __S000 with protection_map[0] and
>    protection_map[8]
> ---
>  mm/debug_vm_pgtable.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c
> index 1403639302e4..228e3954b90c 100644
> --- a/mm/debug_vm_pgtable.c
> +++ b/mm/debug_vm_pgtable.c
> @@ -1104,13 +1104,14 @@ static int __init init_args(struct pgtable_debug_args *args)
>         /*
>          * Initialize the debugging data.
>          *
> -        * __P000 (or even __S000) will help create page table entries with
> -        * PROT_NONE permission as required for pxx_protnone_tests().
> +        * protection_map[0] (or even protection_map[8]) 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     = __P000;
> +       args->page_prot_none     = protection_map[0];
>         args->is_contiguous_page = false;
>         args->pud_pfn            = ULONG_MAX;
>         args->pmd_pfn            = ULONG_MAX;
> --
> 2.25.1
>


-- 
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] mm: debug_vm_pgtable: Don't use __P000 directly
@ 2021-09-24  6:06 guoren
  2021-09-24  6:09 ` Guo Ren
  0 siblings, 1 reply; 5+ messages in thread
From: guoren @ 2021-09-24  6:06 UTC (permalink / raw)
  To: guoren, akpm; +Cc: linux-mm, linux-kernel, Guo Ren

From: Guo Ren <guoren@linux.alibaba.com>

The __Pxxx/__Sxxx macros are only for protection_map[] init. All
usage of them in linux should come from protection_map array.

Because a lot of architectures would re-initilize protection_map[]
array, eg: x86-mem_encrypt, m68k-motorola, mips, arm, sparc.

Using __P000 is not rigorous.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>

---

Changes since V2:
 - s/init protection_map[]/protection_map[] init/
 - s/Becasue/Because/
 - Remove unclear part
 - Replace __P000 and __S000 with protection_map[0] and
   protection_map[8]
---
 mm/debug_vm_pgtable.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c
index 1403639302e4..228e3954b90c 100644
--- a/mm/debug_vm_pgtable.c
+++ b/mm/debug_vm_pgtable.c
@@ -1104,13 +1104,14 @@ static int __init init_args(struct pgtable_debug_args *args)
 	/*
 	 * Initialize the debugging data.
 	 *
-	 * __P000 (or even __S000) will help create page table entries with
-	 * PROT_NONE permission as required for pxx_protnone_tests().
+	 * protection_map[0] (or even protection_map[8]) 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     = __P000;
+	args->page_prot_none     = protection_map[0];
 	args->is_contiguous_page = false;
 	args->pud_pfn            = ULONG_MAX;
 	args->pmd_pfn            = ULONG_MAX;
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-24  6:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-21 20:18 [PATCH] mm: debug_vm_pgtable: Don't use __P000 directly guoren
2021-09-24  3:31 ` Anshuman Khandual
2021-09-24  5:11   ` Guo Ren
2021-09-24  6:06 guoren
2021-09-24  6:09 ` Guo Ren

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