Xen Security Advisory 471 v1 (CVE-2024-36350,CVE-2024-36357) - x86: Transitive Scheduler Attacks
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Xen Security Advisory CVE-2024-36350,CVE-2024-36357 / XSA-471
x86: Transitive Scheduler Attacks
ISSUE DESCRIPTION
=================
Researchers from Microsoft and ETH Zurich have discovered several new speculative sidechannel attacks which bypass current protections. They are detailed in a paper titled "Enter, Exit, Page Fault, Leak: Testing Isolation Boundaries for Microarchitectural Leaks".
Two issues, which AMD have named Transitive Scheduler Attacks, utilise timing information from instruction execution. These are:
* CVE-2024-36350: TSA-SQ (TSA in the Store Queues)
* CVE-2024-36357: TSA-L1 (TSA in the L1 data cache)
For more information, see:
https://www.amd.com/content/dam/amd/en/documents/resources/bulletin/technical-guidance-for-mitigating-transient-scheduler-attacks.pdf
https://www.amd.com/en/resources/product-security/bulletin/amd-sb-7029.html
https://aka.ms/enter-exit-leak
The paper also details other speculative attacks. See below.
IMPACT
======
An attacker might be able to infer data belonging to other contexts, including data belonging to other guests.
VULNERABLE SYSTEMS
==================
Systems running all versions of Xen are affected.
Only AMD Fam19h CPUs (Zen3/4 microarchitectures) are believed to be vulnerable. Other AMD CPUs, and CPUs from other manufacturers are not known to be affected.
MITIGATION
==========
There are no mitigations.
RESOLUTION
==========
AMD are producing microcode to address TSA, which adds scrubbing side effects to the VERW instruction. This was included in the firmware fixes for the Entrysign signature vulnerability from ~December 2024, but are also available in an OS-loadable form on older firmware. Consult your dom0 OS vendor and/or hardware vendor for updated microcode.
In addition to the microcode, changes are requires to Xen to make use of VERW scrubbing at suitable points.
Applying the appropriate set of attached patches resolves this issue.
Note that patches for released versions are generally prepared to apply to the stable branches, and may not apply cleanly to the most recent release tarball. Downstreams are encouraged to update to the tip of the stable branch before applying these patches.
xsa471/xsa471-??.patch xen-unstable xsa471/xsa471-4.20-??.patch Xen 4.20.x xsa471/xsa471-4.19-??.patch Xen 4.19.x xsa471/xsa471-4.18-??.patch Xen 4.18.x xsa471/xsa471-4.17-??.patch Xen 4.17.x
$ sha256sum xsa471*/* 4cc8b54d3cae4864053c4d608061675564cc322c6cd362e33ac59ac4c9371358 xsa471/xsa471-01.patch 9bdfd0ad8d34114e69bb0e264ffdcb176e54211753cc1eed247e73cd3fe752e9 xsa471/xsa471-02.patch 62706c1593cb64bfd053f5ee2e8fa26f5414835c6ef5f694c52a61e18017aa1d xsa471/xsa471-03.patch e06162c55de0b3ca79302ea47c8169079b0f2cd65a48d3e0509677452c9887da xsa471/xsa471-4.17-01.patch 742c59d776c73993c44e72ceada2b83b61fa77a988f5c2c593b6594b4f4078de xsa471/xsa471-4.17-02.patch a8ed5e90e405273115d6a06199de3190319ba12aac33bea17495db42b6a9becc xsa471/xsa471-4.17-03.patch 855c9528d93109a1a673dd8f4feb87a688457908c9dd821d0e1a3326efb19257 xsa471/xsa471-4.17-04.patch f8dbe5c8dbdf921c7f9b4bc7d8234b9bb291df6a4a8cef604284bf4f36947d4e xsa471/xsa471-4.17-05.patch fa2682955663e0966cf285bf79770fe76b387fbf449e1ac64206a6ae4bf79bc4 xsa471/xsa471-4.17-06.patch dc4695aced6ba65e8b16088aefe817e8e4d965cd94e9e3340bd48d77c1369902 xsa471/xsa471-4.17-07.patch 0393a8711805f40eeb936dcca56f5bea174ff94098ffaee7064cd6801eb55099 xsa471/xsa471-4.17-08.patch 346493cc12d9a0fa4154968bc0c8dca9d87e583a25ae9ecd22b8ae2c7bdeae19 xsa471/xsa471-4.17-09.patch 0d652e9a6bb89782036b39160f2db9c1fd1dfc0e659fb4e351f04eb66ffbdba8 xsa471/xsa471-4.17-10.patch ff3ae74f6cfccfaee55f007b2410813068928d20a23729ae2766ddcc65d2e82b xsa471/xsa471-4.17-11.patch 5c6d133f626fdcbc148b596bf3cee1c46260d73fd833aeb6c59cf7c1b315f2b8 xsa471/xsa471-4.17-12.patch acbdca53d713122545ba210a795c4185e842d4cca71802775adc1a4ce971bf3a xsa471/xsa471-4.17-13.patch 4a7fa23b7f501cb88100b55fab13b7315a01fc1e4a3eff46b5d0c867fcc03ca8 xsa471/xsa471-4.17-14.patch 164d626a2f446ad7692bd70ab7e109f8b6259aaea34bfb9f51df68def98a2e62 xsa471/xsa471-4.17-15.patch 35699b19590ccf1872c8da8731b4c47e95cc38d119510e182d196427ea4455f8 xsa471/xsa471-4.17-16.patch 296c95410b6dbf55fa092d15e0eee66125a87b012095f84c550eea54078d0490 xsa471/xsa471-4.17-17.patch 0212aec278afe0dcc6479b756a0c1821d2bfba646fa9ec56f1b9b37ff51756f4 xsa471/xsa471-4.17-18.patch 4e05073bc960b7f43dd383356d1b56fa9c55dc021205678bd8ac456f3a1d00f0 xsa471/xsa471-4.17-19.patch 0d4166420a9e69afe3303d6d3232ee43cf27e88e5bbd8a52a17521934455ed65 xsa471/xsa471-4.18-01.patch 3ff24a622a8ef97af7dddf480dd8c6c12efb8a2dc74ae8d68836543a6cdb8329 xsa471/xsa471-4.18-02.patch fe69ab8c1d45e0d23f58126b22e9914d2269d416cd802619000dc3933c49129e xsa471/xsa471-4.18-03.patch 60b563119ed38a052ed6e6a261b56db5e7b8b40befacd4904d5ce50b2d75d280 xsa471/xsa471-4.18-04.patch 864643c643cfe1f03d28bb36aadcd5bdd1dc7276c30357ea8be1cd1d20ef6f69 xsa471/xsa471-4.18-05.patch 9d5c58339aea8afbeea0bdf34c34cbeb4178ac0a475a32e688317b9810d0f148 xsa471/xsa471-4.18-06.patch 38347e4d096a880cc6d91f09d60277914ad6aa8a6b588913f211097574714ab0 xsa471/xsa471-4.18-07.patch f0db078f811b5c06170f0016fec84a4bbd958b9f8a8d999567c5680d90141c2c xsa471/xsa471-4.18-08.patch 6d2f9de12d113790bbc74327cf94ae08234bec95d88468767462d3a11d0c40d4 xsa471/xsa471-4.18-09.patch 04f63468fca093f8fb5716c0ecafd1ef0be14dd5a464cddc20e719e0c2979980 xsa471/xsa471-4.18-10.patch 5c6e030d1258ce703ddf27fb48ee7b33ca0dbb09657cb38fc7d5b432d215322e xsa471/xsa471-4.18-11.patch 18b17089aa643ae2d6d9d394137a7fe21bf6b8f9743f2237481b68920f3f8f06 xsa471/xsa471-4.18-12.patch d2c35d0a93e9a98fa04623c024a6e152f4d4d6568e6b603ee0cf7f4e4c9dca82 xsa471/xsa471-4.18-13.patch f5b3f0aa8a59033bad4f221709eb4f6f14c82f75ab229ff53ef52b917d0f4021 xsa471/xsa471-4.18-14.patch dc5c0da74f4a6faba0b2af5539cb38a44525379a2f9cafdff18f71cda5280d42 xsa471/xsa471-4.18-15.patch 296c95410b6dbf55fa092d15e0eee66125a87b012095f84c550eea54078d0490 xsa471/xsa471-4.18-16.patch 04c5587d19749a261ca9edc5212d606f2bf577e890c8f4474c55a9c5fe9605d7 xsa471/xsa471-4.18-17.patch 1b10f901d218bafc35d21366e57be89191c0b7c3bcc9def4da5c79bcf93a2e9d xsa471/xsa471-4.18-18.patch d8b010138f5a2773a07902617c65f5d419bae6445410251c9dc1a777b6bf3378 xsa471/xsa471-4.19-01.patch d72ab177637179cccbd32d2dbedfbb399ff4ba59360391e898e3c5fc069803a9 xsa471/xsa471-4.19-02.patch 365ee7e6fb3da83e6238cd4f9138de2018fddb65c1604bbd968e73ce97451fe9 xsa471/xsa471-4.19-03.patch 690cbd2b4b5ce5a855e75cf44c098ca2e231a272d2ebdc1e68d267c5c4e50db0 xsa471/xsa471-4.19-04.patch 82ac6bbca376e33fe1e03569ed76f559f18066000aec6dc72f1722245f5e9a54 xsa471/xsa471-4.19-05.patch 06c475bbb74d86375c17e183bdf74e1ef145a49af2aa237ce69f6ca8e6f78a7c xsa471/xsa471-4.19-06.patch 03bacbdb4cabb3e9eee079a847fa2eda3ff30c86bbfc5d5b1987ee028774a507 xsa471/xsa471-4.19-07.patch b144cea707793e73d6dcbaa0e0ef268bb3cd389e12c080ec687a64a8a3e6ad61 xsa471/xsa471-4.19-08.patch df35ded3dfe5ca84d459eda720699a35e3e49d4b4d461a3f834d05c30b0bcf59 xsa471/xsa471-4.19-09.patch 6719417c0ead056d83ef003cc3b08bf95a3430560fd8f27357c09ca55b6a3993 xsa471/xsa471-4.19-10.patch b7c6ff2f529c6d6cc656b42142d06e5462e652ade57cc2ff5d90320af1234a27 xsa471/xsa471-4.19-11.patch 4b8a05edf04f5b43b1edcf44412ec4be734b011a7b8d2d739ffe0bdc04abce82 xsa471/xsa471-4.19-12.patch e2bca0cd6f66465fdae9e3d251e67ba8a28a96a05201ac939a599dd95a0b3bc6 xsa471/xsa471-4.19-13.patch 8dc65ba84572a090d1bf8ffeb9b5871d9533e4da324fbcdfb1ab32ed83b10fad xsa471/xsa471-4.19-14.patch 2cb102830a29c6c2a898f8f580a9d554c332d6c31dd1608af0fb22b7340f650b xsa471/xsa471-4.19-15.patch 2a873ae56866b9986183e18ea9b70712a15f6df3af299b2d583cbda40a816f58 xsa471/xsa471-4.19-16.patch 77c7634a7d59056f92de619e034f31e63fd6ac6b26dc6e6af65e80fe3e4e5feb xsa471/xsa471-4.20-01.patch 22db1def1859cc7c742b79fee78c994ac4c9cc63daa3663533f324e93e9ef9e0 xsa471/xsa471-4.20-02.patch fb9a103c606552188c05c14092cce084b52b4df75659f4d8013aa30978708ee8 xsa471/xsa471-4.20-03.patch 6930b94a1997b118692a2e0bd5e32bba2e0269b66de4019e3e870304d695c315 xsa471/xsa471-4.20-04.patch 4a67ef27f84eced8fa9cf3ae42d9f79f74a16659ab004fd79a7ee09fce823cf6 xsa471/xsa471-4.20-05.patch 9c62b492be0f1961d5d8062b7d4ac95b9d120e44ca4bf7e009a499fad9c0fcc3 xsa471/xsa471-4.20-06.patch 511728ef65068fa8bda25c31e3fd578aebc8400597d117f31fd2ba436fbb3776 xsa471/xsa471-4.20-07.patch 9a66742ec752a9f58a02f170a4213a22d32bd487e49bfff799800851ba9650e1 xsa471/xsa471-4.20-08.patch 5a02afd655d29b7eba7ac24a8665d64db39994d84e5125a7511f3e5fb7cafacf xsa471/xsa471-4.20-09.patch f55ba571fa668a1ba9fb318c082e684780cc9b8d3c4e7f33db17bf7cc2afcdb3 xsa471/xsa471-4.20-10.patch 4cc8b54d3cae4864053c4d608061675564cc322c6cd362e33ac59ac4c9371358 xsa471/xsa471-4.20-11.patch b180fec77659ce67d24c076301a3d10486afe0c1f224c30b5af7f22f678e8834 xsa471/xsa471-4.20-12.patch 60155cf04e25ad5c95f744dced34c530e0606150e1ca7617e38a9e3d8933eff3 xsa471/xsa471-4.20-13.patch 3d4eb5835d331581fd5c502ea77a0bf3f35c8e12ff9a95d38d32acfed735fefa xsa471/xsa471-4.20-14.patch bc8590f2187d52a727f2354fda9d006087eaae17c34899bec0257ed7e870e7b6 xsa471/xsa471-4.20-15.patch 91c9100a964b0ecaae5ed019e2c846ea0a8a1e5d734e01853be737bb1799d5dd xsa471/xsa471-04.patch 5fce1dfbf084ccabbba9fcb7a8f758cffc1c8ca93a4f1d2a1c6ad49b4fe9e5da xsa471/xsa471-05.patch $
NOTE CONCERNING OTHER SPECULATIVE ATTACKS
=========================================
The paper describes two further attack:
* CVE-2024-36348: Rogue execution of SMSW
* CVE-2045-36349: Rogue read of MSR_TSC_AUX
which are both examples of Rogue System Register Read (sometimes called Spectre-v3a). No fix is planned, because these registers do not typically contain sensitive information.
-----BEGIN PGP SIGNATURE-----
iQFABAEBCAAqFiEEI+MiLBRfRHX6gGCng/4UyVfoK9kFAmhtJggMHHBncEB4ZW4u b3JnAAoJEIP+FMlX6CvZq+0H/0DAl85Esb0oZTu2VugMbZjxbaROEghLa+CaJPeK 5IJEn3E+gHPil9P88nktO8P3SipbXHYzuZeCKzg3FFPZskv+x294zdLCgndPcB1Q Qfx9wKX8IA+hrgfafUORCjQbAeq+ahxTCG6jwrwaSOSuuU1aAM3RZL+haDlhJ8cH Ib5pdfxZnX5BkJc/Fb/1qrwfW1nHSrvtWJkza79hAyi6d1GnhcSPA9QLfbl4KSSP DBNHaWyAzKWQc3yjvekO+1h0XKnvcpGRMIa3jQOgemceXcRO2Vrp7gSB6BnG+CNh ZODnfZM+2zbbXDscdckujoD/0vywEPhEq4RUv2BaDYKna3I=
=lnmx
-----END PGP SIGNATURE-----
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Jun 2025 17:19:19 +0100
Subject: 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.
xen/arch/x86/cpu-policy.c +37 -32
@@ -418,8 +418,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
@@ -464,6 +465,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 ; }/*
@@ -475,27 +492,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
@@ -539,6 +542,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 ; }/*
@@ -550,21 +570,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)
From: Andrew Cooper <[email protected]>
Date: Tue, 10 Sep 2024 19:55:15 +0100
Subject: x86/cpu-policy: Infrastructure for CPUID leaf 0x80000021.ecx
tools/libs/light/libxl_cpuid.c +1 -0
@@ -342,6 +342,7 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *policy, const char* str)CPUID_ENTRY (0x00000007 ,1 ,CPUID_REG_EDX ),MSR_ENTRY (0x10a ,CPUID_REG_EAX ),MSR_ENTRY (0x10a ,CPUID_REG_EDX ), +CPUID_ENTRY (0x80000021 ,NA ,CPUID_REG_ECX ), #undef MSR_ENTRY#undef CPUID_ENTRY };
tools/misc/xen-cpuid.c +1 -0
@@ -37,6 +37,7 @@ static const struct { { "CPUID 0x00000007:1.edx", "7d1" }, { "MSR_ARCH_CAPS.lo", "m10Al" }, { "MSR_ARCH_CAPS.hi", "m10Ah" }, + { "CPUID 0x80000021.ecx", "e21c" }, };#define COL_ALIGN "24"
xen/arch/x86/cpu-policy.c +0 -1
@@ -330,7 +330,6 @@ static void recalculate_misc(struct cpu_policy *p) p->extd.raw[0x1f ] =EMPTY_LEAF ;/* SEV */ p->extd.raw[0x20 ] =EMPTY_LEAF ;/* Platform QoS */ p->extd.raw[0x21 ].b =0 ; - p->extd.raw[0x21 ].c =0 ; p->extd.raw[0x21 ].d =0 ;break ; }
xen/arch/x86/cpu/common.c +3 -1
@@ -480,7 +480,9 @@ static void generic_identify(struct cpuinfo_x86 *c)if (c->extended_cpuid_level >=0x80000008 ) c->x86_capability[FEATURESET_e8b] =cpuid_ebx (0x80000008 );if (c->extended_cpuid_level >=0x80000021 ) - c->x86_capability[FEATURESET_e21a] =cpuid_eax (0x80000021 ); +cpuid (0x80000021 , + &c->x86_capability[FEATURESET_e21a], &tmp, + &c->x86_capability[FEATURESET_e21c], &tmp);/* Intel-defined flags: level 0x00000007 */ if (c->cpuid_level >=7 ) {
xen/include/public/arch-x86/cpufeatureset.h +2 -0
@@ -395,6 +395,8 @@ XEN_CPUFEATURE(MON_UMON_MITG, 16*32+30) /* MCU_OPT_CTRL.MON_UMON_MITG */ XEN_CPUFEATURE(PB_OPT_CTRL, 16*32+32) /* MSR_PB_OPT_CTRL.IBPB_ALT */XEN_CPUFEATURE (ITS_NO ,16 *32 +62 )/*!A No Indirect Target Selection */ +/* AMD-defined CPU features, CPUID level 0x80000021.ecx, word 18 */ +#endif /* XEN_CPUFEATURE */ /* Clean up from a default include. Close the enum (for C). */
xen/include/xen/lib/x86/cpu-policy.h +6 -1
@@ -22,6 +22,7 @@#define FEATURESET_7d1 15/* 0x00000007:1.edx */ #define FEATURESET_m10Al 16/* 0x0000010a.eax */ #define FEATURESET_m10Ah 17/* 0x0000010a.edx */ +#define FEATURESET_e21c 18/* 0x80000021.ecx */ struct cpuid_leaf {
@@ -328,7 +329,11 @@ struct cpu_policyuint16_t ucode_size;/* Units of 16 bytes */ uint8_t rap_size;/* Units of 8 entries */ uint8_t :8; - uint32_t /* c */:32, /* d */:32; +union { +uint32_t e21c; +struct {DECL_BITFIELD (e21c); }; + }; + uint32_t /* d */:32; }; } extd;
xen/lib/x86/cpuid.c +2 -0
@@ -81,6 +81,7 @@ void x86_cpu_policy_to_featureset( fs[FEATURESET_7d1] = p->feat._7d1; fs[FEATURESET_m10Al] = p->arch_caps.lo; fs[FEATURESET_m10Ah] = p->arch_caps.hi; + fs[FEATURESET_e21c] = p->extd.e21c; } void x86_cpu_featureset_to_policy(
@@ -104,6 +105,7 @@ void x86_cpu_featureset_to_policy( p->feat._7d1 = fs[FEATURESET_7d1]; p->arch_caps.lo = fs[FEATURESET_m10Al]; p->arch_caps.hi = fs[FEATURESET_m10Ah]; + p->extd.e21c = fs[FEATURESET_e21c]; }void x86_cpu_policy_recalc_synth (struct cpu_policy *p)
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Sep 2024 11:28:39 +0100
Subject: x86/ucode: Digests for TSA microcode
AMD are releasing microcode for TSA, so extend the known-provenance list with their hashes. These were produced before the remediation of the microcode signature issues (the entrysign vulnerability), so can be OS-loaded on out-of-date firmware.
Include an off-by-default check for the sorted-ness of patch_digests[]. It's not worth running generally under SELF_TESTS, but is useful when editing the digest list.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
xen/arch/x86/cpu/microcode/amd-patch-digests.c +144 -0
237 lines not on this page · raw message
xen/arch/x86/cpu/microcode/amd.c +15 -0
@@ -528,3 +528,18 @@ void __init ucode_probe_amd(struct microcode_ops *ops) *ops = amd_ucode_ops; } + +#if 0 /* Manual CONFIG_SELF_TESTS */ +static void __init __constructor test_digests_sorted(void) +{ +for (unsigned int i =1 ; i <ARRAY_SIZE (patch_digests); ++i ) + { +if ( patch_digests[i -1 ].patch_id < patch_digests[i].patch_id ) +continue ; + +panic ("patch_digests[] not sorted: %08x >= %08x\n" , + patch_digests[i -1 ].patch_id, + patch_digests[i].patch_id); + } +} +#endif /* CONFIG_SELF_TESTS */
From: Roger Pau Monne <[email protected]>
Date: Thu, 17 Apr 2025 12:35:28 +0200
Subject: x86/intel: workaround several MONITOR/MWAIT errata
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
There are several errata on Intel regarding the usage of the MONITOR/MWAIT instructions, all having in common that stores to the monitored region might not wake up the CPU.
Fix them by forcing the sending of an IPI for the affected models.
The Ice Lake issue has been reproduced internally on XenServer hardware, and the fix does seem to prevent it. The symptom was APs getting stuck in the idle loop immediately after bring up, which in turn prevented the BSP from making progress. This would happen before the watchdog was initialized, and hence the whole system would get stuck.
xen/arch/x86/acpi/cpu_idle.c +6 -0
@@ -453,8 +453,14 @@ void cpuidle_wakeup_mwait(cpumask_t *mask)cpumask_andnot (mask, mask, &target); } +/* Force sending of a wakeup IPI regardless of mwait usage. */ +bool __ro_after_init force_mwait_ipi_wakeup; +bool arch_skip_send_event_check (unsigned int cpu) { +if ( force_mwait_ipi_wakeup ) +return false; +/* * This relies on softirq_pending() and mwait_wakeup() to access data * on the same cache line.
xen/arch/x86/cpu/intel.c +35 -1
@@ -7,6 +7,7 @@#include <asm/intel-family.h> #include <asm/processor.h> #include <asm/msr.h> +#include <asm/mwait.h> #include <asm/uaccess.h> #include <asm/mpspec.h> #include <asm/apic.h>
@@ -363,7 +364,6 @@ static void probe_c3_errata(const struct cpuinfo_x86 *c) INTEL_FAM6_MODEL(0x25), { } }; -#undef INTEL_FAM6_MODEL/* Serialized by the AP bringup code. */ if ( max_cstate > 1 && (c->apicid & (c->x86_num_siblings - 1)) &&
@@ -375,6 +375,38 @@ static void probe_c3_errata(const struct cpuinfo_x86 *c) } } +/* +* APL30: One use of the MONITOR/MWAIT instruction pair is to allow a logical +* processor to wait in a sleep state until a store to the armed address range +* occurs. Due to this erratum, stores to the armed address range may not +* trigger MWAIT to resume execution. +* +* ICX143: Under complex microarchitectural conditions, a monitor that is armed +* with the MWAIT instruction may not be triggered, leading to a processor +* hang. +* +* LNL030: Problem P-cores may not exit power state Core C6 on monitor hit. +* +* Force the sending of an IPI in those cases. +*/ +static void __init probe_mwait_errata (void ) +{ +static const struct x86_cpu_id __initconst models[] = { +INTEL_FAM6_MODEL (INTEL_FAM6_ATOM_GOLDMONT ),/* APL30 */ +INTEL_FAM6_MODEL (INTEL_FAM6_ICELAKE_X ),/* ICX143 */ +INTEL_FAM6_MODEL (INTEL_FAM6_LUNARLAKE_M ),/* LNL030 */ + { } + }; +#undef INTEL_FAM6_MODEL + +if (boot_cpu_has (X86_FEATURE_MONITOR ) &&x86_match_cpu (models) ) + { +printk (XENLOG_WARNING +"Forcing IPI MWAIT wakeup due to CPU erratum\n" ); + force_mwait_ipi_wakeup = true; + } +} +/* * P4 Xeon errata 037 workaround. * Hardware prefetcher may cause stale data to be loaded into the cache.
@@ -401,6 +433,8 @@ static void Intel_errata_workarounds(struct cpuinfo_x86 *c)__set_bit (X86_FEATURE_CLFLUSH_MONITOR , c->x86_capability);probe_c3_errata (c); +if (system_state < SYS_STATE_smp_boot) +probe_mwait_errata (); }
xen/arch/x86/include/asm/mwait.h +3 -0
@@ -13,6 +13,9 @@#define MWAIT_ECX_INTERRUPT_BREAK 0x1 +/* Force sending of a wakeup IPI regardless of mwait usage. */ +extern bool force_mwait_ipi_wakeup; +void mwait_idle_with_hints (unsigned int eax,unsigned int ecx);bool mwait_pc10_supported (void );
From: Andrew Cooper <[email protected]>
Date: Tue, 10 Sep 2024 20:59:37 +0100
Subject: x86/cpufeature: Reposition cpu_has_{lfence_dispatch,nscb}
LFENCE_DISPATCH used to be a synthetic feature, but was given a real CPUID bit by AMD. The define wasn't moved when this was changed.
NSCB has always been a real CPUID bit, and was misplaced when introduced in the synthetic block alongside LFENCE_DISPATCH.
xen/arch/x86/include/asm/cpufeature.h +4 -2
@@ -148,6 +148,10 @@#define cpu_has_avx_vnni boot_cpu_has(X86_FEATURE_AVX_VNNI)#define cpu_has_avx512_bf16 boot_cpu_has(X86_FEATURE_AVX512_BF16) +/* CPUID level 0x80000021.eax */ +#define cpu_has_lfence_dispatch boot_cpu_has(X86_FEATURE_LFENCE_DISPATCH) +#define cpu_has_nscb boot_cpu_has(X86_FEATURE_NSCB) +/* MSR_ARCH_CAPS */ #define cpu_has_rdcl_no boot_cpu_has(X86_FEATURE_RDCL_NO)#define cpu_has_eibrs boot_cpu_has(X86_FEATURE_EIBRS)
@@ -170,8 +174,6 @@#define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON)#define cpu_has_cpuid_faulting boot_cpu_has(X86_FEATURE_CPUID_FAULTING)#define cpu_has_aperfmperf boot_cpu_has(X86_FEATURE_APERFMPERF) -#define cpu_has_lfence_dispatch boot_cpu_has(X86_FEATURE_LFENCE_DISPATCH) -#define cpu_has_nscb boot_cpu_has(X86_FEATURE_NSCB)#define cpu_has_xen_lbr boot_cpu_has(X86_FEATURE_XEN_LBR)#define cpu_has_xen_shstk boot_cpu_has(X86_FEATURE_XEN_SHSTK)#define cpu_has_xen_ibt boot_cpu_has(X86_FEATURE_XEN_IBT)
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Apr 2025 14:59:01 +0100
Subject: x86/idle: Move monitor()/mwait() wrappers into cpu-idle.c
They're not used by any other translation unit, so shouldn't live in asm/processor.h, which is included almost everywhere.
Our new toolchain baseline knows the MONITOR/MWAIT instructions, so use them directly rather than using raw hex.
Change the hint/extention parameters from long to int. They're specified to remain 32bit operands even 64-bit mode.
xen/arch/x86/acpi/cpu_idle.c +17 -4
@@ -59,6 +59,19 @@/*#define DEBUG_PM_CX*/ +static always_inline void monitor( +const void *addr,unsigned int ecx,unsigned int edx) +{ + asmvolatile ("monitor" + ::"a" (addr),"c" (ecx),"d" (edx) ); +} + +static always_inline void mwait(unsigned int eax, unsigned int ecx) +{ + asmvolatile ("mwait" + ::"a" (eax),"c" (ecx) ); +} +#define GET_HW_RES_IN_NS (msr, val) \ do { rdmsrl(msr, val); val = tsc_ticks2ns(val); } while( 0 )#define GET_MC6_RES (val) GET_HW_RES_IN_NS(0x664, val)
@@ -482,7 +495,7 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx)mb (); } -__monitor (monitor_addr,0 ,0 ); +monitor (monitor_addr,0 ,0 );smp_mb ();/*
@@ -496,7 +509,7 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx)cpumask_set_cpu (cpu, &cpuidle_mwait_flags);spec_ctrl_enter_idle (info); -__mwait (eax, ecx); +mwait (eax, ecx);spec_ctrl_exit_idle (info);cpumask_clear_cpu (cpu, &cpuidle_mwait_flags);
@@ -927,9 +940,9 @@ void cf_check acpi_dead_idle(void)*/ mb ();clflush (mwait_ptr); -__monitor (mwait_ptr,0 ,0 ); +monitor (mwait_ptr,0 ,0 );mb (); -__mwait (cx->address,0 ); +mwait (cx->address,0 ); } } else if ( (current_cpu_data.x86_vendor &
xen/arch/x86/include/asm/processor.h +0 -17
@@ -405,23 +405,6 @@ static inline bool_t read_pkru_wd(uint32_t pkru, unsigned int pkey)return (pkru >> (pkey *PKRU_ATTRS +PKRU_WRITE )) &1 ; } -static always_inline void __monitor(const void *eax, unsigned long ecx, -unsigned long edx) -{ -/* "monitor %eax,%ecx,%edx;" */ - asmvolatile ( -".byte 0x0f,0x01,0xc8;" - : :"a" (eax),"c" (ecx),"d" (edx) ); -} - -static always_inline void __mwait(unsigned long eax, unsigned long ecx) -{ -/* "mwait %eax,%ecx;" */ - asmvolatile ( -".byte 0x0f,0x01,0xc9;" - : :"a" (eax),"c" (ecx) ); -} -#define IOBMP_BYTES 8192#define IOBMP_INVALID_OFFSET 0x8000
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Apr 2025 15:55:29 +0100
Subject: x86/idle: Remove MFENCEs for CLFLUSH_MONITOR
Commit 48d32458bcd4 ("x86, idle: add barriers to CLFLUSH workaround") was inherited from Linux and added MFENCEs around the AAI65 errata fix.
The SDM now states:
Executions of the CLFLUSH instruction are ordered with respect to each other and with respect to writes, locked read-modify-write instructions, and fence instructions[1].
with footnote 1 reading:
Earlier versions of this manual specified that executions of the CLFLUSH instruction were ordered only by the MFENCE instruction. All processors implementing the CLFLUSH instruction also order it relative to the other operations enumerated above.
I.e. the MFENCEs came about because of an incorrect statement in the SDM.
The Spec Update (no longer available on Intel's website) simply says "issue a CLFLUSH", with no mention of MFENCEs.
As this erratum is specific to Intel, it's fine to remove the the MFENCEs; AMD CPUs of a similar vintage do sport otherwise-unordered CLFLUSHs.
Move the feature bit into the BUG range (rather than FEATURE), and move the workaround into monitor() itself.
The erratum check itself must use setup_force_cpu_cap(). It needs activating if any CPU needs it, not if all of them need it.
xen/arch/x86/acpi/cpu_idle.c +3 -19
@@ -62,6 +62,9 @@ static always_inline void monitor(const void *addr,unsigned int ecx,unsigned int edx) { + alternative_input("", "clflush (%[addr])", X86_BUG_CLFLUSH_MONITOR, + [addr] "a" (addr)); + asmvolatile ("monitor" ::"a" (addr),"c" (ecx),"d" (edx) ); }
@@ -488,13 +491,6 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx)s_time_t expires =per_cpu (timer_deadline, cpu);const void *monitor_addr = &mwait_wakeup (cpu); -if (boot_cpu_has (X86_FEATURE_CLFLUSH_MONITOR ) ) - { -mb (); -clflush (monitor_addr); -mb (); - } -monitor (monitor_addr,0 ,0 );smp_mb ();
@@ -929,19 +925,7 @@ void cf_check acpi_dead_idle(void)while (1 ) { -/* -* 1. The CLFLUSH is a workaround for erratum AAI65 for -* the Xeon 7400 series. -* 2. The WBINVD is insufficient due to the spurious-wakeup -* case where we return around the loop. -* 3. Unlike wbinvd, clflush is a light weight but not serializing -* instruction, hence memory fence is necessary to make sure all -* load/store visible before flush cache line. -*/ -mb (); -clflush (mwait_ptr);monitor (mwait_ptr,0 ,0 ); -mb ();mwait (cx->address,0 ); } }
xen/arch/x86/cpu/intel.c +2 -1
@@ -413,6 +413,7 @@ static void __init probe_mwait_errata(void)* * Xeon 7400 erratum AAI65 (and further newer Xeons) * MONITOR/MWAIT may have excessive false wakeups +* https://web.archive.org/web/20090219054841/http://download.intel.com/design/xeon/specupdt/32033601.pdf */ static void Intel_errata_workarounds (struct cpuinfo_x86 *c) {
@@ -430,7 +431,7 @@ static void Intel_errata_workarounds(struct cpuinfo_x86 *c)if (c->x86 ==6 && cpu_has_clflush && (c->x86_model ==29 || c->x86_model ==46 || c->x86_model ==47 )) -__set_bit (X86_FEATURE_CLFLUSH_MONITOR , c->x86_capability); +setup_force_cpu_cap (X86_BUG_CLFLUSH_MONITOR );probe_c3_errata (c);if (system_state < SYS_STATE_smp_boot)
xen/arch/x86/include/asm/cpufeatures.h +2 -1
@@ -19,7 +19,7 @@ XEN_CPUFEATURE(ARCH_PERFMON, X86_SYNTH( 3)) /* Intel Architectural PerfMon XEN_CPUFEATURE(TSC_RELIABLE, X86_SYNTH( 4)) /* TSC is known to be reliable */ XEN_CPUFEATURE(XTOPOLOGY, X86_SYNTH( 5)) /* cpu topology enum extensions */XEN_CPUFEATURE (CPUID_FAULTING ,X86_SYNTH (6 ))/* cpuid faulting */ -XEN_CPUFEATURE(CLFLUSH_MONITOR, X86_SYNTH( 7)) /* clflush reqd with monitor */ +/* Bit 7 unused */ XEN_CPUFEATURE(APERFMPERF, X86_SYNTH( 8)) /* APERFMPERF */ XEN_CPUFEATURE(MFENCE_RDTSC, X86_SYNTH( 9)) /* MFENCE synchronizes RDTSC */XEN_CPUFEATURE (XEN_SMEP ,X86_SYNTH (10 ))/* SMEP gets used by Xen itself */
@@ -52,6 +52,7 @@ XEN_CPUFEATURE(USE_VMCALL, X86_SYNTH(30)) /* Use VMCALL instead of VMMCAL#define X86_BUG_NULL_SEG X86_BUG( 1)/* NULL-ing a selector preserves the base and limit. */ #define X86_BUG_CLFLUSH_MFENCE X86_BUG( 2)/* MFENCE needed to serialise CLFLUSH */ #define X86_BUG_IBPB_NO_RET X86_BUG( 3)/* IBPB doesn't flush the RSB/RAS */ +#define X86_BUG_CLFLUSH_MONITOR X86_BUG( 4)/* MONITOR requires CLFLUSH */ #define X86_SPEC_NO_LFENCE_ENTRY_PV X86_BUG(16)/* (No) safety LFENCE for SPEC_CTRL_ENTRY_PV. */ #define X86_SPEC_NO_LFENCE_ENTRY_INTR X86_BUG(17)/* (No) safety LFENCE for SPEC_CTRL_ENTRY_INTR. */
From: Andrew Cooper <[email protected]>
Date: Tue, 24 Jun 2025 15:20:52 +0100
Subject: Revert part of "x86/mwait-idle: disable IBRS during long idle"
Most of the patch (handling of CPUIDLE_FLAG_IBRS) is fine, but the adjustements to mwait_idle() are not; spec_ctrl_enter_idle() does more than just alter MSR_SPEC_CTRL.IBRS.
The only reason this doesn't need an XSA is because the unconditional spec_ctrl_{enter,exit}_idle() in mwait_idle_with_hints() were left unaltered, and thus the MWAIT remained properly protected.
There (would have been) two problems. In the ibrs_disable (== deep C) case:
* On entry, VERW and RSB-stuffing are architecturally skipped.
* On exit, there's a branch crossing the WRMSR which reinstates the speculative safety for indirect branches.
All this change did was double up the expensive operations in the deep C case, and fail to optimise the intended case.
I have an idea of how to plumb this more nicely, but it requires larger changes to legacy IBRS handling to not make spec_ctrl_enter_idle() vulnerable in other ways. In the short term, simply take out the perf hit.
xen/arch/x86/cpu/mwait-idle.c +2 -10
@@ -902,7 +902,6 @@ static const struct cpuidle_state snr_cstates[] = { static void cf_check mwait_idle(void) {unsigned int cpu =smp_processor_id (); -struct cpu_info *info =get_cpu_info ();struct acpi_processor_power *power = processor_powers[cpu];struct acpi_processor_cx *cx =NULL ;unsigned int next_state;
@@ -929,6 +928,8 @@ static void cf_check mwait_idle(void)pm_idle_save (); else { +struct cpu_info *info =get_cpu_info (); +spec_ctrl_enter_idle (info);safe_halt ();spec_ctrl_exit_idle (info);
@@ -955,11 +956,6 @@ static void cf_check mwait_idle(void)if ((cx->type >=3 ) &&errata_c6_workaround ()) cx = power->safe_state; -if (cx->ibrs_disable) { -ASSERT (!cx->irq_enable_early); -spec_ctrl_enter_idle (info); - } -#if 0 /* XXX Can we/do we need to do something similar on Xen? */ /* * leave_mm() to avoid costly and often unnecessary wakeups
@@ -991,10 +987,6 @@ static void cf_check mwait_idle(void)/* Now back in C0. */ update_idle_stats (power, cx, before, after); - -if (cx->ibrs_disable) -spec_ctrl_exit_idle (info); -local_irq_enable (); TRACE_6D(TRC_PM_IDLE_EXIT, cx->type, after,
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Jun 2025 14:46:01 +0100
Subject: x86/cpu-policy: Simplify logic in
guest_common_default_feature_adjustments()
For features which are unconditionally set in the max policies, making the default policy to match the host can be done with a conditional clear.
This is simpler than the unconditional clear, conditional set currently performed.
xen/arch/x86/cpu-policy.c +10 -15
@@ -511,17 +511,14 @@ static void __init guest_common_default_feature_adjustments(uint32_t *fs)* reasons, so reset the default policy back to the host values in * case we're unaffected. */ -__clear_bit (X86_FEATURE_MD_CLEAR , fs); -if ( cpu_has_md_clear ) -__set_bit (X86_FEATURE_MD_CLEAR , fs); +if ( !cpu_has_md_clear ) +__clear_bit (X86_FEATURE_MD_CLEAR , fs); -__clear_bit (X86_FEATURE_FB_CLEAR , fs); -if ( cpu_has_fb_clear ) -__set_bit (X86_FEATURE_FB_CLEAR , fs); +if ( !cpu_has_fb_clear ) +__clear_bit (X86_FEATURE_FB_CLEAR , fs); -__clear_bit (X86_FEATURE_RFDS_CLEAR , fs); -if ( cpu_has_rfds_clear ) -__set_bit (X86_FEATURE_RFDS_CLEAR , fs); +if ( !cpu_has_rfds_clear ) +__clear_bit (X86_FEATURE_RFDS_CLEAR , fs);/* * The Gather Data Sampling microcode mitigation (August 2023) has an
@@ -541,13 +538,11 @@ static void __init guest_common_default_feature_adjustments(uint32_t *fs)* Topology information is at the toolstack's discretion so these are * unconditionally set in max, but pick a default which matches the host. */ -__clear_bit (X86_FEATURE_HTT , fs); -if ( cpu_has_htt ) -__set_bit (X86_FEATURE_HTT , fs); +if ( !cpu_has_htt ) +__clear_bit (X86_FEATURE_HTT , fs); -__clear_bit (X86_FEATURE_CMP_LEGACY , fs); -if ( cpu_has_cmp_legacy ) -__set_bit (X86_FEATURE_CMP_LEGACY , fs); +if ( !cpu_has_cmp_legacy ) +__clear_bit (X86_FEATURE_CMP_LEGACY , fs);/* * On certain hardware, speculative or errata workarounds can result in
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 11:33:41 +0100
Subject: x86/cpu-policy: Fix handling of leaf 0x80000021
When support was originally introduced, ebx, ecx and edx were reserved and should have been zeroed in recalculate_misc() to avoid leaking into guests.
Since then, fields have been added into ebx. Guests can't load microcode, so shouldn't see ucode_size, and while in principle we do want to support larger RAP sizes in guests, virtualising this for guests depends on AMD procuding any official documentation for ERAPS, which is long overdue and with no ETA.
This patch will cause a difference in guests on Zen5 CPUs, but as the main ERAPS feature is hidden, guests should be ignoring the rap_size field too.
xen/arch/x86/cpu-policy.c +3 -0
@@ -340,6 +340,9 @@ static void recalculate_misc(struct cpu_policy *p) p->extd.raw[0x1e ] =EMPTY_LEAF ;/* TopoExt APIC ID/Core/Node */ p->extd.raw[0x1f ] =EMPTY_LEAF ;/* SEV */ p->extd.raw[0x20 ] =EMPTY_LEAF ;/* Platform QoS */ + p->extd.raw[0x21 ].b =0 ; + p->extd.raw[0x21 ].c =0 ; + p->extd.raw[0x21 ].d =0 ;break ; } }
xen/include/xen/lib/x86/cpu-policy.h +4 -1
@@ -324,7 +324,10 @@ struct cpu_policyuint32_t e21a;struct {DECL_BITFIELD (e21a); }; }; - uint32_t /* b */:32, /* c */:32, /* d */:32; +uint16_t ucode_size;/* Units of 16 bytes */ +uint8_t rap_size;/* Units of 8 entries */ + uint8_t :8; + uint32_t /* c */:32, /* d */:32; }; } extd;
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 15:51:53 +0100
Subject: x86/idle: Remove broken MWAIT implementation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
cpuidle_wakeup_mwait() is a TOCTOU race. The cpumask_and() sampling cpuidle_mwait_flags can take a arbitrary period of time, and there's no guarantee that the target CPUs are still in MWAIT when writing into mwait_wakeup(cpu).
The consequence of the race is that we'll fail to IPI certain targets. Also, there's no guarantee that mwait_idle_with_hints() will raise a TIMER_SOFTIRQ on it's way out.
The fundamental bug is that the "in_mwait" variable needs to be in the monitored line, and not in a separate cpuidle_mwait_flags variable, in order to do this in a race-free way.
Arranging to fix this while keeping the old implementation is prohibitive, so strip the current one out in order to implement the new one cleanly. In the interim, this causes IPIs to be used unconditionally which is safe albeit suboptimal.
xen/arch/x86/acpi/cpu_idle.c +5 -43
81 lines not on this page · raw message
xen/arch/x86/hpet.c +0 -2
@@ -187,8 +187,6 @@ static void evt_do_broadcast(cpumask_t *mask)if (__cpumask_test_and_clear_cpu (cpu, mask) )raise_softirq (TIMER_SOFTIRQ ); -cpuidle_wakeup_mwait (mask); -if ( !cpumask_empty (mask) )cpumask_raise_softirq (mask,TIMER_SOFTIRQ ); }
xen/arch/x86/include/asm/hardirq.h +4 -5
@@ -5,11 +5,10 @@#include <xen/types.h> typedef struct { -unsigned int __softirq_pending; -unsigned int __local_irq_count; -unsigned int nmi_count; -unsigned int mce_count; -bool_t __mwait_wakeup; +unsigned int __softirq_pending; +unsigned int __local_irq_count; +unsigned int nmi_count; +unsigned int mce_count; } __cacheline_aligned irq_cpustat_t;#include <xen/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
xen/include/xen/cpuidle.h +0 -2
@@ -92,8 +92,6 @@ extern struct cpuidle_governor *cpuidle_current_governor;bool cpuidle_using_deep_cstate (void );void cpuidle_disable_deep_cstate (void ); -extern void cpuidle_wakeup_mwait (cpumask_t *mask); -#define CPUIDLE_DRIVER_STATE_START 1extern void menu_get_trace_data (u32 *expected,u32 *pred);
xen/include/xen/irq_cpustat.h +0 -1
@@ -24,6 +24,5 @@ extern irq_cpustat_t irq_stat[];/* arch independent irq_stat fields */ #define softirq_pending (cpu) __IRQ_STAT((cpu), __softirq_pending)#define local_irq_count (cpu) __IRQ_STAT((cpu), __local_irq_count) -#define mwait_wakeup (cpu) __IRQ_STAT((cpu), __mwait_wakeup)#endif /* __irq_cpustat_h */
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 18:13:27 +0100
Subject: x86/idle: Drop incorrect smp_mb() in mwait_idle_with_hints()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
With the recent simplifications, it becomes obvious that smp_mb() isn't the right barrier. Strictly speaking, MONITOR is ordered as a load, but smp_rmb() isn't correct either, as this only pertains to local ordering. All we need is a compiler barrier().
Merge the barier() into the monitor() itself, along with an explantion.
No functional change.
xen/arch/x86/acpi/cpu_idle.c +5 -2
@@ -65,8 +65,12 @@ static always_inline void monitor( alternative_input("", "clflush (%[addr])", X86_BUG_CLFLUSH_MONITOR, [addr] "a" (addr)); +/* +* The memory clobber is a compiler barrier. Subseqeunt reads from the +* monitored cacheline must not be reordered over MONITOR. +*/ asmvolatile ("monitor" - ::"a" (addr),"c" (ecx),"d" (edx) ); + ::"a" (addr),"c" (ecx),"d" (edx) :"memory" ); } static always_inline void mwait(unsigned int eax, unsigned int ecx)
@@ -465,7 +469,6 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx)const unsigned int *this_softirq_pending = &softirq_pending (cpu);monitor (this_softirq_pending,0 ,0 ); -smp_mb ();if ( !*this_softirq_pending ) {
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 21:40:51 +0100
Subject: x86/idle: Convert force_mwait_ipi_wakeup to X86_BUG_MONITOR
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
We're going to want alternative-patch based on it.
No functional change.
xen/arch/x86/acpi/cpu_idle.c +0 -6
@@ -452,14 +452,8 @@ static int __init cf_check cpu_idle_key_init(void) }__initcall (cpu_idle_key_init); -/* Force sending of a wakeup IPI regardless of mwait usage. */ -bool __ro_after_init force_mwait_ipi_wakeup; -bool arch_skip_send_event_check (unsigned int cpu) { -if ( force_mwait_ipi_wakeup ) -return false; -return false; }
xen/arch/x86/cpu/intel.c +1 -1
@@ -403,7 +403,7 @@ static void __init probe_mwait_errata(void) {printk (XENLOG_WARNING "Forcing IPI MWAIT wakeup due to CPU erratum\n" ); - force_mwait_ipi_wakeup = true; +setup_force_cpu_cap (X86_BUG_MONITOR ); } }
xen/arch/x86/include/asm/cpufeatures.h +1 -0
@@ -53,6 +53,7 @@ XEN_CPUFEATURE(USE_VMCALL, X86_SYNTH(30)) /* Use VMCALL instead of VMMCAL#define X86_BUG_CLFLUSH_MFENCE X86_BUG( 2)/* MFENCE needed to serialise CLFLUSH */ #define X86_BUG_IBPB_NO_RET X86_BUG( 3)/* IBPB doesn't flush the RSB/RAS */ #define X86_BUG_CLFLUSH_MONITOR X86_BUG( 4)/* MONITOR requires CLFLUSH */ +#define X86_BUG_MONITOR X86_BUG( 5)/* MONITOR doesn't always notice writes (force IPIs) */ #define X86_SPEC_NO_LFENCE_ENTRY_PV X86_BUG(16)/* (No) safety LFENCE for SPEC_CTRL_ENTRY_PV. */ #define X86_SPEC_NO_LFENCE_ENTRY_INTR X86_BUG(17)/* (No) safety LFENCE for SPEC_CTRL_ENTRY_INTR. */
xen/arch/x86/include/asm/mwait.h +0 -3
@@ -13,9 +13,6 @@#define MWAIT_ECX_INTERRUPT_BREAK 0x1 -/* Force sending of a wakeup IPI regardless of mwait usage. */ -extern bool force_mwait_ipi_wakeup; -void mwait_idle_with_hints (unsigned int eax,unsigned int ecx);bool mwait_pc10_supported (void );
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 21:04:17 +0100
Subject: xen/softirq: Rework arch_skip_send_event_check() into
arch_set_softirq()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
x86 is the only architecture wanting an optimisation here, but the test_and_set_bit() is a store into the monitored line (i.e. will wake up the target) and, prior to the removal of the broken IPI-elision algorithm, was racy, causing unnecessary IPIs to be sent.
To do this in a race-free way, the store to the monited line needs to also sample the status of the target in one atomic action. Implement a new arch helper with different semantics; to make the softirq pending and decide about IPIs together. For now, implement the default helper. It will be overridden by x86 in a subsequent change.
No functional change.
xen/arch/x86/acpi/cpu_idle.c +0 -5
@@ -452,11 +452,6 @@ static int __init cf_check cpu_idle_key_init(void) }__initcall (cpu_idle_key_init); -bool arch_skip_send_event_check (unsigned int cpu) -{ -return false; -} -void mwait_idle_with_hints (unsigned int eax,unsigned int ecx) {unsigned int cpu =smp_processor_id ();
xen/arch/x86/include/asm/softirq.h +0 -2
@@ -9,6 +9,4 @@#define HVM_DPCI_SOFTIRQ (NR_COMMON_SOFTIRQS + 4)#define NR_ARCH_SOFTIRQS 5 -bool arch_skip_send_event_check (unsigned int cpu); -#endif /* __ASM_SOFTIRQ_H__ */
xen/common/softirq.c +2 -6
@@ -94,9 +94,7 @@ void cpumask_raise_softirq(const cpumask_t *mask, unsigned int nr) raise_mask = &per_cpu (batch_mask, this_cpu);for_each_cpu (cpu, mask) -if ( !test_and_set_bit (nr, &softirq_pending (cpu)) && - cpu != this_cpu && - !arch_skip_send_event_check (cpu) ) +if ( !arch_set_softirq (nr, cpu) && cpu != this_cpu )__cpumask_set_cpu (cpu, raise_mask);if ( raise_mask == &send_mask )
@@ -107,9 +105,7 @@ void cpu_raise_softirq(unsigned int cpu, unsigned int nr) {unsigned int this_cpu =smp_processor_id (); -if (test_and_set_bit (nr, &softirq_pending (cpu)) - || (cpu == this_cpu) - ||arch_skip_send_event_check (cpu) ) +if (arch_set_softirq (nr, cpu) || cpu == this_cpu )return ;if ( !per_cpu (batching, this_cpu) ||in_irq () )
xen/include/xen/softirq.h +16 -0
@@ -21,6 +21,22 @@ enum {#define NR_SOFTIRQS (NR_COMMON_SOFTIRQS + NR_ARCH_SOFTIRQS) +/* +* Ensure softirq @nr is pending on @cpu. Return true if an IPI can be +* skipped, false if the IPI cannot be skipped. +*/ +#ifndef arch_set_softirq +static always_inline bool arch_set_softirq(unsigned int nr, unsigned int cpu) +{ +/* +* Try to set the softirq pending. If we set the bit (i.e. the old bit +* was 0), we're responsible to send the IPI. If the softirq was already +* pending (i.e. the old bit was 1), no IPI is needed. +*/ +return test_and_set_bit (nr, &softirq_pending (cpu)); +} +#endif +typedef void (*softirq_handler )(void );void do_softirq (void );
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 21:26:24 +0100
Subject: x86/idle: Implement a new MWAIT IPI-elision algorithm
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
In order elide IPIs, we must be able to identify whether a target CPU is in MWAIT at the point it is woken up. i.e. the store to wake it up must also identify the state.
Create a new in_mwait variable beside __softirq_pending, so we can use a CMPXCHG to set the softirq while also observing the status safely. Implement an x86 version of arch_pend_softirq() which does this.
In mwait_idle_with_hints(), advertise in_mwait, with an explanation of precisely what it means. X86_BUG_MONITOR can be accounted for simply by not advertising in_mwait.
xen/arch/x86/acpi/cpu_idle.c +19 -1
@@ -455,7 +455,21 @@ __initcall(cpu_idle_key_init);void mwait_idle_with_hints (unsigned int eax,unsigned int ecx) {unsigned int cpu =smp_processor_id (); -const unsigned int *this_softirq_pending = &softirq_pending (cpu); +irq_cpustat_t *stat = &irq_stat[cpu]; +const unsigned int *this_softirq_pending = &stat->__softirq_pending; + +/* +* By setting in_mwait, we promise to other CPUs that we'll notice changes +* to __softirq_pending without being sent an IPI. We achieve this by +* either not going to sleep, or by having hardware notice on our behalf. +* +* Some errata exist where MONITOR doesn't work properly, and the +* workaround is to force the use of an IPI. Cause this to happen by +* simply not advertising ourselves as being in_mwait. +*/ +alternative_io ("movb $1, %[in_mwait]" , + "", X86_BUG_MONITOR, + [in_mwait] "=m" (stat->in_mwait));monitor (this_softirq_pending,0 ,0 );
@@ -467,6 +481,10 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx)mwait (eax, ecx);spec_ctrl_exit_idle (info); } + +alternative_io ("movb $0, %[in_mwait]" , + "", X86_BUG_MONITOR, + [in_mwait] "=m" (stat->in_mwait)); }static void acpi_processor_ffh_cstate_enter (struct acpi_processor_cx *cx)
xen/arch/x86/include/asm/hardirq.h +13 -1
@@ -5,7 +5,19 @@#include <xen/types.h> typedef struct { - unsigned int __softirq_pending; + /* + * The layout is important. Any CPU can set bits in __softirq_pending, + * but in_mwait is a status bit owned by the CPU. softirq_mwait_raw must + * cover both, and must be in a single cacheline. + */ + union { + struct { + unsigned int __softirq_pending; + bool in_mwait; + }; + uint64_t softirq_mwait_raw; + }; + unsigned int __local_irq_count; unsigned int nmi_count; unsigned int mce_count;
xen/arch/x86/include/asm/softirq.h +48 -0
58 lines not on this page · raw message
From: Andrew Cooper <[email protected]>
Date: Wed, 2 Jul 2025 14:51:38 +0100
Subject: x86/idle: Fix buggy "x86/mwait-idle: enable interrupts before C1 on
Xeons"
The check of this_softirq_pending must be performed with irqs disabled, but this property was broken by an attempt to optimise entry/exit latency.
Commit c227233ad64c in Linux (which we copied into Xen) was fixed up by edc8fc01f608 in Linux, which we have so far missed.
Going to sleep without waking on interrupts is nonsensical outside of play_dead(), so overload this to select between two possible MWAITs, the second using the STI shadow to cover MWAIT for exactly the same reason as we do in safe_halt().
xen/arch/x86/acpi/cpu_idle.c +15 -1
@@ -79,6 +79,13 @@ static always_inline void mwait(unsigned int eax, unsigned int ecx) :: "a" (eax), "c" (ecx) ); } +static always_inline void sti_mwait_cli(unsigned int eax, unsigned int ecx) +{ +/* STI shadow covers MWAIT. */ + asmvolatile ("sti; mwait; cli" + ::"a" (eax),"c" (ecx) ); +} +#define GET_HW_RES_IN_NS (msr, val) \ do { rdmsrl(msr, val); val = tsc_ticks2ns(val); } while( 0 )#define GET_MC6_RES (val) GET_HW_RES_IN_NS(0x664, val)
@@ -473,12 +480,19 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx)monitor (this_softirq_pending,0 ,0 ); +ASSERT (!local_irq_is_enabled ()); +if ( !*this_softirq_pending ) {struct cpu_info *info =get_cpu_info ();spec_ctrl_enter_idle (info); -mwait (eax, ecx); + +if ( ecx &MWAIT_ECX_INTERRUPT_BREAK ) +mwait (eax, ecx); +else +sti_mwait_cli (eax, ecx); +spec_ctrl_exit_idle (info); }
xen/arch/x86/cpu/mwait-idle.c +2 -6
@@ -973,12 +973,8 @@ static void cf_check mwait_idle(void)update_last_cx_stat (power, cx, before); -if (cx->irq_enable_early) -local_irq_enable (); - -mwait_idle_with_hints (cx->address,MWAIT_ECX_INTERRUPT_BREAK ); - -local_irq_disable (); +mwait_idle_with_hints (cx->address, + cx->irq_enable_early ?0 :MWAIT_ECX_INTERRUPT_BREAK ); after =alternative_call (cpuidle_get_tick);
From: Andrew Cooper <[email protected]>
Date: Fri, 4 Jul 2025 17:53:15 +0100
Subject: x86/xen-cpuid: Fix backports of new features
Xen 4.18 doesn't automatically generate feature names like Xen 4.19 does, and these hunks were missed on prior security fixes.
tools/misc/xen-cpuid.c +4 -5
@@ -199,6 +199,7 @@ static const char *const str_e21a[32] = /* 26 */ [27] = "sbpb", [28] = "ibpb-brtype", [29] = "srso-no", + [30] = "srso-us-no", [31] = "srso-msr-fix", }; static const char *const str_7b1[32] =
@@ -222,7 +223,7 @@ static const char *const str_7d2[32] = [ 4] = "bhi-ctrl", [ 5] = "mcdt-no", }; -static const char *const str_m10Al[32 ] = +static const char *const str_m10Al[64 ] = { [0 ] ="rdcl-no" , [1 ] ="eibrs" , [2 ] ="rsba" , [3 ] ="skip-l1dfl" ,
@@ -239,10 +240,8 @@ static const char *const str_m10Al[32] = [24] = "pbrsb-no", [25] = "gds-ctrl", [26] = "gds-no", [27] = "rfds-no", [28] = "rfds-clear", -}; -static const char *const str_m10Ah[32 ] = -{ + [62] = "its-no", }; static const struct {
@@ -268,7 +267,7 @@ static const struct { { "CPUID 0x00000007:1.ecx", "7c1", str_7c1 }, { "CPUID 0x00000007:1.edx", "7d1", str_7d1 }, { "MSR_ARCH_CAPS.lo", "m10Al", str_m10Al }, - { "MSR_ARCH_CAPS.hi", "m10Ah", str_m10Ah }, + { "MSR_ARCH_CAPS.hi", "m10Ah", str_m10Al + 32 }, };#define COL_ALIGN "24"
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Jun 2025 17:19:19 +0100
Subject: 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.
xen/arch/x86/cpu-policy.c +37 -32
105 lines not on this page · raw message
From: Andrew Cooper <[email protected]>
Date: Tue, 10 Sep 2024 19:55:15 +0100
Subject: x86/cpu-policy: Infrastructure for CPUID leaf 0x80000021.ecx
tools/libs/light/libxl_cpuid.c +1 -0
@@ -344,6 +344,7 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *policy, const char* str)CPUID_ENTRY (0x00000007 ,1 ,CPUID_REG_EDX ),MSR_ENTRY (0x10a ,CPUID_REG_EAX ),MSR_ENTRY (0x10a ,CPUID_REG_EDX ), +CPUID_ENTRY (0x80000021 ,NA ,CPUID_REG_ECX ), #undef MSR_ENTRY#undef CPUID_ENTRY };
tools/misc/xen-cpuid.c +5 -0
@@ -244,6 +244,10 @@ static const char *const str_m10Al[64] = [62] = "its-no", }; +static const char *const str_e21c[32 ] = +{ +}; + static const struct { const char *name; const char *abbr;
@@ -268,6 +272,7 @@ static const struct { { "CPUID 0x00000007:1.edx", "7d1", str_7d1 }, { "MSR_ARCH_CAPS.lo", "m10Al", str_m10Al }, { "MSR_ARCH_CAPS.hi", "m10Ah", str_m10Al + 32 }, + { "CPUID 0x80000021.ecx", "e21c", str_e21c }, };#define COL_ALIGN "24"
xen/arch/x86/cpu-policy.c +0 -1
@@ -341,7 +341,6 @@ static void recalculate_misc(struct cpu_policy *p) p->extd.raw[0x1f ] =EMPTY_LEAF ;/* SEV */ p->extd.raw[0x20 ] =EMPTY_LEAF ;/* Platform QoS */ p->extd.raw[0x21 ].b =0 ; - p->extd.raw[0x21 ].c =0 ; p->extd.raw[0x21 ].d =0 ;break ; }
xen/arch/x86/cpu/common.c +3 -1
@@ -469,7 +469,9 @@ static void generic_identify(struct cpuinfo_x86 *c)if (c->extended_cpuid_level >=0x80000008 ) c->x86_capability[FEATURESET_e8b] =cpuid_ebx (0x80000008 );if (c->extended_cpuid_level >=0x80000021 ) - c->x86_capability[FEATURESET_e21a] =cpuid_eax (0x80000021 ); +cpuid (0x80000021 , + &c->x86_capability[FEATURESET_e21a], &tmp, + &c->x86_capability[FEATURESET_e21c], &tmp);/* Intel-defined flags: level 0x00000007 */ if (c->cpuid_level >=7 ) {
xen/include/public/arch-x86/cpufeatureset.h +2 -0
@@ -337,6 +337,8 @@ XEN_CPUFEATURE(RFDS_CLEAR, 16*32+28) /*!A Register File(s) cleared by VE/* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.edx, word 17 (express in terms of word 16) */ XEN_CPUFEATURE (ITS_NO ,16 *32 +62 )/*!A No Indirect Target Selection */ +/* AMD-defined CPU features, CPUID level 0x80000021.ecx, word 18 */ +#endif /* XEN_CPUFEATURE */ /* Clean up from a default include. Close the enum (for C). */
xen/include/xen/lib/x86/cpu-policy.h +6 -1
@@ -22,6 +22,7 @@#define FEATURESET_7d1 15/* 0x00000007:1.edx */ #define FEATURESET_m10Al 16/* 0x0000010a.eax */ #define FEATURESET_m10Ah 17/* 0x0000010a.edx */ +#define FEATURESET_e21c 18/* 0x80000021.ecx */ struct cpuid_leaf {
@@ -327,7 +328,11 @@ struct cpu_policyuint16_t ucode_size;/* Units of 16 bytes */ uint8_t rap_size;/* Units of 8 entries */ uint8_t :8; - uint32_t /* c */:32, /* d */:32; +union { +uint32_t e21c; +struct {DECL_BITFIELD (e21c); }; + }; + uint32_t /* d */:32; }; } extd;
xen/lib/x86/cpuid.c +2 -0
@@ -81,6 +81,7 @@ void x86_cpu_policy_to_featureset( fs[FEATURESET_7d1] = p->feat._7d1; fs[FEATURESET_m10Al] = p->arch_caps.lo; fs[FEATURESET_m10Ah] = p->arch_caps.hi; + fs[FEATURESET_e21c] = p->extd.e21c; } void x86_cpu_featureset_to_policy(
@@ -104,6 +105,7 @@ void x86_cpu_featureset_to_policy( p->feat._7d1 = fs[FEATURESET_7d1]; p->arch_caps.lo = fs[FEATURESET_m10Al]; p->arch_caps.hi = fs[FEATURESET_m10Ah]; + p->extd.e21c = fs[FEATURESET_e21c]; }void x86_cpu_policy_recalc_synth (struct cpu_policy *p)
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Sep 2024 11:28:39 +0100
Subject: x86/ucode: Digests for TSA microcode
AMD are releasing microcode for TSA, so extend the known-provenance list with their hashes. These were produced before the remediation of the microcode signature issues (the entrysign vulnerability), so can be OS-loaded on out-of-date firmware.
Include an off-by-default check for the sorted-ness of patch_digests[]. It's not worth running generally under SELF_TESTS, but is useful when editing the digest list.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
xen/arch/x86/cpu/microcode/amd-patch-digests.c +144 -0
237 lines not on this page · raw message
From: Andrew Cooper <[email protected]>
Date: Wed, 2 Apr 2025 03:18:59 +0100
Subject: x86/idle: Rearrange VERW and MONITOR in mwait_idle_with_hints()
In order to mitigate TSA, Xen will need to issue VERW before going idle.
On AMD CPUs, the VERW scrubbing side effects cancel an active MONITOR, causing the MWAIT to exit without entering an idle state. Therefore the VERW must be ahead of MONITOR.
Split spec_ctrl_enter_idle() in two and allow the VERW aspect to be handled separately. While adjusting, update a stale comment concerning MSBDS; more issues have been mitigated using VERW since it was written.
By moving VERW earlier, it is ahead of the determination of whether to go idle. We can't move the check on softirq_pending (for correctness reasons), but we can duplicate it earlier as a best effort attempt to skip the speculative overhead.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
xen/arch/x86/acpi/cpu_idle.c +16 -3
@@ -462,9 +462,18 @@ __initcall(cpu_idle_key_init);void mwait_idle_with_hints (unsigned int eax,unsigned int ecx) {unsigned int cpu =smp_processor_id (); +struct cpu_info *info =get_cpu_info ();irq_cpustat_t *stat = &irq_stat[cpu];const unsigned int *this_softirq_pending = &stat->__softirq_pending; +/* +* Heuristic: if we're definitely not going to idle, bail early as the +* speculative safety can be expensive. This is a performance +* consideration not a correctness issue. +*/ +if ( *this_softirq_pending ) +return ; +/* * By setting in_mwait, we promise to other CPUs that we'll notice changes * to __softirq_pending without being sent an IPI. We achieve this by
@@ -478,15 +487,19 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx) "", X86_BUG_MONITOR, [in_mwait] "=m" (stat->in_mwait)); +/* +* On AMD systems, side effects from VERW cancel MONITOR, causing MWAIT to +* wake up immediately. Therefore, VERW must come ahead of MONITOR. +*/ +__spec_ctrl_enter_idle_verw (info); +monitor (this_softirq_pending,0 ,0 );ASSERT (!local_irq_is_enabled ());if ( !*this_softirq_pending ) { -struct cpu_info *info =get_cpu_info (); - -spec_ctrl_enter_idle (info); +__spec_ctrl_enter_idle (info, false/* VERW handled above */ );if ( ecx &MWAIT_ECX_INTERRUPT_BREAK )mwait (eax, ecx);
xen/arch/x86/include/asm/spec_ctrl.h +23 -16
@@ -126,8 +126,22 @@ static inline void init_shadow_spec_ctrl_state(void) info->verw_sel = __HYPERVISOR_DS32; } +static always_inline void __spec_ctrl_enter_idle_verw(struct cpu_info *info) +{ +/* +* Flush/scrub structures which are statically partitioned between active +* threads. Otherwise data of ours (of unknown sensitivity) will become +* available to our sibling when we go idle. +* +* Note: VERW must be encoded with a memory operand, as it is only that +* form with side effects. +*/ + alternative_input("", "verw %[sel]", X86_FEATURE_SC_VERW_IDLE, + [sel] "m" (info->verw_sel)); +} +/* WARNING! `ret`, `call *`, `jmp *` not safe after this call. */ -static always_inline void spec_ctrl_enter_idle(struct cpu_info *info) +static always_inline void __spec_ctrl_enter_idle(struct cpu_info *info, bool verw) {uint32_t val =0 ;
@@ -146,21 +160,8 @@ static always_inline void spec_ctrl_enter_idle(struct cpu_info *info) "a" (val), "c" (MSR_SPEC_CTRL), "d" (0));barrier (); -/* -* Microarchitectural Store Buffer Data Sampling: -* -* On vulnerable systems, store buffer entries are statically partitioned -* between active threads. When entering idle, our store buffer entries -* are re-partitioned to allow the other threads to use them. -* -* Flush the buffers to ensure that no sensitive data of ours can be -* leaked by a sibling after it gets our store buffer entries. -* -* Note: VERW must be encoded with a memory operand, as it is only that -* form which causes a flush. -*/ - alternative_input("", "verw %[sel]", X86_FEATURE_SC_VERW_IDLE, - [sel] "m" (info->verw_sel)); +if ( verw )/* Expected to be const-propagated. */ +__spec_ctrl_enter_idle_verw (info);/* * Cross-Thread Return Address Predictions:
@@ -178,6 +179,12 @@ static always_inline void spec_ctrl_enter_idle(struct cpu_info *info) : "rax", "rcx"); } +/* WARNING! `ret`, `call *`, `jmp *` not safe after this call. */ +static always_inline void spec_ctrl_enter_idle(struct cpu_info *info) +{ +__spec_ctrl_enter_idle (info, true/* VERW */ ); +} +/* WARNING! `ret`, `call *`, `jmp *` not safe before this call. */ static always_inline void spec_ctrl_exit_idle(struct cpu_info *info) {
From: Andrew Cooper <[email protected]>
Date: Thu, 29 Aug 2024 17:36:11 +0100
Subject: x86/spec-ctrl: Mitigate Transitive Scheduler Attacks
TSA affects AMD Fam19h CPUs (Zen3 and 4 microarchitectures).
Three new CPUID bits have been defined. Two (TSA_SQ_NO and TSA_L1_NO) indicate that the system is unaffected, and must be synthesised by Xen on unaffected parts to date.
A third new bit indicates that VERW now has a flushing side effect. Xen must synthesise this bit on affected systems based on microcode version. As with other VERW-based flushing features, VERW_CLEAR needs OR-ing across a resource pool, and guests which have seen it can safely migrate in.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
tools/misc/xen-cpuid.c +3 -0
@@ -194,6 +194,7 @@ static const char *const str_7a1[32] =static const char *const str_e21a[32 ] = { [2 ] ="lfence+" , +/* 4 */ [5 ] ="verw-clear" , [6 ] ="nscb" , [8 ] ="auto-ibrs" ,
@@ -246,6 +247,8 @@ static const char *const str_m10Al[64] =static const char *const str_e21c[32 ] = { +/* 0 */ [1 ] ="tsa-sq-no" , + [2 ] ="tsa-l1-no" , }; static const struct {
xen/arch/x86/cpu-policy.c +22 -0
@@ -476,6 +476,17 @@ static void __init guest_common_max_feature_adjustments(uint32_t *fs)if (test_bit (X86_FEATURE_RTM , fs) )__set_bit (X86_FEATURE_RTM_ALWAYS_ABORT , fs);break ; + +case X86_VENDOR_AMD : +/* +* This bit indicates that the VERW instruction may have gained +* scrubbing side effects. With pooling, it means "you might migrate +* somewhere where scrubbing is necessary", and may need exposing on +* unaffected hardware. This is fine, because the VERW instruction +* has been around since the 286. +*/ +__set_bit (X86_FEATURE_VERW_CLEAR , fs); +break ; }/*
@@ -554,6 +565,17 @@ static void __init guest_common_default_feature_adjustments(uint32_t *fs)__set_bit (X86_FEATURE_RTM_ALWAYS_ABORT , fs); }break ; + +case X86_VENDOR_AMD : +/* +* This bit indicate that the VERW instruction may have gained +* scrubbing side effects. The max policy has it set for migration +* reasons, so reset the default policy back to the host value in case +* we're unaffected. +*/ +if ( !cpu_has_verw_clear ) +__clear_bit (X86_FEATURE_VERW_CLEAR , fs); +break ; }/*
xen/arch/x86/hvm/svm/entry.S +3 -0
@@ -94,6 +94,9 @@ __UNLIKELY_END(nsvm_hap) pop %rdi sti + + SPEC_CTRL_COND_VERW /* Req: %rsp=eframe Clob: efl */ + vmrun SAVE_ALL
xen/arch/x86/include/asm/cpufeature.h +5 -0
@@ -150,6 +150,7 @@/* CPUID level 0x80000021.eax */ #define cpu_has_lfence_dispatch boot_cpu_has(X86_FEATURE_LFENCE_DISPATCH) +#define cpu_has_verw_clear boot_cpu_has(X86_FEATURE_VERW_CLEAR)#define cpu_has_nscb boot_cpu_has(X86_FEATURE_NSCB)/* MSR_ARCH_CAPS */
@@ -170,6 +171,10 @@#define cpu_has_rfds_clear boot_cpu_has(X86_FEATURE_RFDS_CLEAR)#define cpu_has_its_no boot_cpu_has(X86_FEATURE_ITS_NO) +/* CPUID level 0x80000021.ecx */ +#define cpu_has_tsa_sq_no boot_cpu_has(X86_FEATURE_TSA_SQ_NO) +#define cpu_has_tsa_l1_no boot_cpu_has(X86_FEATURE_TSA_L1_NO) +/* Synthesized. */ #define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON)#define cpu_has_cpuid_faulting boot_cpu_has(X86_FEATURE_CPUID_FAULTING)
xen/arch/x86/spec_ctrl.c +102 -12
182 lines not on this page · raw message
xen/include/public/arch-x86/cpufeatureset.h +3 -0
@@ -284,6 +284,7 @@ XEN_CPUFEATURE(FSRCS, 10*32+12) /*A Fast Short REP CMPSB/SCASB *//* AMD-defined CPU features, CPUID level 0x80000021.eax, word 11 */ XEN_CPUFEATURE(LFENCE_DISPATCH, 11*32+ 2) /*A LFENCE always serializing */ +XEN_CPUFEATURE(VERW_CLEAR, 11*32+ 5) /*!A VERW clears microarchitectural buffers */ XEN_CPUFEATURE(NSCB, 11*32+ 6) /*A Null Selector Clears Base (and limit too) */ XEN_CPUFEATURE(AUTO_IBRS, 11*32+ 8) /* Automatic IBRS */XEN_CPUFEATURE (SBPB ,11 *32 +27 )/*A Selective Branch Predictor Barrier */
@@ -338,6 +339,8 @@ XEN_CPUFEATURE(RFDS_CLEAR, 16*32+28) /*!A Register File(s) cleared by VEXEN_CPUFEATURE (ITS_NO ,16 *32 +62 )/*!A No Indirect Target Selection */ /* AMD-defined CPU features, CPUID level 0x80000021.ecx, word 18 */ +XEN_CPUFEATURE(TSA_SQ_NO, 18*32+ 1) /*A No Store Queue Transitive Scheduler Attacks */ +XEN_CPUFEATURE(TSA_L1_NO, 18*32+ 2) /*A No L1D Transitive Scheduler Attacks */#endif /* XEN_CPUFEATURE */
From: Andrew Cooper <[email protected]>
Date: Tue, 10 Sep 2024 20:59:37 +0100
Subject: x86/cpufeature: Reposition cpu_has_{lfence_dispatch,nscb}
LFENCE_DISPATCH used to be a synthetic feature, but was given a real CPUID bit by AMD. The define wasn't moved when this was changed.
NSCB has always been a real CPUID bit, and was misplaced when introduced in the synthetic block alongside LFENCE_DISPATCH.
xen/arch/x86/include/asm/cpufeature.h +4 -2
@@ -190,6 +190,10 @@ static inline bool boot_cpu_has(unsigned int feat)#define cpu_has_avx512_bf16 boot_cpu_has(X86_FEATURE_AVX512_BF16)#define cpu_has_avx_ifma boot_cpu_has(X86_FEATURE_AVX_IFMA) +/* CPUID level 0x80000021.eax */ +#define cpu_has_lfence_dispatch boot_cpu_has(X86_FEATURE_LFENCE_DISPATCH) +#define cpu_has_nscb boot_cpu_has(X86_FEATURE_NSCB) +/* CPUID level 0x00000007:1.edx */ #define cpu_has_avx_vnni_int8 boot_cpu_has(X86_FEATURE_AVX_VNNI_INT8)#define cpu_has_avx_ne_convert boot_cpu_has(X86_FEATURE_AVX_NE_CONVERT)
@@ -218,8 +222,6 @@ static inline bool boot_cpu_has(unsigned int feat)#define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON)#define cpu_has_cpuid_faulting boot_cpu_has(X86_FEATURE_CPUID_FAULTING)#define cpu_has_aperfmperf boot_cpu_has(X86_FEATURE_APERFMPERF) -#define cpu_has_lfence_dispatch boot_cpu_has(X86_FEATURE_LFENCE_DISPATCH) -#define cpu_has_nscb boot_cpu_has(X86_FEATURE_NSCB)#define cpu_has_xen_lbr boot_cpu_has(X86_FEATURE_XEN_LBR)#define cpu_has_xen_shstk boot_cpu_has(X86_FEATURE_XEN_SHSTK)#define cpu_has_xen_ibt boot_cpu_has(X86_FEATURE_XEN_IBT)
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Apr 2025 14:59:01 +0100
Subject: x86/idle: Move monitor()/mwait() wrappers into cpu-idle.c
They're not used by any other translation unit, so shouldn't live in asm/processor.h, which is included almost everywhere.
Our new toolchain baseline knows the MONITOR/MWAIT instructions, so use them directly rather than using raw hex.
Change the hint/extention parameters from long to int. They're specified to remain 32bit operands even 64-bit mode.
xen/arch/x86/acpi/cpu_idle.c +17 -4
@@ -59,6 +59,19 @@/*#define DEBUG_PM_CX*/ +static always_inline void monitor( +const void *addr,unsigned int ecx,unsigned int edx) +{ + asmvolatile ("monitor" + ::"a" (addr),"c" (ecx),"d" (edx) ); +} + +static always_inline void mwait(unsigned int eax, unsigned int ecx) +{ + asmvolatile ("mwait" + ::"a" (eax),"c" (ecx) ); +} +#define GET_HW_RES_IN_NS (msr, val) \ do { rdmsrl(msr, val); val = tsc_ticks2ns(val); } while( 0 )#define GET_MC6_RES (val) GET_HW_RES_IN_NS(0x664, val)
@@ -482,7 +495,7 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx)mb (); } -__monitor (monitor_addr,0 ,0 ); +monitor (monitor_addr,0 ,0 );smp_mb ();/*
@@ -496,7 +509,7 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx)cpumask_set_cpu (cpu, &cpuidle_mwait_flags);spec_ctrl_enter_idle (info); -__mwait (eax, ecx); +mwait (eax, ecx);spec_ctrl_exit_idle (info);cpumask_clear_cpu (cpu, &cpuidle_mwait_flags);
@@ -927,9 +940,9 @@ void cf_check acpi_dead_idle(void)*/ mb ();clflush (mwait_ptr); -__monitor (mwait_ptr,0 ,0 ); +monitor (mwait_ptr,0 ,0 );mb (); -__mwait (cx->address,0 ); +mwait (cx->address,0 ); } } else if ( (current_cpu_data.x86_vendor &
xen/arch/x86/include/asm/processor.h +0 -17
@@ -312,23 +312,6 @@ static always_inline void set_in_cr4 (unsigned long mask)write_cr4 (read_cr4 () | mask); } -static always_inline void __monitor(const void *eax, unsigned long ecx, -unsigned long edx) -{ -/* "monitor %eax,%ecx,%edx;" */ - asmvolatile ( -".byte 0x0f,0x01,0xc8;" - : :"a" (eax),"c" (ecx),"d" (edx) ); -} - -static always_inline void __mwait(unsigned long eax, unsigned long ecx) -{ -/* "mwait %eax,%ecx;" */ - asmvolatile ( -".byte 0x0f,0x01,0xc9;" - : :"a" (eax),"c" (ecx) ); -} -#define IOBMP_BYTES 8192#define IOBMP_INVALID_OFFSET 0x8000
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Apr 2025 15:55:29 +0100
Subject: x86/idle: Remove MFENCEs for CLFLUSH_MONITOR
Commit 48d32458bcd4 ("x86, idle: add barriers to CLFLUSH workaround") was inherited from Linux and added MFENCEs around the AAI65 errata fix.
The SDM now states:
Executions of the CLFLUSH instruction are ordered with respect to each other and with respect to writes, locked read-modify-write instructions, and fence instructions[1].
with footnote 1 reading:
Earlier versions of this manual specified that executions of the CLFLUSH instruction were ordered only by the MFENCE instruction. All processors implementing the CLFLUSH instruction also order it relative to the other operations enumerated above.
I.e. the MFENCEs came about because of an incorrect statement in the SDM.
The Spec Update (no longer available on Intel's website) simply says "issue a CLFLUSH", with no mention of MFENCEs.
As this erratum is specific to Intel, it's fine to remove the the MFENCEs; AMD CPUs of a similar vintage do sport otherwise-unordered CLFLUSHs.
Move the feature bit into the BUG range (rather than FEATURE), and move the workaround into monitor() itself.
The erratum check itself must use setup_force_cpu_cap(). It needs activating if any CPU needs it, not if all of them need it.
xen/arch/x86/acpi/cpu_idle.c +3 -19
@@ -62,6 +62,9 @@ static always_inline void monitor(const void *addr,unsigned int ecx,unsigned int edx) { + alternative_input("", "clflush (%[addr])", X86_BUG_CLFLUSH_MONITOR, + [addr] "a" (addr)); + asmvolatile ("monitor" ::"a" (addr),"c" (ecx),"d" (edx) ); }
@@ -488,13 +491,6 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx)s_time_t expires =per_cpu (timer_deadline, cpu);const void *monitor_addr = &mwait_wakeup (cpu); -if (boot_cpu_has (X86_FEATURE_CLFLUSH_MONITOR ) ) - { -mb (); -clflush (monitor_addr); -mb (); - } -monitor (monitor_addr,0 ,0 );smp_mb ();
@@ -929,19 +925,7 @@ void cf_check acpi_dead_idle(void)while (1 ) { -/* -* 1. The CLFLUSH is a workaround for erratum AAI65 for -* the Xeon 7400 series. -* 2. The WBINVD is insufficient due to the spurious-wakeup -* case where we return around the loop. -* 3. Unlike wbinvd, clflush is a light weight but not serializing -* instruction, hence memory fence is necessary to make sure all -* load/store visible before flush cache line. -*/ -mb (); -clflush (mwait_ptr);monitor (mwait_ptr,0 ,0 ); -mb ();mwait (cx->address,0 ); } }
xen/arch/x86/cpu/intel.c +2 -1
@@ -446,6 +446,7 @@ static void __init probe_mwait_errata(void)* * Xeon 7400 erratum AAI65 (and further newer Xeons) * MONITOR/MWAIT may have excessive false wakeups +* https://web.archive.org/web/20090219054841/http://download.intel.com/design/xeon/specupdt/32033601.pdf */ static void Intel_errata_workarounds (struct cpuinfo_x86 *c) {
@@ -463,7 +464,7 @@ static void Intel_errata_workarounds(struct cpuinfo_x86 *c)if (c->x86 ==6 && cpu_has_clflush && (c->x86_model ==29 || c->x86_model ==46 || c->x86_model ==47 )) -__set_bit (X86_FEATURE_CLFLUSH_MONITOR , c->x86_capability); +setup_force_cpu_cap (X86_BUG_CLFLUSH_MONITOR );probe_c3_errata (c);if (system_state < SYS_STATE_smp_boot)
xen/arch/x86/include/asm/cpufeatures.h +2 -1
@@ -19,7 +19,7 @@ XEN_CPUFEATURE(ARCH_PERFMON, X86_SYNTH( 3)) /* Intel Architectural PerfMon XEN_CPUFEATURE(TSC_RELIABLE, X86_SYNTH( 4)) /* TSC is known to be reliable */ XEN_CPUFEATURE(XTOPOLOGY, X86_SYNTH( 5)) /* cpu topology enum extensions */XEN_CPUFEATURE (CPUID_FAULTING ,X86_SYNTH (6 ))/* cpuid faulting */ -XEN_CPUFEATURE(CLFLUSH_MONITOR, X86_SYNTH( 7)) /* clflush reqd with monitor */ +/* Bit 7 unused */ XEN_CPUFEATURE(APERFMPERF, X86_SYNTH( 8)) /* APERFMPERF */ XEN_CPUFEATURE(MFENCE_RDTSC, X86_SYNTH( 9)) /* MFENCE synchronizes RDTSC */XEN_CPUFEATURE (XEN_SMEP ,X86_SYNTH (10 ))/* SMEP gets used by Xen itself */
@@ -52,6 +52,7 @@ XEN_CPUFEATURE(USE_VMCALL, X86_SYNTH(30)) /* Use VMCALL instead of VMMCAL#define X86_BUG_NULL_SEG X86_BUG( 1)/* NULL-ing a selector preserves the base and limit. */ #define X86_BUG_CLFLUSH_MFENCE X86_BUG( 2)/* MFENCE needed to serialise CLFLUSH */ #define X86_BUG_IBPB_NO_RET X86_BUG( 3)/* IBPB doesn't flush the RSB/RAS */ +#define X86_BUG_CLFLUSH_MONITOR X86_BUG( 4)/* MONITOR requires CLFLUSH */ #define X86_SPEC_NO_LFENCE_ENTRY_PV X86_BUG(16)/* (No) safety LFENCE for SPEC_CTRL_ENTRY_PV. */ #define X86_SPEC_NO_LFENCE_ENTRY_INTR X86_BUG(17)/* (No) safety LFENCE for SPEC_CTRL_ENTRY_INTR. */
From: Andrew Cooper <[email protected]>
Date: Tue, 24 Jun 2025 15:20:52 +0100
Subject: Revert part of "x86/mwait-idle: disable IBRS during long idle"
Most of the patch (handling of CPUIDLE_FLAG_IBRS) is fine, but the adjustements to mwait_idle() are not; spec_ctrl_enter_idle() does more than just alter MSR_SPEC_CTRL.IBRS.
The only reason this doesn't need an XSA is because the unconditional spec_ctrl_{enter,exit}_idle() in mwait_idle_with_hints() were left unaltered, and thus the MWAIT remained properly protected.
There (would have been) two problems. In the ibrs_disable (== deep C) case:
* On entry, VERW and RSB-stuffing are architecturally skipped.
* On exit, there's a branch crossing the WRMSR which reinstates the speculative safety for indirect branches.
All this change did was double up the expensive operations in the deep C case, and fail to optimise the intended case.
I have an idea of how to plumb this more nicely, but it requires larger changes to legacy IBRS handling to not make spec_ctrl_enter_idle() vulnerable in other ways. In the short term, simply take out the perf hit.
xen/arch/x86/cpu/mwait-idle.c +2 -10
@@ -891,7 +891,6 @@ static const struct cpuidle_state snr_cstates[] = { static void cf_check mwait_idle(void) {unsigned int cpu =smp_processor_id (); -struct cpu_info *info =get_cpu_info ();struct acpi_processor_power *power = processor_powers[cpu];struct acpi_processor_cx *cx =NULL ;unsigned int next_state;
@@ -918,6 +917,8 @@ static void cf_check mwait_idle(void)pm_idle_save (); else { +struct cpu_info *info =get_cpu_info (); +spec_ctrl_enter_idle (info);safe_halt ();spec_ctrl_exit_idle (info);
@@ -944,11 +945,6 @@ static void cf_check mwait_idle(void)if ((cx->type >=3 ) &&errata_c6_workaround ()) cx = power->safe_state; -if (cx->ibrs_disable) { -ASSERT (!cx->irq_enable_early); -spec_ctrl_enter_idle (info); - } -#if 0 /* XXX Can we/do we need to do something similar on Xen? */ /* * leave_mm() to avoid costly and often unnecessary wakeups
@@ -980,10 +976,6 @@ static void cf_check mwait_idle(void)/* Now back in C0. */ update_idle_stats (power, cx, before, after); - -if (cx->ibrs_disable) -spec_ctrl_exit_idle (info); -local_irq_enable (); TRACE_6D(TRC_PM_IDLE_EXIT, cx->type, after,
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Jun 2025 14:46:01 +0100
Subject: x86/cpu-policy: Simplify logic in
guest_common_default_feature_adjustments()
For features which are unconditionally set in the max policies, making the default policy to match the host can be done with a conditional clear.
This is simpler than the unconditional clear, conditional set currently performed.
xen/arch/x86/cpu-policy.c +10 -15
@@ -540,17 +540,14 @@ static void __init guest_common_default_feature_adjustments(uint32_t *fs)* reasons, so reset the default policy back to the host values in * case we're unaffected. */ -__clear_bit (X86_FEATURE_MD_CLEAR , fs); -if ( cpu_has_md_clear ) -__set_bit (X86_FEATURE_MD_CLEAR , fs); +if ( !cpu_has_md_clear ) +__clear_bit (X86_FEATURE_MD_CLEAR , fs); -__clear_bit (X86_FEATURE_FB_CLEAR , fs); -if ( cpu_has_fb_clear ) -__set_bit (X86_FEATURE_FB_CLEAR , fs); +if ( !cpu_has_fb_clear ) +__clear_bit (X86_FEATURE_FB_CLEAR , fs); -__clear_bit (X86_FEATURE_RFDS_CLEAR , fs); -if ( cpu_has_rfds_clear ) -__set_bit (X86_FEATURE_RFDS_CLEAR , fs); +if ( !cpu_has_rfds_clear ) +__clear_bit (X86_FEATURE_RFDS_CLEAR , fs);/* * The Gather Data Sampling microcode mitigation (August 2023) has an
@@ -570,13 +567,11 @@ static void __init guest_common_default_feature_adjustments(uint32_t *fs)* Topology information is at the toolstack's discretion so these are * unconditionally set in max, but pick a default which matches the host. */ -__clear_bit (X86_FEATURE_HTT , fs); -if ( cpu_has_htt ) -__set_bit (X86_FEATURE_HTT , fs); +if ( !cpu_has_htt ) +__clear_bit (X86_FEATURE_HTT , fs); -__clear_bit (X86_FEATURE_CMP_LEGACY , fs); -if ( cpu_has_cmp_legacy ) -__set_bit (X86_FEATURE_CMP_LEGACY , fs); +if ( !cpu_has_cmp_legacy ) +__clear_bit (X86_FEATURE_CMP_LEGACY , fs);/* * On certain hardware, speculative or errata workarounds can result in
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 11:33:41 +0100
Subject: x86/cpu-policy: Fix handling of leaf 0x80000021
When support was originally introduced, ebx, ecx and edx were reserved and should have been zeroed in recalculate_misc() to avoid leaking into guests.
Since then, fields have been added into ebx. Guests can't load microcode, so shouldn't see ucode_size, and while in principle we do want to support larger RAP sizes in guests, virtualising this for guests depends on AMD procuding any official documentation for ERAPS, which is long overdue and with no ETA.
This patch will cause a difference in guests on Zen5 CPUs, but as the main ERAPS feature is hidden, guests should be ignoring the rap_size field too.
xen/arch/x86/cpu-policy.c +3 -0
@@ -341,6 +341,9 @@ static void recalculate_misc(struct cpu_policy *p) p->extd.raw[0x1e ] =EMPTY_LEAF ;/* TopoExt APIC ID/Core/Node */ p->extd.raw[0x1f ] =EMPTY_LEAF ;/* SEV */ p->extd.raw[0x20 ] =EMPTY_LEAF ;/* Platform QoS */ + p->extd.raw[0x21 ].b =0 ; + p->extd.raw[0x21 ].c =0 ; + p->extd.raw[0x21 ].d =0 ;break ; } }
xen/include/xen/lib/x86/cpu-policy.h +4 -1
@@ -324,7 +324,10 @@ struct cpu_policyuint32_t e21a;struct {DECL_BITFIELD (e21a); }; }; - uint32_t /* b */:32, /* c */:32, /* d */:32; +uint16_t ucode_size;/* Units of 16 bytes */ +uint8_t rap_size;/* Units of 8 entries */ + uint8_t :8; + uint32_t /* c */:32, /* d */:32; }; } extd;
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 15:51:53 +0100
Subject: x86/idle: Remove broken MWAIT implementation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
cpuidle_wakeup_mwait() is a TOCTOU race. The cpumask_and() sampling cpuidle_mwait_flags can take a arbitrary period of time, and there's no guarantee that the target CPUs are still in MWAIT when writing into mwait_wakeup(cpu).
The consequence of the race is that we'll fail to IPI certain targets. Also, there's no guarantee that mwait_idle_with_hints() will raise a TIMER_SOFTIRQ on it's way out.
The fundamental bug is that the "in_mwait" variable needs to be in the monitored line, and not in a separate cpuidle_mwait_flags variable, in order to do this in a race-free way.
Arranging to fix this while keeping the old implementation is prohibitive, so strip the current one out in order to implement the new one cleanly. In the interim, this causes IPIs to be used unconditionally which is safe albeit suboptimal.
xen/arch/x86/acpi/cpu_idle.c +5 -43
81 lines not on this page · raw message
xen/arch/x86/hpet.c +0 -2
@@ -187,8 +187,6 @@ static void evt_do_broadcast(cpumask_t *mask)if (__cpumask_test_and_clear_cpu (cpu, mask) )raise_softirq (TIMER_SOFTIRQ ); -cpuidle_wakeup_mwait (mask); -if ( !cpumask_empty (mask) )cpumask_raise_softirq (mask,TIMER_SOFTIRQ ); }
xen/arch/x86/include/asm/hardirq.h +4 -5
@@ -5,11 +5,10 @@#include <xen/types.h> typedef struct { -unsigned int __softirq_pending; -unsigned int __local_irq_count; -unsigned int nmi_count; -unsigned int mce_count; -bool_t __mwait_wakeup; +unsigned int __softirq_pending; +unsigned int __local_irq_count; +unsigned int nmi_count; +unsigned int mce_count; } __cacheline_aligned irq_cpustat_t;#include <xen/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
xen/include/xen/cpuidle.h +0 -2
@@ -92,8 +92,6 @@ extern struct cpuidle_governor *cpuidle_current_governor;bool cpuidle_using_deep_cstate (void );void cpuidle_disable_deep_cstate (void ); -extern void cpuidle_wakeup_mwait (cpumask_t *mask); -#define CPUIDLE_DRIVER_STATE_START 1extern void menu_get_trace_data (u32 *expected,u32 *pred);
xen/include/xen/irq_cpustat.h +0 -1
@@ -24,6 +24,5 @@ extern irq_cpustat_t irq_stat[];/* arch independent irq_stat fields */ #define softirq_pending (cpu) __IRQ_STAT((cpu), __softirq_pending)#define local_irq_count (cpu) __IRQ_STAT((cpu), __local_irq_count) -#define mwait_wakeup (cpu) __IRQ_STAT((cpu), __mwait_wakeup)#endif /* __irq_cpustat_h */
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 18:13:27 +0100
Subject: x86/idle: Drop incorrect smp_mb() in mwait_idle_with_hints()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
With the recent simplifications, it becomes obvious that smp_mb() isn't the right barrier. Strictly speaking, MONITOR is ordered as a load, but smp_rmb() isn't correct either, as this only pertains to local ordering. All we need is a compiler barrier().
Merge the barier() into the monitor() itself, along with an explantion.
No functional change.
xen/arch/x86/acpi/cpu_idle.c +5 -2
@@ -65,8 +65,12 @@ static always_inline void monitor( alternative_input("", "clflush (%[addr])", X86_BUG_CLFLUSH_MONITOR, [addr] "a" (addr)); +/* +* The memory clobber is a compiler barrier. Subseqeunt reads from the +* monitored cacheline must not be reordered over MONITOR. +*/ asmvolatile ("monitor" - ::"a" (addr),"c" (ecx),"d" (edx) ); + ::"a" (addr),"c" (ecx),"d" (edx) :"memory" ); } static always_inline void mwait(unsigned int eax, unsigned int ecx)
@@ -465,7 +469,6 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx)const unsigned int *this_softirq_pending = &softirq_pending (cpu);monitor (this_softirq_pending,0 ,0 ); -smp_mb ();if ( !*this_softirq_pending ) {
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 21:40:51 +0100
Subject: x86/idle: Convert force_mwait_ipi_wakeup to X86_BUG_MONITOR
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
We're going to want alternative-patch based on it.
No functional change.
xen/arch/x86/acpi/cpu_idle.c +0 -6
@@ -452,14 +452,8 @@ static int __init cf_check cpu_idle_key_init(void) }__initcall (cpu_idle_key_init); -/* Force sending of a wakeup IPI regardless of mwait usage. */ -bool __ro_after_init force_mwait_ipi_wakeup; -bool arch_skip_send_event_check (unsigned int cpu) { -if ( force_mwait_ipi_wakeup ) -return false; -return false; }
xen/arch/x86/cpu/intel.c +1 -1
@@ -436,7 +436,7 @@ static void __init probe_mwait_errata(void) {printk (XENLOG_WARNING "Forcing IPI MWAIT wakeup due to CPU erratum\n" ); - force_mwait_ipi_wakeup = true; +setup_force_cpu_cap (X86_BUG_MONITOR ); } }
xen/arch/x86/include/asm/cpufeatures.h +1 -0
@@ -53,6 +53,7 @@ XEN_CPUFEATURE(USE_VMCALL, X86_SYNTH(30)) /* Use VMCALL instead of VMMCAL#define X86_BUG_CLFLUSH_MFENCE X86_BUG( 2)/* MFENCE needed to serialise CLFLUSH */ #define X86_BUG_IBPB_NO_RET X86_BUG( 3)/* IBPB doesn't flush the RSB/RAS */ #define X86_BUG_CLFLUSH_MONITOR X86_BUG( 4)/* MONITOR requires CLFLUSH */ +#define X86_BUG_MONITOR X86_BUG( 5)/* MONITOR doesn't always notice writes (force IPIs) */ #define X86_SPEC_NO_LFENCE_ENTRY_PV X86_BUG(16)/* (No) safety LFENCE for SPEC_CTRL_ENTRY_PV. */ #define X86_SPEC_NO_LFENCE_ENTRY_INTR X86_BUG(17)/* (No) safety LFENCE for SPEC_CTRL_ENTRY_INTR. */
xen/arch/x86/include/asm/mwait.h +0 -3
@@ -13,9 +13,6 @@#define MWAIT_ECX_INTERRUPT_BREAK 0x1 -/* Force sending of a wakeup IPI regardless of mwait usage. */ -extern bool force_mwait_ipi_wakeup; -void mwait_idle_with_hints (unsigned int eax,unsigned int ecx);bool mwait_pc10_supported (void );
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 21:04:17 +0100
Subject: xen/softirq: Rework arch_skip_send_event_check() into
arch_set_softirq()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
x86 is the only architecture wanting an optimisation here, but the test_and_set_bit() is a store into the monitored line (i.e. will wake up the target) and, prior to the removal of the broken IPI-elision algorithm, was racy, causing unnecessary IPIs to be sent.
To do this in a race-free way, the store to the monited line needs to also sample the status of the target in one atomic action. Implement a new arch helper with different semantics; to make the softirq pending and decide about IPIs together. For now, implement the default helper. It will be overridden by x86 in a subsequent change.
No functional change.
xen/arch/x86/acpi/cpu_idle.c +0 -5
@@ -452,11 +452,6 @@ static int __init cf_check cpu_idle_key_init(void) }__initcall (cpu_idle_key_init); -bool arch_skip_send_event_check (unsigned int cpu) -{ -return false; -} -void mwait_idle_with_hints (unsigned int eax,unsigned int ecx) {unsigned int cpu =smp_processor_id ();
xen/arch/x86/include/asm/softirq.h +0 -2
@@ -9,6 +9,4 @@#define HVM_DPCI_SOFTIRQ (NR_COMMON_SOFTIRQS + 4)#define NR_ARCH_SOFTIRQS 5 -bool arch_skip_send_event_check (unsigned int cpu); -#endif /* __ASM_SOFTIRQ_H__ */
xen/common/softirq.c +2 -6
@@ -94,9 +94,7 @@ void cpumask_raise_softirq(const cpumask_t *mask, unsigned int nr) raise_mask = &per_cpu (batch_mask, this_cpu);for_each_cpu (cpu, mask) -if ( !test_and_set_bit (nr, &softirq_pending (cpu)) && - cpu != this_cpu && - !arch_skip_send_event_check (cpu) ) +if ( !arch_set_softirq (nr, cpu) && cpu != this_cpu )__cpumask_set_cpu (cpu, raise_mask);if ( raise_mask == &send_mask )
@@ -107,9 +105,7 @@ void cpu_raise_softirq(unsigned int cpu, unsigned int nr) {unsigned int this_cpu =smp_processor_id (); -if (test_and_set_bit (nr, &softirq_pending (cpu)) - || (cpu == this_cpu) - ||arch_skip_send_event_check (cpu) ) +if (arch_set_softirq (nr, cpu) || cpu == this_cpu )return ;if ( !per_cpu (batching, this_cpu) ||in_irq () )
xen/include/xen/softirq.h +16 -0
@@ -21,6 +21,22 @@ enum {#define NR_SOFTIRQS (NR_COMMON_SOFTIRQS + NR_ARCH_SOFTIRQS) +/* +* Ensure softirq @nr is pending on @cpu. Return true if an IPI can be +* skipped, false if the IPI cannot be skipped. +*/ +#ifndef arch_set_softirq +static always_inline bool arch_set_softirq(unsigned int nr, unsigned int cpu) +{ +/* +* Try to set the softirq pending. If we set the bit (i.e. the old bit +* was 0), we're responsible to send the IPI. If the softirq was already +* pending (i.e. the old bit was 1), no IPI is needed. +*/ +return test_and_set_bit (nr, &softirq_pending (cpu)); +} +#endif +typedef void (*softirq_handler )(void );void do_softirq (void );
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 21:26:24 +0100
Subject: x86/idle: Implement a new MWAIT IPI-elision algorithm
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
In order elide IPIs, we must be able to identify whether a target CPU is in MWAIT at the point it is woken up. i.e. the store to wake it up must also identify the state.
Create a new in_mwait variable beside __softirq_pending, so we can use a CMPXCHG to set the softirq while also observing the status safely. Implement an x86 version of arch_pend_softirq() which does this.
In mwait_idle_with_hints(), advertise in_mwait, with an explanation of precisely what it means. X86_BUG_MONITOR can be accounted for simply by not advertising in_mwait.
xen/arch/x86/acpi/cpu_idle.c +19 -1
@@ -455,7 +455,21 @@ __initcall(cpu_idle_key_init);void mwait_idle_with_hints (unsigned int eax,unsigned int ecx) {unsigned int cpu =smp_processor_id (); -const unsigned int *this_softirq_pending = &softirq_pending (cpu); +irq_cpustat_t *stat = &irq_stat[cpu]; +const unsigned int *this_softirq_pending = &stat->__softirq_pending; + +/* +* By setting in_mwait, we promise to other CPUs that we'll notice changes +* to __softirq_pending without being sent an IPI. We achieve this by +* either not going to sleep, or by having hardware notice on our behalf. +* +* Some errata exist where MONITOR doesn't work properly, and the +* workaround is to force the use of an IPI. Cause this to happen by +* simply not advertising ourselves as being in_mwait. +*/ +alternative_io ("movb $1, %[in_mwait]" , + "", X86_BUG_MONITOR, + [in_mwait] "=m" (stat->in_mwait));monitor (this_softirq_pending,0 ,0 );
@@ -467,6 +481,10 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx)mwait (eax, ecx);spec_ctrl_exit_idle (info); } + +alternative_io ("movb $0, %[in_mwait]" , + "", X86_BUG_MONITOR, + [in_mwait] "=m" (stat->in_mwait)); }static void acpi_processor_ffh_cstate_enter (struct acpi_processor_cx *cx)
xen/arch/x86/include/asm/hardirq.h +13 -1
@@ -5,7 +5,19 @@#include <xen/types.h> typedef struct { - unsigned int __softirq_pending; + /* + * The layout is important. Any CPU can set bits in __softirq_pending, + * but in_mwait is a status bit owned by the CPU. softirq_mwait_raw must + * cover both, and must be in a single cacheline. + */ + union { + struct { + unsigned int __softirq_pending; + bool in_mwait; + }; + uint64_t softirq_mwait_raw; + }; + unsigned int __local_irq_count; unsigned int nmi_count; unsigned int mce_count;
xen/arch/x86/include/asm/softirq.h +48 -0
58 lines not on this page · raw message
From: Andrew Cooper <[email protected]>
Date: Wed, 2 Jul 2025 14:51:38 +0100
Subject: x86/idle: Fix buggy "x86/mwait-idle: enable interrupts before C1 on
Xeons"
The check of this_softirq_pending must be performed with irqs disabled, but this property was broken by an attempt to optimise entry/exit latency.
Commit c227233ad64c in Linux (which we copied into Xen) was fixed up by edc8fc01f608 in Linux, which we have so far missed.
Going to sleep without waking on interrupts is nonsensical outside of play_dead(), so overload this to select between two possible MWAITs, the second using the STI shadow to cover MWAIT for exactly the same reason as we do in safe_halt().
xen/arch/x86/acpi/cpu_idle.c +15 -1
@@ -79,6 +79,13 @@ static always_inline void mwait(unsigned int eax, unsigned int ecx) :: "a" (eax), "c" (ecx) ); } +static always_inline void sti_mwait_cli(unsigned int eax, unsigned int ecx) +{ +/* STI shadow covers MWAIT. */ + asmvolatile ("sti; mwait; cli" + ::"a" (eax),"c" (ecx) ); +} +#define GET_HW_RES_IN_NS (msr, val) \ do { rdmsrl(msr, val); val = tsc_ticks2ns(val); } while( 0 )#define GET_MC6_RES (val) GET_HW_RES_IN_NS(0x664, val)
@@ -473,12 +480,19 @@ void mwait_idle_with_hints(unsigned int eax, unsigned int ecx)monitor (this_softirq_pending,0 ,0 ); +ASSERT (!local_irq_is_enabled ()); +if ( !*this_softirq_pending ) {struct cpu_info *info =get_cpu_info ();spec_ctrl_enter_idle (info); -mwait (eax, ecx); + +if ( ecx &MWAIT_ECX_INTERRUPT_BREAK ) +mwait (eax, ecx); +else +sti_mwait_cli (eax, ecx); +spec_ctrl_exit_idle (info); }
xen/arch/x86/cpu/mwait-idle.c +2 -6
@@ -962,12 +962,8 @@ static void cf_check mwait_idle(void)update_last_cx_stat (power, cx, before); -if (cx->irq_enable_early) -local_irq_enable (); - -mwait_idle_with_hints (cx->address,MWAIT_ECX_INTERRUPT_BREAK ); - -local_irq_disable (); +mwait_idle_with_hints (cx->address, + cx->irq_enable_early ?0 :MWAIT_ECX_INTERRUPT_BREAK ); after =alternative_call (cpuidle_get_tick);
From: Andrew Cooper <[email protected]>
Date: Fri, 4 Jul 2025 17:53:15 +0100
Subject: x86/xen-cpuid: Fix backports of new features
Xen 4.18 doesn't automatically generate feature names like Xen 4.19 does, and these hunks were missed on prior security fixes.
tools/misc/xen-cpuid.c +6 -5
@@ -205,6 +205,7 @@ static const char *const str_e21a[32] = /* 26 */ [27] = "sbpb", [28] = "ibpb-brtype", [29] = "srso-no", + [30] = "srso-us-no", [31] = "srso-msr-fix", }; static const char *const str_7b1[32] =
@@ -230,7 +231,7 @@ static const char *const str_7d2[32] = [ 4] = "bhi-ctrl", [ 5] = "mcdt-no", }; -static const char *const str_m10Al[32 ] = +static const char *const str_m10Al[64 ] = { [0 ] ="rdcl-no" , [1 ] ="eibrs" , [2 ] ="rsba" , [3 ] ="skip-l1dfl" ,
@@ -247,10 +248,10 @@ static const char *const str_m10Al[32] = [24] = "pbrsb-no", [25] = "gds-ctrl", [26] = "gds-no", [27] = "rfds-no", [28] = "rfds-clear", -}; -static const char *const str_m10Ah[32 ] = -{ + [32] = "pb-opt-ctrl", + + [62] = "its-no", }; static const struct {
@@ -276,7 +277,7 @@ static const struct { { "CPUID 0x00000007:1.ecx", "7c1", str_7c1 }, { "CPUID 0x00000007:1.edx", "7d1", str_7d1 }, { "MSR_ARCH_CAPS.lo", "m10Al", str_m10Al }, - { "MSR_ARCH_CAPS.hi", "m10Ah", str_m10Ah }, + { "MSR_ARCH_CAPS.hi", "m10Ah", str_m10Al + 32 }, };#define COL_ALIGN "24"
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Jun 2025 17:19:19 +0100
Subject: 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.
xen/arch/x86/cpu-policy.c +37 -32
105 lines not on this page · raw message
From: Andrew Cooper <[email protected]>
Date: Tue, 10 Sep 2024 19:55:15 +0100
Subject: x86/cpu-policy: Infrastructure for CPUID leaf 0x80000021.ecx
tools/libs/light/libxl_cpuid.c +1 -0
@@ -342,6 +342,7 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *policy, const char* str)CPUID_ENTRY (0x00000007 ,1 ,CPUID_REG_EDX ),MSR_ENTRY (0x10a ,CPUID_REG_EAX ),MSR_ENTRY (0x10a ,CPUID_REG_EDX ), +CPUID_ENTRY (0x80000021 ,NA ,CPUID_REG_ECX ), #undef MSR_ENTRY#undef CPUID_ENTRY };
tools/misc/xen-cpuid.c +5 -0
@@ -254,6 +254,10 @@ static const char *const str_m10Al[64] = [62] = "its-no", }; +static const char *const str_e21c[32 ] = +{ +}; + static const struct { const char *name; const char *abbr;
@@ -278,6 +282,7 @@ static const struct { { "CPUID 0x00000007:1.edx", "7d1", str_7d1 }, { "MSR_ARCH_CAPS.lo", "m10Al", str_m10Al }, { "MSR_ARCH_CAPS.hi", "m10Ah", str_m10Al + 32 }, + { "CPUID 0x80000021.ecx", "e21c", str_e21c }, };#define COL_ALIGN "24"
xen/arch/x86/cpu-policy.c +0 -1
@@ -342,7 +342,6 @@ static void recalculate_misc(struct cpu_policy *p) p->extd.raw[0x1f ] =EMPTY_LEAF ;/* SEV */ p->extd.raw[0x20 ] =EMPTY_LEAF ;/* Platform QoS */ p->extd.raw[0x21 ].b =0 ; - p->extd.raw[0x21 ].c =0 ; p->extd.raw[0x21 ].d =0 ;break ; }
xen/arch/x86/cpu/common.c +3 -1
@@ -479,7 +479,9 @@ static void generic_identify(struct cpuinfo_x86 *c)if (c->extended_cpuid_level >=0x80000008 ) c->x86_capability[FEATURESET_e8b] =cpuid_ebx (0x80000008 );if (c->extended_cpuid_level >=0x80000021 ) - c->x86_capability[FEATURESET_e21a] =cpuid_eax (0x80000021 ); +cpuid (0x80000021 , + &c->x86_capability[FEATURESET_e21a], &tmp, + &c->x86_capability[FEATURESET_e21c], &tmp);/* Intel-defined flags: level 0x00000007 */ if (c->cpuid_level >=7 ) {
xen/include/public/arch-x86/cpufeatureset.h +2 -0
@@ -348,6 +348,8 @@ XEN_CPUFEATURE(RFDS_CLEAR, 16*32+28) /*!A Register File(s) cleared by VE XEN_CPUFEATURE(PB_OPT_CTRL, 16*32+32) /* MSR_PB_OPT_CTRL.IBPB_ALT */XEN_CPUFEATURE (ITS_NO ,16 *32 +62 )/*!A No Indirect Target Selection */ +/* AMD-defined CPU features, CPUID level 0x80000021.ecx, word 18 */ +#endif /* XEN_CPUFEATURE */ /* Clean up from a default include. Close the enum (for C). */
xen/include/xen/lib/x86/cpu-policy.h +6 -1
@@ -22,6 +22,7 @@#define FEATURESET_7d1 15/* 0x00000007:1.edx */ #define FEATURESET_m10Al 16/* 0x0000010a.eax */ #define FEATURESET_m10Ah 17/* 0x0000010a.edx */ +#define FEATURESET_e21c 18/* 0x80000021.ecx */ struct cpuid_leaf {
@@ -327,7 +328,11 @@ struct cpu_policyuint16_t ucode_size;/* Units of 16 bytes */ uint8_t rap_size;/* Units of 8 entries */ uint8_t :8; - uint32_t /* c */:32, /* d */:32; +union { +uint32_t e21c; +struct {DECL_BITFIELD (e21c); }; + }; + uint32_t /* d */:32; }; } extd;
xen/lib/x86/cpuid.c +2 -0
@@ -81,6 +81,7 @@ void x86_cpu_policy_to_featureset( fs[FEATURESET_7d1] = p->feat._7d1; fs[FEATURESET_m10Al] = p->arch_caps.lo; fs[FEATURESET_m10Ah] = p->arch_caps.hi; + fs[FEATURESET_e21c] = p->extd.e21c; } void x86_cpu_featureset_to_policy(
@@ -104,6 +105,7 @@ void x86_cpu_featureset_to_policy( p->feat._7d1 = fs[FEATURESET_7d1]; p->arch_caps.lo = fs[FEATURESET_m10Al]; p->arch_caps.hi = fs[FEATURESET_m10Ah]; + p->extd.e21c = fs[FEATURESET_e21c]; }void x86_cpu_policy_recalc_synth (struct cpu_policy *p)
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Sep 2024 11:28:39 +0100
Subject: x86/ucode: Digests for TSA microcode
AMD are releasing microcode for TSA, so extend the known-provenance list with their hashes. These were produced before the remediation of the microcode signature issues (the entrysign vulnerability), so can be OS-loaded on out-of-date firmware.
Include an off-by-default check for the sorted-ness of patch_digests[]. It's not worth running generally under SELF_TESTS, but is useful when editing the digest list.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
xen/arch/x86/cpu/microcode/amd-patch-digests.c +144 -0
142 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Wed, 2 Apr 2025 03:18:59 +0100
Subject: x86/idle: Rearrange VERW and MONITOR in mwait_idle_with_hints()
In order to mitigate TSA, Xen will need to issue VERW before going idle.
On AMD CPUs, the VERW scrubbing side effects cancel an active MONITOR, causing the MWAIT to exit without entering an idle state. Therefore the VERW must be ahead of MONITOR.
Split spec_ctrl_enter_idle() in two and allow the VERW aspect to be handled separately. While adjusting, update a stale comment concerning MSBDS; more issues have been mitigated using VERW since it was written.
By moving VERW earlier, it is ahead of the determination of whether to go idle. We can't move the check on softirq_pending (for correctness reasons), but we can duplicate it earlier as a best effort attempt to skip the speculative overhead.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Thu, 29 Aug 2024 17:36:11 +0100
Subject: x86/spec-ctrl: Mitigate Transitive Scheduler Attacks
TSA affects AMD Fam19h CPUs (Zen3 and 4 microarchitectures).
Three new CPUID bits have been defined. Two (TSA_SQ_NO and TSA_L1_NO) indicate that the system is unaffected, and must be synthesised by Xen on unaffected parts to date.
A third new bit indicates that VERW now has a flushing side effect. Xen must synthesise this bit on affected systems based on microcode version. As with other VERW-based flushing features, VERW_CLEAR needs OR-ing across a resource pool, and guests which have seen it can safely migrate in.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
xen/arch/x86/spec_ctrl.c +102 -12
114 lines not on this page · raw message
xen/include/public/arch-x86/cpufeatureset.h +3 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 10 Sep 2024 20:59:37 +0100
Subject: x86/cpufeature: Reposition cpu_has_{lfence_dispatch,nscb}
LFENCE_DISPATCH used to be a synthetic feature, but was given a real CPUID bit by AMD. The define wasn't moved when this was changed.
NSCB has always been a real CPUID bit, and was misplaced when introduced in the synthetic block alongside LFENCE_DISPATCH.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Apr 2025 14:59:01 +0100
Subject: x86/idle: Move monitor()/mwait() wrappers into cpu-idle.c
They're not used by any other translation unit, so shouldn't live in asm/processor.h, which is included almost everywhere.
Our new toolchain baseline knows the MONITOR/MWAIT instructions, so use them directly rather than using raw hex.
Change the hint/extention parameters from long to int. They're specified to remain 32bit operands even 64-bit mode.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Apr 2025 15:55:29 +0100
Subject: x86/idle: Remove MFENCEs for CLFLUSH_MONITOR
Commit 48d32458bcd4 ("x86, idle: add barriers to CLFLUSH workaround") was inherited from Linux and added MFENCEs around the AAI65 errata fix.
The SDM now states:
Executions of the CLFLUSH instruction are ordered with respect to each other and with respect to writes, locked read-modify-write instructions, and fence instructions[1].
with footnote 1 reading:
Earlier versions of this manual specified that executions of the CLFLUSH instruction were ordered only by the MFENCE instruction. All processors implementing the CLFLUSH instruction also order it relative to the other operations enumerated above.
I.e. the MFENCEs came about because of an incorrect statement in the SDM.
The Spec Update (no longer available on Intel's website) simply says "issue a CLFLUSH", with no mention of MFENCEs.
As this erratum is specific to Intel, it's fine to remove the the MFENCEs; AMD CPUs of a similar vintage do sport otherwise-unordered CLFLUSHs.
Move the feature bit into the BUG range (rather than FEATURE), and move the workaround into monitor() itself.
The erratum check itself must use setup_force_cpu_cap(). It needs activating if any CPU needs it, not if all of them need it.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 24 Jun 2025 15:20:52 +0100
Subject: Revert part of "x86/mwait-idle: disable IBRS during long idle"
Most of the patch (handling of CPUIDLE_FLAG_IBRS) is fine, but the adjustements to mwait_idle() are not; spec_ctrl_enter_idle() does more than just alter MSR_SPEC_CTRL.IBRS.
The only reason this doesn't need an XSA is because the unconditional spec_ctrl_{enter,exit}_idle() in mwait_idle_with_hints() were left unaltered, and thus the MWAIT remained properly protected.
There (would have been) two problems. In the ibrs_disable (== deep C) case:
* On entry, VERW and RSB-stuffing are architecturally skipped.
* On exit, there's a branch crossing the WRMSR which reinstates the speculative safety for indirect branches.
All this change did was double up the expensive operations in the deep C case, and fail to optimise the intended case.
I have an idea of how to plumb this more nicely, but it requires larger changes to legacy IBRS handling to not make spec_ctrl_enter_idle() vulnerable in other ways. In the short term, simply take out the perf hit.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Jun 2025 14:46:01 +0100
Subject: x86/cpu-policy: Simplify logic in
guest_common_default_feature_adjustments()
For features which are unconditionally set in the max policies, making the default policy to match the host can be done with a conditional clear.
This is simpler than the unconditional clear, conditional set currently performed.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 15:51:53 +0100
Subject: x86/idle: Remove broken MWAIT implementation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
cpuidle_wakeup_mwait() is a TOCTOU race. The cpumask_and() sampling cpuidle_mwait_flags can take a arbitrary period of time, and there's no guarantee that the target CPUs are still in MWAIT when writing into mwait_wakeup(cpu).
The consequence of the race is that we'll fail to IPI certain targets. Also, there's no guarantee that mwait_idle_with_hints() will raise a TIMER_SOFTIRQ on it's way out.
The fundamental bug is that the "in_mwait" variable needs to be in the monitored line, and not in a separate cpuidle_mwait_flags variable, in order to do this in a race-free way.
Arranging to fix this while keeping the old implementation is prohibitive, so strip the current one out in order to implement the new one cleanly. In the interim, this causes IPIs to be used unconditionally which is safe albeit suboptimal.
xen/arch/x86/acpi/cpu_idle.c +5 -43
48 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 18:13:27 +0100
Subject: x86/idle: Drop incorrect smp_mb() in mwait_idle_with_hints()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
With the recent simplifications, it becomes obvious that smp_mb() isn't the right barrier. Strictly speaking, MONITOR is ordered as a load, but smp_rmb() isn't correct either, as this only pertains to local ordering. All we need is a compiler barrier().
Merge the barier() into the monitor() itself, along with an explantion.
No functional change.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 21:40:51 +0100
Subject: x86/idle: Convert force_mwait_ipi_wakeup to X86_BUG_MONITOR
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
We're going to want alternative-patch based on it.
No functional change.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 21:04:17 +0100
Subject: xen/softirq: Rework arch_skip_send_event_check() into
arch_set_softirq()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
x86 is the only architecture wanting an optimisation here, but the test_and_set_bit() is a store into the monitored line (i.e. will wake up the target) and, prior to the removal of the broken IPI-elision algorithm, was racy, causing unnecessary IPIs to be sent.
To do this in a race-free way, the store to the monited line needs to also sample the status of the target in one atomic action. Implement a new arch helper with different semantics; to make the softirq pending and decide about IPIs together. For now, implement the default helper. It will be overridden by x86 in a subsequent change.
No functional change.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 21:26:24 +0100
Subject: x86/idle: Implement a new MWAIT IPI-elision algorithm
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
In order elide IPIs, we must be able to identify whether a target CPU is in MWAIT at the point it is woken up. i.e. the store to wake it up must also identify the state.
Create a new in_mwait variable beside __softirq_pending, so we can use a CMPXCHG to set the softirq while also observing the status safely. Implement an x86 version of arch_pend_softirq() which does this.
In mwait_idle_with_hints(), advertise in_mwait, with an explanation of precisely what it means. X86_BUG_MONITOR can be accounted for simply by not advertising in_mwait.
xen/arch/x86/include/asm/softirq.h +48 -0
48 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Wed, 2 Jul 2025 14:51:38 +0100
Subject: x86/idle: Fix buggy "x86/mwait-idle: enable interrupts before C1 on
Xeons"
The check of this_softirq_pending must be performed with irqs disabled, but this property was broken by an attempt to optimise entry/exit latency.
Commit c227233ad64c in Linux (which we copied into Xen) was fixed up by edc8fc01f608 in Linux, which we have so far missed.
Going to sleep without waking on interrupts is nonsensical outside of play_dead(), so overload this to select between two possible MWAITs, the second using the STI shadow to cover MWAIT for exactly the same reason as we do in safe_halt().
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Jun 2025 17:19:19 +0100
Subject: 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.
xen/arch/x86/cpu-policy.c +37 -32
69 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 10 Sep 2024 19:55:15 +0100
Subject: x86/cpu-policy: Infrastructure for CPUID leaf 0x80000021.ecx
xen/include/public/arch-x86/cpufeatureset.h +2 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Sep 2024 11:28:39 +0100
Subject: x86/ucode: Digests for TSA microcode
AMD are releasing microcode for TSA, so extend the known-provenance list with their hashes. These were produced before the remediation of the microcode signature issues (the entrysign vulnerability), so can be OS-loaded on out-of-date firmware.
Include an off-by-default check for the sorted-ness of patch_digests[]. It's not worth running generally under SELF_TESTS, but is useful when editing the digest list.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
xen/arch/x86/cpu/microcode/amd-patch-digests.c +144 -0
144 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Wed, 2 Apr 2025 03:18:59 +0100
Subject: x86/idle: Rearrange VERW and MONITOR in mwait_idle_with_hints()
In order to mitigate TSA, Xen will need to issue VERW before going idle.
On AMD CPUs, the VERW scrubbing side effects cancel an active MONITOR, causing the MWAIT to exit without entering an idle state. Therefore the VERW must be ahead of MONITOR.
Split spec_ctrl_enter_idle() in two and allow the VERW aspect to be handled separately. While adjusting, update a stale comment concerning MSBDS; more issues have been mitigated using VERW since it was written.
By moving VERW earlier, it is ahead of the determination of whether to go idle. We can't move the check on softirq_pending (for correctness reasons), but we can duplicate it earlier as a best effort attempt to skip the speculative overhead.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Thu, 29 Aug 2024 17:36:11 +0100
Subject: x86/spec-ctrl: Mitigate Transitive Scheduler Attacks
TSA affects AMD Fam19h CPUs (Zen3 and 4 microarchitectures).
Three new CPUID bits have been defined. Two (TSA_SQ_NO and TSA_L1_NO) indicate that the system is unaffected, and must be synthesised by Xen on unaffected parts to date.
A third new bit indicates that VERW now has a flushing side effect. Xen must synthesise this bit on affected systems based on microcode version. As with other VERW-based flushing features, VERW_CLEAR needs OR-ing across a resource pool, and guests which have seen it can safely migrate in.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
xen/arch/x86/spec_ctrl.c +102 -12
114 lines not on this page · raw message
xen/include/public/arch-x86/cpufeatureset.h +3 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Apr 2025 14:59:01 +0100
Subject: x86/idle: Move monitor()/mwait() wrappers into cpu-idle.c
They're not used by any other translation unit, so shouldn't live in asm/processor.h, which is included almost everywhere.
Our new toolchain baseline knows the MONITOR/MWAIT instructions, so use them directly rather than using raw hex.
Change the hint/extention parameters from long to int. They're specified to remain 32bit operands even 64-bit mode.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Apr 2025 15:55:29 +0100
Subject: x86/idle: Remove MFENCEs for CLFLUSH_MONITOR
Commit 48d32458bcd4 ("x86, idle: add barriers to CLFLUSH workaround") was inherited from Linux and added MFENCEs around the AAI65 errata fix.
The SDM now states:
Executions of the CLFLUSH instruction are ordered with respect to each other and with respect to writes, locked read-modify-write instructions, and fence instructions[1].
with footnote 1 reading:
Earlier versions of this manual specified that executions of the CLFLUSH instruction were ordered only by the MFENCE instruction. All processors implementing the CLFLUSH instruction also order it relative to the other operations enumerated above.
I.e. the MFENCEs came about because of an incorrect statement in the SDM.
The Spec Update (no longer available on Intel's website) simply says "issue a CLFLUSH", with no mention of MFENCEs.
As this erratum is specific to Intel, it's fine to remove the the MFENCEs; AMD CPUs of a similar vintage do sport otherwise-unordered CLFLUSHs.
Move the feature bit into the BUG range (rather than FEATURE), and move the workaround into monitor() itself.
The erratum check itself must use setup_force_cpu_cap(). It needs activating if any CPU needs it, not if all of them need it.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 24 Jun 2025 15:20:52 +0100
Subject: Revert part of "x86/mwait-idle: disable IBRS during long idle"
Most of the patch (handling of CPUIDLE_FLAG_IBRS) is fine, but the adjustements to mwait_idle() are not; spec_ctrl_enter_idle() does more than just alter MSR_SPEC_CTRL.IBRS.
The only reason this doesn't need an XSA is because the unconditional spec_ctrl_{enter,exit}_idle() in mwait_idle_with_hints() were left unaltered, and thus the MWAIT remained properly protected.
There (would have been) two problems. In the ibrs_disable (== deep C) case:
* On entry, VERW and RSB-stuffing are architecturally skipped.
* On exit, there's a branch crossing the WRMSR which reinstates the speculative safety for indirect branches.
All this change did was double up the expensive operations in the deep C case, and fail to optimise the intended case.
I have an idea of how to plumb this more nicely, but it requires larger changes to legacy IBRS handling to not make spec_ctrl_enter_idle() vulnerable in other ways. In the short term, simply take out the perf hit.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Jun 2025 14:46:01 +0100
Subject: x86/cpu-policy: Simplify logic in
guest_common_default_feature_adjustments()
For features which are unconditionally set in the max policies, making the default policy to match the host can be done with a conditional clear.
This is simpler than the unconditional clear, conditional set currently performed.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 15:51:53 +0100
Subject: x86/idle: Remove broken MWAIT implementation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
cpuidle_wakeup_mwait() is a TOCTOU race. The cpumask_and() sampling cpuidle_mwait_flags can take a arbitrary period of time, and there's no guarantee that the target CPUs are still in MWAIT when writing into mwait_wakeup(cpu).
The consequence of the race is that we'll fail to IPI certain targets. Also, there's no guarantee that mwait_idle_with_hints() will raise a TIMER_SOFTIRQ on it's way out.
The fundamental bug is that the "in_mwait" variable needs to be in the monitored line, and not in a separate cpuidle_mwait_flags variable, in order to do this in a race-free way.
Arranging to fix this while keeping the old implementation is prohibitive, so strip the current one out in order to implement the new one cleanly. In the interim, this causes IPIs to be used unconditionally which is safe albeit suboptimal.
xen/arch/x86/acpi/cpu_idle.c +5 -43
48 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 18:13:27 +0100
Subject: x86/idle: Drop incorrect smp_mb() in mwait_idle_with_hints()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
With the recent simplifications, it becomes obvious that smp_mb() isn't the right barrier. Strictly speaking, MONITOR is ordered as a load, but smp_rmb() isn't correct either, as this only pertains to local ordering. All we need is a compiler barrier().
Merge the barier() into the monitor() itself, along with an explantion.
No functional change.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 21:40:51 +0100
Subject: x86/idle: Convert force_mwait_ipi_wakeup to X86_BUG_MONITOR
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
We're going to want alternative-patch based on it.
No functional change.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 21:04:17 +0100
Subject: xen/softirq: Rework arch_skip_send_event_check() into
arch_set_softirq()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
x86 is the only architecture wanting an optimisation here, but the test_and_set_bit() is a store into the monitored line (i.e. will wake up the target) and, prior to the removal of the broken IPI-elision algorithm, was racy, causing unnecessary IPIs to be sent.
To do this in a race-free way, the store to the monited line needs to also sample the status of the target in one atomic action. Implement a new arch helper with different semantics; to make the softirq pending and decide about IPIs together. For now, implement the default helper. It will be overridden by x86 in a subsequent change.
No functional change.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 1 Jul 2025 21:26:24 +0100
Subject: x86/idle: Implement a new MWAIT IPI-elision algorithm
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
In order elide IPIs, we must be able to identify whether a target CPU is in MWAIT at the point it is woken up. i.e. the store to wake it up must also identify the state.
Create a new in_mwait variable beside __softirq_pending, so we can use a CMPXCHG to set the softirq while also observing the status safely. Implement an x86 version of arch_pend_softirq() which does this.
In mwait_idle_with_hints(), advertise in_mwait, with an explanation of precisely what it means. X86_BUG_MONITOR can be accounted for simply by not advertising in_mwait.
xen/arch/x86/include/asm/softirq.h +48 -0
48 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Wed, 2 Jul 2025 14:51:38 +0100
Subject: x86/idle: Fix buggy "x86/mwait-idle: enable interrupts before C1 on
Xeons"
The check of this_softirq_pending must be performed with irqs disabled, but this property was broken by an attempt to optimise entry/exit latency.
Commit c227233ad64c in Linux (which we copied into Xen) was fixed up by edc8fc01f608 in Linux, which we have so far missed.
Going to sleep without waking on interrupts is nonsensical outside of play_dead(), so overload this to select between two possible MWAITs, the second using the STI shadow to cover MWAIT for exactly the same reason as we do in safe_halt().
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Jun 2025 17:19:19 +0100
Subject: 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.
xen/arch/x86/cpu-policy.c +37 -32
69 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Tue, 10 Sep 2024 19:55:15 +0100
Subject: x86/cpu-policy: Infrastructure for CPUID leaf 0x80000021.ecx
xen/include/public/arch-x86/cpufeatureset.h +2 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Fri, 27 Sep 2024 11:28:39 +0100
Subject: x86/ucode: Digests for TSA microcode
AMD are releasing microcode for TSA, so extend the known-provenance list with their hashes. These were produced before the remediation of the microcode signature issues (the entrysign vulnerability), so can be OS-loaded on out-of-date firmware.
Include an off-by-default check for the sorted-ness of patch_digests[]. It's not worth running generally under SELF_TESTS, but is useful when editing the digest list.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
xen/arch/x86/cpu/microcode/amd-patch-digests.c +144 -0
144 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Wed, 2 Apr 2025 03:18:59 +0100
Subject: x86/idle: Rearrange VERW and MONITOR in mwait_idle_with_hints()
In order to mitigate TSA, Xen will need to issue VERW before going idle.
On AMD CPUs, the VERW scrubbing side effects cancel an active MONITOR, causing the MWAIT to exit without entering an idle state. Therefore the VERW must be ahead of MONITOR.
Split spec_ctrl_enter_idle() in two and allow the VERW aspect to be handled separately. While adjusting, update a stale comment concerning MSBDS; more issues have been mitigated using VERW since it was written.
By moving VERW earlier, it is ahead of the determination of whether to go idle. We can't move the check on softirq_pending (for correctness reasons), but we can duplicate it earlier as a best effort attempt to skip the speculative overhead.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Thu, 29 Aug 2024 17:36:11 +0100
Subject: x86/spec-ctrl: Mitigate Transitive Scheduler Attacks
TSA affects AMD Fam19h CPUs (Zen3 and 4 microarchitectures).
Three new CPUID bits have been defined. Two (TSA_SQ_NO and TSA_L1_NO) indicate that the system is unaffected, and must be synthesised by Xen on unaffected parts to date.
A third new bit indicates that VERW now has a flushing side effect. Xen must synthesise this bit on affected systems based on microcode version. As with other VERW-based flushing features, VERW_CLEAR needs OR-ing across a resource pool, and guests which have seen it can safely migrate in.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
xen/arch/x86/spec_ctrl.c +102 -12
114 lines not on this page · raw message
xen/include/public/arch-x86/cpufeatureset.h +3 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Wed, 2 Apr 2025 03:18:59 +0100
Subject: x86/idle: Rearrange VERW and MONITOR in mwait_idle_with_hints()
In order to mitigate TSA, Xen will need to issue VERW before going idle.
On AMD CPUs, the VERW scrubbing side effects cancel an active MONITOR, causing the MWAIT to exit without entering an idle state. Therefore the VERW must be ahead of MONITOR.
Split spec_ctrl_enter_idle() in two and allow the VERW aspect to be handled separately. While adjusting, update a stale comment concerning MSBDS; more issues have been mitigated using VERW since it was written.
By moving VERW earlier, it is ahead of the determination of whether to go idle. We can't move the check on softirq_pending (for correctness reasons), but we can duplicate it earlier as a best effort attempt to skip the speculative overhead.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
The rest of this diff is not shown. View the raw message.
From: Andrew Cooper <[email protected]>
Date: Thu, 29 Aug 2024 17:36:11 +0100
Subject: x86/spec-ctrl: Mitigate Transitive Scheduler Attacks
TSA affects AMD Fam19h CPUs (Zen3 and 4 microarchitectures).
Three new CPUID bits have been defined. Two (TSA_SQ_NO and TSA_L1_NO) indicate that the system is unaffected, and must be synthesised by Xen on unaffected parts to date.
A third new bit indicates that VERW now has a flushing side effect. Xen must synthesise this bit on affected systems based on microcode version. As with other VERW-based flushing features, VERW_CLEAR needs OR-ing across a resource pool, and guests which have seen it can safely migrate in.
This is part of XSA-471 / CVE-2024-36350 / CVE-2024-36357.
xen/arch/x86/spec_ctrl.c +102 -12
114 lines not on this page · raw message
xen/include/public/arch-x86/cpufeatureset.h +3 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.