From 470c213bd9676f247948997d330e5febdb8034a2 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 3 Jan 2025 11:14:44 +0100 Subject: [PATCH] vmspawn: Switch to virtconsole for headless console virtconsole is the modern way to set up a headless serial connection to a virtual machine so let's make use of it instead of -serial. This also allows us to get rid of the per architecture serial console device names and makes vmspawn more consistent with mkosi qemu which already uses virtconsole. --- src/vmspawn/vmspawn-util.h | 10 ---------- src/vmspawn/vmspawn.c | 8 +++++--- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/vmspawn/vmspawn-util.h b/src/vmspawn/vmspawn-util.h index 76969abcf11..66c1397ceb5 100644 --- a/src/vmspawn/vmspawn-util.h +++ b/src/vmspawn/vmspawn-util.h @@ -22,16 +22,6 @@ # define ARCHITECTURE_SUPPORTS_SMM 0 #endif -#if defined(__arm__) || defined(__aarch64__) -# define DEFAULT_SERIAL_TTY "ttyAMA0" -#elif defined(__s390__) || defined(__s390x__) -# define DEFAULT_SERIAL_TTY "ttysclp0" -#elif defined(__powerpc__) || defined(__powerpc64__) -# define DEFAULT_SERIAL_TTY "hvc0" -#else -# define DEFAULT_SERIAL_TTY "ttyS0" -#endif - #if defined(__x86_64__) || defined(__i386__) # define QEMU_MACHINE_TYPE "q35" #elif defined(__arm__) || defined(__aarch64__) || defined(__riscv) || defined(__loongarch64) diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index 47c9093741f..00e040d9631 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -1643,6 +1643,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) { &cmdline, "-nographic", "-nodefaults", + "-device", "virtio-serial-pci,id=vmspawn-virtio-serial-pci", "-chardev") < 0) return log_oom(); @@ -1652,7 +1653,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) { r = strv_extend_many( &cmdline, - "-serial", "chardev:console"); + "-device", "virtconsole,chardev=console"); break; } @@ -1669,7 +1670,8 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) { "-nographic", "-nodefaults", "-chardev", "stdio,mux=on,id=console,signal=off", - "-serial", "chardev:console", + "-device", "virtio-serial-pci,id=vmspawn-virtio-serial-pci", + "-device", "virtconsole,chardev=console", "-mon", "console"); break; @@ -1821,7 +1823,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) { return log_oom(); } - r = strv_prepend(&arg_kernel_cmdline_extra, "console=" DEFAULT_SERIAL_TTY); + r = strv_prepend(&arg_kernel_cmdline_extra, "console=hvc0"); if (r < 0) return log_oom(); -- 2.47.3