LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 1/2] x86: early_memremap exact size of struct setup_data
@ 2015-01-07 10:55 WANG Chao
  2015-01-07 10:55 ` [PATCH 2/2] x86: add macro for_each_setup_data() WANG Chao
  2015-01-23 15:18 ` [tip:x86/mm] x86, setup: Let early_memremap() handle page alignment tip-bot for WANG Chao
  0 siblings, 2 replies; 4+ messages in thread
From: WANG Chao @ 2015-01-07 10:55 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Thomas Gleixner, Ingo Molnar, maintainer:X86 ARCHITECTURE...,
	Matt Fleming, Andrew Morton, Borislav Petkov, Santosh Shilimkar,
	Bryan O'Donoghue, open list:X86 ARCHITECTURE...

When early remapping setup_data, we can remap the structure alone, use
sizeof(struct setup_data). No need to remap a larger area, we never
access setup_data->data at that point.

Signed-off-by: WANG Chao <chaowang@redhat.com>
---
 arch/x86/kernel/setup.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index ab4734e..c4648ada 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -431,15 +431,13 @@ static void __init parse_setup_data(void)
 
 	pa_data = boot_params.hdr.setup_data;
 	while (pa_data) {
-		u32 data_len, map_len, data_type;
+		u32 data_len, data_type;
 
-		map_len = max(PAGE_SIZE - (pa_data & ~PAGE_MASK),
-			      (u64)sizeof(struct setup_data));
-		data = early_memremap(pa_data, map_len);
+		data = early_memremap(pa_data, sizeof(*data));
 		data_len = data->len + sizeof(struct setup_data);
 		data_type = data->type;
 		pa_next = data->next;
-		early_iounmap(data, map_len);
+		early_iounmap(data, sizeof(*data));
 
 		switch (data_type) {
 		case SETUP_E820_EXT:
-- 
2.1.0


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

* [PATCH 2/2] x86: add macro for_each_setup_data()
  2015-01-07 10:55 [PATCH 1/2] x86: early_memremap exact size of struct setup_data WANG Chao
@ 2015-01-07 10:55 ` WANG Chao
  2015-01-23 14:24   ` Thomas Gleixner
  2015-01-23 15:18 ` [tip:x86/mm] x86, setup: Let early_memremap() handle page alignment tip-bot for WANG Chao
  1 sibling, 1 reply; 4+ messages in thread
From: WANG Chao @ 2015-01-07 10:55 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Thomas Gleixner, Ingo Molnar, maintainer:X86 ARCHITECTURE...,
	Matt Fleming, Andrew Morton, Santosh Shilimkar, Borislav Petkov,
	Daniel Kiper, Bryan O'Donoghue, open list:X86 ARCHITECTURE...

A common task for parsing setup_data is to iterate over setup_data's
linked list, remap and do something and unmap. Now add macro
for_each_setup_data() to do that.

Signed-off-by: WANG Chao <chaowang@redhat.com>
---
 arch/x86/kernel/setup.c | 37 ++++++++++++-------------------------
 1 file changed, 12 insertions(+), 25 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index c4648ada..1e24c37 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -424,35 +424,30 @@ static void __init reserve_initrd(void)
 }
 #endif /* CONFIG_BLK_DEV_INITRD */
 
+#define for_each_setup_data(pa_data, data) \
+	for (pa_data = boot_params.hdr.setup_data; \
+		pa_data && (data = early_memremap(pa_data, sizeof(*data))); \
+		pa_data = data->next, early_iounmap(data, sizeof(*data)))
+
 static void __init parse_setup_data(void)
 {
 	struct setup_data *data;
-	u64 pa_data, pa_next;
-
-	pa_data = boot_params.hdr.setup_data;
-	while (pa_data) {
-		u32 data_len, data_type;
-
-		data = early_memremap(pa_data, sizeof(*data));
-		data_len = data->len + sizeof(struct setup_data);
-		data_type = data->type;
-		pa_next = data->next;
-		early_iounmap(data, sizeof(*data));
+	u64 pa_data;
 
-		switch (data_type) {
+	for_each_setup_data(pa_data, data) {
+		switch (data->type) {
 		case SETUP_E820_EXT:
-			parse_e820_ext(pa_data, data_len);
+			parse_e820_ext(pa_data, data->len + sizeof(*data));
 			break;
 		case SETUP_DTB:
 			add_dtb(pa_data);
 			break;
 		case SETUP_EFI:
-			parse_efi_setup(pa_data, data_len);
+			parse_efi_setup(pa_data, data->len + sizeof(*data));
 			break;
 		default:
 			break;
 		}
-		pa_data = pa_next;
 	}
 }
 
@@ -462,14 +457,10 @@ static void __init e820_reserve_setup_data(void)
 	u64 pa_data;
 	int found = 0;
 
-	pa_data = boot_params.hdr.setup_data;
-	while (pa_data) {
-		data = early_memremap(pa_data, sizeof(*data));
+	for_each_setup_data(pa_data, data) {
 		e820_update_range(pa_data, sizeof(*data)+data->len,
 			 E820_RAM, E820_RESERVED_KERN);
 		found = 1;
-		pa_data = data->next;
-		early_iounmap(data, sizeof(*data));
 	}
 	if (!found)
 		return;
@@ -485,12 +476,8 @@ static void __init memblock_x86_reserve_range_setup_data(void)
 	struct setup_data *data;
 	u64 pa_data;
 
-	pa_data = boot_params.hdr.setup_data;
-	while (pa_data) {
-		data = early_memremap(pa_data, sizeof(*data));
+	for_each_setup_data(pa_data, data) {
 		memblock_reserve(pa_data, sizeof(*data) + data->len);
-		pa_data = data->next;
-		early_iounmap(data, sizeof(*data));
 	}
 }
 
-- 
2.1.0


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

* Re: [PATCH 2/2] x86: add macro for_each_setup_data()
  2015-01-07 10:55 ` [PATCH 2/2] x86: add macro for_each_setup_data() WANG Chao
@ 2015-01-23 14:24   ` Thomas Gleixner
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Gleixner @ 2015-01-23 14:24 UTC (permalink / raw)
  To: WANG Chao
  Cc: H. Peter Anvin, Ingo Molnar, maintainer:X86 ARCHITECTURE...,
	Matt Fleming, Andrew Morton, Santosh Shilimkar, Borislav Petkov,
	Daniel Kiper, Bryan O'Donoghue, open list:X86 ARCHITECTURE...

On Wed, 7 Jan 2015, WANG Chao wrote:
  
> +#define for_each_setup_data(pa_data, data) \
> +	for (pa_data = boot_params.hdr.setup_data; \
> +		pa_data && (data = early_memremap(pa_data, sizeof(*data))); \
> +		pa_data = data->next, early_iounmap(data, sizeof(*data)))
> +

That makes the code obfuscated not clearer. Brain went into spiral
mode.

struct setup_iter {
       u64 pa_data, pa_next;
       u32 len, type;
};

....
{
     struct setup_iter iter = { .pa_next = boot_params.hdr.setup_data };

     while (get_next_setup_data(&iter)) {
     	   switch (iter.type) {
	   case SETUP_E820_EXT:
	      	 parse_e820_ext(iter.pa_data, iter.len);  	  
....

Perhaps?

Thanks,

	tglx

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

* [tip:x86/mm] x86, setup: Let early_memremap() handle page alignment
  2015-01-07 10:55 [PATCH 1/2] x86: early_memremap exact size of struct setup_data WANG Chao
  2015-01-07 10:55 ` [PATCH 2/2] x86: add macro for_each_setup_data() WANG Chao
@ 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: linux-kernel, hpa, pure.logic, matt.fleming, chaowang, tglx,
	santosh.shilimkar, bp, mingo

Commit-ID:  7389882c81474d635a208726edb22938645ff9ad
Gitweb:     http://git.kernel.org/tip/7389882c81474d635a208726edb22938645ff9ad
Author:     WANG Chao <chaowang@redhat.com>
AuthorDate: Wed, 7 Jan 2015 18:55:48 +0800
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Fri, 23 Jan 2015 16:14:26 +0100

x86, setup: Let early_memremap() handle page alignment

early_memremap() takes care of page alignment and map size, so we can
just remap the required data size and get rid of the adjustments in
the setup code.

[tglx: Massaged changelog ]

Signed-off-by: WANG Chao <chaowang@redhat.com>
Cc: Matt Fleming <matt.fleming@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
Cc: Bryan O'Donoghue <pure.logic@nexus-software.ie>
Link: http://lkml.kernel.org/r/1420628150-16872-1-git-send-email-chaowang@redhat.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/setup.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index ab4734e..c4648ada 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -431,15 +431,13 @@ static void __init parse_setup_data(void)
 
 	pa_data = boot_params.hdr.setup_data;
 	while (pa_data) {
-		u32 data_len, map_len, data_type;
+		u32 data_len, data_type;
 
-		map_len = max(PAGE_SIZE - (pa_data & ~PAGE_MASK),
-			      (u64)sizeof(struct setup_data));
-		data = early_memremap(pa_data, map_len);
+		data = early_memremap(pa_data, sizeof(*data));
 		data_len = data->len + sizeof(struct setup_data);
 		data_type = data->type;
 		pa_next = data->next;
-		early_iounmap(data, map_len);
+		early_iounmap(data, sizeof(*data));
 
 		switch (data_type) {
 		case SETUP_E820_EXT:

^ 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 10:55 [PATCH 1/2] x86: early_memremap exact size of struct setup_data WANG Chao
2015-01-07 10:55 ` [PATCH 2/2] x86: add macro for_each_setup_data() WANG Chao
2015-01-23 14:24   ` Thomas Gleixner
2015-01-23 15:18 ` [tip:x86/mm] x86, setup: Let early_memremap() handle page alignment 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).