[PATCH 31/36] cputest: Add support for MSR features to cpu-gather.sh

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds an inline python code for reading MSR features. Since
reading MSRs is a privileged operation, we have to read them from
/dev/cpu/*/msr if it is readable (i.e., the script runs as root) or
fallback to using KVM ioctl which can be done by any user that can start
virtual machines.

The python code is inlined rather than provided in a separate script
because whenever there's an issue with proper detection of CPU features,
we ask the reporter to run cpu-gather.sh script to give us all data we
need to know about the host CPU. Asking them to run several scripts
would likely result in one of them being ignored or forgotten.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 tests/cputestdata/cpu-gather.sh | 49 ++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/tests/cputestdata/cpu-gather.sh b/tests/cputestdata/cpu-gather.sh
index 9c696f57bd..cefd1b0d0d 100755
--- a/tests/cputestdata/cpu-gather.sh
+++ b/tests/cputestdata/cpu-gather.sh
@@ -7,8 +7,55 @@
 grep 'model name' /proc/cpuinfo | head -n1
 
 cpuid -1r
-
 echo
+
+for python in python3 python2; do
+    $python <<EOF
+from __future__ import print_function
+from struct import pack, unpack
+from fcntl import ioctl
+import sys, errno
+
+IA32_ARCH_CAPABILITIES_MSR = 0x10a
+KVM_GET_MSRS = 0xc008ae88
+
+def print_msr(msr, via=None):
+    if via is None:
+        print("MSR:")
+    else:
+        print("MSR via %s:" % via)
+    print("   0x%x: 0x%016x" % (IA32_ARCH_CAPABILITIES_MSR, msr))
+    print()
+
+try:
+    fd = open("/dev/cpu/0/msr", "rb")
+    fd.seek(IA32_ARCH_CAPABILITIES_MSR)
+    buf = fd.read(8)
+    msr = unpack("=Q", buf)[0]
+
+    print_msr(msr)
+    sys.exit(0)
+except IOError as e:
+    # The MSR is not supported on the host
+    if e.errno == errno.EIO:
+        sys.exit(0)
+
+try:
+    fd = open("/dev/kvm", "r")
+    bufIn = pack("=LLLLQ", 1, 0, IA32_ARCH_CAPABILITIES_MSR, 0, 0)
+    bufOut = ioctl(fd, KVM_GET_MSRS, bufIn)
+    msr = unpack("=LLLLQ", bufOut)[4]
+
+    print_msr(msr, via="KVM")
+except IOError as e:
+    pass
+EOF
+
+    if [[ $? -eq 0 ]]; then
+        break
+    fi
+done
+
 qemu=qemu-system-x86_64
 for cmd in /usr/bin/$qemu /usr/bin/qemu-kvm /usr/libexec/qemu-kvm; do
     if [[ -x $cmd ]]; then
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux