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
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 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.
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 :|
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
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 :|
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
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 :|
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
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
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 :|
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 :|
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 :|
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
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
© 2016 - 2026 Red Hat, Inc.