]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu: Introduce virCPUUpdateFeatures
authorJiri Denemark <jdenemar@redhat.com>
Mon, 25 May 2026 12:22:58 +0000 (14:22 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 2 Jun 2026 11:45:26 +0000 (13:45 +0200)
This new API can be used to update an existing CPU definition with
features described by CPU data.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/cpu/cpu.c
src/cpu/cpu.h
src/cpu/cpu_x86.c
src/libvirt_private.syms

index d81e620a1d596568399960329ca5f413d3c4cc6f..3e9affa1cd5f0d648c949917bbc92118c7444a48 100644 (file)
@@ -1359,6 +1359,40 @@ virCPUGetCanonicalModel(virArch arch,
 }
 
 
+/** virCPUUpdateFeatures:
+ *
+ * @arch: CPU architecture
+ * @cpu: CPU definition to update
+ * @cpuData: CPU data describing features
+ * @policy: to be used by the updated features
+ *
+ * Updates features described in @cpuData to use the specified @policy. Missing
+ * features will be automatically added to the CPU definition.
+ *
+ * Returns 0 on success, -1 otherwise.
+ */
+int
+virCPUUpdateFeatures(virArch arch,
+                     virCPUDef *cpu,
+                     virCPUData *cpuData,
+                     virCPUFeaturePolicy policy)
+{
+    struct cpuArchDriver *driver;
+
+    VIR_DEBUG("arch=%s, cpu=%p, model=%s, policy=%s",
+              virArchToString(arch), cpu, NULLSTR(cpu->model),
+              virCPUFeaturePolicyTypeToString(policy));
+
+    if (!(driver = cpuGetSubDriver(arch)))
+        return -1;
+
+    if (!driver->updateFeatures)
+        return 0;
+
+    return driver->updateFeatures(cpu, cpuData, policy);
+}
+
+
 /**
  * virCPUArchIsSupported:
  *
index 36fd1236754221ea7bee0f65c988c65a7254032d..65711ac08557c9a6fe4eeea02354f4308e6627b4 100644 (file)
@@ -143,6 +143,11 @@ typedef int
 typedef const char *
 (*virCPUArchGetCanonicalModel)(const char *model);
 
+typedef int
+(*virCPUArchUpdateFeatures)(virCPUDef *cpu,
+                            virCPUData *cpuData,
+                            virCPUFeaturePolicy policy);
+
 struct cpuArchDriver {
     const char *name;
     const virArch *arch;
@@ -172,6 +177,7 @@ struct cpuArchDriver {
     virCPUArchDataGetHost dataGetHost;
     virCPUArchGetCheckMode getCheckMode;
     virCPUArchGetCanonicalModel getCanonicalModel;
+    virCPUArchUpdateFeatures updateFeatures;
 };
 
 
@@ -332,6 +338,12 @@ const char *
 virCPUGetCanonicalModel(virArch arch,
                         const char *model);
 
+int
+virCPUUpdateFeatures(virArch arch,
+                     virCPUDef *cpu,
+                     virCPUData *cpuData,
+                     virCPUFeaturePolicy policy);
+
 bool
 virCPUArchIsSupported(virArch arch);
 
index 4e45ed96b5baca856e9c94be2dfbd12714f68efd..18c5756ef9bfb23463e3e998af70631704976948 100644 (file)
@@ -3789,6 +3789,28 @@ virCPUx86GetCanonicalModel(const char *modelName)
 }
 
 
+static int
+virCPUx86UpdateFeatures(virCPUDef *cpu,
+                        virCPUData *cpuData,
+                        virCPUFeaturePolicy policy)
+{
+    virCPUx86Data *data = &cpuData->data.x86;
+    virCPUx86Map *map;
+    size_t i;
+
+    if (!(map = virCPUx86GetMap()))
+        return -1;
+
+    for (i = 0; i < map->nfeatures; i++) {
+        virCPUx86Feature *feature = map->features[i];
+        if (x86DataIsSubset(data, &feature->data))
+            virCPUDefUpdateFeature(cpu, feature->name, policy);
+    }
+
+    return 0;
+}
+
+
 struct cpuArchDriver cpuDriverX86 = {
     .name = "x86",
     .arch = archs,
@@ -3823,4 +3845,5 @@ struct cpuArchDriver cpuDriverX86 = {
 #endif
     .getCheckMode = virCPUx86GetCheckMode,
     .getCanonicalModel = virCPUx86GetCanonicalModel,
+    .updateFeatures = virCPUx86UpdateFeatures,
 };
index 762c409c2a53a717a78dfef0cc6ecb2162bb59a9..30c456445674705cc8028804cd64843c218f6fe4 100644 (file)
@@ -1593,6 +1593,7 @@ virCPUGetVendorForModel;
 virCPUProbeHost;
 virCPUTranslate;
 virCPUUpdate;
+virCPUUpdateFeatures;
 virCPUUpdateLive;
 virCPUValidateFeatures;