Re: [PATCH 19/21] MIPS memblock: Add print out method of kernel virtual memory layout
On Mon, Dec 19, 2016 at 01:02:37PM +, James Hogan wrote: > Hi Matt, > > On Mon, Dec 19, 2016 at 12:04:54PM +, Matt Redfearn wrote: > > On 19/12/16 02:07, Serge Semin wrote: > > > It's useful to have some printed map of the kernel virtual memory, > > > at least for debugging purpose. > > > > > > Signed-off-by: Serge Semin > > > --- > > > > @@ -106,6 +107,49 @@ static void __init zone_sizes_init(void) > > > } > > > > > > /* > > > + * Print out kernel memory 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) > > > +static void __init mem_print_kmap_info(void) > > > +{ > > > + pr_notice("Virtual kernel memory layout:\n" > > > + "lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n" > > > + "vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n" > > > +#ifdef CONFIG_HIGHMEM > > > + "pkmap : 0x%08lx - 0x%08lx (%4ld MB)\n" > > > +#endif > > > + "fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n" > > > + " .text : 0x%p" " - 0x%p" " (%4td kB)\n" > > > + " .data : 0x%p" " - 0x%p" " (%4td kB)\n" > > > + " .init : 0x%p" " - 0x%p" " (%4td kB)\n", > > > + MLM(PAGE_OFFSET, (unsigned long)high_memory), > > > + MLM(VMALLOC_START, VMALLOC_END), > > > +#ifdef CONFIG_HIGHMEM > > > + MLM(PKMAP_BASE, (PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE)), > > > +#endif > > > + MLK(FIXADDR_START, FIXADDR_TOP), > > > + MLK_ROUNDUP(_text, _etext), > > > + MLK_ROUNDUP(_sdata, _edata), > > > + MLK_ROUNDUP(__init_begin, __init_end)); > > > > Please drop printing the kernel addresses, or at least only do it if > > KASLR is not turned on, otherwise you're removing the advantage of > > KASLR, that critical kernel addresses cannot be determined easily from > > userspace. > > According to Documentation/printk-formats.txt, this is what %pK is for. > Better to use that instead? > > Cheers > James > The function is called from the kernel directly, which is privileged enough to do the printing. So I suppose Matt is right, to hide this prints out unless debug is enabled. Thanks, -Sergey > > > > It may be better to merge the functionality of show_kernel_relocation > > http://lxr.free-electrons.com/source/arch/mips/kernel/relocate.c#L354 > > into this function, but only print it under the same conditions as > > currently, i.e. > > #if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO) > > http://lxr.free-electrons.com/source/arch/mips/kernel/setup.c#L530 > > > > Thanks, > > Matt
Re: [PATCH 19/21] MIPS memblock: Add print out method of kernel virtual memory layout
Hi Matt, On Mon, Dec 19, 2016 at 12:04:54PM +, Matt Redfearn wrote: > On 19/12/16 02:07, Serge Semin wrote: > > It's useful to have some printed map of the kernel virtual memory, > > at least for debugging purpose. > > > > Signed-off-by: Serge Semin > > --- > > @@ -106,6 +107,49 @@ static void __init zone_sizes_init(void) > > } > > > > /* > > + * Print out kernel memory 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) > > +static void __init mem_print_kmap_info(void) > > +{ > > + pr_notice("Virtual kernel memory layout:\n" > > + "lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n" > > + "vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n" > > +#ifdef CONFIG_HIGHMEM > > + "pkmap : 0x%08lx - 0x%08lx (%4ld MB)\n" > > +#endif > > + "fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n" > > + " .text : 0x%p" " - 0x%p" " (%4td kB)\n" > > + " .data : 0x%p" " - 0x%p" " (%4td kB)\n" > > + " .init : 0x%p" " - 0x%p" " (%4td kB)\n", > > + MLM(PAGE_OFFSET, (unsigned long)high_memory), > > + MLM(VMALLOC_START, VMALLOC_END), > > +#ifdef CONFIG_HIGHMEM > > + MLM(PKMAP_BASE, (PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE)), > > +#endif > > + MLK(FIXADDR_START, FIXADDR_TOP), > > + MLK_ROUNDUP(_text, _etext), > > + MLK_ROUNDUP(_sdata, _edata), > > + MLK_ROUNDUP(__init_begin, __init_end)); > > Please drop printing the kernel addresses, or at least only do it if > KASLR is not turned on, otherwise you're removing the advantage of > KASLR, that critical kernel addresses cannot be determined easily from > userspace. According to Documentation/printk-formats.txt, this is what %pK is for. Better to use that instead? Cheers James > > It may be better to merge the functionality of show_kernel_relocation > http://lxr.free-electrons.com/source/arch/mips/kernel/relocate.c#L354 > into this function, but only print it under the same conditions as > currently, i.e. > #if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO) > http://lxr.free-electrons.com/source/arch/mips/kernel/setup.c#L530 > > Thanks, > Matt signature.asc Description: Digital signature
Re: [PATCH 19/21] MIPS memblock: Add print out method of kernel virtual memory layout
On Mon, Dec 19, 2016 at 12:04:54PM +, Matt Redfearn wrote: Hello Matt. > Hi Serge, > > > On 19/12/16 02:07, Serge Semin wrote: > >It's useful to have some printed map of the kernel virtual memory, > >at least for debugging purpose. > > > >Signed-off-by: Serge Semin > >--- > > arch/mips/mm/init.c | 47 +++ > > 1 file changed, 47 insertions(+) > > > >diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c > >index 13a032f..35e7ba8 100644 > >--- a/arch/mips/mm/init.c > >+++ b/arch/mips/mm/init.c > >@@ -32,6 +32,7 @@ > > #include > > #include > > #include > >+#include > > #include > > #include > >@@ -106,6 +107,49 @@ static void __init zone_sizes_init(void) > > } > > /* > >+ * Print out kernel memory 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) > >+static void __init mem_print_kmap_info(void) > >+{ > >+pr_notice("Virtual kernel memory layout:\n" > >+ "lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n" > >+ "vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n" > >+#ifdef CONFIG_HIGHMEM > >+ "pkmap : 0x%08lx - 0x%08lx (%4ld MB)\n" > >+#endif > >+ "fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n" > >+ " .text : 0x%p" " - 0x%p" " (%4td kB)\n" > >+ " .data : 0x%p" " - 0x%p" " (%4td kB)\n" > >+ " .init : 0x%p" " - 0x%p" " (%4td kB)\n", > >+MLM(PAGE_OFFSET, (unsigned long)high_memory), > >+MLM(VMALLOC_START, VMALLOC_END), > >+#ifdef CONFIG_HIGHMEM > >+MLM(PKMAP_BASE, (PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE)), > >+#endif > >+MLK(FIXADDR_START, FIXADDR_TOP), > >+MLK_ROUNDUP(_text, _etext), > >+MLK_ROUNDUP(_sdata, _edata), > >+MLK_ROUNDUP(__init_begin, __init_end)); > > Please drop printing the kernel addresses, or at least only do it if KASLR > is not turned on, otherwise you're removing the advantage of KASLR, that > critical kernel addresses cannot be determined easily from userspace. > > It may be better to merge the functionality of show_kernel_relocation > http://lxr.free-electrons.com/source/arch/mips/kernel/relocate.c#L354 > into this function, but only print it under the same conditions as > currently, i.e. > #if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO) > http://lxr.free-electrons.com/source/arch/mips/kernel/setup.c#L530 > > Thanks, > Matt > Understood. Will be fixed within the next patchset. > >+ > >+/* Check some fundamental inconsistencies. May add something else? */ > >+#ifdef CONFIG_HIGHMEM > >+BUILD_BUG_ON(VMALLOC_END < PAGE_OFFSET); > >+BUG_ON(VMALLOC_END < (unsigned long)high_memory); > >+#endif > >+BUILD_BUG_ON((PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE) < PAGE_OFFSET); > >+BUG_ON((PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE) < > >+(unsigned long)high_memory); > >+BUILD_BUG_ON(FIXADDR_TOP < PAGE_OFFSET); > >+BUG_ON(FIXADDR_TOP < (unsigned long)high_memory); > >+} > >+#undef MLK > >+#undef MLM > >+#undef MLK_ROUNDUP > >+ > >+/* > > * Not static inline because used by IP27 special magic initialization code > > */ > > void setup_zero_pages(void) > >@@ -492,6 +536,9 @@ void __init mem_init(void) > > /* Free highmemory registered in memblocks */ > > mem_init_free_highmem(); > >+/* Print out kernel memory layout */ > >+mem_print_kmap_info(); > >+ > > /* Print out memory areas statistics */ > > mem_init_print_info(NULL); >
Re: [PATCH 19/21] MIPS memblock: Add print out method of kernel virtual memory layout
Hi Serge, On 19/12/16 02:07, Serge Semin wrote: It's useful to have some printed map of the kernel virtual memory, at least for debugging purpose. Signed-off-by: Serge Semin --- arch/mips/mm/init.c | 47 +++ 1 file changed, 47 insertions(+) diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c index 13a032f..35e7ba8 100644 --- a/arch/mips/mm/init.c +++ b/arch/mips/mm/init.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -106,6 +107,49 @@ static void __init zone_sizes_init(void) } /* + * Print out kernel memory 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) +static void __init mem_print_kmap_info(void) +{ + pr_notice("Virtual kernel memory layout:\n" + "lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n" + "vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n" +#ifdef CONFIG_HIGHMEM + "pkmap : 0x%08lx - 0x%08lx (%4ld MB)\n" +#endif + "fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n" + " .text : 0x%p" " - 0x%p" " (%4td kB)\n" + " .data : 0x%p" " - 0x%p" " (%4td kB)\n" + " .init : 0x%p" " - 0x%p" " (%4td kB)\n", + MLM(PAGE_OFFSET, (unsigned long)high_memory), + MLM(VMALLOC_START, VMALLOC_END), +#ifdef CONFIG_HIGHMEM + MLM(PKMAP_BASE, (PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE)), +#endif + MLK(FIXADDR_START, FIXADDR_TOP), + MLK_ROUNDUP(_text, _etext), + MLK_ROUNDUP(_sdata, _edata), + MLK_ROUNDUP(__init_begin, __init_end)); Please drop printing the kernel addresses, or at least only do it if KASLR is not turned on, otherwise you're removing the advantage of KASLR, that critical kernel addresses cannot be determined easily from userspace. It may be better to merge the functionality of show_kernel_relocation http://lxr.free-electrons.com/source/arch/mips/kernel/relocate.c#L354 into this function, but only print it under the same conditions as currently, i.e. #if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO) http://lxr.free-electrons.com/source/arch/mips/kernel/setup.c#L530 Thanks, Matt + + /* Check some fundamental inconsistencies. May add something else? */ +#ifdef CONFIG_HIGHMEM + BUILD_BUG_ON(VMALLOC_END < PAGE_OFFSET); + BUG_ON(VMALLOC_END < (unsigned long)high_memory); +#endif + BUILD_BUG_ON((PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE) < PAGE_OFFSET); + BUG_ON((PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE) < + (unsigned long)high_memory); + BUILD_BUG_ON(FIXADDR_TOP < PAGE_OFFSET); + BUG_ON(FIXADDR_TOP < (unsigned long)high_memory); +} +#undef MLK +#undef MLM +#undef MLK_ROUNDUP + +/* * Not static inline because used by IP27 special magic initialization code */ void setup_zero_pages(void) @@ -492,6 +536,9 @@ void __init mem_init(void) /* Free highmemory registered in memblocks */ mem_init_free_highmem(); + /* Print out kernel memory layout */ + mem_print_kmap_info(); + /* Print out memory areas statistics */ mem_init_print_info(NULL);
Re: [PATCH 19/21] MIPS memblock: Add print out method of kernel virtual memory layout
Hi Serge, [auto build test ERROR on linus/master] [also build test ERROR on v4.9 next-20161216] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Serge-Semin/MIPS-memblock-Remove-bootmem-code-and-switch-to-NO_BOOTMEM/20161219-105045 config: mips-allyesconfig (attached as .config) compiler: mips-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705 reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=mips All error/warnings (new ones prefixed by >>): In file included from arch/mips/include/asm/bug.h:4:0, from include/linux/bug.h:4, from arch/mips/mm/init.c:12: arch/mips/mm/init.c: In function 'mem_print_kmap_info': >> arch/mips/mm/init.c:143:31: error: 'LAST_PKMAP' undeclared (first use in >> this function) BUILD_BUG_ON((PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE) < PAGE_OFFSET); ^ include/linux/compiler.h:498:19: note: in definition of macro '__compiletime_assert' bool __cond = !(condition);\ ^ include/linux/compiler.h:518:2: note: in expansion of macro '_compiletime_assert' _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) ^~~ include/linux/bug.h:54:37: note: in expansion of macro 'compiletime_assert' #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) ^~ include/linux/bug.h:78:2: note: in expansion of macro 'BUILD_BUG_ON_MSG' BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) ^~~~ >> arch/mips/mm/init.c:143:2: note: in expansion of macro 'BUILD_BUG_ON' BUILD_BUG_ON((PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE) < PAGE_OFFSET); ^~~~ arch/mips/mm/init.c:143:31: note: each undeclared identifier is reported only once for each function it appears in BUILD_BUG_ON((PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE) < PAGE_OFFSET); ^ include/linux/compiler.h:498:19: note: in definition of macro '__compiletime_assert' bool __cond = !(condition);\ ^ include/linux/compiler.h:518:2: note: in expansion of macro '_compiletime_assert' _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) ^~~ include/linux/bug.h:54:37: note: in expansion of macro 'compiletime_assert' #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) ^~ include/linux/bug.h:78:2: note: in expansion of macro 'BUILD_BUG_ON_MSG' BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) ^~~~ >> arch/mips/mm/init.c:143:2: note: in expansion of macro 'BUILD_BUG_ON' BUILD_BUG_ON((PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE) < PAGE_OFFSET); ^~~~ vim +/LAST_PKMAP +143 arch/mips/mm/init.c 6 * Copyright (C) 1994 - 2000 Ralf Baechle 7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc. 8 * Kevin D. Kissell, kev...@mips.com and Carsten Langgaard, carst...@mips.com 9 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved. 10 * Copyright (C) 2016 T-Platforms. All Rights Reserved. 11 */ > 12 #include 13 #include 14 #include 15 #include 16 #include 17 #include 18 #include 19 #include 20 #include 21 #include 22 #include 23 #include 24 #include 25 #include 26 #include 27 #include 28 #include 29 #include 30 #include 31 #include 32 #include 33 #include 34 #include 35 #include 36 37 #include 38 #include 39 #include 40 #include 41 #include 42 #include 43 #include 44 #include 45 #include 46 #include 47 #include 48 #include 49 #include 50 #include 51 52 /* 53 * We have up to 8 empty zeroed pages so we can map one of the right colour 54 * when needed. This is necessary only on R4000 / R4400 SC and MC versions 55 * where we have to avoid VCED / VECI exceptions for good performance at 56 * any price. Since page is never written to after the initialization we 57 * don't have to care about aliases on other CPUs. 58 */ 59 unsigned long empty_zero_page, zero_page_mask; 60 EXPORT_SYMBOL_GPL(empty_zero_page); 61 EXPORT_SYMBOL(zero_page_mask); 62 63 /* 64 * Initialize sparse memory sections setting node ids and indexes 65 */ 66 static void __init mips_memory_present(void) 67 { 68 #ifdef
[PATCH 19/21] MIPS memblock: Add print out method of kernel virtual memory layout
It's useful to have some printed map of the kernel virtual memory, at least for debugging purpose. Signed-off-by: Serge Semin --- arch/mips/mm/init.c | 47 +++ 1 file changed, 47 insertions(+) diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c index 13a032f..35e7ba8 100644 --- a/arch/mips/mm/init.c +++ b/arch/mips/mm/init.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -106,6 +107,49 @@ static void __init zone_sizes_init(void) } /* + * Print out kernel memory 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) +static void __init mem_print_kmap_info(void) +{ + pr_notice("Virtual kernel memory layout:\n" + "lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n" + "vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n" +#ifdef CONFIG_HIGHMEM + "pkmap : 0x%08lx - 0x%08lx (%4ld MB)\n" +#endif + "fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n" + " .text : 0x%p" " - 0x%p" " (%4td kB)\n" + " .data : 0x%p" " - 0x%p" " (%4td kB)\n" + " .init : 0x%p" " - 0x%p" " (%4td kB)\n", + MLM(PAGE_OFFSET, (unsigned long)high_memory), + MLM(VMALLOC_START, VMALLOC_END), +#ifdef CONFIG_HIGHMEM + MLM(PKMAP_BASE, (PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE)), +#endif + MLK(FIXADDR_START, FIXADDR_TOP), + MLK_ROUNDUP(_text, _etext), + MLK_ROUNDUP(_sdata, _edata), + MLK_ROUNDUP(__init_begin, __init_end)); + + /* Check some fundamental inconsistencies. May add something else? */ +#ifdef CONFIG_HIGHMEM + BUILD_BUG_ON(VMALLOC_END < PAGE_OFFSET); + BUG_ON(VMALLOC_END < (unsigned long)high_memory); +#endif + BUILD_BUG_ON((PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE) < PAGE_OFFSET); + BUG_ON((PKMAP_BASE) + (LAST_PKMAP)*(PAGE_SIZE) < + (unsigned long)high_memory); + BUILD_BUG_ON(FIXADDR_TOP < PAGE_OFFSET); + BUG_ON(FIXADDR_TOP < (unsigned long)high_memory); +} +#undef MLK +#undef MLM +#undef MLK_ROUNDUP + +/* * Not static inline because used by IP27 special magic initialization code */ void setup_zero_pages(void) @@ -492,6 +536,9 @@ void __init mem_init(void) /* Free highmemory registered in memblocks */ mem_init_free_highmem(); + /* Print out kernel memory layout */ + mem_print_kmap_info(); + /* Print out memory areas statistics */ mem_init_print_info(NULL); -- 2.6.6