render / rpms / libvirt

Forked from rpms/libvirt 7 months ago
Clone
c313de
From 0004d2f3b0c3b21336415a967d70b7e9c2d08f54 Mon Sep 17 00:00:00 2001
c313de
Message-Id: <0004d2f3b0c3b21336415a967d70b7e9c2d08f54@dist-git>
c313de
From: Jiri Denemark <jdenemar@redhat.com>
c313de
Date: Fri, 21 Jun 2019 09:26:09 +0200
c313de
Subject: [PATCH] cpu_x86: Read CPU features from IA32_ARCH_CAPABILITIES MSR
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
This is used by the host capabilities code to construct host CPU
c313de
definition.
c313de
c313de
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
(cherry picked from commit 56b254dccc96b7339494812c9df07ccf6af3da95)
c313de
c313de
https://bugzilla.redhat.com/show_bug.cgi?id=1697627
c313de
c313de
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c313de
Message-Id: <58ad207c48e0f2a6c44ff097b0881b649826ecd4.1561068591.git.jdenemar@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/cpu/cpu_x86.c | 22 ++++++++++++++++++++++
c313de
 1 file changed, 22 insertions(+)
c313de
c313de
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
c313de
index ec0e408f98..0a520f07ff 100644
c313de
--- a/src/cpu/cpu_x86.c
c313de
+++ b/src/cpu/cpu_x86.c
c313de
@@ -2771,6 +2771,28 @@ virCPUx86GetHost(virCPUDefPtr cpu,
c313de
         cpuidSet(CPUX86_EXTENDED, cpuData) < 0)
c313de
         goto cleanup;
c313de
 
c313de
+    /* Read the IA32_ARCH_CAPABILITIES MSR (0x10a) if supported.
c313de
+     * This is best effort since there might be no way to read the MSR
c313de
+     * when we are not running as root. */
c313de
+    if (virCPUx86DataCheckFeature(cpuData, "arch-capabilities") == 1) {
c313de
+        uint64_t msr;
c313de
+        unsigned long index = 0x10a;
c313de
+
c313de
+        if (virHostCPUGetMSR(index, &msr) == 0) {
c313de
+            virCPUx86DataItem item = {
c313de
+                .type = VIR_CPU_X86_DATA_MSR,
c313de
+                .data.msr = {
c313de
+                    .index = index,
c313de
+                    .eax = msr & 0xffffffff,
c313de
+                    .edx = msr >> 32,
c313de
+                },
c313de
+            };
c313de
+
c313de
+            if (virCPUx86DataAdd(cpuData, &item) < 0)
c313de
+                return -1;
c313de
+        }
c313de
+    }
c313de
+
c313de
     ret = x86DecodeCPUData(cpu, cpuData, models);
c313de
     cpu->microcodeVersion = virHostCPUGetMicrocodeVersion();
c313de
 
c313de
-- 
c313de
2.22.0
c313de