Commit ba523588 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Greg Kroah-Hartman

x86/speculation: Avoid __switch_to_xtra() calls

commit 5635d999 upstream

The TIF_SPEC_IB bit does not need to be evaluated in the decision to invoke
__switch_to_xtra() when:

 - CONFIG_SMP is disabled

 - The conditional STIPB mode is disabled

The TIF_SPEC_IB bit still controls IBPB in both cases so the TIF work mask
checks might invoke __switch_to_xtra() for nothing if TIF_SPEC_IB is the
only set bit in the work masks.

Optimize it out by masking the bit at compile time for CONFIG_SMP=n and at
run time when the static key controlling the conditional STIBP mode is
Signed-off-by: default avatarThomas Gleixner <>
Reviewed-by: default avatarIngo Molnar <>
Cc: Peter Zijlstra <>
Cc: Andy Lutomirski <>
Cc: Linus Torvalds <>
Cc: Jiri Kosina <>
Cc: Tom Lendacky <>
Cc: Josh Poimboeuf <>
Cc: Andrea Arcangeli <>
Cc: David Woodhouse <>
Cc: Tim Chen <>
Cc: Andi Kleen <>
Cc: Dave Hansen <>
Cc: Casey Schaufler <>
Cc: Asit Mallick <>
Cc: Arjan van de Ven <>
Cc: Jon Masters <>
Cc: Waiman Long <>
Cc: Greg KH <>
Cc: Dave Stewart <>
Cc: Kees Cook <>
Link: default avatarGreg Kroah-Hartman <>
parent 7fe6a4ba
......@@ -149,9 +149,18 @@ struct thread_info {
/* flags to check in __switch_to() */
#define _TIF_WORK_CTXSW \
* Avoid calls to __switch_to_xtra() on UP as STIBP is not evaluated.
......@@ -2,6 +2,8 @@
// Code shared between 32 and 64 bit
#include <asm/spec-ctrl.h>
void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p);
......@@ -14,6 +16,19 @@ static inline void switch_to_extra(struct task_struct *prev,
unsigned long next_tif = task_thread_info(next)->flags;
unsigned long prev_tif = task_thread_info(prev)->flags;
* Avoid __switch_to_xtra() invocation when conditional
* STIPB is disabled and the only different bit is
* in the TIF_WORK_CTXSW masks.
if (!static_branch_likely(&switch_to_cond_stibp)) {
prev_tif &= ~_TIF_SPEC_IB;
next_tif &= ~_TIF_SPEC_IB;
* __switch_to_xtra() handles debug registers, i/o bitmaps,
* speculation mitigations etc.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment