Commit eb0ea741 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'x86-fpu-2020-12-14' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 FPU updates from Thomas Gleixner:

 - Simplify the FPU protection for !RT kernels

 - Add the RT variant of FPU protections

* tag 'x86-fpu-2020-12-14' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86/fpu: Make kernel FPU protection RT friendly
  x86/fpu: Simplify fpregs_[un]lock()
parents edd7ab76 cba08c5d
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -29,16 +29,31 @@ extern void fpregs_mark_activate(void);
 * A context switch will (and softirq might) save CPU's FPU registers to
 * fpu->state and set TIF_NEED_FPU_LOAD leaving CPU's FPU registers in
 * a random state.
 *
 * local_bh_disable() protects against both preemption and soft interrupts
 * on !RT kernels.
 *
 * On RT kernels local_bh_disable() is not sufficient because it only
 * serializes soft interrupt related sections via a local lock, but stays
 * preemptible. Disabling preemption is the right choice here as bottom
 * half processing is always in thread context on RT kernels so it
 * implicitly prevents bottom half processing as well.
 *
 * Disabling preemption also serializes against kernel_fpu_begin().
 */
static inline void fpregs_lock(void)
{
	preempt_disable();
	if (!IS_ENABLED(CONFIG_PREEMPT_RT))
		local_bh_disable();
	else
		preempt_disable();
}

static inline void fpregs_unlock(void)
{
	if (!IS_ENABLED(CONFIG_PREEMPT_RT))
		local_bh_enable();
	else
		preempt_enable();
}