[PATCH 6/7] x86/efi: Make efi_enter/leave_mm use the temporary_mm machinery

From: Peter Zijlstra
Date: Tue Nov 19 2024 - 11:32:30 EST


From: Andy Lutomirski <luto@xxxxxxxxxx>

This should be considerably more robust. It's also necessary for optimized
for_each_possible_lazymm_cpu() on x86 -- without this patch, EFI calls in
lazy context would remove the lazy mm from mm_cpumask().

Signed-off-by: Andy Lutomirski <luto@xxxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Link: https://lkml.kernel.org/r/3efc4cfd1d7c45a32752ced389d6666be15cde56.1641659630.git.luto@xxxxxxxxxx
---
arch/x86/platform/efi/efi_64.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -54,7 +54,7 @@
* 0xffff_ffff_0000_0000 and limit EFI VA mapping space to 64G.
*/
static u64 efi_va = EFI_VA_START;
-static struct mm_struct *efi_prev_mm;
+static temp_mm_state_t efi_temp_mm_state;

/*
* We need our own copy of the higher levels of the page tables
@@ -476,15 +476,12 @@ void __init efi_dump_pagetable(void)
*/
static void efi_enter_mm(void)
{
- efi_prev_mm = current->active_mm;
- current->active_mm = &efi_mm;
- switch_mm(efi_prev_mm, &efi_mm, NULL);
+ efi_temp_mm_state = use_temporary_mm(&efi_mm);
}

static void efi_leave_mm(void)
{
- current->active_mm = efi_prev_mm;
- switch_mm(&efi_mm, efi_prev_mm, NULL);
+ unuse_temporary_mm(efi_temp_mm_state);
}

void arch_efi_call_virt_setup(void)