Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: Properly disable FPU in start_thread()

start_thread() (called for execve(2)) clears the TIF_USEDFPU flag
without atomically disabling the FPU. With a preemptive kernel, an
unfortunately timed preemption after this could result in another
task (or KVM guest) being scheduled in with the FPU still enabled, since
lose_fpu_inatomic() only turns it off if TIF_USEDFPU is set.

Use lose_fpu(0) instead of the separate FPU / MSA management, which
should do the right thing (drop FPU properly and atomically without
saving state) and will be more future proof.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Reviewed-by: Paul Burton <paul.burton@imgtec.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/12302/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

James Hogan and committed by
Ralf Baechle
76e5846d f4dce1ff

+3 -5
+3 -5
arch/mips/kernel/process.c
··· 65 65 status = regs->cp0_status & ~(ST0_CU0|ST0_CU1|ST0_FR|KU_MASK); 66 66 status |= KU_USER; 67 67 regs->cp0_status = status; 68 - clear_used_math(); 69 - clear_fpu_owner(); 70 - init_dsp(); 71 - clear_thread_flag(TIF_USEDMSA); 68 + lose_fpu(0); 72 69 clear_thread_flag(TIF_MSA_CTX_LIVE); 73 - disable_msa(); 70 + clear_used_math(); 71 + init_dsp(); 74 72 regs->cp0_epc = pc; 75 73 regs->regs[29] = sp; 76 74 }