Skip to contentSkip to conversation

virtio-console: notify about the terminal size

PATCH Superseded Filip Hejsek 8 participants 37 messages Jun 9 – Oct 21 Networking

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#1 lore raw

PATCH v7 1/12 chardev: add cols, rows fields

In reply to Filip Hejsek

From: Szymon Lukasz <[email protected]>

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

[Filip: CharBackend -> CharFrontend]
---
 chardev/char-fe.c         | 13 +++++++++++++
 include/chardev/char-fe.h | 10 ++++++++++
 include/chardev/char.h    |  1 +
 3 files changed, 24 insertions(+)
chardev/char-fe.c +13 -0
index a44f267373..c61c91f779 100644
@@ -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;
include/chardev/char-fe.h +10 -0
index 5f8a6df17d..53b8d2a1dc 100644
@@ -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
include/chardev/char.h +1 -0
index 7377d8e60a..6394ec2ffe 100644
@@ -66,6 +66,7 @@ struct Chardev {
     bool logtimestamp;
     bool log_line_start;
     int be_open;
+    uint16_t cols, rows;
     /* used to coordinate the chardev-change special-case: */
     bool handover_yank_instance;
     GSource *gsource;
Signature · 1 line
2.54.0
#2 lore raw

PATCH v7 2/12 chardev: add CHR_EVENT_RESIZE

In reply to Filip Hejsek

From: Szymon Lukasz <[email protected]>

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

[Filip: add note that only the focused frontend gets the event]
---
 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(+)
backends/cryptodev-vhost-user.c +1 -0
index cc478d9902..36564d4307 100644
@@ -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;
     }
chardev/char.c +1 -0
index ca8b37ed8d..5e62f2949e 100644
@@ -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;
     }
hw/block/vhost-user-blk.c +1 -0
index c151e83677..16c1a536f1 100644
@@ -413,6 +413,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;
     }
hw/char/terminal3270.c +1 -0
index 989b6f6ee1..acd754bcfa 100644
@@ -169,6 +169,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;
     }
hw/char/virtio-console.c +1 -0
index 4737b9a56e..36ad2ddc3f 100644
@@ -165,6 +165,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;
     }
hw/ipmi/ipmi_bmc_extern.c +1 -0
index fa08ed6c21..bd7c61b2d2 100644
@@ -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;
     }
hw/scsi/vhost-user-scsi.c +1 -0
index 3612897d4b..5601097bc9 100644
@@ -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;
     }
hw/usb/ccid-card-passthru.c +1 -0
index 5ab7855272..3f4052ec82 100644
@@ -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;
     }
hw/usb/dev-serial.c +1 -0
index b238cb7937..98d2abbd56 100644
@@ -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;
     }
hw/usb/redirect.c +1 -0
index bde821e214..7a492c1e54 100644
@@ -1387,6 +1387,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;
     }
hw/virtio/vhost-user-base.c +1 -0
index 01ab9ca56b..fd3a9d6265 100644
@@ -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;
     }
hw/virtio/vhost-user-scmi.c +1 -0
index f9264c4374..180787ec6d 100644
@@ -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;
     }
include/chardev/char.h +6 -0
index 6394ec2ffe..ee9f24038b 100644
@@ -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
monitor/hmp.c +1 -0
index cc4390486e..67d3fcba6d 100644
@@ -1496,6 +1496,7 @@ static void monitor_event(void *opaque, QEMUChrEvent event)
         break;
 
     case CHR_EVENT_BREAK:
+    case CHR_EVENT_RESIZE:
         /* Ignored */
         break;
     }
monitor/qmp.c +1 -0
index 687019811f..3d5ab8ff4f 100644
@@ -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;
     }
net/passt.c +1 -0
index 45440c399b..e65198960e 100644
@@ -428,6 +428,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;
     }
net/vhost-user.c +1 -0
index 2d0fc49b4d..b849de92da 100644
@@ -363,6 +363,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;
     }
Signature · 1 line
2.54.0
#10 lore raw

PATCH v7 9/12 ui/gtk: forward gtk console size to vc chardev

In reply to Filip Hejsek

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.

---
 ui/gtk.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
ui/gtk.c +28 -0
index 4f706c6bbb..2863082a24 100644
@@ -2040,6 +2040,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)
@@ -2105,6 +2127,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;
 }
 
Signature · 1 line
2.54.0
#0 lore raw

v7 cover virtio-console: notify about the terminal size

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 was a bug in Linux versions prior to 6.15 which caused the dimensions to be interpreted incorrectly by the guest. The fix has been backported to currently supported kernels, but to avoid making the terminal harder to use on out of date guests, the feature is disabled by default and must be enabled with the console-size property.

Limitations
-----------

There is still no documentation for the console-size property, which would be nice to have so that people can discover this functionality.

Resizing support for the spice version of 'vc' chardev is still missing.

After migration, the guest is not informed about the new console size (fixing this requires migration stream changes).

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

v7:
- Rebased
- Renamed some functions
- Made virtio size support disabled by default
- "Since: 11.0" -> "Since: 11.1"
- Dropped "must exist" from chardev id param description in qmp docs
- Link to v6: https://lore.kernel.org/qemu-devel/[email protected]

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/[email protected]

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/[email protected]

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/[email protected]

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):
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
virtio-serial-bus: add terminal resize messages

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                | 19 ++++++++-
 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       | 81 ++++++++++++++++++++++++++++++++++++++-
 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 |  7 ++++
 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                   |  8 ++++
 ui/curses.c                       | 11 +++---
 ui/gtk.c                          | 28 ++++++++++++++
 util/main-loop.c                  | 21 ++++++++++
 31 files changed, 356 insertions(+), 11 deletions(-)

---
base-commit: cc329c491768b2d91eb0b0984f3baa0bf805776d
change-id: 20250912-console-resize-96c42140ba08

Best regards,

Signature · 1 line
Filip Hejsek <[email protected]>
#5 lore raw

PATCH v7 4/12 char-mux: add support for the terminal size

From: Szymon Lukasz <[email protected]>

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.

---
 chardev/char-mux.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
chardev/char-mux.c +18 -1
index 881443d869..5a90f0221b 100644
@@ -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)
@@ -378,6 +393,8 @@ static bool mux_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
         return false;
     }
 
+    mux_update_winsize(chr);
+
     /*
      * Only move to opened state if we've realized
      * the initial set of muxes:
Signature · 1 line
2.54.0
#9 lore raw

PATCH v7 8/12 ui/console-vc: forward text console size to vc chardev

In reply to Filip Hejsek

Update the vc chardev size when initializing the console and after changing the surface image.

NOTE: There seems to be a bug in the code where the dpy_text_resize
callback is not called when the size changes due to changing the surface image. (Though it doesn't cause any problem in practice because the callback is only used by ui/ncurses for fixed consoles, whose size never changes.)

---
 ui/console-vc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
ui/console-vc.c +8 -0
index 828e78c41e..d28dc4cdb7 100644
@@ -115,12 +115,19 @@ static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
     return vt100_input(&s->vt, buf, len);
 }
 
+static void text_console_chr_resize(QemuTextConsole *s)
+{
+    qemu_chr_resize(s->chr, s->vt.width, s->vt.height);
+}
+
 static void text_console_invalidate(void *opaque)
 {
     QemuTextConsole *s = QEMU_TEXT_CONSOLE(opaque);
 
     if (!QEMU_IS_FIXED_TEXT_CONSOLE(s)) {
         vt100_set_image(&s->vt, QEMU_CONSOLE(s)->surface->image);
+        text_console_chr_resize(s);
+        /* XXX Shouldn't qemu_text_console_update_size() also be called here? */
     }
     vt100_refresh(&s->vt);
 }
@@ -254,6 +261,7 @@ static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
         s->vt.t_attrib = TEXT_ATTRIBUTES_DEFAULT;
     }
 
+    text_console_chr_resize(s);
     qemu_chr_be_event(chr, CHR_EVENT_OPENED);
     return true;
 }
Signature · 1 line
2.54.0
#11 lore raw

PATCH v7 10/12 qmp: add chardev-window-size-changed command

In reply to Filip Hejsek

From: Szymon Lukasz <[email protected]>

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.

---
 chardev/char.c | 14 ++++++++++++++
 qapi/char.json | 31 +++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
chardev/char.c +14 -0
index d4ef717c56..96e67de815 100644
@@ -1339,6 +1339,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
qapi/char.json +31 -0
index aa5ee9ffcd..d26af6bcc3 100644
@@ -891,6 +891,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
+#
+# @cols: the number of columns
+#
+# @rows: the number of rows
+#
+# Since: 11.1
+#
+# .. 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:
 #
Signature · 1 line
2.54.0
#12 lore raw

PATCH v7 11/12 virtio-serial-bus: add terminal resize messages

In reply to Filip Hejsek

Implement the part of the virtio spec that allows to notify the virtio driver about terminal resizes. Gate the new resize support behind the console-size property, which defaults to off. To implement the property, restore VirtIOSerial::host_features (previously removed by commit d0660e5b7fc7e97926232d13d2500a16df32b310).

The virtio spec contains two methods to inform the guest about console size:

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. Unfortunately, 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 running an old guest kernel, the number of rows and columns will be swapped.

Based on a patch originally written by Szymon Lukasz <[email protected]>, but partially rewritten to fix various corner cases.

---
 hw/char/trace-events              |  1 +
 hw/char/virtio-serial-bus.c       | 81 ++++++++++++++++++++++++++++++++++++++-
 include/hw/virtio/virtio-serial.h |  7 ++++
 3 files changed, 87 insertions(+), 2 deletions(-)
hw/char/trace-events +1 -0
index a3fcc77287..e387c8853f 100644
@@ -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"
hw/char/virtio-serial-bus.c +79 -2

120 lines not on this page · raw message

include/hw/virtio/virtio-serial.h +7 -0
index da0c91e1a4..bda6d5312a 100644
@@ -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 */
@@ -186,6 +189,8 @@ struct VirtIOSerial {
     struct VirtIOSerialPostLoad *post_load;
 
     virtio_serial_conf serial;
+
+    uint64_t host_features;
 };
 
 /* Interface to the virtio-serial bus */
@@ -220,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
Signature · 1 line
2.54.0
#6 lore raw

PATCH v7 5/12 main-loop: change the handling of SIGWINCH

In reply to Filip Hejsek

From: Szymon Lukasz <[email protected]>

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

---
 include/qemu/main-loop.h |  4 ++++
 ui/curses.c              | 11 ++++++-----
 util/main-loop.c         | 21 +++++++++++++++++++++
 3 files changed, 31 insertions(+), 5 deletions(-)
include/qemu/main-loop.h +4 -0
index 8c1241a2c1..ff41346b0b 100644
@@ -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
ui/curses.c +6 -5
index 24d3713e57..04feaeb390 100644
@@ -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) {}
util/main-loop.c +21 -0
index ad8645c30a..136886e4ee 100644
@@ -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)
Signature · 1 line
2.54.0
#7 lore raw

PATCH v7 6/12 char-stdio: add support for the terminal size

In reply to Filip Hejsek

From: Szymon Lukasz <[email protected]>

Update the terminal size upon SIGWINCH delivery.

[Filip: use DECLARE_INSTANCE_CHECKER, qemu_chr_resize_stdio -> stdio_chr_resize]
---
 chardev/char-stdio.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
chardev/char-stdio.c +30 -0
index fe1cbb2d88..4fc8db212c 100644
@@ -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,8 +95,23 @@ static void term_stdio_handler(int sig)
     stdio_chr_set_echo(NULL, stdio_echo_state);
 }
 
+static void stdio_chr_resize(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);
+    stdio_chr_resize(CHARDEV(s));
+}
+
 static bool stdio_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
 {
+    StdioChardev *s = STDIO_CHARDEV(chr);
     ChardevStdio *opts = backend->u.stdio.data;
     struct sigaction act;
 
@@ -121,6 +146,10 @@ static bool stdio_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
     stdio_allow_signal = !opts->has_signal || opts->signal;
     stdio_chr_set_echo(chr, false);
 
+    s->resize_notifier.notify = term_resize_notify;
+    sigwinch_add_notifier(&s->resize_notifier);
+    stdio_chr_resize(chr);
+
     qemu_chr_be_event(chr, CHR_EVENT_OPENED);
     return true;
 }
@@ -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,
Signature · 1 line
2.54.0
#4 lore raw

PATCH v7 3/12 chardev: add qemu_chr_resize()

In reply to Filip Hejsek

From: Szymon Lukasz <[email protected]>

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

---
 chardev/char.c         | 11 +++++++++++
 include/chardev/char.h |  2 ++
 2 files changed, 13 insertions(+)
chardev/char.c +11 -0
index 5e62f2949e..d4ef717c56 100644
@@ -386,6 +386,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)
 {
include/chardev/char.h +2 -0
index ee9f24038b..2616c19cc0 100644
@@ -235,6 +235,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)
 
Signature · 1 line
2.54.0
#15 lore raw

PATCH v7 12/12 virtio-console: notify the guest about terminal resizes

In reply to Filip Hejsek

From: Szymon Lukasz <[email protected]>

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

[Filip: rename things, remove logic that is now handled in virtio-serial-bus.c]
---
 hw/char/virtio-console.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)
hw/char/virtio-console.c +31 -3
index 36ad2ddc3f..db9d8ca797 100644
@@ -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)
 {
@@ -171,6 +180,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;
@@ -179,7 +205,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);
@@ -207,7 +235,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,
@@ -239,7 +267,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 {
Signature · 1 line
2.54.0
#8 lore raw

PATCH v7 7/12 char-win-stdio: add support for terminal size

In reply to Filip Hejsek

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

---
 chardev/char-win-stdio.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
chardev/char-win-stdio.c +19 -0
index bb9c195a8b..188d26502d 100644
@@ -44,6 +44,20 @@ typedef struct WinStdioChardev WinStdioChardev;
 DECLARE_INSTANCE_CHECKER(WinStdioChardev, WIN_STDIO_CHARDEV,
                          TYPE_CHARDEV_WIN_STDIO)
 
+static void win_stdio_chr_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) {
+            win_stdio_chr_resize(chr);
+        }
     }
 }
 
@@ -201,6 +218,8 @@ static bool win_stdio_chr_open(Chardev *chr,
         } else {
             dwMode &= ~ENABLE_PROCESSED_INPUT;
         }
+        dwMode |= ENABLE_WINDOW_INPUT;
+        win_stdio_chr_resize(chr);
     }
 
     SetConsoleMode(stdio->hStdIn, dwMode);
Signature · 1 line
2.54.0
#13 lore raw

Re: [PATCH v7 11/12] virtio-serial-bus: add terminal resize messages

In reply to Filip Hejsek

hw/char/virtio-serial-bus.c static size_t send_control_event(VirtIOSerial *vser, uint32_t port_id, · line 287

Quoted 12 lines · Filip Hejsek
hw/char/virtio-serial-bus.c +0 -0
index cd234dc6db1..a31e80cfdee 100644
@@ -260,6 +260,68 @@ static size_t send_control_event(VirtIOSerial *vser, uint32_t port_id,

[ ... skip 22 lines ... ]

hw/char/virtio-serial-bus.c +6 -0
+
+    if (use_multiport(vser)) {
+        struct {
+            struct virtio_console_control control;
+            struct virtio_console_resize resize;
+        } buffer;

Initialize the buffer to = {},..

hw/char/virtio-serial-bus.c static size_t send_control_event(VirtIOSerial *vser, uint32_t port_id, · line 292

Quoted 5 lines
hw/char/virtio-serial-bus.c +5 -0
+
+        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);

..otherwise whatever is on the stack at control.value is sent to the guest.

Signature · 1 line
Marc-André Lureau <[email protected]>
Reviewed-by on v7 2/12
#3 lore raw

Re: [PATCH v7 02/12] chardev: add CHR_EVENT_RESIZE

In reply to Filip Hejsek
Quoted 19 lines · Filip Hejsek

From: Szymon Lukasz <[email protected]>

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

[Filip: add note that only the focused frontend gets the event]
---
 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 +
Quoted 8 lines
 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(+)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
Reviewed-by on v7 11/12
#14 lore raw

Re: [PATCH v7 11/12] virtio-serial-bus: add terminal resize messages

In reply to Filip Hejsek
Quoted 22 lines · Filip Hejsek

Implement the part of the virtio spec that allows to notify the virtio driver about terminal resizes. Gate the new resize support behind the console-size property, which defaults to off. To implement the property, restore VirtIOSerial::host_features (previously removed by commit d0660e5b7fc7e97926232d13d2500a16df32b310).

The virtio spec contains two methods to inform the guest about console size:

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. Unfortunately, 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 running an old guest kernel, the number of rows and columns will be swapped.

Based on a patch originally written by Szymon Lukasz <[email protected]>, but partially rewritten to fix various corner cases.

Quoted 7 lines
---
 hw/char/trace-events              |  1 +
 hw/char/virtio-serial-bus.c       | 81 ++++++++++++++++++++++++++++++++++++++-
 include/hw/virtio/virtio-serial.h |  7 ++++
 3 files changed, 87 insertions(+), 2 deletions(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#16 lore raw

PATCH 1/1 s390x/sclpconsole: implement resizing for vt220 consoles

In reply to Filip Hejsek

Adds a tty code to indicate a resize frame. The body contains two big endian 16-bit integers rows and columns.

---
Requires the following pre-req:
[PATCH v7 00/12] virtio-console: notify about the terminal size
(https://lore.kernel.org/qemu-devel/[email protected]/)

Testing:
- Tested on QEMU: commit 38879a667f with the following patches applied:
[PATCH v7 00/12] virtio-console: notify about the terminal size
- Tested on linux-next (commit c1f49dea2b8f) with the following patches applied:

    [PATCH 0/2] s390/sclp: Resize for sclp-vt220 console
---
 hw/char/sclpconsole.c | 52 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)
hw/char/sclpconsole.c +51 -1
index 179d12745c..acf1fea6b5 100644
@@ -42,6 +42,7 @@ struct SCLPConsole {
     uint32_t iov_data_len;  /* length of byte stream in buffer             */
     uint32_t iov_sclp_rest; /* length of byte stream not read via SCLP     */
     bool notify;            /* qemu_notify_event() req'd if true           */
+    bool resize;
 };
 typedef struct SCLPConsole SCLPConsole;
 
@@ -81,6 +82,28 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
     sclp_service_interrupt(0);
 }
 
+static void chr_event(void *opaque, QEMUChrEvent event)
+{
+    SCLPConsole *scon = opaque;
+
+    assert(scon);
+
+    switch(event) {
+    case CHR_EVENT_RESIZE:
+    case CHR_EVENT_MUX_IN:
+        scon->resize = true;
+        scon->event.event_pending = true;
+        sclp_service_interrupt(0);
+        break;
+    case CHR_EVENT_BREAK:
+    case CHR_EVENT_OPENED:
+    case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_CLOSED:
+        /* ignore */
+        break;
+    }
+}
+
 /* functions to be called by event facility */
 
 static bool can_handle_event(uint8_t type)
@@ -105,6 +128,28 @@ static void get_console_data(SCLPEvent *event, uint8_t *buf, size_t *size,
                              int avail)
 {
     SCLPConsole *cons = SCLP_CONSOLE(event);
+    uint16_t be_rows, be_cols, rows, cols;
+
+    if (cons->resize) {
+        if (avail < 5) {
+            *size = 0;
+            return;
+        }
+
+        qemu_chr_fe_get_winsize(&cons->chr, &cols, &rows);
+        be_rows = cpu_to_be16(rows);
+        be_cols = cpu_to_be16(cols);
+
+        /* first byte hex 0x08 indicates a new terminal size follows */
+        *buf++ = 0x08;
+        memcpy(buf, &be_rows, sizeof(be_rows));
+        memcpy(buf + 2, &be_cols, sizeof(be_cols));
+        *size = 5;
+
+        cons->resize = false;
+
+        return;
+    }
 
     /* first byte is hex 0 saying an ascii string follows */
     *buf++ = '\0';
@@ -233,7 +278,12 @@ static int console_init(SCLPEvent *event)
     }
     console_available = true;
     qemu_chr_fe_set_handlers(&scon->chr, chr_can_read,
-                             chr_read, NULL, NULL, scon, NULL, true);
+                             chr_read, chr_event, NULL, scon, NULL, true);
+
+    /* set the initial terminal size */
+    scon->resize = true;
+    scon->event.event_pending = true;
+    sclp_service_interrupt(0);
 
     return 0;
 }
Signature · 1 line
2.54.0
#18 lore raw

Re: [PATCH] s390x/sclpconsole: implement resizing for vt220 consoles

In reply to Maximilian Immanuel Brandtner
Quoted 24 lines · Maximilian Immanuel Brandtner

Adds a tty code to indicate a resize frame. The body contains two big endian 16-bit integers rows and columns.

---
Requires the following pre-req:
[PATCH v7 00/12] virtio-console: notify about the terminal size
(https://lore.kernel.org/qemu-devel/[email protected]/)

Testing:
- Tested on QEMU: commit 38879a667f with the following patches applied:
[PATCH v7 00/12] virtio-console: notify about the terminal size
- Tested on linux-next (commit c1f49dea2b8f) with the following patches applied:

    [PATCH 0/2] s390/sclp: Resize for sclp-vt220 console
---
 hw/char/sclpconsole.c | 52 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)
hw/char/sclpconsole.c +0 -0
index 179d12745c..acf1fea6b5 100644

hw/char/sclpconsole.c struct SCLPConsole { · line 45

Quoted 4 lines
hw/char/sclpconsole.c +1 -0
@@ -42,6 +42,7 @@ struct SCLPConsole {
     uint32_t iov_data_len;  /* length of byte stream in buffer             */
     uint32_t iov_sclp_rest; /* length of byte stream not read via SCLP     */
     bool notify;            /* qemu_notify_event() req'd if true           */
+    bool resize;

Does this need to be in vmstate_sclpconsole / included in migration so we don't miss pending resize events during a migration?

Also, should the resize value be explicitly set to false during console_reset()?

[...]

hw/char/sclpconsole.c static void get_console_data(SCLPEvent *event, uint8_t *buf, size_t *size, · line 134

Quoted 8 lines
hw/char/sclpconsole.c +4 -0
@@ -105,6 +128,28 @@ static void get_console_data(SCLPEvent *event, uint8_t *buf, size_t *size,
                              int avail)
 {
     SCLPConsole *cons = SCLP_CONSOLE(event);
+    uint16_t be_rows, be_cols, rows, cols;
+
+    if (cons->resize) {
+        if (avail < 5) {

I dislike the use of a magic number here, when it's tied directly to the combined sizes of a few structures. Can you derive the size instead e.g. sizeof(*buf) + sizeof(be_rows) + sizeof(be_cols);

hw/char/sclpconsole.c static void get_console_data(SCLPEvent *event, uint8_t *buf, size_t *size, · line 147

Quoted 13 lines
hw/char/sclpconsole.c +13 -0
+            *size = 0;
+            return;
+        }
+
+        qemu_chr_fe_get_winsize(&cons->chr, &cols, &rows);
+        be_rows = cpu_to_be16(rows);
+        be_cols = cpu_to_be16(cols);
+
+        /* first byte hex 0x08 indicates a new terminal size follows */
+        *buf++ = 0x08;
+        memcpy(buf, &be_rows, sizeof(be_rows));
+        memcpy(buf + 2, &be_cols, sizeof(be_cols));
+        *size = 5;

Ditto

#19 lore raw

Re: [PATCH] s390x/sclpconsole: implement resizing for vt220 consoles

Quoted 26 lines · Matthew Rosato
Quoted 25 lines · Maximilian Immanuel Brandtner

Adds a tty code to indicate a resize frame. The body contains two big
endian 16-bit integers rows and columns.

---
Requires the following pre-req:
    [PATCH v7 00/12] virtio-console: notify about the terminal size
(https://lore.kernel.org/qemu-devel/20260609-console-resize-v7-0-0c
[email protected]/)

Testing:
- Tested on QEMU: commit 38879a667f with the following patches applied:
    [PATCH v7 00/12] virtio-console: notify about the terminal size
- Tested on linux-next (commit c1f49dea2b8f) with the following patches
  applied:
    [PATCH 0/2] s390/sclp: Resize for sclp-vt220 console
---
 hw/char/sclpconsole.c | 52
++++++++++++++++++++++++++++++++++++++++++-

 1 file changed, 51 insertions(+), 1 deletion(-)
Quoted 16 lines
Quoted 5 lines
hw/char/sclpconsole.c +0 -0
index 179d12745c..acf1fea6b5 100644
@@ -42,6 +42,7 @@ struct SCLPConsole {
Quoted 7 lines

     uint32_t iov_data_len;  /* length of byte stream in buffer             */
     uint32_t iov_sclp_rest; /* length of byte stream not read via SCLP     */
     bool notify;            /* qemu_notify_event() req'd if true           */
+    bool resize;

Does this need to be in vmstate_sclpconsole / included in migration so
we don't miss pending resize events during a migration?

No, console_init() already sets scon->resize = true. So after migration a resize event is always pending.

Quoted 3 lines

Also, should the resize value be explicitly set to false during console_reset()?

Not to false. This would eliminate the initial resize event, because console_reset() runs after console_init(). We need an initial resize event, because the chardev (eg chardev-stdio) might send its initializing resize event before sclpconsole has been initialized. That said, I think it's better for me to move the initial resize code from console_init to console_reset.

Quoted 17 lines

[...]

hw/char/sclpconsole.c static void get_console_data(SCLPEvent *event, · line 135

Quoted 9 lines
hw/char/sclpconsole.c +4 -0
@@ -105,6 +128,28 @@ static void get_console_data(SCLPEvent *event,
 uint8_t *buf, size_t *size,
                               int avail)
  {
      SCLPConsole *cons = SCLP_CONSOLE(event);
+    uint16_t be_rows, be_cols, rows, cols;
+
+    if (cons->resize) {
+        if (avail < 5) {

I dislike the use of a magic number here, when it's tied directly to the
combined sizes of a few structures.  Can you derive the size instead e.g.
sizeof(*buf) + sizeof(be_rows) + sizeof(be_cols);

Sure, though sizeof(*buf) seems misleading, as we're really dealing with a 1-byte header value which just so happens to be the same type as the raw buffer. Looking at the code again though, I think it's best to use a packed struct instead.

Quoted 18 lines
Quoted 10 lines
hw/char/sclpconsole.c +9 -0
+            *size = 0;
+            return;
+        }
+
+        qemu_chr_fe_get_winsize(&cons->chr, &cols, &rows);
+        be_rows = cpu_to_be16(rows);
+        be_cols = cpu_to_be16(cols);
+
+        /* first byte hex 0x08 indicates a new terminal size
Quoted 5 lines

follows */
+        *buf++ = 0x08;
+        memcpy(buf, &be_rows, sizeof(be_rows)); +        memcpy(buf + 2, &be_cols, sizeof(be_cols)); +        *size = 5;

Ditto

#20 lore raw

PATCH v2 1/1 s390x/sclpconsole: implement resizing for vt220 consoles

In reply to Maximilian Immanuel Brandtner

Add a tty code to indicate a resize frame. The body contains two big endian 16-bit integers rows and columns.

After reset, the guest must be informed of the terminal size again. A chardev that doesn't report its size yields 0x0, which shouldn't replace the guest's default.

---
Changelog:
v2:
- Use packed struct and named event type codes for resize frames
- Trigger initial resize event in console_reset() instead of console_init(), skip when chardev reports no size
- Reset event_pending after resize event

Requires the following pre-req:
[PATCH v7 00/12] virtio-console: notify about the terminal size
(https://lore.kernel.org/qemu-devel/[email protected]/)

Testing:
- Tested on QEMU: commit 38879a667f with the following patches applied:
[PATCH v7 00/12] virtio-console: notify about the terminal size
- Tested on linux-next (commit c1f49dea2b8f) with the following patches applied:

    [PATCH 0/2] s390/sclp: Resize for sclp-vt220 console
---
 hw/char/sclpconsole.c | 92 +++++++++++++++++++++++++++++++++++++------
 1 file changed, 80 insertions(+), 12 deletions(-)
hw/char/sclpconsole.c +80 -12
index 179d12745c..12033e1e46 100644
@@ -33,6 +33,9 @@ typedef struct ASCIIConsoleData {
 /* max size for ASCII data in 4K SCCB page */
 #define SIZE_BUFFER_VT220 4080
 
+#define SCLP_CONSOLE_EVENT_TYPE_DATA 0x00
+#define SCLP_CONSOLE_EVENT_TYPE_RESIZE 0x08
+
 struct SCLPConsole {
     SCLPEvent event;
     CharFrontend chr;
@@ -42,6 +45,8 @@ struct SCLPConsole {
     uint32_t iov_data_len;  /* length of byte stream in buffer             */
     uint32_t iov_sclp_rest; /* length of byte stream not read via SCLP     */
     bool notify;            /* qemu_notify_event() req'd if true           */
+    bool resize;
+    bool resize_init;
 };
 typedef struct SCLPConsole SCLPConsole;
 
@@ -49,6 +54,12 @@ typedef struct SCLPConsole SCLPConsole;
 DECLARE_INSTANCE_CHECKER(SCLPConsole, SCLP_CONSOLE,
                          TYPE_SCLP_CONSOLE)
 
+typedef struct SCLPConsoleResizeData {
+    uint8_t type;
+    uint16_t rows;
+    uint16_t cols;
+} QEMU_PACKED SCLPConsoleResizeData;
+
 /* character layer call-back functions */
 
 /* Return number of bytes that fit into iov buffer */
@@ -81,6 +92,29 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
     sclp_service_interrupt(0);
 }
 
+static void chr_event(void *opaque, QEMUChrEvent event)
+{
+    SCLPConsole *scon = opaque;
+
+    assert(scon);
+
+    switch (event) {
+    case CHR_EVENT_RESIZE:
+    case CHR_EVENT_MUX_IN:
+        scon->resize = true;
+        scon->resize_init = false;
+        scon->event.event_pending = true;
+        sclp_service_interrupt(0);
+        break;
+    case CHR_EVENT_BREAK:
+    case CHR_EVENT_OPENED:
+    case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_CLOSED:
+        /* ignore */
+        break;
+    }
+}
+
 /* functions to be called by event facility */
 
 static bool can_handle_event(uint8_t type)
@@ -104,10 +138,37 @@ static sccb_mask_t receive_mask(void)
 static void get_console_data(SCLPEvent *event, uint8_t *buf, size_t *size,
                              int avail)
 {
+    SCLPConsoleResizeData resize_data;
     SCLPConsole *cons = SCLP_CONSOLE(event);
+    uint16_t rows, cols;
+
+    if (cons->resize) {
+        if (avail < sizeof(resize_data)) {
+            *size = 0;
+            return;
+        }
 
-    /* first byte is hex 0 saying an ascii string follows */
-    *buf++ = '\0';
+        qemu_chr_fe_get_winsize(&cons->chr, &cols, &rows);
+
+        if (cons->resize_init && cols == 0 && rows == 0) {
+            *size = 0;
+        } else {
+            resize_data.type = SCLP_CONSOLE_EVENT_TYPE_RESIZE;
+            resize_data.rows = cpu_to_be16(rows);
+            resize_data.cols = cpu_to_be16(cols);
+
+            memcpy(buf, &resize_data, sizeof(resize_data));
+            *size = sizeof(resize_data);
+        }
+
+        cons->resize = false;
+        cons->resize_init = false;
+        event->event_pending = cons->iov_sclp_rest != 0;
+
+        return;
+    }
+
+    *buf++ = SCLP_CONSOLE_EVENT_TYPE_DATA;
     avail--;
     /* if all data fit into provided SCLP buffer */
     if (avail >= cons->iov_sclp_rest) {
@@ -150,6 +211,9 @@ static int read_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr,
     to = (uint8_t *)&acd->data;
     avail = *slen - sizeof(ASCIIConsoleData);
     get_console_data(event, to, &src_len, avail);
+    if (src_len == 0) {
+        return 0;
+    }
 
     acd->ebh.length = cpu_to_be16(sizeof(ASCIIConsoleData) + src_len);
     acd->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA;
@@ -233,22 +297,26 @@ static int console_init(SCLPEvent *event)
     }
     console_available = true;
     qemu_chr_fe_set_handlers(&scon->chr, chr_can_read,
-                             chr_read, NULL, NULL, scon, NULL, true);
+                             chr_read, chr_event, NULL, scon, NULL, true);
 
     return 0;
 }
 
 static void console_reset(DeviceState *dev)
 {
-   SCLPEvent *event = SCLP_EVENT(dev);
-   SCLPConsole *scon = SCLP_CONSOLE(event);
-
-   event->event_pending = false;
-   scon->iov_sclp = 0;
-   scon->iov_bs = 0;
-   scon->iov_data_len = 0;
-   scon->iov_sclp_rest = 0;
-   scon->notify = false;
+    SCLPEvent *event = SCLP_EVENT(dev);
+    SCLPConsole *scon = SCLP_CONSOLE(event);
+
+    scon->iov_sclp = 0;
+    scon->iov_bs = 0;
+    scon->iov_data_len = 0;
+    scon->iov_sclp_rest = 0;
+    scon->notify = false;
+
+    /* the guest defaults its terminal size on reset, announce the real one */
+    scon->resize = true;
+    scon->resize_init = true;
+    event->event_pending = true;
 }
 
 static const Property console_properties[] = {
Signature · 1 line
2.54.0
#31 lore raw
In reply to Filip Hejsek

I would really appreciate it, if this patch-set could be merged. I know that things can get really busy, but it seems to me that there aren't any blockers that should prevent this patch-set from being merged (apart from some minor refactors), even as is. It would be a real shame if all this work were put into this feature, just for it to rot on the mailing-list.

Kind regards,
Max Brandtner

#32 lore raw
Quoted 4 lines · Maximilian Immanuel Brandtner

I would really appreciate it, if this patch-set could be merged. I know that things can get really busy, but it seems to me that there aren't any blockers that should prevent this patch-set from being merged (apart from some minor refactors), even as is.

Why not address the minor comments you got?

Quoted 6 lines

It would be a real shame
if all this work were put into this feature, just for it to rot on the mailing-list.

Kind regards,
Max Brandtner

Reviewer's time is not less valuable.

Signature · 1 line
MST
Reviewed-by on v2 1/1
#21 lore raw

Re: [PATCH v2] s390x/sclpconsole: implement resizing for vt220 consoles

In reply to Maximilian Immanuel Brandtner
Quoted 170 lines · Maximilian Immanuel Brandtner

Add a tty code to indicate a resize frame. The body contains two big endian 16-bit integers rows and columns.

After reset, the guest must be informed of the terminal size again. A chardev that doesn't report its size yields 0x0, which shouldn't replace the guest's default.

---
Changelog:
v2:
- Use packed struct and named event type codes for resize frames
- Trigger initial resize event in console_reset() instead of console_init(), skip when chardev reports no size
- Reset event_pending after resize event

Requires the following pre-req:
[PATCH v7 00/12] virtio-console: notify about the terminal size
(https://lore.kernel.org/qemu-devel/[email protected]/)

Testing:
- Tested on QEMU: commit 38879a667f with the following patches applied:
[PATCH v7 00/12] virtio-console: notify about the terminal size
- Tested on linux-next (commit c1f49dea2b8f) with the following patches applied:

     [PATCH 0/2] s390/sclp: Resize for sclp-vt220 console
---
  hw/char/sclpconsole.c | 92 +++++++++++++++++++++++++++++++++++++------
  1 file changed, 80 insertions(+), 12 deletions(-)
hw/char/sclpconsole.c +71 -12
index 179d12745c..12033e1e46 100644
@@ -33,6 +33,9 @@ typedef struct ASCIIConsoleData {
  /* max size for ASCII data in 4K SCCB page */
  #define SIZE_BUFFER_VT220 4080
 
+#define SCLP_CONSOLE_EVENT_TYPE_DATA 0x00
+#define SCLP_CONSOLE_EVENT_TYPE_RESIZE 0x08
+
  struct SCLPConsole {
      SCLPEvent event;
      CharFrontend chr;
@@ -42,6 +45,8 @@ struct SCLPConsole {
      uint32_t iov_data_len;  /* length of byte stream in buffer             */
      uint32_t iov_sclp_rest; /* length of byte stream not read via SCLP     */
      bool notify;            /* qemu_notify_event() req'd if true           */
+    bool resize;
+    bool resize_init;
  };
  typedef struct SCLPConsole SCLPConsole;
 
@@ -49,6 +54,12 @@ typedef struct SCLPConsole SCLPConsole;
  DECLARE_INSTANCE_CHECKER(SCLPConsole, SCLP_CONSOLE,
                           TYPE_SCLP_CONSOLE)
 
+typedef struct SCLPConsoleResizeData {
+    uint8_t type;
+    uint16_t rows;
+    uint16_t cols;
+} QEMU_PACKED SCLPConsoleResizeData;
+
  /* character layer call-back functions */
 
  /* Return number of bytes that fit into iov buffer */
@@ -81,6 +92,29 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
      sclp_service_interrupt(0);
  }
 
+static void chr_event(void *opaque, QEMUChrEvent event)
+{
+    SCLPConsole *scon = opaque;
+
+    assert(scon);
+
+    switch (event) {
+    case CHR_EVENT_RESIZE:
+    case CHR_EVENT_MUX_IN:
+        scon->resize = true;
+        scon->resize_init = false;
+        scon->event.event_pending = true;
+        sclp_service_interrupt(0);
+        break;
+    case CHR_EVENT_BREAK:
+    case CHR_EVENT_OPENED:
+    case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_CLOSED:
+        /* ignore */
+        break;
+    }
+}
+
  /* functions to be called by event facility */
 
  static bool can_handle_event(uint8_t type)
@@ -104,10 +138,37 @@ static sccb_mask_t receive_mask(void)
  static void get_console_data(SCLPEvent *event, uint8_t *buf, size_t *size,
                               int avail)
  {
+    SCLPConsoleResizeData resize_data;
      SCLPConsole *cons = SCLP_CONSOLE(event);
+    uint16_t rows, cols;
+
+    if (cons->resize) {
+        if (avail < sizeof(resize_data)) {
+            *size = 0;
+            return;
+        }
 
-    /* first byte is hex 0 saying an ascii string follows */
-    *buf++ = '\0';
+        qemu_chr_fe_get_winsize(&cons->chr, &cols, &rows);
+
+        if (cons->resize_init && cols == 0 && rows == 0) {
+            *size = 0;
+        } else {
+            resize_data.type = SCLP_CONSOLE_EVENT_TYPE_RESIZE;
+            resize_data.rows = cpu_to_be16(rows);
+            resize_data.cols = cpu_to_be16(cols);
+
+            memcpy(buf, &resize_data, sizeof(resize_data));
+            *size = sizeof(resize_data);
+        }
+
+        cons->resize = false;
+        cons->resize_init = false;
+        event->event_pending = cons->iov_sclp_rest != 0;
+
+        return;
+    }
+
+    *buf++ = SCLP_CONSOLE_EVENT_TYPE_DATA;
      avail--;
      /* if all data fit into provided SCLP buffer */
      if (avail >= cons->iov_sclp_rest) {
@@ -150,6 +211,9 @@ static int read_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr,
      to = (uint8_t *)&acd->data;
      avail = *slen - sizeof(ASCIIConsoleData);
      get_console_data(event, to, &src_len, avail);
+    if (src_len == 0) {
+        return 0;
+    }
      acd->ebh.length = cpu_to_be16(sizeof(ASCIIConsoleData) + src_len);
      acd->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA;
@@ -233,22 +297,26 @@ static int console_init(SCLPEvent *event)
      }
      console_available = true;
      qemu_chr_fe_set_handlers(&scon->chr, chr_can_read,
-                             chr_read, NULL, NULL, scon, NULL, true);
+                             chr_read, chr_event, NULL, scon, NULL, true);
 
      return 0;
  }
 
  static void console_reset(DeviceState *dev)
  {
-   SCLPEvent *event = SCLP_EVENT(dev);
-   SCLPConsole *scon = SCLP_CONSOLE(event);
-
-   event->event_pending = false;
-   scon->iov_sclp = 0;
-   scon->iov_bs = 0;
-   scon->iov_data_len = 0;
-   scon->iov_sclp_rest = 0;
-   scon->notify = false;
+    SCLPEvent *event = SCLP_EVENT(dev);
+    SCLPConsole *scon = SCLP_CONSOLE(event);
+
+    scon->iov_sclp = 0;

hw/char/sclpconsole.c static int console_init(SCLPEvent *event) · line 320

Quoted 10 lines
hw/char/sclpconsole.c +9 -0
+    scon->iov_bs = 0;
+    scon->iov_data_len = 0;
+    scon->iov_sclp_rest = 0;
+    scon->notify = false;
+
+    /* the guest defaults its terminal size on reset, announce the real one */
+    scon->resize = true;
+    scon->resize_init = true;
+    event->event_pending = true;
  }

This is a style fix, included in a functional patch. I suppose it is probably borderline, but it might be best to put this in its own patch.

Other than that:

#22 lore raw

Re: [PATCH v2] s390x/sclpconsole: implement resizing for vt220 consoles

Quoted 199 lines · Jason J. Herne
Quoted 196 lines · Maximilian Immanuel Brandtner

Add a tty code to indicate a resize frame. The body contains two big
endian 16-bit integers rows and columns.

After reset, the guest must be informed of the terminal size again. A
chardev that doesn't report its size yields 0x0, which shouldn't replace
the guest's default.

---
Changelog:
v2:
- Use packed struct and named event type codes for resize frames
- Trigger initial resize event in console_reset() instead of console_init(), skip when chardev reports no size
- Reset event_pending after resize event

Requires the following pre-req:
     [PATCH v7 00/12] virtio-console: notify about the terminal size

(https://lore.kernel.org/qemu-devel/20260609-console-resize-v7-0-0c
[email protected]/)

Testing:
- Tested on QEMU: commit 38879a667f with the following patches applied:
     [PATCH v7 00/12] virtio-console: notify about the terminal size
- Tested on linux-next (commit c1f49dea2b8f) with the following patches
   applied:
     [PATCH 0/2] s390/sclp: Resize for sclp-vt220 console
---
  hw/char/sclpconsole.c | 92 +++++++++++++++++++++++++++++++++++++-
-----

  1 file changed, 80 insertions(+), 12 deletions(-)
hw/char/sclpconsole.c +0 -0
index 179d12745c..12033e1e46 100644
@@ -33,6 +33,9 @@ typedef struct ASCIIConsoleData {
   /* max size for ASCII data in 4K SCCB page */
   #define SIZE_BUFFER_VT220 4080

hw/char/sclpconsole.c +3 -0
+#define SCLP_CONSOLE_EVENT_TYPE_DATA 0x00
+#define SCLP_CONSOLE_EVENT_TYPE_RESIZE 0x08
+

  struct SCLPConsole {
      SCLPEvent event;
      CharFrontend chr;

hw/char/sclpconsole.c +0 -0
@@ -42,6 +45,8 @@ struct SCLPConsole {

      uint32_t iov_data_len;  /* length of byte stream in buffer             */
      uint32_t iov_sclp_rest; /* length of byte stream not read via SCLP     */
      bool notify;            /* qemu_notify_event() req'd if true           */
+    bool resize;
+    bool resize_init;
  };
  typedef struct SCLPConsole SCLPConsole;

hw/char/sclpconsole.c +0 -0
@@ -49,6 +54,12 @@ typedef struct SCLPConsole SCLPConsole;
   DECLARE_INSTANCE_CHECKER(SCLPConsole, SCLP_CONSOLE,
                            TYPE_SCLP_CONSOLE)

hw/char/sclpconsole.c +6 -0
+typedef struct SCLPConsoleResizeData {
+    uint8_t type;
+    uint16_t rows;
+    uint16_t cols;
+} QEMU_PACKED SCLPConsoleResizeData;
+

  /* character layer call-back functions */

  /* Return number of bytes that fit into iov buffer */

hw/char/sclpconsole.c +0 -0
@@ -81,6 +92,29 @@ static void chr_read(void *opaque, const uint8_t
 *buf, int size)
       sclp_service_interrupt(0);
   }

hw/char/sclpconsole.c +23 -0
+static void chr_event(void *opaque, QEMUChrEvent event)
+{
+    SCLPConsole *scon = opaque;
+
+    assert(scon);
+
+    switch (event) {
+    case CHR_EVENT_RESIZE:
+    case CHR_EVENT_MUX_IN:
+        scon->resize = true;
+        scon->resize_init = false;
+        scon->event.event_pending = true;
+        sclp_service_interrupt(0);
+        break;
+    case CHR_EVENT_BREAK:
+    case CHR_EVENT_OPENED:
+    case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_CLOSED:
+        /* ignore */
+        break;
+    }
+}
+

  /* functions to be called by event facility */

  static bool can_handle_event(uint8_t type)

hw/char/sclpconsole.c +8 -0
@@ -104,10 +138,37 @@ static sccb_mask_t receive_mask(void)
   static void get_console_data(SCLPEvent *event, uint8_t *buf,
 size_t *size,
                                int avail)
   {
+    SCLPConsoleResizeData resize_data;
       SCLPConsole *cons = SCLP_CONSOLE(event);
+    uint16_t rows, cols;
+
+    if (cons->resize) {
+        if (avail < sizeof(resize_data)) {
+            *size = 0;
+            return;
+        }


-    /* first byte is hex 0 saying an ascii string follows */ -    *buf++ = '\0';
+        qemu_chr_fe_get_winsize(&cons->chr, &cols, &rows);

hw/char/sclpconsole.c +20 -0
+
+        if (cons->resize_init && cols == 0 && rows == 0) {
+            *size = 0;
+        } else {
+            resize_data.type = SCLP_CONSOLE_EVENT_TYPE_RESIZE;
+            resize_data.rows = cpu_to_be16(rows);
+            resize_data.cols = cpu_to_be16(cols);
+
+            memcpy(buf, &resize_data, sizeof(resize_data));
+            *size = sizeof(resize_data);
+        }
+
+        cons->resize = false;
+        cons->resize_init = false;
+        event->event_pending = cons->iov_sclp_rest != 0;
+
+        return;
+    }
+
+    *buf++ = SCLP_CONSOLE_EVENT_TYPE_DATA;

      avail--;
      /* if all data fit into provided SCLP buffer */ if (avail >= cons->iov_sclp_rest) {

hw/char/sclpconsole.c +3 -0
@@ -150,6 +211,9 @@ static int read_event_data(SCLPEvent *event,
 EventBufferHeader *evt_buf_hdr,
       to = (uint8_t *)&acd->data;
       avail = *slen - sizeof(ASCIIConsoleData);
       get_console_data(event, to, &src_len, avail);
+    if (src_len == 0) {
+        return 0;
+    }

      acd->ebh.length = cpu_to_be16(sizeof(ASCIIConsoleData) + src_len);
      acd->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA;

hw/char/sclpconsole.c +1 -1
@@ -233,22 +297,26 @@ static int console_init(SCLPEvent *event)
       }
       console_available = true;
       qemu_chr_fe_set_handlers(&scon->chr, chr_can_read,
-                             chr_read, NULL, NULL, scon, NULL,
 true);
+                             chr_read, chr_event, NULL, scon,
 NULL, true);


      return 0;
  }

  static void console_reset(DeviceState *dev)
  {
-   SCLPEvent *event = SCLP_EVENT(dev);
-   SCLPConsole *scon = SCLP_CONSOLE(event);

hw/char/sclpconsole.c +10 -7
-
-   event->event_pending = false;
-   scon->iov_sclp = 0;
-   scon->iov_bs = 0;
-   scon->iov_data_len = 0;
-   scon->iov_sclp_rest = 0;
-   scon->notify = false;
+    SCLPEvent *event = SCLP_EVENT(dev);
+    SCLPConsole *scon = SCLP_CONSOLE(event);
+
+    scon->iov_sclp = 0;
+    scon->iov_bs = 0;
+    scon->iov_data_len = 0;
+    scon->iov_sclp_rest = 0;
+    scon->notify = false;
+
+    /* the guest defaults its terminal size on reset, announce the

real one */

Quoted 8 lines
Quoted 4 lines

+    scon->resize = true;
+    scon->resize_init = true;
+    event->event_pending = true;
  }

This is a style fix, included in a functional patch. I suppose it is probably borderline, but it might be best to put this in its own patch.

I thought about that, but concluded that a 6-line indentation commit would be too small to warrant its own patch. If you'd prefer it to be split I could also send it as a seperate patch.

Quoted 3 lines

Other than that:

Thanks

Reviewed-by
#23 lore raw

Re: [PATCH v2] s390x/sclpconsole: implement resizing for vt220 consoles

Quoted 209 lines · Maximilian Immanuel Brandtner
Quoted 199 lines · Jason J. Herne
Quoted 196 lines · Maximilian Immanuel Brandtner

Add a tty code to indicate a resize frame. The body contains two big
endian 16-bit integers rows and columns.

After reset, the guest must be informed of the terminal size again. A
chardev that doesn't report its size yields 0x0, which shouldn't replace
the guest's default.

---
Changelog:
v2:
- Use packed struct and named event type codes for resize frames
- Trigger initial resize event in console_reset() instead of console_init(), skip when chardev reports no size
- Reset event_pending after resize event

Requires the following pre-req:
     [PATCH v7 00/12] virtio-console: notify about the terminal size

(https://lore.kernel.org/qemu-devel/20260609-console-resize-v7-0-0c
[email protected]/)

Testing:
- Tested on QEMU: commit 38879a667f with the following patches applied:
     [PATCH v7 00/12] virtio-console: notify about the terminal size
- Tested on linux-next (commit c1f49dea2b8f) with the following patches
   applied:
     [PATCH 0/2] s390/sclp: Resize for sclp-vt220 console
---
  hw/char/sclpconsole.c | 92 +++++++++++++++++++++++++++++++++++++-
-----

  1 file changed, 80 insertions(+), 12 deletions(-)
hw/char/sclpconsole.c +0 -0
index 179d12745c..12033e1e46 100644
@@ -33,6 +33,9 @@ typedef struct ASCIIConsoleData {
   /* max size for ASCII data in 4K SCCB page */
   #define SIZE_BUFFER_VT220 4080

hw/char/sclpconsole.c +3 -0
+#define SCLP_CONSOLE_EVENT_TYPE_DATA 0x00
+#define SCLP_CONSOLE_EVENT_TYPE_RESIZE 0x08
+

  struct SCLPConsole {
      SCLPEvent event;
      CharFrontend chr;

hw/char/sclpconsole.c +0 -0
@@ -42,6 +45,8 @@ struct SCLPConsole {

      uint32_t iov_data_len;  /* length of byte stream in buffer             */
      uint32_t iov_sclp_rest; /* length of byte stream not read via SCLP     */
      bool notify;            /* qemu_notify_event() req'd if true           */
+    bool resize;
+    bool resize_init;
  };
  typedef struct SCLPConsole SCLPConsole;

hw/char/sclpconsole.c +0 -0
@@ -49,6 +54,12 @@ typedef struct SCLPConsole SCLPConsole;
   DECLARE_INSTANCE_CHECKER(SCLPConsole, SCLP_CONSOLE,
                            TYPE_SCLP_CONSOLE)

hw/char/sclpconsole.c +6 -0
+typedef struct SCLPConsoleResizeData {
+    uint8_t type;
+    uint16_t rows;
+    uint16_t cols;
+} QEMU_PACKED SCLPConsoleResizeData;
+

  /* character layer call-back functions */

  /* Return number of bytes that fit into iov buffer */

hw/char/sclpconsole.c +0 -0
@@ -81,6 +92,29 @@ static void chr_read(void *opaque, const uint8_t
 *buf, int size)
       sclp_service_interrupt(0);
   }

hw/char/sclpconsole.c +23 -0
+static void chr_event(void *opaque, QEMUChrEvent event)
+{
+    SCLPConsole *scon = opaque;
+
+    assert(scon);
+
+    switch (event) {
+    case CHR_EVENT_RESIZE:
+    case CHR_EVENT_MUX_IN:
+        scon->resize = true;
+        scon->resize_init = false;
+        scon->event.event_pending = true;
+        sclp_service_interrupt(0);
+        break;
+    case CHR_EVENT_BREAK:
+    case CHR_EVENT_OPENED:
+    case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_CLOSED:
+        /* ignore */
+        break;
+    }
+}
+

  /* functions to be called by event facility */

  static bool can_handle_event(uint8_t type)

hw/char/sclpconsole.c +8 -0
@@ -104,10 +138,37 @@ static sccb_mask_t receive_mask(void)
   static void get_console_data(SCLPEvent *event, uint8_t *buf,
 size_t *size,
                                int avail)
   {
+    SCLPConsoleResizeData resize_data;
       SCLPConsole *cons = SCLP_CONSOLE(event);
+    uint16_t rows, cols;
+
+    if (cons->resize) {
+        if (avail < sizeof(resize_data)) {
+            *size = 0;
+            return;
+        }


-    /* first byte is hex 0 saying an ascii string follows */ -    *buf++ = '\0';
+        qemu_chr_fe_get_winsize(&cons->chr, &cols, &rows);

hw/char/sclpconsole.c +20 -0
+
+        if (cons->resize_init && cols == 0 && rows == 0) {
+            *size = 0;
+        } else {
+            resize_data.type = SCLP_CONSOLE_EVENT_TYPE_RESIZE;
+            resize_data.rows = cpu_to_be16(rows);
+            resize_data.cols = cpu_to_be16(cols);
+
+            memcpy(buf, &resize_data, sizeof(resize_data));
+            *size = sizeof(resize_data);
+        }
+
+        cons->resize = false;
+        cons->resize_init = false;
+        event->event_pending = cons->iov_sclp_rest != 0;
+
+        return;
+    }
+
+    *buf++ = SCLP_CONSOLE_EVENT_TYPE_DATA;

      avail--;
      /* if all data fit into provided SCLP buffer */ if (avail >= cons->iov_sclp_rest) {

hw/char/sclpconsole.c +3 -0
@@ -150,6 +211,9 @@ static int read_event_data(SCLPEvent *event,
 EventBufferHeader *evt_buf_hdr,
       to = (uint8_t *)&acd->data;
       avail = *slen - sizeof(ASCIIConsoleData);
       get_console_data(event, to, &src_len, avail);
+    if (src_len == 0) {
+        return 0;
+    }

      acd->ebh.length = cpu_to_be16(sizeof(ASCIIConsoleData) + src_len);
      acd->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA;

hw/char/sclpconsole.c +1 -1
@@ -233,22 +297,26 @@ static int console_init(SCLPEvent *event)
       }
       console_available = true;
       qemu_chr_fe_set_handlers(&scon->chr, chr_can_read,
-                             chr_read, NULL, NULL, scon, NULL,
 true);
+                             chr_read, chr_event, NULL, scon,
 NULL, true);


      return 0;
  }

  static void console_reset(DeviceState *dev)
  {
-   SCLPEvent *event = SCLP_EVENT(dev);
-   SCLPConsole *scon = SCLP_CONSOLE(event);

hw/char/sclpconsole.c +10 -7
-
-   event->event_pending = false;
-   scon->iov_sclp = 0;
-   scon->iov_bs = 0;
-   scon->iov_data_len = 0;
-   scon->iov_sclp_rest = 0;
-   scon->notify = false;
+    SCLPEvent *event = SCLP_EVENT(dev);
+    SCLPConsole *scon = SCLP_CONSOLE(event);
+
+    scon->iov_sclp = 0;
+    scon->iov_bs = 0;
+    scon->iov_data_len = 0;
+    scon->iov_sclp_rest = 0;
+    scon->notify = false;
+
+    /* the guest defaults its terminal size on reset, announce the

real one */

Quoted 8 lines
Quoted 4 lines

+    scon->resize = true;
+    scon->resize_init = true;
+    event->event_pending = true;
  }

This is a style fix, included in a functional patch. I suppose it is probably borderline, but it might be best to put this in its own patch.

Quoted 3 lines

I thought about that, but concluded that a 6-line indentation commit would be too small to warrant its own patch. If you'd prefer it to be split I could also send it as a seperate patch.

I would prefer it in its own patch if possible as a preparatory commit prior to this one. It keeps git blame easier to read if we have issues later and are trying to sort out where the functional changes occurred vs what was just whitespace cleanup.

With the whitespace changes broken out:

#33 lore raw
In reply to Michael S. Tsirkin
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines · Maximilian Immanuel Brandtner

I would really appreciate it, if this patch-set could be merged. I know that things can get really busy, but it seems to me that there aren't any blockers that should prevent this patch-set from being merged (apart from some minor refactors), even as is.

Why not address the minor comments you got?

Just to clarify, Max did not write the subject series; he is expressing interest in it because he wrote a patch that builds upon it for s390x [1].

Now, I'm not asking anyone to take code that isn't ready; but I would like to understand if this series is abandoned or if the developer is planning to send a v8 so we (s390x maintainers) know what to do about Max's patch.

@Filip, do you plan to respin and address the comments you received? There isn't much, but it looks like there was at least one real bug identified.

Thanks,
Matt

[1] https://lore.kernel.org/qemu-devel/[email protected]/

#34 lore raw
Quoted 14 lines · Matthew Rosato
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines · Maximilian Immanuel Brandtner

I would really appreciate it, if this patch-set could be merged. I know that things can get really busy, but it seems to me that there aren't any blockers that should prevent this patch-set from being merged (apart from some minor refactors), even as is.

Why not address the minor comments you got?

Just to clarify, Max did not write the subject series; he is expressing interest in it because he wrote a patch that builds upon it for s390x [1].

Quoted 8 lines

Now, I'm not asking anyone to take code that isn't ready; but I would like to understand if this series is abandoned or if the developer is planning to send a v8 so we (s390x maintainers) know what to do about Max's patch.

@Filip, do you plan to respin and address the comments you received? There isn't much, but it looks like there was at least one real bug identified.

The series also has conflicts with Git master, so cannot be applied as is.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#36 lore raw
In reply to Matthew Rosato
Quoted 19 lines · Matthew Rosato
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines · Maximilian Immanuel Brandtner

I would really appreciate it, if this patch-set could be merged. I know that things can get really busy, but it seems to me that there aren't any blockers that should prevent this patch-set from being merged (apart from some minor refactors), even as is.

Why not address the minor comments you got?

Just to clarify, Max did not write the subject series; he is expressing interest in it because he wrote a patch that builds upon it for s390x [1].

Now, I'm not asking anyone to take code that isn't ready; but I would like to understand if this series is abandoned or if the developer is planning to send a v8 so we (s390x maintainers) know what to do about Max's patch.

Quoted 8 lines

@Filip, do you plan to respin and address the comments you received? There isn't much, but it looks like there was at least one real bug identified.

Thanks,
Matt

[1] https://lore.kernel.org/qemu-devel/[email protected]/

This is what I am saying. It's been since June. Whoever wants this, should clean it up and repost.

Signature · 1 line
MST
#24 lore raw

v3 cover s390x/sclpconsole: implement resizing for vt220 consoles

In reply to Maximilian Immanuel Brandtner

This patch-set implements resize event handling for the vt220 console. Add a tty code to indicate a resize frame. The body contains two big endian 16-bit integers rows and columns.
---
Changelog:
v3:
- split console_reset indentation fix into its own patch

v2:
- Use packed struct and named event type codes for resize frames
- Trigger initial resize event in console_reset() instead of console_init(), skip when chardev reports no size
- Reset event_pending after resize event

Requires the following pre-req:
[PATCH v7 00/12] virtio-console: notify about the terminal size
(https://lore.kernel.org/qemu-devel/[email protected]/)

Testing:
- Tested on QEMU: commit 38879a667f with the following patches applied:
[PATCH v7 00/12] virtio-console: notify about the terminal size
- Tested on linux-next (commit c1f49dea2b8f) with the following patches applied:

    [PATCH 0/2] s390/sclp: Resize for sclp-vt220 console

Maximilian Immanuel Brandtner (2):
s390x/sclpconsole: fix indentation for console_reset s390x/sclpconsole: implement resizing for vt220 consoles

 hw/char/sclpconsole.c | 92 +++++++++++++++++++++++++++++++++++++------
 1 file changed, 80 insertions(+), 12 deletions(-)
Signature · 1 line
2.54.0
#25 lore raw

PATCH v3 1/2 s390x/sclpconsole: fix indentation for console_reset

Adjust indentation to match the rest of the file. No functional change intended.

---
 hw/char/sclpconsole.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
hw/char/sclpconsole.c +9 -9
index 179d12745c..1ad39084d3 100644
@@ -240,15 +240,15 @@ static int console_init(SCLPEvent *event)
 
 static void console_reset(DeviceState *dev)
 {
-   SCLPEvent *event = SCLP_EVENT(dev);
-   SCLPConsole *scon = SCLP_CONSOLE(event);
-
-   event->event_pending = false;
-   scon->iov_sclp = 0;
-   scon->iov_bs = 0;
-   scon->iov_data_len = 0;
-   scon->iov_sclp_rest = 0;
-   scon->notify = false;
+    SCLPEvent *event = SCLP_EVENT(dev);
+    SCLPConsole *scon = SCLP_CONSOLE(event);
+
+    event->event_pending = false;
+    scon->iov_sclp = 0;
+    scon->iov_bs = 0;
+    scon->iov_data_len = 0;
+    scon->iov_sclp_rest = 0;
+    scon->notify = false;
 }
 
 static const Property console_properties[] = {
Signature · 1 line
2.54.0
#28 lore raw

PATCH v3 2/2 s390x/sclpconsole: implement resizing for vt220 consoles

In reply to Maximilian Immanuel Brandtner

Add a tty code to indicate a resize frame. The body contains two big endian 16-bit integers rows and columns.

After reset, the guest must be informed of the terminal size again. A chardev that doesn't report its size yields 0x0, which shouldn't replace the guest's default.

---
Changelog:
v3:
- split console_reset indentation fix into its own patch

v2:
- Use packed struct and named event type codes for resize frames
- Trigger initial resize event in console_reset() instead of console_init(), skip when chardev reports no size
- Reset event_pending after resize event

Requires the following pre-req:
[PATCH v7 00/12] virtio-console: notify about the terminal size
(https://lore.kernel.org/qemu-devel/[email protected]/)

Testing:
- Tested on QEMU: commit 38879a667f with the following patches applied:
[PATCH v7 00/12] virtio-console: notify about the terminal size
- Tested on linux-next (commit c1f49dea2b8f) with the following patches applied:

    [PATCH 0/2] s390/sclp: Resize for sclp-vt220 console
---
 hw/char/sclpconsole.c | 76 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 72 insertions(+), 4 deletions(-)
hw/char/sclpconsole.c +72 -4
index 1ad39084d3..12033e1e46 100644
@@ -33,6 +33,9 @@ typedef struct ASCIIConsoleData {
 /* max size for ASCII data in 4K SCCB page */
 #define SIZE_BUFFER_VT220 4080
 
+#define SCLP_CONSOLE_EVENT_TYPE_DATA 0x00
+#define SCLP_CONSOLE_EVENT_TYPE_RESIZE 0x08
+
 struct SCLPConsole {
     SCLPEvent event;
     CharFrontend chr;
@@ -42,6 +45,8 @@ struct SCLPConsole {
     uint32_t iov_data_len;  /* length of byte stream in buffer             */
     uint32_t iov_sclp_rest; /* length of byte stream not read via SCLP     */
     bool notify;            /* qemu_notify_event() req'd if true           */
+    bool resize;
+    bool resize_init;
 };
 typedef struct SCLPConsole SCLPConsole;
 
@@ -49,6 +54,12 @@ typedef struct SCLPConsole SCLPConsole;
 DECLARE_INSTANCE_CHECKER(SCLPConsole, SCLP_CONSOLE,
                          TYPE_SCLP_CONSOLE)
 
+typedef struct SCLPConsoleResizeData {
+    uint8_t type;
+    uint16_t rows;
+    uint16_t cols;
+} QEMU_PACKED SCLPConsoleResizeData;
+
 /* character layer call-back functions */
 
 /* Return number of bytes that fit into iov buffer */
@@ -81,6 +92,29 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
     sclp_service_interrupt(0);
 }
 
+static void chr_event(void *opaque, QEMUChrEvent event)
+{
+    SCLPConsole *scon = opaque;
+
+    assert(scon);
+
+    switch (event) {
+    case CHR_EVENT_RESIZE:
+    case CHR_EVENT_MUX_IN:
+        scon->resize = true;
+        scon->resize_init = false;
+        scon->event.event_pending = true;
+        sclp_service_interrupt(0);
+        break;
+    case CHR_EVENT_BREAK:
+    case CHR_EVENT_OPENED:
+    case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_CLOSED:
+        /* ignore */
+        break;
+    }
+}
+
 /* functions to be called by event facility */
 
 static bool can_handle_event(uint8_t type)
@@ -104,10 +138,37 @@ static sccb_mask_t receive_mask(void)
 static void get_console_data(SCLPEvent *event, uint8_t *buf, size_t *size,
                              int avail)
 {
+    SCLPConsoleResizeData resize_data;
     SCLPConsole *cons = SCLP_CONSOLE(event);
+    uint16_t rows, cols;
 
-    /* first byte is hex 0 saying an ascii string follows */
-    *buf++ = '\0';
+    if (cons->resize) {
+        if (avail < sizeof(resize_data)) {
+            *size = 0;
+            return;
+        }
+
+        qemu_chr_fe_get_winsize(&cons->chr, &cols, &rows);
+
+        if (cons->resize_init && cols == 0 && rows == 0) {
+            *size = 0;
+        } else {
+            resize_data.type = SCLP_CONSOLE_EVENT_TYPE_RESIZE;
+            resize_data.rows = cpu_to_be16(rows);
+            resize_data.cols = cpu_to_be16(cols);
+
+            memcpy(buf, &resize_data, sizeof(resize_data));
+            *size = sizeof(resize_data);
+        }
+
+        cons->resize = false;
+        cons->resize_init = false;
+        event->event_pending = cons->iov_sclp_rest != 0;
+
+        return;
+    }
+
+    *buf++ = SCLP_CONSOLE_EVENT_TYPE_DATA;
     avail--;
     /* if all data fit into provided SCLP buffer */
     if (avail >= cons->iov_sclp_rest) {
@@ -150,6 +211,9 @@ static int read_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr,
     to = (uint8_t *)&acd->data;
     avail = *slen - sizeof(ASCIIConsoleData);
     get_console_data(event, to, &src_len, avail);
+    if (src_len == 0) {
+        return 0;
+    }
 
     acd->ebh.length = cpu_to_be16(sizeof(ASCIIConsoleData) + src_len);
     acd->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA;
@@ -233,7 +297,7 @@ static int console_init(SCLPEvent *event)
     }
     console_available = true;
     qemu_chr_fe_set_handlers(&scon->chr, chr_can_read,
-                             chr_read, NULL, NULL, scon, NULL, true);
+                             chr_read, chr_event, NULL, scon, NULL, true);
 
     return 0;
 }
@@ -243,12 +307,16 @@ static void console_reset(DeviceState *dev)
     SCLPEvent *event = SCLP_EVENT(dev);
     SCLPConsole *scon = SCLP_CONSOLE(event);
 
-    event->event_pending = false;
     scon->iov_sclp = 0;
     scon->iov_bs = 0;
     scon->iov_data_len = 0;
     scon->iov_sclp_rest = 0;
     scon->notify = false;
+
+    /* the guest defaults its terminal size on reset, announce the real one */
+    scon->resize = true;
+    scon->resize_init = true;
+    event->event_pending = true;
 }
 
 static const Property console_properties[] = {
Signature · 1 line
2.54.0
Reviewed-by on v3 1/2
#26 lore raw

Re: [PATCH v3 1/2] s390x/sclpconsole: fix indentation for console_reset

In reply to Maximilian Immanuel Brandtner
Quoted 4 lines · Maximilian Immanuel Brandtner

Adjust indentation to match the rest of the file. No functional change intended.

Thanks.

@Eric this whitespace fixup applies cleanly to master and could get applied separately if you care to -- or it can remain bundled with the resize patch (patch 2 of this series) until we sort out the fate of the pre-req virtio-console series.

Thanks,
Matt

#27 lore raw

Re: [PATCH v3 1/2] s390x/sclpconsole: fix indentation for console_reset

Quoted 6 lines · Matthew Rosato
Quoted 4 lines · Maximilian Immanuel Brandtner

Adjust indentation to match the rest of the file. No functional change intended.

Quoted 8 lines

Thanks.

@Eric this whitespace fixup applies cleanly to master and could get applied separately if you care to -- or it can remain bundled with the resize patch (patch 2 of this series) until we sort out the fate of the pre-req virtio-console series.

Thanks Matt (and Max!).

I'll pick this up for the next PR, so we're not dragging it along. Then it's just the pre-req and functional piece in the future.

Quoted 6 lines

Thanks,
Matt

#35 lore raw
In reply to Daniel P. Berrangé
Quoted 24 lines · Daniel P. Berrangé
Quoted 14 lines · Matthew Rosato
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines · Maximilian Immanuel Brandtner

I would really appreciate it, if this patch-set could be merged. I know that things can get really busy, but it seems to me that there aren't any blockers that should prevent this patch-set from being merged (apart from some minor refactors), even as is.

Why not address the minor comments you got?

Just to clarify, Max did not write the subject series; he is expressing interest in it because he wrote a patch that builds upon it for s390x [1].

Quoted 8 lines

Now, I'm not asking anyone to take code that isn't ready; but I would like to understand if this series is abandoned or if the developer is planning to send a v8 so we (s390x maintainers) know what to do about Max's patch.

@Filip, do you plan to respin and address the comments you received? There isn't much, but it looks like there was at least one real bug identified.

Quoted 5 lines

The series also has conflicts with Git master, so cannot be applied as is.

With regards,
Daniel

Hi all,

I've sent a v8 [1], which is a rebase on master plus the uninitialized buffer fix suggested by Marc-André Lureau.

Sorry for the delay, and thanks for the nudge, which got me to come back to it. I do this in my free time, so progress comes in bursts, but feel free to nag me if I don't respond for a while again.

I originally planned to include a fix for the migration issue in v8 too, but I don't have time right now for implementing the necessary migration stream changes. I think you can merge it without the fix, as it's only a minor issue, but I hope it can be fixed in a follow-up. If someone wants to pick that up, help is welcome. I have a rough WIP refactor of virtio-serial serialization to use VMState at [2], which might be useful as a starting point if that is the chosen approach.

Matthew, Max: I hope this unblocks the s390x patch.

[1]: https://lore.kernel.org/qemu-devel/[email protected]
[2]: https://gitlab.com/filip-hejsek/qemu/-/commits/b4/virtio-serial-vmstate

Best regards,
Filip

Tested-by on v3 2/2
#29 lore raw

Re: [PATCH v3 2/2] s390x/sclpconsole: implement resizing for vt220 consoles

In reply to Maximilian Immanuel Brandtner
Quoted 10 lines · Maximilian Immanuel Brandtner

Add a tty code to indicate a resize frame. The body contains two big endian 16-bit integers rows and columns.

After reset, the guest must be informed of the terminal size again. A chardev that doesn't report its size yields 0x0, which shouldn't replace the guest's default.

This works well for me.

Quoted 168 lines

---
Changelog:
v3:
- split console_reset indentation fix into its own patch

v2:
- Use packed struct and named event type codes for resize frames
- Trigger initial resize event in console_reset() instead of console_init(), skip when chardev reports no size
- Reset event_pending after resize event

Requires the following pre-req:
[PATCH v7 00/12] virtio-console: notify about the terminal size
(https://lore.kernel.org/qemu-devel/[email protected]/)

Testing:
- Tested on QEMU: commit 38879a667f with the following patches applied:
[PATCH v7 00/12] virtio-console: notify about the terminal size
- Tested on linux-next (commit c1f49dea2b8f) with the following patches applied:

     [PATCH 0/2] s390/sclp: Resize for sclp-vt220 console
---
  hw/char/sclpconsole.c | 76 ++++++++++++++++++++++++++++++++++++++++---
  1 file changed, 72 insertions(+), 4 deletions(-)
hw/char/sclpconsole.c +72 -4
index 1ad39084d3..12033e1e46 100644
@@ -33,6 +33,9 @@ typedef struct ASCIIConsoleData {
  /* max size for ASCII data in 4K SCCB page */
  #define SIZE_BUFFER_VT220 4080
 
+#define SCLP_CONSOLE_EVENT_TYPE_DATA 0x00
+#define SCLP_CONSOLE_EVENT_TYPE_RESIZE 0x08
+
  struct SCLPConsole {
      SCLPEvent event;
      CharFrontend chr;
@@ -42,6 +45,8 @@ struct SCLPConsole {
      uint32_t iov_data_len;  /* length of byte stream in buffer             */
      uint32_t iov_sclp_rest; /* length of byte stream not read via SCLP     */
      bool notify;            /* qemu_notify_event() req'd if true           */
+    bool resize;
+    bool resize_init;
  };
  typedef struct SCLPConsole SCLPConsole;
 
@@ -49,6 +54,12 @@ typedef struct SCLPConsole SCLPConsole;
  DECLARE_INSTANCE_CHECKER(SCLPConsole, SCLP_CONSOLE,
                           TYPE_SCLP_CONSOLE)
 
+typedef struct SCLPConsoleResizeData {
+    uint8_t type;
+    uint16_t rows;
+    uint16_t cols;
+} QEMU_PACKED SCLPConsoleResizeData;
+
  /* character layer call-back functions */
 
  /* Return number of bytes that fit into iov buffer */
@@ -81,6 +92,29 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
      sclp_service_interrupt(0);
  }
 
+static void chr_event(void *opaque, QEMUChrEvent event)
+{
+    SCLPConsole *scon = opaque;
+
+    assert(scon);
+
+    switch (event) {
+    case CHR_EVENT_RESIZE:
+    case CHR_EVENT_MUX_IN:
+        scon->resize = true;
+        scon->resize_init = false;
+        scon->event.event_pending = true;
+        sclp_service_interrupt(0);
+        break;
+    case CHR_EVENT_BREAK:
+    case CHR_EVENT_OPENED:
+    case CHR_EVENT_MUX_OUT:
+    case CHR_EVENT_CLOSED:
+        /* ignore */
+        break;
+    }
+}
+
  /* functions to be called by event facility */
 
  static bool can_handle_event(uint8_t type)
@@ -104,10 +138,37 @@ static sccb_mask_t receive_mask(void)
  static void get_console_data(SCLPEvent *event, uint8_t *buf, size_t *size,
                               int avail)
  {
+    SCLPConsoleResizeData resize_data;
      SCLPConsole *cons = SCLP_CONSOLE(event);
+    uint16_t rows, cols;
 
-    /* first byte is hex 0 saying an ascii string follows */
-    *buf++ = '\0';
+    if (cons->resize) {
+        if (avail < sizeof(resize_data)) {
+            *size = 0;
+            return;
+        }
+
+        qemu_chr_fe_get_winsize(&cons->chr, &cols, &rows);
+
+        if (cons->resize_init && cols == 0 && rows == 0) {
+            *size = 0;
+        } else {
+            resize_data.type = SCLP_CONSOLE_EVENT_TYPE_RESIZE;
+            resize_data.rows = cpu_to_be16(rows);
+            resize_data.cols = cpu_to_be16(cols);
+
+            memcpy(buf, &resize_data, sizeof(resize_data));
+            *size = sizeof(resize_data);
+        }
+
+        cons->resize = false;
+        cons->resize_init = false;
+        event->event_pending = cons->iov_sclp_rest != 0;
+
+        return;
+    }
+
+    *buf++ = SCLP_CONSOLE_EVENT_TYPE_DATA;
      avail--;
      /* if all data fit into provided SCLP buffer */
      if (avail >= cons->iov_sclp_rest) {
@@ -150,6 +211,9 @@ static int read_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr,
      to = (uint8_t *)&acd->data;
      avail = *slen - sizeof(ASCIIConsoleData);
      get_console_data(event, to, &src_len, avail);
+    if (src_len == 0) {
+        return 0;
+    }
 
      acd->ebh.length = cpu_to_be16(sizeof(ASCIIConsoleData) + src_len);
      acd->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA;
@@ -233,7 +297,7 @@ static int console_init(SCLPEvent *event)
      }
      console_available = true;
      qemu_chr_fe_set_handlers(&scon->chr, chr_can_read,
-                             chr_read, NULL, NULL, scon, NULL, true);
+                             chr_read, chr_event, NULL, scon, NULL, true);
 
      return 0;
  }
@@ -243,12 +307,16 @@ static void console_reset(DeviceState *dev)
      SCLPEvent *event = SCLP_EVENT(dev);
      SCLPConsole *scon = SCLP_CONSOLE(event);
 
-    event->event_pending = false;
      scon->iov_sclp = 0;
      scon->iov_bs = 0;
      scon->iov_data_len = 0;
      scon->iov_sclp_rest = 0;
      scon->notify = false;
+
+    /* the guest defaults its terminal size on reset, announce the real one */
+    scon->resize = true;
+    scon->resize_init = true;
+    event->event_pending = true;
  }
 
  static const Property console_properties[] = {
#30 lore raw

Re: [PATCH v3 0/2] s390x/sclpconsole: implement resizing for vt220 consoles

In reply to Maximilian Immanuel Brandtner
Quoted 23 lines · Maximilian Immanuel Brandtner

This patch-set implements resize event handling for the vt220 console. Add a tty code to indicate a resize frame. The body contains two big endian 16-bit integers rows and columns.
---
Changelog:
v3:
- split console_reset indentation fix into its own patch

v2:
- Use packed struct and named event type codes for resize frames
- Trigger initial resize event in console_reset() instead of console_init(), skip when chardev reports no size
- Reset event_pending after resize event

Requires the following pre-req:
[PATCH v7 00/12] virtio-console: notify about the terminal size
(https://lore.kernel.org/qemu-devel/[email protected]/)

Testing:
- Tested on QEMU: commit 38879a667f with the following patches applied:
[PATCH v7 00/12] virtio-console: notify about the terminal size
- Tested on linux-next (commit c1f49dea2b8f) with the following patches applied:

Quoted 9 lines
     [PATCH 0/2] s390/sclp: Resize for sclp-vt220 console

Maximilian Immanuel Brandtner (2):

   s390x/sclpconsole: fix indentation for console_reset
   s390x/sclpconsole: implement resizing for vt220 consoles
  hw/char/sclpconsole.c | 92 +++++++++++++++++++++++++++++++++++++------
  1 file changed, 80 insertions(+), 12 deletions(-)

TLDR: Applied to my 11.2 queue; thanks!

The prereq series went through a few additional versions, ending in v10 [0] which was recently merged [1]. I previously picked up patch 1 of this series [2], and see no concerns with "the meat" of this series.

[0] https://lore.kernel.org/qemu-devel/[email protected]/
[1] https://lore.kernel.org/qemu-devel/[email protected]/
[2] https://lore.kernel.org/qemu-devel/[email protected]/