]> xenbits.xensource.com Git - xen.git/commitdiff
x86/spec-ctrl: Expose IPRED_CTRL to guests
authorRoger Pau Monné <roger.pau@citrix.com>
Tue, 30 Jan 2024 09:13:58 +0000 (10:13 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 9 Apr 2024 16:10:28 +0000 (17:10 +0100)
The CPUID feature bit signals the presence of the IPRED_DIS_{U,S} controls in
SPEC_CTRL MSR, first available in Intel AlderLake and Sapphire Rapids CPUs.

Xen already knows how to context switch MSR_SPEC_CTRL properly between guest
and hypervisor context.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
(cherry picked from commit 4dd6760706848de30f7c8b5f83462b9bcb070c91)

tools/misc/xen-cpuid.c
xen/arch/x86/msr.c
xen/include/asm-x86/msr-index.h
xen/include/public/arch-x86/cpufeatureset.h
xen/tools/gen-cpuid.py

index 0c792679e594610897a9f99c3cb911c151209b84..e59e17c722e75ab981b0304f3b4c71f8d4ad3502 100644 (file)
@@ -212,7 +212,7 @@ static const char *const str_7d1[32] =
 
 static const char *const str_7d2[32] =
 {
-    [ 0] = "intel-psfd",
+    [ 0] = "intel-psfd",    [ 1] = "ipred-ctrl",
 };
 
 static const char *const str_m10Al[32] =
index 22f86f2785d8239c56f769f5abb083498ab49531..91b7402fba780cf2e44096759df305c1d9b248ec 100644 (file)
@@ -306,8 +306,8 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)
 
 /*
  * Caller to confirm that MSR_SPEC_CTRL is available.  Intel and AMD have
- * separate CPUID features for this functionality, but only set will be
- * active.
+ * separate CPUID features for some of this functionality, but only one
+ * vendors-worth will be active on a single host.
  */
 uint64_t msr_spec_ctrl_valid_bits(const struct cpu_policy *cp)
 {
@@ -321,6 +321,8 @@ uint64_t msr_spec_ctrl_valid_bits(const struct cpu_policy *cp)
     return (SPEC_CTRL_IBRS | SPEC_CTRL_STIBP |
             (ssbd       ? SPEC_CTRL_SSBD       : 0) |
             (psfd       ? SPEC_CTRL_PSFD       : 0) |
+            (cp->feat.ipred_ctrl
+             ? (SPEC_CTRL_IPRED_DIS_U | SPEC_CTRL_IPRED_DIS_S) : 0) |
             0);
 }
 
index eb6295d8a7a4379318f6704de642b2538b3dbed7..cab836c88fe5426ab8ab57c86ec2c13fc0dca2dc 100644 (file)
@@ -36,6 +36,8 @@
 #define  SPEC_CTRL_IBRS                     (_AC(1, ULL) <<  0)
 #define  SPEC_CTRL_STIBP                    (_AC(1, ULL) <<  1)
 #define  SPEC_CTRL_SSBD                     (_AC(1, ULL) <<  2)
+#define  SPEC_CTRL_IPRED_DIS_U              (_AC(1, ULL) <<  3)
+#define  SPEC_CTRL_IPRED_DIS_S              (_AC(1, ULL) <<  4)
 #define  SPEC_CTRL_PSFD                     (_AC(1, ULL) <<  7)
 
 #define MSR_PRED_CMD                        0x00000049
index 7a9d8d05d3fbddf2e70de2962b12a7d719e26d10..96601c5c2091122888dddf20be9ee67df4f5a2d0 100644 (file)
@@ -307,6 +307,7 @@ XEN_CPUFEATURE(SRSO_NO,            11*32+29) /*A  Hardware not vulenrable to Spe
 
 /* Intel-defined CPU features, CPUID level 0x00000007:2.edx, word 13 */
 XEN_CPUFEATURE(INTEL_PSFD,         13*32+ 0) /*A  MSR_SPEC_CTRL.PSFD */
+XEN_CPUFEATURE(IPRED_CTRL,         13*32+ 1) /*A  MSR_SPEC_CTRL.IPRED_DIS_* */
 
 /* Intel-defined CPU features, CPUID level 0x00000007:1.ecx, word 14 */
 
index 3ad926322100c9674fe5c674abec044ad3081be5..f68e3ff875df2986b0f42855dfccb3f3a38da00f 100755 (executable)
@@ -317,7 +317,8 @@ def crunch_numbers(state):
         # IBRSB/IBRS, and we pass this MSR directly to guests.  Treating them
         # as dependent features simplifies Xen's logic, and prevents the guest
         # from seeing implausible configurations.
-        IBRSB: [STIBP, SSBD, INTEL_PSFD, EIBRS],
+        IBRSB: [STIBP, SSBD, INTEL_PSFD, EIBRS,
+                IPRED_CTRL],
         IBRS: [AMD_STIBP, AMD_SSBD, PSFD,
                IBRS_ALWAYS, IBRS_FAST, IBRS_SAME_MODE],
         IBPB: [IBPB_RET, SBPB, IBPB_BRTYPE],