[PATCH v2 0/1] x86: install modules-load.d file to load msr module

This submission is a follow-up (v2) of the discussion (RFC) that was happening at: https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/thread/ADJ4A... On x86, libvirt makes use of the API exposed by the msr kernel module to read the MSR (Model Specific Registers) values. On some Linux distros, this module is not loaded by default so libvirt might fail to read the MSR values and falls back to /dev/kvm to obtain these values. KVM might be behind in term of exposing all the values of the MSRs so using /dev/kvm is not ideal. This submission tries to make libvirt deploy the modules-load.d configuration so that linux loads the msr module at next boot. One caveat, libvirt installs only the file and does not trigger the load that is only done at next reboot, it is up to each distro to trigger immediately the load of the module without a reboot. v2: - only install the file when qemu driver is enabled Hector Cao (1): x86: install modules-load.d file to load msr module 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 -- 2.45.2

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 <hector.cao@canonical.com> --- 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
participants (1)
-
Hector Cao