]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
kmod-setup: Load virtio-vsock kernel module early
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 27 May 2023 09:32:39 +0000 (11:32 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 30 May 2023 12:48:38 +0000 (14:48 +0200)
We might want to send sd-notify over vsock very early on so let's
make sure we load the relevant kernel module as early as possible.

src/core/kmod-setup.c

index c09e17f568bac85a981511deef0f32dfe78393a1..a99309f5c223de30ff11ca6907163ddfc75732b5 100644 (file)
@@ -107,6 +107,27 @@ static bool has_virtio_console(void) {
         return r > 0;
 }
 
+static bool has_virtio_vsock(void) {
+        int r;
+
+        /* Directory traversal might be slow, hence let's do a cheap check first if it's even worth it */
+        if (detect_vm() == VIRTUALIZATION_NONE)
+                return false;
+
+        r = recurse_dir_at(
+                        AT_FDCWD,
+                        "/sys/devices/pci0000:00",
+                        /* statx_mask= */ 0,
+                        /* n_depth_max= */ 3,
+                        RECURSE_DIR_ENSURE_TYPE,
+                        match_modalias_recurse_dir_cb,
+                        STRV_MAKE("virtio:d00000013v"));
+        if (r < 0)
+                log_debug_errno(r, "Failed to determine whether host has virtio-vsock device, ignoring: %m");
+
+        return r > 0;
+}
+
 static bool in_qemu(void) {
         return IN_SET(detect_vm(), VIRTUALIZATION_KVM, VIRTUALIZATION_QEMU);
 }
@@ -124,35 +145,38 @@ int kmod_setup(void) {
         } kmod_table[] = {
                 /* This one we need to load explicitly, since auto-loading on use doesn't work
                  * before udev created the ghost device nodes, and we need it earlier than that. */
-                { "autofs4",         "/sys/class/misc/autofs",    true,  false, NULL               },
+                { "autofs4",                    "/sys/class/misc/autofs",    true,  false, NULL               },
 
                 /* This one we need to load explicitly, since auto-loading of IPv6 is not done when
                  * we try to configure ::1 on the loopback device. */
-                { "ipv6",            "/sys/module/ipv6",          false, true,  NULL               },
+                { "ipv6",                       "/sys/module/ipv6",          false, true,  NULL               },
 
                 /* This should never be a module */
-                { "unix",            "/proc/net/unix",            true,  true,  NULL               },
+                { "unix",                       "/proc/net/unix",            true,  true,  NULL               },
 
 #if HAVE_LIBIPTC
                 /* netfilter is needed by networkd, nspawn among others, and cannot be autoloaded */
-                { "ip_tables",       "/proc/net/ip_tables_names", false, false, NULL               },
+                { "ip_tables",                  "/proc/net/ip_tables_names", false, false, NULL               },
 #endif
                 /* virtio_rng would be loaded by udev later, but real entropy might be needed very early */
-                { "virtio_rng",      NULL,                        false, false, has_virtio_rng     },
+                { "virtio_rng",                 NULL,                        false, false, has_virtio_rng     },
 
                 /* 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, has_virtio_console },
+
+                /* Make sure we can send sd-notify messages over vsock as early as possible. */
+                { "vmw_vsock_virtio_transport", NULL,                        false, false, has_virtio_vsock   },
 
                 /* qemu_fw_cfg would be loaded by udev later, but we want to import credentials from it super early */
-                { "qemu_fw_cfg",     "/sys/firmware/qemu_fw_cfg", false, false, in_qemu            },
+                { "qemu_fw_cfg",                "/sys/firmware/qemu_fw_cfg", false, false, in_qemu            },
 
                 /* dmi-sysfs is needed to import credentials from it super early */
-                { "dmi-sysfs",       "/sys/firmware/dmi/entries", false, false, NULL               },
+                { "dmi-sysfs",                  "/sys/firmware/dmi/entries", false, false, NULL               },
 
 #if HAVE_TPM2
                 /* Make sure the tpm subsystem is available which ConditionSecurity=tpm2 depends on. */
-                { "tpm",             "/sys/class/tpmrm",          false, false, efi_has_tpm2       },
+                { "tpm",                        "/sys/class/tpmrm",          false, false, efi_has_tpm2       },
 #endif
         };
         _cleanup_(kmod_unrefp) struct kmod_ctx *ctx = NULL;