render / rpms / libvirt

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