]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu: Avoid adding <vendor> to custom CPUs
authorJiri Denemark <jdenemar@redhat.com>
Thu, 10 Nov 2016 09:26:03 +0000 (10:26 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 15 Nov 2016 14:49:16 +0000 (15:49 +0100)
Guest CPU definitions with mode='custom' and missing <vendor> are
expected to run on a host CPU from any vendor as long as the required
CPU model can be used as a guest CPU on the host. But even though no CPU
vendor was explicitly requested we would sometimes force it due to a bug
in virCPUUpdate and virCPUTranslate.

The bug would effectively forbid cross vendor migrations even if they
were previously working just fine.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/conf/cpu_conf.c
src/conf/cpu_conf.h
src/cpu/cpu_arm.c
src/cpu/cpu_x86.c
tests/cputestdata/x86-host+guest,model486-result.xml
tests/cputestdata/x86-host+guest,models-result.xml
tests/cputestdata/x86-host+min.xml
tests/cputestdata/x86-host+pentium3.xml
tests/cputestdata/x86-host-Haswell-noTSX+Haswell-noTSX,haswell-result.xml
tests/cputestdata/x86-host-better+pentium3-result.xml

index f17452908c08bd642df64c5855d77ac91063bc14..9eb69c9c85982c464e9f11889ce775c4cfdda699 100644 (file)
@@ -132,20 +132,42 @@ virCPUDefCopyModelFilter(virCPUDefPtr dst,
 }
 
 
+/**
+ * virCPUDefStealModel:
+ *
+ * Move CPU model related parts virCPUDef from @src to @dst. If @keepVendor
+ * is true, the function keeps the original vendor/vendor_id in @dst rather
+ * than overwriting it with the values from @src.
+ */
 void
 virCPUDefStealModel(virCPUDefPtr dst,
-                    virCPUDefPtr src)
+                    virCPUDefPtr src,
+                    bool keepVendor)
 {
+    char *vendor;
+    char *vendor_id;
+
+    if (keepVendor) {
+        VIR_STEAL_PTR(vendor, dst->vendor);
+        VIR_STEAL_PTR(vendor_id, dst->vendor_id);
+    }
+
     virCPUDefFreeModel(dst);
 
     VIR_STEAL_PTR(dst->model, src->model);
-    VIR_STEAL_PTR(dst->vendor, src->vendor);
-    VIR_STEAL_PTR(dst->vendor_id, src->vendor_id);
     VIR_STEAL_PTR(dst->features, src->features);
     dst->nfeatures_max = src->nfeatures_max;
     src->nfeatures_max = 0;
     dst->nfeatures = src->nfeatures;
     src->nfeatures = 0;
+
+    if (keepVendor) {
+        dst->vendor = vendor;
+        dst->vendor_id = vendor_id;
+    } else {
+        VIR_STEAL_PTR(dst->vendor, src->vendor);
+        VIR_STEAL_PTR(dst->vendor_id, src->vendor_id);
+    }
 }
 
 
index e0843926db9ef454869b42506b5f646d8d91fc31..cc3fbf0a45b95d23f5923f404000807ceb77b04e 100644 (file)
@@ -139,7 +139,8 @@ virCPUDefCopyModelFilter(virCPUDefPtr dst,
 
 void
 virCPUDefStealModel(virCPUDefPtr dst,
-                    virCPUDefPtr src);
+                    virCPUDefPtr src,
+                    bool keepVendor);
 
 virCPUDefPtr
 virCPUDefCopy(const virCPUDef *cpu);
index db603a678a8880fa6ab3e8147b92507a763a3070..b5002c3720fea75ef5a3387b241aa47a26c1e20c 100644 (file)
@@ -67,7 +67,7 @@ virCPUarmUpdate(virCPUDefPtr guest,
     if (virCPUDefCopyModel(updated, host, true) < 0)
         goto cleanup;
 
-    virCPUDefStealModel(guest, updated);
+    virCPUDefStealModel(guest, updated, false);
     guest->mode = VIR_CPU_MODE_CUSTOM;
     guest->match = VIR_CPU_MATCH_EXACT;
     ret = 0;
index 4f2a111b8246ab8a416b44f56aa0b476b90b74d6..851ec5dfe9b07c2da76e7b77e9e2ebb43624e8da 100644 (file)
@@ -2576,7 +2576,8 @@ x86UpdateHostModel(virCPUDefPtr guest,
             goto cleanup;
     }
 
-    virCPUDefStealModel(guest, updated);
+    virCPUDefStealModel(guest, updated,
+                        guest->mode == VIR_CPU_MODE_CUSTOM);
     guest->mode = VIR_CPU_MODE_CUSTOM;
     guest->match = VIR_CPU_MATCH_EXACT;
     ret = 0;
@@ -2737,7 +2738,7 @@ virCPUx86Translate(virCPUDefPtr cpu,
             goto cleanup;
     }
 
-    virCPUDefStealModel(cpu, translated);
+    virCPUDefStealModel(cpu, translated, true);
     ret = 0;
 
  cleanup:
index 88df4679b0c2ae9d1f0658adbeb18708e279f0f0..85564ff45897cd50253ce7fec85809c9515f8293 100644 (file)
@@ -1,6 +1,5 @@
 <cpu mode='custom' match='exact'>
   <model fallback='allow'>486</model>
-  <vendor>Intel</vendor>
   <topology sockets='2' cores='4' threads='1'/>
   <feature policy='require' name='de'/>
   <feature policy='require' name='tsc'/>
index e7a77c27e45de8c14b9441d30d15c5632f75182a..f79ed324c158eb15b398c4cc163b5c7ca6c1bcf0 100644 (file)
@@ -1,6 +1,5 @@
 <cpu mode='custom' match='exact'>
   <model fallback='allow'>Nehalem</model>
-  <vendor>Intel</vendor>
   <topology sockets='2' cores='4' threads='1'/>
   <feature policy='force' name='pbe'/>
   <feature policy='force' name='monitor'/>
index a2847673793f558099ec8398ca82729c77a4e85a..81011517bb6bdecfa902d7c6684dfa8c17e5e9d7 100644 (file)
@@ -1,6 +1,5 @@
 <cpu mode='custom' match='exact'>
   <model fallback='allow'>Penryn</model>
-  <vendor>Intel</vendor>
   <feature policy='require' name='dca'/>
   <feature policy='require' name='xtpr'/>
   <feature policy='require' name='tm2'/>
index a2847673793f558099ec8398ca82729c77a4e85a..81011517bb6bdecfa902d7c6684dfa8c17e5e9d7 100644 (file)
@@ -1,6 +1,5 @@
 <cpu mode='custom' match='exact'>
   <model fallback='allow'>Penryn</model>
-  <vendor>Intel</vendor>
   <feature policy='require' name='dca'/>
   <feature policy='require' name='xtpr'/>
   <feature policy='require' name='tm2'/>
index 5902f6c76f6cfbc66060e684075ed653db4e4c1a..5d149bb295d89c1954174cba42da2cae5607422c 100644 (file)
@@ -1,6 +1,5 @@
 <cpu mode='custom' match='exact'>
   <model fallback='allow'>Haswell</model>
-  <vendor>Intel</vendor>
   <topology sockets='1' cores='2' threads='2'/>
   <feature policy='disable' name='hle'/>
   <feature policy='disable' name='rtm'/>
index 12336daf900ce7ce6f9555450675ac2b66820c31..9d4f98f09e51a86414ac96db8d6ff2b0959767e5 100644 (file)
@@ -1,6 +1,5 @@
 <cpu mode='custom' match='exact'>
   <model fallback='allow'>Nehalem</model>
-  <vendor>Intel</vendor>
   <feature policy='require' name='dca'/>
   <feature policy='require' name='xtpr'/>
   <feature policy='require' name='tm2'/>