]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
cpu: Let explicit features override model features
authorJiri Denemark <jdenemar@redhat.com>
Sat, 20 Jul 2013 22:27:40 +0000 (00:27 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 22 Jul 2013 11:57:53 +0000 (13:57 +0200)
Until now CPU features inherited from a specified CPU model could only
be overridden with 'disable' policy. With this patch, any explicitly
specified feature always overrides the same feature inherited from a CPU
model regardless on the specified policy.

The CPU in x86-exact-force-Haswell.xml would previously be incompatible
with x86-host-SandyBridge.xml CPU even though x86-host-SandyBridge.xml
provides all features required by x86-exact-force-Haswell.xml.

src/cpu/cpu_x86.c
tests/cputest.c
tests/cputestdata/x86-exact-force-Haswell.xml [new file with mode: 0644]
tests/cputestdata/x86-host-SandyBridge.xml [new file with mode: 0644]

index 4564bd4743cffadb7c0d5da14a81395de2535392..a388f0f2b8b8590cbe83fb95aead70627bb6d8a0 100644 (file)
@@ -1223,6 +1223,11 @@ x86Compute(virCPUDefPtr host,
         goto out;
     }
 
+    /* first remove features that were inherited from the CPU model and were
+     * explicitly forced, disabled, or made optional
+     */
+    x86DataSubtract(cpu_require->data, cpu_force->data);
+    x86DataSubtract(cpu_require->data, cpu_optional->data);
     x86DataSubtract(cpu_require->data, cpu_disable->data);
     result = x86ModelCompare(host_model, cpu_require);
     if (result == SUBSET || result == UNRELATED) {
index 6abe18ded4b288a6c02d1e7a2f1c036e3f06659f..2e5f0cdfb86053a24d3bc0129d9f00de57a906ff 100644 (file)
@@ -581,6 +581,7 @@ mymain(void)
     DO_TEST_COMPARE("x86", "host", "pentium3-amd", VIR_CPU_COMPARE_INCOMPATIBLE);
     DO_TEST_COMPARE("x86", "host-amd", "pentium3-amd", VIR_CPU_COMPARE_SUPERSET);
     DO_TEST_COMPARE("x86", "host-worse", "nehalem-force", VIR_CPU_COMPARE_IDENTICAL);
+    DO_TEST_COMPARE("x86", "host-SandyBridge", "exact-force-Haswell", VIR_CPU_COMPARE_IDENTICAL);
 
     /* guest updates for migration
      * automatically compares host CPU with the result */
diff --git a/tests/cputestdata/x86-exact-force-Haswell.xml b/tests/cputestdata/x86-exact-force-Haswell.xml
new file mode 100644 (file)
index 0000000..614ed7e
--- /dev/null
@@ -0,0 +1,15 @@
+<cpu mode='custom' match='exact'>
+  <model fallback='allow'>Haswell</model>
+  <feature policy='force' name='pcid'/>
+  <feature policy='force' name='rtm'/>
+  <feature policy='force' name='invpcid'/>
+  <feature policy='force' name='erms'/>
+  <feature policy='force' name='bmi2'/>
+  <feature policy='optional' name='smep'/>
+  <feature policy='optional' name='avx2'/>
+  <feature policy='optional' name='hle'/>
+  <feature policy='force' name='bmi1'/>
+  <feature policy='force' name='fsgsbase'/>
+  <feature policy='disable' name='movbe'/>
+  <feature policy='disable' name='fma'/>
+</cpu>
diff --git a/tests/cputestdata/x86-host-SandyBridge.xml b/tests/cputestdata/x86-host-SandyBridge.xml
new file mode 100644 (file)
index 0000000..7f26b7b
--- /dev/null
@@ -0,0 +1,6 @@
+<cpu>
+  <arch>x86_64</arch>
+  <model>SandyBridge</model>
+  <vendor>Intel</vendor>
+  <topology sockets='1' cores='2' threads='2'/>
+</cpu>