cputest: Add support for MSR features to cpu-gather.sh

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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Jiri Denemark 2019-03-26 10:18:10 +01:00
parent 4dbb82a967
commit ab3d6ea0da

View File

@ -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