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

Maximilian Immanuel Brandtner posted 1 patch 5 days, 7 hours ago
hw/char/sclpconsole.c | 52 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
[PATCH] s390x/sclpconsole: implement resizing for vt220 consoles
Posted by Maximilian Immanuel Brandtner 5 days, 7 hours ago
Adds a tty code to indicate a resize frame. The body contains two big
endian 16-bit integers rows and columns.

Signed-off-by: Maximilian Immanuel Brandtner <maxbr@linux.ibm.com>
---
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-0c550fdcec15@gmail.com/)

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(-)

diff --git a/hw/char/sclpconsole.c b/hw/char/sclpconsole.c
index 179d12745c..acf1fea6b5 100644
--- a/hw/char/sclpconsole.c
+++ b/hw/char/sclpconsole.c
@@ -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;
 }
-- 
2.54.0
Re: [PATCH] s390x/sclpconsole: implement resizing for vt220 consoles
Posted by Matthew Rosato 1 day, 16 hours ago
On 9/21/26 8:16 AM, Maximilian Immanuel Brandtner wrote:
> Adds a tty code to indicate a resize frame. The body contains two big
> endian 16-bit integers rows and columns.
> 
> Signed-off-by: Maximilian Immanuel Brandtner <maxbr@linux.ibm.com>
> ---
> 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-0c550fdcec15@gmail.com/)
> 
> 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(-)
> 
> diff --git a/hw/char/sclpconsole.c b/hw/char/sclpconsole.c
> index 179d12745c..acf1fea6b5 100644
> --- a/hw/char/sclpconsole.c
> +++ b/hw/char/sclpconsole.c
> @@ -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()?

[...]

> @@ -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);

> +            *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
Re: [PATCH] s390x/sclpconsole: implement resizing for vt220 consoles
Posted by Maximilian Immanuel Brandtner 5 days, 6 hours ago
For the Linux Kernel patch-set see: [PATCH 0/2] s390/sclp: Resize for
sclp-vt220 console
 
(https://lore.kernel.org/all/20260921121619.1354611-1-
maxbr@linux.ibm.com/T/#t)