All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabiano Rosas <farosas@suse.de>
To: Warner Losh <imp@bsdimp.com>, Peter Maydell <peter.maydell@linaro.org>
Cc: Dave Blanchard <dave@killthe.net>,
	QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: Qemu resets terminal to crazy defaults
Date: Wed, 20 Dec 2023 12:23:08 -0300	[thread overview]
Message-ID: <87a5q4rj8j.fsf@suse.de> (raw)
In-Reply-To: <CANCZdfqX=URh2C+upKQPF9sg9TX6oZpHfrYF6rGRNz-6SdbhLw@mail.gmail.com>

Warner Losh <imp@bsdimp.com> writes:

> On Tue, Dec 19, 2023, 1:55 PM Peter Maydell <peter.maydell@linaro.org>
> wrote:
>
>> On Tue, 19 Dec 2023 at 19:40, Fabiano Rosas <farosas@suse.de> wrote:
>> >
>> > Dave Blanchard <dave@killthe.net> writes:
>> >
>> > > Hello all, can you please help me to understand what Qemu is doing
>> here?
>> > >
>> > > When connecting to the guest for example using a serial/tcp/telnet
>> link, some kind of code is being immediately transmitted over the link
>> which screws up my Xterm terminal settings, including changing the text
>> cursor shape and most notably, disabling wraparound of long lines, so that
>> they get truncated at the edge of the window instead.
>> > >
>> > > Can this behavior be disabled by command line, and if not, what is the
>> code doing exactly so I can know where to disable it? I tried disabling all
>> calls to tcsetattr() but that had no effect.
>>
>> > I looked into the automatic margins issue a long time ago and I seem to
>> > remember it was caused by the firmware (SeaBIOS) configuring the
>> > terminal and QEMU just never returning it to the original state. I
>> > eventually gave up trying to fix it because I was having trouble finding
>> > a reliable point in QEMU shutdown sequence to enable the capability
>> > back. Nowadays I just run 'tput smam' after quitting QEMU.
>>
>> To check whether this is happening because of the BIOS (or other
>> guest code) vs QEMU itself, you can try running QEMU in a configuration
>> where it doesn't run any BIOS code. One I happen to know offhand
>> is an arm one:
>>
>>    qemu-system-aarch64 -M virt -serial stdio
>>
>> This won't print anything, because we haven't loaded any guest
>> code at all and there's no default BIOS on this machine type.
>> (The emulated CPU is sat in effectively a tight loop taking
>> exceptions.) If that messes up the terminal settings, then it's
>> likely being done by something inside QEMU. If it doesn't, then
>> it sounds like as you say it'll be because of the SeaBIOS
>> firmware writing stuff to the terminal.
>>
>> (There might be a way to run the x86 PC machine without it
>> running a BIOS, for a similar test, but I don't know if there
>> is or how to do it off the top of my head.)
>>

I tried using an empty bios file. I see with 'info registers' that the
vcpu is spinning. After quitting QEMU, the terminal state is unchanged:

$ dd if=/dev/zero of=dummy-bios.bin count=256 bs=1k
$ qemu-system-x86_64 -nographic -bios ./dummy-bios.bin
$ <line wrap preserved>

With SeaBIOS, the issue manifests:

$ qemu-system-x86_64 -nographic
SeaBIOS (version rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org)
<bunch of boot and iPXE messages>
...
$ <line wrap disabled>

>> I do know that QEMU doesn't clean up things the guest does
>> to the terminal, because for instance if you have a serial
>> terminal and the guest puts it into "emit boldface/bright",
>> that doesn't go back to normal non-bold text when QEMU exits.
>> (It would be nice if it did do that...)
>>
>
> It would be nice indeed. Trouble is quarrying the state beforehand to know
> what to reset by random software producing effectively random bytes..
>

Maybe we could focus on the more annoying/obvious state? The line wrap
issue is a very salient one, specially since QEMU command lines
themselves tend to take more than one line.

> ESC c
>
> is the reset sequence as well...but that's likely too big a hammer.
>
> Warner
>
> thanks
>> -- PMM
>>
>>


  reply	other threads:[~2023-12-20 15:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19 19:21 Qemu resets terminal to crazy defaults Dave Blanchard
2023-12-19 19:38 ` Warner Losh
2023-12-19 19:38 ` Fabiano Rosas
2023-12-19 20:53   ` Peter Maydell
2023-12-19 21:04     ` Warner Losh
2023-12-20 15:23       ` Fabiano Rosas [this message]
2023-12-20 15:33         ` Dave Blanchard
2023-12-20 16:57         ` BALATON Zoltan
2023-12-21 13:29           ` Fabiano Rosas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a5q4rj8j.fsf@suse.de \
    --to=farosas@suse.de \
    --cc=dave@killthe.net \
    --cc=imp@bsdimp.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.