Skip to content

Commit 6b9c98e

Browse files
ardbiesheuvelctmarinas
authored andcommitted
arm64/efi: Move uaccess en/disable out of efi_set_pgd()
efi_set_pgd() will no longer be called when invoking EFI runtime services via the efi_rts_wq work queue, but the uaccess en/disable are still needed when using PAN emulation using TTBR0 switching. So move these into the callers. Acked-by: Will Deacon <will@kernel.org> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 1068cb5 commit 6b9c98e

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

arch/arm64/include/asm/efi.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,14 @@ static inline void efi_set_pgd(struct mm_struct *mm)
126126
if (mm != current->active_mm) {
127127
/*
128128
* Update the current thread's saved ttbr0 since it is
129-
* restored as part of a return from exception. Enable
130-
* access to the valid TTBR0_EL1 and invoke the errata
131-
* workaround directly since there is no return from
132-
* exception when invoking the EFI run-time services.
129+
* restored as part of a return from exception.
133130
*/
134131
update_saved_ttbr0(current, mm);
135-
uaccess_ttbr0_enable();
136-
post_ttbr_update_workaround();
137132
} else {
138133
/*
139-
* Defer the switch to the current thread's TTBR0_EL1
140-
* until uaccess_enable(). Restore the current
141-
* thread's saved ttbr0 corresponding to its active_mm
134+
* Restore the current thread's saved ttbr0
135+
* corresponding to its active_mm
142136
*/
143-
uaccess_ttbr0_disable();
144137
update_saved_ttbr0(current, current->active_mm);
145138
}
146139
}

arch/arm64/kernel/efi.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,30 @@ void arch_efi_call_virt_setup(void)
169169
{
170170
efi_runtime_assert_lock_held();
171171
efi_virtmap_load();
172+
173+
/*
174+
* Enable access to the valid TTBR0_EL1 and invoke the errata
175+
* workaround directly since there is no return from exception when
176+
* invoking the EFI run-time services.
177+
*/
178+
uaccess_ttbr0_enable();
179+
post_ttbr_update_workaround();
180+
172181
__efi_fpsimd_begin();
173182
}
174183

175184
void arch_efi_call_virt_teardown(void)
176185
{
177186
__efi_fpsimd_end();
187+
188+
/*
189+
* Defer the switch to the current thread's TTBR0_EL1 until
190+
* uaccess_enable(). Do so before efi_virtmap_unload() updates the
191+
* saved TTBR0 value, so the userland page tables are not activated
192+
* inadvertently over the back of an exception.
193+
*/
194+
uaccess_ttbr0_disable();
195+
178196
efi_virtmap_unload();
179197
}
180198

0 commit comments

Comments
 (0)