[patch 00/24] x86/speculation: Remedy the STIBP/IBPB overhead

From: Thomas Gleixner
Date: Wed Nov 21 2018 - 15:20:15 EST


This is based on Tim Chen's V5 patch series. The following changes have
been made:

- Control STIPB evaluation with a single static key

- Move IBPB out from switch_mm() into switch_to() and control the
always and the conditional mode with static keys.

The mainline implementation is wrong in a few aspects, e.g. it fails
to protect tasks within the same process, which breaks
sandboxing. That same process optimization was the sole reason to have
it in switch_mm().

The new always mode is just issuing the barrier unconditionally when
switching to a user task, but that also leaves STIPB always on. So
really paranoid people get the highest possible protection and the
highest overhead.

The conditional mode issues the barrier when a task which is mitigated
is scheduling out or scheduling in. That is required to support proper
sandboxing.

- Remove the ptrace_may_access_sched() code as it's unused now. It was
ugly anyway and would have given people ideas how to slow down
switch_mm() some more.

- Rename TIF_STIPB to TIF_SPEC_IB because it controls both STIBP and
IBPB.

- Fix all the corner cases vs. UP and SMT disabled.

- Limit the overhead when conditional STIPB is not enabled so
switch_to_xtra() is not invoked for nothing when the TIF bit would
trigger the entry and nothing else is to do. That can happen when SMT
is off and a task has the TIF bit set. On UP STIPB is never enabled.

- Dropped the dumpable part

TODO: Write documentation

It's avaiable from git:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git WIP.x86/pti

It's based on the x86/pti branch unfortunately, which contains the removal
of the minimal asm retpoline hackery. I noticed too late. If the minimal
asm stuff should not be backported it's trivial to rebase that series on
Linus tree.

Thanks,

tglx