mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC][PATCH] x86: nit: wrong page size in init_memory_mapping() printks
@ 2015-02-10 21:20 Dave Hansen
  2015-02-11 12:11 ` Borislav Petkov
  2015-02-19 11:34 ` [tip:x86/urgent] x86/mm/init: Fix incorrect " tip-bot for Dave Hansen
  0 siblings, 2 replies; 3+ messages in thread
From: Dave Hansen @ 2015-02-10 21:20 UTC (permalink / raw)
  To: linux-kernel; +Cc: x86, Dave Hansen, dave.hansen


From: Dave Hansen <dave.hansen@linux.intel.com>

With 32-bit non-PAE kernels, we have 2 page sizes available
(at most): 4k and 4M.

Enabling PAE replaces that 4M size with a 2M one (which 64-bit
systems use too).

But, when booting a 32-bit non-PAE kernel, in one of our
early-boot printouts, we say:

[    0.000000] init_memory_mapping: [mem 0x00000000-0x000fffff]
[    0.000000]  [mem 0x00000000-0x000fffff] page 4k
[    0.000000] init_memory_mapping: [mem 0x37000000-0x373fffff]
[    0.000000]  [mem 0x37000000-0x373fffff] page 2M
[    0.000000] init_memory_mapping: [mem 0x00100000-0x36ffffff]
[    0.000000]  [mem 0x00100000-0x003fffff] page 4k
[    0.000000]  [mem 0x00400000-0x36ffffff] page 2M
[    0.000000] init_memory_mapping: [mem 0x37400000-0x377fdfff]
[    0.000000]  [mem 0x37400000-0x377fdfff] page 4k

Which is obviously wrong.  There is no 2M page available.  This
is probably because of a badly-named variable: in the map_range
code: PG_LEVEL_2M.

Instead of renaming all the PG_LEVEL_2M's.  This patch just
fixes the printout:

[    0.000000] init_memory_mapping: [mem 0x00000000-0x000fffff]
[    0.000000]  [mem 0x00000000-0x000fffff] page 4k
[    0.000000] init_memory_mapping: [mem 0x37000000-0x373fffff]
[    0.000000]  [mem 0x37000000-0x373fffff] page 4M
[    0.000000] init_memory_mapping: [mem 0x00100000-0x36ffffff]
[    0.000000]  [mem 0x00100000-0x003fffff] page 4k
[    0.000000]  [mem 0x00400000-0x36ffffff] page 4M
[    0.000000] init_memory_mapping: [mem 0x37400000-0x377fdfff]
[    0.000000]  [mem 0x37400000-0x377fdfff] page 4k
[    0.000000] BRK [0x03206000, 0x03206fff] PGTABLE


Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
---

 b/arch/x86/mm/init.c |   28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff -puN arch/x86/mm/init.c~spitting-out-bad-page-size arch/x86/mm/init.c
--- a/arch/x86/mm/init.c~spitting-out-bad-page-size	2015-02-10 11:19:21.839208023 -0800
+++ b/arch/x86/mm/init.c	2015-02-10 11:19:21.848208428 -0800
@@ -238,6 +238,31 @@ static void __init_refok adjust_range_pa
 	}
 }
 
+static const char *page_size_string(struct map_range *mr)
+{
+	static const char str_1g[] = "1G";
+	static const char str_2m[] = "2M";
+	static const char str_4m[] = "4M";
+	static const char str_4k[] = "4k";
+
+	if (mr->page_size_mask & (1<<PG_LEVEL_1G))
+		return str_1g;
+	/*
+	 * 32-bit without PAE has a 4M large page size.
+	 * PG_LEVEL_2M is misnamed, but we can at least
+	 * print out the right size in the string.
+	 */
+	if (IS_ENABLED(CONFIG_X86_32) &&
+	    !IS_ENABLED(CONFIG_X86_PAE) &&
+	    mr->page_size_mask & (1<<PG_LEVEL_2M))
+		return str_4m;
+
+	if (mr->page_size_mask & (1<<PG_LEVEL_2M))
+		return str_2m;
+
+	return str_4k;
+}
+
 static int __meminit split_mem_range(struct map_range *mr, int nr_range,
 				     unsigned long start,
 				     unsigned long end)
@@ -333,8 +358,7 @@ static int __meminit split_mem_range(str
 	for (i = 0; i < nr_range; i++)
 		printk(KERN_DEBUG " [mem %#010lx-%#010lx] page %s\n",
 				mr[i].start, mr[i].end - 1,
-			(mr[i].page_size_mask & (1<<PG_LEVEL_1G))?"1G":(
-			 (mr[i].page_size_mask & (1<<PG_LEVEL_2M))?"2M":"4k"));
+				page_size_string(&mr[i]));
 
 	return nr_range;
 }
_

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC][PATCH] x86: nit: wrong page size in init_memory_mapping() printks
  2015-02-10 21:20 [RFC][PATCH] x86: nit: wrong page size in init_memory_mapping() printks Dave Hansen
@ 2015-02-11 12:11 ` Borislav Petkov
  2015-02-19 11:34 ` [tip:x86/urgent] x86/mm/init: Fix incorrect " tip-bot for Dave Hansen
  1 sibling, 0 replies; 3+ messages in thread
From: Borislav Petkov @ 2015-02-11 12:11 UTC (permalink / raw)
  To: Dave Hansen; +Cc: linux-kernel, x86, dave.hansen

On Tue, Feb 10, 2015 at 01:20:30PM -0800, Dave Hansen wrote:
> 
> From: Dave Hansen <dave.hansen@linux.intel.com>
> 
> With 32-bit non-PAE kernels, we have 2 page sizes available
> (at most): 4k and 4M.
> 
> Enabling PAE replaces that 4M size with a 2M one (which 64-bit
> systems use too).
> 
> But, when booting a 32-bit non-PAE kernel, in one of our
> early-boot printouts, we say:
> 
> [    0.000000] init_memory_mapping: [mem 0x00000000-0x000fffff]
> [    0.000000]  [mem 0x00000000-0x000fffff] page 4k
> [    0.000000] init_memory_mapping: [mem 0x37000000-0x373fffff]
> [    0.000000]  [mem 0x37000000-0x373fffff] page 2M
> [    0.000000] init_memory_mapping: [mem 0x00100000-0x36ffffff]
> [    0.000000]  [mem 0x00100000-0x003fffff] page 4k
> [    0.000000]  [mem 0x00400000-0x36ffffff] page 2M
> [    0.000000] init_memory_mapping: [mem 0x37400000-0x377fdfff]
> [    0.000000]  [mem 0x37400000-0x377fdfff] page 4k
> 
> Which is obviously wrong.  There is no 2M page available.  This
> is probably because of a badly-named variable: in the map_range
> code: PG_LEVEL_2M.
> 
> Instead of renaming all the PG_LEVEL_2M's.  This patch just
> fixes the printout:
> 
> [    0.000000] init_memory_mapping: [mem 0x00000000-0x000fffff]
> [    0.000000]  [mem 0x00000000-0x000fffff] page 4k
> [    0.000000] init_memory_mapping: [mem 0x37000000-0x373fffff]
> [    0.000000]  [mem 0x37000000-0x373fffff] page 4M
> [    0.000000] init_memory_mapping: [mem 0x00100000-0x36ffffff]
> [    0.000000]  [mem 0x00100000-0x003fffff] page 4k
> [    0.000000]  [mem 0x00400000-0x36ffffff] page 4M
> [    0.000000] init_memory_mapping: [mem 0x37400000-0x377fdfff]
> [    0.000000]  [mem 0x37400000-0x377fdfff] page 4k
> [    0.000000] BRK [0x03206000, 0x03206fff] PGTABLE
> 
> 
> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>

Looks ok to me considering that we're missing a PG_LEVEL_4M thing
completely which would need to be handled depending on X86_PAE and CR4
PSE and PAE bits. Probably not worth the trouble though.

Acked-by: Borislav Petkov <bp@suse.de>

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:x86/urgent] x86/mm/init: Fix incorrect page size in init_memory_mapping() printks
  2015-02-10 21:20 [RFC][PATCH] x86: nit: wrong page size in init_memory_mapping() printks Dave Hansen
  2015-02-11 12:11 ` Borislav Petkov
@ 2015-02-19 11:34 ` tip-bot for Dave Hansen
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Dave Hansen @ 2015-02-19 11:34 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, yinghai, bp, dave.hansen, linux-kernel, hpa, penberg, mingo

Commit-ID:  f15e05186c3244e9195378a0a568283a8ccc60b0
Gitweb:     http://git.kernel.org/tip/f15e05186c3244e9195378a0a568283a8ccc60b0
Author:     Dave Hansen <dave.hansen@linux.intel.com>
AuthorDate: Tue, 10 Feb 2015 13:20:30 -0800
Committer:  Borislav Petkov <bp@suse.de>
CommitDate: Thu, 19 Feb 2015 11:45:27 +0100

x86/mm/init: Fix incorrect page size in init_memory_mapping() printks

With 32-bit non-PAE kernels, we have 2 page sizes available
(at most): 4k and 4M.

Enabling PAE replaces that 4M size with a 2M one (which 64-bit
systems use too).

But, when booting a 32-bit non-PAE kernel, in one of our
early-boot printouts, we say:

  init_memory_mapping: [mem 0x00000000-0x000fffff]
   [mem 0x00000000-0x000fffff] page 4k
  init_memory_mapping: [mem 0x37000000-0x373fffff]
   [mem 0x37000000-0x373fffff] page 2M
  init_memory_mapping: [mem 0x00100000-0x36ffffff]
   [mem 0x00100000-0x003fffff] page 4k
   [mem 0x00400000-0x36ffffff] page 2M
  init_memory_mapping: [mem 0x37400000-0x377fdfff]
   [mem 0x37400000-0x377fdfff] page 4k

Which is obviously wrong.  There is no 2M page available.  This
is probably because of a badly-named variable: in the map_range
code: PG_LEVEL_2M.

Instead of renaming all the PG_LEVEL_2M's.  This patch just
fixes the printout:

  init_memory_mapping: [mem 0x00000000-0x000fffff]
   [mem 0x00000000-0x000fffff] page 4k
  init_memory_mapping: [mem 0x37000000-0x373fffff]
   [mem 0x37000000-0x373fffff] page 4M
  init_memory_mapping: [mem 0x00100000-0x36ffffff]
   [mem 0x00100000-0x003fffff] page 4k
   [mem 0x00400000-0x36ffffff] page 4M
  init_memory_mapping: [mem 0x37400000-0x377fdfff]
   [mem 0x37400000-0x377fdfff] page 4k
  BRK [0x03206000, 0x03206fff] PGTABLE

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/20150210212030.665EC267@viggo.jf.intel.com
Signed-off-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/mm/init.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 079c3b6..7ff2424 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -238,6 +238,31 @@ static void __init_refok adjust_range_page_size_mask(struct map_range *mr,
 	}
 }
 
+static const char *page_size_string(struct map_range *mr)
+{
+	static const char str_1g[] = "1G";
+	static const char str_2m[] = "2M";
+	static const char str_4m[] = "4M";
+	static const char str_4k[] = "4k";
+
+	if (mr->page_size_mask & (1<<PG_LEVEL_1G))
+		return str_1g;
+	/*
+	 * 32-bit without PAE has a 4M large page size.
+	 * PG_LEVEL_2M is misnamed, but we can at least
+	 * print out the right size in the string.
+	 */
+	if (IS_ENABLED(CONFIG_X86_32) &&
+	    !IS_ENABLED(CONFIG_X86_PAE) &&
+	    mr->page_size_mask & (1<<PG_LEVEL_2M))
+		return str_4m;
+
+	if (mr->page_size_mask & (1<<PG_LEVEL_2M))
+		return str_2m;
+
+	return str_4k;
+}
+
 static int __meminit split_mem_range(struct map_range *mr, int nr_range,
 				     unsigned long start,
 				     unsigned long end)
@@ -333,8 +358,7 @@ static int __meminit split_mem_range(struct map_range *mr, int nr_range,
 	for (i = 0; i < nr_range; i++)
 		printk(KERN_DEBUG " [mem %#010lx-%#010lx] page %s\n",
 				mr[i].start, mr[i].end - 1,
-			(mr[i].page_size_mask & (1<<PG_LEVEL_1G))?"1G":(
-			 (mr[i].page_size_mask & (1<<PG_LEVEL_2M))?"2M":"4k"));
+				page_size_string(&mr[i]));
 
 	return nr_range;
 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-19 11:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-10 21:20 [RFC][PATCH] x86: nit: wrong page size in init_memory_mapping() printks Dave Hansen
2015-02-11 12:11 ` Borislav Petkov
2015-02-19 11:34 ` [tip:x86/urgent] x86/mm/init: Fix incorrect " tip-bot for Dave Hansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome