Skip to content

Commit abee7c4

Browse files
jgross1Peter Zijlstra
authored andcommitted
x86/alternative: Don't call text_poke() in lazy TLB mode
When running in lazy TLB mode the currently active page tables might be the ones of a previous process, e.g. when running a kernel thread. This can be problematic in case kernel code is being modified via text_poke() in a kernel thread, and on another processor exit_mmap() is active for the process which was running on the first cpu before the kernel thread. As text_poke() is using a temporary address space and the former address space (obtained via cpu_tlbstate.loaded_mm) is restored afterwards, there is a race possible in case the cpu on which exit_mmap() is running wants to make sure there are no stale references to that address space on any cpu active (this e.g. is required when running as a Xen PV guest, where this problem has been observed and analyzed). In order to avoid that, drop off TLB lazy mode before switching to the temporary address space. Fixes: cefa929 ("x86/mm: Introduce temporary mm structs") Signed-off-by: Juergen Gross <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent c3b484c commit abee7c4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

arch/x86/kernel/alternative.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,15 @@ static inline temp_mm_state_t use_temporary_mm(struct mm_struct *mm)
807807
temp_mm_state_t temp_state;
808808

809809
lockdep_assert_irqs_disabled();
810+
811+
/*
812+
* Make sure not to be in TLB lazy mode, as otherwise we'll end up
813+
* with a stale address space WITHOUT being in lazy mode after
814+
* restoring the previous mm.
815+
*/
816+
if (this_cpu_read(cpu_tlbstate.is_lazy))
817+
leave_mm(smp_processor_id());
818+
810819
temp_state.mm = this_cpu_read(cpu_tlbstate.loaded_mm);
811820
switch_mm_irqs_off(NULL, mm, current);
812821

0 commit comments

Comments
 (0)