[PATCH RFC v5 00/12] virtio-console: notify about the terminal size

Filip Hejsek posted 12 patches 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250921-console-resize-v5-0-89e3c6727060@gmail.com
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, "Gonglei (Arei)" <arei.gonglei@huawei.com>, Zhenwei Pi <pizhenwei@bytedance.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Raphael Norwitz <raphael@enfabrica.net>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Thomas Huth <thuth@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, "Collin L. Walling" <walling@linux.ibm.com>, Laurent Vivier <lvivier@redhat.com>, Amit Shah <amit@kernel.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Corey Minyard <minyard@acm.org>, Fam Zheng <fam@euphon.net>, Samuel Thibault <samuel.thibault@ens-lyon.org>, "Alex Bennée" <alex.bennee@linaro.org>, "Dr. David Alan Gilbert" <dave@treblig.org>, Markus Armbruster <armbru@redhat.com>, Jason Wang <jasowang@redhat.com>, Eric Blake <eblake@redhat.com>
backends/cryptodev-vhost-user.c   |  1 +
chardev/char-fe.c                 | 13 ++++++++
chardev/char-mux.c                | 18 ++++++++++-
chardev/char-stdio.c              | 30 +++++++++++++++++++
chardev/char-win-stdio.c          | 19 ++++++++++++
chardev/char.c                    | 26 ++++++++++++++++
hw/block/vhost-user-blk.c         |  1 +
hw/char/terminal3270.c            |  1 +
hw/char/trace-events              |  1 +
hw/char/virtio-console.c          | 63 ++++++++++++++++++++++++++++++++++++---
hw/char/virtio-serial-bus.c       | 51 +++++++++++++++++++++++++++++--
hw/core/machine.c                 |  4 ++-
hw/ipmi/ipmi_bmc_extern.c         |  1 +
hw/scsi/vhost-user-scsi.c         |  1 +
hw/usb/ccid-card-passthru.c       |  1 +
hw/usb/dev-serial.c               |  1 +
hw/usb/redirect.c                 |  1 +
hw/virtio/vhost-user-base.c       |  1 +
hw/virtio/vhost-user-scmi.c       |  1 +
include/chardev/char-fe.h         | 10 +++++++
include/chardev/char.h            |  7 +++++
include/hw/virtio/virtio-serial.h |  5 ++++
include/qemu/main-loop.h          |  4 +++
monitor/hmp.c                     |  1 +
monitor/qmp.c                     |  1 +
net/passt.c                       |  1 +
net/vhost-user.c                  |  1 +
qapi/char.json                    | 30 +++++++++++++++++++
ui/console-vc.c                   |  3 ++
ui/curses.c                       | 11 +++----
ui/gtk.c                          | 27 +++++++++++++++++
util/main-loop.c                  | 21 +++++++++++++
32 files changed, 344 insertions(+), 13 deletions(-)
[PATCH RFC v5 00/12] virtio-console: notify about the terminal size
Posted by Filip Hejsek 1 week ago
The goal of this series is to have a resizable terminal into a guest
without having to set up networking and using, e.g. ssh.

I tagged this version as an RFC as we still need to wait for a decision
on the swapped rows/cols issue by the virtio maintainers, so it cannot
be merged right away. I would still like to request a review especially
for the two (small) 'vc' chardev patches, which are new in this version.

The virtio spec allows a virtio-console device to notify the guest about
terminal resizes in the host. Linux Kernel implements the driver part of
the spec. This series implement the device part in QEMU.

Terminal size support is added for stdio and vc backends. It would make
sense to also add size support to the pty and serial backends, however
it's not possible to receive resize notifications for tty devices other
than a process' controlling terminal. For the serial backend, it might
still be useful to query the initial dimensions. (In a previous
discussion, only the pty backend was considered, where the initial
dimensions are useless.)

The 'vc' chardev changes are incomplete, because this chardev has
multiple implementations in QEMU. This series contains adds size support
to the generic and gtk/vte implementations. I think I also need to add
a spice implementation, please let me know if there is anything else.

I would also like some advice on how to test resizing the virtual
console. I tried resizing the window of the sdl backend, but that didn't
change the dimensions of the console (instead rescaling the console
image to fit the window).

This series also introduces resize messages that can be sent over QMP to
notify QEMU about the size of the terminal connented to some chardev.
In the libvirt setting, it will allow to implement a resizable terminal
for virsh console and other libvirt clients.

For a long time, the Linux implementation of virtio-console had rows and
columns swapped. This was fixed in Linux 6.15, but older versions will
interpret the dimensions incorrectly. There are two ways this might be
resolved:
 - It has been proposed to change the virtio spec to match historical
   Linux behavior. If the change is accepted, the fix would be reverted
   and we would end up with only two or three broken Linux versions.
 - Alternately, the Linux fix would be kept and backported to LTS
   versions.

In any case, users of broken Linux versions can disable the feature
using the console-size property.

Thanks to Markus, Daniel and Max for their feedback on v4,
and to Michael for helping with the swapped rows/cols issue.

v5:
- rename chardev-resize -> chardev-window-size-changed
- improve chardev-window-size-changed documentation
- add partial implementation for 'vc' chardev
- config space now returns port 0 size if multiport
- console-size property completely disables size support
- fix misnamed variables in char-win-stdio
- Link to v4: https://lore.kernel.org/qemu-devel/20250912-console-resize-v4-0-7925e444afc4@gmail.com

v4:
- changed order of rows and cols fields
- added support for terminal size on Windows
- trace event is also emitted for legacy (non-multiport) drivers
- minor fixes required because of changes in QEMU (DECLARE_INSTANCE_CHECKER, qmp-example)
- updated version numbers ('Since: 10.2', hw_compat_10_1)
- Link to v3: https://lore.kernel.org/qemu-devel/20200629164041.472528-1-noh4hss@gmail.com

v3:
- add resize messages over QMP, as suggested by Daniel

v2:
- fix adding a new virtio feature bit to the virtio console device

---
Filip Hejsek (3):
      char-win-stdio: add support for terminal size
      ui/console-vc: forward text console size to vc chardev
      ui/gtk: forward gtk console size to vc chardev

Szymon Lukasz (9):
      chardev: add cols, rows fields
      chardev: add CHR_EVENT_RESIZE
      chardev: add qemu_chr_resize()
      char-mux: add support for the terminal size
      main-loop: change the handling of SIGWINCH
      char-stdio: add support for the terminal size
      qmp: add chardev-window-size-changed command
      virtio-serial-bus: add terminal resize messages
      virtio-console: notify the guest about terminal resizes

 backends/cryptodev-vhost-user.c   |  1 +
 chardev/char-fe.c                 | 13 ++++++++
 chardev/char-mux.c                | 18 ++++++++++-
 chardev/char-stdio.c              | 30 +++++++++++++++++++
 chardev/char-win-stdio.c          | 19 ++++++++++++
 chardev/char.c                    | 26 ++++++++++++++++
 hw/block/vhost-user-blk.c         |  1 +
 hw/char/terminal3270.c            |  1 +
 hw/char/trace-events              |  1 +
 hw/char/virtio-console.c          | 63 ++++++++++++++++++++++++++++++++++++---
 hw/char/virtio-serial-bus.c       | 51 +++++++++++++++++++++++++++++--
 hw/core/machine.c                 |  4 ++-
 hw/ipmi/ipmi_bmc_extern.c         |  1 +
 hw/scsi/vhost-user-scsi.c         |  1 +
 hw/usb/ccid-card-passthru.c       |  1 +
 hw/usb/dev-serial.c               |  1 +
 hw/usb/redirect.c                 |  1 +
 hw/virtio/vhost-user-base.c       |  1 +
 hw/virtio/vhost-user-scmi.c       |  1 +
 include/chardev/char-fe.h         | 10 +++++++
 include/chardev/char.h            |  7 +++++
 include/hw/virtio/virtio-serial.h |  5 ++++
 include/qemu/main-loop.h          |  4 +++
 monitor/hmp.c                     |  1 +
 monitor/qmp.c                     |  1 +
 net/passt.c                       |  1 +
 net/vhost-user.c                  |  1 +
 qapi/char.json                    | 30 +++++++++++++++++++
 ui/console-vc.c                   |  3 ++
 ui/curses.c                       | 11 +++----
 ui/gtk.c                          | 27 +++++++++++++++++
 util/main-loop.c                  | 21 +++++++++++++
 32 files changed, 344 insertions(+), 13 deletions(-)
---
base-commit: 190d5d7fd725ff754f94e8e0cbfb69f279c82b5d
change-id: 20250912-console-resize-96c42140ba08

Best regards,
-- 
Filip Hejsek <filip.hejsek@gmail.com>