Skip to contentSkip to conversation

x86/efi: Setup separate EFI page tables in kexec paths

PATCH In review Matt Fleming 3 participants 5 messages Jan 21, 2016 – Jan 25, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/efi: Setup separate EFI page tables in kexec paths

The switch to using a new dedicated page table for EFI runtime calls in commit commit 67a9108ed431 ("x86/efi: Build our own page table structures") failed to take into account changes required for the kexec code paths, which are unfortunately duplicated in the EFI code.

Call the allocation and setup functions in kexec_enter_virtual_mode() just like we do for __efi_enter_virtual_mode() to avoid hitting NULL-pointer dereferences when making EFI runtime calls.

At the very least, the call to efi_setup_page_tables() should have existed for kexec before commit 67a9108ed431. Things just magically worked because we were actually using the kernel's page tables that contained the required mappings.

Cc Raghavendra K T <[email protected]>
Cc Dave Young <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Linus Torvalds <torvalds-de/[email protected]>
Cc Borislav Petkov <[email protected]>
---
 arch/x86/platform/efi/efi.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Folks, please apply this to the queue of EFI patches sitting in tip/x86/efi.

arch/x86/platform/efi/efi.c +15 -0
index 3c1f3cd7b2ba..2aedee71f965 100644
@@ -815,6 +815,7 @@ static void __init kexec_enter_virtual_mode(void)
 {
 #ifdef CONFIG_KEXEC_CORE
 	efi_memory_desc_t *md;
+	unsigned num_pages;
 	void *p;
 
 	efi.systab = NULL;
@@ -829,6 +830,12 @@ static void __init kexec_enter_virtual_mode(void)
 		return;
 	}
 
+	if (efi_alloc_page_tables()) {
+		pr_err("Failed to allocate EFI page tables\n");
+		clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
+		return;
+	}
+
 	/*
 	* Map efi regions which were passed via setup_data. The virt_addr is a
 	* fixed addr which was used in first kernel of a kexec boot.
@@ -843,6 +850,14 @@ static void __init kexec_enter_virtual_mode(void)
 
 	BUG_ON(!efi.systab);
 
+	num_pages = ALIGN(memmap.nr_map * memmap.desc_size, PAGE_SIZE);
+	num_pages >>= PAGE_SHIFT;
+
+	if (efi_setup_page_tables(memmap.phys_map, num_pages)) {
+		clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
+		return;
+	}
+
 	efi_sync_low_kernel_mappings();
 
 	/*
Signature · 1 line
2.6.2
#1 lore raw
Quoted 14 lines · Matt Fleming

The switch to using a new dedicated page table for EFI runtime calls in commit commit 67a9108ed431 ("x86/efi: Build our own page table structures") failed to take into account changes required for the kexec code paths, which are unfortunately duplicated in the EFI code.

Call the allocation and setup functions in kexec_enter_virtual_mode() just like we do for __efi_enter_virtual_mode() to avoid hitting NULL-pointer dereferences when making EFI runtime calls.

At the very least, the call to efi_setup_page_tables() should have existed for kexec before commit 67a9108ed431. Things just magically worked because we were actually using the kernel's page tables that contained the required mappings.

Quoted 7 lines
Cc Raghavendra K T <[email protected]>
Cc Dave Young <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Linus Torvalds <torvalds-de/[email protected]>
Cc Borislav Petkov <[email protected]>

Applied this patch on top of tip/x86/efi and was able to build and boot the kernel.

Signature · 2 lines
Thanks and Regards
Srikar Dronamraju
#2 lore raw
Quoted 24 lines · Srikar Dronamraju
Quoted 14 lines · Matt Fleming

The switch to using a new dedicated page table for EFI runtime calls in commit commit 67a9108ed431 ("x86/efi: Build our own page table structures") failed to take into account changes required for the kexec code paths, which are unfortunately duplicated in the EFI code.

Call the allocation and setup functions in kexec_enter_virtual_mode() just like we do for __efi_enter_virtual_mode() to avoid hitting NULL-pointer dereferences when making EFI runtime calls.

At the very least, the call to efi_setup_page_tables() should have existed for kexec before commit 67a9108ed431. Things just magically worked because we were actually using the kernel's page tables that contained the required mappings.

Quoted 7 lines
Cc Raghavendra K T <[email protected]>
Cc Dave Young <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Borislav Petkov <[email protected]>
Quoted 2 lines

Applied this patch on top of tip/x86/efi and was able to build and boot the kernel.

Fantastic, thanks for testing!

Ingo, this commit should unblock the EFI changes for v4.5.

#4 lore raw
In reply to Matt Fleming
x86/efi: Setup separate EFI page tables in kexec paths
Commit-ID:  753b11ef8e92a1c1bbe97f2a5ec14bdd1ef2e6fe
Gitweb:     http://git.kernel.org/tip/753b11ef8e92a1c1bbe97f2a5ec14bdd1ef2e6fe
Author:     Matt Fleming <[email protected]>
AuthorDate: Thu, 21 Jan 2016 14:11:59 +0000
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 21 Jan 2016 21:01:34 +0100

x86/efi: Setup separate EFI page tables in kexec paths

The switch to using a new dedicated page table for EFI runtime calls in commit commit 67a9108ed431 ("x86/efi: Build our own page table structures") failed to take into account changes required for the kexec code paths, which are unfortunately duplicated in the EFI code.

Call the allocation and setup functions in kexec_enter_virtual_mode() just like we do for __efi_enter_virtual_mode() to avoid hitting NULL-pointer dereferences when making EFI runtime calls.

At the very least, the call to efi_setup_page_tables() should have existed for kexec before the following commit:

67a9108ed431 ("x86/efi: Build our own page table structures")

Things just magically worked because we were actually using the kernel's page tables that contained the required mappings.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Dave Young <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Raghavendra K T <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/platform/efi/efi.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/x86/platform/efi/efi.c +15 -0
index 3c1f3cd..bdd9477 100644
@@ -815,6 +815,7 @@ static void __init kexec_enter_virtual_mode(void)
 {
 #ifdef CONFIG_KEXEC_CORE
 	efi_memory_desc_t *md;
+	unsigned int num_pages;
 	void *p;
 
 	efi.systab = NULL;
@@ -829,6 +830,12 @@ static void __init kexec_enter_virtual_mode(void)
 		return;
 	}
 
+	if (efi_alloc_page_tables()) {
+		pr_err("Failed to allocate EFI page tables\n");
+		clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
+		return;
+	}
+
 	/*
 	* Map efi regions which were passed via setup_data. The virt_addr is a
 	* fixed addr which was used in first kernel of a kexec boot.
@@ -843,6 +850,14 @@ static void __init kexec_enter_virtual_mode(void)
 
 	BUG_ON(!efi.systab);
 
+	num_pages = ALIGN(memmap.nr_map * memmap.desc_size, PAGE_SIZE);
+	num_pages >>= PAGE_SHIFT;
+
+	if (efi_setup_page_tables(memmap.phys_map, num_pages)) {
+		clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
+		return;
+	}
+
 	efi_sync_low_kernel_mappings();
 
 	/*
#3 lore raw
In reply to Matt Fleming
Quoted 2 lines · Matt Fleming

Ingo, this commit should unblock the EFI changes for v4.5.

Looks like all this material missed v4.5. Was that intentional?