]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu_x86: Read CPU features from IA32_ARCH_CAPABILITIES MSR
authorJiri Denemark <jdenemar@redhat.com>
Fri, 22 Mar 2019 15:52:21 +0000 (16:52 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 20 Jun 2019 12:02:36 +0000 (14:02 +0200)
This is used by the host capabilities code to construct host CPU
definition.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/cpu/cpu_x86.c

index 4624ebaff56ea1607b775228cf520533ca559af0..71fc365139b87f42bbc46a0d184da6c96f71a579 100644 (file)
@@ -2773,6 +2773,28 @@ virCPUx86GetHost(virCPUDefPtr cpu,
         cpuidSet(CPUX86_EXTENDED, cpuData) < 0)
         goto cleanup;
 
+    /* Read the IA32_ARCH_CAPABILITIES MSR (0x10a) if supported.
+     * This is best effort since there might be no way to read the MSR
+     * when we are not running as root. */
+    if (virCPUx86DataCheckFeature(cpuData, "arch-capabilities") == 1) {
+        uint64_t msr;
+        unsigned long index = 0x10a;
+
+        if (virHostCPUGetMSR(index, &msr) == 0) {
+            virCPUx86DataItem item = {
+                .type = VIR_CPU_X86_DATA_MSR,
+                .data.msr = {
+                    .index = index,
+                    .eax = msr & 0xffffffff,
+                    .edx = msr >> 32,
+                },
+            };
+
+            if (virCPUx86DataAdd(cpuData, &item) < 0)
+                return -1;
+        }
+    }
+
     ret = x86DecodeCPUData(cpu, cpuData, models);
     cpu->microcodeVersion = virHostCPUGetMicrocodeVersion();