public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
* [PATCH v6 00/12] virtio-console: notify about the terminal size
@ 2026-01-19  3:27 Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 01/12] chardev: add cols, rows fields Filip Hejsek
                   ` (11 more replies)
  0 siblings, 12 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-19  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner, Szymon Lukasz

Summary of The Series
---------------------

This series adds terminal size support to the virtio-console device.
The goal is to make it possible to get a resizable terminal into a guest
without using e.g. ssh.

Support for detecting terminal size is added to stdio and vc backends,
but not pty and serial, because for the later it's unfortunately
impossible to get resize notifications.

A QMP command is added for notifying QEMU about the terminal size
of any chardev. This can be used by clients to support resizing for
devices where QEMU is not able to detect the size by itself (e.g. virsh
console).

There is a bug in Linux versions prior to 6.15 which causes the
dimensions to be interpreted incorrectly by the guest. If the guest
kernel is not up to date, the wrong dimensions can make the terminal
hard to use. The fix will be backported to stable kernels soon, and the
problem can be worked around by disabling the feature using the
console-size property, restoring the previous behavior.

Notes for This Version
----------------------

The issue with swapped rows/cols has now been resolved - the virtio spec
will remain unchanged, and the kernel fix is being backported.

The console-size property is not documented, even though it can be
useful for working aroung a guest kernel bug.

The 'vc' chardev size support is still incomplete - size support has
been added only to the generic and gtk/vte implementations. Size support
for the spice implementation is still missing, and the generic
implementation is mostly untested.

The previous version had a bug that it didn't resend the size
after a guest reset. While fixing this, I ended up rewriting a
significant part of the virtio changes. I also removed the logic
that tries to avoid sending VIRTIO_CONSOLE_RESIZE messages before a
VIRTIO_CONSOLE_CONSOLE_PORT message. I don't think this should cause any
problems, but if it does, the logic could be reintroduced.

Because one of the patches ended up being significantly different from
Szymon Lukasz's original version, I decided to change patch author and
instead add a note about the original version to the commit message. Let
me know if you would like this to be handled differently.

I have also found an initial size bug in the Linux kernel
implementation, although it only affects non-multiport devices. I posted
a fix for the Linux bug to Linux maining lists [1].

[1]: https://lore.kernel.org/virtualization/20251224-virtio-console-fix-v1-1-69d0349692dc@gmail.com/

Full Changelog
--------------

v6:
- Rebased (renaming CharBackend -> CharFrontend)
- Virtio resize message code rewritten to fix corner cases
- Updated version numbers ('Since: 11.0', hw_compat_10_2)
- Added note to CHR_EVENT_RESIZE definition comment, explaining
  that only the focused frontend gets the event
- Fixed checkpatch warning (line length)
- Link to v5: https://lore.kernel.org/qemu-devel/20250921-console-resize-v5-0-89e3c6727060@gmail.com

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 (4):
      virtio-serial-bus: add terminal resize messages
      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 (8):
      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-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          | 35 ++++++++++++++++--
 hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
 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            |  9 +++++
 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                    | 31 ++++++++++++++++
 ui/console-vc.c                   |  3 ++
 ui/curses.c                       | 11 +++---
 ui/gtk.c                          | 28 +++++++++++++++
 util/main-loop.c                  | 21 +++++++++++
 32 files changed, 346 insertions(+), 12 deletions(-)
---
base-commit: 38879a667fbb4ef54c70de71494882615f600a64
change-id: 20250912-console-resize-96c42140ba08

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



^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH v6 01/12] chardev: add cols, rows fields
  2026-01-19  3:27 [PATCH v6 00/12] virtio-console: notify about the terminal size Filip Hejsek
@ 2026-01-19  3:27 ` Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 02/12] chardev: add CHR_EVENT_RESIZE Filip Hejsek
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-19  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner, Szymon Lukasz

From: Szymon Lukasz <noh4hss@gmail.com>

These fields should be interpreted as the size of the terminal connected
to a given chardev.

Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
[Filip: CharBackend -> CharFrontend]
Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
---
 chardev/char-fe.c         | 13 +++++++++++++
 include/chardev/char-fe.h | 10 ++++++++++
 include/chardev/char.h    |  1 +
 3 files changed, 24 insertions(+)

diff --git a/chardev/char-fe.c b/chardev/char-fe.c
index 34b83fc1c4..a3bb1071b3 100644
--- a/chardev/char-fe.c
+++ b/chardev/char-fe.c
@@ -329,6 +329,19 @@ void qemu_chr_fe_set_echo(CharFrontend *c, bool echo)
     }
 }
 
+void qemu_chr_fe_get_winsize(CharFrontend *c, uint16_t *cols, uint16_t *rows)
+{
+    Chardev *chr = c->chr;
+
+    if (chr) {
+        *cols = chr->cols;
+        *rows = chr->rows;
+    } else {
+        *cols = 0;
+        *rows = 0;
+    }
+}
+
 void qemu_chr_fe_set_open(CharFrontend *c, bool is_open)
 {
     Chardev *chr = c->chr;
diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h
index 5f8a6df17d..53b8d2a1dc 100644
--- a/include/chardev/char-fe.h
+++ b/include/chardev/char-fe.h
@@ -157,6 +157,16 @@ int qemu_chr_fe_wait_connected(CharFrontend *c, Error **errp);
  */
 void qemu_chr_fe_set_echo(CharFrontend *c, bool echo);
 
+/**
+ * qemu_chr_fe_get_winsize:
+ * @cols: the address for storing columns
+ * @rows: the address for storing rows
+ *
+ * Get the size of the terminal connected to the chardev backend.
+ * Returns *cols = *rows = 0, if no associated Chardev.
+ */
+void qemu_chr_fe_get_winsize(CharFrontend *c, uint16_t *cols, uint16_t *rows);
+
 /**
  * qemu_chr_fe_set_open:
  * @c: a CharFrontend
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 192cad67d4..237238e5a0 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -65,6 +65,7 @@ struct Chardev {
     char *filename;
     int logfd;
     int be_open;
+    uint16_t cols, rows;
     /* used to coordinate the chardev-change special-case: */
     bool handover_yank_instance;
     GSource *gsource;

-- 
2.52.0



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 02/12] chardev: add CHR_EVENT_RESIZE
  2026-01-19  3:27 [PATCH v6 00/12] virtio-console: notify about the terminal size Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 01/12] chardev: add cols, rows fields Filip Hejsek
@ 2026-01-19  3:27 ` Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 03/12] chardev: add qemu_chr_resize() Filip Hejsek
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-19  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner, Szymon Lukasz

From: Szymon Lukasz <noh4hss@gmail.com>

Add a new chardev event, CHR_EVENT_RESIZE, which a backend should
trigger if it detects the size of the connected terminal changed.

Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
[Filip: add note that only the focused frontend gets the event]
Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
---
 backends/cryptodev-vhost-user.c | 1 +
 chardev/char.c                  | 1 +
 hw/block/vhost-user-blk.c       | 1 +
 hw/char/terminal3270.c          | 1 +
 hw/char/virtio-console.c        | 1 +
 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.h          | 6 ++++++
 monitor/hmp.c                   | 1 +
 monitor/qmp.c                   | 1 +
 net/passt.c                     | 1 +
 net/vhost-user.c                | 1 +
 17 files changed, 22 insertions(+)

diff --git a/backends/cryptodev-vhost-user.c b/backends/cryptodev-vhost-user.c
index cc478d9902..36564d4307 100644
--- a/backends/cryptodev-vhost-user.c
+++ b/backends/cryptodev-vhost-user.c
@@ -173,6 +173,7 @@ static void cryptodev_vhost_user_event(void *opaque, QEMUChrEvent event)
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/chardev/char.c b/chardev/char.c
index 3e432195a5..0f493d793f 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -75,6 +75,7 @@ void qemu_chr_be_event(Chardev *s, QEMUChrEvent event)
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index 4d81d2dc34..a460d6ed33 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -412,6 +412,7 @@ static void vhost_user_blk_event(void *opaque, QEMUChrEvent event)
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c
index 1d857bad9b..c212fd1aac 100644
--- a/hw/char/terminal3270.c
+++ b/hw/char/terminal3270.c
@@ -172,6 +172,7 @@ static void chr_event(void *opaque, QEMUChrEvent event)
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c
index 25db0f019b..dcfe5830f9 100644
--- a/hw/char/virtio-console.c
+++ b/hw/char/virtio-console.c
@@ -168,6 +168,7 @@ static void chr_event(void *opaque, QEMUChrEvent event)
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/hw/ipmi/ipmi_bmc_extern.c b/hw/ipmi/ipmi_bmc_extern.c
index fa08ed6c21..bd7c61b2d2 100644
--- a/hw/ipmi/ipmi_bmc_extern.c
+++ b/hw/ipmi/ipmi_bmc_extern.c
@@ -436,6 +436,7 @@ static void chr_event(void *opaque, QEMUChrEvent event)
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c
index 3612897d4b..5601097bc9 100644
--- a/hw/scsi/vhost-user-scsi.c
+++ b/hw/scsi/vhost-user-scsi.c
@@ -226,6 +226,7 @@ static void vhost_user_scsi_event(void *opaque, QEMUChrEvent event)
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c
index 5ab7855272..3f4052ec82 100644
--- a/hw/usb/ccid-card-passthru.c
+++ b/hw/usb/ccid-card-passthru.c
@@ -323,6 +323,7 @@ static void ccid_card_vscard_event(void *opaque, QEMUChrEvent event)
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
     case CHR_EVENT_CLOSED:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
index b238cb7937..98d2abbd56 100644
--- a/hw/usb/dev-serial.c
+++ b/hw/usb/dev-serial.c
@@ -576,6 +576,7 @@ static void usb_serial_event(void *opaque, QEMUChrEvent event)
         break;
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index fda5bbca67..34ab8339e1 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -1390,6 +1390,7 @@ static void usbredir_chardev_event(void *opaque, QEMUChrEvent event)
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/hw/virtio/vhost-user-base.c b/hw/virtio/vhost-user-base.c
index 01ab9ca56b..fd3a9d6265 100644
--- a/hw/virtio/vhost-user-base.c
+++ b/hw/virtio/vhost-user-base.c
@@ -267,6 +267,7 @@ static void vub_event(void *opaque, QEMUChrEvent event)
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/hw/virtio/vhost-user-scmi.c b/hw/virtio/vhost-user-scmi.c
index f9264c4374..180787ec6d 100644
--- a/hw/virtio/vhost-user-scmi.c
+++ b/hw/virtio/vhost-user-scmi.c
@@ -214,6 +214,7 @@ static void vu_scmi_event(void *opaque, QEMUChrEvent event)
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 237238e5a0..2c139f07dc 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -22,6 +22,12 @@ typedef enum {
     CHR_EVENT_OPENED, /* new connection established */
     CHR_EVENT_MUX_IN, /* mux-focus was set to this terminal */
     CHR_EVENT_MUX_OUT, /* mux-focus will move on */
+    CHR_EVENT_RESIZE, /*
+                       * the size of the terminal connected to
+                       * the chardev has changed.  NOTE: this event is only
+                       * sent to the focused frontend, so you should also
+                       * update the size on receiving CHR_EVENT_MUX_IN.
+                       */
     CHR_EVENT_CLOSED /* connection closed.  NOTE: currently this event
                       * is only bound to the read port of the chardev.
                       * Normally the read port and write port of a
diff --git a/monitor/hmp.c b/monitor/hmp.c
index 4caafbc714..dea912092d 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1445,6 +1445,7 @@ static void monitor_event(void *opaque, QEMUChrEvent event)
         break;
 
     case CHR_EVENT_BREAK:
+    case CHR_EVENT_RESIZE:
         /* Ignored */
         break;
     }
diff --git a/monitor/qmp.c b/monitor/qmp.c
index 687019811f..3d5ab8ff4f 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -486,6 +486,7 @@ static void monitor_qmp_event(void *opaque, QEMUChrEvent event)
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/net/passt.c b/net/passt.c
index 9ed811a514..a3e239f306 100644
--- a/net/passt.c
+++ b/net/passt.c
@@ -421,6 +421,7 @@ static void passt_vhost_user_event(void *opaque, QEMUChrEvent event)
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }
diff --git a/net/vhost-user.c b/net/vhost-user.c
index a4bb49bbcf..0b8df2ee30 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -367,6 +367,7 @@ static void net_vhost_user_event(void *opaque, QEMUChrEvent event)
     case CHR_EVENT_BREAK:
     case CHR_EVENT_MUX_IN:
     case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_RESIZE:
         /* Ignore */
         break;
     }

-- 
2.52.0



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 03/12] chardev: add qemu_chr_resize()
  2026-01-19  3:27 [PATCH v6 00/12] virtio-console: notify about the terminal size Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 01/12] chardev: add cols, rows fields Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 02/12] chardev: add CHR_EVENT_RESIZE Filip Hejsek
@ 2026-01-19  3:27 ` Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 04/12] char-mux: add support for the terminal size Filip Hejsek
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-19  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner, Szymon Lukasz

From: Szymon Lukasz <noh4hss@gmail.com>

This function should be called whenever we learn about a new size of
the terminal connected to a chardev.

Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
---
 chardev/char.c         | 11 +++++++++++
 include/chardev/char.h |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/chardev/char.c b/chardev/char.c
index 0f493d793f..f3c6a12c99 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -351,6 +351,17 @@ int qemu_chr_wait_connected(Chardev *chr, Error **errp)
     return 0;
 }
 
+void qemu_chr_resize(Chardev *chr, uint16_t cols, uint16_t rows)
+{
+    if (cols != chr->cols || rows != chr->rows) {
+        chr->cols = cols;
+        chr->rows = rows;
+        if (chr->be_open) {
+            qemu_chr_be_event(chr, CHR_EVENT_RESIZE);
+        }
+    }
+}
+
 QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename,
                                 bool permit_mux_mon)
 {
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 2c139f07dc..8e998ed3c1 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -234,6 +234,8 @@ int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all);
 #define qemu_chr_write_all(s, buf, len) qemu_chr_write(s, buf, len, true)
 int qemu_chr_wait_connected(Chardev *chr, Error **errp);
 
+void qemu_chr_resize(Chardev *chr, uint16_t cols, uint16_t rows);
+
 #define TYPE_CHARDEV "chardev"
 OBJECT_DECLARE_TYPE(Chardev, ChardevClass, CHARDEV)
 

-- 
2.52.0



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 04/12] char-mux: add support for the terminal size
  2026-01-19  3:27 [PATCH v6 00/12] virtio-console: notify about the terminal size Filip Hejsek
                   ` (2 preceding siblings ...)
  2026-01-19  3:27 ` [PATCH v6 03/12] chardev: add qemu_chr_resize() Filip Hejsek
@ 2026-01-19  3:27 ` Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 05/12] main-loop: change the handling of SIGWINCH Filip Hejsek
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-19  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner, Szymon Lukasz

From: Szymon Lukasz <noh4hss@gmail.com>

The terminal size of a mux chardev should be the same as the real
chardev, so listen for CHR_EVENT_RESIZE to be up to date.

We forward CHR_EVENT_RESIZE only to the focused frontend. This means
frontends should update their view of the terminal size on
receiving CHR_EVENT_MUX_IN.

Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
---
 chardev/char-mux.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/chardev/char-mux.c b/chardev/char-mux.c
index db9e89f441..b23fedbcfe 100644
--- a/chardev/char-mux.c
+++ b/chardev/char-mux.c
@@ -264,9 +264,24 @@ void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event)
     }
 }
 
+static void mux_update_winsize(Chardev *chr)
+{
+    MuxChardev *d = MUX_CHARDEV(chr);
+    uint16_t cols, rows;
+
+    qemu_chr_fe_get_winsize(&d->chr, &cols, &rows);
+    qemu_chr_resize(chr, cols, rows);
+}
+
 static void mux_chr_event(void *opaque, QEMUChrEvent event)
 {
-    mux_chr_send_all_event(CHARDEV(opaque), event);
+    Chardev *chr = CHARDEV(opaque);
+
+    if (event == CHR_EVENT_RESIZE) {
+        mux_update_winsize(chr);
+    } else {
+        mux_chr_send_all_event(chr, event);
+    }
 }
 
 static GSource *mux_chr_add_watch(Chardev *s, GIOCondition cond)
@@ -382,6 +397,7 @@ static void qemu_chr_open_mux(Chardev *chr,
      */
     *be_opened = muxes_opened;
     qemu_chr_fe_init(&d->chr, drv, errp);
+    mux_update_winsize(chr);
 }
 
 static void qemu_chr_parse_mux(QemuOpts *opts, ChardevBackend *backend,

-- 
2.52.0



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 05/12] main-loop: change the handling of SIGWINCH
  2026-01-19  3:27 [PATCH v6 00/12] virtio-console: notify about the terminal size Filip Hejsek
                   ` (3 preceding siblings ...)
  2026-01-19  3:27 ` [PATCH v6 04/12] char-mux: add support for the terminal size Filip Hejsek
@ 2026-01-19  3:27 ` Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 06/12] char-stdio: add support for the terminal size Filip Hejsek
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-19  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner, Szymon Lukasz

From: Szymon Lukasz <noh4hss@gmail.com>

Block SIGWINCH, so it is delivered only via signalfd.
Install a handler that uses NotifierList to tell
interested parties about SIGWINCH delivery.

Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
---
 include/qemu/main-loop.h |  4 ++++
 ui/curses.c              | 11 ++++++-----
 util/main-loop.c         | 21 +++++++++++++++++++++
 3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
index 8c1241a2c1..ff41346b0b 100644
--- a/include/qemu/main-loop.h
+++ b/include/qemu/main-loop.h
@@ -449,4 +449,8 @@ typedef struct MainLoopPoll {
 void main_loop_poll_add_notifier(Notifier *notify);
 void main_loop_poll_remove_notifier(Notifier *notify);
 
+#ifndef _WIN32
+void sigwinch_add_notifier(Notifier *n);
+#endif
+
 #endif
diff --git a/ui/curses.c b/ui/curses.c
index 161f78c35c..d1b308d5f8 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -33,6 +33,7 @@
 #include <iconv.h>
 
 #include "qapi/error.h"
+#include "qemu/main-loop.h"
 #include "qemu/module.h"
 #include "ui/console.h"
 #include "ui/input.h"
@@ -149,7 +150,7 @@ static void curses_resize(DisplayChangeListener *dcl,
 }
 
 #if !defined(_WIN32) && defined(SIGWINCH) && defined(KEY_RESIZE)
-static volatile sig_atomic_t got_sigwinch;
+static bool got_sigwinch;
 static void curses_winch_check(void)
 {
     struct winsize {
@@ -172,17 +173,17 @@ static void curses_winch_check(void)
     invalidate = 1;
 }
 
-static void curses_winch_handler(int signum)
+static void curses_winch_handler(Notifier *n, void *data)
 {
     got_sigwinch = true;
 }
 
 static void curses_winch_init(void)
 {
-    struct sigaction old, winch = {
-        .sa_handler  = curses_winch_handler,
+    static Notifier n = {
+        .notify = curses_winch_handler
     };
-    sigaction(SIGWINCH, &winch, &old);
+    sigwinch_add_notifier(&n);
 }
 #else
 static void curses_winch_check(void) {}
diff --git a/util/main-loop.c b/util/main-loop.c
index ad8645c30a..136886e4ee 100644
--- a/util/main-loop.c
+++ b/util/main-loop.c
@@ -100,6 +100,7 @@ static int qemu_signal_init(Error **errp)
     sigaddset(&set, SIGIO);
     sigaddset(&set, SIGALRM);
     sigaddset(&set, SIGBUS);
+    sigaddset(&set, SIGWINCH);
     /* SIGINT cannot be handled via signalfd, so that ^C can be used
      * to interrupt QEMU when it is being run under gdb.  SIGHUP and
      * SIGTERM are also handled asynchronously, even though it is not
@@ -124,6 +125,26 @@ static int qemu_signal_init(Error **errp)
     return 0;
 }
 
+static NotifierList sigwinch_notifiers =
+    NOTIFIER_LIST_INITIALIZER(sigwinch_notifiers);
+
+static void sigwinch_handler(int signum)
+{
+    notifier_list_notify(&sigwinch_notifiers, NULL);
+}
+
+void sigwinch_add_notifier(Notifier *n)
+{
+    if (notifier_list_empty(&sigwinch_notifiers)) {
+        struct sigaction action = {
+            .sa_handler = sigwinch_handler,
+        };
+        sigaction(SIGWINCH, &action, NULL);
+    }
+
+    notifier_list_add(&sigwinch_notifiers, n);
+}
+
 #else /* _WIN32 */
 
 static int qemu_signal_init(Error **errp)

-- 
2.52.0



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 06/12] char-stdio: add support for the terminal size
  2026-01-19  3:27 [PATCH v6 00/12] virtio-console: notify about the terminal size Filip Hejsek
                   ` (4 preceding siblings ...)
  2026-01-19  3:27 ` [PATCH v6 05/12] main-loop: change the handling of SIGWINCH Filip Hejsek
@ 2026-01-19  3:27 ` Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 07/12] qmp: add chardev-window-size-changed command Filip Hejsek
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-19  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner, Szymon Lukasz

From: Szymon Lukasz <noh4hss@gmail.com>

Update the terminal size upon SIGWINCH delivery.

Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
[Filip: use DECLARE_INSTANCE_CHECKER]
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
---
 chardev/char-stdio.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c
index 2568164a10..f55a7be24b 100644
--- a/chardev/char-stdio.c
+++ b/chardev/char-stdio.c
@@ -34,7 +34,9 @@
 #include "chardev/char-win-stdio.h"
 #else
 #include <termios.h>
+#include <sys/ioctl.h>
 #include "chardev/char-fd.h"
+#include "qemu/main-loop.h"
 #endif
 
 #ifndef _WIN32
@@ -46,6 +48,14 @@ static bool stdio_in_use;
 static bool stdio_allow_signal;
 static bool stdio_echo_state;
 
+typedef struct {
+    FDChardev parent;
+    Notifier resize_notifier;
+} StdioChardev;
+
+DECLARE_INSTANCE_CHECKER(StdioChardev, STDIO_CHARDEV,
+                         TYPE_CHARDEV_STDIO)
+
 static void term_exit(void)
 {
     if (stdio_in_use) {
@@ -85,11 +95,26 @@ static void term_stdio_handler(int sig)
     qemu_chr_set_echo_stdio(NULL, stdio_echo_state);
 }
 
+static void qemu_chr_resize_stdio(Chardev *chr)
+{
+    struct winsize ws;
+    if (ioctl(1, TIOCGWINSZ, &ws) != -1) {
+        qemu_chr_resize(chr, ws.ws_col, ws.ws_row);
+    }
+}
+
+static void term_resize_notify(Notifier *n, void *data)
+{
+    StdioChardev *s = container_of(n, StdioChardev, resize_notifier);
+    qemu_chr_resize_stdio(CHARDEV(s));
+}
+
 static void qemu_chr_open_stdio(Chardev *chr,
                                 ChardevBackend *backend,
                                 bool *be_opened,
                                 Error **errp)
 {
+    StdioChardev *s = STDIO_CHARDEV(chr);
     ChardevStdio *opts = backend->u.stdio.data;
     struct sigaction act;
 
@@ -123,6 +148,10 @@ static void qemu_chr_open_stdio(Chardev *chr,
 
     stdio_allow_signal = !opts->has_signal || opts->signal;
     qemu_chr_set_echo_stdio(chr, false);
+
+    qemu_chr_resize_stdio(chr);
+    s->resize_notifier.notify = term_resize_notify;
+    sigwinch_add_notifier(&s->resize_notifier);
 }
 #endif
 
@@ -162,6 +191,7 @@ static const TypeInfo char_stdio_type_info = {
     .parent = TYPE_CHARDEV_WIN_STDIO,
 #else
     .parent = TYPE_CHARDEV_FD,
+    .instance_size = sizeof(StdioChardev),
 #endif
     .instance_finalize = char_stdio_finalize,
     .class_init = char_stdio_class_init,

-- 
2.52.0



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 07/12] qmp: add chardev-window-size-changed command
  2026-01-19  3:27 [PATCH v6 00/12] virtio-console: notify about the terminal size Filip Hejsek
                   ` (5 preceding siblings ...)
  2026-01-19  3:27 ` [PATCH v6 06/12] char-stdio: add support for the terminal size Filip Hejsek
@ 2026-01-19  3:27 ` Filip Hejsek
  2026-01-19  6:47   ` Markus Armbruster
  2026-01-19  3:27 ` [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages Filip Hejsek
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 30+ messages in thread
From: Filip Hejsek @ 2026-01-19  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner, Szymon Lukasz

From: Szymon Lukasz <noh4hss@gmail.com>

The managment software can use this command to notify QEMU about the
size of the terminal connected to a chardev, QEMU can then forward this
information to the guest if the chardev is connected to a virtio console
device.

Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
[Filip: rename command, change documentation]
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Acked-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
---
 chardev/char.c | 14 ++++++++++++++
 qapi/char.json | 31 +++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/chardev/char.c b/chardev/char.c
index f3c6a12c99..458059a9e0 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -1266,6 +1266,20 @@ bool qmp_add_client_char(int fd, bool has_skipauth, bool skipauth,
     return true;
 }
 
+void qmp_chardev_window_size_changed(const char *id, uint16_t cols,
+                                     uint16_t rows, Error **errp)
+{
+    Chardev *chr;
+
+    chr = qemu_chr_find(id);
+    if (chr == NULL) {
+        error_setg(errp, "Chardev '%s' not found", id);
+        return;
+    }
+
+    qemu_chr_resize(chr, cols, rows);
+}
+
 /*
  * Add a timeout callback for the chardev (in milliseconds), return
  * the GSource object created. Please use this to add timeout hook for
diff --git a/qapi/char.json b/qapi/char.json
index 140614f82c..bc08f0161a 100644
--- a/qapi/char.json
+++ b/qapi/char.json
@@ -861,6 +861,37 @@
 { 'command': 'chardev-send-break',
   'data': { 'id': 'str' } }
 
+##
+# @chardev-window-size-changed:
+#
+# Notifies a chardev about the current size of the terminal connected
+# to this chardev.  The information will be forwarded to the guest if
+# the chardev is connected to a virtio console device.
+#
+# The initial size is 0x0, which should be interpreted as an unknown
+# size.
+#
+# Some backends detect the terminal size automatically, in which case
+# the size may unpredictably revert to the detected one at any time.
+#
+# @id: the chardev's ID, must exist
+#
+# @cols: the number of columns
+#
+# @rows: the number of rows
+#
+# Since: 11.0
+#
+# .. qmp-example::
+#
+#     -> { "execute": "chardev-window-size-changed", "arguments": { "id": "foo", "cols": 80, "rows": 24 } }
+#     <- { "return": {} }
+##
+{ 'command': 'chardev-window-size-changed',
+  'data': { 'id': 'str',
+            'cols': 'uint16',
+            'rows': 'uint16' } }
+
 ##
 # @VSERPORT_CHANGE:
 #

-- 
2.52.0



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-19  3:27 [PATCH v6 00/12] virtio-console: notify about the terminal size Filip Hejsek
                   ` (6 preceding siblings ...)
  2026-01-19  3:27 ` [PATCH v6 07/12] qmp: add chardev-window-size-changed command Filip Hejsek
@ 2026-01-19  3:27 ` Filip Hejsek
  2026-01-19  9:38   ` Daniel P. Berrangé
  2026-01-20  9:50   ` Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 09/12] virtio-console: notify the guest about terminal resizes Filip Hejsek
                   ` (3 subsequent siblings)
  11 siblings, 2 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-19  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner, Szymon Lukasz

Implement the part of the virtio spec that allows to notify the virtio
driver about terminal resizes. The virtio spec contains two methods to
achieve that:

For legacy drivers, we have only one port and we put the terminal size
in the config space and inject the config changed interrupt.

For multiport devices, we use the control virtqueue to send a packet
containing the terminal size. Note that old versions of the Linux kernel
used an incorrect order for the fields (rows then cols instead of cols
then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.

As a result, when using a Linux kernel older than 6.15, the number of rows
and columns will be swapped.

Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
but partially rewritten to fix various corner cases.

Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
---
 hw/char/trace-events              |  1 +
 hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
 hw/core/machine.c                 |  4 ++-
 include/hw/virtio/virtio-serial.h |  5 +++
 4 files changed, 83 insertions(+), 3 deletions(-)

diff --git a/hw/char/trace-events b/hw/char/trace-events
index 9e74be2c14..2416d4d04e 100644
--- a/hw/char/trace-events
+++ b/hw/char/trace-events
@@ -11,6 +11,7 @@ serial_update_parameters(uint64_t baudrate, char parity, int data_bits, int stop
 
 # virtio-serial-bus.c
 virtio_serial_send_control_event(unsigned int port, uint16_t event, uint16_t value) "port %u, event %u, value %u"
+virtio_serial_send_console_resize(unsigned int port, uint16_t cols, uint16_t rows) "port %u, cols %u, rows %u"
 virtio_serial_throttle_port(unsigned int port, bool throttle) "port %u, throttle %d"
 virtio_serial_handle_control_message(uint16_t event, uint16_t value) "event %u, value %u"
 virtio_serial_handle_control_message_port(unsigned int port) "port %u"
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 5ec5f5313b..6348eef3a2 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -260,6 +260,68 @@ static size_t send_control_event(VirtIOSerial *vser, uint32_t port_id,
     return send_control_msg(vser, &cpkt, sizeof(cpkt));
 }
 
+/*
+ * This struct should be added to the Linux kernel uapi headers
+ * and later imported to standard-headers/linux/virtio_console.h
+ */
+struct virtio_console_resize {
+    __virtio16 cols;
+    __virtio16 rows;
+};
+
+static void send_console_resize(VirtIOSerialPort *port)
+{
+    VirtIOSerial *vser = port->vser;
+    VirtIODevice *vdev = VIRTIO_DEVICE(vser);
+
+    if (!virtio_has_feature(vser->host_features, VIRTIO_CONSOLE_F_SIZE)) {
+        return;
+    }
+
+    trace_virtio_serial_send_console_resize(port->id, port->cols, port->rows);
+
+    if (use_multiport(vser)) {
+        struct {
+            struct virtio_console_control control;
+            struct virtio_console_resize resize;
+        } buffer;
+
+        virtio_stl_p(vdev, &buffer.control.id, port->id);
+        virtio_stw_p(vdev, &buffer.control.event, VIRTIO_CONSOLE_RESIZE);
+        virtio_stw_p(vdev, &buffer.resize.cols, port->cols);
+        virtio_stw_p(vdev, &buffer.resize.rows, port->rows);
+
+        send_control_msg(vser, &buffer, sizeof(buffer));
+    }
+}
+
+void virtio_serial_resize_console(VirtIOSerialPort *port,
+                                  uint16_t cols, uint16_t rows)
+{
+    VirtIOSerial *vser = port->vser;
+    VirtIODevice *vdev = VIRTIO_DEVICE(vser);
+
+    if (port->cols == cols && port->rows == rows) {
+        return;
+    }
+
+    port->cols = cols;
+    port->rows = rows;
+
+    if (port->id == 0 && !use_multiport(vser) &&
+        virtio_vdev_has_feature(vdev, VIRTIO_CONSOLE_F_SIZE)) {
+        virtio_notify_config(vdev);
+    }
+
+    /*
+     * We will send these messages even before we told the guest that
+     * it is a console port (by sending VIRTIO_CONSOLE_CONSOLE_PORT
+     * message), but that should be fine as the guest will likely
+     * ignore them.
+     */
+    send_console_resize(port);
+}
+
 /* Functions for use inside qemu to open and read from/write to ports */
 int virtio_serial_open(VirtIOSerialPort *port)
 {
@@ -408,6 +470,7 @@ static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
          */
         if (vsc->is_console) {
             send_control_event(vser, port->id, VIRTIO_CONSOLE_CONSOLE_PORT, 1);
+            send_console_resize(port);
         }
 
         if (port->name) {
@@ -568,11 +631,18 @@ static uint64_t get_features(VirtIODevice *vdev, uint64_t features,
 static void get_config(VirtIODevice *vdev, uint8_t *config_data)
 {
     VirtIOSerial *vser = VIRTIO_SERIAL(vdev);
+    VirtIOSerialPort *port;
     struct virtio_console_config *config =
         (struct virtio_console_config *)config_data;
 
-    config->cols = 0;
-    config->rows = 0;
+    port = find_port_by_id(vser, 0);
+    if (port) {
+        config->cols = virtio_tswap16(vdev, port->cols);
+        config->rows = virtio_tswap16(vdev, port->rows);
+    } else {
+        config->cols = 0;
+        config->rows = 0;
+    }
     config->max_nr_ports = virtio_tswap32(vdev,
                                           vser->serial.max_virtserial_ports);
 }
@@ -1158,6 +1228,8 @@ static const Property virtio_serial_properties[] = {
                                                   31),
     DEFINE_PROP_BIT64("emergency-write", VirtIOSerial, host_features,
                       VIRTIO_CONSOLE_F_EMERG_WRITE, true),
+    DEFINE_PROP_BIT64("console-size", VirtIOSerial, host_features,
+                      VIRTIO_CONSOLE_F_SIZE, true),
 };
 
 static void virtio_serial_class_init(ObjectClass *klass, const void *data)
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 6411e68856..50554b8900 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -38,7 +38,9 @@
 #include "hw/acpi/generic_event_device.h"
 #include "qemu/audio.h"
 
-GlobalProperty hw_compat_10_2[] = {};
+GlobalProperty hw_compat_10_2[] = {
+    { "virtio-serial-device", "console-size", "off" },
+};
 const size_t hw_compat_10_2_len = G_N_ELEMENTS(hw_compat_10_2);
 
 GlobalProperty hw_compat_10_1[] = {
diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
index 60641860bf..bda6d5312a 100644
--- a/include/hw/virtio/virtio-serial.h
+++ b/include/hw/virtio/virtio-serial.h
@@ -145,6 +145,9 @@ struct VirtIOSerialPort {
     bool host_connected;
     /* Do apps not want to receive data? */
     bool throttled;
+
+    /* Terminal size reported to the guest.  Only used for consoles. */
+    uint16_t cols, rows;
 };
 
 /* The virtio-serial bus on top of which the ports will ride as devices */
@@ -222,5 +225,7 @@ size_t virtio_serial_guest_ready(VirtIOSerialPort *port);
  */
 void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle);
 
+void virtio_serial_resize_console(VirtIOSerialPort *port,
+                                  uint16_t cols, uint16_t rows);
 
 #endif

-- 
2.52.0



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 09/12] virtio-console: notify the guest about terminal resizes
  2026-01-19  3:27 [PATCH v6 00/12] virtio-console: notify about the terminal size Filip Hejsek
                   ` (7 preceding siblings ...)
  2026-01-19  3:27 ` [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages Filip Hejsek
@ 2026-01-19  3:27 ` Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 10/12] char-win-stdio: add support for terminal size Filip Hejsek
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-19  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner, Szymon Lukasz

From: Szymon Lukasz <noh4hss@gmail.com>

If a virtio serial port is a console port, forward terminal resize
messages from the chardev backend to the guest.

Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
[Filip: rename things, remove logic that is now handled in virtio-serial-bus.c]
Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
---
 hw/char/virtio-console.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c
index dcfe5830f9..de7979c2d3 100644
--- a/hw/char/virtio-console.c
+++ b/hw/char/virtio-console.c
@@ -107,6 +107,15 @@ static ssize_t flush_buf(VirtIOSerialPort *port,
     return ret;
 }
 
+static void virtconsole_update_size(VirtIOSerialPort *port)
+{
+    uint16_t cols, rows;
+    VirtConsole *vcon = VIRTIO_CONSOLE(port);
+
+    qemu_chr_fe_get_winsize(&vcon->chr, &cols, &rows);
+    virtio_serial_resize_console(port, cols, rows);
+}
+
 /* Callback function that's called when the guest opens/closes the port */
 static void set_guest_connected(VirtIOSerialPort *port, int guest_connected)
 {
@@ -174,6 +183,23 @@ static void chr_event(void *opaque, QEMUChrEvent event)
     }
 }
 
+static void chr_event_console(void *opaque, QEMUChrEvent event)
+{
+    VirtConsole *vcon = opaque;
+    VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(vcon);
+
+    trace_virtio_console_chr_event(port->id, event);
+    switch (event) {
+    case CHR_EVENT_OPENED:
+    case CHR_EVENT_MUX_IN:
+    case CHR_EVENT_RESIZE:
+        virtconsole_update_size(port);
+        break;
+    default:
+        break;
+    }
+}
+
 static int chr_be_change(void *opaque)
 {
     VirtConsole *vcon = opaque;
@@ -182,7 +208,9 @@ static int chr_be_change(void *opaque)
 
     if (k->is_console) {
         qemu_chr_fe_set_handlers(&vcon->chr, chr_can_read, chr_read,
-                                 NULL, chr_be_change, vcon, NULL, true);
+                                 chr_event_console, chr_be_change,
+                                 vcon, NULL, true);
+        virtconsole_update_size(port);
     } else {
         qemu_chr_fe_set_handlers(&vcon->chr, chr_can_read, chr_read,
                                  chr_event, chr_be_change, vcon, NULL, false);
@@ -210,7 +238,7 @@ static void virtconsole_enable_backend(VirtIOSerialPort *port, bool enable)
         VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(port);
 
         qemu_chr_fe_set_handlers(&vcon->chr, chr_can_read, chr_read,
-                                 k->is_console ? NULL : chr_event,
+                                 k->is_console ? chr_event_console : chr_event,
                                  chr_be_change, vcon, NULL, false);
     } else {
         qemu_chr_fe_set_handlers(&vcon->chr, NULL, NULL, NULL,
@@ -242,7 +270,7 @@ static void virtconsole_realize(DeviceState *dev, Error **errp)
          */
         if (k->is_console) {
             qemu_chr_fe_set_handlers(&vcon->chr, chr_can_read, chr_read,
-                                     NULL, chr_be_change,
+                                     chr_event_console, chr_be_change,
                                      vcon, NULL, true);
             virtio_serial_open(port);
         } else {

-- 
2.52.0



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 10/12] char-win-stdio: add support for terminal size
  2026-01-19  3:27 [PATCH v6 00/12] virtio-console: notify about the terminal size Filip Hejsek
                   ` (8 preceding siblings ...)
  2026-01-19  3:27 ` [PATCH v6 09/12] virtio-console: notify the guest about terminal resizes Filip Hejsek
@ 2026-01-19  3:27 ` Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 11/12] ui/console-vc: forward text console size to vc chardev Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 12/12] ui/gtk: forward gtk " Filip Hejsek
  11 siblings, 0 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-19  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner

Use GetConsoleScreenBufferInfo to obtain terminal size
and set ENABLE_WINDOW_INPUT to receive resize notifications.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
---
 chardev/char-win-stdio.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/chardev/char-win-stdio.c b/chardev/char-win-stdio.c
index fb802a00b1..0d33138d0d 100644
--- a/chardev/char-win-stdio.c
+++ b/chardev/char-win-stdio.c
@@ -44,6 +44,20 @@ typedef struct WinStdioChardev WinStdioChardev;
 DECLARE_INSTANCE_CHECKER(WinStdioChardev, WIN_STDIO_CHARDEV,
                          TYPE_CHARDEV_WIN_STDIO)
 
+static void char_win_stdio_resize(Chardev *chr)
+{
+    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
+    CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo;
+
+    if (GetConsoleScreenBufferInfo(hStdOut, &ScreenBufferInfo)) {
+        uint16_t cols = ScreenBufferInfo.srWindow.Right + 1
+                        - ScreenBufferInfo.srWindow.Left;
+        uint16_t rows = ScreenBufferInfo.srWindow.Bottom + 1
+                        - ScreenBufferInfo.srWindow.Top;
+        qemu_chr_resize(chr, cols, rows);
+    }
+}
+
 static void win_stdio_wait_func(void *opaque)
 {
     Chardev *chr = CHARDEV(opaque);
@@ -75,6 +89,9 @@ static void win_stdio_wait_func(void *opaque)
                 }
             }
         }
+        if (buf[i].EventType == WINDOW_BUFFER_SIZE_EVENT) {
+            char_win_stdio_resize(chr);
+        }
     }
 }
 
@@ -202,6 +219,8 @@ static void qemu_chr_open_stdio(Chardev *chr,
         } else {
             dwMode &= ~ENABLE_PROCESSED_INPUT;
         }
+        dwMode |= ENABLE_WINDOW_INPUT;
+        char_win_stdio_resize(chr);
     }
 
     SetConsoleMode(stdio->hStdIn, dwMode);

-- 
2.52.0



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 11/12] ui/console-vc: forward text console size to vc chardev
  2026-01-19  3:27 [PATCH v6 00/12] virtio-console: notify about the terminal size Filip Hejsek
                   ` (9 preceding siblings ...)
  2026-01-19  3:27 ` [PATCH v6 10/12] char-win-stdio: add support for terminal size Filip Hejsek
@ 2026-01-19  3:27 ` Filip Hejsek
  2026-01-19  3:27 ` [PATCH v6 12/12] ui/gtk: forward gtk " Filip Hejsek
  11 siblings, 0 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-19  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner

Update the vc chardev size when the size of a text console is recomputed.

NOTE: It seems wrong that the dpy_text_resize callback is not called
      when the size is recomputed. I believe this is a bug, although it
      doesn't matter much because the only user of the callback is
      ui/ncurses and it only uses the size of fixed consoles.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
---
 ui/console-vc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/ui/console-vc.c b/ui/console-vc.c
index 830842064d..a3a90440d5 100644
--- a/ui/console-vc.c
+++ b/ui/console-vc.c
@@ -414,6 +414,9 @@ static void text_console_resize(QemuTextConsole *t)
     }
     g_free(t->cells);
     t->cells = cells;
+
+    /* XXX Shouldn't qemu_text_console_update_size() also be called here? */
+    qemu_chr_resize(t->chr, t->width, t->height);
 }
 
 static void vc_put_lf(VCChardev *vc)

-- 
2.52.0



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 12/12] ui/gtk: forward gtk console size to vc chardev
  2026-01-19  3:27 [PATCH v6 00/12] virtio-console: notify about the terminal size Filip Hejsek
                   ` (10 preceding siblings ...)
  2026-01-19  3:27 ` [PATCH v6 11/12] ui/console-vc: forward text console size to vc chardev Filip Hejsek
@ 2026-01-19  3:27 ` Filip Hejsek
  11 siblings, 0 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-19  3:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner

Query the terminal size from the vte library when creating the console
and every time it might change. Vte doesn't send any signal specifically
for terminal size changes, so instead we register callbacks for
size-allocate and char-size-changed.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
---
 ui/gtk.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/ui/gtk.c b/ui/gtk.c
index e83a366625..471528362f 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2029,6 +2029,28 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size,
     return TRUE;
 }
 
+static void gd_vc_vte_update_size(VirtualConsole *vc)
+{
+    uint16_t cols, rows;
+    cols = vte_terminal_get_column_count(VTE_TERMINAL(vc->vte.terminal));
+    rows = vte_terminal_get_row_count(VTE_TERMINAL(vc->vte.terminal));
+    qemu_chr_resize(vc->vte.chr, cols, rows);
+}
+
+static void gd_vc_size_allocate(VteTerminal *terminal,
+                                GtkAllocation *allocation, gpointer user_data)
+{
+    VirtualConsole *vc = user_data;
+    gd_vc_vte_update_size(vc);
+}
+
+static void gd_vc_char_size_changed(VteTerminal *terminal, guint width,
+                                    guint height, gpointer user_data)
+{
+    VirtualConsole *vc = user_data;
+    gd_vc_vte_update_size(vc);
+}
+
 static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc,
                               Chardev *chr, int idx,
                               GSList *group, GtkWidget *view_menu)
@@ -2094,6 +2116,12 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc,
 
     qemu_chr_be_event(vc->vte.chr, CHR_EVENT_OPENED);
 
+    g_signal_connect(vc->vte.terminal, "size-allocate",
+                     G_CALLBACK(gd_vc_size_allocate), vc);
+    g_signal_connect(vc->vte.terminal, "char-size-changed",
+                     G_CALLBACK(gd_vc_char_size_changed), vc);
+    gd_vc_vte_update_size(vc);
+
     return group;
 }
 

-- 
2.52.0



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 07/12] qmp: add chardev-window-size-changed command
  2026-01-19  3:27 ` [PATCH v6 07/12] qmp: add chardev-window-size-changed command Filip Hejsek
@ 2026-01-19  6:47   ` Markus Armbruster
  2026-01-20  8:04     ` Filip Hejsek
  0 siblings, 1 reply; 30+ messages in thread
From: Markus Armbruster @ 2026-01-19  6:47 UTC (permalink / raw)
  To: Filip Hejsek
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Michael S. Tsirkin, Laurent Vivier, Amit Shah, Markus Armbruster,
	Eric Blake, Eduardo Habkost, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Yanan Wang, Zhao Liu,
	Daniel P. Berrangé, Maximilian Immanuel Brandtner,
	Szymon Lukasz

Filip Hejsek <filip.hejsek@gmail.com> writes:

> From: Szymon Lukasz <noh4hss@gmail.com>
>
> The managment software can use this command to notify QEMU about the
> size of the terminal connected to a chardev, QEMU can then forward this
> information to the guest if the chardev is connected to a virtio console
> device.
>
> Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> [Filip: rename command, change documentation]
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> Acked-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>

[...]

> diff --git a/qapi/char.json b/qapi/char.json
> index 140614f82c..bc08f0161a 100644
> --- a/qapi/char.json
> +++ b/qapi/char.json
> @@ -861,6 +861,37 @@
>  { 'command': 'chardev-send-break',
>    'data': { 'id': 'str' } }
>  
> +##
> +# @chardev-window-size-changed:
> +#
> +# Notifies a chardev about the current size of the terminal connected
> +# to this chardev.  The information will be forwarded to the guest if
> +# the chardev is connected to a virtio console device.
> +#
> +# The initial size is 0x0, which should be interpreted as an unknown
> +# size.
> +#
> +# Some backends detect the terminal size automatically, in which case
> +# the size may unpredictably revert to the detected one at any time.
> +#
> +# @id: the chardev's ID, must exist

Please drop ", must exist" for consistency with ID descriptions
elsewhere.

> +#
> +# @cols: the number of columns
> +#
> +# @rows: the number of rows
> +#
> +# Since: 11.0
> +#
> +# .. qmp-example::
> +#
> +#     -> { "execute": "chardev-window-size-changed", "arguments": { "id": "foo", "cols": 80, "rows": 24 } }
> +#     <- { "return": {} }
> +##
> +{ 'command': 'chardev-window-size-changed',
> +  'data': { 'id': 'str',
> +            'cols': 'uint16',
> +            'rows': 'uint16' } }
> +
>  ##
>  # @VSERPORT_CHANGE:
>  #



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-19  3:27 ` [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages Filip Hejsek
@ 2026-01-19  9:38   ` Daniel P. Berrangé
  2026-01-19  9:43     ` Michael S. Tsirkin
  2026-01-20  9:50   ` Filip Hejsek
  1 sibling, 1 reply; 30+ messages in thread
From: Daniel P. Berrangé @ 2026-01-19  9:38 UTC (permalink / raw)
  To: Filip Hejsek
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Michael S. Tsirkin, Laurent Vivier, Amit Shah, Markus Armbruster,
	Eric Blake, Eduardo Habkost, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Yanan Wang, Zhao Liu,
	Maximilian Immanuel Brandtner, Szymon Lukasz

On Mon, Jan 19, 2026 at 04:27:51AM +0100, Filip Hejsek wrote:
> Implement the part of the virtio spec that allows to notify the virtio
> driver about terminal resizes. The virtio spec contains two methods to
> achieve that:
> 
> For legacy drivers, we have only one port and we put the terminal size
> in the config space and inject the config changed interrupt.
> 
> For multiport devices, we use the control virtqueue to send a packet
> containing the terminal size. Note that old versions of the Linux kernel
> used an incorrect order for the fields (rows then cols instead of cols
> then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> 
> As a result, when using a Linux kernel older than 6.15, the number of rows
> and columns will be swapped.
> 
> Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> but partially rewritten to fix various corner cases.
> 
> Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> ---
>  hw/char/trace-events              |  1 +
>  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
>  hw/core/machine.c                 |  4 ++-
>  include/hw/virtio/virtio-serial.h |  5 +++
>  4 files changed, 83 insertions(+), 3 deletions(-)
> 

> @@ -1158,6 +1228,8 @@ static const Property virtio_serial_properties[] = {
>                                                    31),
>      DEFINE_PROP_BIT64("emergency-write", VirtIOSerial, host_features,
>                        VIRTIO_CONSOLE_F_EMERG_WRITE, true),
> +    DEFINE_PROP_BIT64("console-size", VirtIOSerial, host_features,
> +                      VIRTIO_CONSOLE_F_SIZE, true),
>  };

Given the horrible mess with the kernel intentionally changing its
behaviour after 15 years, I don't think we can we set this to be
enabled by default.

The recent behaviour change is never going to be backported to enough
stable distros that we can rely on the new behaviour, and thanks to
the change we can't rely on the old behaviour either. We're doomed no
matter what ordernig we use.

Thus, IMHO, this has to stay set to false indefinitely.

>  static void virtio_serial_class_init(ObjectClass *klass, const void *data)
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index 6411e68856..50554b8900 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -38,7 +38,9 @@
>  #include "hw/acpi/generic_event_device.h"
>  #include "qemu/audio.h"
>  
> -GlobalProperty hw_compat_10_2[] = {};
> +GlobalProperty hw_compat_10_2[] = {
> +    { "virtio-serial-device", "console-size", "off" },
> +};
>  const size_t hw_compat_10_2_len = G_N_ELEMENTS(hw_compat_10_2);
>  
>  GlobalProperty hw_compat_10_1[] = {

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 :|



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-19  9:38   ` Daniel P. Berrangé
@ 2026-01-19  9:43     ` Michael S. Tsirkin
  2026-01-20  8:43       ` Daniel P. Berrangé
  0 siblings, 1 reply; 30+ messages in thread
From: Michael S. Tsirkin @ 2026-01-19  9:43 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Filip Hejsek, qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Maximilian Immanuel Brandtner,
	Szymon Lukasz

On Mon, Jan 19, 2026 at 09:38:41AM +0000, Daniel P. Berrangé wrote:
> On Mon, Jan 19, 2026 at 04:27:51AM +0100, Filip Hejsek wrote:
> > Implement the part of the virtio spec that allows to notify the virtio
> > driver about terminal resizes. The virtio spec contains two methods to
> > achieve that:
> > 
> > For legacy drivers, we have only one port and we put the terminal size
> > in the config space and inject the config changed interrupt.
> > 
> > For multiport devices, we use the control virtqueue to send a packet
> > containing the terminal size. Note that old versions of the Linux kernel
> > used an incorrect order for the fields (rows then cols instead of cols
> > then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> > 
> > As a result, when using a Linux kernel older than 6.15, the number of rows
> > and columns will be swapped.
> > 
> > Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> > but partially rewritten to fix various corner cases.
> > 
> > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> > ---
> >  hw/char/trace-events              |  1 +
> >  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
> >  hw/core/machine.c                 |  4 ++-
> >  include/hw/virtio/virtio-serial.h |  5 +++
> >  4 files changed, 83 insertions(+), 3 deletions(-)
> > 
> 
> > @@ -1158,6 +1228,8 @@ static const Property virtio_serial_properties[] = {
> >                                                    31),
> >      DEFINE_PROP_BIT64("emergency-write", VirtIOSerial, host_features,
> >                        VIRTIO_CONSOLE_F_EMERG_WRITE, true),
> > +    DEFINE_PROP_BIT64("console-size", VirtIOSerial, host_features,
> > +                      VIRTIO_CONSOLE_F_SIZE, true),
> >  };
> 
> Given the horrible mess with the kernel intentionally changing its
> behaviour after 15 years, I don't think we can we set this to be
> enabled by default.
> 
> The recent behaviour change is never going to be backported to enough
> stable distros that we can rely on the new behaviour, and thanks to
> the change we can't rely on the old behaviour either. We're doomed no
> matter what ordernig we use.
> 
> Thus, IMHO, this has to stay set to false indefinitely.

Not sure. But what we can do is add another flag to detect new kernels.
I'll try to think of a good name but suggestions are welcome.

> >  static void virtio_serial_class_init(ObjectClass *klass, const void *data)
> > diff --git a/hw/core/machine.c b/hw/core/machine.c
> > index 6411e68856..50554b8900 100644
> > --- a/hw/core/machine.c
> > +++ b/hw/core/machine.c
> > @@ -38,7 +38,9 @@
> >  #include "hw/acpi/generic_event_device.h"
> >  #include "qemu/audio.h"
> >  
> > -GlobalProperty hw_compat_10_2[] = {};
> > +GlobalProperty hw_compat_10_2[] = {
> > +    { "virtio-serial-device", "console-size", "off" },
> > +};
> >  const size_t hw_compat_10_2_len = G_N_ELEMENTS(hw_compat_10_2);
> >  
> >  GlobalProperty hw_compat_10_1[] = {
> 
> 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 :|



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 07/12] qmp: add chardev-window-size-changed command
  2026-01-19  6:47   ` Markus Armbruster
@ 2026-01-20  8:04     ` Filip Hejsek
  2026-01-20  8:18       ` [PATCH] qapi: drop "must exist" from ID descriptions for consistency Filip Hejsek
  0 siblings, 1 reply; 30+ messages in thread
From: Filip Hejsek @ 2026-01-20  8:04 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Michael S. Tsirkin, Laurent Vivier, Amit Shah, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P.Berrangé,
	Maximilian Immanuel Brandtner, Szymon Lukasz

On Mon, 2026-01-19 at 07:47 +0100, Markus Armbruster wrote:
> Filip Hejsek <filip.hejsek@gmail.com> writes:
> 
> > From: Szymon Lukasz <noh4hss@gmail.com>
> > 
> > The managment software can use this command to notify QEMU about the
> > size of the terminal connected to a chardev, QEMU can then forward this
> > information to the guest if the chardev is connected to a virtio console
> > device.
> > 
> > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> > [Filip: rename command, change documentation]
> > Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> > Acked-by: Markus Armbruster <armbru@redhat.com>
> > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> 
> [...]
> 
> > diff --git a/qapi/char.json b/qapi/char.json
> > index 140614f82c..bc08f0161a 100644
> > --- a/qapi/char.json
> > +++ b/qapi/char.json
> > @@ -861,6 +861,37 @@
> >  { 'command': 'chardev-send-break',
> >    'data': { 'id': 'str' } }
> >  
> > +##
> > +# @chardev-window-size-changed:
> > +#
> > +# Notifies a chardev about the current size of the terminal connected
> > +# to this chardev.  The information will be forwarded to the guest if
> > +# the chardev is connected to a virtio console device.
> > +#
> > +# The initial size is 0x0, which should be interpreted as an unknown
> > +# size.
> > +#
> > +# Some backends detect the terminal size automatically, in which case
> > +# the size may unpredictably revert to the detected one at any time.
> > +#
> > +# @id: the chardev's ID, must exist
> 
> Please drop ", must exist" for consistency with ID descriptions
> elsewhere.
> 

On Mon, 2025-09-22 at 11:38 +0200, Markus Armbruster wrote:
> [...]
> >> Let's drop ", must exist" for consistency with ID descriptions
> >> elsewhere.
> >
> > All chardev @id parameters in qapi/char.json have ", must exist"
> > (although you're right that nothing else has it).
> 
> Right.  Feel free to stay locally consistent then.

I'll drop it in next version, but all the other instances should be
dropped too.

> > +#
> > +# @cols: the number of columns
> > +#
> > +# @rows: the number of rows
> > +#
> > +# Since: 11.0
> > +#
> > +# .. qmp-example::
> > +#
> > +#     -> { "execute": "chardev-window-size-changed", "arguments": { "id": "foo", "cols": 80, "rows": 24 } }
> > +#     <- { "return": {} }
> > +##
> > +{ 'command': 'chardev-window-size-changed',
> > +  'data': { 'id': 'str',
> > +            'cols': 'uint16',
> > +            'rows': 'uint16' } }
> > +
> >  ##
> >  # @VSERPORT_CHANGE:
> >  #


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH] qapi: drop "must exist" from ID descriptions for consistency
  2026-01-20  8:04     ` Filip Hejsek
@ 2026-01-20  8:18       ` Filip Hejsek
  0 siblings, 0 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-20  8:18 UTC (permalink / raw)
  To: armbru
  Cc: amit, berrange, eblake, eduardo, lvivier, marcandre.lureau,
	marcel.apfelbaum, maxbr, mst, noh4hss, pbonzini, philmd,
	qemu-devel, wangyanan55, zhao1.liu, Filip Hejsek

Make chardev ID param descriptions more consistend with ID descriptions
elsewhere.
---
 qapi/char.json | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/qapi/char.json b/qapi/char.json
index 140614f82c..fbac5a1cb7 100644
--- a/qapi/char.json
+++ b/qapi/char.json
@@ -791,7 +791,7 @@
 #
 # Change a character device backend
 #
-# @id: the chardev's ID, must exist
+# @id: the chardev's ID
 #
 # @backend: new backend type and parameters
 #
@@ -832,7 +832,7 @@
 #
 # Remove a character device backend
 #
-# @id: the chardev's ID, must exist and not be in use
+# @id: the chardev's ID, must not be in use
 #
 # Since: 1.4
 #
@@ -849,7 +849,7 @@
 #
 # Send a break to a character device
 #
-# @id: the chardev's ID, must exist
+# @id: the chardev's ID
 #
 # Since: 2.10
 #
-- 
2.52.0



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-19  9:43     ` Michael S. Tsirkin
@ 2026-01-20  8:43       ` Daniel P. Berrangé
  2026-01-20  9:16         ` Filip Hejsek
  0 siblings, 1 reply; 30+ messages in thread
From: Daniel P. Berrangé @ 2026-01-20  8:43 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Filip Hejsek, qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Maximilian Immanuel Brandtner,
	Szymon Lukasz

On Mon, Jan 19, 2026 at 04:43:21AM -0500, Michael S. Tsirkin wrote:
> On Mon, Jan 19, 2026 at 09:38:41AM +0000, Daniel P. Berrangé wrote:
> > On Mon, Jan 19, 2026 at 04:27:51AM +0100, Filip Hejsek wrote:
> > > Implement the part of the virtio spec that allows to notify the virtio
> > > driver about terminal resizes. The virtio spec contains two methods to
> > > achieve that:
> > > 
> > > For legacy drivers, we have only one port and we put the terminal size
> > > in the config space and inject the config changed interrupt.
> > > 
> > > For multiport devices, we use the control virtqueue to send a packet
> > > containing the terminal size. Note that old versions of the Linux kernel
> > > used an incorrect order for the fields (rows then cols instead of cols
> > > then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> > > 
> > > As a result, when using a Linux kernel older than 6.15, the number of rows
> > > and columns will be swapped.
> > > 
> > > Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> > > but partially rewritten to fix various corner cases.
> > > 
> > > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> > > ---
> > >  hw/char/trace-events              |  1 +
> > >  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
> > >  hw/core/machine.c                 |  4 ++-
> > >  include/hw/virtio/virtio-serial.h |  5 +++
> > >  4 files changed, 83 insertions(+), 3 deletions(-)
> > > 
> > 
> > > @@ -1158,6 +1228,8 @@ static const Property virtio_serial_properties[] = {
> > >                                                    31),
> > >      DEFINE_PROP_BIT64("emergency-write", VirtIOSerial, host_features,
> > >                        VIRTIO_CONSOLE_F_EMERG_WRITE, true),
> > > +    DEFINE_PROP_BIT64("console-size", VirtIOSerial, host_features,
> > > +                      VIRTIO_CONSOLE_F_SIZE, true),
> > >  };
> > 
> > Given the horrible mess with the kernel intentionally changing its
> > behaviour after 15 years, I don't think we can we set this to be
> > enabled by default.
> > 
> > The recent behaviour change is never going to be backported to enough
> > stable distros that we can rely on the new behaviour, and thanks to
> > the change we can't rely on the old behaviour either. We're doomed no
> > matter what ordernig we use.
> > 
> > Thus, IMHO, this has to stay set to false indefinitely.
> 
> Not sure. But what we can do is add another flag to detect new kernels.
> I'll try to think of a good name but suggestions are welcome.

How can we detect the kernel ? There's no feature flag that can be
negotiated or detected to report the changed kernel behaviour
AFAICS. We have no visibility of kernel version, and even if we did,
the possibility of backports would make that unreliable too. The
inability to auto-detect anything is what makes the kernel behaviour
change so awful.

We can add a nother qemu flag "console-size-inverted" to flip QEMU
between the 2 behaviours, but that still won't let us be able to
enable 'console-size' by default without guaranteed regressions.
The 'console-size-inverted' flag would merely flip the breakage
between different groups of guest OS.

> > >  static void virtio_serial_class_init(ObjectClass *klass, const void *data)
> > > diff --git a/hw/core/machine.c b/hw/core/machine.c
> > > index 6411e68856..50554b8900 100644
> > > --- a/hw/core/machine.c
> > > +++ b/hw/core/machine.c
> > > @@ -38,7 +38,9 @@
> > >  #include "hw/acpi/generic_event_device.h"
> > >  #include "qemu/audio.h"
> > >  
> > > -GlobalProperty hw_compat_10_2[] = {};
> > > +GlobalProperty hw_compat_10_2[] = {
> > > +    { "virtio-serial-device", "console-size", "off" },
> > > +};
> > >  const size_t hw_compat_10_2_len = G_N_ELEMENTS(hw_compat_10_2);
> > >  
> > >  GlobalProperty hw_compat_10_1[] = {

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 :|



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-20  8:43       ` Daniel P. Berrangé
@ 2026-01-20  9:16         ` Filip Hejsek
  2026-01-20 12:56           ` Michael S. Tsirkin
  0 siblings, 1 reply; 30+ messages in thread
From: Filip Hejsek @ 2026-01-20  9:16 UTC (permalink / raw)
  To: Daniel P. Berrangé, Michael S. Tsirkin
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini, Laurent Vivier,
	Amit Shah, Markus Armbruster, Eric Blake, Eduardo Habkost,
	Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
	Zhao Liu, Maximilian Immanuel Brandtner, Szymon Lukasz

On Tue, 2026-01-20 at 08:43 +0000, Daniel P. Berrangé wrote:
> On Mon, Jan 19, 2026 at 04:43:21AM -0500, Michael S. Tsirkin wrote:
> > On Mon, Jan 19, 2026 at 09:38:41AM +0000, Daniel P. Berrangé wrote:
> > > On Mon, Jan 19, 2026 at 04:27:51AM +0100, Filip Hejsek wrote:
> > > > Implement the part of the virtio spec that allows to notify the virtio
> > > > driver about terminal resizes. The virtio spec contains two methods to
> > > > achieve that:
> > > > 
> > > > For legacy drivers, we have only one port and we put the terminal size
> > > > in the config space and inject the config changed interrupt.
> > > > 
> > > > For multiport devices, we use the control virtqueue to send a packet
> > > > containing the terminal size. Note that old versions of the Linux kernel
> > > > used an incorrect order for the fields (rows then cols instead of cols
> > > > then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> > > > 
> > > > As a result, when using a Linux kernel older than 6.15, the number of rows
> > > > and columns will be swapped.
> > > > 
> > > > Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> > > > but partially rewritten to fix various corner cases.
> > > > 
> > > > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > > > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> > > > ---
> > > >  hw/char/trace-events              |  1 +
> > > >  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
> > > >  hw/core/machine.c                 |  4 ++-
> > > >  include/hw/virtio/virtio-serial.h |  5 +++
> > > >  4 files changed, 83 insertions(+), 3 deletions(-)
> > > > 
> > > 
> > > > @@ -1158,6 +1228,8 @@ static const Property virtio_serial_properties[] = {
> > > >                                                    31),
> > > >      DEFINE_PROP_BIT64("emergency-write", VirtIOSerial, host_features,
> > > >                        VIRTIO_CONSOLE_F_EMERG_WRITE, true),
> > > > +    DEFINE_PROP_BIT64("console-size", VirtIOSerial, host_features,
> > > > +                      VIRTIO_CONSOLE_F_SIZE, true),
> > > >  };
> > > 
> > > Given the horrible mess with the kernel intentionally changing its
> > > behaviour after 15 years, I don't think we can we set this to be
> > > enabled by default.
> > > 
> > > The recent behaviour change is never going to be backported to enough
> > > stable distros that we can rely on the new behaviour, and thanks to
> > > the change we can't rely on the old behaviour either. We're doomed no
> > > matter what ordernig we use.
> > > 
> > > Thus, IMHO, this has to stay set to false indefinitely.
> > 
> > Not sure. But what we can do is add another flag to detect new kernels.
> > I'll try to think of a good name but suggestions are welcome.
> 
> How can we detect the kernel ? There's no feature flag that can be
> negotiated or detected to report the changed kernel behaviour
> AFAICS. We have no visibility of kernel version, and even if we did,
> the possibility of backports would make that unreliable too. The
> inability to auto-detect anything is what makes the kernel behaviour
> change so awful.
> 
> We can add a nother qemu flag "console-size-inverted" to flip QEMU
> between the 2 behaviours, but that still won't let us be able to
> enable 'console-size' by default without guaranteed regressions.
> The 'console-size-inverted' flag would merely flip the breakage
> between different groups of guest OS.

We could add a new virtio feature flag, and by default only enable
resizing when the guest supports this new flag. Kernels that support
the flag would work by default, and kernels that have the correct order
but don't yet support the flag would require manually enabling the
feature.

In any case, we will probably need to add some documentation for the
property. I'm trying to find a good place for it, but it seems that the
virtconsole and virtio-serial-bus devices are not actually documented
anywhere at all. They should probably be documented in the man page,
right?

> 
> > > >  static void virtio_serial_class_init(ObjectClass *klass, const void *data)
> > > > diff --git a/hw/core/machine.c b/hw/core/machine.c
> > > > index 6411e68856..50554b8900 100644
> > > > --- a/hw/core/machine.c
> > > > +++ b/hw/core/machine.c
> > > > @@ -38,7 +38,9 @@
> > > >  #include "hw/acpi/generic_event_device.h"
> > > >  #include "qemu/audio.h"
> > > >  
> > > > -GlobalProperty hw_compat_10_2[] = {};
> > > > +GlobalProperty hw_compat_10_2[] = {
> > > > +    { "virtio-serial-device", "console-size", "off" },
> > > > +};
> > > >  const size_t hw_compat_10_2_len = G_N_ELEMENTS(hw_compat_10_2);
> > > >  
> > > >  GlobalProperty hw_compat_10_1[] = {
> 
> With regards,
> Daniel


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-19  3:27 ` [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages Filip Hejsek
  2026-01-19  9:38   ` Daniel P. Berrangé
@ 2026-01-20  9:50   ` Filip Hejsek
  2026-01-20  9:54     ` Daniel P. Berrangé
  2026-01-20 12:58     ` Michael S. Tsirkin
  1 sibling, 2 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-20  9:50 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Michael S. Tsirkin,
	Laurent Vivier, Amit Shah, Markus Armbruster, Eric Blake,
	Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Maximilian Immanuel Brandtner, Szymon Lukasz

On Mon, 2026-01-19 at 04:27 +0100, Filip Hejsek wrote:
> Implement the part of the virtio spec that allows to notify the virtio
> driver about terminal resizes. The virtio spec contains two methods to
> achieve that:
> 
> For legacy drivers, we have only one port and we put the terminal size
> in the config space and inject the config changed interrupt.
> 
> For multiport devices, we use the control virtqueue to send a packet
> containing the terminal size. Note that old versions of the Linux kernel
> used an incorrect order for the fields (rows then cols instead of cols
> then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> 
> As a result, when using a Linux kernel older than 6.15, the number of rows
> and columns will be swapped.
> 
> Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> but partially rewritten to fix various corner cases.
> 
> Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> ---
>  hw/char/trace-events              |  1 +
>  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
>  hw/core/machine.c                 |  4 ++-
>  include/hw/virtio/virtio-serial.h |  5 +++
>  4 files changed, 83 insertions(+), 3 deletions(-)
> 
> [...]
> 
> diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
> index 60641860bf..bda6d5312a 100644
> --- a/include/hw/virtio/virtio-serial.h
> +++ b/include/hw/virtio/virtio-serial.h
> @@ -145,6 +145,9 @@ struct VirtIOSerialPort {
>      bool host_connected;
>      /* Do apps not want to receive data? */
>      bool throttled;
> +
> +    /* Terminal size reported to the guest.  Only used for consoles. */
> +    uint16_t cols, rows;
>  };

I found a bug: after a migration, the guest is not informed about the
new console size. I see two ways to fix this: either add the cols and
rows fields to the migration stream, or always send the console size to
the guest after migration, even if it might not have changed. Which do
you prefer? Modifying the migration stream is somewhat annoying,
because both versions will have to be supported, and also the device
still uses legacy save/load functions rather than VMState.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-20  9:50   ` Filip Hejsek
@ 2026-01-20  9:54     ` Daniel P. Berrangé
  2026-01-20 10:07       ` Filip Hejsek
  2026-01-20 12:58     ` Michael S. Tsirkin
  1 sibling, 1 reply; 30+ messages in thread
From: Daniel P. Berrangé @ 2026-01-20  9:54 UTC (permalink / raw)
  To: Filip Hejsek
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Michael S. Tsirkin, Laurent Vivier, Amit Shah, Markus Armbruster,
	Eric Blake, Eduardo Habkost, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Yanan Wang, Zhao Liu,
	Maximilian Immanuel Brandtner, Szymon Lukasz

On Tue, Jan 20, 2026 at 10:50:04AM +0100, Filip Hejsek wrote:
> On Mon, 2026-01-19 at 04:27 +0100, Filip Hejsek wrote:
> > Implement the part of the virtio spec that allows to notify the virtio
> > driver about terminal resizes. The virtio spec contains two methods to
> > achieve that:
> > 
> > For legacy drivers, we have only one port and we put the terminal size
> > in the config space and inject the config changed interrupt.
> > 
> > For multiport devices, we use the control virtqueue to send a packet
> > containing the terminal size. Note that old versions of the Linux kernel
> > used an incorrect order for the fields (rows then cols instead of cols
> > then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> > 
> > As a result, when using a Linux kernel older than 6.15, the number of rows
> > and columns will be swapped.
> > 
> > Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> > but partially rewritten to fix various corner cases.
> > 
> > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> > ---
> >  hw/char/trace-events              |  1 +
> >  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
> >  hw/core/machine.c                 |  4 ++-
> >  include/hw/virtio/virtio-serial.h |  5 +++
> >  4 files changed, 83 insertions(+), 3 deletions(-)
> > 
> > [...]
> > 
> > diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
> > index 60641860bf..bda6d5312a 100644
> > --- a/include/hw/virtio/virtio-serial.h
> > +++ b/include/hw/virtio/virtio-serial.h
> > @@ -145,6 +145,9 @@ struct VirtIOSerialPort {
> >      bool host_connected;
> >      /* Do apps not want to receive data? */
> >      bool throttled;
> > +
> > +    /* Terminal size reported to the guest.  Only used for consoles. */
> > +    uint16_t cols, rows;
> >  };
> 
> I found a bug: after a migration, the guest is not informed about the
> new console size. I see two ways to fix this: either add the cols and
> rows fields to the migration stream, or always send the console size to
> the guest after migration, even if it might not have changed. Which do
> you prefer? Modifying the migration stream is somewhat annoying,
> because both versions will have to be supported, and also the device
> still uses legacy save/load functions rather than VMState.

On the backend side, I'd consider migration to be equivalent to closing
and re-opening the backend character device. That should imply sending
a resize event on  migration completion. I'm surprised the chardev on
the dst isn't already triggering that when it gets connected, but perhaps
that is too early & getting lost ?

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 :|



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-20  9:54     ` Daniel P. Berrangé
@ 2026-01-20 10:07       ` Filip Hejsek
  2026-01-20 10:10         ` Daniel P. Berrangé
  0 siblings, 1 reply; 30+ messages in thread
From: Filip Hejsek @ 2026-01-20 10:07 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Michael S. Tsirkin, Laurent Vivier, Amit Shah, Markus Armbruster,
	Eric Blake, Eduardo Habkost, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Yanan Wang, Zhao Liu,
	Maximilian Immanuel Brandtner, Szymon Lukasz

On Tue, 2026-01-20 at 09:54 +0000, Daniel P. Berrangé wrote:
> On Tue, Jan 20, 2026 at 10:50:04AM +0100, Filip Hejsek wrote:
> > On Mon, 2026-01-19 at 04:27 +0100, Filip Hejsek wrote:
> > > Implement the part of the virtio spec that allows to notify the virtio
> > > driver about terminal resizes. The virtio spec contains two methods to
> > > achieve that:
> > > 
> > > For legacy drivers, we have only one port and we put the terminal size
> > > in the config space and inject the config changed interrupt.
> > > 
> > > For multiport devices, we use the control virtqueue to send a packet
> > > containing the terminal size. Note that old versions of the Linux kernel
> > > used an incorrect order for the fields (rows then cols instead of cols
> > > then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> > > 
> > > As a result, when using a Linux kernel older than 6.15, the number of rows
> > > and columns will be swapped.
> > > 
> > > Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> > > but partially rewritten to fix various corner cases.
> > > 
> > > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> > > ---
> > >  hw/char/trace-events              |  1 +
> > >  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
> > >  hw/core/machine.c                 |  4 ++-
> > >  include/hw/virtio/virtio-serial.h |  5 +++
> > >  4 files changed, 83 insertions(+), 3 deletions(-)
> > > 
> > > [...]
> > > 
> > > diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
> > > index 60641860bf..bda6d5312a 100644
> > > --- a/include/hw/virtio/virtio-serial.h
> > > +++ b/include/hw/virtio/virtio-serial.h
> > > @@ -145,6 +145,9 @@ struct VirtIOSerialPort {
> > >      bool host_connected;
> > >      /* Do apps not want to receive data? */
> > >      bool throttled;
> > > +
> > > +    /* Terminal size reported to the guest.  Only used for consoles. */
> > > +    uint16_t cols, rows;
> > >  };
> > 
> > I found a bug: after a migration, the guest is not informed about the
> > new console size. I see two ways to fix this: either add the cols and
> > rows fields to the migration stream, or always send the console size to
> > the guest after migration, even if it might not have changed. Which do
> > you prefer? Modifying the migration stream is somewhat annoying,
> > because both versions will have to be supported, and also the device
> > still uses legacy save/load functions rather than VMState.
> 
> On the backend side, I'd consider migration to be equivalent to closing
> and re-opening the backend character device. That should imply sending
> a resize event on  migration completion. I'm surprised the chardev on
> the dst isn't already triggering that when it gets connected, but perhaps
> that is too early & getting lost ?

The virtio device caches the size and doesn't send a resize message if
the size hasn't actually changed.

> 
> With regards,
> Daniel


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-20 10:07       ` Filip Hejsek
@ 2026-01-20 10:10         ` Daniel P. Berrangé
  2026-01-20 10:16           ` Filip Hejsek
  0 siblings, 1 reply; 30+ messages in thread
From: Daniel P. Berrangé @ 2026-01-20 10:10 UTC (permalink / raw)
  To: Filip Hejsek
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Michael S. Tsirkin, Laurent Vivier, Amit Shah, Markus Armbruster,
	Eric Blake, Eduardo Habkost, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Yanan Wang, Zhao Liu,
	Maximilian Immanuel Brandtner, Szymon Lukasz

On Tue, Jan 20, 2026 at 11:07:16AM +0100, Filip Hejsek wrote:
> On Tue, 2026-01-20 at 09:54 +0000, Daniel P. Berrangé wrote:
> > On Tue, Jan 20, 2026 at 10:50:04AM +0100, Filip Hejsek wrote:
> > > On Mon, 2026-01-19 at 04:27 +0100, Filip Hejsek wrote:
> > > > Implement the part of the virtio spec that allows to notify the virtio
> > > > driver about terminal resizes. The virtio spec contains two methods to
> > > > achieve that:
> > > > 
> > > > For legacy drivers, we have only one port and we put the terminal size
> > > > in the config space and inject the config changed interrupt.
> > > > 
> > > > For multiport devices, we use the control virtqueue to send a packet
> > > > containing the terminal size. Note that old versions of the Linux kernel
> > > > used an incorrect order for the fields (rows then cols instead of cols
> > > > then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> > > > 
> > > > As a result, when using a Linux kernel older than 6.15, the number of rows
> > > > and columns will be swapped.
> > > > 
> > > > Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> > > > but partially rewritten to fix various corner cases.
> > > > 
> > > > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > > > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> > > > ---
> > > >  hw/char/trace-events              |  1 +
> > > >  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
> > > >  hw/core/machine.c                 |  4 ++-
> > > >  include/hw/virtio/virtio-serial.h |  5 +++
> > > >  4 files changed, 83 insertions(+), 3 deletions(-)
> > > > 
> > > > [...]
> > > > 
> > > > diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
> > > > index 60641860bf..bda6d5312a 100644
> > > > --- a/include/hw/virtio/virtio-serial.h
> > > > +++ b/include/hw/virtio/virtio-serial.h
> > > > @@ -145,6 +145,9 @@ struct VirtIOSerialPort {
> > > >      bool host_connected;
> > > >      /* Do apps not want to receive data? */
> > > >      bool throttled;
> > > > +
> > > > +    /* Terminal size reported to the guest.  Only used for consoles. */
> > > > +    uint16_t cols, rows;
> > > >  };
> > > 
> > > I found a bug: after a migration, the guest is not informed about the
> > > new console size. I see two ways to fix this: either add the cols and
> > > rows fields to the migration stream, or always send the console size to
> > > the guest after migration, even if it might not have changed. Which do
> > > you prefer? Modifying the migration stream is somewhat annoying,
> > > because both versions will have to be supported, and also the device
> > > still uses legacy save/load functions rather than VMState.
> > 
> > On the backend side, I'd consider migration to be equivalent to closing
> > and re-opening the backend character device. That should imply sending
> > a resize event on  migration completion. I'm surprised the chardev on
> > the dst isn't already triggering that when it gets connected, but perhaps
> > that is too early & getting lost ?
> 
> The virtio device caches the size and doesn't send a resize message if
> the size hasn't actually changed.

If the size on the dest has not changed vs the size on the src, that's
fine surely ? We only need to tell the guest a new size if the dst
was different from the source after migration 

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 :|



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-20 10:10         ` Daniel P. Berrangé
@ 2026-01-20 10:16           ` Filip Hejsek
  2026-01-20 10:20             ` Daniel P. Berrangé
  0 siblings, 1 reply; 30+ messages in thread
From: Filip Hejsek @ 2026-01-20 10:16 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Michael S. Tsirkin, Laurent Vivier, Amit Shah, Markus Armbruster,
	Eric Blake, Eduardo Habkost, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Yanan Wang, Zhao Liu,
	Maximilian Immanuel Brandtner, Szymon Lukasz

On Tue, 2026-01-20 at 10:10 +0000, Daniel P. Berrangé wrote:
> On Tue, Jan 20, 2026 at 11:07:16AM +0100, Filip Hejsek wrote:
> > On Tue, 2026-01-20 at 09:54 +0000, Daniel P. Berrangé wrote:
> > > On Tue, Jan 20, 2026 at 10:50:04AM +0100, Filip Hejsek wrote:
> > > > On Mon, 2026-01-19 at 04:27 +0100, Filip Hejsek wrote:
> > > > > Implement the part of the virtio spec that allows to notify the virtio
> > > > > driver about terminal resizes. The virtio spec contains two methods to
> > > > > achieve that:
> > > > > 
> > > > > For legacy drivers, we have only one port and we put the terminal size
> > > > > in the config space and inject the config changed interrupt.
> > > > > 
> > > > > For multiport devices, we use the control virtqueue to send a packet
> > > > > containing the terminal size. Note that old versions of the Linux kernel
> > > > > used an incorrect order for the fields (rows then cols instead of cols
> > > > > then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> > > > > 
> > > > > As a result, when using a Linux kernel older than 6.15, the number of rows
> > > > > and columns will be swapped.
> > > > > 
> > > > > Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> > > > > but partially rewritten to fix various corner cases.
> > > > > 
> > > > > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > > > > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> > > > > ---
> > > > >  hw/char/trace-events              |  1 +
> > > > >  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
> > > > >  hw/core/machine.c                 |  4 ++-
> > > > >  include/hw/virtio/virtio-serial.h |  5 +++
> > > > >  4 files changed, 83 insertions(+), 3 deletions(-)
> > > > > 
> > > > > [...]
> > > > > 
> > > > > diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
> > > > > index 60641860bf..bda6d5312a 100644
> > > > > --- a/include/hw/virtio/virtio-serial.h
> > > > > +++ b/include/hw/virtio/virtio-serial.h
> > > > > @@ -145,6 +145,9 @@ struct VirtIOSerialPort {
> > > > >      bool host_connected;
> > > > >      /* Do apps not want to receive data? */
> > > > >      bool throttled;
> > > > > +
> > > > > +    /* Terminal size reported to the guest.  Only used for consoles. */
> > > > > +    uint16_t cols, rows;
> > > > >  };
> > > > 
> > > > I found a bug: after a migration, the guest is not informed about the
> > > > new console size. I see two ways to fix this: either add the cols and
> > > > rows fields to the migration stream, or always send the console size to
> > > > the guest after migration, even if it might not have changed. Which do
> > > > you prefer? Modifying the migration stream is somewhat annoying,
> > > > because both versions will have to be supported, and also the device
> > > > still uses legacy save/load functions rather than VMState.
> > > 
> > > On the backend side, I'd consider migration to be equivalent to closing
> > > and re-opening the backend character device. That should imply sending
> > > a resize event on  migration completion. I'm surprised the chardev on
> > > the dst isn't already triggering that when it gets connected, but perhaps
> > > that is too early & getting lost ?
> > 
> > The virtio device caches the size and doesn't send a resize message if
> > the size hasn't actually changed.
> 
> If the size on the dest has not changed vs the size on the src, that's
> fine surely ? We only need to tell the guest a new size if the dst
> was different from the source after migration 

The current size is compared against previous size on the *dst*. We
don't know the size on the src, because it is not sent in the migration
stream.

Best regards,
Filip


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-20 10:16           ` Filip Hejsek
@ 2026-01-20 10:20             ` Daniel P. Berrangé
  2026-01-20 10:22               ` Filip Hejsek
  0 siblings, 1 reply; 30+ messages in thread
From: Daniel P. Berrangé @ 2026-01-20 10:20 UTC (permalink / raw)
  To: Filip Hejsek
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Michael S. Tsirkin, Laurent Vivier, Amit Shah, Markus Armbruster,
	Eric Blake, Eduardo Habkost, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Yanan Wang, Zhao Liu,
	Maximilian Immanuel Brandtner, Szymon Lukasz

On Tue, Jan 20, 2026 at 11:16:51AM +0100, Filip Hejsek wrote:
> On Tue, 2026-01-20 at 10:10 +0000, Daniel P. Berrangé wrote:
> > On Tue, Jan 20, 2026 at 11:07:16AM +0100, Filip Hejsek wrote:
> > > On Tue, 2026-01-20 at 09:54 +0000, Daniel P. Berrangé wrote:
> > > > On Tue, Jan 20, 2026 at 10:50:04AM +0100, Filip Hejsek wrote:
> > > > > On Mon, 2026-01-19 at 04:27 +0100, Filip Hejsek wrote:
> > > > > > Implement the part of the virtio spec that allows to notify the virtio
> > > > > > driver about terminal resizes. The virtio spec contains two methods to
> > > > > > achieve that:
> > > > > > 
> > > > > > For legacy drivers, we have only one port and we put the terminal size
> > > > > > in the config space and inject the config changed interrupt.
> > > > > > 
> > > > > > For multiport devices, we use the control virtqueue to send a packet
> > > > > > containing the terminal size. Note that old versions of the Linux kernel
> > > > > > used an incorrect order for the fields (rows then cols instead of cols
> > > > > > then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> > > > > > 
> > > > > > As a result, when using a Linux kernel older than 6.15, the number of rows
> > > > > > and columns will be swapped.
> > > > > > 
> > > > > > Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> > > > > > but partially rewritten to fix various corner cases.
> > > > > > 
> > > > > > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > > > > > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> > > > > > ---
> > > > > >  hw/char/trace-events              |  1 +
> > > > > >  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
> > > > > >  hw/core/machine.c                 |  4 ++-
> > > > > >  include/hw/virtio/virtio-serial.h |  5 +++
> > > > > >  4 files changed, 83 insertions(+), 3 deletions(-)
> > > > > > 
> > > > > > [...]
> > > > > > 
> > > > > > diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
> > > > > > index 60641860bf..bda6d5312a 100644
> > > > > > --- a/include/hw/virtio/virtio-serial.h
> > > > > > +++ b/include/hw/virtio/virtio-serial.h
> > > > > > @@ -145,6 +145,9 @@ struct VirtIOSerialPort {
> > > > > >      bool host_connected;
> > > > > >      /* Do apps not want to receive data? */
> > > > > >      bool throttled;
> > > > > > +
> > > > > > +    /* Terminal size reported to the guest.  Only used for consoles. */
> > > > > > +    uint16_t cols, rows;
> > > > > >  };
> > > > > 
> > > > > I found a bug: after a migration, the guest is not informed about the
> > > > > new console size. I see two ways to fix this: either add the cols and
> > > > > rows fields to the migration stream, or always send the console size to
> > > > > the guest after migration, even if it might not have changed. Which do
> > > > > you prefer? Modifying the migration stream is somewhat annoying,
> > > > > because both versions will have to be supported, and also the device
> > > > > still uses legacy save/load functions rather than VMState.
> > > > 
> > > > On the backend side, I'd consider migration to be equivalent to closing
> > > > and re-opening the backend character device. That should imply sending
> > > > a resize event on  migration completion. I'm surprised the chardev on
> > > > the dst isn't already triggering that when it gets connected, but perhaps
> > > > that is too early & getting lost ?
> > > 
> > > The virtio device caches the size and doesn't send a resize message if
> > > the size hasn't actually changed.
> > 
> > If the size on the dest has not changed vs the size on the src, that's
> > fine surely ? We only need to tell the guest a new size if the dst
> > was different from the source after migration 
> 
> The current size is compared against previous size on the *dst*. We
> don't know the size on the src, because it is not sent in the migration
> stream.

Oh, I see what you mean. In that case we should probably use a .post_load
hook to invalidate the dst cached size in some manner, so that the next
update from the backend is forced to be sent to the guest.

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 :|



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-20 10:20             ` Daniel P. Berrangé
@ 2026-01-20 10:22               ` Filip Hejsek
  2026-01-20 10:28                 ` Filip Hejsek
  0 siblings, 1 reply; 30+ messages in thread
From: Filip Hejsek @ 2026-01-20 10:22 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Michael S. Tsirkin, Laurent Vivier, Amit Shah, Markus Armbruster,
	Eric Blake, Eduardo Habkost, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Yanan Wang, Zhao Liu,
	Maximilian Immanuel Brandtner, Szymon Lukasz

On Tue, 2026-01-20 at 10:20 +0000, Daniel P. Berrangé wrote:
> On Tue, Jan 20, 2026 at 11:16:51AM +0100, Filip Hejsek wrote:
> > On Tue, 2026-01-20 at 10:10 +0000, Daniel P. Berrangé wrote:
> > > On Tue, Jan 20, 2026 at 11:07:16AM +0100, Filip Hejsek wrote:
> > > > On Tue, 2026-01-20 at 09:54 +0000, Daniel P. Berrangé wrote:
> > > > > On Tue, Jan 20, 2026 at 10:50:04AM +0100, Filip Hejsek wrote:
> > > > > > On Mon, 2026-01-19 at 04:27 +0100, Filip Hejsek wrote:
> > > > > > > Implement the part of the virtio spec that allows to notify the virtio
> > > > > > > driver about terminal resizes. The virtio spec contains two methods to
> > > > > > > achieve that:
> > > > > > > 
> > > > > > > For legacy drivers, we have only one port and we put the terminal size
> > > > > > > in the config space and inject the config changed interrupt.
> > > > > > > 
> > > > > > > For multiport devices, we use the control virtqueue to send a packet
> > > > > > > containing the terminal size. Note that old versions of the Linux kernel
> > > > > > > used an incorrect order for the fields (rows then cols instead of cols
> > > > > > > then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> > > > > > > 
> > > > > > > As a result, when using a Linux kernel older than 6.15, the number of rows
> > > > > > > and columns will be swapped.
> > > > > > > 
> > > > > > > Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> > > > > > > but partially rewritten to fix various corner cases.
> > > > > > > 
> > > > > > > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > > > > > > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> > > > > > > ---
> > > > > > >  hw/char/trace-events              |  1 +
> > > > > > >  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
> > > > > > >  hw/core/machine.c                 |  4 ++-
> > > > > > >  include/hw/virtio/virtio-serial.h |  5 +++
> > > > > > >  4 files changed, 83 insertions(+), 3 deletions(-)
> > > > > > > 
> > > > > > > [...]
> > > > > > > 
> > > > > > > diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
> > > > > > > index 60641860bf..bda6d5312a 100644
> > > > > > > --- a/include/hw/virtio/virtio-serial.h
> > > > > > > +++ b/include/hw/virtio/virtio-serial.h
> > > > > > > @@ -145,6 +145,9 @@ struct VirtIOSerialPort {
> > > > > > >      bool host_connected;
> > > > > > >      /* Do apps not want to receive data? */
> > > > > > >      bool throttled;
> > > > > > > +
> > > > > > > +    /* Terminal size reported to the guest.  Only used for consoles. */
> > > > > > > +    uint16_t cols, rows;
> > > > > > >  };
> > > > > > 
> > > > > > I found a bug: after a migration, the guest is not informed about the
> > > > > > new console size. I see two ways to fix this: either add the cols and
> > > > > > rows fields to the migration stream, or always send the console size to
> > > > > > the guest after migration, even if it might not have changed. Which do
> > > > > > you prefer? Modifying the migration stream is somewhat annoying,
> > > > > > because both versions will have to be supported, and also the device
> > > > > > still uses legacy save/load functions rather than VMState.
> > > > > 
> > > > > On the backend side, I'd consider migration to be equivalent to closing
> > > > > and re-opening the backend character device. That should imply sending
> > > > > a resize event on  migration completion. I'm surprised the chardev on
> > > > > the dst isn't already triggering that when it gets connected, but perhaps
> > > > > that is too early & getting lost ?
> > > > 
> > > > The virtio device caches the size and doesn't send a resize message if
> > > > the size hasn't actually changed.
> > > 
> > > If the size on the dest has not changed vs the size on the src, that's
> > > fine surely ? We only need to tell the guest a new size if the dst
> > > was different from the source after migration 
> > 
> > The current size is compared against previous size on the *dst*. We
> > don't know the size on the src, because it is not sent in the migration
> > stream.
> 
> Oh, I see what you mean. In that case we should probably use a .post_load
> hook to invalidate the dst cached size in some manner, so that the next
> update from the backend is forced to be sent to the guest.

I think just sending the cached size is simpler.

Best regards,
Filip


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-20 10:22               ` Filip Hejsek
@ 2026-01-20 10:28                 ` Filip Hejsek
  0 siblings, 0 replies; 30+ messages in thread
From: Filip Hejsek @ 2026-01-20 10:28 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Michael S. Tsirkin, Laurent Vivier, Amit Shah, Markus Armbruster,
	Eric Blake, Eduardo Habkost, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Yanan Wang, Zhao Liu,
	Maximilian Immanuel Brandtner, Szymon Lukasz

On Tue, 2026-01-20 at 11:22 +0100, Filip Hejsek wrote:
> On Tue, 2026-01-20 at 10:20 +0000, Daniel P. Berrangé wrote:
> > On Tue, Jan 20, 2026 at 11:16:51AM +0100, Filip Hejsek wrote:
> > > On Tue, 2026-01-20 at 10:10 +0000, Daniel P. Berrangé wrote:
> > > > On Tue, Jan 20, 2026 at 11:07:16AM +0100, Filip Hejsek wrote:
> > > > > On Tue, 2026-01-20 at 09:54 +0000, Daniel P. Berrangé wrote:
> > > > > > On Tue, Jan 20, 2026 at 10:50:04AM +0100, Filip Hejsek wrote:
> > > > > > > On Mon, 2026-01-19 at 04:27 +0100, Filip Hejsek wrote:
> > > > > > > > Implement the part of the virtio spec that allows to notify the virtio
> > > > > > > > driver about terminal resizes. The virtio spec contains two methods to
> > > > > > > > achieve that:
> > > > > > > > 
> > > > > > > > For legacy drivers, we have only one port and we put the terminal size
> > > > > > > > in the config space and inject the config changed interrupt.
> > > > > > > > 
> > > > > > > > For multiport devices, we use the control virtqueue to send a packet
> > > > > > > > containing the terminal size. Note that old versions of the Linux kernel
> > > > > > > > used an incorrect order for the fields (rows then cols instead of cols
> > > > > > > > then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> > > > > > > > 
> > > > > > > > As a result, when using a Linux kernel older than 6.15, the number of rows
> > > > > > > > and columns will be swapped.
> > > > > > > > 
> > > > > > > > Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> > > > > > > > but partially rewritten to fix various corner cases.
> > > > > > > > 
> > > > > > > > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > > > > > > > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> > > > > > > > ---
> > > > > > > >  hw/char/trace-events              |  1 +
> > > > > > > >  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
> > > > > > > >  hw/core/machine.c                 |  4 ++-
> > > > > > > >  include/hw/virtio/virtio-serial.h |  5 +++
> > > > > > > >  4 files changed, 83 insertions(+), 3 deletions(-)
> > > > > > > > 
> > > > > > > > [...]
> > > > > > > > 
> > > > > > > > diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
> > > > > > > > index 60641860bf..bda6d5312a 100644
> > > > > > > > --- a/include/hw/virtio/virtio-serial.h
> > > > > > > > +++ b/include/hw/virtio/virtio-serial.h
> > > > > > > > @@ -145,6 +145,9 @@ struct VirtIOSerialPort {
> > > > > > > >      bool host_connected;
> > > > > > > >      /* Do apps not want to receive data? */
> > > > > > > >      bool throttled;
> > > > > > > > +
> > > > > > > > +    /* Terminal size reported to the guest.  Only used for consoles. */
> > > > > > > > +    uint16_t cols, rows;
> > > > > > > >  };
> > > > > > > 
> > > > > > > I found a bug: after a migration, the guest is not informed about the
> > > > > > > new console size. I see two ways to fix this: either add the cols and
> > > > > > > rows fields to the migration stream, or always send the console size to
> > > > > > > the guest after migration, even if it might not have changed. Which do
> > > > > > > you prefer? Modifying the migration stream is somewhat annoying,
> > > > > > > because both versions will have to be supported, and also the device
> > > > > > > still uses legacy save/load functions rather than VMState.
> > > > > > 
> > > > > > On the backend side, I'd consider migration to be equivalent to closing
> > > > > > and re-opening the backend character device. That should imply sending
> > > > > > a resize event on  migration completion. I'm surprised the chardev on
> > > > > > the dst isn't already triggering that when it gets connected, but perhaps
> > > > > > that is too early & getting lost ?
> > > > > 
> > > > > The virtio device caches the size and doesn't send a resize message if
> > > > > the size hasn't actually changed.
> > > > 
> > > > If the size on the dest has not changed vs the size on the src, that's
> > > > fine surely ? We only need to tell the guest a new size if the dst
> > > > was different from the source after migration 
> > > 
> > > The current size is compared against previous size on the *dst*. We
> > > don't know the size on the src, because it is not sent in the migration
> > > stream.
> > 
> > Oh, I see what you mean. In that case we should probably use a .post_load
> > hook to invalidate the dst cached size in some manner, so that the next
> > update from the backend is forced to be sent to the guest.
> 
> I think just sending the cached size is simpler.

This fixes it:

@@ -806,6 +806,9 @@ static void virtio_serial_post_load_timer_cb(void *opaque)
                                port->host_connected);
         }
         vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
+        if (vsc->is_console) {
+            send_console_resize(port);
+        }
         if (vsc->set_guest_connected) {
             vsc->set_guest_connected(port, port->guest_connected);
         }


Best regards,
Filip


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-20  9:16         ` Filip Hejsek
@ 2026-01-20 12:56           ` Michael S. Tsirkin
  0 siblings, 0 replies; 30+ messages in thread
From: Michael S. Tsirkin @ 2026-01-20 12:56 UTC (permalink / raw)
  To: Filip Hejsek
  Cc: Daniel P. Berrangé, qemu-devel, Marc-André Lureau,
	Paolo Bonzini, Laurent Vivier, Amit Shah, Markus Armbruster,
	Eric Blake, Eduardo Habkost, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Yanan Wang, Zhao Liu,
	Maximilian Immanuel Brandtner, Szymon Lukasz

On Tue, Jan 20, 2026 at 10:16:08AM +0100, Filip Hejsek wrote:
> On Tue, 2026-01-20 at 08:43 +0000, Daniel P. Berrangé wrote:
> > On Mon, Jan 19, 2026 at 04:43:21AM -0500, Michael S. Tsirkin wrote:
> > > On Mon, Jan 19, 2026 at 09:38:41AM +0000, Daniel P. Berrangé wrote:
> > > > On Mon, Jan 19, 2026 at 04:27:51AM +0100, Filip Hejsek wrote:
> > > > > Implement the part of the virtio spec that allows to notify the virtio
> > > > > driver about terminal resizes. The virtio spec contains two methods to
> > > > > achieve that:
> > > > > 
> > > > > For legacy drivers, we have only one port and we put the terminal size
> > > > > in the config space and inject the config changed interrupt.
> > > > > 
> > > > > For multiport devices, we use the control virtqueue to send a packet
> > > > > containing the terminal size. Note that old versions of the Linux kernel
> > > > > used an incorrect order for the fields (rows then cols instead of cols
> > > > > then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> > > > > 
> > > > > As a result, when using a Linux kernel older than 6.15, the number of rows
> > > > > and columns will be swapped.
> > > > > 
> > > > > Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> > > > > but partially rewritten to fix various corner cases.
> > > > > 
> > > > > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > > > > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> > > > > ---
> > > > >  hw/char/trace-events              |  1 +
> > > > >  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
> > > > >  hw/core/machine.c                 |  4 ++-
> > > > >  include/hw/virtio/virtio-serial.h |  5 +++
> > > > >  4 files changed, 83 insertions(+), 3 deletions(-)
> > > > > 
> > > > 
> > > > > @@ -1158,6 +1228,8 @@ static const Property virtio_serial_properties[] = {
> > > > >                                                    31),
> > > > >      DEFINE_PROP_BIT64("emergency-write", VirtIOSerial, host_features,
> > > > >                        VIRTIO_CONSOLE_F_EMERG_WRITE, true),
> > > > > +    DEFINE_PROP_BIT64("console-size", VirtIOSerial, host_features,
> > > > > +                      VIRTIO_CONSOLE_F_SIZE, true),
> > > > >  };
> > > > 
> > > > Given the horrible mess with the kernel intentionally changing its
> > > > behaviour after 15 years, I don't think we can we set this to be
> > > > enabled by default.
> > > > 
> > > > The recent behaviour change is never going to be backported to enough
> > > > stable distros that we can rely on the new behaviour, and thanks to
> > > > the change we can't rely on the old behaviour either. We're doomed no
> > > > matter what ordernig we use.
> > > > 
> > > > Thus, IMHO, this has to stay set to false indefinitely.
> > > 
> > > Not sure. But what we can do is add another flag to detect new kernels.
> > > I'll try to think of a good name but suggestions are welcome.
> > 
> > How can we detect the kernel ? There's no feature flag that can be
> > negotiated or detected to report the changed kernel behaviour
> > AFAICS. We have no visibility of kernel version, and even if we did,
> > the possibility of backports would make that unreliable too. The
> > inability to auto-detect anything is what makes the kernel behaviour
> > change so awful.
> > 
> > We can add a nother qemu flag "console-size-inverted" to flip QEMU
> > between the 2 behaviours, but that still won't let us be able to
> > enable 'console-size' by default without guaranteed regressions.
> > The 'console-size-inverted' flag would merely flip the breakage
> > between different groups of guest OS.
> 
> We could add a new virtio feature flag, and by default only enable
> resizing when the guest supports this new flag. Kernels that support
> the flag would work by default, and kernels that have the correct order
> but don't yet support the flag would require manually enabling the
> feature.

Right. For now. In X years when we see downstreams backporting the
feature, things can change.


> In any case, we will probably need to add some documentation for the
> property. I'm trying to find a good place for it, but it seems that the
> virtconsole and virtio-serial-bus devices are not actually documented
> anywhere at all. They should probably be documented in the man page,
> right?
> 
> > 
> > > > >  static void virtio_serial_class_init(ObjectClass *klass, const void *data)
> > > > > diff --git a/hw/core/machine.c b/hw/core/machine.c
> > > > > index 6411e68856..50554b8900 100644
> > > > > --- a/hw/core/machine.c
> > > > > +++ b/hw/core/machine.c
> > > > > @@ -38,7 +38,9 @@
> > > > >  #include "hw/acpi/generic_event_device.h"
> > > > >  #include "qemu/audio.h"
> > > > >  
> > > > > -GlobalProperty hw_compat_10_2[] = {};
> > > > > +GlobalProperty hw_compat_10_2[] = {
> > > > > +    { "virtio-serial-device", "console-size", "off" },
> > > > > +};
> > > > >  const size_t hw_compat_10_2_len = G_N_ELEMENTS(hw_compat_10_2);
> > > > >  
> > > > >  GlobalProperty hw_compat_10_1[] = {
> > 
> > With regards,
> > Daniel



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages
  2026-01-20  9:50   ` Filip Hejsek
  2026-01-20  9:54     ` Daniel P. Berrangé
@ 2026-01-20 12:58     ` Michael S. Tsirkin
  1 sibling, 0 replies; 30+ messages in thread
From: Michael S. Tsirkin @ 2026-01-20 12:58 UTC (permalink / raw)
  To: Filip Hejsek
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini, Laurent Vivier,
	Amit Shah, Markus Armbruster, Eric Blake, Eduardo Habkost,
	Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
	Zhao Liu, Daniel P. Berrangé, Maximilian Immanuel Brandtner,
	Szymon Lukasz

On Tue, Jan 20, 2026 at 10:50:04AM +0100, Filip Hejsek wrote:
> On Mon, 2026-01-19 at 04:27 +0100, Filip Hejsek wrote:
> > Implement the part of the virtio spec that allows to notify the virtio
> > driver about terminal resizes. The virtio spec contains two methods to
> > achieve that:
> > 
> > For legacy drivers, we have only one port and we put the terminal size
> > in the config space and inject the config changed interrupt.
> > 
> > For multiport devices, we use the control virtqueue to send a packet
> > containing the terminal size. Note that old versions of the Linux kernel
> > used an incorrect order for the fields (rows then cols instead of cols
> > then rows), until it was fixed by commit 5326ab737a47278dbd16ed3ee7380b26c7056ddd.
> > 
> > As a result, when using a Linux kernel older than 6.15, the number of rows
> > and columns will be swapped.
> > 
> > Based on a patch originally written by Szymon Lukasz <noh4hss@gmail.com>,
> > but partially rewritten to fix various corner cases.
> > 
> > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> > ---
> >  hw/char/trace-events              |  1 +
> >  hw/char/virtio-serial-bus.c       | 76 +++++++++++++++++++++++++++++++++++++--
> >  hw/core/machine.c                 |  4 ++-
> >  include/hw/virtio/virtio-serial.h |  5 +++
> >  4 files changed, 83 insertions(+), 3 deletions(-)
> > 
> > [...]
> > 
> > diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
> > index 60641860bf..bda6d5312a 100644
> > --- a/include/hw/virtio/virtio-serial.h
> > +++ b/include/hw/virtio/virtio-serial.h
> > @@ -145,6 +145,9 @@ struct VirtIOSerialPort {
> >      bool host_connected;
> >      /* Do apps not want to receive data? */
> >      bool throttled;
> > +
> > +    /* Terminal size reported to the guest.  Only used for consoles. */
> > +    uint16_t cols, rows;
> >  };
> 
> I found a bug: after a migration, the guest is not informed about the
> new console size. I see two ways to fix this: either add the cols and
> rows fields to the migration stream, or always send the console size to
> the guest after migration, even if it might not have changed. Which do
> you prefer?

I prefer not adding a performance overhead to guests without
a good reason. We are already sending too much stuff to guests on
resume, let's not add more to this.

> Modifying the migration stream is somewhat annoying,
> because both versions will have to be supported, and also the device
> still uses legacy save/load functions rather than VMState.



^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2026-01-20 12:58 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-19  3:27 [PATCH v6 00/12] virtio-console: notify about the terminal size Filip Hejsek
2026-01-19  3:27 ` [PATCH v6 01/12] chardev: add cols, rows fields Filip Hejsek
2026-01-19  3:27 ` [PATCH v6 02/12] chardev: add CHR_EVENT_RESIZE Filip Hejsek
2026-01-19  3:27 ` [PATCH v6 03/12] chardev: add qemu_chr_resize() Filip Hejsek
2026-01-19  3:27 ` [PATCH v6 04/12] char-mux: add support for the terminal size Filip Hejsek
2026-01-19  3:27 ` [PATCH v6 05/12] main-loop: change the handling of SIGWINCH Filip Hejsek
2026-01-19  3:27 ` [PATCH v6 06/12] char-stdio: add support for the terminal size Filip Hejsek
2026-01-19  3:27 ` [PATCH v6 07/12] qmp: add chardev-window-size-changed command Filip Hejsek
2026-01-19  6:47   ` Markus Armbruster
2026-01-20  8:04     ` Filip Hejsek
2026-01-20  8:18       ` [PATCH] qapi: drop "must exist" from ID descriptions for consistency Filip Hejsek
2026-01-19  3:27 ` [PATCH v6 08/12] virtio-serial-bus: add terminal resize messages Filip Hejsek
2026-01-19  9:38   ` Daniel P. Berrangé
2026-01-19  9:43     ` Michael S. Tsirkin
2026-01-20  8:43       ` Daniel P. Berrangé
2026-01-20  9:16         ` Filip Hejsek
2026-01-20 12:56           ` Michael S. Tsirkin
2026-01-20  9:50   ` Filip Hejsek
2026-01-20  9:54     ` Daniel P. Berrangé
2026-01-20 10:07       ` Filip Hejsek
2026-01-20 10:10         ` Daniel P. Berrangé
2026-01-20 10:16           ` Filip Hejsek
2026-01-20 10:20             ` Daniel P. Berrangé
2026-01-20 10:22               ` Filip Hejsek
2026-01-20 10:28                 ` Filip Hejsek
2026-01-20 12:58     ` Michael S. Tsirkin
2026-01-19  3:27 ` [PATCH v6 09/12] virtio-console: notify the guest about terminal resizes Filip Hejsek
2026-01-19  3:27 ` [PATCH v6 10/12] char-win-stdio: add support for terminal size Filip Hejsek
2026-01-19  3:27 ` [PATCH v6 11/12] ui/console-vc: forward text console size to vc chardev Filip Hejsek
2026-01-19  3:27 ` [PATCH v6 12/12] ui/gtk: forward gtk " Filip Hejsek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox