]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpuBaseline: Detect empty set of common features
authorJiri Denemark <jdenemar@redhat.com>
Fri, 2 Jul 2010 15:51:40 +0000 (17:51 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 7 Jul 2010 15:25:06 +0000 (17:25 +0200)
In case the set of CPUs has no features in common, report incompatible
CPUs instead of returning the simplest CPU model with all features
disabled.

src/cpu/cpu_x86.c

index 30a2db68fdc9b88534da638446d96ec92ba08f35..0266ce94a9f31058ee8630676ec5e6a813dc1088 100644 (file)
@@ -233,6 +233,26 @@ x86DataSubtract(union cpuData *data1,
 }
 
 
+static bool
+x86DataIsEmpty(union cpuData *data)
+{
+    struct cpuX86cpuid zero = { 0, 0, 0, 0, 0 };
+    unsigned int i;
+
+    for (i = 0; i < data->x86.basic_len; i++) {
+        if (!x86cpuidMatch(data->x86.basic + i, &zero))
+            return false;
+    }
+
+    for (i = 0; i < data->x86.extended_len; i++) {
+        if (!x86cpuidMatch(data->x86.extended + i, &zero))
+            return false;
+    }
+
+    return true;
+}
+
+
 static union cpuData *
 x86DataFromModel(const struct x86_model *model)
 {
@@ -1363,6 +1383,12 @@ x86Baseline(virCPUDefPtr *cpus,
     if (!(data = x86DataFromModel(base_model)))
         goto no_memory;
 
+    if (x86DataIsEmpty(data)) {
+        virCPUReportError(VIR_ERR_OPERATION_FAILED,
+                "%s", _("CPUs are incompatible"));
+        goto error;
+    }
+
     if (x86Decode(cpu, data, models, nmodels, NULL) < 0)
         goto error;