diff mbox series

[v4,1/5] mm: add ARCH_SUPPORTS_NON_LEAF_PTDUMP

Message ID fgvecau2k64sfzvxbs2yxrhzimseogdt2qk4izboywnrtco4od@ezdoxozrt2yj (mailing list archive)
State New, archived
Headers show
Series ptdump: add intermediate directory support | expand

Commit Message

Maxwell Bland June 18, 2024, 2:40 p.m. UTC
Provide a Kconfig option indicating if note_page can be called for
intermediate page directories during ptdump.

Signed-off-by: Maxwell Bland <mbland@motorola.com>
---
 mm/Kconfig.debug |  9 +++++++++
 mm/ptdump.c      | 21 +++++++++++++--------
 2 files changed, 22 insertions(+), 8 deletions(-)

Comments

LEROY Christophe June 18, 2024, 6:38 p.m. UTC | #1
Le 18/06/2024 à 16:40, Maxwell Bland a écrit :
> [Vous ne recevez pas souvent de courriers de mbland@motorola.com. D?couvrez pourquoi ceci est important ? https://aka.ms/LearnAboutSenderIdentification ]
> 
> Provide a Kconfig option indicating if note_page can be called for
> intermediate page directories during ptdump.
> 
> Signed-off-by: Maxwell Bland <mbland@motorola.com>
> ---
>   mm/Kconfig.debug |  9 +++++++++
>   mm/ptdump.c      | 21 +++++++++++++--------
>   2 files changed, 22 insertions(+), 8 deletions(-)
> 
> diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug
> index afc72fde0f03..6af5ecfdef93 100644
> --- a/mm/Kconfig.debug
> +++ b/mm/Kconfig.debug
> @@ -201,6 +201,15 @@ config PTDUMP_DEBUGFS
> 
>            If in doubt, say N.
> 
> +config ARCH_SUPPORTS_NON_LEAF_PTDUMP
> +       bool "Include intermediate directory entries in pagetable dumps"
> +       default n
> +       help
> +         Enable the inclusion of intermediate page directory entries in calls
> +         to the ptdump API. Once an architecture defines correct ptdump
> +         behavior for PGD, PUD, P4D, and PMD entries, this config can be
> +         selected.
> +
>   config HAVE_DEBUG_KMEMLEAK
>          bool
> 
> diff --git a/mm/ptdump.c b/mm/ptdump.c
> index 106e1d66e9f9..6180708669fe 100644
> --- a/mm/ptdump.c
> +++ b/mm/ptdump.c
> @@ -41,10 +41,11 @@ static int ptdump_pgd_entry(pgd_t *pgd, unsigned long addr,
>          if (st->effective_prot)
>                  st->effective_prot(st, 0, pgd_val(val));
> 
> -       if (pgd_leaf(val)) {
> +       if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_NON_LEAF_PTDUMP) || pgd_leaf(val))
>                  st->note_page(st, addr, 0, pgd_val(val));
> +
> +       if (pgd_leaf(val))
>                  walk->action = ACTION_CONTINUE;
> -       }
> 
>          return 0;
>   }
> @@ -64,10 +65,11 @@ static int ptdump_p4d_entry(p4d_t *p4d, unsigned long addr,
>          if (st->effective_prot)
>                  st->effective_prot(st, 1, p4d_val(val));
> 
> -       if (p4d_leaf(val)) {
> +       if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_NON_LEAF_PTDUMP) || pgd_leaf(val))

Don't you mean p4d_leaf() here instead of pgd_leaf() ?

>                  st->note_page(st, addr, 1, p4d_val(val));
> +
> +       if (p4d_leaf(val))
>                  walk->action = ACTION_CONTINUE;
> -       }
> 
>          return 0;
>   }
> @@ -87,10 +89,11 @@ static int ptdump_pud_entry(pud_t *pud, unsigned long addr,
>          if (st->effective_prot)
>                  st->effective_prot(st, 2, pud_val(val));
> 
> -       if (pud_leaf(val)) {
> +       if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_NON_LEAF_PTDUMP) || pgd_leaf(val))

Don't you mean pud_leaf() here instead of pgd_leaf() ?

>                  st->note_page(st, addr, 2, pud_val(val));
> +
> +       if (pud_leaf(val))
>                  walk->action = ACTION_CONTINUE;
> -       }
> 
>          return 0;
>   }
> @@ -108,10 +111,12 @@ static int ptdump_pmd_entry(pmd_t *pmd, unsigned long addr,
> 
>          if (st->effective_prot)
>                  st->effective_prot(st, 3, pmd_val(val));
> -       if (pmd_leaf(val)) {
> +
> +       if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_NON_LEAF_PTDUMP) || pgd_leaf(val))

Don't you mean pmd_leaf() here instead of pgd_leaf() ?

>                  st->note_page(st, addr, 3, pmd_val(val));
> +
> +       if (pmd_leaf(val))
>                  walk->action = ACTION_CONTINUE;
> -       }
> 
>          return 0;
>   }
> --
> 2.39.2
> 
>
Maxwell Bland June 18, 2024, 7:41 p.m. UTC | #2
On Tue, Jun 18, 2024 at 06:38:24PM GMT, LEROY Christophe wrote:
> Le 18/06/2024 à 16:40, Maxwell Bland a écrit :
> > @@ -64,10 +65,11 @@ static int ptdump_p4d_entry(p4d_t *p4d, unsigned long addr,
> >          if (st->effective_prot)
> >                  st->effective_prot(st, 1, p4d_val(val));
> > 
> > -       if (p4d_leaf(val)) {
> > +       if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_NON_LEAF_PTDUMP) || pgd_leaf(val))
> 
> Don't you mean p4d_leaf() here instead of pgd_leaf() ?
> Don't you mean pud_leaf() here instead of pgd_leaf() ?
> Don't you mean pmd_leaf() here instead of pgd_leaf() ?

Oh my, this is embarrassing. )-:

Hence the review process---thank you for catching these, will fix in v5.

Maxwell
LEROY Christophe June 19, 2024, 8:44 a.m. UTC | #3
Le 18/06/2024 à 21:41, Maxwell Bland a écrit :
> [Vous ne recevez pas souvent de courriers de mbland@motorola.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
> 
> On Tue, Jun 18, 2024 at 06:38:24PM GMT, LEROY Christophe wrote:
>> Le 18/06/2024 à 16:40, Maxwell Bland a écrit :
>>> @@ -64,10 +65,11 @@ static int ptdump_p4d_entry(p4d_t *p4d, unsigned long addr,
>>>           if (st->effective_prot)
>>>                   st->effective_prot(st, 1, p4d_val(val));
>>>
>>> -       if (p4d_leaf(val)) {
>>> +       if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_NON_LEAF_PTDUMP) || pgd_leaf(val))
>>
>> Don't you mean p4d_leaf() here instead of pgd_leaf() ?
>> Don't you mean pud_leaf() here instead of pgd_leaf() ?
>> Don't you mean pmd_leaf() here instead of pgd_leaf() ?
> 
> Oh my, this is embarrassing. )-:
> 
> Hence the review process---thank you for catching these, will fix in v5.

Maybe we could have a nicer code with something like:

static inline bool has_non_leaf_ptdump()
{
	return IS_ENABLED(CONFIG_ARCH_SUPPORTS_NON_LEAF_PTDUMP);
}

static int ptdump_p4d_entry(...)
{
	...
	if (has_non_leaf_ptdump() || pgd_leaf(val))
		...
}

Christophe
Maxwell Bland June 24, 2024, 10:27 p.m. UTC | #4
On Wed, Jun 19, 2024 at 08:44:21AM GMT, LEROY Christophe wrote:
> Le 18/06/2024 à 21:41, Maxwell Bland a écrit :
> > On Tue, Jun 18, 2024 at 06:38:24PM GMT, LEROY Christophe wrote:
> >> Le 18/06/2024 à 16:40, Maxwell Bland a écrit :
> >> Don't you mean pmd_leaf() here instead of pgd_leaf() ?
> > thank you for catching these, will fix in v5.
> 
> Maybe we could have a nicer code with something like:
> 
> static inline bool has_non_leaf_ptdump()
> {
> 	return IS_ENABLED(CONFIG_ARCH_SUPPORTS_NON_LEAF_PTDUMP);
> }
> 
> static int ptdump_p4d_entry(...)
> {
> 	...
> 	if (has_non_leaf_ptdump() || pgd_leaf(val))
> 		...
> }

Hi Christophe, nice, thank you! I incorporated this critique as well.

Forward pointer to v5:
https://lore.kernel.org/all/2bcb3htsjhepxdybpw2bwot2jnuezl3p5mnj5rhjwgitlsufe7@xzhkyntridw3/#t

Maxwell
diff mbox series

Patch

diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug
index afc72fde0f03..6af5ecfdef93 100644
--- a/mm/Kconfig.debug
+++ b/mm/Kconfig.debug
@@ -201,6 +201,15 @@  config PTDUMP_DEBUGFS
 
 	  If in doubt, say N.
 
+config ARCH_SUPPORTS_NON_LEAF_PTDUMP
+	bool "Include intermediate directory entries in pagetable dumps"
+	default n
+	help
+	  Enable the inclusion of intermediate page directory entries in calls
+	  to the ptdump API. Once an architecture defines correct ptdump
+	  behavior for PGD, PUD, P4D, and PMD entries, this config can be
+	  selected.
+
 config HAVE_DEBUG_KMEMLEAK
 	bool
 
diff --git a/mm/ptdump.c b/mm/ptdump.c
index 106e1d66e9f9..6180708669fe 100644
--- a/mm/ptdump.c
+++ b/mm/ptdump.c
@@ -41,10 +41,11 @@  static int ptdump_pgd_entry(pgd_t *pgd, unsigned long addr,
 	if (st->effective_prot)
 		st->effective_prot(st, 0, pgd_val(val));
 
-	if (pgd_leaf(val)) {
+	if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_NON_LEAF_PTDUMP) || pgd_leaf(val))
 		st->note_page(st, addr, 0, pgd_val(val));
+
+	if (pgd_leaf(val))
 		walk->action = ACTION_CONTINUE;
-	}
 
 	return 0;
 }
@@ -64,10 +65,11 @@  static int ptdump_p4d_entry(p4d_t *p4d, unsigned long addr,
 	if (st->effective_prot)
 		st->effective_prot(st, 1, p4d_val(val));
 
-	if (p4d_leaf(val)) {
+	if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_NON_LEAF_PTDUMP) || pgd_leaf(val))
 		st->note_page(st, addr, 1, p4d_val(val));
+
+	if (p4d_leaf(val))
 		walk->action = ACTION_CONTINUE;
-	}
 
 	return 0;
 }
@@ -87,10 +89,11 @@  static int ptdump_pud_entry(pud_t *pud, unsigned long addr,
 	if (st->effective_prot)
 		st->effective_prot(st, 2, pud_val(val));
 
-	if (pud_leaf(val)) {
+	if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_NON_LEAF_PTDUMP) || pgd_leaf(val))
 		st->note_page(st, addr, 2, pud_val(val));
+
+	if (pud_leaf(val))
 		walk->action = ACTION_CONTINUE;
-	}
 
 	return 0;
 }
@@ -108,10 +111,12 @@  static int ptdump_pmd_entry(pmd_t *pmd, unsigned long addr,
 
 	if (st->effective_prot)
 		st->effective_prot(st, 3, pmd_val(val));
-	if (pmd_leaf(val)) {
+
+	if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_NON_LEAF_PTDUMP) || pgd_leaf(val))
 		st->note_page(st, addr, 3, pmd_val(val));
+
+	if (pmd_leaf(val))
 		walk->action = ACTION_CONTINUE;
-	}
 
 	return 0;
 }