LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] x86, e820: clean up around sanitize_e820_map()
@ 2015-01-07  3:37 WANG Chao
  2015-01-21 22:51 ` David Rientjes
  2015-01-23 15:18 ` [tip:x86/mm] x86, e820: Clean up sanitize_e820_map() users tip-bot for WANG Chao
  0 siblings, 2 replies; 4+ messages in thread
From: WANG Chao @ 2015-01-07  3:37 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Thomas Gleixner, Ingo Molnar, maintainer:X86 ARCHITECTURE...,
	Andrew Morton, Grygorii Strashko, Pavel Machek, David Rientjes,
	Lee, Chun-Yi, Xishi Qiu, open list:X86 ARCHITECTURE...

The argument 3 of sanitize_e820_map() will only update upon a successful
sanitization. Some of the callers may not be aware of this in the past.
Now clean up these callers.

Signed-off-by: WANG Chao <chaowang@redhat.com>
---
 arch/x86/kernel/e820.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index dd2f07a..ae70de8 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -185,7 +185,7 @@ void __init e820_print_map(char *who)
  *
  * The integer pointed to by pnr_map must be valid on entry (the
  * current number of valid entries located at biosmap) and will
- * be updated on return, with the new number of valid entries
+ * only be updated on return 0, with the new number of valid entries
  * (something no more than max_nr_map.)
  *
  * The return value from sanitize_e820_map() is zero if it
@@ -561,23 +561,15 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
 
 void __init update_e820(void)
 {
-	u32 nr_map;
-
-	nr_map = e820.nr_map;
-	if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr_map))
+	if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map))
 		return;
-	e820.nr_map = nr_map;
 	printk(KERN_INFO "e820: modified physical RAM map:\n");
 	e820_print_map("modified");
 }
 static void __init update_e820_saved(void)
 {
-	u32 nr_map;
-
-	nr_map = e820_saved.nr_map;
-	if (sanitize_e820_map(e820_saved.map, ARRAY_SIZE(e820_saved.map), &nr_map))
-		return;
-	e820_saved.nr_map = nr_map;
+	sanitize_e820_map(e820_saved.map, ARRAY_SIZE(e820_saved.map),
+				&e820_saved.nr_map);
 }
 #define MAX_GAP_END 0x100000000ull
 /*
@@ -898,11 +890,9 @@ early_param("memmap", parse_memmap_opt);
 void __init finish_e820_parsing(void)
 {
 	if (userdef) {
-		u32 nr = e820.nr_map;
-
-		if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr) < 0)
+		if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map),
+					&e820.nr_map) < 0)
 			early_panic("Invalid user supplied memory map");
-		e820.nr_map = nr;
 
 		printk(KERN_INFO "e820: user-defined physical RAM map:\n");
 		e820_print_map("user");
-- 
2.1.0


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

* Re: [PATCH] x86, e820: clean up around sanitize_e820_map()
  2015-01-07  3:37 [PATCH] x86, e820: clean up around sanitize_e820_map() WANG Chao
@ 2015-01-21 22:51 ` David Rientjes
  2015-01-22  2:25   ` WANG Chao
  2015-01-23 15:18 ` [tip:x86/mm] x86, e820: Clean up sanitize_e820_map() users tip-bot for WANG Chao
  1 sibling, 1 reply; 4+ messages in thread
From: David Rientjes @ 2015-01-21 22:51 UTC (permalink / raw)
  To: WANG Chao
  Cc: H. Peter Anvin, Thomas Gleixner, Ingo Molnar, x86, Andrew Morton,
	Grygorii Strashko, Pavel Machek, Lee, Chun-Yi, Xishi Qiu,
	linux-kernel

On Wed, 7 Jan 2015, WANG Chao wrote:

> The argument 3 of sanitize_e820_map() will only update upon a successful
> sanitization. Some of the callers may not be aware of this in the past.
> Now clean up these callers.
> 
> Signed-off-by: WANG Chao <chaowang@redhat.com>

Nice, but it's incomplete: it should also cleanup 
default_machine_specific_memory_setup().  After that's fixed, feel free to 
add my

	Acked-by: David Rientjes <rientjes@google.com>

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

* Re: [PATCH] x86, e820: clean up around sanitize_e820_map()
  2015-01-21 22:51 ` David Rientjes
@ 2015-01-22  2:25   ` WANG Chao
  0 siblings, 0 replies; 4+ messages in thread
From: WANG Chao @ 2015-01-22  2:25 UTC (permalink / raw)
  To: David Rientjes
  Cc: H. Peter Anvin, Thomas Gleixner, Ingo Molnar, x86, Andrew Morton,
	Grygorii Strashko, Pavel Machek, Lee, Chun-Yi, Xishi Qiu,
	linux-kernel

Hi, David

On 01/21/15 at 02:51pm, David Rientjes wrote:
> On Wed, 7 Jan 2015, WANG Chao wrote:
> 
> > The argument 3 of sanitize_e820_map() will only update upon a successful
> > sanitization. Some of the callers may not be aware of this in the past.
> > Now clean up these callers.
> > 
> > Signed-off-by: WANG Chao <chaowang@redhat.com>
> 
> Nice, but it's incomplete: it should also cleanup 
> default_machine_specific_memory_setup().

default_machine_specific_memory_setup() is special. Because
boot_params.e820_entries is 8bit unsigned, and sanitize_e820_map() which
takes 32bit unsigned, will step on other member of boot_params next to
e820_entries.

Thanks
WANG Chao

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

* [tip:x86/mm] x86, e820: Clean up sanitize_e820_map() users
  2015-01-07  3:37 [PATCH] x86, e820: clean up around sanitize_e820_map() WANG Chao
  2015-01-21 22:51 ` David Rientjes
@ 2015-01-23 15:18 ` tip-bot for WANG Chao
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for WANG Chao @ 2015-01-23 15:18 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, qiuxishi, rientjes, linux-kernel, chaowang, pavel,
	joeyli.kernel, mingo, hpa, grygorii.strashko

Commit-ID:  d574ffa1066003569ed5cdaeabf44597564ce975
Gitweb:     http://git.kernel.org/tip/d574ffa1066003569ed5cdaeabf44597564ce975
Author:     WANG Chao <chaowang@redhat.com>
AuthorDate: Wed, 7 Jan 2015 11:37:38 +0800
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Fri, 23 Jan 2015 16:14:27 +0100

x86, e820: Clean up sanitize_e820_map() users

The argument 3 of sanitize_e820_map() will only be updated upon a
successful sanitization. Some of the callers have extra conditionals
for the same purpose. Clean them up.

default_machine_specific_memory_setup() must keep the extra
conditional because boot_params.e820_entries is an u8 and not an u32,
so the direct update would overwrite other fields in boot_params.

[ tglx: Massaged changelog ]

Signed-off-by: WANG Chao <chaowang@redhat.com>
Acked-by: David Rientjes <rientjes@google.com>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Lee Chun-Yi <joeyli.kernel@gmail.com>
Cc: Xishi Qiu <qiuxishi@huawei.com>
Link: http://lkml.kernel.org/r/1420601859-18439-1-git-send-email-chaowang@redhat.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/e820.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index dd2f07a..46201de 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -184,9 +184,9 @@ void __init e820_print_map(char *who)
  * overwritten in the same location, starting at biosmap.
  *
  * The integer pointed to by pnr_map must be valid on entry (the
- * current number of valid entries located at biosmap) and will
- * be updated on return, with the new number of valid entries
- * (something no more than max_nr_map.)
+ * current number of valid entries located at biosmap). If the
+ * sanitizing succeeds the *pnr_map will be updated with the new
+ * number of valid entries (something no more than max_nr_map).
  *
  * The return value from sanitize_e820_map() is zero if it
  * successfully 'sanitized' the map entries passed in, and is -1
@@ -561,23 +561,15 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
 
 void __init update_e820(void)
 {
-	u32 nr_map;
-
-	nr_map = e820.nr_map;
-	if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr_map))
+	if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map))
 		return;
-	e820.nr_map = nr_map;
 	printk(KERN_INFO "e820: modified physical RAM map:\n");
 	e820_print_map("modified");
 }
 static void __init update_e820_saved(void)
 {
-	u32 nr_map;
-
-	nr_map = e820_saved.nr_map;
-	if (sanitize_e820_map(e820_saved.map, ARRAY_SIZE(e820_saved.map), &nr_map))
-		return;
-	e820_saved.nr_map = nr_map;
+	sanitize_e820_map(e820_saved.map, ARRAY_SIZE(e820_saved.map),
+				&e820_saved.nr_map);
 }
 #define MAX_GAP_END 0x100000000ull
 /*
@@ -898,11 +890,9 @@ early_param("memmap", parse_memmap_opt);
 void __init finish_e820_parsing(void)
 {
 	if (userdef) {
-		u32 nr = e820.nr_map;
-
-		if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr) < 0)
+		if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map),
+					&e820.nr_map) < 0)
 			early_panic("Invalid user supplied memory map");
-		e820.nr_map = nr;
 
 		printk(KERN_INFO "e820: user-defined physical RAM map:\n");
 		e820_print_map("user");

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

end of thread, other threads:[~2015-01-23 15:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-07  3:37 [PATCH] x86, e820: clean up around sanitize_e820_map() WANG Chao
2015-01-21 22:51 ` David Rientjes
2015-01-22  2:25   ` WANG Chao
2015-01-23 15:18 ` [tip:x86/mm] x86, e820: Clean up sanitize_e820_map() users tip-bot for WANG Chao

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).