]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
kmod-setup: fix loading virtio related drivers
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 3 Feb 2026 07:59:49 +0000 (16:59 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 13 Feb 2026 07:14:54 +0000 (16:14 +0900)
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

index e8230d4adf87aa4d5e10dae9dda70c31b0c2a7ab..82b53959b3a52e7642df095cee880444fab0c572 100644 (file)
@@ -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 */