Skip to contentSkip to conversation

x86: Extend LASS support to EFI configurations

PATCH Applied Sohil Mehta 6 participants 14 messages Jan 20 – Mar 3

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

v2 cover x86: Extend LASS support to EFI configurations

Linear Address Space Separation (LASS) is currently disabled [1] when support for vsyscall emulation or EFI is compiled in. This series extends LASS support to EFI-enabled configurations.

Changes in v2
-------------
- Rebased the series to v6.19-rc5
- Improved commit messages and code comments based on feedback

v1: https://lore.kernel.org/lkml/[email protected]/

Issues with EFI
---------------
EFI boot and runtime services are incompatible with LASS because they end up accessing addresses with bit 63 cleared, which is blocked by LASS.

1) The most obvious one is the SetVirtualAddressMap() runtime service, which is expected to be called in EFI physical mode [2].

2) Some runtime services fail to switch to virtual mode properly and continue referencing physical addresses even after SVAM. The kernel maintains a 1:1 mapping of all runtime services code and data regions to avoid breaking such firmware.

3) Some boot services code and data regions are referenced long after ExitBootServices(). Most of these access use the kernel direct map so bit 63 is expected to be set. But some odd firmware implementation could access that memory via a mapping in the lower range.

Solution
--------
These patches take LASS out of the path of all EFI boot and runtime service interactions by:

Patch 1: Deferring LASS enabling until userspace comes up, which ensures EFI has completed switching to virtual mode and all boot services memory has been freed [3].

Patch 2: Temporarily disabling LASS every time a runtime service is executed after boot. Runtime services execute in a special efi_mm which doesn't have userspace mapped. So, the security implications of disabling LASS are fairly limited [4].

Please find more details in the respective patches.

Alternate options
-----------------
One option is to not support broken firmware implementations (by avoiding patch 2) starting with systems that support LASS. That would trigger #GP faults if runtime calls try to access the 1:1 mapped physical memory. Even though this is expected to be rare in modern platforms, there isn't a clear benefit of keeping LASS active during runtime calls executing under efi_mm.

Also, client BIOSes typically get validated with Windows during development. So, some users could see in-field failures when they start running newer Linux kernels with LASS enabled. Though Ard suggests that things have improved on the Windows side, it doesn't seem worth taking the risk to me.

In the long run, to encourage BIOSes to fix bad code, the kernel could trap invalid accesses to 1:1 mapped physical memory and then warn about buggy firmware. However, such an effort should be pursued independent of LASS [5].

Links
-----
[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://uefi.org/specs/UEFI/2.10/08_Services_Runtime_Services.html#setvirtualaddressmap
[3]: https://lore.kernel.org/lkml/[email protected]/
[4]: https://lore.kernel.org/lkml/[email protected]/
[5]: https://lore.kernel.org/lkml/[email protected]/

Sohil Mehta (3):
x86/cpu: Defer LASS enabling until userspace comes up x86/efi: Disable LASS while executing runtime services x86/cpu: Remove LASS restriction on EFI

 arch/x86/kernel/cpu/common.c   | 30 ++++++++++++++++++++++-------
 arch/x86/platform/efi/efi_64.c | 35 ++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 7 deletions(-)

base-commit: 0f61b1860cc3f52aef9036d7235ed1f017632193

Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/3 x86/cpu: Defer LASS enabling until userspace comes up

LASS blocks any kernel access to the lower half of the virtual address space. Unfortunately, some EFI accesses happen during boot with bit 63 cleared, which causes a #GP fault when LASS is enabled.

Notably, the SetVirtualAddressMap() call can only happen in EFI physical mode. Also, EFI_BOOT_SERVICES_CODE/_DATA could be accessed even after ExitBootServices(). The boot services memory is truly freed during efi_free_boot_services() after SVAM has completed.

To prevent EFI from tripping LASS, at a minimum, LASS enabling must be deferred until EFI has completely finished entering virtual mode (including freeing boot services memory). Moving setup_lass() to arch_cpu_finalize_init() would do the trick, but that would make the implementation very fragile. Something else might come in the future that would need the LASS enabling to be moved again.

In general, security features such as LASS provide limited value before userspace is up. They aren't necessary during early boot while only trusted ring0 code is executing. Introduce a generic late initcall to defer activating some CPU features until userspace is enabled.

For now, only move the LASS CR4 programming to this initcall. As APs are already up by the time late initcalls run, some extra steps are needed to enable LASS on all CPUs. Use a CPU hotplug callback instead of on_each_cpu() or smp_call_function(). This ensures that LASS is enabled on every CPU that is currently online as well as any future CPUs that come online later. Note, even though hotplug callbacks run with preemption enabled, cr4_set_bits() would disable interrupts while updating CR4.

Keep the existing logic in place to clear the LASS feature bits early. setup_clear_cpu_cap() must be called before boot_cpu_data is finalized and alternatives are patched. Eventually, the entire setup_lass() logic can go away once the restrictions based on vsyscall emulation and EFI are removed.

---
v2:
- Add code comments for clarity.

---
 arch/x86/kernel/cpu/common.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/common.c +22 -1
index e7ab22fce3b5..cefd0722e6cc 100644
@@ -422,12 +422,33 @@ static __always_inline void setup_lass(struct cpuinfo_x86 *c)
 	if (IS_ENABLED(CONFIG_X86_VSYSCALL_EMULATION) ||
 	    IS_ENABLED(CONFIG_EFI)) {
 		setup_clear_cpu_cap(X86_FEATURE_LASS);
-		return;
 	}
+}
 
+static int enable_lass(unsigned int cpu)
+{
 	cr4_set_bits(X86_CR4_LASS);
+
+	return 0;
 }
 
+/*
+ * Finalize features that need to be enabled just before entering
+ * userspace. Note that this only runs on a single CPU. Use appropriate
+ * callbacks if all the CPUs need to reflect the same change.
+ */
+static int cpu_finalize_pre_userspace(void)
+{
+	if (!cpu_feature_enabled(X86_FEATURE_LASS))
+		return 0;
+
+	/* Runs on all online CPUs and future CPUs that come online. */
+	cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/lass:enable", enable_lass, NULL);
+
+	return 0;
+}
+late_initcall(cpu_finalize_pre_userspace);
+
 /* These bits should not change their value after CPU init is finished. */
 static const unsigned long cr4_pinned_mask = X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_UMIP |
 					     X86_CR4_FSGSBASE | X86_CR4_CET | X86_CR4_FRED;
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 1/3] x86/cpu: Defer LASS enabling until userspace comes up

Quoted 7 lines · Sohil Mehta
arch/x86/kernel/cpu/common.c +7 -0
+/*
+ * Finalize features that need to be enabled just before entering
+ * userspace. Note that this only runs on a single CPU. Use appropriate
+ * callbacks if all the CPUs need to reflect the same change.
+ */
+static int cpu_finalize_pre_userspace(void)
+{

arch/x86/kernel/cpu/common.c static __always_inline void setup_lass(struct cpuinfo_x86 *c) · line 451

Quoted 10 lines
arch/x86/kernel/cpu/common.c +10 -0
+	if (!cpu_feature_enabled(X86_FEATURE_LASS))
+		return 0;
+
+	/* Runs on all online CPUs and future CPUs that come online. */
+	cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/lass:enable", enable_lass, NULL);
+
+	return 0;
+}
+late_initcall(cpu_finalize_pre_userspace);
+

@Dave, Nikunj,

The current patch

	https://lore.kernel.org/lkml/[email protected]/

..to defer CR pinning enforcement until CPU online makes sense for the FRED fix. Eventually, I am thinking we can defer CR pinning even further until userspace comes up.

setup_cr_pinning(), which enables the static key, can be moved to a late_initcall() such as above. The cpu_online() check to enforce CR pinning would still be needed to make it play nice with CPU hotplug.

Do you see an issue with that approach?

Quoted 3 lines

/* These bits should not change their value after CPU init is finished. */ static const unsigned long cr4_pinned_mask = X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_UMIP |
X86_CR4_FSGSBASE | X86_CR4_CET | X86_CR4_FRED;

#3 lore raw

Re: [PATCH v2 1/3] x86/cpu: Defer LASS enabling until userspace comes up

Quoted 7 lines · Sohil Mehta

The current patch

	https://lore.kernel.org/lkml/[email protected]/

..to defer CR pinning enforcement until CPU online makes sense for the FRED fix. Eventually, I am thinking we can defer CR pinning even further until userspace comes up.

Quoted 5 lines

setup_cr_pinning(), which enables the static key, can be moved to a late_initcall() such as above. The cpu_online() check to enforce CR pinning would still be needed to make it play nice with CPU hotplug.

Do you see an issue with that approach?

Seems fine to me.

merge bot Applied
#4 lore raw

[tip: x86/cpu] x86/cpu: Defer LASS enabling until userspace comes up

In reply to Sohil Mehta
The following commit has been merged into the x86/cpu branch of tip:

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

Commit-ID:     b3226af5ad7bbfcba79d26f547fe6582baf20ce9
Gitweb:        https://git.kernel.org/tip/b3226af5ad7bbfcba79d26f547fe6582baf20ce9
Author:        Sohil Mehta <[email protected]>
AuthorDate:    Tue, 20 Jan 2026 15:47:28 -08:00
Committer:     Dave Hansen <[email protected]>
CommitterDate: Tue, 03 Mar 2026 09:49:44 -08:00

x86/cpu: Defer LASS enabling until userspace comes up

LASS blocks any kernel access to the lower half of the virtual address space. Unfortunately, some EFI accesses happen during boot with bit 63 cleared, which causes a #GP fault when LASS is enabled.

Notably, the SetVirtualAddressMap() call can only happen in EFI physical mode. Also, EFI_BOOT_SERVICES_CODE/_DATA could be accessed even after ExitBootServices(). The boot services memory is truly freed during efi_free_boot_services() after SVAM has completed.

To prevent EFI from tripping LASS, at a minimum, LASS enabling must be deferred until EFI has completely finished entering virtual mode (including freeing boot services memory). Moving setup_lass() to arch_cpu_finalize_init() would do the trick, but that would make the implementation very fragile. Something else might come in the future that would need the LASS enabling to be moved again.

In general, security features such as LASS provide limited value before userspace is up. They aren't necessary during early boot while only trusted ring0 code is executing. Introduce a generic late initcall to defer activating some CPU features until userspace is enabled.

For now, only move the LASS CR4 programming to this initcall. As APs are already up by the time late initcalls run, some extra steps are needed to enable LASS on all CPUs. Use a CPU hotplug callback instead of on_each_cpu() or smp_call_function(). This ensures that LASS is enabled on every CPU that is currently online as well as any future CPUs that come online later. Note, even though hotplug callbacks run with preemption enabled, cr4_set_bits() would disable interrupts while updating CR4.

Keep the existing logic in place to clear the LASS feature bits early. setup_clear_cpu_cap() must be called before boot_cpu_data is finalized and alternatives are patched. Eventually, the entire setup_lass() logic can go away once the restrictions based on vsyscall emulation and EFI are removed.

---
 arch/x86/kernel/cpu/common.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/common.c +22 -1
index 1c3261c..8c56d59 100644
@@ -422,11 +422,32 @@ static __always_inline void setup_lass(struct cpuinfo_x86 *c)
 	if (IS_ENABLED(CONFIG_X86_VSYSCALL_EMULATION) ||
 	    IS_ENABLED(CONFIG_EFI)) {
 		setup_clear_cpu_cap(X86_FEATURE_LASS);
-		return;
 	}
+}
 
+static int enable_lass(unsigned int cpu)
+{
 	cr4_set_bits(X86_CR4_LASS);
+
+	return 0;
+}
+
+/*
+ * Finalize features that need to be enabled just before entering
+ * userspace. Note that this only runs on a single CPU. Use appropriate
+ * callbacks if all the CPUs need to reflect the same change.
+ */
+static int cpu_finalize_pre_userspace(void)
+{
+	if (!cpu_feature_enabled(X86_FEATURE_LASS))
+		return 0;
+
+	/* Runs on all online CPUs and future CPUs that come online. */
+	cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/lass:enable", enable_lass, NULL);
+
+	return 0;
 }
+late_initcall(cpu_finalize_pre_userspace);
 
 /* These bits should not change their value after CPU init is finished. */
 static const unsigned long cr4_pinned_mask = X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_UMIP |
#5 lore raw

PATCH v2 2/3 x86/efi: Disable LASS while executing runtime services

In reply to Sohil Mehta

Ideally, EFI runtime services should switch to kernel virtual addresses after SetVirtualAddressMap(). However, firmware implementations are known to be buggy in this regard and continue to access physical addresses. The kernel maintains a 1:1 mapping of all runtime services code and data regions to avoid breaking such firmware.

LASS enforcement relies on bit 63 of the virtual address, which would block such accesses to the lower half. Unfortunately, not doing anything could lead to #GP faults when users update to a kernel with LASS enabled.

One option is to use a STAC/CLAC pair to temporarily disable LASS data enforcement. However, there is no guarantee that the stray accesses would only touch data and not perform instruction fetches. Also, relying on the AC bit would depend on the runtime calls preserving RFLAGS, which is highly unlikely in practice.

Instead, use the big hammer and switch off the entire LASS mechanism temporarily by clearing CR4.LASS. Runtime services are called in the context of efi_mm, which has explicitly unmapped any memory EFI isn't allowed to touch (including userspace). So, do this right after switching to efi_mm to avoid any security impact.

Some runtime services can be invoked during boot when LASS isn't active. Use a global variable (similar to efi_mm) to save and restore the correct CR4.LASS state. The runtime calls are serialized with the efi_runtime_lock, so no concurrency issues are expected.

---
v2:
- Improve commit message and code comments.

---
 arch/x86/platform/efi/efi_64.c | 35 ++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
arch/x86/platform/efi/efi_64.c +35 -0
index b4409df2105a..5861008eab22 100644
@@ -55,6 +55,7 @@
  */
 static u64 efi_va = EFI_VA_START;
 static struct mm_struct *efi_prev_mm;
+static unsigned long efi_cr4_lass;
 
 /*
  * We need our own copy of the higher levels of the page tables
@@ -443,16 +444,50 @@ static void efi_leave_mm(void)
 	unuse_temporary_mm(efi_prev_mm);
 }
 
+/*
+ * Toggle LASS to allow EFI to access any 1:1 mapped region in the lower
+ * half.
+ *
+ * Disable LASS only after switching to EFI-mm, as userspace is not
+ * mapped in it. Similar to EFI-mm, these rely on preemption being
+ * disabled and the calls being serialized.
+ */
+
+static void efi_disable_lass(void)
+{
+	if (!cpu_feature_enabled(X86_FEATURE_LASS))
+		return;
+
+	lockdep_assert_preemption_disabled();
+
+	/* Save current CR4.LASS state */
+	efi_cr4_lass = cr4_read_shadow() & X86_CR4_LASS;
+	cr4_clear_bits(efi_cr4_lass);
+}
+
+static void efi_enable_lass(void)
+{
+	if (!cpu_feature_enabled(X86_FEATURE_LASS))
+		return;
+
+	lockdep_assert_preemption_disabled();
+
+	/* Reprogram CR4.LASS only if it was set earlier */
+	cr4_set_bits(efi_cr4_lass);
+}
+
 void arch_efi_call_virt_setup(void)
 {
 	efi_sync_low_kernel_mappings();
 	efi_fpu_begin();
 	firmware_restrict_branch_speculation_start();
 	efi_enter_mm();
+	efi_disable_lass();
 }
 
 void arch_efi_call_virt_teardown(void)
 {
+	efi_enable_lass();
 	efi_leave_mm();
 	firmware_restrict_branch_speculation_end();
 	efi_fpu_end();
Signature · 1 line
2.43.0
merge bot Applied
#6 lore raw

[tip: x86/cpu] x86/efi: Disable LASS while executing runtime services

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

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

Commit-ID:     0021e71cfb96d7816e2027a76b813da6003c3a0c
Gitweb:        https://git.kernel.org/tip/0021e71cfb96d7816e2027a76b813da6003c3a0c
Author:        Sohil Mehta <[email protected]>
AuthorDate:    Tue, 20 Jan 2026 15:47:29 -08:00
Committer:     Dave Hansen <[email protected]>
CommitterDate: Tue, 03 Mar 2026 09:49:45 -08:00

x86/efi: Disable LASS while executing runtime services

Ideally, EFI runtime services should switch to kernel virtual addresses after SetVirtualAddressMap(). However, firmware implementations are known to be buggy in this regard and continue to access physical addresses. The kernel maintains a 1:1 mapping of all runtime services code and data regions to avoid breaking such firmware.

LASS enforcement relies on bit 63 of the virtual address, which would block such accesses to the lower half. Unfortunately, not doing anything could lead to #GP faults when users update to a kernel with LASS enabled.

One option is to use a STAC/CLAC pair to temporarily disable LASS data enforcement. However, there is no guarantee that the stray accesses would only touch data and not perform instruction fetches. Also, relying on the AC bit would depend on the runtime calls preserving RFLAGS, which is highly unlikely in practice.

Instead, use the big hammer and switch off the entire LASS mechanism temporarily by clearing CR4.LASS. Runtime services are called in the context of efi_mm, which has explicitly unmapped any memory EFI isn't allowed to touch (including userspace). So, do this right after switching to efi_mm to avoid any security impact.

Some runtime services can be invoked during boot when LASS isn't active. Use a global variable (similar to efi_mm) to save and restore the correct CR4.LASS state. The runtime calls are serialized with the efi_runtime_lock, so no concurrency issues are expected.

---
 arch/x86/platform/efi/efi_64.c | 35 +++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+)
arch/x86/platform/efi/efi_64.c +35 -0
index b4409df..5861008 100644
@@ -55,6 +55,7 @@
  */
 static u64 efi_va = EFI_VA_START;
 static struct mm_struct *efi_prev_mm;
+static unsigned long efi_cr4_lass;
 
 /*
  * We need our own copy of the higher levels of the page tables
@@ -443,16 +444,50 @@ static void efi_leave_mm(void)
 	unuse_temporary_mm(efi_prev_mm);
 }
 
+/*
+ * Toggle LASS to allow EFI to access any 1:1 mapped region in the lower
+ * half.
+ *
+ * Disable LASS only after switching to EFI-mm, as userspace is not
+ * mapped in it. Similar to EFI-mm, these rely on preemption being
+ * disabled and the calls being serialized.
+ */
+
+static void efi_disable_lass(void)
+{
+	if (!cpu_feature_enabled(X86_FEATURE_LASS))
+		return;
+
+	lockdep_assert_preemption_disabled();
+
+	/* Save current CR4.LASS state */
+	efi_cr4_lass = cr4_read_shadow() & X86_CR4_LASS;
+	cr4_clear_bits(efi_cr4_lass);
+}
+
+static void efi_enable_lass(void)
+{
+	if (!cpu_feature_enabled(X86_FEATURE_LASS))
+		return;
+
+	lockdep_assert_preemption_disabled();
+
+	/* Reprogram CR4.LASS only if it was set earlier */
+	cr4_set_bits(efi_cr4_lass);
+}
+
 void arch_efi_call_virt_setup(void)
 {
 	efi_sync_low_kernel_mappings();
 	efi_fpu_begin();
 	firmware_restrict_branch_speculation_start();
 	efi_enter_mm();
+	efi_disable_lass();
 }
 
 void arch_efi_call_virt_teardown(void)
 {
+	efi_enable_lass();
 	efi_leave_mm();
 	firmware_restrict_branch_speculation_end();
 	efi_fpu_end();
#7 lore raw

PATCH v2 3/3 x86/cpu: Remove LASS restriction on EFI

In reply to Sohil Mehta

The initial LASS enabling has been deferred to much later during boot, and EFI runtime services now run with LASS temporarily disabled. This removes LASS from the path of all EFI services.

Remove the LASS restriction on EFI config, as the two can now coexist.

---
v2:
- No change

---
 arch/x86/kernel/cpu/common.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
arch/x86/kernel/cpu/common.c +1 -6
index cefd0722e6cc..5833849f0b52 100644
@@ -415,14 +415,9 @@ static __always_inline void setup_lass(struct cpuinfo_x86 *c)
 	 * Legacy vsyscall page access causes a #GP when LASS is active.
 	 * Disable LASS because the #GP handler doesn't support vsyscall
 	 * emulation.
-	 *
-	 * Also disable LASS when running under EFI, as some runtime and
-	 * boot services rely on 1:1 mappings in the lower half.
 	 */
-	if (IS_ENABLED(CONFIG_X86_VSYSCALL_EMULATION) ||
-	    IS_ENABLED(CONFIG_EFI)) {
+	if (IS_ENABLED(CONFIG_X86_VSYSCALL_EMULATION))
 		setup_clear_cpu_cap(X86_FEATURE_LASS);
-	}
 }
 
 static int enable_lass(unsigned int cpu)
Signature · 1 line
2.43.0
merge bot Applied
#8 lore raw

[tip: x86/cpu] x86/cpu: Remove LASS restriction on EFI

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

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

Commit-ID:     68400c1aaf02636a97c45ba198110b66feb270a9
Gitweb:        https://git.kernel.org/tip/68400c1aaf02636a97c45ba198110b66feb270a9
Author:        Sohil Mehta <[email protected]>
AuthorDate:    Tue, 20 Jan 2026 15:47:30 -08:00
Committer:     Dave Hansen <[email protected]>
CommitterDate: Tue, 03 Mar 2026 09:49:45 -08:00

x86/cpu: Remove LASS restriction on EFI

The initial LASS enabling has been deferred to much later during boot, and EFI runtime services now run with LASS temporarily disabled. This removes LASS from the path of all EFI services.

Remove the LASS restriction on EFI config, as the two can now coexist.

---
 arch/x86/kernel/cpu/common.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
arch/x86/kernel/cpu/common.c +1 -6
index 8c56d59..3557f0e 100644
@@ -415,14 +415,9 @@ static __always_inline void setup_lass(struct cpuinfo_x86 *c)
 	 * Legacy vsyscall page access causes a #GP when LASS is active.
 	 * Disable LASS because the #GP handler doesn't support vsyscall
 	 * emulation.
-	 *
-	 * Also disable LASS when running under EFI, as some runtime and
-	 * boot services rely on 1:1 mappings in the lower half.
 	 */
-	if (IS_ENABLED(CONFIG_X86_VSYSCALL_EMULATION) ||
-	    IS_ENABLED(CONFIG_EFI)) {
+	if (IS_ENABLED(CONFIG_X86_VSYSCALL_EMULATION))
 		setup_clear_cpu_cap(X86_FEATURE_LASS);
-	}
 }
 
 static int enable_lass(unsigned int cpu)
Tested-by on the v2 series
#9 lore raw
In reply to Sohil Mehta

Booted successfully with the patches on a Sierra Forest system. Checked it out with LAM enabled and my KASAN series, and ran KASAN kunits without issues and the LAM selftests also worked as expected.

(resending because my email client ate the in-reply-to)

Quoted 88 lines · Sohil Mehta

Linear Address Space Separation (LASS) is currently disabled [1] when support for vsyscall emulation or EFI is compiled in. This series extends LASS support to EFI-enabled configurations.

Changes in v2
-------------
- Rebased the series to v6.19-rc5
- Improved commit messages and code comments based on feedback

v1: https://lore.kernel.org/lkml/[email protected]/

Issues with EFI
---------------
EFI boot and runtime services are incompatible with LASS because they end up accessing addresses with bit 63 cleared, which is blocked by LASS.

1) The most obvious one is the SetVirtualAddressMap() runtime service, which is expected to be called in EFI physical mode [2].

2) Some runtime services fail to switch to virtual mode properly and continue referencing physical addresses even after SVAM. The kernel maintains a 1:1 mapping of all runtime services code and data regions to avoid breaking such firmware.

3) Some boot services code and data regions are referenced long after ExitBootServices(). Most of these access use the kernel direct map so bit 63 is expected to be set. But some odd firmware implementation could access that memory via a mapping in the lower range.

Solution
--------
These patches take LASS out of the path of all EFI boot and runtime service interactions by:

Patch 1: Deferring LASS enabling until userspace comes up, which ensures EFI has completed switching to virtual mode and all boot services memory has been freed [3].

Patch 2: Temporarily disabling LASS every time a runtime service is executed after boot. Runtime services execute in a special efi_mm which doesn't have userspace mapped. So, the security implications of disabling LASS are fairly limited [4].

Please find more details in the respective patches.

Alternate options
-----------------
One option is to not support broken firmware implementations (by avoiding patch 2) starting with systems that support LASS. That would trigger #GP faults if runtime calls try to access the 1:1 mapped physical memory. Even though this is expected to be rare in modern platforms, there isn't a clear benefit of keeping LASS active during runtime calls executing under efi_mm.

Also, client BIOSes typically get validated with Windows during development. So, some users could see in-field failures when they start running newer Linux kernels with LASS enabled. Though Ard suggests that things have improved on the Windows side, it doesn't seem worth taking the risk to me.

In the long run, to encourage BIOSes to fix bad code, the kernel could trap invalid accesses to 1:1 mapped physical memory and then warn about buggy firmware. However, such an effort should be pursued independent of LASS [5].

Links
-----
[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://uefi.org/specs/UEFI/2.10/08_Services_Runtime_Services.html#setvirtualaddressmap
[3]: https://lore.kernel.org/lkml/[email protected]/
[4]: https://lore.kernel.org/lkml/[email protected]/
[5]: https://lore.kernel.org/lkml/[email protected]/

Sohil Mehta (3):
x86/cpu: Defer LASS enabling until userspace comes up x86/efi: Disable LASS while executing runtime services x86/cpu: Remove LASS restriction on EFI

arch/x86/kernel/cpu/common.c | 30 ++++++++++++++++++++++-------
arch/x86/platform/efi/efi_64.c | 35 ++++++++++++++++++++++++++++++++++

2 files changed, 58 insertions(+), 7 deletions(-)

base-commit: 0f61b1860cc3f52aef9036d7235ed1f017632193

Signature · 1 line
2.43.0
Tested-by on the v2 series
#10 lore raw
In reply to Sohil Mehta
Quoted 3 lines · Sohil Mehta

Linear Address Space Separation (LASS) is currently disabled [1] when support for vsyscall emulation or EFI is compiled in. This series extends LASS support to EFI-enabled configurations.

I tried these patches on a LASS-capable system with a kernel built with CONFIG_X86_VSYSCALL_EMULATION disabled, and traces added to efi_disable_lass() and efi_enable_lass().

System boots OK (with a bunch of my trace messages showing that CR4.LASS was disabled/enabled around EFI calls from several CPUs).

Just for grins I commented out the CR4 changes from the efi_disable_lass() and efi_enable_lass(). System still boots OK, so it seems the EFI runtime calls during boot don't have any of the BIOS bugs that require LASS disable.

-Tony

#11 lore raw
In reply to Sohil Mehta

Hello x86 Maintainers, Ard,

Quoted 5 lines · Sohil Mehta

Solution
--------
These patches take LASS out of the path of all EFI boot and runtime service interactions by:

Quoted 9 lines

Patch 1: Deferring LASS enabling until userspace comes up, which ensures EFI has completed switching to virtual mode and all boot services memory has been freed [3].

Patch 2: Temporarily disabling LASS every time a runtime service is executed after boot. Runtime services execute in a special efi_mm which doesn't have userspace mapped. So, the security implications of disabling LASS are fairly limited [4].

The patches now have tested-by tags from Maciej and Tony. Also, the patches apply cleanly on v7.0-rc1. I am hoping to get some review feedback on the patches before resending another version.

Ard, are you okay with patch 2 that disables LASS during EFI runtime calls?

x86 Maintainers, patch 1 introduces a common mechanism to defer initializing features until userspace is about to come up. In the future, enabling of features (such as SMAP, SMEP, UMIP) and CR pinning, SPEC_CTRL MSR can be moved here.

Also, there is a possibility that the freeing of EFI boot services memory might happen later based on the recent discussion at:
https://lore.kernel.org/lkml/[email protected]/

Overall, the approach in patch 1 seems useful. The implementation is based on a combination of late_initcall() and CPU hotplug callbacks. Thoughts?

maintainer
#12 lore raw
Quoted 18 lines · Sohil Mehta

Hello x86 Maintainers, Ard,

Quoted 5 lines · Sohil Mehta

Solution
--------
These patches take LASS out of the path of all EFI boot and runtime service interactions by:

Quoted 9 lines

Patch 1: Deferring LASS enabling until userspace comes up, which ensures EFI has completed switching to virtual mode and all boot services memory has been freed [3].

Patch 2: Temporarily disabling LASS every time a runtime service is executed after boot. Runtime services execute in a special efi_mm which doesn't have userspace mapped. So, the security implications of disabling LASS are fairly limited [4].

Quoted 6 lines

The patches now have tested-by tags from Maciej and Tony. Also, the patches apply cleanly on v7.0-rc1. I am hoping to get some review feedback on the patches before resending another version.

Ard, are you okay with patch 2 that disables LASS during EFI runtime calls?

Yeah I think that's fine.

#13 lore raw
In reply to Sohil Mehta
Quoted 3 lines · Sohil Mehta

Overall, the approach in patch 1 seems useful. The implementation is based on a combination of late_initcall() and CPU hotplug callbacks. Thoughts?

It looks great, actually. It's really nice how the CPU hotplug infrastructure takes care of all the hard work.