[PATCH v4 00/10] virtio-console: notify about the terminal size

Filip Hejsek posted 10 patches 2 weeks, 2 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250912-console-resize-v4-0-7925e444afc4@gmail.com
Maintainers: "Gonglei (Arei)" <arei.gonglei@huawei.com>, Zhenwei Pi <pizhenwei@bytedance.com>, "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.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>
There is a newer version of this series
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       | 43 ++++++++++++++++++++++++--
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                    | 22 ++++++++++++++
ui/curses.c                       | 11 +++----
util/main-loop.c                  | 21 +++++++++++++
30 files changed, 298 insertions(+), 13 deletions(-)
[PATCH v4 00/10] virtio-console: notify about the terminal size
Posted by Filip Hejsek 2 weeks, 2 days 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.

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.

This series adds support for a resizable terminal if a virtio console
device is connected to the stdio backend.

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.

This patch series was originally authored by Szymon Lukasz and submitted
to qemu-devel about 5 years ago. The previous submission can be found at
<https://lists.nongnu.org/archive/html/qemu-devel/2020-06/msg09591.html>.
I have updated the patches to be compatible with latest master and made
a few small changes of my own, including the addition of Windows support.

Probably the most important change I made is the swapping of rows and
cols fields in resize messages. I would like to hear some feedback on
this change from reviewers. The problem is that for a long time, the
Linux kernel used a different field order from what was specified in the
virtio spec. The kernel implementation was apparently merged around 2010,
while the virtio spec came in 2014, so when a previous version of this
patch series was being discussed here on this mailing list in 2020, it
was decided that QEMU should match the Linux implementation, and ideally,
the virtio spec should be changed.

However, recently, the Linux kernel implementation was changed to conform
to the spec: <https://git.kernel.org/linus/5326ab737a47278dbd16ed3ee7380b26c7056ddd>.
As a result, to be compatible with latest kernel releases, QEMU needs to
also use the field order matching the specification. I have changed the
patch to use the spec-compliant order, so it works correctly with latest
kernels now.

That leaves the issue of older kernels. There are about 15 years' worth
of kernel versions with the swapped field order, including the kernel
currently shipped in Debian stable. The effects of the swapped dimensions
can sometimes be quite annoying - e.g. if you have a terminal with
24 rows, this will be interpreted as 24 columns, and your shell may limit 
line editing to this small space, most of which will be taken by your
prompt. The patch series in its current form provides no way to disable
the console size functionality, so users may end up worse off than if
the functionality were not implemented at all.

PS: One of the patches adds one additional noop switch case
    to a bunch of files. I didn't include the maintainers of these files
    in the Cc list. I hope that's OK. :)

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)

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 (1):
      char-win-stdio: add support for terminal size

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-resize 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       | 43 ++++++++++++++++++++++++--
 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                    | 22 ++++++++++++++
 ui/curses.c                       | 11 +++----
 util/main-loop.c                  | 21 +++++++++++++
 30 files changed, 298 insertions(+), 13 deletions(-)
---
base-commit: 190d5d7fd725ff754f94e8e0cbfb69f279c82b5d
change-id: 20250912-console-resize-96c42140ba08

Best regards,
-- 
Filip Hejsek <filip.hejsek@gmail.com>
Re: [PATCH v4 00/10] virtio-console: notify about the terminal size
Posted by Filip Hejsek 1 week, 5 days ago
While thinking about the patches, a few questions about the virtio spec
have popped into my head.

1. Should the config space size also be updated (for port 0) when
multiport is used? Based on my reading of the spec, I think yes.

2. Can VIRTIO_CONSOLE_RESIZE be sent if VIRTIO_CONSOLE_F_SIZE is not
negotiated? The spec does not say, which I think means it can.

3. The spec says that reading from config space fields that are
conditional on features should be allowed even if the driver has not
(yet) accepted the feature. Does it mean that we have to update the
size even if the feature is not accepted (yet), or is it OK if the
reads return 0?

Thanks for any answers or opinions,
Filip Hejsek
Re: [PATCH v4 00/10] virtio-console: notify about the terminal size
Posted by Michael S. Tsirkin 1 week, 5 days ago
On Tue, Sep 16, 2025 at 01:02:02AM +0200, Filip Hejsek wrote:
> While thinking about the patches, a few questions about the virtio spec
> have popped into my head.
> 
> 1. Should the config space size also be updated (for port 0) when
> multiport is used? Based on my reading of the spec, I think yes.
> 
> 2. Can VIRTIO_CONSOLE_RESIZE be sent if VIRTIO_CONSOLE_F_SIZE is not
> negotiated? The spec does not say, which I think means it can.

But the guest can't do anything useful here.

> 3. The spec says that reading from config space fields that are
> conditional on features should be allowed even if the driver has not
> (yet) accepted the feature. Does it mean that we have to update the
> size even if the feature is not accepted (yet), or is it OK if the
> reads return 0?

This is talking about the window before FEATURES_OK (and so DRIVER_OK)
is set.  It is best to update the size. There's no interrupt to send
though.


> Thanks for any answers or opinions,
> Filip Hejsek
Re: [PATCH v4 00/10] virtio-console: notify about the terminal size
Posted by Michael S. Tsirkin 2 weeks, 2 days ago
On Fri, Sep 12, 2025 at 05:39:45AM +0200, Filip Hejsek wrote:
> 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.
> 
> 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.
> 
> This series adds support for a resizable terminal if a virtio console
> device is connected to the stdio backend.
> 
> 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.
> 
> This patch series was originally authored by Szymon Lukasz and submitted
> to qemu-devel about 5 years ago. The previous submission can be found at
> <https://lists.nongnu.org/archive/html/qemu-devel/2020-06/msg09591.html>.
> I have updated the patches to be compatible with latest master and made
> a few small changes of my own, including the addition of Windows support.
> 
> Probably the most important change I made is the swapping of rows and
> cols fields in resize messages. I would like to hear some feedback on
> this change from reviewers. The problem is that for a long time, the
> Linux kernel used a different field order from what was specified in the
> virtio spec. The kernel implementation was apparently merged around 2010,
> while the virtio spec came in 2014, so when a previous version of this
> patch series was being discussed here on this mailing list in 2020, it
> was decided that QEMU should match the Linux implementation, and ideally,
> the virtio spec should be changed.
> 
> However, recently, the Linux kernel implementation was changed to conform
> to the spec: <https://git.kernel.org/linus/5326ab737a47278dbd16ed3ee7380b26c7056ddd>.
> As a result, to be compatible with latest kernel releases, QEMU needs to
> also use the field order matching the specification. I have changed the
> patch to use the spec-compliant order, so it works correctly with latest
> kernels now.
>

Well this is not in any release yet. If you want me to revert that
one, let me know ASAP. Maximilian?

> That leaves the issue of older kernels. There are about 15 years' worth
> of kernel versions with the swapped field order, including the kernel
> currently shipped in Debian stable. The effects of the swapped dimensions
> can sometimes be quite annoying - e.g. if you have a terminal with
> 24 rows, this will be interpreted as 24 columns, and your shell may limit 
> line editing to this small space, most of which will be taken by your
> prompt. The patch series in its current form provides no way to disable
> the console size functionality,

Well I see the console-size property, no?

> so users may end up worse off than if
> the functionality were not implemented at all.

If we want to keep the Linux patch, the straight forward way is to send
the fix to stable@ then poke at Debian at al to fix their kernels.

Another option is to make the property default to off, have
management turn it on when guest is up to date.

But it really sounds like we should revert that Linux patch.
I posted a revert, pls comment.

> PS: One of the patches adds one additional noop switch case
>     to a bunch of files. I didn't include the maintainers of these files
>     in the Cc list. I hope that's OK. :)
> 
> 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)
> 
> 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 (1):
>       char-win-stdio: add support for terminal size
> 
> 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-resize 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       | 43 ++++++++++++++++++++++++--
>  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                    | 22 ++++++++++++++
>  ui/curses.c                       | 11 +++----
>  util/main-loop.c                  | 21 +++++++++++++
>  30 files changed, 298 insertions(+), 13 deletions(-)
> ---
> base-commit: 190d5d7fd725ff754f94e8e0cbfb69f279c82b5d
> change-id: 20250912-console-resize-96c42140ba08
> 
> Best regards,
> -- 
> Filip Hejsek <filip.hejsek@gmail.com>
Re: [PATCH v4 00/10] virtio-console: notify about the terminal size
Posted by Daniel P. Berrangé 2 weeks, 2 days ago
On Fri, Sep 12, 2025 at 04:41:02AM -0400, Michael S. Tsirkin wrote:
> On Fri, Sep 12, 2025 at 05:39:45AM +0200, Filip Hejsek wrote:
> > 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.
> > 
> > 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.
> > 
> > This series adds support for a resizable terminal if a virtio console
> > device is connected to the stdio backend.
> > 
> > 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.
> > 
> > This patch series was originally authored by Szymon Lukasz and submitted
> > to qemu-devel about 5 years ago. The previous submission can be found at
> > <https://lists.nongnu.org/archive/html/qemu-devel/2020-06/msg09591.html>.
> > I have updated the patches to be compatible with latest master and made
> > a few small changes of my own, including the addition of Windows support.
> > 
> > Probably the most important change I made is the swapping of rows and
> > cols fields in resize messages. I would like to hear some feedback on
> > this change from reviewers. The problem is that for a long time, the
> > Linux kernel used a different field order from what was specified in the
> > virtio spec. The kernel implementation was apparently merged around 2010,
> > while the virtio spec came in 2014, so when a previous version of this
> > patch series was being discussed here on this mailing list in 2020, it
> > was decided that QEMU should match the Linux implementation, and ideally,
> > the virtio spec should be changed.
> > 
> > However, recently, the Linux kernel implementation was changed to conform
> > to the spec: <https://git.kernel.org/linus/5326ab737a47278dbd16ed3ee7380b26c7056ddd>.
> > As a result, to be compatible with latest kernel releases, QEMU needs to
> > also use the field order matching the specification. I have changed the
> > patch to use the spec-compliant order, so it works correctly with latest
> > kernels now.
> >
> 
> Well this is not in any release yet. If you want me to revert that
> one, let me know ASAP. Maximilian?
> 
> > That leaves the issue of older kernels. There are about 15 years' worth
> > of kernel versions with the swapped field order, including the kernel
> > currently shipped in Debian stable. The effects of the swapped dimensions
> > can sometimes be quite annoying - e.g. if you have a terminal with
> > 24 rows, this will be interpreted as 24 columns, and your shell may limit 
> > line editing to this small space, most of which will be taken by your
> > prompt. The patch series in its current form provides no way to disable
> > the console size functionality,
> 
> Well I see the console-size property, no?

At least in the case of libvirt managed VMs, this series does
nothin by default, as they won't be using the 'stdio' chardev,
they'll require libvirt to first wire up the new QMP command,
and then apps using libvirt to call it. So in that sense, it'll
take a while before the effects are seen by users.

> > so users may end up worse off than if
> > the functionality were not implemented at all.
> 
> If we want to keep the Linux patch, the straight forward way is to send
> the fix to stable@ then poke at Debian at al to fix their kernels.
> 
> Another option is to make the property default to off, have
> management turn it on when guest is up to date.
> 
> But it really sounds like we should revert that Linux patch.
> I posted a revert, pls comment.

What about other non-Linux guest OS that may have correctly
implemented the virtio spec ?

At least FreeBSD appears to /not/ implemenmt resize at all:

  https://github.com/freebsd/freebsd-src/blob/main/sys/dev/virtio/console/virtio_console.c#L884

Do we have a Windows impl of virtio-console with resize support ?

Any other places we should check ?

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Re: [PATCH v4 00/10] virtio-console: notify about the terminal size
Posted by Maximilian Immanuel Brandtner 1 week, 6 days ago
On Fri, 2025-09-12 at 09:50 +0100, Daniel P. Berrangé wrote:
> On Fri, Sep 12, 2025 at 04:41:02AM -0400, Michael S. Tsirkin wrote:
> > On Fri, Sep 12, 2025 at 05:39:45AM +0200, Filip Hejsek wrote:
> > > 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.
> > > 
> > > 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.
> > > 
> > > This series adds support for a resizable terminal if a virtio
> > > console
> > > device is connected to the stdio backend.
> > > 
> > > 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.
> > > 
> > > This patch series was originally authored by Szymon Lukasz and
> > > submitted
> > > to qemu-devel about 5 years ago. The previous submission can be
> > > found at
> > > <
> > > https://lists.nongnu.org/archive/html/qemu-devel/2020-06/msg09591.
> > > html>.
> > > I have updated the patches to be compatible with latest master
> > > and made
> > > a few small changes of my own, including the addition of Windows
> > > support.
> > > 
> > > Probably the most important change I made is the swapping of rows
> > > and
> > > cols fields in resize messages. I would like to hear some
> > > feedback on
> > > this change from reviewers. The problem is that for a long time,
> > > the
> > > Linux kernel used a different field order from what was specified
> > > in the
> > > virtio spec. The kernel implementation was apparently merged
> > > around 2010,
> > > while the virtio spec came in 2014, so when a previous version of
> > > this
> > > patch series was being discussed here on this mailing list in
> > > 2020, it
> > > was decided that QEMU should match the Linux implementation, and
> > > ideally,
> > > the virtio spec should be changed.
> > > 
> > > However, recently, the Linux kernel implementation was changed to
> > > conform
> > > to the spec:
> > > <https://git.kernel.org/linus/5326ab737a47278dbd16ed3ee7380b26c70
> > > 56ddd>.
> > > As a result, to be compatible with latest kernel releases, QEMU
> > > needs to
> > > also use the field order matching the specification. I have
> > > changed the
> > > patch to use the spec-compliant order, so it works correctly with
> > > latest
> > > kernels now.
> > > 
> > 
> > Well this is not in any release yet. If you want me to revert that
> > one, let me know ASAP. Maximilian?
> > 
> > > That leaves the issue of older kernels. There are about 15 years'
> > > worth
> > > of kernel versions with the swapped field order, including the
> > > kernel
> > > currently shipped in Debian stable. The effects of the swapped
> > > dimensions
> > > can sometimes be quite annoying - e.g. if you have a terminal
> > > with
> > > 24 rows, this will be interpreted as 24 columns, and your shell
> > > may limit 
> > > line editing to this small space, most of which will be taken by
> > > your
> > > prompt. The patch series in its current form provides no way to
> > > disable
> > > the console size functionality,
> > 
> > Well I see the console-size property, no?
> 
> At least in the case of libvirt managed VMs, this series does
> nothin by default, as they won't be using the 'stdio' chardev,
> they'll require libvirt to first wire up the new QMP command,
> and then apps using libvirt to call it. So in that sense, it'll
> take a while before the effects are seen by users.

Correct me if I'm wrong on this, but shouldn't the 'pty' chardev also
be able to take advantage of the same size change mechanisms as the
'stdio' chardev (receiving SIGWINCH and being able to use the ioctl
TIOCGWINSZ)? If so the work for the 'stdio' chardev should probably be
replicated for the 'pty' chardev. 

> 
> > > so users may end up worse off than if
> > > the functionality were not implemented at all.
> > 
> > If we want to keep the Linux patch, the straight forward way is to
> > send
> > the fix to stable@ then poke at Debian at al to fix their kernels.
> > 
> > Another option is to make the property default to off, have
> > management turn it on when guest is up to date.
> > 
> > But it really sounds like we should revert that Linux patch.
> > I posted a revert, pls comment.
> 
> What about other non-Linux guest OS that may have correctly
> implemented the virtio spec ?
> 
> At least FreeBSD appears to /not/ implemenmt resize at all:
> 
>  
> https://github.com/freebsd/freebsd-src/blob/main/sys/dev/virtio/console/virtio_console.c#L884
> 
> Do we have a Windows impl of virtio-console with resize support ?
> 
> Any other places we should check ?
> 
> With regards,
> Daniel
Re: [PATCH v4 00/10] virtio-console: notify about the terminal size
Posted by Daniel P. Berrangé 1 week, 6 days ago
On Mon, Sep 15, 2025 at 10:41:44AM +0200, Maximilian Immanuel Brandtner wrote:
> On Fri, 2025-09-12 at 09:50 +0100, Daniel P. Berrangé wrote:
> > On Fri, Sep 12, 2025 at 04:41:02AM -0400, Michael S. Tsirkin wrote:
> > > On Fri, Sep 12, 2025 at 05:39:45AM +0200, Filip Hejsek wrote:
> > > > 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.
> > > > 
> > > > 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.
> > > > 
> > > > This series adds support for a resizable terminal if a virtio
> > > > console
> > > > device is connected to the stdio backend.
> > > > 
> > > > 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.
> > > > 
> > > > This patch series was originally authored by Szymon Lukasz and
> > > > submitted
> > > > to qemu-devel about 5 years ago. The previous submission can be
> > > > found at
> > > > <
> > > > https://lists.nongnu.org/archive/html/qemu-devel/2020-06/msg09591.
> > > > html>.
> > > > I have updated the patches to be compatible with latest master
> > > > and made
> > > > a few small changes of my own, including the addition of Windows
> > > > support.
> > > > 
> > > > Probably the most important change I made is the swapping of rows
> > > > and
> > > > cols fields in resize messages. I would like to hear some
> > > > feedback on
> > > > this change from reviewers. The problem is that for a long time,
> > > > the
> > > > Linux kernel used a different field order from what was specified
> > > > in the
> > > > virtio spec. The kernel implementation was apparently merged
> > > > around 2010,
> > > > while the virtio spec came in 2014, so when a previous version of
> > > > this
> > > > patch series was being discussed here on this mailing list in
> > > > 2020, it
> > > > was decided that QEMU should match the Linux implementation, and
> > > > ideally,
> > > > the virtio spec should be changed.
> > > > 
> > > > However, recently, the Linux kernel implementation was changed to
> > > > conform
> > > > to the spec:
> > > > <https://git.kernel.org/linus/5326ab737a47278dbd16ed3ee7380b26c70
> > > > 56ddd>.
> > > > As a result, to be compatible with latest kernel releases, QEMU
> > > > needs to
> > > > also use the field order matching the specification. I have
> > > > changed the
> > > > patch to use the spec-compliant order, so it works correctly with
> > > > latest
> > > > kernels now.
> > > > 
> > > 
> > > Well this is not in any release yet. If you want me to revert that
> > > one, let me know ASAP. Maximilian?
> > > 
> > > > That leaves the issue of older kernels. There are about 15 years'
> > > > worth
> > > > of kernel versions with the swapped field order, including the
> > > > kernel
> > > > currently shipped in Debian stable. The effects of the swapped
> > > > dimensions
> > > > can sometimes be quite annoying - e.g. if you have a terminal
> > > > with
> > > > 24 rows, this will be interpreted as 24 columns, and your shell
> > > > may limit 
> > > > line editing to this small space, most of which will be taken by
> > > > your
> > > > prompt. The patch series in its current form provides no way to
> > > > disable
> > > > the console size functionality,
> > > 
> > > Well I see the console-size property, no?
> > 
> > At least in the case of libvirt managed VMs, this series does
> > nothin by default, as they won't be using the 'stdio' chardev,
> > they'll require libvirt to first wire up the new QMP command,
> > and then apps using libvirt to call it. So in that sense, it'll
> > take a while before the effects are seen by users.
> 
> Correct me if I'm wrong on this, but shouldn't the 'pty' chardev also
> be able to take advantage of the same size change mechanisms as the
> 'stdio' chardev (receiving SIGWINCH and being able to use the ioctl
> TIOCGWINSZ)? If so the work for the 'stdio' chardev should probably be
> replicated for the 'pty' chardev.

Yes, if using a suitable client app, it ought to work for
'pty' I think.


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


[PATCH] char-pty: add support for the terminal size
Posted by Maximilian Immanuel Brandtner 1 week, 6 days ago
Update the terminal size upon SIGWINCH delivery.

To be committed with the patch-set: [PATCH v4 00/10] virtio-console: notify about the terminal size

Signed-off-by: Maximilian Immanuel Brandtner <maxbr@linux.ibm.com>
---
 chardev/char-pty.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/chardev/char-pty.c b/chardev/char-pty.c
index 674e9b3f14..802bae9037 100644
--- a/chardev/char-pty.c
+++ b/chardev/char-pty.c
@@ -28,6 +28,7 @@
 #include "io/channel-file.h"
 #include "qemu/sockets.h"
 #include "qemu/error-report.h"
+#include "qemu/main-loop.h"
 #include "qemu/module.h"
 #include "qemu/option.h"
 #include "qemu/qemu-print.h"
@@ -35,6 +36,8 @@
 #include "chardev/char-io.h"
 #include "qom/object.h"
 
+#include <sys/ioctl.h>
+
 struct PtyChardev {
     Chardev parent;
     QIOChannel *ioc;
@@ -43,6 +46,8 @@ struct PtyChardev {
     int connected;
     GSource *timer_src;
     char *path;
+
+    Notifier resize_notifier;
 };
 typedef struct PtyChardev PtyChardev;
 
@@ -85,6 +90,15 @@ static void pty_chr_rearm_timer(Chardev *chr, int ms)
     g_free(name);
 }
 
+static void pty_chr_resize(PtyChardev *s)
+{
+    struct winsize ws;
+
+    if (ioctl(QIO_CHANNEL_FILE(s->ioc)->fd, TIOCGWINSZ, &ws) != -1) {
+        qemu_chr_resize(CHARDEV(s), ws.ws_col, ws.ws_row);
+    }
+}
+
 static void pty_chr_update_read_handler(Chardev *chr)
 {
     PtyChardev *s = PTY_CHARDEV(chr);
@@ -331,6 +345,12 @@ static int qemu_openpty_raw(int *aslave, char *pty_name)
     return amaster;
 }
 
+static void term_resize_notify(Notifier *n, void *data)
+{
+    PtyChardev *s = container_of(n, PtyChardev, resize_notifier);
+    pty_chr_resize(s);
+}
+
 static void char_pty_open(Chardev *chr,
                           ChardevBackend *backend,
                           bool *be_opened,
@@ -376,6 +396,10 @@ static void char_pty_open(Chardev *chr,
             s->path = g_strdup(path);
         }
     }
+
+    pty_chr_resize(s);
+    s->resize_notifier.notify = term_resize_notify;
+    sigwinch_add_notifier(&s->resize_notifier);
 }
 
 static void char_pty_parse(QemuOpts *opts, ChardevBackend *backend,
-- 
2.50.1
[PATCH v2] char-pty: add support for the terminal size
Posted by Maximilian Immanuel Brandtner 1 week, 5 days ago
Update the terminal size upon SIGWINCH delivery.

Signed-off-by: Maximilian Immanuel Brandtner <maxbr@linux.ibm.com>
---

To be committed with the patch-set: [PATCH v4 00/10] virtio-console: notify about the terminal size

v1 -> v2: Move comment regarding patch dependencies to note section
---
 chardev/char-pty.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/chardev/char-pty.c b/chardev/char-pty.c
index 674e9b3f14..802bae9037 100644
--- a/chardev/char-pty.c
+++ b/chardev/char-pty.c
@@ -28,6 +28,7 @@
 #include "io/channel-file.h"
 #include "qemu/sockets.h"
 #include "qemu/error-report.h"
+#include "qemu/main-loop.h"
 #include "qemu/module.h"
 #include "qemu/option.h"
 #include "qemu/qemu-print.h"
@@ -35,6 +36,8 @@
 #include "chardev/char-io.h"
 #include "qom/object.h"
 
+#include <sys/ioctl.h>
+
 struct PtyChardev {
     Chardev parent;
     QIOChannel *ioc;
@@ -43,6 +46,8 @@ struct PtyChardev {
     int connected;
     GSource *timer_src;
     char *path;
+
+    Notifier resize_notifier;
 };
 typedef struct PtyChardev PtyChardev;
 
@@ -85,6 +90,15 @@ static void pty_chr_rearm_timer(Chardev *chr, int ms)
     g_free(name);
 }
 
+static void pty_chr_resize(PtyChardev *s)
+{
+    struct winsize ws;
+
+    if (ioctl(QIO_CHANNEL_FILE(s->ioc)->fd, TIOCGWINSZ, &ws) != -1) {
+        qemu_chr_resize(CHARDEV(s), ws.ws_col, ws.ws_row);
+    }
+}
+
 static void pty_chr_update_read_handler(Chardev *chr)
 {
     PtyChardev *s = PTY_CHARDEV(chr);
@@ -331,6 +345,12 @@ static int qemu_openpty_raw(int *aslave, char *pty_name)
     return amaster;
 }
 
+static void term_resize_notify(Notifier *n, void *data)
+{
+    PtyChardev *s = container_of(n, PtyChardev, resize_notifier);
+    pty_chr_resize(s);
+}
+
 static void char_pty_open(Chardev *chr,
                           ChardevBackend *backend,
                           bool *be_opened,
@@ -376,6 +396,10 @@ static void char_pty_open(Chardev *chr,
             s->path = g_strdup(path);
         }
     }
+
+    pty_chr_resize(s);
+    s->resize_notifier.notify = term_resize_notify;
+    sigwinch_add_notifier(&s->resize_notifier);
 }
 
 static void char_pty_parse(QemuOpts *opts, ChardevBackend *backend,
-- 
2.50.1
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Filip Hejsek 1 week, 5 days ago
On Mon, 2025-09-15 at 18:34 +0200, Maximilian Immanuel Brandtner wrote:
> Update the terminal size upon SIGWINCH delivery.
> 
> Signed-off-by: Maximilian Immanuel Brandtner <maxbr@linux.ibm.com>

I don't think this will work, because SIGWINCH is only delivered for
the process' controling terminal. Unfortunately I don't think there is
any way to get size notifications for arbitrary terminal.
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Maximilian Immanuel Brandtner 1 week, 4 days ago
On Tue, 2025-09-16 at 00:02 +0200, Filip Hejsek wrote:
> On Mon, 2025-09-15 at 18:34 +0200, Maximilian Immanuel Brandtner
> wrote:
> > Update the terminal size upon SIGWINCH delivery.
> > 
> > Signed-off-by: Maximilian Immanuel Brandtner <maxbr@linux.ibm.com>
> 
> I don't think this will work, because SIGWINCH is only delivered for
> the process' controling terminal. Unfortunately I don't think there
> is
> any way to get size notifications for arbitrary terminal.

In that case there are two solutions:
1. make qemu the controlling process of the pty (this has the
disadvantage of QEMU being quit when the pty is closed)
2. create a timer polling every eg 100ms to check if the winsize has
changed

I would go with the second approach then and implement the timer as a
g_source. Or are there other timer mechanisms I should use instead?
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Filip Hejsek 1 week, 4 days ago

On September 17, 2025 11:39:55 AM GMT+02:00, Maximilian Immanuel Brandtner <maxbr@linux.ibm.com> wrote:
> On Tue, 2025-09-16 at 00:02 +0200, Filip Hejsek wrote:
> > On Mon, 2025-09-15 at 18:34 +0200, Maximilian Immanuel Brandtner
> > wrote:
> > > Update the terminal size upon SIGWINCH delivery.
> > > 
> > > Signed-off-by: Maximilian Immanuel Brandtner <maxbr@linux.ibm.com>
> > 
> > I don't think this will work, because SIGWINCH is only delivered for
> > the process' controling terminal. Unfortunately I don't think there
> > is
> > any way to get size notifications for arbitrary terminal.
> 
> In that case there are two solutions:
> 1. make qemu the controlling process of the pty (this has the
> disadvantage of QEMU being quit when the pty is closed)

A bigger disadvantage is that a process can only have one controlling terminal, and a terminal can only be the controlling terminal for a single session (and only sends signals to the foreground process group of that session). It would require forking a process for each pty, and I don't even know if the master end can have its own session.

> 2. create a timer polling every eg 100ms to check if the winsize has
> changed
> 
> I would go with the second approach then

Me too, the timer is a bit unfortunate, but it's probably the less bad option.
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Daniel P. Berrangé 1 week, 4 days ago
On Wed, Sep 17, 2025 at 03:09:50PM +0200, Filip Hejsek wrote:
> 
> 
> On September 17, 2025 11:39:55 AM GMT+02:00, Maximilian Immanuel Brandtner <maxbr@linux.ibm.com> wrote:
> > On Tue, 2025-09-16 at 00:02 +0200, Filip Hejsek wrote:
> > > On Mon, 2025-09-15 at 18:34 +0200, Maximilian Immanuel Brandtner
> > > wrote:
> > > > Update the terminal size upon SIGWINCH delivery.
> > > > 
> > > > Signed-off-by: Maximilian Immanuel Brandtner <maxbr@linux.ibm.com>
> > > 
> > > I don't think this will work, because SIGWINCH is only delivered for
> > > the process' controling terminal. Unfortunately I don't think there
> > > is
> > > any way to get size notifications for arbitrary terminal.
> > 
> > In that case there are two solutions:
> > 1. make qemu the controlling process of the pty (this has the
> > disadvantage of QEMU being quit when the pty is closed)
> 
> A bigger disadvantage is that a process can only have one controlling terminal, and a terminal can only be the controlling terminal for a single session (and only sends signals to the foreground process group of that session). It would require forking a process for each pty, and I don't even know if the master end can have its own session.
> 
> > 2. create a timer polling every eg 100ms to check if the winsize has
> > changed
> > 
> > I would go with the second approach then
> 
> Me too, the timer is a bit unfortunate, but it's probably the less bad option.

I don't think we want a timer polling for an situation that will very
rarely arise.  We already add the 'chardev_resize' QMP command, which is
a good enough way to kick QEMU to re-read the size.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Maximilian Immanuel Brandtner 1 week, 3 days ago
On Wed, 2025-09-17 at 14:31 +0100, Daniel P. Berrangé wrote:
> On Wed, Sep 17, 2025 at 03:09:50PM +0200, Filip Hejsek wrote:
> > 
> > 
> > On September 17, 2025 11:39:55 AM GMT+02:00, Maximilian Immanuel
> > Brandtner <maxbr@linux.ibm.com> wrote:
> > > On Tue, 2025-09-16 at 00:02 +0200, Filip Hejsek wrote:
> > > > On Mon, 2025-09-15 at 18:34 +0200, Maximilian Immanuel
> > > > Brandtner
> > > > wrote:
> > > > > Update the terminal size upon SIGWINCH delivery.
> > > > > 
> > > > > Signed-off-by: Maximilian Immanuel Brandtner
> > > > > <maxbr@linux.ibm.com>
> > > > 
> > > > I don't think this will work, because SIGWINCH is only
> > > > delivered for
> > > > the process' controling terminal. Unfortunately I don't think
> > > > there
> > > > is
> > > > any way to get size notifications for arbitrary terminal.
> > > 
> > > In that case there are two solutions:
> > > 1. make qemu the controlling process of the pty (this has the
> > > disadvantage of QEMU being quit when the pty is closed)
> > 
> > A bigger disadvantage is that a process can only have one
> > controlling terminal, and a terminal can only be the controlling
> > terminal for a single session (and only sends signals to the
> > foreground process group of that session). It would require forking
> > a process for each pty, and I don't even know if the master end can
> > have its own session.
> > 
> > > 2. create a timer polling every eg 100ms to check if the winsize
> > > has
> > > changed
> > > 
> > > I would go with the second approach then
> > 
> > Me too, the timer is a bit unfortunate, but it's probably the less
> > bad option.
> 
> I don't think we want a timer polling for an situation that will very
> rarely arise.  We already add the 'chardev_resize' QMP command, which
> is
> a good enough way to kick QEMU to re-read the size.
> 
> With regards,
> Daniel

This approach would only work with libvirt and not generic pty
applications though. Perhaps a bool poll_resize could be added to the
struct Chardev which is disabled, as soon as the chardev_resize QMP
command is used to avoid race conditions.
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Filip Hejsek 1 week, 3 days ago
On September 18, 2025 9:53:27 AM GMT+02:00, Maximilian Immanuel Brandtner <maxbr@linux.ibm.com> wrote:
> On Wed, 2025-09-17 at 14:31 +0100, Daniel P. Berrangé wrote:
> > On Wed, Sep 17, 2025 at 03:09:50PM +0200, Filip Hejsek wrote:
> > > 
> > > 
> > > On September 17, 2025 11:39:55 AM GMT+02:00, Maximilian Immanuel
> > > Brandtner <maxbr@linux.ibm.com> wrote:
> > > > On Tue, 2025-09-16 at 00:02 +0200, Filip Hejsek wrote:
> > > > > On Mon, 2025-09-15 at 18:34 +0200, Maximilian Immanuel
> > > > > Brandtner
> > > > > wrote:
> > > > > > Update the terminal size upon SIGWINCH delivery.
> > > > > > 
> > > > > > Signed-off-by: Maximilian Immanuel Brandtner
> > > > > > <maxbr@linux.ibm.com>
> > > > > 
> > > > > I don't think this will work, because SIGWINCH is only
> > > > > delivered for
> > > > > the process' controling terminal. Unfortunately I don't think
> > > > > there
> > > > > is
> > > > > any way to get size notifications for arbitrary terminal.
> > > > 
> > > > In that case there are two solutions:
> > > > 1. make qemu the controlling process of the pty (this has the
> > > > disadvantage of QEMU being quit when the pty is closed)
> > > 
> > > A bigger disadvantage is that a process can only have one
> > > controlling terminal, and a terminal can only be the controlling
> > > terminal for a single session (and only sends signals to the
> > > foreground process group of that session). It would require forking
> > > a process for each pty, and I don't even know if the master end can
> > > have its own session.
> > > 
> > > > 2. create a timer polling every eg 100ms to check if the winsize
> > > > has
> > > > changed
> > > > 
> > > > I would go with the second approach then
> > > 
> > > Me too, the timer is a bit unfortunate, but it's probably the less
> > > bad option.
> > 
> > I don't think we want a timer polling for an situation that will very
> > rarely arise.  We already add the 'chardev_resize' QMP command, which
> > is
> > a good enough way to kick QEMU to re-read the size.
> > 
> > With regards,
> > Daniel
> 
> This approach would only work with libvirt and not generic pty
> applications though. Perhaps a bool poll_resize could be added to the
> struct Chardev which is disabled, as soon as the chardev_resize QMP
> command is used to avoid race conditions.

Well, terminal emulators that set the pty size typically create their own pty
and control it from the master side. I don't know what pty applications you
have in mind—changing the window size from the slave side is somewhat
atypical. Applications designed for a real serial port probably don't set the size at all.

Regards,
Filip
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Filip Hejsek 1 week, 4 days ago

On September 17, 2025 3:31:57 PM GMT+02:00, "Daniel P. Berrangé" <berrange@redhat.com> wrote:
> [...]
> > > 2. create a timer polling every eg 100ms to check if the winsize has
> > > changed
> [...]
> 
> I don't think we want a timer polling for an situation that will very
> rarely arise.  We already add the 'chardev_resize' QMP command, which is
> a good enough way to kick QEMU to re-read the size.

So the size provided in the command would be ignored, and QEMU would instead query the pty fd?

Note that this would mean there is no size info if the command is not used, because the size will be 0x0 when the pty is created by QEMU (though we could add device parameters for the initial size).

Best regards,
Filip
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Daniel P. Berrangé 1 week, 4 days ago
On Wed, Sep 17, 2025 at 04:08:01PM +0200, Filip Hejsek wrote:
> 
> 
> On September 17, 2025 3:31:57 PM GMT+02:00, "Daniel P. Berrangé" <berrange@redhat.com> wrote:
> > [...]
> > > > 2. create a timer polling every eg 100ms to check if the winsize has
> > > > changed
> > [...]
> > 
> > I don't think we want a timer polling for an situation that will very
> > rarely arise.  We already add the 'chardev_resize' QMP command, which is
> > a good enough way to kick QEMU to re-read the size.
> 
> So the size provided in the command would be ignored, and QEMU would
> instead query the pty fd?

Actually I was just thinking we ignore the pty and only support the QMP
command. There is little point in trying for access size via the pty
if clients need the QMP command regardless to notify QEMU.

> Note that this would mean there is no size info if the command is
> not used, because the size will be 0x0 when the pty is created by
> QEMU (though we could add device parameters for the initial size).

We shouldn't send any size info to the guest if the hsot backend
does not have it available.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Filip Hejsek 1 week, 3 days ago
On Wed, 2025-09-17 at 17:17 +0100, Daniel P. Berrangé wrote:

> We shouldn't send any size info to the guest if the hsot backend
> does not have it available.

Does that mean sending 0x0, or not sending anything at all? The later
is tricky, because for non-multiport devices it's only really possible
by not offering the feature bit, but we don't know upfront whether the
size command will be used.
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Daniel P. Berrangé 1 week, 3 days ago
On Wed, Sep 17, 2025 at 07:11:03PM +0200, Filip Hejsek wrote:
> On Wed, 2025-09-17 at 17:17 +0100, Daniel P. Berrangé wrote:
> 
> > We shouldn't send any size info to the guest if the hsot backend
> > does not have it available.
> 
> Does that mean sending 0x0, or not sending anything at all? The later
> is tricky, because for non-multiport devices it's only really possible
> by not offering the feature bit, but we don't know upfront whether the
> size command will be used.

Nothing at all - is in no difference from current QEMU behaviour.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Filip Hejsek 1 week, 3 days ago
On Wed, 2025-09-17 at 18:53 +0100, Daniel P. Berrangé wrote:
> On Wed, Sep 17, 2025 at 07:11:03PM +0200, Filip Hejsek wrote:
> > On Wed, 2025-09-17 at 17:17 +0100, Daniel P. Berrangé wrote:
> > 
> > > We shouldn't send any size info to the guest if the hsot backend
> > > does not have it available.
> > 
> > Does that mean sending 0x0, or not sending anything at all? The later
> > is tricky, because for non-multiport devices it's only really possible
> > by not offering the feature bit, but we don't know upfront whether the
> > size command will be used.
> 
> Nothing at all - is in no difference from current QEMU behaviour.

As I said, that's not possible with the current semantics of the resize
command, as we would need to know upfront whether it is going to be
used.

To get the exact same behavior as current QEMU, we would need to add
some way to inform QEMU whether we want to use the resize command (e.g.
device property).

Even then, depending on how you interpret the virtio spec, there would
be a problem with multiport devices if port 0 didn't support size, but
another port did. Not providing port 0 size can only be done by not
offering the size feature bit, and then the question is, can you still
send resize events for the other ports? The spec does not say either
way.

Note that getting the exact same behavior as current QEMU is still
possible by disabling the console-size property on the virtio-serial
device (but it applies to all ports).

With regards,
Filip
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Daniel P. Berrangé 1 week, 3 days ago
On Wed, Sep 17, 2025 at 08:29:39PM +0200, Filip Hejsek wrote:
> On Wed, 2025-09-17 at 18:53 +0100, Daniel P. Berrangé wrote:
> > On Wed, Sep 17, 2025 at 07:11:03PM +0200, Filip Hejsek wrote:
> > > On Wed, 2025-09-17 at 17:17 +0100, Daniel P. Berrangé wrote:
> > > 
> > > > We shouldn't send any size info to the guest if the hsot backend
> > > > does not have it available.
> > > 
> > > Does that mean sending 0x0, or not sending anything at all? The later
> > > is tricky, because for non-multiport devices it's only really possible
> > > by not offering the feature bit, but we don't know upfront whether the
> > > size command will be used.

What are the semantics in the guest if we sent 0x0 as the size ?
AFAICT the virtio spec is silent on what '0x0' means.

It seems like it could conceivably have any behaviour, whether
a zero-size console, or a console clamped to 1x1 as a min size,
or a console reset to an arbitrary guest default like 80x24.


> > Nothing at all - is in no difference from current QEMU behaviour.
> 
> As I said, that's not possible with the current semantics of the resize
> command, as we would need to know upfront whether it is going to be
> used.
> 
> To get the exact same behavior as current QEMU, we would need to add
> some way to inform QEMU whether we want to use the resize command (e.g.
> device property).

That is usually unknowable at the time we spawn QEMU.

I'd say that the common case is for guests to get given a console
connected to a UNIX socket. Most of the time the console will not
be used. If it is, then we've no idea whether the client will be
something virtualization-unaware like a plain 'socat', or something
virtualization-aware like libvirt's  'virsh console'.

> Even then, depending on how you interpret the virtio spec, there would
> be a problem with multiport devices if port 0 didn't support size, but
> another port did. Not providing port 0 size can only be done by not
> offering the size feature bit, and then the question is, can you still
> send resize events for the other ports? The spec does not say either
> way.
>
> Note that getting the exact same behavior as current QEMU is still
> possible by disabling the console-size property on the virtio-serial
> device (but it applies to all ports).

Yes, it seems like the spec ties our hands here wrt multiple ports.

I didn't apprepreciate in my previous review that integrating this support
into QEMU was going to imply us /always/ informing the guest about the
requested console size for all ports, regardless of the backend.

I had been under the belief that we were only going to pass size info to
the guest, if the chardev was 'stdio', and for all other chardev backends
no size info would be passed unless we had issued the QMP resize command.

That we will always pass size info the guest regardless of the backend,
across all ports, changes my view about whether it is  reasonable to
enable resize by default given the known Linux guest bug.

The impact of the guest bug is just about tolerable if we were only going
to enable passing size information when the user had chosen 'stdio' backend
as that is relatively rarely used and mostly by ad-hoc dev usage where it
is perhaps easier for users to get a fixed guest kernel.

If we enable this for all ports though, regardless of backend, then I think
we're going to cause too much pain for users with the inverted rows/cols,
as its going to apply in every single deployment of QEMU using virtioconsole.

So IMHO we cannot enable this without explict user opt-in.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Maximilian Immanuel Brandtner 1 week, 3 days ago
On Thu, 2025-09-18 at 09:35 +0100, Daniel P. Berrangé wrote:
> On Wed, Sep 17, 2025 at 08:29:39PM +0200, Filip Hejsek wrote:
> > On Wed, 2025-09-17 at 18:53 +0100, Daniel P. Berrangé wrote:
> > > On Wed, Sep 17, 2025 at 07:11:03PM +0200, Filip Hejsek wrote:
> > > > On Wed, 2025-09-17 at 17:17 +0100, Daniel P. Berrangé wrote:
> > > > 
> > > > > We shouldn't send any size info to the guest if the hsot
> > > > > backend
> > > > > does not have it available.
> > > > 
> > > > Does that mean sending 0x0, or not sending anything at all? The
> > > > later
> > > > is tricky, because for non-multiport devices it's only really
> > > > possible
> > > > by not offering the feature bit, but we don't know upfront
> > > > whether the
> > > > size command will be used.
> 
> What are the semantics in the guest if we sent 0x0 as the size ?
> AFAICT the virtio spec is silent on what '0x0' means.
> 
> It seems like it could conceivably have any behaviour, whether
> a zero-size console, or a console clamped to 1x1 as a min size,
> or a console reset to an arbitrary guest default like 80x24.

During testing the kernel resized the tty to 0x0 if VirtIO instructed
the kernel to resize the tty to 0x0.
> 
> 
> > > Nothing at all - is in no difference from current QEMU behaviour.
> > 
> > As I said, that's not possible with the current semantics of the
> > resize
> > command, as we would need to know upfront whether it is going to be
> > used.
> > 
> > To get the exact same behavior as current QEMU, we would need to
> > add
> > some way to inform QEMU whether we want to use the resize command
> > (e.g.
> > device property).
> 
> That is usually unknowable at the time we spawn QEMU.
> 
> I'd say that the common case is for guests to get given a console
> connected to a UNIX socket. Most of the time the console will not
> be used. If it is, then we've no idea whether the client will be
> something virtualization-unaware like a plain 'socat', or something
> virtualization-aware like libvirt's  'virsh console'.
> 
> > Even then, depending on how you interpret the virtio spec, there
> > would
> > be a problem with multiport devices if port 0 didn't support size,
> > but
> > another port did. Not providing port 0 size can only be done by not
> > offering the size feature bit, and then the question is, can you
> > still
> > send resize events for the other ports? The spec does not say
> > either
> > way.
> > 
> > Note that getting the exact same behavior as current QEMU is still
> > possible by disabling the console-size property on the virtio-
> > serial
> > device (but it applies to all ports).
> 
> Yes, it seems like the spec ties our hands here wrt multiple ports.
> 
> I didn't apprepreciate in my previous review that integrating this
> support
> into QEMU was going to imply us /always/ informing the guest about
> the
> requested console size for all ports, regardless of the backend.
> 
> I had been under the belief that we were only going to pass size info
> to
> the guest, if the chardev was 'stdio', and for all other chardev
> backends
> no size info would be passed unless we had issued the QMP resize
> command.
> 
> That we will always pass size info the guest regardless of the
> backend,
> across all ports, changes my view about whether it is  reasonable to
> enable resize by default given the known Linux guest bug.
> 
> The impact of the guest bug is just about tolerable if we were only
> going
> to enable passing size information when the user had chosen 'stdio'
> backend
> as that is relatively rarely used and mostly by ad-hoc dev usage
> where it
> is perhaps easier for users to get a fixed guest kernel.
> 
> If we enable this for all ports though, regardless of backend, then I
> think
> we're going to cause too much pain for users with the inverted
> rows/cols,
> as its going to apply in every single deployment of QEMU using
> virtioconsole.
> 
> So IMHO we cannot enable this without explict user opt-in.
> 
> With regards,
> Daniel
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Daniel P. Berrangé 1 week, 3 days ago
On Thu, Sep 18, 2025 at 10:39:28AM +0200, Maximilian Immanuel Brandtner wrote:
> On Thu, 2025-09-18 at 09:35 +0100, Daniel P. Berrangé wrote:
> > On Wed, Sep 17, 2025 at 08:29:39PM +0200, Filip Hejsek wrote:
> > > On Wed, 2025-09-17 at 18:53 +0100, Daniel P. Berrangé wrote:
> > > > On Wed, Sep 17, 2025 at 07:11:03PM +0200, Filip Hejsek wrote:
> > > > > On Wed, 2025-09-17 at 17:17 +0100, Daniel P. Berrangé wrote:
> > > > > 
> > > > > > We shouldn't send any size info to the guest if the hsot
> > > > > > backend
> > > > > > does not have it available.
> > > > > 
> > > > > Does that mean sending 0x0, or not sending anything at all? The
> > > > > later
> > > > > is tricky, because for non-multiport devices it's only really
> > > > > possible
> > > > > by not offering the feature bit, but we don't know upfront
> > > > > whether the
> > > > > size command will be used.
> > 
> > What are the semantics in the guest if we sent 0x0 as the size ?
> > AFAICT the virtio spec is silent on what '0x0' means.
> > 
> > It seems like it could conceivably have any behaviour, whether
> > a zero-size console, or a console clamped to 1x1 as a min size,
> > or a console reset to an arbitrary guest default like 80x24.
> 
> During testing the kernel resized the tty to 0x0 if VirtIO instructed
> the kernel to resize the tty to 0x0.

If the chardev backends are defaulting to 0x0 for everything except
the 'stdio' backend, then this series is surely going to break all
existing usage of virtio-console for non-stdio backends ?

What am I missing here ?

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Maximilian Immanuel Brandtner 1 week, 3 days ago
On Thu, 2025-09-18 at 09:48 +0100, Daniel P. Berrangé wrote:
> On Thu, Sep 18, 2025 at 10:39:28AM +0200, Maximilian Immanuel
> Brandtner wrote:
> > On Thu, 2025-09-18 at 09:35 +0100, Daniel P. Berrangé wrote:
> > > On Wed, Sep 17, 2025 at 08:29:39PM +0200, Filip Hejsek wrote:
> > > > On Wed, 2025-09-17 at 18:53 +0100, Daniel P. Berrangé wrote:
> > > > > On Wed, Sep 17, 2025 at 07:11:03PM +0200, Filip Hejsek wrote:
> > > > > > On Wed, 2025-09-17 at 17:17 +0100, Daniel P. Berrangé
> > > > > > wrote:
> > > > > > 
> > > > > > > We shouldn't send any size info to the guest if the hsot
> > > > > > > backend
> > > > > > > does not have it available.
> > > > > > 
> > > > > > Does that mean sending 0x0, or not sending anything at all?
> > > > > > The
> > > > > > later
> > > > > > is tricky, because for non-multiport devices it's only
> > > > > > really
> > > > > > possible
> > > > > > by not offering the feature bit, but we don't know upfront
> > > > > > whether the
> > > > > > size command will be used.
> > > 
> > > What are the semantics in the guest if we sent 0x0 as the size ?
> > > AFAICT the virtio spec is silent on what '0x0' means.
> > > 
> > > It seems like it could conceivably have any behaviour, whether
> > > a zero-size console, or a console clamped to 1x1 as a min size,
> > > or a console reset to an arbitrary guest default like 80x24.
> > 
> > During testing the kernel resized the tty to 0x0 if VirtIO
> > instructed
> > the kernel to resize the tty to 0x0.
> 
> If the chardev backends are defaulting to 0x0 for everything except
> the 'stdio' backend, then this series is surely going to break all
> existing usage of virtio-console for non-stdio backends ?
> 
> What am I missing here ?
> 
> With regards,
> Daniel

Most applications fall back to 80x24 if the terminal size is 0x0 so
it's not as big of a dealbreaker as you might think.

However, I think it would be even better if the patch-set could be
changed to account for that. After initializing the VirtIO console a
resize event could be sent to set the initial size (80x24), which might
later be changed or be left as is.
If the VIRTIO_CONSOLE_F_SIZE is negotiated(and this feature flag is
necessary for multiport resize messages not to be ignored) QEMU is
responsible for setting the initial terminal size.

Kind regards,
Max Brandtner
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Daniel P. Berrangé 1 week, 3 days ago
On Thu, Sep 18, 2025 at 10:54:45AM +0200, Maximilian Immanuel Brandtner wrote:
> On Thu, 2025-09-18 at 09:48 +0100, Daniel P. Berrangé wrote:
> > On Thu, Sep 18, 2025 at 10:39:28AM +0200, Maximilian Immanuel
> > Brandtner wrote:
> > > On Thu, 2025-09-18 at 09:35 +0100, Daniel P. Berrangé wrote:
> > > > On Wed, Sep 17, 2025 at 08:29:39PM +0200, Filip Hejsek wrote:
> > > > > On Wed, 2025-09-17 at 18:53 +0100, Daniel P. Berrangé wrote:
> > > > > > On Wed, Sep 17, 2025 at 07:11:03PM +0200, Filip Hejsek wrote:
> > > > > > > On Wed, 2025-09-17 at 17:17 +0100, Daniel P. Berrangé
> > > > > > > wrote:
> > > > > > > 
> > > > > > > > We shouldn't send any size info to the guest if the hsot
> > > > > > > > backend
> > > > > > > > does not have it available.
> > > > > > > 
> > > > > > > Does that mean sending 0x0, or not sending anything at all?
> > > > > > > The
> > > > > > > later
> > > > > > > is tricky, because for non-multiport devices it's only
> > > > > > > really
> > > > > > > possible
> > > > > > > by not offering the feature bit, but we don't know upfront
> > > > > > > whether the
> > > > > > > size command will be used.
> > > > 
> > > > What are the semantics in the guest if we sent 0x0 as the size ?
> > > > AFAICT the virtio spec is silent on what '0x0' means.
> > > > 
> > > > It seems like it could conceivably have any behaviour, whether
> > > > a zero-size console, or a console clamped to 1x1 as a min size,
> > > > or a console reset to an arbitrary guest default like 80x24.
> > > 
> > > During testing the kernel resized the tty to 0x0 if VirtIO
> > > instructed
> > > the kernel to resize the tty to 0x0.
> > 
> > If the chardev backends are defaulting to 0x0 for everything except
> > the 'stdio' backend, then this series is surely going to break all
> > existing usage of virtio-console for non-stdio backends ?
> > 
> > What am I missing here ?
> 
> Most applications fall back to 80x24 if the terminal size is 0x0 so
> it's not as big of a dealbreaker as you might think.

I'm not convinced that its a good idea for QEMU to be relying on every
application to be doing that. I can forsee the bug reports from situations
where this doesn't happen and something ends up dividing by zero when
doing an aspect ratio calculation.  Yes, we could point to the app code
and call it buggy, but I think there's a strong case to be made that we
shouldn't have been sending 0x0 to begin with.

> However, I think it would be even better if the patch-set could be
> changed to account for that. After initializing the VirtIO console a
> resize event could be sent to set the initial size (80x24), which might
> later be changed or be left as is.

The problem with QEMU sending 80x24 instead of 0x0 is that the majority
of Linux guests will then treat that as 24x80 due to the historical bug
in Linux drivers. This will probably be even worse than the bugs we get
from sending 0x0.

> If the VIRTIO_CONSOLE_F_SIZE is negotiated(and this feature flag is
> necessary for multiport resize messages not to be ignored) QEMU is
> responsible for setting the initial terminal size.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Maximilian Immanuel Brandtner 1 week, 3 days ago
On Thu, 2025-09-18 at 09:59 +0100, Daniel P. Berrangé wrote:
> On Thu, Sep 18, 2025 at 10:54:45AM +0200, Maximilian Immanuel
> Brandtner wrote:
> > On Thu, 2025-09-18 at 09:48 +0100, Daniel P. Berrangé wrote:
> > > On Thu, Sep 18, 2025 at 10:39:28AM +0200, Maximilian Immanuel
> > > Brandtner wrote:
> > > > On Thu, 2025-09-18 at 09:35 +0100, Daniel P. Berrangé wrote:
> > > > > On Wed, Sep 17, 2025 at 08:29:39PM +0200, Filip Hejsek wrote:
> > > > > > On Wed, 2025-09-17 at 18:53 +0100, Daniel P. Berrangé
> > > > > > wrote:
> > > > > > > On Wed, Sep 17, 2025 at 07:11:03PM +0200, Filip Hejsek
> > > > > > > wrote:
> > > > > > > > On Wed, 2025-09-17 at 17:17 +0100, Daniel P. Berrangé
> > > > > > > > wrote:
> > > > > > > > 
> > > > > > > > > We shouldn't send any size info to the guest if the
> > > > > > > > > hsot
> > > > > > > > > backend
> > > > > > > > > does not have it available.
> > > > > > > > 
> > > > > > > > Does that mean sending 0x0, or not sending anything at
> > > > > > > > all?
> > > > > > > > The
> > > > > > > > later
> > > > > > > > is tricky, because for non-multiport devices it's only
> > > > > > > > really
> > > > > > > > possible
> > > > > > > > by not offering the feature bit, but we don't know
> > > > > > > > upfront
> > > > > > > > whether the
> > > > > > > > size command will be used.
> > > > > 
> > > > > What are the semantics in the guest if we sent 0x0 as the
> > > > > size ?
> > > > > AFAICT the virtio spec is silent on what '0x0' means.
> > > > > 
> > > > > It seems like it could conceivably have any behaviour,
> > > > > whether
> > > > > a zero-size console, or a console clamped to 1x1 as a min
> > > > > size,
> > > > > or a console reset to an arbitrary guest default like 80x24.
> > > > 
> > > > During testing the kernel resized the tty to 0x0 if VirtIO
> > > > instructed
> > > > the kernel to resize the tty to 0x0.
> > > 
> > > If the chardev backends are defaulting to 0x0 for everything
> > > except
> > > the 'stdio' backend, then this series is surely going to break
> > > all
> > > existing usage of virtio-console for non-stdio backends ?
> > > 
> > > What am I missing here ?
> > 
> > Most applications fall back to 80x24 if the terminal size is 0x0 so
> > it's not as big of a dealbreaker as you might think.
> 
> I'm not convinced that its a good idea for QEMU to be relying on
> every
> application to be doing that. I can forsee the bug reports from
> situations
> where this doesn't happen and something ends up dividing by zero when
> doing an aspect ratio calculation.  Yes, we could point to the app
> code
> and call it buggy, but I think there's a strong case to be made that
> we
> shouldn't have been sending 0x0 to begin with.
> 
> > However, I think it would be even better if the patch-set could be
> > changed to account for that. After initializing the VirtIO console
> > a
> > resize event could be sent to set the initial size (80x24), which
> > might
> > later be changed or be left as is.
> 
> The problem with QEMU sending 80x24 instead of 0x0 is that the
> majority
> of Linux guests will then treat that as 24x80 due to the historical
> bug
> in Linux drivers. This will probably be even worse than the bugs we
> get
> from sending 0x0.

I agree that this is a much more significant issue and I like your idea
of adding an opt-in parameter to support resizing for the virtio-
console chardev. The smoothest solution would have been a spec-change.

> 
> > If the VIRTIO_CONSOLE_F_SIZE is negotiated(and this feature flag is
> > necessary for multiport resize messages not to be ignored) QEMU is
> > responsible for setting the initial terminal size.
> 
> With regards,
> Daniel
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Filip Hejsek 1 week, 2 days ago
I will respond to all messages from this thread at once here.

Daniel P. Berrangé wrote:
> That we will always pass size info the guest regardless of the backend,
> across all ports, changes my view about whether it is  reasonable to
> enable resize by default given the known Linux guest bug.
>
> The impact of the guest bug is just about tolerable if we were only going
> to enable passing size information when the user had chosen 'stdio' backend
> as that is relatively rarely used and mostly by ad-hoc dev usage where it
> is perhaps easier for users to get a fixed guest kernel.
>
> If we enable this for all ports though, regardless of backend, then I think
> we're going to cause too much pain for users with the inverted rows/cols,
> as its going to apply in every single deployment of QEMU using virtioconsole.

Inverted rows/cols don't matter for 0x0 size, 0x0 is still 0x0 when
swapped. Sizes other than 0x0 will only be sent from supported backends
(but it will be supported by more than just stdio).

> If the chardev backends are defaulting to 0x0 for everything except
> the 'stdio' backend, then this series is surely going to break all
> existing usage of virtio-console for non-stdio backends ?

At least for Linux guests, if no size is sent, the kernel defaults to
0x0, so sending 0x0 is equivalent to not sending anything. Nothing new
will break by sending 0x0.

We still need to be careful not to reset the size to 0x0 after
userspace has changed it though. With the non-multiport interface, the
kernel will reapply the size every time it gets the config interrupt.
If some other use for the config interrupt is added in the future
besides resizing, it could become a problem.

Actually, from looking at Linux source, it appears that linux only
reads the size after getting the config interrupt. This seems to imply
that linux will ignore the initial value if no interrupt is sent. That
might be a bug.

Maximilian Immanuel Brandtner wrote:
> I agree that this is a much more significant issue and I like your idea
> of adding an opt-in parameter to support resizing for the virtio-
> console chardev.

The console-size property can already disable size support, so making
it an opt-in is only a matter of changing the default

> The smoothest solution would have been a spec-change.

Here is the spec change proposal (thanks to MST for submitting it!):
https://lore.kernel.org/virtio-comment/7b939d85ec0b532bae4c16bb927edddcf663bb48.1758212319.git.mst@redhat.com/

Best regards,
Filip Hejsek
Re: [PATCH v2] char-pty: add support for the terminal size
Posted by Michael S. Tsirkin 1 week, 5 days ago
On Mon, Sep 15, 2025 at 06:34:15PM +0200, Maximilian Immanuel Brandtner wrote:
> Update the terminal size upon SIGWINCH delivery.
> 
> Signed-off-by: Maximilian Immanuel Brandtner <maxbr@linux.ibm.com>


Maximilian, on  a related note, could you comment on the revert
of your patch that I posted to lkml? Thanks!

> ---
> 
> To be committed with the patch-set: [PATCH v4 00/10] virtio-console: notify about the terminal size
> 
> v1 -> v2: Move comment regarding patch dependencies to note section
> ---
>  chardev/char-pty.c | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/chardev/char-pty.c b/chardev/char-pty.c
> index 674e9b3f14..802bae9037 100644
> --- a/chardev/char-pty.c
> +++ b/chardev/char-pty.c
> @@ -28,6 +28,7 @@
>  #include "io/channel-file.h"
>  #include "qemu/sockets.h"
>  #include "qemu/error-report.h"
> +#include "qemu/main-loop.h"
>  #include "qemu/module.h"
>  #include "qemu/option.h"
>  #include "qemu/qemu-print.h"
> @@ -35,6 +36,8 @@
>  #include "chardev/char-io.h"
>  #include "qom/object.h"
>  
> +#include <sys/ioctl.h>
> +
>  struct PtyChardev {
>      Chardev parent;
>      QIOChannel *ioc;
> @@ -43,6 +46,8 @@ struct PtyChardev {
>      int connected;
>      GSource *timer_src;
>      char *path;
> +
> +    Notifier resize_notifier;
>  };
>  typedef struct PtyChardev PtyChardev;
>  
> @@ -85,6 +90,15 @@ static void pty_chr_rearm_timer(Chardev *chr, int ms)
>      g_free(name);
>  }
>  
> +static void pty_chr_resize(PtyChardev *s)
> +{
> +    struct winsize ws;
> +
> +    if (ioctl(QIO_CHANNEL_FILE(s->ioc)->fd, TIOCGWINSZ, &ws) != -1) {
> +        qemu_chr_resize(CHARDEV(s), ws.ws_col, ws.ws_row);
> +    }
> +}
> +
>  static void pty_chr_update_read_handler(Chardev *chr)
>  {
>      PtyChardev *s = PTY_CHARDEV(chr);
> @@ -331,6 +345,12 @@ static int qemu_openpty_raw(int *aslave, char *pty_name)
>      return amaster;
>  }
>  
> +static void term_resize_notify(Notifier *n, void *data)
> +{
> +    PtyChardev *s = container_of(n, PtyChardev, resize_notifier);
> +    pty_chr_resize(s);
> +}
> +
>  static void char_pty_open(Chardev *chr,
>                            ChardevBackend *backend,
>                            bool *be_opened,
> @@ -376,6 +396,10 @@ static void char_pty_open(Chardev *chr,
>              s->path = g_strdup(path);
>          }
>      }
> +
> +    pty_chr_resize(s);
> +    s->resize_notifier.notify = term_resize_notify;
> +    sigwinch_add_notifier(&s->resize_notifier);
>  }
>  
>  static void char_pty_parse(QemuOpts *opts, ChardevBackend *backend,
> -- 
> 2.50.1
Re: [PATCH v4 00/10] virtio-console: notify about the terminal size
Posted by Michael S. Tsirkin 2 weeks, 2 days ago
On Fri, Sep 12, 2025 at 09:50:30AM +0100, Daniel P. Berrangé wrote:
> On Fri, Sep 12, 2025 at 04:41:02AM -0400, Michael S. Tsirkin wrote:
> > On Fri, Sep 12, 2025 at 05:39:45AM +0200, Filip Hejsek wrote:
> > > 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.
> > > 
> > > 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.
> > > 
> > > This series adds support for a resizable terminal if a virtio console
> > > device is connected to the stdio backend.
> > > 
> > > 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.
> > > 
> > > This patch series was originally authored by Szymon Lukasz and submitted
> > > to qemu-devel about 5 years ago. The previous submission can be found at
> > > <https://lists.nongnu.org/archive/html/qemu-devel/2020-06/msg09591.html>.
> > > I have updated the patches to be compatible with latest master and made
> > > a few small changes of my own, including the addition of Windows support.
> > > 
> > > Probably the most important change I made is the swapping of rows and
> > > cols fields in resize messages. I would like to hear some feedback on
> > > this change from reviewers. The problem is that for a long time, the
> > > Linux kernel used a different field order from what was specified in the
> > > virtio spec. The kernel implementation was apparently merged around 2010,
> > > while the virtio spec came in 2014, so when a previous version of this
> > > patch series was being discussed here on this mailing list in 2020, it
> > > was decided that QEMU should match the Linux implementation, and ideally,
> > > the virtio spec should be changed.
> > > 
> > > However, recently, the Linux kernel implementation was changed to conform
> > > to the spec: <https://git.kernel.org/linus/5326ab737a47278dbd16ed3ee7380b26c7056ddd>.
> > > As a result, to be compatible with latest kernel releases, QEMU needs to
> > > also use the field order matching the specification. I have changed the
> > > patch to use the spec-compliant order, so it works correctly with latest
> > > kernels now.
> > >
> > 
> > Well this is not in any release yet. If you want me to revert that
> > one, let me know ASAP. Maximilian?
> > 
> > > That leaves the issue of older kernels. There are about 15 years' worth
> > > of kernel versions with the swapped field order, including the kernel
> > > currently shipped in Debian stable. The effects of the swapped dimensions
> > > can sometimes be quite annoying - e.g. if you have a terminal with
> > > 24 rows, this will be interpreted as 24 columns, and your shell may limit 
> > > line editing to this small space, most of which will be taken by your
> > > prompt. The patch series in its current form provides no way to disable
> > > the console size functionality,
> > 
> > Well I see the console-size property, no?
> 
> At least in the case of libvirt managed VMs, this series does
> nothin by default, as they won't be using the 'stdio' chardev,
> they'll require libvirt to first wire up the new QMP command,
> and then apps using libvirt to call it. So in that sense, it'll
> take a while before the effects are seen by users.
> 
> > > so users may end up worse off than if
> > > the functionality were not implemented at all.
> > 
> > If we want to keep the Linux patch, the straight forward way is to send
> > the fix to stable@ then poke at Debian at al to fix their kernels.
> > 
> > Another option is to make the property default to off, have
> > management turn it on when guest is up to date.
> > 
> > But it really sounds like we should revert that Linux patch.
> > I posted a revert, pls comment.
> 
> What about other non-Linux guest OS that may have correctly
> implemented the virtio spec ?
> 
> At least FreeBSD appears to /not/ implemenmt resize at all:
> 
>   https://github.com/freebsd/freebsd-src/blob/main/sys/dev/virtio/console/virtio_console.c#L884
> 
> Do we have a Windows impl of virtio-console with resize support ?

Windows seems to ignore it:

        case VIRTIO_CONSOLE_RESIZE:
            TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "VIRTIO_CONSOLE_RESIZE id = %d\n", cpkt->id);
            break;



> Any other places we should check ?
> 
> With regards,
> Daniel
> -- 
> |: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org         -o-            https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Re: [PATCH v4 00/10] virtio-console: notify about the terminal size
Posted by Michael S. Tsirkin 2 weeks, 2 days ago
On Fri, Sep 12, 2025 at 04:41:05AM -0400, Michael S. Tsirkin wrote:
> On Fri, Sep 12, 2025 at 05:39:45AM +0200, Filip Hejsek wrote:
> > 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.
> > 
> > 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.
> > 
> > This series adds support for a resizable terminal if a virtio console
> > device is connected to the stdio backend.
> > 
> > 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.
> > 
> > This patch series was originally authored by Szymon Lukasz and submitted
> > to qemu-devel about 5 years ago. The previous submission can be found at
> > <https://lists.nongnu.org/archive/html/qemu-devel/2020-06/msg09591.html>.
> > I have updated the patches to be compatible with latest master and made
> > a few small changes of my own, including the addition of Windows support.
> > 
> > Probably the most important change I made is the swapping of rows and
> > cols fields in resize messages. I would like to hear some feedback on
> > this change from reviewers. The problem is that for a long time, the
> > Linux kernel used a different field order from what was specified in the
> > virtio spec. The kernel implementation was apparently merged around 2010,
> > while the virtio spec came in 2014, so when a previous version of this
> > patch series was being discussed here on this mailing list in 2020, it
> > was decided that QEMU should match the Linux implementation, and ideally,
> > the virtio spec should be changed.
> > 
> > However, recently, the Linux kernel implementation was changed to conform
> > to the spec: <https://git.kernel.org/linus/5326ab737a47278dbd16ed3ee7380b26c7056ddd>.
> > As a result, to be compatible with latest kernel releases, QEMU needs to
> > also use the field order matching the specification. I have changed the
> > patch to use the spec-compliant order, so it works correctly with latest
> > kernels now.
> >
> 
> Well this is not in any release yet. If you want me to revert that
> one, let me know ASAP. Maximilian?
> 
> > That leaves the issue of older kernels. There are about 15 years' worth
> > of kernel versions with the swapped field order, including the kernel
> > currently shipped in Debian stable. The effects of the swapped dimensions
> > can sometimes be quite annoying - e.g. if you have a terminal with
> > 24 rows, this will be interpreted as 24 columns, and your shell may limit 
> > line editing to this small space, most of which will be taken by your
> > prompt. The patch series in its current form provides no way to disable
> > the console size functionality,
> 
> Well I see the console-size property, no?
> 
> > so users may end up worse off than if
> > the functionality were not implemented at all.
> 
> If we want to keep the Linux patch, the straight forward way is to send
> the fix to stable@ then poke at Debian at al to fix their kernels.
> 
> Another option is to make the property default to off, have
> management turn it on when guest is up to date.
> 
> But it really sounds like we should revert that Linux patch.
> I posted a revert, pls comment.

Oh no, I was confused. This was in 6.15 and 6.16 :(


Pls ignore this, I will reply separately.




> > PS: One of the patches adds one additional noop switch case
> >     to a bunch of files. I didn't include the maintainers of these files
> >     in the Cc list. I hope that's OK. :)
> > 
> > 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)
> > 
> > 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 (1):
> >       char-win-stdio: add support for terminal size
> > 
> > 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-resize 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       | 43 ++++++++++++++++++++++++--
> >  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                    | 22 ++++++++++++++
> >  ui/curses.c                       | 11 +++----
> >  util/main-loop.c                  | 21 +++++++++++++
> >  30 files changed, 298 insertions(+), 13 deletions(-)
> > ---
> > base-commit: 190d5d7fd725ff754f94e8e0cbfb69f279c82b5d
> > change-id: 20250912-console-resize-96c42140ba08
> > 
> > Best regards,
> > -- 
> > Filip Hejsek <filip.hejsek@gmail.com>