]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu_x86: Introduce virCPUx86DataAddMSR
authorJiri Denemark <jdenemar@redhat.com>
Mon, 25 May 2026 11:17:47 +0000 (13:17 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 2 Jun 2026 11:45:26 +0000 (13:45 +0200)
This just makes the relevant part of virCPUx86GetHost reusable in other
places.

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

index 3a18d859dc29b48cd22adbd25560157c221cc79c..4e45ed96b5baca856e9c94be2dfbd12714f68efd 100644 (file)
@@ -2911,18 +2911,8 @@ virCPUx86GetHost(virCPUDef *cpu,
     /* This is best effort since there might be no way to read the MSR
      * when we are not running as root. */
     for (i = 0; i < nmsrs; i++) {
-        if (virHostCPUGetMSR(msrs[i], &msr) == 0) {
-            virCPUx86DataItem item = {
-                .type = VIR_CPU_X86_DATA_MSR,
-                .data.msr = {
-                    .index = msrs[i],
-                    .eax = msr & 0xffffffff,
-                    .edx = msr >> 32,
-                },
-            };
-
-            virCPUx86DataAdd(cpuData, &item);
-        }
+        if (virHostCPUGetMSR(msrs[i], &msr) == 0)
+            virCPUx86DataAddMSR(cpuData, msrs[i], msr);
     }
 
     ret = x86DecodeCPUData(cpu, cpuData, models);
@@ -3460,6 +3450,32 @@ virCPUx86DataAdd(virCPUData *cpuData,
 }
 
 
+/**
+ * virCPUx86DataAddMSR:
+ * @cpuData: CPU data to update
+ * @index: MSR index
+ * @value: content of the @index MSR
+ *
+ * Adds the specified MSR content to CPU data.
+ */
+void
+virCPUx86DataAddMSR(virCPUData *cpuData,
+                    uint32_t index,
+                    uint64_t value)
+{
+    virCPUx86DataItem item = {
+        .type = VIR_CPU_X86_DATA_MSR,
+        .data.msr = {
+            .index = index,
+            .eax = value & 0xffffffff,
+            .edx = value >> 32,
+        },
+    };
+
+    virCPUx86DataAdd(cpuData, &item);
+}
+
+
 void
 virCPUx86DataSetSignature(virCPUData *cpuData,
                           unsigned int family,
index 2cd965fea4cebf2c434599b01f1e46fb7e359435..bbc2a16447f97a868d122b0756e1fed6c15818ca 100644 (file)
@@ -28,6 +28,10 @@ extern struct cpuArchDriver cpuDriverX86;
 void virCPUx86DataAdd(virCPUData *cpuData,
                       const virCPUx86DataItem *cpuid);
 
+void virCPUx86DataAddMSR(virCPUData *cpuData,
+                         uint32_t index,
+                         uint64_t value);
+
 void virCPUx86DataSetSignature(virCPUData *cpuData,
                                unsigned int family,
                                unsigned int model,
index db59695a45551a0f39176e39b47bffd1edfcadb7..762c409c2a53a717a78dfef0cc6ecb2162bb59a9 100644 (file)
@@ -1599,6 +1599,7 @@ virCPUValidateFeatures;
 
 # cpu/cpu_x86.h
 virCPUx86DataAdd;
+virCPUx86DataAddMSR;
 virCPUx86DataGetSignature;
 virCPUx86DataSetSignature;
 virCPUx86DataSetVendor;