All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/mm: Fix boot with some memory above MAXMEM
@ 2020-05-11 19:17 Kirill A. Shutemov
  2020-05-25  4:49 ` Kirill A. Shutemov
  0 siblings, 1 reply; 10+ messages in thread
From: Kirill A. Shutemov @ 2020-05-11 19:17 UTC (permalink / raw)
  To: Dave Hansen, Andy Lutomirski, Peter Zijlstra, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, H. Peter Anvin
  Cc: Dan Williams, Tony Luck, x86, linux-mm, linux-kernel,
	Kirill A. Shutemov, Dave Hansen, stable

A 5-level paging capable machine can have memory above 46-bit in the
physical address space. This memory is only addressable in the 5-level
paging mode: we don't have enough virtual address space to create direct
mapping for such memory in the 4-level paging mode.

Currently, we fail boot completely: NULL pointer dereference in
subsection_map_init().

Skip creating a memblock for such memory instead and notify user that
some memory is not addressable.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reviewed-by: Dave Hansen <dave.hansen@intel.com>
Cc: stable@vger.kernel.org # v4.14
---

Tested with a hacked QEMU: https://gist.github.com/kiryl/d45eb54110944ff95e544972d8bdac1d

---
 arch/x86/kernel/e820.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index c5399e80c59c..d320d37d0f95 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -1280,8 +1280,8 @@ void __init e820__memory_setup(void)
 
 void __init e820__memblock_setup(void)
 {
+	u64 size, end, not_addressable = 0;
 	int i;
-	u64 end;
 
 	/*
 	 * The bootstrap memblock region count maximum is 128 entries
@@ -1307,7 +1307,22 @@ void __init e820__memblock_setup(void)
 		if (entry->type != E820_TYPE_RAM && entry->type != E820_TYPE_RESERVED_KERN)
 			continue;
 
-		memblock_add(entry->addr, entry->size);
+		if (entry->addr >= MAXMEM) {
+			not_addressable += entry->size;
+			continue;
+		}
+
+		end = min_t(u64, end, MAXMEM - 1);
+		size = end - entry->addr;
+		not_addressable += entry->size - size;
+		memblock_add(entry->addr, size);
+	}
+
+	if (not_addressable) {
+		pr_err("%lldGB of physical memory is not addressable in the paging mode\n",
+		       not_addressable >> 30);
+		if (!pgtable_l5_enabled())
+			pr_err("Consider enabling 5-level paging\n");
 	}
 
 	/* Throw away partial pages: */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread
* [PATCH] x86/mm: Fix boot with some memory above MAXMEM
@ 2020-05-11 16:37 Kirill A. Shutemov
  2020-05-11 16:43 ` Dave Hansen
  0 siblings, 1 reply; 10+ messages in thread
From: Kirill A. Shutemov @ 2020-05-11 16:37 UTC (permalink / raw)
  To: Hansen, Dave, Dan Williams, Kleen, Andi
  Cc: dave.hansen, linux-drivers-review, Kirill A. Shutemov, stable

A 5-level paging capable machine can have memory above 46-bit in the
physical address space. This memory is only addressable in the 5-level
paging mode: we don't have enough virtual address space to create direct
mapping for such memory in the 4-level paging mode.

Currently, we fail boot completely: NULL pointer dereference in
subsection_map_init().

Skip creating a memblock for such memory instead and notify user that
some memory is not addressable.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: stable@vger.kernel.org # v4.14
---

Tested with a hacked QEMU: https://gist.github.com/kiryl/d45eb54110944ff95e544972d8bdac1d

---
 arch/x86/kernel/e820.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index c5399e80c59c..022fe1de8940 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -1307,7 +1307,14 @@ void __init e820__memblock_setup(void)
 		if (entry->type != E820_TYPE_RAM && entry->type != E820_TYPE_RESERVED_KERN)
 			continue;
 
-		memblock_add(entry->addr, entry->size);
+		if (entry->addr >= MAXMEM || end >= MAXMEM)
+			pr_err_once("Some physical memory is not addressable in the paging mode.\n");
+
+		if (entry->addr >= MAXMEM)
+			continue;
+
+		end = min_t(u64, end, MAXMEM - 1);
+		memblock_add(entry->addr, end - entry->addr);
 	}
 
 	/* Throw away partial pages: */
-- 
2.26.2


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

end of thread, other threads:[~2020-06-03 19:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 19:17 [PATCH] x86/mm: Fix boot with some memory above MAXMEM Kirill A. Shutemov
2020-05-25  4:49 ` Kirill A. Shutemov
2020-05-25 14:59   ` Mike Rapoport
2020-05-25 15:08     ` Kirill A. Shutemov
2020-05-25 15:58       ` Mike Rapoport
2020-05-26 14:27       ` Dave Hansen
2020-06-02 23:18         ` Kirill A. Shutemov
2020-06-03 19:18           ` Dave Hansen
  -- strict thread matches above, loose matches on Subject: below --
2020-05-11 16:37 Kirill A. Shutemov
2020-05-11 16:43 ` Dave Hansen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.