From 8c7ce2d48abfbf9fc08dccfb469fcc687c3cd68a Mon Sep 17 00:00:00 2001 From: Hayzam Sherif Date: Wed, 30 Sep 2026 14:16:38 +0000 Subject: [PATCH] bhyve: Defer virtio-console PORT_NAME until the guest is ready pci_vtcon_announce_port() sends VIRTIO_CONSOLE_PORT_NAME immediately after VIRTIO_CONSOLE_DEVICE_ADD, without waiting for the guest to initialize the port. The Windows virtio-serial driver ignores the name if the port is not yet available, which can prevent the QEMU guest agent from finding org.qemu.guest_agent.0. Send the name after the guest reports successful port initialization with VIRTIO_CONSOLE_PORT_READY, as QEMU does. While here, validate the guest-supplied port ID before forming a pointer into vsc_ports[]. This ports the PORT_NAME ordering fix from illumos change 18082. Obtained from: illumos 643ee887be44404b690eeaff14f20a27ad3c715c Reviewed by: markj MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D59847 --- usr.sbin/bhyve/pci_virtio_console.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/usr.sbin/bhyve/pci_virtio_console.c b/usr.sbin/bhyve/pci_virtio_console.c index 2950c2276942..0efaba317d2f 100644 --- a/usr.sbin/bhyve/pci_virtio_console.c +++ b/usr.sbin/bhyve/pci_virtio_console.c @@ -515,12 +515,25 @@ pci_vtcon_control_tx(struct pci_vtcon_port *port, void *arg __unused, break; case VTCON_PORT_READY: - tmp = &sc->vsc_ports[ctrl->id]; - if (ctrl->id >= VTCON_MAXPORTS || !tmp->vsp_enabled) { + if (ctrl->id >= VTCON_MAXPORTS) { WPRINTF(("VTCON_PORT_READY event for unknown port %d", ctrl->id)); return; } + tmp = &sc->vsc_ports[ctrl->id]; + if (!tmp->vsp_enabled) { + WPRINTF(("VTCON_PORT_READY event for unknown port %d", + ctrl->id)); + return; + } + + if (ctrl->value == 1) { + resp.id = ctrl->id; + resp.event = VTCON_PORT_NAME; + resp.value = 1; + pci_vtcon_control_send(sc, &resp, tmp->vsp_name, + strlen(tmp->vsp_name)); + } if (tmp->vsp_console) { resp.event = VTCON_CONSOLE_PORT; @@ -541,10 +554,6 @@ pci_vtcon_announce_port(struct pci_vtcon_port *port) event.event = VTCON_DEVICE_ADD; event.value = 1; pci_vtcon_control_send(port->vsp_sc, &event, NULL, 0); - - event.event = VTCON_PORT_NAME; - pci_vtcon_control_send(port->vsp_sc, &event, port->vsp_name, - strlen(port->vsp_name)); } static void