diff mbox series

[v6,01/11] lib/x86: Relax checks about policy compatibility

Message ID 20241001123807.605-2-alejandro.vallejo@cloud.com (mailing list archive)
State New
Headers show
Series x86: Expose consistent topology to guests | expand

Commit Message

Alejandro Vallejo Oct. 1, 2024, 12:37 p.m. UTC
Allow a guest policy have up to leaf 0xb even if the host doesn't.
Otherwise it's not possible to show leaf 0xb to guests we're emulating
an x2APIC for on old AMD machines.

No externally visible changes though because toolstack doesn't yet
populate that leaf.

Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
---
 tools/tests/cpu-policy/test-cpu-policy.c |  6 +++++-
 xen/lib/x86/policy.c                     | 11 ++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-policy/test-cpu-policy.c
index 301df2c00285..9216010b1c5d 100644
--- a/tools/tests/cpu-policy/test-cpu-policy.c
+++ b/tools/tests/cpu-policy/test-cpu-policy.c
@@ -586,6 +586,10 @@  static void test_is_compatible_success(void)
                 .platform_info.cpuid_faulting = true,
             },
         },
+        {
+            .name = "Host missing leaf 0xb, Guest wanted",
+            .guest.basic.max_leaf = 0xb,
+        },
     };
     struct cpu_policy_errors no_errors = INIT_CPU_POLICY_ERRORS;
 
@@ -614,7 +618,7 @@  static void test_is_compatible_failure(void)
     } tests[] = {
         {
             .name = "Host basic.max_leaf out of range",
-            .guest.basic.max_leaf = 1,
+            .guest.basic.max_leaf = 0xc,
             .e = { 0, -1, -1 },
         },
         {
diff --git a/xen/lib/x86/policy.c b/xen/lib/x86/policy.c
index f033d22785be..63bc96451d2c 100644
--- a/xen/lib/x86/policy.c
+++ b/xen/lib/x86/policy.c
@@ -15,7 +15,16 @@  int x86_cpu_policies_are_compatible(const struct cpu_policy *host,
 #define FAIL_MSR(m) \
     do { e.msr = (m); goto out; } while ( 0 )
 
-    if ( guest->basic.max_leaf > host->basic.max_leaf )
+    /*
+     * Old AMD hardware doesn't expose topology information in leaf 0xb. We
+     * want to emulate that leaf with credible information because it must be
+     * present on systems in which we emulate the x2APIC.
+     *
+     * For that reason, allow the max basic guest leaf to be larger than the
+     * hosts' up until 0xb.
+     */
+    if ( guest->basic.max_leaf > 0xb &&
+         guest->basic.max_leaf > host->basic.max_leaf )
         FAIL_CPUID(0, NA);
 
     if ( guest->feat.max_subleaf > host->feat.max_subleaf )