* [PATCH] RISC-V: Add address map dumper
@ 2019-11-11 5:27 Yash Shah
2019-11-11 18:14 ` Logan Gunthorpe
2019-11-11 21:56 ` Mike Rapoport
0 siblings, 2 replies; 6+ messages in thread
From: Yash Shah @ 2019-11-11 5:27 UTC (permalink / raw)
To: Paul Walmsley ( Sifive), linux-riscv, linux-kernel
Cc: palmer, aou, Anup.Patel, rppt, logang, ren_guo, bmeng.cn, tglx,
Sachin Ghadi, Yash Shah
Add support for dumping the kernel address space layout to the console.
User can enable CONFIG_DEBUG_VM_LAYOUT to dump the virtual memory region
into dmesg buffer during boot-up.
Signed-off-by: Yash Shah <yash.shah@sifive.com>
---
This patch is based on Linux 5.4-rc6 and tested on SiFive HiFive Unleashed
board.
---
arch/riscv/Kconfig.debug | 9 +++++++++
arch/riscv/mm/init.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/arch/riscv/Kconfig.debug b/arch/riscv/Kconfig.debug
index e69de29..cdedfd3 100644
--- a/arch/riscv/Kconfig.debug
+++ b/arch/riscv/Kconfig.debug
@@ -0,0 +1,9 @@
+config DEBUG_VM_LAYOUT
+ bool "Print virtual memory layout on boot up"
+ depends on DEBUG_KERNEL
+ help
+ Say Y here if you want to dump the kernel virtual memory layout to
+ dmesg log on boot up. This information is only useful for kernel
+ developers who are working in architecture specific areas of the
+ kernel. It is probably not a good idea to enable this feature in a
+ production kernel.
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 79cfb35..fcb8144 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -55,6 +55,36 @@ void __init mem_init(void)
memblock_free_all();
mem_init_print_info(NULL);
+#ifdef CONFIG_DEBUG_VM_LAYOUT
+#define MLK(b, t) b, t, (((t) - (b)) >> 10)
+#define MLM(b, t) b, t, (((t) - (b)) >> 20)
+#define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K)
+
+
+ pr_notice("Virtual kernel memory layout:\n"
+ " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
+ " vmemmap : 0x%08lx - 0x%08lx (%4ld MB)\n"
+ " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n"
+ " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n"
+ " .init : 0x%px - 0x%px (%4td kB)\n"
+ " .text : 0x%px - 0x%px (%4td kB)\n"
+ " .data : 0x%px - 0x%px (%4td kB)\n"
+ " .bss : 0x%px - 0x%px (%4td kB)\n",
+
+ MLK(FIXADDR_START, FIXADDR_TOP),
+ MLM(VMEMMAP_START, VMEMMAP_END),
+ MLM(VMALLOC_START, VMALLOC_END),
+ MLM(PAGE_OFFSET, (unsigned long)high_memory),
+
+ MLK_ROUNDUP(__init_begin, __init_end),
+ MLK_ROUNDUP(_text, _etext),
+ MLK_ROUNDUP(_sdata, _edata),
+ MLK_ROUNDUP(__bss_start, __bss_stop));
+
+#undef MLK
+#undef MLM
+#undef MLK_ROUNDUP
+#endif
}
#ifdef CONFIG_BLK_DEV_INITRD
--
2.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] RISC-V: Add address map dumper
2019-11-11 5:27 [PATCH] RISC-V: Add address map dumper Yash Shah
@ 2019-11-11 18:14 ` Logan Gunthorpe
2019-11-11 21:55 ` Mike Rapoport
2019-11-12 6:19 ` Yash Shah
2019-11-11 21:56 ` Mike Rapoport
1 sibling, 2 replies; 6+ messages in thread
From: Logan Gunthorpe @ 2019-11-11 18:14 UTC (permalink / raw)
To: Yash Shah, Paul Walmsley ( Sifive), linux-riscv, linux-kernel
Cc: palmer, aou, Anup.Patel, rppt, ren_guo, bmeng.cn, tglx, Sachin Ghadi
On 2019-11-10 10:27 p.m., Yash Shah wrote:
> Add support for dumping the kernel address space layout to the console.
> User can enable CONFIG_DEBUG_VM_LAYOUT to dump the virtual memory region
> into dmesg buffer during boot-up.
Cool, I'd find this useful. Though, is there any reason we don't do this
more generally for all architectures?
> Signed-off-by: Yash Shah <yash.shah@sifive.com>
> ---
> This patch is based on Linux 5.4-rc6 and tested on SiFive HiFive Unleashed
> board.
> ---
> arch/riscv/Kconfig.debug | 9 +++++++++
> arch/riscv/mm/init.c | 30 ++++++++++++++++++++++++++++++
> 2 files changed, 39 insertions(+)
>
> diff --git a/arch/riscv/Kconfig.debug b/arch/riscv/Kconfig.debug
> index e69de29..cdedfd3 100644
> --- a/arch/riscv/Kconfig.debug
> +++ b/arch/riscv/Kconfig.debug
> @@ -0,0 +1,9 @@
> +config DEBUG_VM_LAYOUT
> + bool "Print virtual memory layout on boot up"
> + depends on DEBUG_KERNEL
> + help
> + Say Y here if you want to dump the kernel virtual memory layout to
> + dmesg log on boot up. This information is only useful for kernel
> + developers who are working in architecture specific areas of the
> + kernel. It is probably not a good idea to enable this feature in a
> + production kernel.
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 79cfb35..fcb8144 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -55,6 +55,36 @@ void __init mem_init(void)
> memblock_free_all();
>
> mem_init_print_info(NULL);
> +#ifdef CONFIG_DEBUG_VM_LAYOUT
Generally, it's best to avoid #ifdefs inside functions, it's even
counter-indicated in the style guide[1].
> +#define MLK(b, t) b, t, (((t) - (b)) >> 10)
> +#define MLM(b, t) b, t, (((t) - (b)) >> 20)
> +#define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K)
I personally find these inline defines rather ugly. Maybe it would be
better to have a helper function that prints a single line. Also seems
like MLK and MLK_ROUNDUP could be the same assuming the entries in MLK
are aligned...
> +
> + pr_notice("Virtual kernel memory layout:\n"
> + " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
> + " vmemmap : 0x%08lx - 0x%08lx (%4ld MB)\n"
> + " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n"
> + " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n"
> + " .init : 0x%px - 0x%px (%4td kB)\n"
> + " .text : 0x%px - 0x%px (%4td kB)\n"
> + " .data : 0x%px - 0x%px (%4td kB)\n"
> + " .bss : 0x%px - 0x%px (%4td kB)\n",
> +
> + MLK(FIXADDR_START, FIXADDR_TOP),
> + MLM(VMEMMAP_START, VMEMMAP_END),
> + MLM(VMALLOC_START, VMALLOC_END),
> + MLM(PAGE_OFFSET, (unsigned long)high_memory),
> +
> + MLK_ROUNDUP(__init_begin, __init_end),
> + MLK_ROUNDUP(_text, _etext),
> + MLK_ROUNDUP(_sdata, _edata),
> + MLK_ROUNDUP(__bss_start, __bss_stop));
> +
> +#undef MLK
> +#undef MLM
> +#undef MLK_ROUNDUP
> +#endif
> }
>
> #ifdef CONFIG_BLK_DEV_INITRD
Thanks,
Logan
[1]
https://www.kernel.org/doc/html/latest/process/coding-style.html#conditional-compilation
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] RISC-V: Add address map dumper
2019-11-11 18:14 ` Logan Gunthorpe
@ 2019-11-11 21:55 ` Mike Rapoport
2019-11-12 6:19 ` Yash Shah
1 sibling, 0 replies; 6+ messages in thread
From: Mike Rapoport @ 2019-11-11 21:55 UTC (permalink / raw)
To: Logan Gunthorpe
Cc: Yash Shah, Paul Walmsley ( Sifive),
linux-riscv, linux-kernel, palmer, aou, Anup.Patel, ren_guo,
bmeng.cn, tglx, Sachin Ghadi
On Mon, Nov 11, 2019 at 11:14:30AM -0700, Logan Gunthorpe wrote:
>
>
> On 2019-11-10 10:27 p.m., Yash Shah wrote:
> > Add support for dumping the kernel address space layout to the console.
> > User can enable CONFIG_DEBUG_VM_LAYOUT to dump the virtual memory region
> > into dmesg buffer during boot-up.
>
> Cool, I'd find this useful. Though, is there any reason we don't do this
> more generally for all architectures?
Some architectures do this, some don't. I don't think there's a particular
reason we don't do this generally, it just evolved that way :)
> > Signed-off-by: Yash Shah <yash.shah@sifive.com>
> > ---
> > This patch is based on Linux 5.4-rc6 and tested on SiFive HiFive Unleashed
> > board.
> > ---
> > arch/riscv/Kconfig.debug | 9 +++++++++
> > arch/riscv/mm/init.c | 30 ++++++++++++++++++++++++++++++
> > 2 files changed, 39 insertions(+)
> >
> > diff --git a/arch/riscv/Kconfig.debug b/arch/riscv/Kconfig.debug
> > index e69de29..cdedfd3 100644
> > --- a/arch/riscv/Kconfig.debug
> > +++ b/arch/riscv/Kconfig.debug
> > @@ -0,0 +1,9 @@
> > +config DEBUG_VM_LAYOUT
> > + bool "Print virtual memory layout on boot up"
> > + depends on DEBUG_KERNEL
> > + help
> > + Say Y here if you want to dump the kernel virtual memory layout to
> > + dmesg log on boot up. This information is only useful for kernel
> > + developers who are working in architecture specific areas of the
> > + kernel. It is probably not a good idea to enable this feature in a
> > + production kernel.
> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> > index 79cfb35..fcb8144 100644
> > --- a/arch/riscv/mm/init.c
> > +++ b/arch/riscv/mm/init.c
> > @@ -55,6 +55,36 @@ void __init mem_init(void)
> > memblock_free_all();
> >
> > mem_init_print_info(NULL);
> > +#ifdef CONFIG_DEBUG_VM_LAYOUT
>
> Generally, it's best to avoid #ifdefs inside functions, it's even
> counter-indicated in the style guide[1].
>
> > +#define MLK(b, t) b, t, (((t) - (b)) >> 10)
> > +#define MLM(b, t) b, t, (((t) - (b)) >> 20)
> > +#define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K)
>
> I personally find these inline defines rather ugly. Maybe it would be
> better to have a helper function that prints a single line. Also seems
> like MLK and MLK_ROUNDUP could be the same assuming the entries in MLK
> are aligned...
>
> > +
> > + pr_notice("Virtual kernel memory layout:\n"
> > + " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
> > + " vmemmap : 0x%08lx - 0x%08lx (%4ld MB)\n"
> > + " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n"
> > + " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n"
> > + " .init : 0x%px - 0x%px (%4td kB)\n"
> > + " .text : 0x%px - 0x%px (%4td kB)\n"
> > + " .data : 0x%px - 0x%px (%4td kB)\n"
> > + " .bss : 0x%px - 0x%px (%4td kB)\n",
> > +
> > + MLK(FIXADDR_START, FIXADDR_TOP),
> > + MLM(VMEMMAP_START, VMEMMAP_END),
> > + MLM(VMALLOC_START, VMALLOC_END),
> > + MLM(PAGE_OFFSET, (unsigned long)high_memory),
> > +
> > + MLK_ROUNDUP(__init_begin, __init_end),
> > + MLK_ROUNDUP(_text, _etext),
> > + MLK_ROUNDUP(_sdata, _edata),
> > + MLK_ROUNDUP(__bss_start, __bss_stop));
> > +
> > +#undef MLK
> > +#undef MLM
> > +#undef MLK_ROUNDUP
> > +#endif
> > }
> >
> > #ifdef CONFIG_BLK_DEV_INITRD
>
> Thanks,
>
> Logan
>
> [1]
> https://www.kernel.org/doc/html/latest/process/coding-style.html#conditional-compilation
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] RISC-V: Add address map dumper
2019-11-11 5:27 [PATCH] RISC-V: Add address map dumper Yash Shah
2019-11-11 18:14 ` Logan Gunthorpe
@ 2019-11-11 21:56 ` Mike Rapoport
2019-11-12 6:35 ` Yash Shah
1 sibling, 1 reply; 6+ messages in thread
From: Mike Rapoport @ 2019-11-11 21:56 UTC (permalink / raw)
To: Yash Shah
Cc: Paul Walmsley ( Sifive),
linux-riscv, linux-kernel, palmer, aou, Anup.Patel, logang,
ren_guo, bmeng.cn, tglx, Sachin Ghadi
Hi,
On Mon, Nov 11, 2019 at 05:27:25AM +0000, Yash Shah wrote:
> Add support for dumping the kernel address space layout to the console.
> User can enable CONFIG_DEBUG_VM_LAYOUT to dump the virtual memory region
> into dmesg buffer during boot-up.
>
> Signed-off-by: Yash Shah <yash.shah@sifive.com>
> ---
> This patch is based on Linux 5.4-rc6 and tested on SiFive HiFive Unleashed
> board.
> ---
> arch/riscv/Kconfig.debug | 9 +++++++++
> arch/riscv/mm/init.c | 30 ++++++++++++++++++++++++++++++
> 2 files changed, 39 insertions(+)
>
> diff --git a/arch/riscv/Kconfig.debug b/arch/riscv/Kconfig.debug
> index e69de29..cdedfd3 100644
> --- a/arch/riscv/Kconfig.debug
> +++ b/arch/riscv/Kconfig.debug
> @@ -0,0 +1,9 @@
> +config DEBUG_VM_LAYOUT
I believe this could be enabled when CONFIG_DEBUG_VM=y without adding yet
another architecture specific Kconfig option.
> + bool "Print virtual memory layout on boot up"
> + depends on DEBUG_KERNEL
> + help
> + Say Y here if you want to dump the kernel virtual memory layout to
> + dmesg log on boot up. This information is only useful for kernel
> + developers who are working in architecture specific areas of the
> + kernel. It is probably not a good idea to enable this feature in a
> + production kernel.
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 79cfb35..fcb8144 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -55,6 +55,36 @@ void __init mem_init(void)
> memblock_free_all();
>
> mem_init_print_info(NULL);
> +#ifdef CONFIG_DEBUG_VM_LAYOUT
> +#define MLK(b, t) b, t, (((t) - (b)) >> 10)
> +#define MLM(b, t) b, t, (((t) - (b)) >> 20)
> +#define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K)
> +
> +
> + pr_notice("Virtual kernel memory layout:\n"
> + " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
> + " vmemmap : 0x%08lx - 0x%08lx (%4ld MB)\n"
> + " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n"
> + " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n"
> + " .init : 0x%px - 0x%px (%4td kB)\n"
> + " .text : 0x%px - 0x%px (%4td kB)\n"
> + " .data : 0x%px - 0x%px (%4td kB)\n"
> + " .bss : 0x%px - 0x%px (%4td kB)\n",
> +
> + MLK(FIXADDR_START, FIXADDR_TOP),
> + MLM(VMEMMAP_START, VMEMMAP_END),
> + MLM(VMALLOC_START, VMALLOC_END),
> + MLM(PAGE_OFFSET, (unsigned long)high_memory),
> +
> + MLK_ROUNDUP(__init_begin, __init_end),
> + MLK_ROUNDUP(_text, _etext),
> + MLK_ROUNDUP(_sdata, _edata),
> + MLK_ROUNDUP(__bss_start, __bss_stop));
> +
> +#undef MLK
> +#undef MLM
> +#undef MLK_ROUNDUP
> +#endif
> }
>
> #ifdef CONFIG_BLK_DEV_INITRD
> --
> 2.7.4
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] RISC-V: Add address map dumper
2019-11-11 18:14 ` Logan Gunthorpe
2019-11-11 21:55 ` Mike Rapoport
@ 2019-11-12 6:19 ` Yash Shah
1 sibling, 0 replies; 6+ messages in thread
From: Yash Shah @ 2019-11-12 6:19 UTC (permalink / raw)
To: Logan Gunthorpe, Paul Walmsley ( Sifive), linux-riscv, linux-kernel
Cc: aou, Anup.Patel, rppt, Sachin Ghadi, palmer, ren_guo, tglx, bmeng.cn
> On 2019-11-10 10:27 p.m., Yash Shah wrote:
> > Add support for dumping the kernel address space layout to the console.
> > User can enable CONFIG_DEBUG_VM_LAYOUT to dump the virtual
> memory
> > region into dmesg buffer during boot-up.
>
> Cool, I'd find this useful. Though, is there any reason we don't do this more
> generally for all architectures?
>
> > Signed-off-by: Yash Shah <yash.shah@sifive.com>
> > ---
> > This patch is based on Linux 5.4-rc6 and tested on SiFive HiFive
> > Unleashed board.
> > ---
> > arch/riscv/Kconfig.debug | 9 +++++++++
> > arch/riscv/mm/init.c | 30 ++++++++++++++++++++++++++++++
> > 2 files changed, 39 insertions(+)
> >
...
> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index
> > 79cfb35..fcb8144 100644
> > --- a/arch/riscv/mm/init.c
> > +++ b/arch/riscv/mm/init.c
> > @@ -55,6 +55,36 @@ void __init mem_init(void)
> > memblock_free_all();
> >
> > mem_init_print_info(NULL);
> > +#ifdef CONFIG_DEBUG_VM_LAYOUT
>
> Generally, it's best to avoid #ifdefs inside functions, it's even counter-
> indicated in the style guide[1].
Yes, I will move out the print logic as a separate function and guard it with #ifdefs
>
> > +#define MLK(b, t) b, t, (((t) - (b)) >> 10) #define MLM(b, t) b, t,
> > +(((t) - (b)) >> 20) #define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t)
> > +- (b)), SZ_1K)
>
> I personally find these inline defines rather ugly. Maybe it would be better to
> have a helper function that prints a single line. Also seems like MLK and
> MLK_ROUNDUP could be the same assuming the entries in MLK are
> aligned...
>
Sure, will convert this macros into helper inline functions and will also drop MLK_ROUNDUP.
>
> Thanks,
>
> Logan
>
Thanks for your comments!
- Yash
> [1]
> https://www.kernel.org/doc/html/latest/process/coding-
> style.html#conditional-compilation
>
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] RISC-V: Add address map dumper
2019-11-11 21:56 ` Mike Rapoport
@ 2019-11-12 6:35 ` Yash Shah
0 siblings, 0 replies; 6+ messages in thread
From: Yash Shah @ 2019-11-12 6:35 UTC (permalink / raw)
To: Mike Rapoport
Cc: Paul Walmsley ( Sifive),
linux-riscv, linux-kernel, palmer, aou, Anup.Patel, logang,
ren_guo, bmeng.cn, tglx, Sachin Ghadi
> -----Original Message-----
> From: Mike Rapoport <rppt@linux.ibm.com>
> Sent: 12 November 2019 03:27
> To: Yash Shah <yash.shah@sifive.com>
> Cc: Paul Walmsley ( Sifive) <paul.walmsley@sifive.com>; linux-
> riscv@lists.infradead.org; linux-kernel@vger.kernel.org;
> palmer@dabbelt.com; aou@eecs.berkeley.edu; Anup.Patel@wdc.com;
> logang@deltatee.com; ren_guo@c-sky.com; bmeng.cn@gmail.com;
> tglx@linutronix.de; Sachin Ghadi <sachin.ghadi@sifive.com>
> Subject: Re: [PATCH] RISC-V: Add address map dumper
>
> Hi,
>
> On Mon, Nov 11, 2019 at 05:27:25AM +0000, Yash Shah wrote:
> > Add support for dumping the kernel address space layout to the console.
> > User can enable CONFIG_DEBUG_VM_LAYOUT to dump the virtual
> memory
> > region into dmesg buffer during boot-up.
> >
> > Signed-off-by: Yash Shah <yash.shah@sifive.com>
> > ---
> > This patch is based on Linux 5.4-rc6 and tested on SiFive HiFive
> > Unleashed board.
> > ---
> > arch/riscv/Kconfig.debug | 9 +++++++++
> > arch/riscv/mm/init.c | 30 ++++++++++++++++++++++++++++++
> > 2 files changed, 39 insertions(+)
> >
> > diff --git a/arch/riscv/Kconfig.debug b/arch/riscv/Kconfig.debug index
> > e69de29..cdedfd3 100644
> > --- a/arch/riscv/Kconfig.debug
> > +++ b/arch/riscv/Kconfig.debug
> > @@ -0,0 +1,9 @@
> > +config DEBUG_VM_LAYOUT
>
> I believe this could be enabled when CONFIG_DEBUG_VM=y without adding
> yet another architecture specific Kconfig option.
Oh yes, I will drop the newly added kconfig option in v2.
> --
> Sincerely yours,
> Mike.
Thanks for your comment!
- Yash
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-11-12 6:35 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-11 5:27 [PATCH] RISC-V: Add address map dumper Yash Shah
2019-11-11 18:14 ` Logan Gunthorpe
2019-11-11 21:55 ` Mike Rapoport
2019-11-12 6:19 ` Yash Shah
2019-11-11 21:56 ` Mike Rapoport
2019-11-12 6:35 ` Yash Shah
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).