x86/cpuid: Rework HLE and RTM handling
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 20 May 2021 18:48:39 +0000 (19:48 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 27 May 2021 18:34:00 +0000 (19:34 +0100)
commit8fe24090d940d760145ccd5e234290be7418b175
treed4b16d2adf193de7d6b6829249d67e42c98eec9e
parent722f59d38c710a940ab05e542a83020eb5546dea
x86/cpuid: Rework HLE and RTM handling

The TAA mitigation offered the option to hide the HLE and RTM CPUID bits,
which has caused some migration compatibility problems.

These two bits are special.  Annotate them with ! to emphasise this point.

Hardware Lock Elision (HLE) may or may not be visible in CPUID, but is
disabled in microcode on all CPUs, and has been removed from the architecture.
Do not advertise it to VMs by default.

Restricted Transactional Memory (RTM) may or may not be visible in CPUID, and
may or may not be configured in force-abort mode.  Have tsx_init() note
whether RTM has been configured into force-abort mode, so
guest_common_feature_adjustments() can conditionally hide it from VMs by
default.

The host policy values for HLE/RTM may or may not be set, depending on any
previous running kernel's choice of visibility, and Xen's choice.  TSX is
available on any CPU which enumerates a TSX-hiding mechanism, so instead of
doing a two-step to clobber any hiding, scan CPUID, then set the visibility,
just force visibility of the bits in the first place.

With the HLE/RTM bits now unilaterally visible in the host policy,
xc_cpuid_apply_policy() can construct a more appropriate policy out of thin
air for pre-4.13 VMs with no CPUID data in their migration stream, and
specifically one where HLE/RTM doesn't potentially disappear behind the back
of a running VM.

Fixes: 8c4330818f6 ("x86/spec-ctrl: Mitigate the TSX Asynchronous Abort sidechannel")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
tools/libs/guest/xg_cpuid_x86.c
xen/arch/x86/cpuid.c
xen/arch/x86/spec_ctrl.c
xen/arch/x86/tsx.c
xen/include/asm-x86/processor.h
xen/include/public/arch-x86/cpufeatureset.h