linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86: selective remapping in parse_setup_data()
@ 2013-08-12 21:00 Linn Crosetto
  2013-08-12 21:08 ` H. Peter Anvin
  0 siblings, 1 reply; 13+ messages in thread
From: Linn Crosetto @ 2013-08-12 21:00 UTC (permalink / raw)
  To: tglx, mingo, hpa, x86, yinghai, penberg, jacob.shin
  Cc: linux-kernel, Linn Crosetto

PCI devices may advertise a ROM size larger than early_memremap() is
able to handle. If this occurs it leads to a NULL dereference in
parse_setup_data(). Avoid this by remapping the data only when
necessary.

Signed-off-by: Linn Crosetto <linn@hp.com>
---
 arch/x86/kernel/setup.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index f8ec578..2063a49 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -423,6 +423,17 @@ static void __init reserve_initrd(void)
 }
 #endif /* CONFIG_BLK_DEV_INITRD */
 
+static void __init remap_setup_data(u64 pa_data, u32 data_len,
+				    struct setup_data **data, u32 *map_len)
+{
+	if (data_len <= *map_len)
+		return;
+
+	early_iounmap(*data, *map_len);
+	*data = early_memremap(pa_data, data_len);
+	*map_len = data_len;
+}
+
 static void __init parse_setup_data(void)
 {
 	struct setup_data *data;
@@ -432,18 +443,16 @@ static void __init parse_setup_data(void)
 	while (pa_data) {
 		u32 data_len, map_len;
 
+		/* The data length may be too large for early remapping,
+		   remap the data only when needed. */
 		map_len = max(PAGE_SIZE - (pa_data & ~PAGE_MASK),
 			      (u64)sizeof(struct setup_data));
 		data = early_memremap(pa_data, map_len);
 		data_len = data->len + sizeof(struct setup_data);
-		if (data_len > map_len) {
-			early_iounmap(data, map_len);
-			data = early_memremap(pa_data, data_len);
-			map_len = data_len;
-		}
 
 		switch (data->type) {
 		case SETUP_E820_EXT:
+			remap_setup_data(pa_data, data_len, &data, &map_len);
 			parse_e820_ext(data);
 			break;
 		case SETUP_DTB:
-- 
1.7.11.3


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

end of thread, other threads:[~2013-09-06 18:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-12 21:00 [PATCH] x86: selective remapping in parse_setup_data() Linn Crosetto
2013-08-12 21:08 ` H. Peter Anvin
2013-08-12 23:01   ` [PATCH v2] " Linn Crosetto
2013-08-12 23:30     ` Yinghai Lu
2013-08-13 21:46     ` [PATCH v3] x86: avoid remapping data " Linn Crosetto
2013-08-13 22:22       ` Yinghai Lu
2013-08-14  6:26       ` Pekka Enberg
2013-09-01 11:40       ` [tip:x86/mm] " tip-bot for Linn Crosetto
2013-09-01 23:15       ` [PATCH v3] " H. Peter Anvin
2013-09-06 18:06         ` [PATCH 0/3] x86/mm: fix early_memremap() sparse warnings Linn Crosetto
2013-09-06 18:06           ` [PATCH 1/3] x86/mm: fix sparse warnings from early_memremap() Linn Crosetto
2013-09-06 18:06           ` [PATCH 2/3] x86: fix sparse warning in parse_e820_ext() Linn Crosetto
2013-09-06 18:06           ` [PATCH 3/3] x86: fix early_iounmap() sparse warnings in setup.c Linn Crosetto

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