linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matt Redfearn <matt.redfearn@imgtec.com>
To: Serge Semin <fancer.lancer@gmail.com>,
	ralf@linux-mips.org, paul.burton@imgtec.com, rabinv@axis.com,
	james.hogan@imgtec.com, alexander.sverdlin@nokia.com,
	robh+dt@kernel.org, frowand.list@gmail.com
Cc: Sergey.Semin@t-platforms.ru, linux-mips@linux-mips.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 19/21] MIPS memblock: Add print out method of kernel virtual memory layout
Date: Mon, 19 Dec 2016 12:04:54 +0000	[thread overview]
Message-ID: <db27f41e-4121-bb83-6533-6727c26b9c5b@imgtec.com> (raw)
Message-ID: <20161219120454.nkNURdpAYZdeUymRpEd798eAaY4_CteAPaazoFS4cCU@z> (raw)
In-Reply-To: <1482113266-13207-20-git-send-email-fancer.lancer@gmail.com>

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 <fancer.lancer@gmail.com>
> ---
>   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 <linux/hardirq.h>
>   #include <linux/gfp.h>
>   #include <linux/kcore.h>
> +#include <linux/sizes.h>
>   
>   #include <asm/asm-offsets.h>
>   #include <asm/bootinfo.h>
> @@ -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);
>   

  reply	other threads:[~2016-12-19 12:05 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-19  2:07 [PATCH 00/21] MIPS memblock: Remove bootmem code and switch to NO_BOOTMEM Serge Semin
2016-12-19  2:07 ` [PATCH 01/21] MIPS memblock: Unpin dts memblock sanity check method Serge Semin
2016-12-19  4:21   ` kbuild test robot
2016-12-19  4:21     ` kbuild test robot
2016-12-19  4:28   ` kbuild test robot
2016-12-19  4:28     ` kbuild test robot
2016-12-22 20:57   ` Rob Herring
2016-12-22 21:57     ` Serge Semin
2016-12-19  2:07 ` [PATCH 02/21] MIPS memblock: Add dts mem and reserved-mem callbacks Serge Semin
2016-12-19  4:13   ` kbuild test robot
2016-12-19  4:13     ` kbuild test robot
2016-12-19  2:07 ` [PATCH 03/21] MIPS memblock: Alter traditional add_memory_region() method Serge Semin
2016-12-19  2:07 ` [PATCH 04/21] MIPS memblock: Alter user-defined memory parameter parser Serge Semin
2017-01-23  7:55   ` Marcin Nowakowski
2017-01-23  7:55     ` Marcin Nowakowski
2016-12-19  2:07 ` [PATCH 05/21] MIPS memblock: Alter initrd memory reservation method Serge Semin
2016-12-19  5:08   ` kbuild test robot
2016-12-19  5:08     ` kbuild test robot
2016-12-19  2:07 ` [PATCH 06/21] MIPS memblock: Alter kexec-crashkernel parameters parser Serge Semin
2016-12-19  2:07 ` [PATCH 07/21] MIPS memblock: Alter elfcorehdr " Serge Semin
2016-12-19  4:09   ` kbuild test robot
2016-12-19  4:09     ` kbuild test robot
2016-12-19  2:07 ` [PATCH 08/21] MIPS memblock: Move kernel parameters parser into individual method Serge Semin
2016-12-19  2:07 ` [PATCH 09/21] MIPS memblock: Move kernel memory reservation to " Serge Semin
2016-12-19  2:07 ` [PATCH 10/21] MIPS memblock: Discard bootmem allocator initialization Serge Semin
2016-12-19  4:28   ` kbuild test robot
2016-12-19  4:28     ` kbuild test robot
2017-01-23  7:55   ` Marcin Nowakowski
2017-01-23  7:55     ` Marcin Nowakowski
2016-12-19  2:07 ` [PATCH 11/21] MIPS memblock: Add memblock sanity check method Serge Semin
2016-12-19  2:07 ` [PATCH 12/21] MIPS memblock: Add memblock print outs in debug Serge Semin
2016-12-19  2:07 ` [PATCH 13/21] MIPS memblock: Add memblock allocator initialization Serge Semin
2016-12-19  2:07 ` [PATCH 14/21] MIPS memblock: Alter IO resources initialization method Serge Semin
2016-12-19  2:07 ` [PATCH 15/21] MIPS memblock: Alter weakened MAAR " Serge Semin
2016-12-19  2:07 ` [PATCH 16/21] MIPS memblock: Alter paging " Serge Semin
2016-12-19  2:07 ` [PATCH 17/21] MIPS memblock: Alter high memory freeing method Serge Semin
2016-12-19  2:07 ` [PATCH 18/21] MIPS memblock: Slightly improve buddy allocator init method Serge Semin
2016-12-19  2:07 ` [PATCH 19/21] MIPS memblock: Add print out method of kernel virtual memory layout Serge Semin
2016-12-19 12:04   ` Matt Redfearn [this message]
2016-12-19 12:04     ` Matt Redfearn
2016-12-19 12:09     ` Serge Semin
2016-12-19 13:02     ` James Hogan
2016-12-19 13:02       ` James Hogan
2016-12-19 13:15       ` Serge Semin
2016-12-19  2:07 ` [PATCH 20/21] MIPS memblock: Add free low memory test method call Serge Semin
2016-12-19  2:07 ` [PATCH 21/21] MIPS memblock: Deactivate old bootmem allocator Serge Semin
2017-01-23  7:55 ` [PATCH 00/21] MIPS memblock: Remove bootmem code and switch to NO_BOOTMEM Marcin Nowakowski
2017-01-23  7:55   ` Marcin Nowakowski
2017-03-02  3:06   ` Florian Fainelli
2017-01-23 14:51 ` Joshua Kinard
2017-05-22  9:48 ` Marcin Nowakowski
2017-05-22  9:48   ` Marcin Nowakowski
2017-05-22 10:26   ` Serge Semin
2017-05-22 12:19     ` Marcin Nowakowski
2017-05-22 12:19       ` Marcin Nowakowski
2017-05-22 12:47     ` Joshua Kinard
2017-05-22 13:03       ` Serge Semin
2017-05-22 13:20         ` Alexander Sverdlin
2017-05-22 13:20           ` Alexander Sverdlin
2017-05-22 13:29           ` Serge Semin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=db27f41e-4121-bb83-6533-6727c26b9c5b@imgtec.com \
    --to=matt.redfearn@imgtec.com \
    --cc=Sergey.Semin@t-platforms.ru \
    --cc=alexander.sverdlin@nokia.com \
    --cc=devicetree@vger.kernel.org \
    --cc=fancer.lancer@gmail.com \
    --cc=frowand.list@gmail.com \
    --cc=james.hogan@imgtec.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=paul.burton@imgtec.com \
    --cc=rabinv@axis.com \
    --cc=ralf@linux-mips.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).