linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Andy Lutomirski <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: jpoimboe@redhat.com, bp@alien8.de, mfleming@suse.de,
	peterz@infradead.org, dvlasenk@redhat.com,
	linux-kernel@vger.kernel.org, luto@kernel.org,
	mjg59@srcf.ucam.org, brgerst@gmail.com,
	mario_limonciello@dell.com, hpa@zytor.com, tglx@linutronix.de,
	mingo@kernel.org, torvalds@linux-foundation.org,
	matt@codeblueprint.co.uk
Subject: [tip:x86/urgent] x86/efi: Allocate a trampoline if needed in efi_free_boot_services()
Date: Thu, 11 Aug 2016 09:19:16 -0700	[thread overview]
Message-ID: <tip-5bc653b7318217c54244a14f248f1f07abe0a865@git.kernel.org> (raw)
In-Reply-To: <998c77b3bf709f3dfed85cb30701ed1a5d8a438b.1470821230.git.luto@kernel.org>

Commit-ID:  5bc653b7318217c54244a14f248f1f07abe0a865
Gitweb:     http://git.kernel.org/tip/5bc653b7318217c54244a14f248f1f07abe0a865
Author:     Andy Lutomirski <luto@kernel.org>
AuthorDate: Wed, 10 Aug 2016 02:29:17 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 11 Aug 2016 13:53:07 +0200

x86/efi: Allocate a trampoline if needed in efi_free_boot_services()

On my Dell XPS 13 9350 with firmware 1.4.4 and SGX on, if I boot
Fedora 24's grub2-efi off a hard disk, my first 1MB of RAM looks
like:

 efi: mem00: [Runtime Data       |RUN|  |  |  |  |  |  |   |WB|WT|WC|UC] range=[0x0000000000000000-0x0000000000000fff] (0MB)
 efi: mem01: [Boot Data          |   |  |  |  |  |  |  |   |WB|WT|WC|UC] range=[0x0000000000001000-0x0000000000027fff] (0MB)
 efi: mem02: [Loader Data        |   |  |  |  |  |  |  |   |WB|WT|WC|UC] range=[0x0000000000028000-0x0000000000029fff] (0MB)
 efi: mem03: [Reserved           |   |  |  |  |  |  |  |   |WB|WT|WC|UC] range=[0x000000000002a000-0x000000000002bfff] (0MB)
 efi: mem04: [Runtime Data       |RUN|  |  |  |  |  |  |   |WB|WT|WC|UC] range=[0x000000000002c000-0x000000000002cfff] (0MB)
 efi: mem05: [Loader Data        |   |  |  |  |  |  |  |   |WB|WT|WC|UC] range=[0x000000000002d000-0x000000000002dfff] (0MB)
 efi: mem06: [Conventional Memory|   |  |  |  |  |  |  |   |WB|WT|WC|UC] range=[0x000000000002e000-0x0000000000057fff] (0MB)
 efi: mem07: [Reserved           |   |  |  |  |  |  |  |   |WB|WT|WC|UC] range=[0x0000000000058000-0x0000000000058fff] (0MB)
 efi: mem08: [Conventional Memory|   |  |  |  |  |  |  |   |WB|WT|WC|UC] range=[0x0000000000059000-0x000000000009ffff] (0MB)

My EBDA is at 0x2c000, which blocks off everything from 0x2c000 and
up, and my trampoline is 0x6000 bytes (6 pages), so it doesn't fit
in the loader data range at 0x28000.

Without this patch, it panics due to a failure to allocate the
trampoline.  With this patch, it works:

 [  +0.001744] Base memory trampoline at [ffff880000001000] 1000 size 24576

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Reviewed-by: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mario Limonciello <mario_limonciello@dell.com>
Cc: Matt Fleming <mfleming@suse.de>
Cc: Matthew Garrett <mjg59@srcf.ucam.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/998c77b3bf709f3dfed85cb30701ed1a5d8a438b.1470821230.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/platform/efi/quirks.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index 4480c06..89d1146 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -254,6 +254,7 @@ void __init efi_free_boot_services(void)
 	for_each_efi_memory_desc(md) {
 		unsigned long long start = md->phys_addr;
 		unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
+		size_t rm_size;
 
 		if (md->type != EFI_BOOT_SERVICES_CODE &&
 		    md->type != EFI_BOOT_SERVICES_DATA)
@@ -263,6 +264,26 @@ void __init efi_free_boot_services(void)
 		if (md->attribute & EFI_MEMORY_RUNTIME)
 			continue;
 
+		/*
+		 * Nasty quirk: if all sub-1MB memory is used for boot
+		 * services, we can get here without having allocated the
+		 * real mode trampoline.  It's too late to hand boot services
+		 * memory back to the memblock allocator, so instead
+		 * try to manually allocate the trampoline if needed.
+		 *
+		 * I've seen this on a Dell XPS 13 9350 with firmware
+		 * 1.4.4 with SGX enabled booting Linux via Fedora 24's
+		 * grub2-efi on a hard disk.  (And no, I don't know why
+		 * this happened, but Linux should still try to boot rather
+		 * panicing early.)
+		 */
+		rm_size = real_mode_size_needed();
+		if (rm_size && (start + rm_size) < (1<<20) && size >= rm_size) {
+			set_real_mode_mem(start, rm_size);
+			start += rm_size;
+			size -= rm_size;
+		}
+
 		free_bootmem_late(start, size);
 	}
 

  reply	other threads:[~2016-08-11 16:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-10  9:29 [PATCH v2 0/5] Allow the trampoline to use EFI boot services RAM Andy Lutomirski
2016-08-10  9:29 ` [PATCH v2 1/5] x86/boot: Run reserve_bios_regions() after we initialize the memory map Andy Lutomirski
2016-08-11 11:57   ` [tip:x86/urgent] " tip-bot for Andy Lutomirski
2016-08-10  9:29 ` [PATCH v2 2/5] x86/boot: Synchronize trampoline_cr4_features and mmu_cr4_features directly Andy Lutomirski
2016-08-11 11:58   ` [tip:x86/urgent] " tip-bot for Andy Lutomirski
2016-08-10  9:29 ` [PATCH v2 3/5] x86/boot: Defer setup_real_mode() to early_initcall time Andy Lutomirski
2016-08-11 11:58   ` [tip:x86/urgent] " tip-bot for Andy Lutomirski
2016-08-10  9:29 ` [PATCH v2 4/5] x86/boot: Rework reserve_real_mode() to allow multiple tries Andy Lutomirski
2016-08-11 11:59   ` [tip:x86/urgent] " tip-bot for Andy Lutomirski
2016-08-10  9:29 ` [PATCH v2 5/5] x86/efi: Allocate a trampoline if needed in efi_free_boot_services() Andy Lutomirski
2016-08-11 16:19   ` tip-bot for Andy Lutomirski [this message]
2016-08-10 12:28 ` [PATCH v2 0/5] Allow the trampoline to use EFI boot services RAM Ingo Molnar
2016-08-10 13:21   ` Andy Lutomirski
2016-08-10 16:08     ` Mario_Limonciello
2016-08-10 12:30 ` Ingo Molnar
2016-08-10 13:18   ` Andy Lutomirski
2016-08-11  8:52     ` Ingo Molnar
2016-08-11 10:36       ` Matt Fleming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-5bc653b7318217c54244a14f248f1f07abe0a865@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dvlasenk@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mario_limonciello@dell.com \
    --cc=matt@codeblueprint.co.uk \
    --cc=mfleming@suse.de \
    --cc=mingo@kernel.org \
    --cc=mjg59@srcf.ucam.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).