x86/cpu-policy: Rearrange guest_common_*_feature_adjustments()

Turn the if()s into switch()es, as we're going to need AMD sections.

Move the RTM adjustments into the Intel section, where they ought to live.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
(cherry picked from commit 7c5025394d)
This commit is contained in:
Andrew Cooper committed 2025-07-07 22:52:15 +01:00
1 parent 67bb8f699d
commit d45dfbcbc6
1 file changed
+37 -32
+37 -32
View File
@@ -415,8 +415,9 @@ static void __init guest_common_default_leaves(struct cpu_policy *p)
static void __init guest_common_max_feature_adjustments(uint32_t *fs)
{
if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
switch ( boot_cpu_data.x86_vendor )
{
case X86_VENDOR_INTEL:
/*
* MSR_ARCH_CAPS is just feature data, and we can offer it to guests
* unconditionally, although limit it to Intel systems as it is highly
@@ -461,6 +462,22 @@ static void __init guest_common_max_feature_adjustments(uint32_t *fs)
boot_cpu_data.x86_model == INTEL_FAM6_SKYLAKE_X &&
raw_cpu_policy.feat.clwb )
__set_bit(X86_FEATURE_CLWB, fs);
/*
* To mitigate Native-BHI, one option is to use a TSX Abort on capable
* systems. This is safe even if RTM has been disabled for other
* reasons via MSR_TSX_{CTRL,FORCE_ABORT}. However, a guest kernel
* doesn't get to know this type of information.
*
* Therefore the meaning of RTM_ALWAYS_ABORT has been adjusted, to
* instead mean "XBEGIN won't fault". This is enough for a guest
* kernel to make an informed choice WRT mitigating Native-BHI.
*
* If RTM-capable, we can run a VM which has seen RTM_ALWAYS_ABORT.
*/
if ( test_bit(X86_FEATURE_RTM, fs) )
__set_bit(X86_FEATURE_RTM_ALWAYS_ABORT, fs);
break;
}
/*
@@ -472,27 +489,13 @@ static void __init guest_common_max_feature_adjustments(uint32_t *fs)
*/
__set_bit(X86_FEATURE_HTT, fs);
__set_bit(X86_FEATURE_CMP_LEGACY, fs);
/*
* To mitigate Native-BHI, one option is to use a TSX Abort on capable
* systems. This is safe even if RTM has been disabled for other reasons
* via MSR_TSX_{CTRL,FORCE_ABORT}. However, a guest kernel doesn't get to
* know this type of information.
*
* Therefore the meaning of RTM_ALWAYS_ABORT has been adjusted, to instead
* mean "XBEGIN won't fault". This is enough for a guest kernel to make
* an informed choice WRT mitigating Native-BHI.
*
* If RTM-capable, we can run a VM which has seen RTM_ALWAYS_ABORT.
*/
if ( test_bit(X86_FEATURE_RTM, fs) )
__set_bit(X86_FEATURE_RTM_ALWAYS_ABORT, fs);
}
static void __init guest_common_default_feature_adjustments(uint32_t *fs)
{
if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
switch ( boot_cpu_data.x86_vendor )
{
case X86_VENDOR_INTEL:
/*
* IvyBridge client parts suffer from leakage of RDRAND data due to SRBDS
* (XSA-320 / CVE-2020-0543), and won't be receiving microcode to
@@ -536,6 +539,23 @@ static void __init guest_common_default_feature_adjustments(uint32_t *fs)
boot_cpu_data.x86_model == INTEL_FAM6_SKYLAKE_X &&
raw_cpu_policy.feat.clwb )
__clear_bit(X86_FEATURE_CLWB, fs);
/*
* On certain hardware, speculative or errata workarounds can result
* in TSX being placed in "force-abort" mode, where it doesn't
* actually function as expected, but is technically compatible with
* the ISA.
*
* Do not advertise RTM to guests by default if it won't actually
* work. Instead, advertise RTM_ALWAYS_ABORT indicating that TSX
* Aborts are safe to use, e.g. for mitigating Native-BHI.
*/
if ( rtm_disabled )
{
__clear_bit(X86_FEATURE_RTM, fs);
__set_bit(X86_FEATURE_RTM_ALWAYS_ABORT, fs);
}
break;
}
/*
@@ -547,21 +567,6 @@ static void __init guest_common_default_feature_adjustments(uint32_t *fs)
if ( !cpu_has_cmp_legacy )
__clear_bit(X86_FEATURE_CMP_LEGACY, fs);
/*
* On certain hardware, speculative or errata workarounds can result in
* TSX being placed in "force-abort" mode, where it doesn't actually
* function as expected, but is technically compatible with the ISA.
*
* Do not advertise RTM to guests by default if it won't actually work.
* Instead, advertise RTM_ALWAYS_ABORT indicating that TSX Aborts are safe
* to use, e.g. for mitigating Native-BHI.
*/
if ( rtm_disabled )
{
__clear_bit(X86_FEATURE_RTM, fs);
__set_bit(X86_FEATURE_RTM_ALWAYS_ABORT, fs);
}
}
static void __init guest_common_feature_adjustments(uint32_t *fs)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.