On recent Intel CPUs, some of the CPU features (e.g.
vmx-* sub-features) are listed and controlled via the
MSRs (Model Specific Registers) instead of the traditional
CPUID instruction method.
To be able to read the MSR's values, the kernel module msr
has to be loaded and the values can be read via /dev/cpu/*/msr.
This commit introduces following changes:
- install modules-load.d file for msr for x86 and when qemu
driver is enabled.
by default, this option is enabled but user can disable it
via a build option:
meson ... -Dmsr_module_load=false ... build
- modify virt-host-validate to check of /dev/cpu/*/msr is
available.
Signed-off-by: Hector Cao <[email protected]>
---
meson_options.txt | 1 +
src/util/meson.build | 19 +++++++++++++++++++
src/util/modules-load.d/msr.conf | 1 +
tools/virt-host-validate-qemu.c | 7 +++++++
4 files changed, 28 insertions(+)
create mode 100644 src/util/modules-load.d/msr.conf
diff --git a/meson_options.txt b/meson_options.txt
index 3dc3e8667b..5a9e067407 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -135,3 +135,4 @@ option('sysctl_config', type: 'feature', value: 'auto',
description: 'Whether to
# dep:sysctl_config
option('userfaultfd_sysctl', type: 'feature', value: 'auto', description:
'Whether to install sysctl config for enabling unprivileged userfaultfd')
option('tls_priority', type: 'string', value: 'NORMAL', description: 'set the
default TLS session priority string')
+option('msr_module_load', type: 'boolean', value: true, description: 'Install
modules-load.d file for msr module on x86')
diff --git a/src/util/meson.build b/src/util/meson.build
index 69ef49139a..024c05f0dd 100644
--- a/src/util/meson.build
+++ b/src/util/meson.build
@@ -225,3 +225,22 @@ if conf.has('WITH_LIBVIRTD')
endif
util_inc_dir = include_directories('.')
+
+# Install the modules-load.d file to load the MSR module
+# NB: For the file to taken into account and the module load to happen, users
must trigger
+# the modules-load.d reload (by reboot or restart the systemd-modules-load
service).
+msr_module_load = get_option('msr_module_load')
+if (msr_module_load and
+ get_option('driver_qemu').enabled() and
+ (host_machine.cpu_family() == 'x86' or host_machine.cpu_family() ==
'x86_64'))
+ message('msr_module_load: Enabling installation of modules-load.d/msr.conf
for x86')
+
+ install_data(
+ 'modules-load.d/msr.conf',
+ install_dir: join_paths(sysconfdir, 'modules-load.d')
+ )
+elif msr_module_load
+ message('msr_module_load: option enabled, but not applicable : skipping')
+else
+ message('msr_module_load: option disabled: skipping')
+endif
\ No newline at end of file
diff --git a/src/util/modules-load.d/msr.conf b/src/util/modules-load.d/msr.conf
new file mode 100644
index 0000000000..3e5ee7fa15
--- /dev/null
+++ b/src/util/modules-load.d/msr.conf
@@ -0,0 +1 @@
+msr
diff --git a/tools/virt-host-validate-qemu.c b/tools/virt-host-validate-qemu.c
index 833bb1b914..f582e1146e 100644
--- a/tools/virt-host-validate-qemu.c
+++ b/tools/virt-host-validate-qemu.c
@@ -95,6 +95,13 @@ int virHostValidateQEMU(void)
virValidatePass();
}
+ if (arch == VIR_ARCH_X86_64) {
+ if (virHostValidateDeviceExists("QEMU", "/dev/cpu/0/msr",
+ VIR_HOST_VALIDATE_WARN,
+ _("Load the 'msr' module for better
x86 CPU features detection")) < 0)
+ ret = -1;
+ }
+
if (virHostValidateDeviceExists("QEMU", "/dev/vhost-net",
VIR_VALIDATE_WARN,
_("Load the 'vhost_net' module to improve
performance of virtio networking")) < 0)
--
2.45.2