Skip to contentSkip to conversation

x86: Introduce MSR_ARCH_CAPS into featuresets

PATCH Superseded Andrew Cooper 2 participants 31 messages May 15, 2023 – May 22, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover x86: Introduce MSR_ARCH_CAPS into featuresets

Also cleanup of the various special cases we've already got. No practical change to a system, but this is the trimmed view of the featuresets on a Cascade Lake CPU with the series in place.

                        KEY ... 10Al     10Ah
  Static sets:
  Known                     ... 01beffff:00000000
  Special                   ... 00080004:00000000
  PV Max                    ... 011ae17f:00000000
  PV Default                ... 011ae17f:00000000
  HVM Shadow Max            ... 011ae17f:00000000
  HVM Shadow Default        ... 011ae17f:00000000
  HVM Hap Max               ... 011ae17f:00000000
  HVM Hap Default           ... 011ae17f:00000000

Dynamic sets:

  Raw                       ... 000aacab:00000000
  Host                      ... 000aacab:00000000
  PV Default                ... 00000000:00000000
  HVM Default               ... 00000000:00000000
  PV Max                    ... 000aa02b:00000000
  HVM Max                   ... 000aa02b:00000000

Andrew Cooper (6):
x86/boot: Rework dom0 feature configuration x86/boot: Adjust MSR_ARCH_CAPS handling for the Host policy x86/cpu-policy: Infrastructure for MSR_ARCH_CAPS x86/cpu-policy: MSR_ARCH_CAPS feature names x86/boot: Record MSR_ARCH_CAPS for the Raw and Host CPU policy x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

 tools/misc/xen-cpuid.c                      | 23 ++++++
 xen/arch/x86/cpu-policy.c                   | 83 ++++++++++-----------
 xen/arch/x86/cpu/common.c                   |  5 ++
 xen/include/public/arch-x86/cpufeatureset.h | 27 +++++++
 xen/include/xen/lib/x86/cpu-policy.h        | 18 ++---
 xen/lib/x86/cpuid.c                         | 11 ++-
 xen/tools/gen-cpuid.py                      |  3 +
 7 files changed, 117 insertions(+), 53 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/6 x86/boot: Rework dom0 feature configuration

Right now, dom0's feature configuration is split between between the common path and a dom0-specific one. This mostly is by accident, and causes some very subtle bugs.

First, start by clearly defining init_dom0_cpuid_policy() to be the domain that Xen builds automatically. The late hwdom case is still constructed in a mostly normal way, with the control domain having full discretion over the CPU policy.

Identifying this highlights a latent bug - the two halves of the MSR_ARCH_CAPS bodge are asymmetric with respect to the hardware domain. This means that shim, or a control-only dom0 sees the MSR_ARCH_CAPS CPUID bit but none of the MSR content. This in turn declares the hardware to be retpoline-safe by failing to advertise the {R,}RSBA bits appropriately. Restrict this logic to the hardware domain, although the special case will cease to exist shortly.

For the CPUID Faulting adjustment, the comment in ctxt_switch_levelling() isn't actually relevant. Provide a better explanation.

Move the recalculate_cpuid_policy() call outside of the dom0-cpuid= case. This is no change for now, but will become necessary shortly.

Finally, place the second half of the MSR_ARCH_CAPS bodge after the recalculate_cpuid_policy() call. This is necessary to avoid transiently breaking the hardware domain's view while the handling is cleaned up. This special case will cease to exist shortly.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/arch/x86/cpu-policy.c | 57 +++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 26 deletions(-)
xen/arch/x86/cpu-policy.c +31 -26
index ef6a2d0d180a..5e7e19fbcda8 100644
@@ -687,29 +687,6 @@ int init_domain_cpu_policy(struct domain *d)
     if ( !p )
         return -ENOMEM;
 
-    /* See comment in ctxt_switch_levelling() */
-    if ( !opt_dom0_cpuid_faulting && is_control_domain(d) && is_pv_domain(d) )
-        p->platform_info.cpuid_faulting = false;
-
-    /*
-     * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0,
-     * so dom0 can turn off workarounds as appropriate.  Temporary, until the
-     * domain policy logic gains a better understanding of MSRs.
-     */
-    if ( is_hardware_domain(d) && cpu_has_arch_caps )
-    {
-        uint64_t val;
-
-        rdmsrl(MSR_ARCH_CAPABILITIES, val);
-
-        p->arch_caps.raw = val &
-            (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
-             ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO | ARCH_CAPS_IF_PSCHANGE_MC_NO |
-             ARCH_CAPS_TAA_NO | ARCH_CAPS_SBDR_SSDP_NO | ARCH_CAPS_FBSDP_NO |
-             ARCH_CAPS_PSDP_NO | ARCH_CAPS_FB_CLEAR | ARCH_CAPS_RRSBA |
-             ARCH_CAPS_BHI_NO | ARCH_CAPS_PBRSB_NO);
-    }
-
     d->arch.cpu_policy = p;
 
     recalculate_cpuid_policy(d);
@@ -845,11 +822,15 @@ void recalculate_cpuid_policy(struct domain *d)
         p->extd.raw[0x19] = EMPTY_LEAF;
 }
 
+/*
+ * Adjust the CPU policy for dom0.  Really, this is "the domain Xen builds
+ * automatically on boot", and might not have the domid 0 (e.g. pvshim).
+ */
 void __init init_dom0_cpuid_policy(struct domain *d)
 {
     struct cpu_policy *p = d->arch.cpuid;
 
-    /* dom0 can't migrate.  Give it ITSC if available. */
+    /* Dom0 doesn't migrate relative to Xen.  Give it ITSC if available. */
     if ( cpu_has_itsc )
         p->extd.itsc = true;
 
@@ -858,7 +839,7 @@ void __init init_dom0_cpuid_policy(struct domain *d)
      * so dom0 can turn off workarounds as appropriate.  Temporary, until the
      * domain policy logic gains a better understanding of MSRs.
      */
-    if ( cpu_has_arch_caps )
+    if ( is_hardware_domain(d) && cpu_has_arch_caps )
         p->feat.arch_caps = true;
 
     /* Apply dom0-cpuid= command line settings, if provided. */
@@ -876,8 +857,32 @@ void __init init_dom0_cpuid_policy(struct domain *d)
         }
 
         x86_cpu_featureset_to_policy(fs, p);
+    }
+
+    /*
+     * PV Control domains used to require unfiltered CPUID.  This was fixed in
+     * Xen 4.13, but there is an cmdline knob to restore the prior behaviour.
+     *
+     * If the domain is getting unfiltered CPUID, don't let the guest kernel
+     * play with CPUID faulting either, as Xen's CPUID path won't cope.
+     */
+    if ( !opt_dom0_cpuid_faulting && is_control_domain(d) && is_pv_domain(d) )
+        p->platform_info.cpuid_faulting = false;
 
-        recalculate_cpuid_policy(d);
+    recalculate_cpuid_policy(d);
+
+    if ( is_hardware_domain(d) && cpu_has_arch_caps )
+    {
+        uint64_t val;
+
+        rdmsrl(MSR_ARCH_CAPABILITIES, val);
+
+        p->arch_caps.raw = val &
+            (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
+             ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO | ARCH_CAPS_IF_PSCHANGE_MC_NO |
+             ARCH_CAPS_TAA_NO | ARCH_CAPS_SBDR_SSDP_NO | ARCH_CAPS_FBSDP_NO |
+             ARCH_CAPS_PSDP_NO | ARCH_CAPS_FB_CLEAR | ARCH_CAPS_RRSBA |
+             ARCH_CAPS_BHI_NO | ARCH_CAPS_PBRSB_NO);
     }
 }
 
Signature · 1 line
2.30.2
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] x86/boot: Rework dom0 feature configuration

Quoted 22 lines · Andrew Cooper

Right now, dom0's feature configuration is split between between the common path and a dom0-specific one. This mostly is by accident, and causes some very subtle bugs.

First, start by clearly defining init_dom0_cpuid_policy() to be the domain that Xen builds automatically. The late hwdom case is still constructed in a mostly normal way, with the control domain having full discretion over the CPU policy.

Identifying this highlights a latent bug - the two halves of the MSR_ARCH_CAPS bodge are asymmetric with respect to the hardware domain. This means that shim, or a control-only dom0 sees the MSR_ARCH_CAPS CPUID bit but none of the MSR content. This in turn declares the hardware to be retpoline-safe by failing to advertise the {R,}RSBA bits appropriately. Restrict this logic to the hardware domain, although the special case will cease to exist shortly.

For the CPUID Faulting adjustment, the comment in ctxt_switch_levelling() isn't actually relevant. Provide a better explanation.

Move the recalculate_cpuid_policy() call outside of the dom0-cpuid= case. This is no change for now, but will become necessary shortly.

Quoted 6 lines

Finally, place the second half of the MSR_ARCH_CAPS bodge after the recalculate_cpuid_policy() call. This is necessary to avoid transiently breaking the hardware domain's view while the handling is cleaned up. This special case will cease to exist shortly.

with one question / suggestion:

xen/arch/x86/cpu-policy.c void __init init_dom0_cpuid_policy(struct domain *d) · line 843

Quoted 7 lines
xen/arch/x86/cpu-policy.c +1 -1
@@ -858,7 +839,7 @@ void __init init_dom0_cpuid_policy(struct domain *d)
      * so dom0 can turn off workarounds as appropriate.  Temporary, until the
      * domain policy logic gains a better understanding of MSRs.
      */
-    if ( cpu_has_arch_caps )
+    if ( is_hardware_domain(d) && cpu_has_arch_caps )
         p->feat.arch_caps = true;

As a result of this, ...

Quoted 10 lines
xen/arch/x86/cpu-policy.c +6 -0
@@ -876,8 +857,32 @@ void __init init_dom0_cpuid_policy(struct domain *d)
         }
 
         x86_cpu_featureset_to_policy(fs, p);
+    }
+
+    /*
+     * PV Control domains used to require unfiltered CPUID.  This was fixed in
+     * Xen 4.13, but there is an cmdline knob to restore the prior behaviour.
+     *

xen/arch/x86/cpu-policy.c void __init init_dom0_cpuid_policy(struct domain *d) · line 874

Quoted 10 lines
xen/arch/x86/cpu-policy.c +8 -1
+     * If the domain is getting unfiltered CPUID, don't let the guest kernel
+     * play with CPUID faulting either, as Xen's CPUID path won't cope.
+     */
+    if ( !opt_dom0_cpuid_faulting && is_control_domain(d) && is_pv_domain(d) )
+        p->platform_info.cpuid_faulting = false;
 
-        recalculate_cpuid_policy(d);
+    recalculate_cpuid_policy(d);
+
+    if ( is_hardware_domain(d) && cpu_has_arch_caps )

... it would feel slightly more logical if p->feat.arch_caps was used here. Whether that's to replace the entire condition or merely the right side of the && depends on what the subsequent changes require (which I haven't looked at yet).

Jan

Quoted 14 lines
xen/arch/x86/cpu-policy.c +11 -0
+    {
+        uint64_t val;
+
+        rdmsrl(MSR_ARCH_CAPABILITIES, val);
+
+        p->arch_caps.raw = val &
+            (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
+             ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO | ARCH_CAPS_IF_PSCHANGE_MC_NO |
+             ARCH_CAPS_TAA_NO | ARCH_CAPS_SBDR_SSDP_NO | ARCH_CAPS_FBSDP_NO |
+             ARCH_CAPS_PSDP_NO | ARCH_CAPS_FB_CLEAR | ARCH_CAPS_RRSBA |
+             ARCH_CAPS_BHI_NO | ARCH_CAPS_PBRSB_NO);
     }
 }
 
#3 lore raw

Re: [PATCH 1/6] x86/boot: Rework dom0 feature configuration

Quoted 23 lines · Jan Beulich
Quoted 22 lines · Andrew Cooper

Right now, dom0's feature configuration is split between between the common path and a dom0-specific one. This mostly is by accident, and causes some very subtle bugs.

First, start by clearly defining init_dom0_cpuid_policy() to be the domain that Xen builds automatically. The late hwdom case is still constructed in a mostly normal way, with the control domain having full discretion over the CPU policy.

Identifying this highlights a latent bug - the two halves of the MSR_ARCH_CAPS bodge are asymmetric with respect to the hardware domain. This means that shim, or a control-only dom0 sees the MSR_ARCH_CAPS CPUID bit but none of the MSR content. This in turn declares the hardware to be retpoline-safe by failing to advertise the {R,}RSBA bits appropriately. Restrict this logic to the hardware domain, although the special case will cease to exist shortly.

For the CPUID Faulting adjustment, the comment in ctxt_switch_levelling() isn't actually relevant. Provide a better explanation.

Move the recalculate_cpuid_policy() call outside of the dom0-cpuid= case. This is no change for now, but will become necessary shortly.

Quoted 7 lines
Quoted 6 lines

Finally, place the second half of the MSR_ARCH_CAPS bodge after the recalculate_cpuid_policy() call. This is necessary to avoid transiently breaking the hardware domain's view while the handling is cleaned up. This special case will cease to exist shortly.

Thanks.

Quoted 27 lines

with one question / suggestion:

xen/arch/x86/cpu-policy.c void __init init_dom0_cpuid_policy(struct domain *d) · line 843

Quoted 7 lines
xen/arch/x86/cpu-policy.c +1 -1
@@ -858,7 +839,7 @@ void __init init_dom0_cpuid_policy(struct domain *d)
      * so dom0 can turn off workarounds as appropriate.  Temporary, until the
      * domain policy logic gains a better understanding of MSRs.
      */
-    if ( cpu_has_arch_caps )
+    if ( is_hardware_domain(d) && cpu_has_arch_caps )
         p->feat.arch_caps = true;

As a result of this, ...

Quoted 16 lines
xen/arch/x86/cpu-policy.c +11 -0
@@ -876,8 +857,32 @@ void __init init_dom0_cpuid_policy(struct domain *d)
         }
 
         x86_cpu_featureset_to_policy(fs, p);
+    }
+
+    /*
+     * PV Control domains used to require unfiltered CPUID.  This was fixed in
+     * Xen 4.13, but there is an cmdline knob to restore the prior behaviour.
+     *
+     * If the domain is getting unfiltered CPUID, don't let the guest kernel
+     * play with CPUID faulting either, as Xen's CPUID path won't cope.
+     */
+    if ( !opt_dom0_cpuid_faulting && is_control_domain(d) && is_pv_domain(d) )
+        p->platform_info.cpuid_faulting = false;
 
Quoted 8 lines

xen/arch/x86/cpu-policy.c void __init init_dom0_cpuid_policy(struct domain *d) · line 874

Quoted 4 lines
xen/arch/x86/cpu-policy.c +3 -1
-        recalculate_cpuid_policy(d);
+    recalculate_cpuid_policy(d);
+
+    if ( is_hardware_domain(d) && cpu_has_arch_caps )

... it would feel slightly more logical if p->feat.arch_caps was used here. Whether that's to replace the entire condition or merely the right side of the && depends on what the subsequent changes require (which I haven't looked at yet).

I'd really prefer to leave it as-is.

You're likely right, but this entire block is deleted in patch 6 and it has been a giant pain already making this series bisectable WRT all our special cases.

For the sake of a few patches, it's safer to go with it in the pre-existing form.

~Andrew

#4 lore raw

Re: [PATCH 1/6] x86/boot: Rework dom0 feature configuration

Quoted 36 lines · Andrew Cooper
Quoted 26 lines · Jan Beulich

xen/arch/x86/cpu-policy.c void __init init_dom0_cpuid_policy(struct domain *d) · line 843

Quoted 7 lines · Andrew Cooper
xen/arch/x86/cpu-policy.c +1 -1
@@ -858,7 +839,7 @@ void __init init_dom0_cpuid_policy(struct domain *d)
      * so dom0 can turn off workarounds as appropriate.  Temporary, until the
      * domain policy logic gains a better understanding of MSRs.
      */
-    if ( cpu_has_arch_caps )
+    if ( is_hardware_domain(d) && cpu_has_arch_caps )
         p->feat.arch_caps = true;

As a result of this, ...

Quoted 16 lines
xen/arch/x86/cpu-policy.c +11 -0
@@ -876,8 +857,32 @@ void __init init_dom0_cpuid_policy(struct domain *d)
         }
 
         x86_cpu_featureset_to_policy(fs, p);
+    }
+
+    /*
+     * PV Control domains used to require unfiltered CPUID.  This was fixed in
+     * Xen 4.13, but there is an cmdline knob to restore the prior behaviour.
+     *
+     * If the domain is getting unfiltered CPUID, don't let the guest kernel
+     * play with CPUID faulting either, as Xen's CPUID path won't cope.
+     */
+    if ( !opt_dom0_cpuid_faulting && is_control_domain(d) && is_pv_domain(d) )
+        p->platform_info.cpuid_faulting = false;
 
Quoted 8 lines

xen/arch/x86/cpu-policy.c void __init init_dom0_cpuid_policy(struct domain *d) · line 874

Quoted 4 lines
xen/arch/x86/cpu-policy.c +3 -1
-        recalculate_cpuid_policy(d);
+    recalculate_cpuid_policy(d);
+
+    if ( is_hardware_domain(d) && cpu_has_arch_caps )

... it would feel slightly more logical if p->feat.arch_caps was used here. Whether that's to replace the entire condition or merely the right side of the && depends on what the subsequent changes require (which I haven't looked at yet).

Quoted 8 lines

I'd really prefer to leave it as-is.

You're likely right, but this entire block is deleted in patch 6 and it has been a giant pain already making this series bisectable WRT all our special cases.

For the sake of a few patches, it's safer to go with it in the pre-existing form.

Oh, sure, if this goes away anyway, then there's not that much point in making such a change.

Jan

#5 lore raw

PATCH 2/6 x86/boot: Adjust MSR_ARCH_CAPS handling for the Host policy

In reply to Andrew Cooper

We are about to move MSR_ARCH_CAPS into featureset, but the order of operations (copy raw policy, then copy x86_capabilitiles[] in) will end up clobbering the ARCH_CAPS value currently visible in the Host policy.

To avoid this transient breakage, read from raw_cpu_policy rather than modifying it in place. This logic will be removed entirely in due course.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/arch/x86/cpu-policy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/cpu-policy.c +1 -1
index 5e7e19fbcda8..49f5465ec445 100644
@@ -411,7 +411,7 @@ static void __init calculate_host_policy(void)
     p->platform_info.cpuid_faulting = cpu_has_cpuid_faulting;
 
     /* Temporary, until we have known_features[] for feature bits in MSRs. */
-    p->arch_caps.raw &=
+    p->arch_caps.raw = raw_cpu_policy.arch_caps.raw &
         (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
          ARCH_CAPS_SKIP_L1DFL | ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO |
          ARCH_CAPS_IF_PSCHANGE_MC_NO | ARCH_CAPS_TSX_CTRL | ARCH_CAPS_TAA_NO |
Signature · 1 line
2.30.2
Acked-by on v1 2/6
#6 lore raw

Re: [PATCH 2/6] x86/boot: Adjust MSR_ARCH_CAPS handling for the Host policy

Quoted 8 lines · Andrew Cooper

We are about to move MSR_ARCH_CAPS into featureset, but the order of operations (copy raw policy, then copy x86_capabilitiles[] in) will end up clobbering the ARCH_CAPS value currently visible in the Host policy.

To avoid this transient breakage, read from raw_cpu_policy rather than modifying it in place. This logic will be removed entirely in due course.

#7 lore raw

PATCH 3/6 x86/cpu-policy: Infrastructure for MSR_ARCH_CAPS

In reply to Andrew Cooper

Bits through 24 are already defined, meaning that we're not far off needing the second word. Put both in right away.

The bool bitfield names in the arch_caps union are unused, and somewhat out of date. They'll shortly be automatically generated.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

---
 tools/misc/xen-cpuid.c                      | 10 ++++++++++
 xen/include/public/arch-x86/cpufeatureset.h |  4 ++++
 xen/include/xen/lib/x86/cpu-policy.h        | 18 ++++++++----------
 xen/lib/x86/cpuid.c                         |  4 ++++
 4 files changed, 26 insertions(+), 10 deletions(-)
tools/misc/xen-cpuid.c +10 -0
index 8ec143ebc854..258584aafb9f 100644
@@ -226,6 +226,14 @@ static const char *const str_7d2[32] =
     [ 4] = "bhi-ctrl",      [ 5] = "mcdt-no",
 };
 
+static const char *const str_10Al[32] =
+{
+};
+
+static const char *const str_10Ah[32] =
+{
+};
+
 static const struct {
     const char *name;
     const char *abbr;
@@ -248,6 +256,8 @@ static const struct {
     { "0x00000007:2.edx", "7d2", str_7d2 },
     { "0x00000007:1.ecx", "7c1", str_7c1 },
     { "0x00000007:1.edx", "7d1", str_7d1 },
+    { "0x0000010a.lo",   "10Al", str_10Al },
+    { "0x0000010a.hi",   "10Ah", str_10Ah },
 };
 
 #define COL_ALIGN "18"
xen/include/public/arch-x86/cpufeatureset.h +4 -0
index 8de73aebc3e0..032cec3ccba2 100644
@@ -307,6 +307,10 @@ XEN_CPUFEATURE(AVX_VNNI_INT8,      15*32+ 4) /*A  AVX-VNNI-INT8 Instructions */
 XEN_CPUFEATURE(AVX_NE_CONVERT,     15*32+ 5) /*A  AVX-NE-CONVERT Instructions */
 XEN_CPUFEATURE(CET_SSS,            15*32+18) /*   CET Supervisor Shadow Stacks safe to use */
 
+/* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.eax, word 16 */
+
+/* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.edx, word 17 */
+
 #endif /* XEN_CPUFEATURE */
 
 /* Clean up from a default include.  Close the enum (for C). */
xen/include/xen/lib/x86/cpu-policy.h +8 -10
index bfa425060464..9b51f8330f92 100644
@@ -20,6 +20,8 @@
 #define FEATURESET_7d2   13 /* 0x00000007:2.edx    */
 #define FEATURESET_7c1   14 /* 0x00000007:1.ecx    */
 #define FEATURESET_7d1   15 /* 0x00000007:1.edx    */
+#define FEATURESET_10Al  16 /* 0x0000010a.eax      */
+#define FEATURESET_10Ah  17 /* 0x0000010a.edx      */
 
 struct cpuid_leaf
 {
@@ -350,17 +352,13 @@ struct cpu_policy
      * fixed in hardware.
      */
     union {
-        uint32_t raw;
+        uint64_t raw;
+        struct {
+            uint32_t lo, hi;
+        };
         struct {
-            bool rdcl_no:1;
-            bool ibrs_all:1;
-            bool rsba:1;
-            bool skip_l1dfl:1;
-            bool ssb_no:1;
-            bool mds_no:1;
-            bool if_pschange_mc_no:1;
-            bool tsx_ctrl:1;
-            bool taa_no:1;
+            DECL_BITFIELD(10Al);
+            DECL_BITFIELD(10Ah);
         };
     } arch_caps;
 
xen/lib/x86/cpuid.c +4 -0
index 68aafb404927..a9f31858aeff 100644
@@ -79,6 +79,8 @@ void x86_cpu_policy_to_featureset(
     fs[FEATURESET_7d2]       = p->feat._7d2;
     fs[FEATURESET_7c1]       = p->feat._7c1;
     fs[FEATURESET_7d1]       = p->feat._7d1;
+    fs[FEATURESET_10Al]      = p->arch_caps.lo;
+    fs[FEATURESET_10Ah]      = p->arch_caps.hi;
 }
 
 void x86_cpu_featureset_to_policy(
@@ -100,6 +102,8 @@ void x86_cpu_featureset_to_policy(
     p->feat._7d2             = fs[FEATURESET_7d2];
     p->feat._7c1             = fs[FEATURESET_7c1];
     p->feat._7d1             = fs[FEATURESET_7d1];
+    p->arch_caps.lo          = fs[FEATURESET_10Al];
+    p->arch_caps.hi          = fs[FEATURESET_10Ah];
 }
 
 void x86_cpu_policy_recalc_synth(struct cpu_policy *p)
Signature · 1 line
2.30.2
#8 lore raw

Re: [PATCH 3/6] x86/cpu-policy: Infrastructure for MSR_ARCH_CAPS

Quoted 7 lines · Andrew Cooper

Bits through 24 are already defined, meaning that we're not far off needing the second word. Put both in right away.

The bool bitfield names in the arch_caps union are unused, and somewhat out of date. They'll shortly be automatically generated.

I'm largely okay, but I'd like to raise a couple of naming / presentation questions:

Quoted 18 lines
tools/misc/xen-cpuid.c +8 -0
@@ -226,6 +226,14 @@ static const char *const str_7d2[32] =
     [ 4] = "bhi-ctrl",      [ 5] = "mcdt-no",
 };
 
+static const char *const str_10Al[32] =
+{
+};
+
+static const char *const str_10Ah[32] =
+{
+};
+
 static const struct {
     const char *name;
     const char *abbr;

tools/misc/xen-cpuid.c static const struct { · line 260

Quoted 5 lines
tools/misc/xen-cpuid.c +2 -0
@@ -248,6 +256,8 @@ static const struct {
     { "0x00000007:2.edx", "7d2", str_7d2 },
     { "0x00000007:1.ecx", "7c1", str_7c1 },
     { "0x00000007:1.edx", "7d1", str_7d1 },
+    { "0x0000010a.lo",   "10Al", str_10Al },
+    { "0x0000010a.hi",   "10Ah", str_10Ah },

The MSR-ness can certainly be inferred from the .lo / .hi and l/h suffixes of the strings, but I wonder whether having it e.g. like

    { "MSR0000010a.lo",   "m10Al", str_10Al },
    { "MSR0000010a.hi",   "m10Ah", str_10Ah },

or

    { "MSR[010a].lo",   "m10Al", str_10Al },
    { "MSR[010a].hi",   "m10Ah", str_10Ah },

or even

    { "ARCH_CAPS.lo",   "m10Al", str_10Al },
    { "ARCH_CAPS.hi",   "m10Ah", str_10Ah },

wouldn't make it more obvious. For the two str_*, see below.

xen/include/public/arch-x86/cpufeatureset.h XEN_CPUFEATURE(AVX_VNNI_INT8, 15*32+ 4) /*A AVX-VNNI-INT8 Instructions */ · line 312

Quoted 9 lines
xen/include/public/arch-x86/cpufeatureset.h +3 -0
@@ -307,6 +307,10 @@ XEN_CPUFEATURE(AVX_VNNI_INT8,      15*32+ 4) /*A  AVX-VNNI-INT8 Instructions */
 XEN_CPUFEATURE(AVX_NE_CONVERT,     15*32+ 5) /*A  AVX-NE-CONVERT Instructions */
 XEN_CPUFEATURE(CET_SSS,            15*32+18) /*   CET Supervisor Shadow Stacks safe to use */
 
+/* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.eax, word 16 */
+
+/* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.edx, word 17 */

Right here I'd be inclined to omit the MSR index; the name ought to be sufficient.

xen/include/xen/lib/x86/cpu-policy.h line 24

Quoted 8 lines
xen/include/xen/lib/x86/cpu-policy.h +2 -0
@@ -20,6 +20,8 @@
 #define FEATURESET_7d2   13 /* 0x00000007:2.edx    */
 #define FEATURESET_7c1   14 /* 0x00000007:1.ecx    */
 #define FEATURESET_7d1   15 /* 0x00000007:1.edx    */
+#define FEATURESET_10Al  16 /* 0x0000010a.eax      */
+#define FEATURESET_10Ah  17 /* 0x0000010a.edx      */

Just like we use an "e" prefix for extended CPUID leaves, perhaps use an "m" prefix for MSRs (then also affecting e.g. the str_* above)?

Jan

#9 lore raw

Re: [PATCH 3/6] x86/cpu-policy: Infrastructure for MSR_ARCH_CAPS

Quoted 45 lines · Jan Beulich
Quoted 7 lines · Andrew Cooper

Bits through 24 are already defined, meaning that we're not far off needing the second word. Put both in right away.

The bool bitfield names in the arch_caps union are unused, and somewhat out of date. They'll shortly be automatically generated.

I'm largely okay, but I'd like to raise a couple of naming / presentation questions:

Quoted 18 lines
tools/misc/xen-cpuid.c +8 -0
@@ -226,6 +226,14 @@ static const char *const str_7d2[32] =
     [ 4] = "bhi-ctrl",      [ 5] = "mcdt-no",
 };
 
+static const char *const str_10Al[32] =
+{
+};
+
+static const char *const str_10Ah[32] =
+{
+};
+
 static const struct {
     const char *name;
     const char *abbr;

tools/misc/xen-cpuid.c static const struct { · line 260

Quoted 5 lines
tools/misc/xen-cpuid.c +2 -0
@@ -248,6 +256,8 @@ static const struct {
     { "0x00000007:2.edx", "7d2", str_7d2 },
     { "0x00000007:1.ecx", "7c1", str_7c1 },
     { "0x00000007:1.edx", "7d1", str_7d1 },
+    { "0x0000010a.lo",   "10Al", str_10Al },
+    { "0x0000010a.hi",   "10Ah", str_10Ah },

The MSR-ness can certainly be inferred from the .lo / .hi and l/h suffixes of the strings, but I wonder whether having it e.g. like

    { "MSR0000010a.lo",   "m10Al", str_10Al },
    { "MSR0000010a.hi",   "m10Ah", str_10Ah },

or

    { "MSR[010a].lo",   "m10Al", str_10Al },
    { "MSR[010a].hi",   "m10Ah", str_10Ah },
Quoted 6 lines

or even

    { "ARCH_CAPS.lo",   "m10Al", str_10Al },
    { "ARCH_CAPS.hi",   "m10Ah", str_10Ah },

wouldn't make it more obvious.

Well, it's takes something which is consistent, and introduces inconsistencies.

The e is logically part of the leaf number, so using m for MSRs is not equivalent.  If you do want to prefix MSRs, you need to prefix the non-extended leaves, and c isn't obviously CPUID when there's the Centaur range at 0xC000xxxx

Nor can you reasonably have MSR[...] in the long names without CPUID[...] too, and that's taking some pretty long lines and making them even longer.

Quoted 8 lines

For the two str_*, see below.

Quoted 6 lines
xen/include/public/arch-x86/cpufeatureset.h +0 -0
@@ -307,6 +307,10 @@ XEN_CPUFEATURE(AVX_VNNI_INT8,      15*32+ 4) /*A  AVX-VNNI-INT8 Instructions */
 XEN_CPUFEATURE(AVX_NE_CONVERT,     15*32+ 5) /*A  AVX-NE-CONVERT Instructions */
 XEN_CPUFEATURE(CET_SSS,            15*32+18) /*   CET Supervisor Shadow Stacks safe to use */
 
Quoted 5 lines

xen/include/public/arch-x86/cpufeatureset.h XEN_CPUFEATURE(AVX_VNNI_INT8, 15*32+ 4) /*A AVX-VNNI-INT8 Instructions */ · line 312

Quoted 3 lines
xen/include/public/arch-x86/cpufeatureset.h +3 -0
+/* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.eax, word 16 */
+
+/* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.edx, word 17 */

Right here I'd be inclined to omit the MSR index; the name ought to be sufficient.

It doesn't hurt to have it, and it it might be helpful for people who don't know the indices off by heart.

~Andrew

#10 lore raw

Re: [PATCH 3/6] x86/cpu-policy: Infrastructure for MSR_ARCH_CAPS

Quoted 56 lines · Andrew Cooper
Quoted 45 lines · Jan Beulich
Quoted 7 lines · Andrew Cooper

Bits through 24 are already defined, meaning that we're not far off needing the second word. Put both in right away.

The bool bitfield names in the arch_caps union are unused, and somewhat out of date. They'll shortly be automatically generated.

I'm largely okay, but I'd like to raise a couple of naming / presentation questions:

Quoted 18 lines
tools/misc/xen-cpuid.c +8 -0
@@ -226,6 +226,14 @@ static const char *const str_7d2[32] =
     [ 4] = "bhi-ctrl",      [ 5] = "mcdt-no",
 };
 
+static const char *const str_10Al[32] =
+{
+};
+
+static const char *const str_10Ah[32] =
+{
+};
+
 static const struct {
     const char *name;
     const char *abbr;

tools/misc/xen-cpuid.c static const struct { · line 260

Quoted 5 lines
tools/misc/xen-cpuid.c +2 -0
@@ -248,6 +256,8 @@ static const struct {
     { "0x00000007:2.edx", "7d2", str_7d2 },
     { "0x00000007:1.ecx", "7c1", str_7c1 },
     { "0x00000007:1.edx", "7d1", str_7d1 },
+    { "0x0000010a.lo",   "10Al", str_10Al },
+    { "0x0000010a.hi",   "10Ah", str_10Ah },

The MSR-ness can certainly be inferred from the .lo / .hi and l/h suffixes of the strings, but I wonder whether having it e.g. like

    { "MSR0000010a.lo",   "m10Al", str_10Al },
    { "MSR0000010a.hi",   "m10Ah", str_10Ah },

or

    { "MSR[010a].lo",   "m10Al", str_10Al },
    { "MSR[010a].hi",   "m10Ah", str_10Ah },
Quoted 6 lines

or even

    { "ARCH_CAPS.lo",   "m10Al", str_10Al },
    { "ARCH_CAPS.hi",   "m10Ah", str_10Ah },

wouldn't make it more obvious.

Well, it's takes something which is consistent, and introduces inconsistencies.

Quoted 8 lines

The e is logically part of the leaf number, so using m for MSRs is not equivalent.  If you do want to prefix MSRs, you need to prefix the non-extended leaves, and c isn't obviously CPUID when there's the Centaur range at 0xC000xxxx

Nor can you reasonably have MSR[...] in the long names without CPUID[...] too, and that's taking some pretty long lines and making them even longer.

I disagree, simply because of the name of the tool we're talking about here. It's all about CPUID, so calling that out isn't relevant. Calling out parts which aren't CPUID is, imo.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
xen/include/public/arch-x86/cpufeatureset.h +0 -0
@@ -307,6 +307,10 @@ XEN_CPUFEATURE(AVX_VNNI_INT8,      15*32+ 4) /*A  AVX-VNNI-INT8 Instructions */
 XEN_CPUFEATURE(AVX_NE_CONVERT,     15*32+ 5) /*A  AVX-NE-CONVERT Instructions */
 XEN_CPUFEATURE(CET_SSS,            15*32+18) /*   CET Supervisor Shadow Stacks safe to use */
 
Quoted 8 lines
Quoted 5 lines

xen/include/public/arch-x86/cpufeatureset.h XEN_CPUFEATURE(AVX_VNNI_INT8, 15*32+ 4) /*A AVX-VNNI-INT8 Instructions */ · line 312

Quoted 3 lines
xen/include/public/arch-x86/cpufeatureset.h +3 -0
+/* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.eax, word 16 */
+
+/* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.edx, word 17 */

Right here I'd be inclined to omit the MSR index; the name ought to be sufficient.

It doesn't hurt to have it, and it it might be helpful for people who don't know the indices off by heart.

I'm one of those who don't, yet I still view the number as odd here. Imo it has no relevance in this context. But anyway, I'm going to accept this part whichever way you want it, while I continue to be unconvinced of the xen-cpuid side of things.

Roger, do you have any opinion here? If you and Andrew agreed, I'd certainly accept that.

Jan

#11 lore raw

PATCH 4/6 x86/cpu-policy: MSR_ARCH_CAPS feature names

In reply to Andrew Cooper

Seed the default visibility from the dom0 special case, which for the most part just exposes the *_NO bits. Insert a block dependency from the ARCH_CAPS CPUID bit to the entire content of the MSR.

The overall CPUID bit is still max-only, so all of MSR_ARCH_CAPS is hidden in the default policies.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

There is no libxl logic because libxl still uses the older xend format which is specific to CPUID data. That is going to need untangling at some other point.

---
 tools/misc/xen-cpuid.c                      | 13 ++++++++++++
 xen/include/public/arch-x86/cpufeatureset.h | 23 +++++++++++++++++++++
 xen/tools/gen-cpuid.py                      |  3 +++
 3 files changed, 39 insertions(+)
tools/misc/xen-cpuid.c +13 -0
index 258584aafb9f..5b717f3f0091 100644
@@ -228,6 +228,19 @@ static const char *const str_7d2[32] =
 
 static const char *const str_10Al[32] =
 {
+    [ 0] = "rdcl-no",             [ 1] = "eibrs",
+    [ 2] = "rsba",                [ 3] = "skip-l1dfl",
+    [ 4] = "intel-ssb-no",        [ 5] = "mds-no",
+    [ 6] = "if-pschange-mc-no",   [ 7] = "tsx-ctrl",
+    [ 8] = "taa-no",              [ 9] = "mcu-ctrl",
+    [10] = "misc-pkg-ctrl",       [11] = "energy-ctrl",
+    [12] = "doitm",               [13] = "sbdr-ssdp-no",
+    [14] = "fbsdp-no",            [15] = "psdp-no",
+    /* 16 */                      [17] = "fb-clear",
+    [18] = "fb-clear-ctrl",       [19] = "rrsba",
+    [20] = "bhi-no",              [21] = "xapic-status",
+    /* 22 */                      [23] = "ovrclk-status",
+    [24] = "pbrsb-no",
 };
 
 static const char *const str_10Ah[32] =
xen/include/public/arch-x86/cpufeatureset.h +23 -0
index 032cec3ccba2..3cfdc71df92b 100644
@@ -308,6 +308,29 @@ XEN_CPUFEATURE(AVX_NE_CONVERT,     15*32+ 5) /*A  AVX-NE-CONVERT Instructions */
 XEN_CPUFEATURE(CET_SSS,            15*32+18) /*   CET Supervisor Shadow Stacks safe to use */
 
 /* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.eax, word 16 */
+XEN_CPUFEATURE(RDCL_NO,            16*32+ 0) /*A  No Rogue Data Cache Load (Meltdown) */
+XEN_CPUFEATURE(EIBRS,              16*32+ 1) /*A  Enhanced IBRS */
+XEN_CPUFEATURE(RSBA,               16*32+ 2) /*!A RSB Alternative (Retpoline not safe) */
+XEN_CPUFEATURE(SKIP_L1DFL,         16*32+ 3) /*A  Don't need to flush L1D on VMEntry */
+XEN_CPUFEATURE(INTEL_SSB_NO,       16*32+ 4) /*A  No Speculative Store Bypass */
+XEN_CPUFEATURE(MDS_NO,             16*32+ 5) /*A  No Microarchitectural Data Sampling */
+XEN_CPUFEATURE(IF_PSCHANGE_MC_NO,  16*32+ 6) /*A  No Instruction fetch #MC */
+XEN_CPUFEATURE(TSX_CTRL,           16*32+ 7) /*   MSR_TSX_CTRL */
+XEN_CPUFEATURE(TAA_NO,             16*32+ 8) /*A  No TSX Async Abort */
+XEN_CPUFEATURE(MCU_CTRL,           16*32+ 9) /*   MSR_MCU_CTRL */
+XEN_CPUFEATURE(MISC_PKG_CTRL,      16*32+10) /*   MSR_MISC_PKG_CTRL */
+XEN_CPUFEATURE(ENERGY_FILTERING,   16*32+11) /*   MSR_MISC_PKG_CTRL.ENERGY_FILTERING */
+XEN_CPUFEATURE(DOITM,              16*32+12) /*   Data Operand Invariant Timing Mode */
+XEN_CPUFEATURE(SBDR_SSBD_NO,       16*32+13) /*A  No Shared Buffer Data Read or Sideband Stale Data Propagation */
+XEN_CPUFEATURE(FBDSP_NO,           16*32+14) /*A  No Fill Buffer Stale Data Propagation */
+XEN_CPUFEATURE(PSDP_NO,            16*32+15) /*A  No Primary Stale Data Propagation */
+XEN_CPUFEATURE(FB_CLEAR,           16*32+17) /*A  Fill Buffers cleared by VERW */
+XEN_CPUFEATURE(FB_CLEAR_CTRL,      16*32+18) /*   MSR_OPT_CPU_CTRL.FB_CLEAR_DIS */
+XEN_CPUFEATURE(RRSBA,              16*32+19) /*!A Restricted RSB Alternative */
+XEN_CPUFEATURE(BHI_NO,             16*32+20) /*A  No Branch History Injection  */
+XEN_CPUFEATURE(XAPIC_STATUS,       16*32+21) /*   MSR_XAPIC_DISABLE_STATUS */
+XEN_CPUFEATURE(OVRCLK_STATUS,      16*32+23) /*   MSR_OVERCLOCKING_STATUS */
+XEN_CPUFEATURE(PBRSB_NO,           16*32+24) /*A  No Post-Barrier RSB predictions */
 
 /* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.edx, word 17 */
 
xen/tools/gen-cpuid.py +3 -0
index 86d00bb3c273..f28ff708a2fc 100755
@@ -325,6 +325,9 @@ def crunch_numbers(state):
 
         # In principle the TSXLDTRK insns could also be considered independent.
         RTM: [TSXLDTRK],
+
+        # The ARCH_CAPS CPUID bit enumerates the availability of the whole register.
+        ARCH_CAPS: list(range(RDCL_NO, RDCL_NO + 64)),
     }
 
     deep_features = tuple(sorted(deps.keys()))
Signature · 1 line
2.30.2
#12 lore raw

Re: [PATCH 4/6] x86/cpu-policy: MSR_ARCH_CAPS feature names

Quoted 2 lines · Andrew Cooper

Seed the default visibility from the dom0 special case, which for the most part just exposes the *_NO bits.

EIBRS and SKIP_L1DFL are outliers here, in not presently being exposed to Dom0. If (latent) exposing of them wasn't an oversight, then this would imo want justifying here. They'll get exposed, after all, ...

Quoted 5 lines

Insert a block dependency from the ARCH_CAPS
CPUID bit to the entire content of the MSR.

The overall CPUID bit is still max-only, so all of MSR_ARCH_CAPS is hidden in the default policies.

... once this changes, as they're also not just 'a', but 'A'.

tools/misc/xen-cpuid.c static const char *const str_7d2[32] = · line 236

Quoted 12 lines
tools/misc/xen-cpuid.c +6 -0
@@ -228,6 +228,19 @@ static const char *const str_7d2[32] =
 
 static const char *const str_10Al[32] =
 {
+    [ 0] = "rdcl-no",             [ 1] = "eibrs",
+    [ 2] = "rsba",                [ 3] = "skip-l1dfl",
+    [ 4] = "intel-ssb-no",        [ 5] = "mds-no",
+    [ 6] = "if-pschange-mc-no",   [ 7] = "tsx-ctrl",
+    [ 8] = "taa-no",              [ 9] = "mcu-ctrl",
+    [10] = "misc-pkg-ctrl",       [11] = "energy-ctrl",

Not "energy-filtering" or "energy-filtering-ctl" for the right one here?

Quoted 18 lines
tools/misc/xen-cpuid.c +7 -0
+    [12] = "doitm",               [13] = "sbdr-ssdp-no",
+    [14] = "fbsdp-no",            [15] = "psdp-no",
+    /* 16 */                      [17] = "fb-clear",
+    [18] = "fb-clear-ctrl",       [19] = "rrsba",
+    [20] = "bhi-no",              [21] = "xapic-status",
+    /* 22 */                      [23] = "ovrclk-status",
+    [24] = "pbrsb-no",
 };
 
 static const char *const str_10Ah[32] =
xen/include/public/arch-x86/cpufeatureset.h +2 -0
@@ -308,6 +308,29 @@ XEN_CPUFEATURE(AVX_NE_CONVERT,     15*32+ 5) /*A  AVX-NE-CONVERT Instructions */
 XEN_CPUFEATURE(CET_SSS,            15*32+18) /*   CET Supervisor Shadow Stacks safe to use */
 
 /* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.eax, word 16 */
+XEN_CPUFEATURE(RDCL_NO,            16*32+ 0) /*A  No Rogue Data Cache Load (Meltdown) */
+XEN_CPUFEATURE(EIBRS,              16*32+ 1) /*A  Enhanced IBRS */

xen/include/public/arch-x86/cpufeatureset.h XEN_CPUFEATURE(AVX_NE_CONVERT, 15*32+ 5) /*A AVX-NE-CONVERT Instructions */ · line 322

Quoted 10 lines
xen/include/public/arch-x86/cpufeatureset.h +10 -0
+XEN_CPUFEATURE(RSBA,               16*32+ 2) /*!A RSB Alternative (Retpoline not safe) */
+XEN_CPUFEATURE(SKIP_L1DFL,         16*32+ 3) /*A  Don't need to flush L1D on VMEntry */
+XEN_CPUFEATURE(INTEL_SSB_NO,       16*32+ 4) /*A  No Speculative Store Bypass */
+XEN_CPUFEATURE(MDS_NO,             16*32+ 5) /*A  No Microarchitectural Data Sampling */
+XEN_CPUFEATURE(IF_PSCHANGE_MC_NO,  16*32+ 6) /*A  No Instruction fetch #MC */
+XEN_CPUFEATURE(TSX_CTRL,           16*32+ 7) /*   MSR_TSX_CTRL */
+XEN_CPUFEATURE(TAA_NO,             16*32+ 8) /*A  No TSX Async Abort */
+XEN_CPUFEATURE(MCU_CTRL,           16*32+ 9) /*   MSR_MCU_CTRL */
+XEN_CPUFEATURE(MISC_PKG_CTRL,      16*32+10) /*   MSR_MISC_PKG_CTRL */
+XEN_CPUFEATURE(ENERGY_FILTERING,   16*32+11) /*   MSR_MISC_PKG_CTRL.ENERGY_FILTERING */

These last two aren't exactly in sync with the SDM; I assume that's intended?

xen/include/public/arch-x86/cpufeatureset.h XEN_CPUFEATURE(AVX_NE_CONVERT, 15*32+ 5) /*A AVX-NE-CONVERT Instructions */ · line 324

Quoted 2 lines
xen/include/public/arch-x86/cpufeatureset.h +2 -0
+XEN_CPUFEATURE(DOITM,              16*32+12) /*   Data Operand Invariant Timing Mode */
+XEN_CPUFEATURE(SBDR_SSBD_NO,       16*32+13) /*A  No Shared Buffer Data Read or Sideband Stale Data Propagation */

SBDR_SSDP_NO?

xen/include/public/arch-x86/cpufeatureset.h XEN_CPUFEATURE(AVX_NE_CONVERT, 15*32+ 5) /*A AVX-NE-CONVERT Instructions */ · line 325

Quoted 1 line
xen/include/public/arch-x86/cpufeatureset.h +1 -0
+XEN_CPUFEATURE(FBDSP_NO,           16*32+14) /*A  No Fill Buffer Stale Data Propagation */

FBSDP_NO?

Jan

#13 lore raw

Re: [PATCH 4/6] x86/cpu-policy: MSR_ARCH_CAPS feature names

Quoted 6 lines · Jan Beulich
Quoted 2 lines · Andrew Cooper

Seed the default visibility from the dom0 special case, which for the most part just exposes the *_NO bits.

EIBRS and SKIP_L1DFL are outliers here, in not presently being exposed to Dom0. If (latent) exposing of them wasn't an oversight, then this would imo want justifying here. They'll get exposed, after all, ...

EIBRS is exposed to dom0.  I've intentionally renamed it from ARCH_CAPS_IBRS_ALL because EIBRS is by far the more recognisable name now.

SKIP_L1DFL is more complicated, but on yet more consideration I think it's probably wrong here.

The confusion is regarding L1 Terminal Fault, where RDCL_NO was retroactively declared to mean "also fixes L1TF".  SKIP_L1DFL means "you don't need to flush on vmentry", which is advertised by real hardware that also advertises RDCL_NO, but should also be advertised on vulnerable hardware by the L0 hypervisor to an L1 to say "don't worry, I'm already taking care of that for you".

So on consideration, I think SKIP_L1DFL should not be visible by default, and when we start doing nested virt, should be reintroduced with a dependency on the VMX feature.

Quoted 15 lines
Quoted 15 lines
tools/misc/xen-cpuid.c +7 -0
+    [12] = "doitm",               [13] = "sbdr-ssdp-no",
+    [14] = "fbsdp-no",            [15] = "psdp-no",
+    /* 16 */                      [17] = "fb-clear",
+    [18] = "fb-clear-ctrl",       [19] = "rrsba",
+    [20] = "bhi-no",              [21] = "xapic-status",
+    /* 22 */                      [23] = "ovrclk-status",
+    [24] = "pbrsb-no",
 };
 
 static const char *const str_10Ah[32] =
xen/include/public/arch-x86/cpufeatureset.h +0 -0
@@ -308,6 +308,29 @@ XEN_CPUFEATURE(AVX_NE_CONVERT,     15*32+ 5) /*A  AVX-NE-CONVERT Instructions */
 XEN_CPUFEATURE(CET_SSS,            15*32+18) /*   CET Supervisor Shadow Stacks safe to use */
 
Quoted 15 lines

xen/include/public/arch-x86/cpufeatureset.h XEN_CPUFEATURE(AVX_NE_CONVERT, 15*32+ 5) /*A AVX-NE-CONVERT Instructions */ · line 322

Quoted 13 lines
xen/include/public/arch-x86/cpufeatureset.h +12 -0
 /* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.eax, word 16 */
+XEN_CPUFEATURE(RDCL_NO,            16*32+ 0) /*A  No Rogue Data Cache Load (Meltdown) */
+XEN_CPUFEATURE(EIBRS,              16*32+ 1) /*A  Enhanced IBRS */
+XEN_CPUFEATURE(RSBA,               16*32+ 2) /*!A RSB Alternative (Retpoline not safe) */
+XEN_CPUFEATURE(SKIP_L1DFL,         16*32+ 3) /*A  Don't need to flush L1D on VMEntry */
+XEN_CPUFEATURE(INTEL_SSB_NO,       16*32+ 4) /*A  No Speculative Store Bypass */
+XEN_CPUFEATURE(MDS_NO,             16*32+ 5) /*A  No Microarchitectural Data Sampling */
+XEN_CPUFEATURE(IF_PSCHANGE_MC_NO,  16*32+ 6) /*A  No Instruction fetch #MC */
+XEN_CPUFEATURE(TSX_CTRL,           16*32+ 7) /*   MSR_TSX_CTRL */
+XEN_CPUFEATURE(TAA_NO,             16*32+ 8) /*A  No TSX Async Abort */
+XEN_CPUFEATURE(MCU_CTRL,           16*32+ 9) /*   MSR_MCU_CTRL */
+XEN_CPUFEATURE(MISC_PKG_CTRL,      16*32+10) /*   MSR_MISC_PKG_CTRL */
+XEN_CPUFEATURE(ENERGY_FILTERING,   16*32+11) /*   MSR_MISC_PKG_CTRL.ENERGY_FILTERING */

These last two aren't exactly in sync with the SDM; I assume that's intended?

Yeah.  I'm bored of Intel failing with naming consistency.  This one, I was assured that the draft was going to be fixed before publishing it, and yet...

Quoted 7 lines

xen/include/public/arch-x86/cpufeatureset.h XEN_CPUFEATURE(AVX_NE_CONVERT, 15*32+ 5) /*A AVX-NE-CONVERT Instructions */ · line 324

Quoted 3 lines
xen/include/public/arch-x86/cpufeatureset.h +2 -0
+XEN_CPUFEATURE(DOITM,              16*32+12) /*   Data Operand Invariant Timing Mode */
+XEN_CPUFEATURE(SBDR_SSBD_NO,       16*32+13) /*A  No Shared Buffer Data Read or Sideband Stale Data Propagation */

SBDR_SSDP_NO?

xen/include/public/arch-x86/cpufeatureset.h XEN_CPUFEATURE(AVX_NE_CONVERT, 15*32+ 5) /*A AVX-NE-CONVERT Instructions */ · line 325

Quoted 1 line
xen/include/public/arch-x86/cpufeatureset.h +1 -0
+XEN_CPUFEATURE(FBDSP_NO,           16*32+14) /*A  No Fill Buffer Stale Data Propagation */

FBSDP_NO?

Oops.  I hate the MMIO vulns especially because they're too similar to other vulns.  Will fix.

~Andrew

#14 lore raw

Re: [PATCH 4/6] x86/cpu-policy: MSR_ARCH_CAPS feature names

Quoted 10 lines · Andrew Cooper
Quoted 6 lines · Jan Beulich
Quoted 2 lines · Andrew Cooper

Seed the default visibility from the dom0 special case, which for the most part just exposes the *_NO bits.

EIBRS and SKIP_L1DFL are outliers here, in not presently being exposed to Dom0. If (latent) exposing of them wasn't an oversight, then this would imo want justifying here. They'll get exposed, after all, ...

EIBRS is exposed to dom0.  I've intentionally renamed it from ARCH_CAPS_IBRS_ALL because EIBRS is by far the more recognisable name now.

Oh, of course - I should have looked at more than just the names themselves.

Hence the comment on a later patch then also is incorrectly saying "two bits", when referring back here.

Jan

#15 lore raw

PATCH 5/6 x86/boot: Record MSR_ARCH_CAPS for the Raw and Host CPU policy

In reply to Andrew Cooper

Extend x86_cpu_policy_fill_native() with a read of ARCH_CAPS based on the CPUID information just read, which removes the need handling it specially in calculate_raw_cpu_policy().

Extend generic_identify() to read ARCH_CAPS into x86_capability[], which is fed into the Host Policy. This in turn means there's no need to special case arch_caps in calculate_host_policy().

No practical change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/arch/x86/cpu-policy.c | 12 ------------
 xen/arch/x86/cpu/common.c |  5 +++++
 xen/lib/x86/cpuid.c       |  7 ++++++-
 3 files changed, 11 insertions(+), 13 deletions(-)
xen/arch/x86/cpu-policy.c +0 -12
index 49f5465ec445..dfd9abd8564c 100644
@@ -354,9 +354,6 @@ void calculate_raw_cpu_policy(void)
 
     /* 0x000000ce  MSR_INTEL_PLATFORM_INFO */
     /* Was already added by probe_cpuid_faulting() */
-
-    if ( cpu_has_arch_caps )
-        rdmsrl(MSR_ARCH_CAPABILITIES, p->arch_caps.raw);
 }
 
 static void __init calculate_host_policy(void)
@@ -409,15 +406,6 @@ static void __init calculate_host_policy(void)
     /* 0x000000ce  MSR_INTEL_PLATFORM_INFO */
     /* probe_cpuid_faulting() sanity checks presence of MISC_FEATURES_ENABLES */
     p->platform_info.cpuid_faulting = cpu_has_cpuid_faulting;
-
-    /* Temporary, until we have known_features[] for feature bits in MSRs. */
-    p->arch_caps.raw = raw_cpu_policy.arch_caps.raw &
-        (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
-         ARCH_CAPS_SKIP_L1DFL | ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO |
-         ARCH_CAPS_IF_PSCHANGE_MC_NO | ARCH_CAPS_TSX_CTRL | ARCH_CAPS_TAA_NO |
-         ARCH_CAPS_SBDR_SSDP_NO | ARCH_CAPS_FBSDP_NO | ARCH_CAPS_PSDP_NO |
-         ARCH_CAPS_FB_CLEAR | ARCH_CAPS_RRSBA | ARCH_CAPS_BHI_NO |
-         ARCH_CAPS_PBRSB_NO);
 }
 
 static void __init guest_common_default_feature_adjustments(uint32_t *fs)
xen/arch/x86/cpu/common.c +5 -0
index edc4db1335eb..a3a341fd7db2 100644
@@ -474,6 +474,11 @@ static void generic_identify(struct cpuinfo_x86 *c)
 		cpuid_count(0xd, 1,
 			    &c->x86_capability[FEATURESET_Da1],
 			    &tmp, &tmp, &tmp);
+
+	if (test_bit(X86_FEATURE_ARCH_CAPS, c->x86_capability))
+		rdmsr(MSR_ARCH_CAPABILITIES,
+		      c->x86_capability[FEATURESET_10Al],
+		      c->x86_capability[FEATURESET_10Ah]);
 }
 
 /*
xen/lib/x86/cpuid.c +6 -1
index a9f31858aeff..dfd377cfb7ef 100644
@@ -226,7 +226,12 @@ void x86_cpu_policy_fill_native(struct cpu_policy *p)
     p->hv_limit = 0;
     p->hv2_limit = 0;
 
-    /* TODO MSRs */
+#ifdef __XEN__
+    /* TODO MSR_PLATFORM_INFO */
+
+    if ( p->feat.arch_caps )
+        rdmsrl(MSR_ARCH_CAPABILITIES, p->arch_caps.raw);
+#endif
 
     x86_cpu_policy_recalc_synth(p);
 }
Signature · 1 line
2.30.2
Reviewed-by on v1 5/6
#16 lore raw

Re: [PATCH 5/6] x86/boot: Record MSR_ARCH_CAPS for the Raw and Host CPU policy

Quoted 11 lines · Andrew Cooper

Extend x86_cpu_policy_fill_native() with a read of ARCH_CAPS based on the CPUID information just read, which removes the need handling it specially in calculate_raw_cpu_policy().

Extend generic_identify() to read ARCH_CAPS into x86_capability[], which is fed into the Host Policy. This in turn means there's no need to special case arch_caps in calculate_host_policy().

No practical change.

I have a question though, which I think would be nice if the description had covered:

xen/lib/x86/cpuid.c void x86_cpu_policy_fill_native(struct cpu_policy *p) · line 234

Quoted 13 lines
xen/lib/x86/cpuid.c +6 -1
@@ -226,7 +226,12 @@ void x86_cpu_policy_fill_native(struct cpu_policy *p)
     p->hv_limit = 0;
     p->hv2_limit = 0;
 
-    /* TODO MSRs */
+#ifdef __XEN__
+    /* TODO MSR_PLATFORM_INFO */
+
+    if ( p->feat.arch_caps )
+        rdmsrl(MSR_ARCH_CAPABILITIES, p->arch_caps.raw);
+#endif

What about non-Xen environments re-using this code? In particular the test harnesses would be nice if they didn't run with the two fields all blank at all times.

Jan

#17 lore raw

Re: [PATCH 5/6] x86/boot: Record MSR_ARCH_CAPS for the Raw and Host CPU policy

Quoted 5 lines · Jan Beulich
Quoted 4 lines · Andrew Cooper

Extend x86_cpu_policy_fill_native() with a read of ARCH_CAPS based on the CPUID information just read, which removes the need handling it specially in calculate_raw_cpu_policy().

Quoted 8 lines
Quoted 7 lines

Extend generic_identify() to read ARCH_CAPS into x86_capability[], which is fed into the Host Policy. This in turn means there's no need to special case arch_caps in calculate_host_policy().

No practical change.

Thanks.

Quoted 10 lines

I have a question though, which I think would be nice if the description had covered:

Quoted 6 lines
xen/lib/x86/cpuid.c +0 -0
@@ -226,7 +226,12 @@ void x86_cpu_policy_fill_native(struct cpu_policy *p)
     p->hv_limit = 0;
     p->hv2_limit = 0;
 
Quoted 10 lines

xen/lib/x86/cpuid.c void x86_cpu_policy_fill_native(struct cpu_policy *p) · line 234

Quoted 7 lines
xen/lib/x86/cpuid.c +6 -1
-    /* TODO MSRs */
+#ifdef __XEN__
+    /* TODO MSR_PLATFORM_INFO */
+
+    if ( p->feat.arch_caps )
+        rdmsrl(MSR_ARCH_CAPABILITIES, p->arch_caps.raw);
+#endif

What about non-Xen environments re-using this code? In particular the test harnesses would be nice if they didn't run with the two fields all blank at all times.

Right now, I don't have an answer.

In Linux in lockdown mode, there isn't even a way to access this info userspace, because /proc/cpu/$/msr goes away.

It's only a unit test, and this doesn't break it.

~Andrew

#18 lore raw

PATCH 6/6 x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

In reply to Andrew Cooper

We already have common and default feature adjustment helpers. Introduce one for max featuresets too.

Offer MSR_ARCH_CAPS unconditionally in the max policy, and stop clobbering the data inherited from the Host policy. This will be necessary level a VM safely for migration. Note: ARCH_CAPS is still max-only for now, so will not be inhereted by the default policies.

With this done, the special case for dom0 can be shrunk to just resampling the Host policy (as ARCH_CAPS isn't visible by default yet).

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/arch/x86/cpu-policy.c | 42 ++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 18 deletions(-)
xen/arch/x86/cpu-policy.c +24 -18
index dfd9abd8564c..74266d30b551 100644
@@ -408,6 +408,25 @@ static void __init calculate_host_policy(void)
     p->platform_info.cpuid_faulting = cpu_has_cpuid_faulting;
 }
 
+static void __init guest_common_max_feature_adjustments(uint32_t *fs)
+{
+    if ( boot_cpu_data.x86_vendor == 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
+         * uarch-specific.
+         *
+         * In particular, the RSBA and RRSBA bits mean "you might migrate to a
+         * system where RSB underflow uses alternative predictors (a.k.a
+         * Retpoline not safe)", so these need to be visible to a guest in all
+         * cases, even when it's only some other server in the pool which
+         * suffers the identified behaviour.
+         */
+        __set_bit(X86_FEATURE_ARCH_CAPS, fs);
+    }
+}
+
 static void __init guest_common_default_feature_adjustments(uint32_t *fs)
 {
     /*
@@ -483,6 +502,7 @@ static void __init calculate_pv_max_policy(void)
         __clear_bit(X86_FEATURE_IBRS, fs);
     }
 
+    guest_common_max_feature_adjustments(fs);
     guest_common_feature_adjustments(fs);
 
     sanitise_featureset(fs);
@@ -490,8 +510,6 @@ static void __init calculate_pv_max_policy(void)
     recalculate_xstate(p);
 
     p->extd.raw[0xa] = EMPTY_LEAF; /* No SVM for PV guests. */
-
-    p->arch_caps.raw = 0; /* Not supported yet. */
 }
 
 static void __init calculate_pv_def_policy(void)
@@ -598,6 +616,7 @@ static void __init calculate_hvm_max_policy(void)
     if ( !cpu_has_vmx )
         __clear_bit(X86_FEATURE_PKS, fs);
 
+    guest_common_max_feature_adjustments(fs);
     guest_common_feature_adjustments(fs);
 
     sanitise_featureset(fs);
@@ -606,8 +625,6 @@ static void __init calculate_hvm_max_policy(void)
 
     /* It's always possible to emulate CPUID faulting for HVM guests */
     p->platform_info.cpuid_faulting = true;
-
-    p->arch_caps.raw = 0; /* Not supported yet. */
 }
 
 static void __init calculate_hvm_def_policy(void)
@@ -828,7 +845,10 @@ void __init init_dom0_cpuid_policy(struct domain *d)
      * domain policy logic gains a better understanding of MSRs.
      */
     if ( is_hardware_domain(d) && cpu_has_arch_caps )
+    {
         p->feat.arch_caps = true;
+        p->arch_caps.raw = host_cpu_policy.arch_caps.raw;
+    }
 
     /* Apply dom0-cpuid= command line settings, if provided. */
     if ( dom0_cpuid_cmdline )
@@ -858,20 +878,6 @@ void __init init_dom0_cpuid_policy(struct domain *d)
         p->platform_info.cpuid_faulting = false;
 
     recalculate_cpuid_policy(d);
-
-    if ( is_hardware_domain(d) && cpu_has_arch_caps )
-    {
-        uint64_t val;
-
-        rdmsrl(MSR_ARCH_CAPABILITIES, val);
-
-        p->arch_caps.raw = val &
-            (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
-             ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO | ARCH_CAPS_IF_PSCHANGE_MC_NO |
-             ARCH_CAPS_TAA_NO | ARCH_CAPS_SBDR_SSDP_NO | ARCH_CAPS_FBSDP_NO |
-             ARCH_CAPS_PSDP_NO | ARCH_CAPS_FB_CLEAR | ARCH_CAPS_RRSBA |
-             ARCH_CAPS_BHI_NO | ARCH_CAPS_PBRSB_NO);
-    }
 }
 
 static void __init __maybe_unused build_assertions(void)
Signature · 1 line
2.30.2
#19 lore raw

Re: [PATCH 6/6] x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

Quoted 14 lines · Andrew Cooper
xen/arch/x86/cpu-policy.c +8 -0
@@ -408,6 +408,25 @@ static void __init calculate_host_policy(void)
     p->platform_info.cpuid_faulting = cpu_has_cpuid_faulting;
 }
 
+static void __init guest_common_max_feature_adjustments(uint32_t *fs)
+{
+    if ( boot_cpu_data.x86_vendor == 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
+         * uarch-specific.

xen/arch/x86/cpu-policy.c static void __init calculate_host_policy(void) · line 428

Quoted 10 lines
xen/arch/x86/cpu-policy.c +10 -0
+         *
+         * In particular, the RSBA and RRSBA bits mean "you might migrate to a
+         * system where RSB underflow uses alternative predictors (a.k.a
+         * Retpoline not safe)", so these need to be visible to a guest in all
+         * cases, even when it's only some other server in the pool which
+         * suffers the identified behaviour.
+         */
+        __set_bit(X86_FEATURE_ARCH_CAPS, fs);
+    }
+}

The comment reads as if it wasn't applying to "max" only, but rather to "default". Reading this I'm therefore now (and perhaps even more so in the future, when coming across it) wondering whether it's misplaced, or and hence whether the commented code is also misplaced and/or wrong.

Further is even just non-default exposure of all the various bits okay to other than Dom0? IOW is there indeed no further adjustment necessary to guest_rdmsr()?

xen/arch/x86/cpu-policy.c void __init init_dom0_cpuid_policy(struct domain *d) · line 851

Quoted 8 lines
xen/arch/x86/cpu-policy.c +3 -0
@@ -828,7 +845,10 @@ void __init init_dom0_cpuid_policy(struct domain *d)
      * domain policy logic gains a better understanding of MSRs.
      */
     if ( is_hardware_domain(d) && cpu_has_arch_caps )
+    {
         p->feat.arch_caps = true;
+        p->arch_caps.raw = host_cpu_policy.arch_caps.raw;
+    }

Doesn't this expose all the bits, irrespective of their exposure annotations in the public header? I.e. even more than just the two bits that become 'A' in patch 4, but weren't ...

Quoted 8 lines
xen/arch/x86/cpu-policy.c +0 -4
@@ -858,20 +878,6 @@ void __init init_dom0_cpuid_policy(struct domain *d)
         p->platform_info.cpuid_faulting = false;
 
     recalculate_cpuid_policy(d);
-
-    if ( is_hardware_domain(d) && cpu_has_arch_caps )
-    {
-        uint64_t val;

xen/arch/x86/cpu-policy.c void __init init_dom0_cpuid_policy(struct domain *d) · line 874

Quoted 10 lines
xen/arch/x86/cpu-policy.c +0 -10
-
-        rdmsrl(MSR_ARCH_CAPABILITIES, val);
-
-        p->arch_caps.raw = val &
-            (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA |
-             ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO | ARCH_CAPS_IF_PSCHANGE_MC_NO |
-             ARCH_CAPS_TAA_NO | ARCH_CAPS_SBDR_SSDP_NO | ARCH_CAPS_FBSDP_NO |
-             ARCH_CAPS_PSDP_NO | ARCH_CAPS_FB_CLEAR | ARCH_CAPS_RRSBA |
-             ARCH_CAPS_BHI_NO | ARCH_CAPS_PBRSB_NO);
-    }

... included here?

Jan

#20 lore raw

Re: [PATCH 6/6] x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

Quoted 21 lines · Jan Beulich
Quoted 20 lines · Andrew Cooper
xen/arch/x86/cpu-policy.c +14 -0
@@ -408,6 +408,25 @@ static void __init calculate_host_policy(void)
     p->platform_info.cpuid_faulting = cpu_has_cpuid_faulting;
 }
 
+static void __init guest_common_max_feature_adjustments(uint32_t *fs)
+{
+    if ( boot_cpu_data.x86_vendor == 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
+         * uarch-specific.
+         *
+         * In particular, the RSBA and RRSBA bits mean "you might migrate to a
+         * system where RSB underflow uses alternative predictors (a.k.a
+         * Retpoline not safe)", so these need to be visible to a guest in all
+         * cases, even when it's only some other server in the pool which
+         * suffers the identified behaviour.
Quoted 8 lines

xen/arch/x86/cpu-policy.c static void __init calculate_host_policy(void) · line 428

Quoted 4 lines
xen/arch/x86/cpu-policy.c +4 -0
+         */
+        __set_bit(X86_FEATURE_ARCH_CAPS, fs);
+    }
+}

The comment reads as if it wasn't applying to "max" only, but rather to "default". Reading this I'm therefore now (and perhaps even more so in the future, when coming across it) wondering whether it's misplaced, or and hence whether the commented code is also misplaced and/or wrong.

On migrate-in, we (well - toolstacks that understand multiple hosts) check the cpu policy the VM saw against the appropriate PV/HVM max policy to determine whether it can safely run.

So this is very intentionally for the max policy.  We need (I think - still pending an clarification from Intel because there's pending work still not published) to set RSBA unconditionally, and RRSBA conditional on EIBRS being available, in max even on pre-Skylake hardware such that we can migrate-in a VM which previously ran on Skylake or later hardware.

Activating this by default for VMs is just a case of swapping the CPUID ARCH_CAPS bit from 'a' to 'A', without any adjustment to this logic.

Quoted 4 lines

Further is even just non-default exposure of all the various bits okay to other than Dom0? IOW is there indeed no further adjustment necessary to guest_rdmsr()?

Quoted 10 lines

xen/arch/x86/cpu-policy.c void __init init_dom0_cpuid_policy(struct domain *d) · line 851

Quoted 8 lines
xen/arch/x86/cpu-policy.c +3 -0
@@ -828,7 +845,10 @@ void __init init_dom0_cpuid_policy(struct domain *d)
      * domain policy logic gains a better understanding of MSRs.
      */
     if ( is_hardware_domain(d) && cpu_has_arch_caps )
+    {
         p->feat.arch_caps = true;
+        p->arch_caps.raw = host_cpu_policy.arch_caps.raw;
+    }

Doesn't this expose all the bits, irrespective of their exposure annotations in the public header?

No, because of ...

Quoted 7 lines

I.e. even more than just the two
bits that become 'A' in patch 4, but weren't ...

xen/arch/x86/cpu-policy.c void __init init_dom0_cpuid_policy(struct domain *d) · line 880

Quoted 4 lines
xen/arch/x86/cpu-policy.c +0 -0
@@ -858,20 +878,6 @@ void __init init_dom0_cpuid_policy(struct domain *d)
         p->platform_info.cpuid_faulting = false;
 
     recalculate_cpuid_policy(d);

... this recalculate_cpuid_policy() (which was moved in patch 1), which applies the appropriate pv/hvm max mask over the inherited bits.

More generally, this is how *all* opting-into-non-default features needs to work when it's more than just turning on a single feature bit.  It's also why doing full-policy levelling in the toolstack is much harder than it appears on paper.

All domains get the default policy, so zero out all non-default information.  It has to be recovered from somewhere.  Generally that would be the appropriate max policy, but the host policy here is fine because there's nothing to do other than applying the appropriate max mask.

When arch-caps becomes default, the full block feeding arch caps back into dom0 will be dropped, but there's still a lot of work to do first.

~Andrew

#21 lore raw

Re: [PATCH 6/6] x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

Quoted 35 lines · Andrew Cooper
Quoted 21 lines · Jan Beulich
Quoted 20 lines · Andrew Cooper
xen/arch/x86/cpu-policy.c +14 -0
@@ -408,6 +408,25 @@ static void __init calculate_host_policy(void)
     p->platform_info.cpuid_faulting = cpu_has_cpuid_faulting;
 }
 
+static void __init guest_common_max_feature_adjustments(uint32_t *fs)
+{
+    if ( boot_cpu_data.x86_vendor == 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
+         * uarch-specific.
+         *
+         * In particular, the RSBA and RRSBA bits mean "you might migrate to a
+         * system where RSB underflow uses alternative predictors (a.k.a
+         * Retpoline not safe)", so these need to be visible to a guest in all
+         * cases, even when it's only some other server in the pool which
+         * suffers the identified behaviour.
Quoted 8 lines

xen/arch/x86/cpu-policy.c static void __init calculate_host_policy(void) · line 428

Quoted 4 lines
xen/arch/x86/cpu-policy.c +4 -0
+         */
+        __set_bit(X86_FEATURE_ARCH_CAPS, fs);
+    }
+}

The comment reads as if it wasn't applying to "max" only, but rather to "default". Reading this I'm therefore now (and perhaps even more so in the future, when coming across it) wondering whether it's misplaced, or and hence whether the commented code is also misplaced and/or wrong.

On migrate-in, we (well - toolstacks that understand multiple hosts) check the cpu policy the VM saw against the appropriate PV/HVM max policy to determine whether it can safely run.

Quoted 8 lines

So this is very intentionally for the max policy.  We need (I think - still pending an clarification from Intel because there's pending work still not published) to set RSBA unconditionally, and RRSBA conditional on EIBRS being available, in max even on pre-Skylake hardware such that we can migrate-in a VM which previously ran on Skylake or later hardware.

Activating this by default for VMs is just a case of swapping the CPUID ARCH_CAPS bit from 'a' to 'A', without any adjustment to this logic.

Hmm, I see. Not very intuitive, but I think I follow.

Quoted 3 lines
Quoted 3 lines

Further is even just non-default exposure of all the various bits okay to other than Dom0? IOW is there indeed no further adjustment necessary to guest_rdmsr()?

With your reply further down also sufficiently clarifying things for me (in particular pointing the one oversight of mine), the question above is the sole part remaining before I'd be okay giving my R-b here.

Jan

Quoted 39 lines
Quoted 10 lines

xen/arch/x86/cpu-policy.c void __init init_dom0_cpuid_policy(struct domain *d) · line 851

Quoted 8 lines
xen/arch/x86/cpu-policy.c +3 -0
@@ -828,7 +845,10 @@ void __init init_dom0_cpuid_policy(struct domain *d)
      * domain policy logic gains a better understanding of MSRs.
      */
     if ( is_hardware_domain(d) && cpu_has_arch_caps )
+    {
         p->feat.arch_caps = true;
+        p->arch_caps.raw = host_cpu_policy.arch_caps.raw;
+    }

Doesn't this expose all the bits, irrespective of their exposure annotations in the public header?

No, because of ...

Quoted 7 lines

I.e. even more than just the two
bits that become 'A' in patch 4, but weren't ...

xen/arch/x86/cpu-policy.c void __init init_dom0_cpuid_policy(struct domain *d) · line 880

Quoted 4 lines
xen/arch/x86/cpu-policy.c +0 -0
@@ -858,20 +878,6 @@ void __init init_dom0_cpuid_policy(struct domain *d)
         p->platform_info.cpuid_faulting = false;
 
     recalculate_cpuid_policy(d);

... this recalculate_cpuid_policy() (which was moved in patch 1), which applies the appropriate pv/hvm max mask over the inherited bits.

More generally, this is how *all* opting-into-non-default features needs to work when it's more than just turning on a single feature bit.  It's also why doing full-policy levelling in the toolstack is much harder than it appears on paper.

All domains get the default policy, so zero out all non-default information.  It has to be recovered from somewhere.  Generally that would be the appropriate max policy, but the host policy here is fine because there's nothing to do other than applying the appropriate max mask.

When arch-caps becomes default, the full block feeding arch caps back into dom0 will be dropped, but there's still a lot of work to do first.

~Andrew

#22 lore raw

Re: [PATCH 6/6] x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

Quoted 43 lines · Jan Beulich
Quoted 34 lines · Andrew Cooper
Quoted 21 lines · Jan Beulich
Quoted 20 lines · Andrew Cooper
xen/arch/x86/cpu-policy.c +14 -0
@@ -408,6 +408,25 @@ static void __init calculate_host_policy(void)
     p->platform_info.cpuid_faulting = cpu_has_cpuid_faulting;
 }
 
+static void __init guest_common_max_feature_adjustments(uint32_t *fs)
+{
+    if ( boot_cpu_data.x86_vendor == 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
+         * uarch-specific.
+         *
+         * In particular, the RSBA and RRSBA bits mean "you might migrate to a
+         * system where RSB underflow uses alternative predictors (a.k.a
+         * Retpoline not safe)", so these need to be visible to a guest in all
+         * cases, even when it's only some other server in the pool which
+         * suffers the identified behaviour.
Quoted 8 lines

xen/arch/x86/cpu-policy.c static void __init calculate_host_policy(void) · line 428

Quoted 4 lines
xen/arch/x86/cpu-policy.c +4 -0
+         */
+        __set_bit(X86_FEATURE_ARCH_CAPS, fs);
+    }
+}

The comment reads as if it wasn't applying to "max" only, but rather to "default". Reading this I'm therefore now (and perhaps even more so in the future, when coming across it) wondering whether it's misplaced, or and hence whether the commented code is also misplaced and/or wrong.

On migrate-in, we (well - toolstacks that understand multiple hosts) check the cpu policy the VM saw against the appropriate PV/HVM max policy to determine whether it can safely run.

Quoted 8 lines

So this is very intentionally for the max policy.  We need (I think - still pending an clarification from Intel because there's pending work still not published) to set RSBA unconditionally, and RRSBA conditional on EIBRS being available, in max even on pre-Skylake hardware such that we can migrate-in a VM which previously ran on Skylake or later hardware.

Activating this by default for VMs is just a case of swapping the CPUID ARCH_CAPS bit from 'a' to 'A', without any adjustment to this logic.

Quoted 8 lines

Hmm, I see. Not very intuitive, but I think I follow.

Quoted 3 lines
Quoted 3 lines

Further is even just non-default exposure of all the various bits okay to other than Dom0? IOW is there indeed no further adjustment necessary to guest_rdmsr()?

With your reply further down also sufficiently clarifying things for me (in particular pointing the one oversight of mine), the question above is the sole part remaining before I'd be okay giving my R-b here.

Oh sorry.  Yes, it is sufficient.  Because VMs (other than dom0) don't get the ARCH_CAPS CPUID bit, reads of MSR_ARCH_CAPS will #GP.

Right now, you can set cpuid = "host:arch-caps" in an xl.cfg file.  If you do this, you get to keep both pieces, as you'll end up advertising the MSR but with a value of 0 because of the note in patch 4.  libxl still only understand the xend CPUID format and can't express any MSR data at all.

~Andrew

#23 lore raw

Re: [PATCH 6/6] x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

Quoted 11 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich

On 15.05.2023 16:42, Andrew Cooper wrote:
Further is even just non-default exposure of all the various bits okay to other than Dom0? IOW is there indeed no further adjustment necessary to guest_rdmsr()?

With your reply further down also sufficiently clarifying things for me (in particular pointing the one oversight of mine), the question above is the sole part remaining before I'd be okay giving my R-b here.

Quoted 8 lines

Oh sorry.  Yes, it is sufficient.  Because VMs (other than dom0) don't get the ARCH_CAPS CPUID bit, reads of MSR_ARCH_CAPS will #GP.

Right now, you can set cpuid = "host:arch-caps" in an xl.cfg file.  If you do this, you get to keep both pieces, as you'll end up advertising the MSR but with a value of 0 because of the note in patch 4.  libxl still only understand the xend CPUID format and can't express any MSR data at all.

Hmm, so the CPUID bit being max only results in all the ARCH_CAPS bits getting turned off in the default policy. That is, to enable anything you need to not only enable the CPUID bit, but also the ARCH_CAPS bits you want enabled (with no presents means to do so). I guess that's no different from other max-only features with dependents, but I wonder whether that's good behavior. Wouldn't it make more sense for the individual bits' exposure qualifiers to become meaningful one to qualifying feature is enabled? I.e. here this would then mean that some ARCH_CAPS bits may become available, while others may require explicit turning on (assuming they weren't all 'A').

But irrespective of that (which is kind of orthogonal) my question was rather with already considering the point in time when the CPUID bit would become 'A'. IOW I was wondering whether at that point having all the individual bits be 'A' is actually going to be correct.

Jan

#24 lore raw

Re: [PATCH 6/6] x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

Quoted 19 lines · Jan Beulich
Quoted 10 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich

On 15.05.2023 16:42, Andrew Cooper wrote:
Further is even just non-default exposure of all the various bits okay to other than Dom0? IOW is there indeed no further adjustment necessary to guest_rdmsr()?

With your reply further down also sufficiently clarifying things for me (in particular pointing the one oversight of mine), the question above is the sole part remaining before I'd be okay giving my R-b here.

Quoted 8 lines

Oh sorry.  Yes, it is sufficient.  Because VMs (other than dom0) don't get the ARCH_CAPS CPUID bit, reads of MSR_ARCH_CAPS will #GP.

Right now, you can set cpuid = "host:arch-caps" in an xl.cfg file.  If you do this, you get to keep both pieces, as you'll end up advertising the MSR but with a value of 0 because of the note in patch 4.  libxl still only understand the xend CPUID format and can't express any MSR data at all.

Quoted 4 lines

Hmm, so the CPUID bit being max only results in all the ARCH_CAPS bits getting turned off in the default policy. That is, to enable anything you need to not only enable the CPUID bit, but also the ARCH_CAPS bits you want enabled (with no presents means to do so).

Correct.

Quoted 3 lines

I guess that's no
different from other max-only features with dependents, but I wonder whether that's good behavior.

It's not really something you get a choice over.

Default is always less than max, so however you choose to express these concepts, when you're opting-in you're always having to put information back in which was previously stripped out.

Quoted 5 lines

Wouldn't it make more sense for the
individual bits' exposure qualifiers to become meaningful one to qualifying feature is enabled? I.e. here this would then mean that some ARCH_CAPS bits may become available, while others may require explicit turning on (assuming they weren't all 'A').

I'm afraid I don't follow.  You could make some bits of MSR_ARCH_CAPS itself 'a' vs 'A', and that would have the expected effect (for any VM where arch_caps was visible).

The thing which is 99% of the complexity with MSR_ARCH_CAPS is getting RSBA/RRSBA right.  The moment we advertise MSR_ARCH_CAPS to guests, RSBA/RRSBA must be set appropriately for migrate or we're creating a security vulnerability in the guest.

If you're wondering about the block disable, that's because MSRs and CPUID are different.  With CPUID, we have x86_cpu_policy_clear_out_of_range_leaves() which uses the various max_leaf.  e.g. a feat.max_leaf=0 is what causes all of subleaf 1 and 2 to be zeroed in a policy.

Quoted 4 lines

But irrespective of that (which is kind of orthogonal) my question was rather with already considering the point in time when the CPUID bit would become 'A'. IOW I was wondering whether at that point having all the individual bits be 'A' is actually going to be correct.

I've chosen all 'A' for these bits because that is what I expect to be correct in due course.  They're all the simple "you're not vulnerable to $X" bits, plus eIBRS which in practice is just a qualifying statement on IBRS (already fully supported in guests).

The rest of MSR_ARCH_CAPS is pretty much a dumping ground for all of the controls we can't give to guests under any circumstance.  (FB_CLEAR_CTRL might be an exception - allegedly we might want to give it to guests which have passthrough and trust their userspace, but I'm unconvinced of this argument and going to insist on concrete numbers from anyone wanting to try and implement this usecase.)

But there certainly could be a feature in there in the future where we leave it at 'a' for a while...  It's just feature bitmap data in a non-CPUID form factor.

~Andrew

#25 lore raw

Re: [PATCH 6/6] x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

Quoted 31 lines · Andrew Cooper
Quoted 19 lines · Jan Beulich
Quoted 10 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich

On 15.05.2023 16:42, Andrew Cooper wrote:
Further is even just non-default exposure of all the various bits okay to other than Dom0? IOW is there indeed no further adjustment necessary to guest_rdmsr()?

With your reply further down also sufficiently clarifying things for me (in particular pointing the one oversight of mine), the question above is the sole part remaining before I'd be okay giving my R-b here.

Quoted 8 lines

Oh sorry.  Yes, it is sufficient.  Because VMs (other than dom0) don't get the ARCH_CAPS CPUID bit, reads of MSR_ARCH_CAPS will #GP.

Right now, you can set cpuid = "host:arch-caps" in an xl.cfg file.  If you do this, you get to keep both pieces, as you'll end up advertising the MSR but with a value of 0 because of the note in patch 4.  libxl still only understand the xend CPUID format and can't express any MSR data at all.

Quoted 4 lines

Hmm, so the CPUID bit being max only results in all the ARCH_CAPS bits getting turned off in the default policy. That is, to enable anything you need to not only enable the CPUID bit, but also the ARCH_CAPS bits you want enabled (with no presents means to do so).

Correct.

Quoted 3 lines

I guess that's no
different from other max-only features with dependents, but I wonder whether that's good behavior.

Quoted 5 lines

It's not really something you get a choice over.

Default is always less than max, so however you choose to express these concepts, when you're opting-in you're always having to put information back in which was previously stripped out.

But my point is towards the amount of data you need to specify manually. I would find it quite helpful if default-on sub-features became available automatically once the top-level feature was turned on. I guess so far we don't have many such cases, but here you add a whole bunch.

Quoted 9 lines
Quoted 5 lines

Wouldn't it make more sense for the
individual bits' exposure qualifiers to become meaningful one to qualifying feature is enabled? I.e. here this would then mean that some ARCH_CAPS bits may become available, while others may require explicit turning on (assuming they weren't all 'A').

I'm afraid I don't follow.  You could make some bits of MSR_ARCH_CAPS itself 'a' vs 'A', and that would have the expected effect (for any VM where arch_caps was visible).

Visible by default, you mean. Whereas I'm considering the case where the CPUID bit is default-off, and turning it on for a guest doesn't at the same time turn on all the 'A' bits in ARCH_CAPS (which hardware offers, or which we synthesize).

Something similar could be seen / utilized for AMX, where in my pending series I set all the bits to 'a', requiring every individual bit to be turned on along with turning on AMX-TILE. Yet it would be more user friendly if only the top-level bit needed enabling manually, with available sub-features then becoming available "automatically".

Quoted 17 lines

The thing which is 99% of the complexity with MSR_ARCH_CAPS is getting RSBA/RRSBA right.  The moment we advertise MSR_ARCH_CAPS to guests, RSBA/RRSBA must be set appropriately for migrate or we're creating a security vulnerability in the guest.

If you're wondering about the block disable, that's because MSRs and CPUID are different.  With CPUID, we have x86_cpu_policy_clear_out_of_range_leaves() which uses the various max_leaf.  e.g. a feat.max_leaf=0 is what causes all of subleaf 1 and 2 to be zeroed in a policy.

Quoted 4 lines

But irrespective of that (which is kind of orthogonal) my question was rather with already considering the point in time when the CPUID bit would become 'A'. IOW I was wondering whether at that point having all the individual bits be 'A' is actually going to be correct.

Quoted 4 lines

I've chosen all 'A' for these bits because that is what I expect to be correct in due course.  They're all the simple "you're not vulnerable to $X" bits, plus eIBRS which in practice is just a qualifying statement on IBRS (already fully supported in guests).

Right, upon checking again I agree.

Jan

Quoted 12 lines

The rest of MSR_ARCH_CAPS is pretty much a dumping ground for all of the controls we can't give to guests under any circumstance.  (FB_CLEAR_CTRL might be an exception - allegedly we might want to give it to guests which have passthrough and trust their userspace, but I'm unconvinced of this argument and going to insist on concrete numbers from anyone wanting to try and implement this usecase.)

But there certainly could be a feature in there in the future where we leave it at 'a' for a while...  It's just feature bitmap data in a non-CPUID form factor.

~Andrew

#26 lore raw

Re: [PATCH 6/6] x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
Quoted 3 lines · Jan Beulich

I guess that's no
different from other max-only features with dependents, but I wonder whether that's good behavior.

It's not really something you get a choice over.

Quoted 7 lines
Quoted 3 lines

Default is always less than max, so however you choose to express these concepts, when you're opting-in you're always having to put information back in which was previously stripped out.

But my point is towards the amount of data you need to specify manually. I would find it quite helpful if default-on sub-features became available automatically once the top-level feature was turned on. I guess so far we don't have many such cases, but here you add a whole bunch.

I'm not suggesting specifying it manually.  That would be a dumb UX move.

But you absolutely cannot have "user turns on EIBRS" meaning "turn on ARCH_CAPS too", because a) that requires creating the reverse feature map which is massively larger than the forward feature map, and b) it creates a vulnerability in the guest, and c) it's ambiguous - e.g. what does turning on a sub-mode of AVX-512 mean for sibling sub-modes?

Whichever algorithm you want, you still need *something* to know that ARCH_CAPS is special and how to arrange the defaults given a non-default overarching setting.

When the toolstack infrastructure grows the ability to say no to the user, it will be able to identify explicit user settings which cannot be fulfilled.  (And with a bit more complicated logic, why.)

Quoted 13 lines
Quoted 8 lines
Quoted 5 lines

Wouldn't it make more sense for the
individual bits' exposure qualifiers to become meaningful one to qualifying feature is enabled? I.e. here this would then mean that some ARCH_CAPS bits may become available, while others may require explicit turning on (assuming they weren't all 'A').

I'm afraid I don't follow.  You could make some bits of MSR_ARCH_CAPS itself 'a' vs 'A', and that would have the expected effect (for any VM where arch_caps was visible).

Visible by default, you mean. Whereas I'm considering the case where the CPUID bit is default-off, and turning it on for a guest doesn't at the same time turn on all the 'A' bits in ARCH_CAPS (which hardware offers, or which we synthesize).

Quoted 5 lines

Something similar could be seen / utilized for AMX, where in my pending series I set all the bits to 'a', requiring every individual bit to be turned on along with turning on AMX-TILE. Yet it would be more user friendly if only the top-level bit needed enabling manually, with available sub-features then becoming available "automatically".

I think I've covered all of this in the reply above?

~Andrew

#27 lore raw

Re: [PATCH 6/6] x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

Quoted 16 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
Quoted 3 lines · Jan Beulich

I guess that's no
different from other max-only features with dependents, but I wonder whether that's good behavior.

It's not really something you get a choice over.

Quoted 7 lines
Quoted 3 lines

Default is always less than max, so however you choose to express these concepts, when you're opting-in you're always having to put information back in which was previously stripped out.

But my point is towards the amount of data you need to specify manually. I would find it quite helpful if default-on sub-features became available automatically once the top-level feature was turned on. I guess so far we don't have many such cases, but here you add a whole bunch.

Quoted 7 lines

I'm not suggesting specifying it manually.  That would be a dumb UX move.

But you absolutely cannot have "user turns on EIBRS" meaning "turn on ARCH_CAPS too", because a) that requires creating the reverse feature map which is massively larger than the forward feature map, and b) it creates a vulnerability in the guest, and c) it's ambiguous - e.g. what does turning on a sub-mode of AVX-512 mean for sibling sub-modes?

Feels like a misunderstanding at this point, because what you're describing above is not what I was referring to. Instead I was specifically referring to "cpuid=...,arch-caps" not having any effect beyond the turning on of the MSR itself (with all-zero content). This is even worse with libxl not even having a way right now to express something like "arch-caps=..." to enable some of the sub-features for guests.

To explicitly answer the AVX512 part of your reply: Turning on a sub-mode alone could be useful as well (with the effect of also turning on the main feature, and with or without [policy question] also turning on other default-on subfeatures of AVX512). But again - that direction of possible "implications" isn't what my earlier reply was about. As you say, reverse maps would then also be needed, whereas for what I'm suggesting only the deep-deps we already have are necessary: We'd grab the main feature's dependencies and AND that with the default mask before ORing into the domain's policy.

Quoted 3 lines

Whichever algorithm you want, you still need *something* to know that ARCH_CAPS is special and how to arrange the defaults given a non-default overarching setting.

Afaict right now that would be achieved by the same 'a', 'A', '!a", and "!A" annotations, suitably placed on every of the sub-features.

Jan

Quoted 26 lines

When the toolstack infrastructure grows the ability to say no to the user, it will be able to identify explicit user settings which cannot be fulfilled.  (And with a bit more complicated logic, why.)

Quoted 13 lines
Quoted 8 lines
Quoted 5 lines

Wouldn't it make more sense for the
individual bits' exposure qualifiers to become meaningful one to qualifying feature is enabled? I.e. here this would then mean that some ARCH_CAPS bits may become available, while others may require explicit turning on (assuming they weren't all 'A').

I'm afraid I don't follow.  You could make some bits of MSR_ARCH_CAPS itself 'a' vs 'A', and that would have the expected effect (for any VM where arch_caps was visible).

Visible by default, you mean. Whereas I'm considering the case where the CPUID bit is default-off, and turning it on for a guest doesn't at the same time turn on all the 'A' bits in ARCH_CAPS (which hardware offers, or which we synthesize).

Quoted 5 lines

Something similar could be seen / utilized for AMX, where in my pending series I set all the bits to 'a', requiring every individual bit to be turned on along with turning on AMX-TILE. Yet it would be more user friendly if only the top-level bit needed enabling manually, with available sub-features then becoming available "automatically".

I think I've covered all of this in the reply above?

~Andrew

#28 lore raw

Re: [PATCH 6/6] x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

Quoted 23 lines · Jan Beulich
Quoted 15 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
Quoted 3 lines · Jan Beulich

I guess that's no
different from other max-only features with dependents, but I wonder whether that's good behavior.

It's not really something you get a choice over.

Quoted 7 lines
Quoted 3 lines

Default is always less than max, so however you choose to express these concepts, when you're opting-in you're always having to put information back in which was previously stripped out.

But my point is towards the amount of data you need to specify manually. I would find it quite helpful if default-on sub-features became available automatically once the top-level feature was turned on. I guess so far we don't have many such cases, but here you add a whole bunch.

Quoted 7 lines

I'm not suggesting specifying it manually.  That would be a dumb UX move.

But you absolutely cannot have "user turns on EIBRS" meaning "turn on ARCH_CAPS too", because a) that requires creating the reverse feature map which is massively larger than the forward feature map, and b) it creates a vulnerability in the guest, and c) it's ambiguous - e.g. what does turning on a sub-mode of AVX-512 mean for sibling sub-modes?

Quoted 6 lines

Feels like a misunderstanding at this point, because what you're describing above is not what I was referring to. Instead I was specifically referring to "cpuid=...,arch-caps" not having any effect beyond the turning on of the MSR itself (with all-zero content). This is even worse with libxl not even having a way right now to express something like "arch-caps=..." to enable some of the sub-features for guests.

We discussed this on the x86 call.  In summary:

Right now, arch-caps is off-by-default because it doesn't work safely or nicely.  I'm working on safely first, and nicely will come second.

The end result of my work is going to have arch-caps active by default and supported.  End users aren't going to in a position of needing to specify cpuid="...,arch-caps" in their config files.

Fixing libxl's ability to specify the contents is something needing to be done before we can say arch-caps is fully supported, because right now it's the only way users of xl/libxl have for levelling a VM for migrate.

Quoted 9 lines

To explicitly answer the AVX512 part of your reply: Turning on a sub-mode alone could be useful as well (with the effect of also turning on the main feature, and with or without [policy question] also turning on other default-on subfeatures of AVX512). But again - that direction of possible "implications" isn't what my earlier reply was about. As you say, reverse maps would then also be needed, whereas for what I'm suggesting only the deep-deps we already have are necessary: We'd grab the main feature's dependencies and AND that with the default mask before ORing into the domain's policy.

Having discussed this, I agree and specifically have an idea for how to use it for AVX512.  But it is also going to take a fair amount of rearranging in libxl/libxc to make work.

I.e., yes, but not immediately right now.

~Andrew

#29 lore raw

Re: [PATCH 6/6] x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

In reply to Andrew Cooper
Quoted 14 lines · Andrew Cooper
xen/arch/x86/cpu-policy.c +8 -0
@@ -408,6 +408,25 @@ static void __init calculate_host_policy(void)
     p->platform_info.cpuid_faulting = cpu_has_cpuid_faulting;
 }
 
+static void __init guest_common_max_feature_adjustments(uint32_t *fs)
+{
+    if ( boot_cpu_data.x86_vendor == 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
+         * uarch-specific.

xen/arch/x86/cpu-policy.c static void __init calculate_host_policy(void) · line 428

Quoted 10 lines
xen/arch/x86/cpu-policy.c +10 -0
+         *
+         * In particular, the RSBA and RRSBA bits mean "you might migrate to a
+         * system where RSB underflow uses alternative predictors (a.k.a
+         * Retpoline not safe)", so these need to be visible to a guest in all
+         * cases, even when it's only some other server in the pool which
+         * suffers the identified behaviour.
+         */
+        __set_bit(X86_FEATURE_ARCH_CAPS, fs);
+    }
+}

Wouldn't this better be accompanied by marking the bit !a in the public header?

Jan

#30 lore raw

Re: [PATCH 6/6] x86/boot: Expose MSR_ARCH_CAPS data in guest max policies

Quoted 18 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
xen/arch/x86/cpu-policy.c +11 -0
@@ -408,6 +408,25 @@ static void __init calculate_host_policy(void)
     p->platform_info.cpuid_faulting = cpu_has_cpuid_faulting;
 }
 
+static void __init guest_common_max_feature_adjustments(uint32_t *fs)
+{
+    if ( boot_cpu_data.x86_vendor == 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
+         * uarch-specific.
+         *
+         * In particular, the RSBA and RRSBA bits mean "you might migrate to a
+         * system where RSB underflow uses alternative predictors (a.k.a
Quoted 8 lines

xen/arch/x86/cpu-policy.c static void __init calculate_host_policy(void) · line 428

Quoted 7 lines
xen/arch/x86/cpu-policy.c +7 -0
+         * Retpoline not safe)", so these need to be visible to a guest in all
+         * cases, even when it's only some other server in the pool which
+         * suffers the identified behaviour.
+         */
+        __set_bit(X86_FEATURE_ARCH_CAPS, fs);
+    }
+}

Wouldn't this better be accompanied by marking the bit !a in the public header?

Yes, probably.

~Andrew