On Thu, 2026-09-24 at 22:42 -0400, Matthew Rosato wrote:
> 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 <[email protected]>
> > ---
> > 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(-)
> >
> > 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?
No, console_init() already sets scon->resize = true. So after migration
a resize event is always pending.
>
> 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.
> [...]
>
> > @@ -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.
>
> > + *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
>