[PATCH v3 07/60] arm64: ptdump: Discover start of vmemmap region at runtime

Ard Biesheuvel posted 60 patches 2 years, 9 months ago
[PATCH v3 07/60] arm64: ptdump: Discover start of vmemmap region at runtime
Posted by Ard Biesheuvel 2 years, 9 months ago
We will soon reclaim the part of the vmemmap region that covers VA space
that is not addressable by the hardware. To avoid confusion, ensure that
the 'vmemmap start' marker points at the start of the region that is
actually being used for the struct page array, rather than the start of
the region we set aside for it at build time.

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

diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
index 910b35f02280cbdb..8f37d6d8b5216473 100644
--- a/arch/arm64/mm/ptdump.c
+++ b/arch/arm64/mm/ptdump.c
@@ -37,6 +37,7 @@ enum address_markers_idx {
 	MODULES_END_NR,
 	VMALLOC_START_NR,
 	VMALLOC_END_NR,
+	VMEMMAP_START_NR,
 };
 
 static struct addr_marker address_markers[] = {
@@ -386,6 +387,10 @@ static int __init ptdump_init(void)
 #endif
 	address_markers[VMALLOC_END_NR].start_address = VMALLOC_END;
 	ptdump_initialize();
+	if (vabits_actual < VA_BITS) {
+		address_markers[VMEMMAP_START_NR].start_address =
+			(unsigned long)virt_to_page(_PAGE_OFFSET(vabits_actual));
+	}
 	ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
 	return 0;
 }
-- 
2.39.2
Re: [PATCH v3 07/60] arm64: ptdump: Discover start of vmemmap region at runtime
Posted by Mark Rutland 2 years, 7 months ago
On Tue, Mar 07, 2023 at 03:04:29PM +0100, Ard Biesheuvel wrote:
> We will soon reclaim the part of the vmemmap region that covers VA space
> that is not addressable by the hardware. To avoid confusion, ensure that
> the 'vmemmap start' marker points at the start of the region that is
> actually being used for the struct page array, rather than the start of
> the region we set aside for it at build time.
> 
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
>  arch/arm64/mm/ptdump.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
> index 910b35f02280cbdb..8f37d6d8b5216473 100644
> --- a/arch/arm64/mm/ptdump.c
> +++ b/arch/arm64/mm/ptdump.c
> @@ -37,6 +37,7 @@ enum address_markers_idx {
>  	MODULES_END_NR,
>  	VMALLOC_START_NR,
>  	VMALLOC_END_NR,
> +	VMEMMAP_START_NR,
>  };
>  
>  static struct addr_marker address_markers[] = {
> @@ -386,6 +387,10 @@ static int __init ptdump_init(void)
>  #endif
>  	address_markers[VMALLOC_END_NR].start_address = VMALLOC_END;
>  	ptdump_initialize();
> +	if (vabits_actual < VA_BITS) {
> +		address_markers[VMEMMAP_START_NR].start_address =
> +			(unsigned long)virt_to_page(_PAGE_OFFSET(vabits_actual));
> +	}

As Ryan suggested, I think it'd be worth doing this unconditionally, to keep
this simple.

Mark.

>  	ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
>  	return 0;
>  }
> -- 
> 2.39.2
> 
>
Re: [PATCH v3 07/60] arm64: ptdump: Discover start of vmemmap region at runtime
Posted by Ryan Roberts 2 years, 9 months ago
On 07/03/2023 14:04, Ard Biesheuvel wrote:
> We will soon reclaim the part of the vmemmap region that covers VA space
> that is not addressable by the hardware. To avoid confusion, ensure that
> the 'vmemmap start' marker points at the start of the region that is
> actually being used for the struct page array, rather than the start of
> the region we set aside for it at build time.
> 
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
>  arch/arm64/mm/ptdump.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
> index 910b35f02280cbdb..8f37d6d8b5216473 100644
> --- a/arch/arm64/mm/ptdump.c
> +++ b/arch/arm64/mm/ptdump.c
> @@ -37,6 +37,7 @@ enum address_markers_idx {
>  	MODULES_END_NR,
>  	VMALLOC_START_NR,
>  	VMALLOC_END_NR,
> +	VMEMMAP_START_NR,
>  };
>  
>  static struct addr_marker address_markers[] = {
> @@ -386,6 +387,10 @@ static int __init ptdump_init(void)
>  #endif
>  	address_markers[VMALLOC_END_NR].start_address = VMALLOC_END;
>  	ptdump_initialize();
> +	if (vabits_actual < VA_BITS) {
> +		address_markers[VMEMMAP_START_NR].start_address =
> +			(unsigned long)virt_to_page(_PAGE_OFFSET(vabits_actual));
> +	}

nit: Do you need the conditional here? Why not just do it unconditionally?

>  	ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables");
>  	return 0;
>  }