Skip to contentSkip to conversation

x86/efi: Make efi_set_virtual_address_map IBT safe

PATCH Applied Thomas Gleixner 3 participants 4 messages Jun 29, 2023 – Jun 30, 2023

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

Niklāvs reported a boot regression on an Alderlake machine and bisected it to commit 9df9d2f0471b ("init: Invoke arch_cpu_finalize_init() earlier").

By moving the invocation of arch_cpu_finalize_init() further down he identified that efi_enter_virtual_mode() is the function which causes the boot hang.

The main difference of the earlier invocation is that the boot CPU is already fully initialized and mitigations and alternatives are applied.

But the only really interesting change turned out to be IBT, which is now enabled before efi_enter_virtual_mode(). "ibt=off" on the kernel command line cured the problem.

Inspection of the involved calls in efi_enter_virtual_mode() unearthed that efi_set_virtual_address_map() is the only place in the kernel which invokes an EFI call without the IBT safe wrapper. This went obviously unnoticed so far as IBT was enabled later.

Use arch_efi_call_virt() instead of efi_call() to cure that.

Fixes fe379fa4d199 ("x86/ibt: Disable IBT around firmware")
Fixes 9df9d2f0471b ("init: Invoke arch_cpu_finalize_init() earlier")

---
I put two fixes tags in as the IBT one missed that and the earlier invocation unearthed it and made it observable.

---
 arch/x86/platform/efi/efi_64.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/platform/efi/efi_64.c +3 -3
@@ -853,9 +853,9 @@ efi_set_virtual_address_map(unsigned lon
 
 	/* Disable interrupts around EFI calls: */
 	local_irq_save(flags);
-	status = efi_call(efi.runtime->set_virtual_address_map,
-			  memory_map_size, descriptor_size,
-			  descriptor_version, virtual_map);
+	status = arch_efi_call_virt(efi.runtime, set_virtual_address_map,
+				    memory_map_size, descriptor_size,
+				    descriptor_version, virtual_map);
 	local_irq_restore(flags);
 
 	efi_fpu_end();
maintainer Reviewed-by
#1 lore raw
Quoted 20 lines · Thomas Gleixner

Niklāvs reported a boot regression on an Alderlake machine and bisected it to commit 9df9d2f0471b ("init: Invoke arch_cpu_finalize_init() earlier").

By moving the invocation of arch_cpu_finalize_init() further down he identified that efi_enter_virtual_mode() is the function which causes the boot hang.

The main difference of the earlier invocation is that the boot CPU is already fully initialized and mitigations and alternatives are applied.

But the only really interesting change turned out to be IBT, which is now enabled before efi_enter_virtual_mode(). "ibt=off" on the kernel command line cured the problem.

Inspection of the involved calls in efi_enter_virtual_mode() unearthed that efi_set_virtual_address_map() is the only place in the kernel which invokes an EFI call without the IBT safe wrapper. This went obviously unnoticed so far as IBT was enabled later.

Quoted 7 lines

Use arch_efi_call_virt() instead of efi_call() to cure that.

Fixes fe379fa4d199 ("x86/ibt: Disable IBT around firmware")
Fixes 9df9d2f0471b ("init: Invoke arch_cpu_finalize_init() earlier")

I take it you'll send this straight to Linus?

Quoted 22 lines

---
I put two fixes tags in as the IBT one missed that and the earlier invocation unearthed it and made it observable.

---
 arch/x86/platform/efi/efi_64.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/platform/efi/efi_64.c +3 -3
@@ -853,9 +853,9 @@ efi_set_virtual_address_map(unsigned lon
 
        /* Disable interrupts around EFI calls: */
        local_irq_save(flags);
-       status = efi_call(efi.runtime->set_virtual_address_map,
-                         memory_map_size, descriptor_size,
-                         descriptor_version, virtual_map);
+       status = arch_efi_call_virt(efi.runtime, set_virtual_address_map,
+                                   memory_map_size, descriptor_size,
+                                   descriptor_version, virtual_map);
        local_irq_restore(flags);
 
        efi_fpu_end();
#2 lore raw
Quoted 28 lines · Ard Biesheuvel
Quoted 19 lines · Thomas Gleixner

Niklāvs reported a boot regression on an Alderlake machine and bisected it to commit 9df9d2f0471b ("init: Invoke arch_cpu_finalize_init() earlier").

By moving the invocation of arch_cpu_finalize_init() further down he identified that efi_enter_virtual_mode() is the function which causes the boot hang.

The main difference of the earlier invocation is that the boot CPU is already fully initialized and mitigations and alternatives are applied.

But the only really interesting change turned out to be IBT, which is now enabled before efi_enter_virtual_mode(). "ibt=off" on the kernel command line cured the problem.

Inspection of the involved calls in efi_enter_virtual_mode() unearthed that efi_set_virtual_address_map() is the only place in the kernel which invokes an EFI call without the IBT safe wrapper. This went obviously unnoticed so far as IBT was enabled later.

Quoted 7 lines

Use arch_efi_call_virt() instead of efi_call() to cure that.

Fixes fe379fa4d199 ("x86/ibt: Disable IBT around firmware")
Fixes 9df9d2f0471b ("init: Invoke arch_cpu_finalize_init() earlier")
Quoted 3 lines

I take it you'll send this straight to Linus?

I can do that.

Thanks,

tglx

#3 lore raw
In reply to Thomas Gleixner
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     0303c9729afc4094ef53e552b7b8cff7436028d6
Gitweb:        https://git.kernel.org/tip/0303c9729afc4094ef53e552b7b8cff7436028d6
Author:        Thomas Gleixner <[email protected]>
AuthorDate:    Thu, 29 Jun 2023 21:35:19 +02:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Fri, 30 Jun 2023 15:26:24 +02:00

x86/efi: Make efi_set_virtual_address_map IBT safe

Niklāvs reported a boot regression on an Alderlake machine and bisected it to commit 9df9d2f0471b ("init: Invoke arch_cpu_finalize_init() earlier").

By moving the invocation of arch_cpu_finalize_init() further down he identified that efi_enter_virtual_mode() is the function which causes the boot hang.

The main difference of the earlier invocation is that the boot CPU is already fully initialized and mitigations and alternatives are applied.

But the only really interesting change turned out to be IBT, which is now enabled before efi_enter_virtual_mode(). "ibt=off" on the kernel command line cured the problem.

Inspection of the involved calls in efi_enter_virtual_mode() unearthed that efi_set_virtual_address_map() is the only place in the kernel which invokes an EFI call without the IBT safe wrapper. This went obviously unnoticed so far as IBT was enabled later.

Use arch_efi_call_virt() instead of efi_call() to cure that.

Fixes fe379fa4d199 ("x86/ibt: Disable IBT around firmware")
Fixes 9df9d2f0471b ("init: Invoke arch_cpu_finalize_init() earlier")
---
 arch/x86/platform/efi/efi_64.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/platform/efi/efi_64.c +3 -3
index 232acf4..77f7ac3 100644
@@ -853,9 +853,9 @@ efi_set_virtual_address_map(unsigned long memory_map_size,
 
 	/* Disable interrupts around EFI calls: */
 	local_irq_save(flags);
-	status = efi_call(efi.runtime->set_virtual_address_map,
-			  memory_map_size, descriptor_size,
-			  descriptor_version, virtual_map);
+	status = arch_efi_call_virt(efi.runtime, set_virtual_address_map,
+				    memory_map_size, descriptor_size,
+				    descriptor_version, virtual_map);
 	local_irq_restore(flags);
 
 	efi_fpu_end();