[v3,06/60] arm64: ptdump: Allow VMALLOC_END to be defined at boot

Message ID 20230307140522.2311461-7-ardb@kernel.org
State New
Headers
Series arm64: Add support for LPA2 at stage1 and WXN |

Commit Message

Ard Biesheuvel March 7, 2023, 2:04 p.m. UTC
  Extend the existing pattern for populating ptdump marker entries at
boot, and add handling of VMALLOC_END, which will cease to be a compile
time constant for configurations that support 52-bit virtual addressing.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm64/mm/ptdump.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
  

Comments

Ryan Roberts March 7, 2023, 4:58 p.m. UTC | #1
On 07/03/2023 14:04, Ard Biesheuvel wrote:
> Extend the existing pattern for populating ptdump marker entries at
> boot, and add handling of VMALLOC_END, which will cease to be a compile
> time constant for configurations that support 52-bit virtual addressing.
> 
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
>  arch/arm64/mm/ptdump.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
> index 76d28056bd14920a..910b35f02280cbdb 100644
> --- a/arch/arm64/mm/ptdump.c
> +++ b/arch/arm64/mm/ptdump.c
> @@ -31,7 +31,12 @@ enum address_markers_idx {
>  	PAGE_END_NR,
>  #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
>  	KASAN_START_NR,
> +	KASAN_END_NR,
>  #endif
> +	MODULES_NR,
> +	MODULES_END_NR,
> +	VMALLOC_START_NR,
> +	VMALLOC_END_NR,
>  };
>  
>  static struct addr_marker address_markers[] = {
> @@ -44,7 +49,7 @@ static struct addr_marker address_markers[] = {
>  	{ MODULES_VADDR,		"Modules start" },
>  	{ MODULES_END,			"Modules end" },
>  	{ VMALLOC_START,		"vmalloc() area" },
> -	{ VMALLOC_END,			"vmalloc() end" },
> +	{ 0,				"vmalloc() end" },
>  	{ VMEMMAP_START,		"vmemmap start" },
>  	{ VMEMMAP_START + VMEMMAP_SIZE,	"vmemmap end" },
>  	{ PCI_IO_START,			"PCI I/O start" },

With all the VA layout changes, and the addition of 52-bit PA/VA for 4KB and
16KB pages, Documentation/arm64/memory.rst now looks very wrong. Suggest
updating it to reflect reality?



> @@ -379,6 +384,7 @@ static int __init ptdump_init(void)
>  #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
>  	address_markers[KASAN_START_NR].start_address = KASAN_SHADOW_START;
>  #endif
> +	address_markers[VMALLOC_END_NR].start_address = VMALLOC_END;
>  	ptdump_initialize();
>  	ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
>  	return 0;
  
Ard Biesheuvel March 7, 2023, 5:01 p.m. UTC | #2
On Tue, 7 Mar 2023 at 17:58, Ryan Roberts <ryan.roberts@arm.com> wrote:
>
> On 07/03/2023 14:04, Ard Biesheuvel wrote:
> > Extend the existing pattern for populating ptdump marker entries at
> > boot, and add handling of VMALLOC_END, which will cease to be a compile
> > time constant for configurations that support 52-bit virtual addressing.
> >
> > Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> > ---
> >  arch/arm64/mm/ptdump.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
> > index 76d28056bd14920a..910b35f02280cbdb 100644
> > --- a/arch/arm64/mm/ptdump.c
> > +++ b/arch/arm64/mm/ptdump.c
> > @@ -31,7 +31,12 @@ enum address_markers_idx {
> >       PAGE_END_NR,
> >  #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
> >       KASAN_START_NR,
> > +     KASAN_END_NR,
> >  #endif
> > +     MODULES_NR,
> > +     MODULES_END_NR,
> > +     VMALLOC_START_NR,
> > +     VMALLOC_END_NR,
> >  };
> >
> >  static struct addr_marker address_markers[] = {
> > @@ -44,7 +49,7 @@ static struct addr_marker address_markers[] = {
> >       { MODULES_VADDR,                "Modules start" },
> >       { MODULES_END,                  "Modules end" },
> >       { VMALLOC_START,                "vmalloc() area" },
> > -     { VMALLOC_END,                  "vmalloc() end" },
> > +     { 0,                            "vmalloc() end" },
> >       { VMEMMAP_START,                "vmemmap start" },
> >       { VMEMMAP_START + VMEMMAP_SIZE, "vmemmap end" },
> >       { PCI_IO_START,                 "PCI I/O start" },
>
> With all the VA layout changes, and the addition of 52-bit PA/VA for 4KB and
> 16KB pages, Documentation/arm64/memory.rst now looks very wrong. Suggest
> updating it to reflect reality?
>

Yeah good point. And I don't think we necessarily have to describe
every imaginable combo exhaustively.
  
Mark Rutland April 28, 2023, 11:25 a.m. UTC | #3
On Tue, Mar 07, 2023 at 03:04:28PM +0100, Ard Biesheuvel wrote:
> Extend the existing pattern for populating ptdump marker entries at
> boot, and add handling of VMALLOC_END, which will cease to be a compile
> time constant for configurations that support 52-bit virtual addressing.
> 
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
>  arch/arm64/mm/ptdump.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
> index 76d28056bd14920a..910b35f02280cbdb 100644
> --- a/arch/arm64/mm/ptdump.c
> +++ b/arch/arm64/mm/ptdump.c
> @@ -31,7 +31,12 @@ enum address_markers_idx {
>  	PAGE_END_NR,
>  #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
>  	KASAN_START_NR,
> +	KASAN_END_NR,
>  #endif
> +	MODULES_NR,
> +	MODULES_END_NR,
> +	VMALLOC_START_NR,
> +	VMALLOC_END_NR,
>  };

While it'd be a bit more verbose, I reckon it'd be worth making all of this
dynamically initialized. That would naturally handle things which are not
compile-time constant, and it'd keep all the values in one place, so it's
easier to keep the start/end/name/whatever in sync.

Something like:

| enum address_markers_idx {
| 	MARKER_LINEAR_START,
| 	MARKER_LINEAR_END,
| #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
| 	MARKER_KASAN_START,
| 	MARKER_KASAN_END,
| #endif
| 	MARKER_FOO_START,
| 	MARKER_FOO_END,
| 	MARKER_BAR_START,
| 	MARKER_BAR_END,
| 	MARKER_SENTINEL,
| };
| 
| static __ro_after_init struct addr_marker address_markers[] {
| 	[MARKER_SENTINEL] = {
| 		.start_address = 0,
|		.name = NULL,
| 	}
| };
| 
| static int __init ptdump_init(void)
| {
| 	address_markers[MARKER_LINEAR_START] = (struct addr_marker) {
| 		.start_address = [...],
| 		.name = "Linear mapping start",
| 	};
| 	address_markers[MARKER_LINEAR_END] = (struct addr_marker) {
| 		.start_address = [...],
| 		.name = "Linear mapping end",
| 	};
| 
| #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
| 	address_markers[MARKER_LINEAR_START] = (struct addr_marker) {
| 		.start_adddress = [...],
| 		.name = "KASAN shadow start",
| 	};
| 	address_markers[MARKER_LINEAR_START] = (struct addr_marker) {
| 		.start_adddress = [...],
| 		.name = "KASAN shadow end",
| 	};
| #endif
| 
| 	[...]
|
|  	ptdump_initialize();
|  	ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
|  	return 0;
| };

Thanks,
Mark.

>  
>  static struct addr_marker address_markers[] = {
> @@ -44,7 +49,7 @@ static struct addr_marker address_markers[] = {
>  	{ MODULES_VADDR,		"Modules start" },
>  	{ MODULES_END,			"Modules end" },
>  	{ VMALLOC_START,		"vmalloc() area" },
> -	{ VMALLOC_END,			"vmalloc() end" },
> +	{ 0,				"vmalloc() end" },
>  	{ VMEMMAP_START,		"vmemmap start" },
>  	{ VMEMMAP_START + VMEMMAP_SIZE,	"vmemmap end" },
>  	{ PCI_IO_START,			"PCI I/O start" },
> @@ -379,6 +384,7 @@ static int __init ptdump_init(void)
>  #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
>  	address_markers[KASAN_START_NR].start_address = KASAN_SHADOW_START;
>  #endif
> +	address_markers[VMALLOC_END_NR].start_address = VMALLOC_END;
>  	ptdump_initialize();
>  	ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
>  	return 0;
> -- 
> 2.39.2
> 
>
  

Patch

diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
index 76d28056bd14920a..910b35f02280cbdb 100644
--- a/arch/arm64/mm/ptdump.c
+++ b/arch/arm64/mm/ptdump.c
@@ -31,7 +31,12 @@  enum address_markers_idx {
 	PAGE_END_NR,
 #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
 	KASAN_START_NR,
+	KASAN_END_NR,
 #endif
+	MODULES_NR,
+	MODULES_END_NR,
+	VMALLOC_START_NR,
+	VMALLOC_END_NR,
 };
 
 static struct addr_marker address_markers[] = {
@@ -44,7 +49,7 @@  static struct addr_marker address_markers[] = {
 	{ MODULES_VADDR,		"Modules start" },
 	{ MODULES_END,			"Modules end" },
 	{ VMALLOC_START,		"vmalloc() area" },
-	{ VMALLOC_END,			"vmalloc() end" },
+	{ 0,				"vmalloc() end" },
 	{ VMEMMAP_START,		"vmemmap start" },
 	{ VMEMMAP_START + VMEMMAP_SIZE,	"vmemmap end" },
 	{ PCI_IO_START,			"PCI I/O start" },
@@ -379,6 +384,7 @@  static int __init ptdump_init(void)
 #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
 	address_markers[KASAN_START_NR].start_address = KASAN_SHADOW_START;
 #endif
+	address_markers[VMALLOC_END_NR].start_address = VMALLOC_END;
 	ptdump_initialize();
 	ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
 	return 0;