x86/spec-ctrl: Mitigate Branch Type Confusion when possible
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 27 Jun 2022 18:29:40 +0000 (19:29 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 12 Jul 2022 15:25:33 +0000 (16:25 +0100)
commit0a5387a01165b46c8c85e7f7e2ddbe60a7f5db44
treef424dfc48f46ea6106d1b1fdb491da52ebe704f3
parent5457a6870eb1369b868f7b8e833966ed43a773ad
x86/spec-ctrl: Mitigate Branch Type Confusion when possible

Branch Type Confusion affects AMD/Hygon CPUs on Zen2 and earlier.  To
mitigate, we require SMT safety (STIBP on Zen2, no-SMT on Zen1), and to issue
an IBPB on each entry to Xen, to flush the BTB.

Due to performance concerns, dom0 (which is trusted in most configurations) is
excluded from protections by default.

Therefore:
 * Use STIBP by default on Zen2 too, which now means we want it on by default
   on all hardware supporting STIBP.
 * Break the current IBPB logic out into a new function, extending it with
   IBPB-at-entry logic.
 * Change the existing IBPB-at-ctxt-switch boolean to be tristate, and disable
   it by default when IBPB-at-entry is providing sufficient safety.

If all PV guests on the system are trusted, then it is recommended to boot
with `spec-ctrl=ibpb-entry=no-pv`, as this will provide an additional marginal
perf improvement.

This is part of XSA-407 / CVE-2022-23825.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
(cherry picked from commit d8cb7e0f069e0f106d24941355b59b45a731eabe)
docs/misc/xen-command-line.pandoc
xen/arch/x86/spec_ctrl.c
xen/include/asm-x86/spec_ctrl.h