From 6d36e5fae618aeadc6b4ff39db6ec2cfa777543f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 3 Feb 2026 16:59:49 +0900 Subject: [PATCH] kmod-setup: fix loading virtio related drivers It seems the device with modalias e.g. virtio:d00000013v, only appears after the relevant module is loaded. So, we cannot use the string to determine if we should load the module. Fixes #40503. --- src/core/kmod-setup.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/core/kmod-setup.c b/src/core/kmod-setup.c index e8230d4adf8..82b53959b3a 100644 --- a/src/core/kmod-setup.c +++ b/src/core/kmod-setup.c @@ -74,22 +74,15 @@ static bool has_virtio_rng(void) { return has_virtio_feature("virtio-rng", STRV_MAKE("pci:v00001AF4d00001005", "pci:v00001AF4d00001044")); } -static bool has_virtio_console(void) { - return has_virtio_feature("virtio-console", STRV_MAKE("virtio:d00000003v", "virtio:d0000000Bv")); -} - -static bool has_virtio_vsock(void) { - return has_virtio_feature("virtio-vsock", STRV_MAKE("virtio:d00000013v")); -} - -static bool has_virtiofs(void) { - return has_virtio_feature("virtiofs", STRV_MAKE("virtio:d0000001Av")); -} - static bool has_virtio_pci(void) { return has_virtio_feature("virtio-pci", STRV_MAKE("pci:v00001AF4d")); } +static bool may_have_virtio(void) { + /* FIXME: strictly speaking, other virtio features, e.g. vsock, are independent of the virtio PCI device. */ + return has_virtio_pci(); +} + static bool in_qemu(void) { return IN_SET(detect_vm(), VIRTUALIZATION_KVM, VIRTUALIZATION_QEMU); } @@ -117,10 +110,10 @@ int kmod_setup(void) { /* we want early logging to hvc consoles if possible, and make sure systemd-getty-generator * can rely on all consoles being probed already. */ - { "virtio_console", NULL, false, false, has_virtio_console }, + { "virtio_console", NULL, false, false, may_have_virtio }, /* Make sure we can send sd-notify messages over vsock as early as possible. */ - { "vmw_vsock_virtio_transport", NULL, false, false, has_virtio_vsock }, + { "vmw_vsock_virtio_transport", NULL, false, false, may_have_virtio }, /* We can't wait for specific virtiofs tags to show up as device nodes so we have to load the * virtiofs and virtio_pci modules early to make sure the virtiofs tags are found when @@ -128,7 +121,7 @@ int kmod_setup(void) { * * TODO: Remove these again once https://gitlab.com/virtio-fs/virtiofsd/-/issues/128 is * resolved and the kernel fix is widely available. */ - { "virtiofs", "/sys/module/virtiofs", false, false, has_virtiofs }, + { "virtiofs", "/sys/module/virtiofs", false, false, may_have_virtio }, { "virtio_pci", "/sys/module/virtio_pci", false, false, has_virtio_pci }, /* qemu_fw_cfg would be loaded by udev later, but we want to import credentials from it super early */ -- 2.47.3