libxc: allow changing max number of hypervisor cpuid leaves
authorBoris Ostrovsky <boris.ostrovsky@oracle.com>
Fri, 2 May 2014 10:03:36 +0000 (12:03 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 2 May 2014 10:03:36 +0000 (12:03 +0200)
Add support for changing max number of hypervisor leaves from configuration
file.

This number can be specified using xl's standard 'cpuid' option. Only lowest
8 bits of leaf's 0x4000xx00 eax register are processed, all others are ignored.

The changes allow us to revert commit 80ecb40362365ba77e68fc609de8bd3b7208ae19
which is most likely no longer needed now anyway (Solaris bug that it addressed
has been fixed and backported to earlier releases) but leave possibility of
running unpatched version of Solaris by forcing number of leaves to 2 in the
configuration file.

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
docs/man/xl.cfg.pod.5
tools/libxc/xc_cpuid_x86.c
tools/libxl/libxl_cpuid.c
xen/arch/x86/traps.c
xen/include/public/arch-x86/cpuid.h

index c8ce6c18805960a451de53c7daf3c8e63e36c44d..0ca37bc7582dab405f1fef285a9bbe90fb9bab5a 100644 (file)
@@ -881,9 +881,13 @@ Possible values for a single feature bit:
   'k' -> pass through the host bit value
   's' -> as 'k' but preserve across save/restore and migration (not implemented)
 
+Note: when specifying B<cpuid> for hypervisor leaves (0x4000xxxx major group)
+only the lowest 8 bits of leaf's 0x4000xx00 EAX register are processed, the rest
+are ignored (these 8 bits signify maximum number of hypervisor leaves).
+
 List of keys taking a value:
-apicidsize brandid clflush family localapicid maxleaf model nc proccount procpkg
-stepping
+apicidsize brandid clflush family localapicid maxleaf maxhvleaf model nc
+proccount procpkg stepping
 
 List of keys taking a character:
 3dnow 3dnowext 3dnowprefetch abm acpi aes altmovcr8 apic avx clfsh cmov
index 71917e30c92258f8b51fa593ae47c03548b04936..6a02bf011da8cbb38a005c57134abea62fe2f49f 100644 (file)
@@ -561,6 +561,17 @@ static int xc_cpuid_policy(
 {
     xc_dominfo_t        info;
 
+    /*
+     * For hypervisor leaves (0x4000XXXX) only 0x4000xx00.EAX[7:0] bits (max
+     * number of leaves) can be set by user. Hypervisor will enforce this so
+     * all other bits are don't-care and we can set them to zero.
+     */
+    if ( (input[0] & 0xffff0000) == 0x40000000 )
+    {
+        regs[0] = regs[1] = regs[2] = regs[3] = 0;
+        return 0;
+    }
+
     if ( xc_domain_getinfo(xch, domid, 1, &info) == 0 )
         return -EINVAL;
 
index dd21b78864d871b32cdb545e27682accc2a12183..d1ea50d1ef5a45e8cdc0469c5e0c76131e641bc2 100644 (file)
@@ -187,6 +187,7 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str)
         {"svm_vmcbclean",0x8000000a, NA, CPUID_REG_EDX,  5,  1},
         {"svm_decode",   0x8000000a, NA, CPUID_REG_EDX,  7,  1},
         {"svm_pausefilt",0x8000000a, NA, CPUID_REG_EDX, 10,  1},
+        {"maxhvleaf",    0x40000000, NA, CPUID_REG_EAX,  0,  8},
 
         {NULL, 0, NA, CPUID_REG_INV, 0, 0}
     };
index 45070bb974b02fade1387880ee35a350eebed9e2..d6114f86e4b81a31dae1f454686ca75b3a7540e9 100644 (file)
@@ -677,15 +677,19 @@ int cpuid_hypervisor_leaves( uint32_t idx, uint32_t sub_idx,
     struct domain *d = current->domain;
     /* Optionally shift out of the way of Viridian architectural leaves. */
     uint32_t base = is_viridian_domain(d) ? 0x40000100 : 0x40000000;
-    uint32_t limit;
+    uint32_t limit, dummy;
 
     idx -= base;
-
-    /*
-     * Some Solaris PV drivers fail if max > base + 2. Help them out by
-     * hiding the PVRDTSCP leaf if PVRDTSCP is disabled.
-     */
-    limit = (d->arch.tsc_mode < TSC_MODE_PVRDTSCP) ? 2 : 3;
+    if ( idx > XEN_CPUID_MAX_NUM_LEAVES )
+        return 0; /* Avoid unnecessary pass through domain_cpuid() */
+
+    /* Number of leaves may be user-specified */
+    domain_cpuid(d, base, 0, &limit, &dummy, &dummy, &dummy);
+    limit &= 0xff;
+    if ( limit < 2 )
+        limit = 2;
+    else if ( limit > XEN_CPUID_MAX_NUM_LEAVES )
+        limit = XEN_CPUID_MAX_NUM_LEAVES;
 
     if ( idx > limit ) 
         return 0;
index d9bd62714fbf3283cde39ee357eaba1fb14db803..19fc9ddf705444a09567ed9b6808e2c365b531eb 100644 (file)
@@ -65,4 +65,6 @@
 #define _XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD 0
 #define XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD  (1u<<0)
 
+#define XEN_CPUID_MAX_NUM_LEAVES 3
+
 #endif /* __XEN_PUBLIC_ARCH_X86_CPUID_H__ */