From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Nicholas Piggin" <npiggin@gmail.com>,
qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Pavel Dovgalyuk" <pavel.dovgaluk@ispras.ru>,
"Cleber Rosa" <crosa@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
"Beraldo Leal" <bleal@redhat.com>,
"Ani Sinha" <anisinha@redhat.com>, "John Snow" <jsnow@redhat.com>,
qemu-ppc@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH 2/3] chardev: report blocked write to chardev backend
Date: Wed, 22 Nov 2023 10:42:45 +0000 [thread overview]
Message-ID: <ZV3bJXOy4vxyHTWK@redhat.com> (raw)
In-Reply-To: <99568f4f-2168-4719-8454-90f0e0658c2c@redhat.com>
On Wed, Nov 22, 2023 at 11:38:28AM +0100, Thomas Huth wrote:
> On 21/11/2023 12.47, Marc-André Lureau wrote:
> > Hi
> >
> > On Tue, Nov 21, 2023 at 1:45 PM Thomas Huth <thuth@redhat.com> wrote:
> > >
> > > On 21/11/2023 10.39, Marc-André Lureau wrote:
> > > > Hi
> > > >
> > > > On Mon, Nov 20, 2023 at 5:36 PM Nicholas Piggin <npiggin@gmail.com> wrote:
> > > > >
> > > > > On Mon Nov 20, 2023 at 10:06 PM AEST, Marc-André Lureau wrote:
> > > > > > Hi
> > > > > >
> > > > > > On Thu, Nov 16, 2023 at 3:54 PM Nicholas Piggin <npiggin@gmail.com> wrote:
> > > > > > >
> > > > > > > If a chardev socket is not read, it will eventually fill and QEMU
> > > > > > > can block attempting to write to it. A difficult bug in avocado
> > > > > > > tests where the console socket was not being read from caused this
> > > > > > > hang.
> > > > > > >
> > > > > > > warn if a chardev write is blocked for 100ms.
> > > > > > >
> > > > > > > Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> > > > > > > ---
> > > > > > > This is not necessary for the fix but it does trigger in the
> > > > > > > failing avocado test without the previous patch applied. Maybe
> > > > > > > it would be helpful?
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Nick
> > > > > > >
> > > > > > > chardev/char.c | 6 ++++++
> > > > > > > 1 file changed, 6 insertions(+)
> > > > > > >
> > > > > > > diff --git a/chardev/char.c b/chardev/char.c
> > > > > > > index 996a024c7a..7c375e3cc4 100644
> > > > > > > --- a/chardev/char.c
> > > > > > > +++ b/chardev/char.c
> > > > > > > @@ -114,6 +114,8 @@ static int qemu_chr_write_buffer(Chardev *s,
> > > > > > > {
> > > > > > > ChardevClass *cc = CHARDEV_GET_CLASS(s);
> > > > > > > int res = 0;
> > > > > > > + int nr_retries = 0;
> > > > > > > +
> > > > > > > *offset = 0;
> > > > > > >
> > > > > > > qemu_mutex_lock(&s->chr_write_lock);
> > > > > > > @@ -126,6 +128,10 @@ static int qemu_chr_write_buffer(Chardev *s,
> > > > > > > } else {
> > > > > > > g_usleep(100);
> > > > > > > }
> > > > > > > + if (++nr_retries == 1000) { /* 100ms */
> > > > > > > + warn_report("Chardev '%s' write blocked for > 100ms, "
> > > > > > > + "socket buffer full?", s->label);
> > > > > > > + }
> > > > > >
> > > > > > That shouldn't happen, the frontend should poll and only write when it
> > > > > > can. What is the qemu command being used here?
> > > > >
> > > > > You can follow it through the thread here
> > > > >
> > > > > https://lore.kernel.org/qemu-devel/ZVT-bY9YOr69QTPX@redhat.com/
> > > > >
> > > > > In short, a console device is attached to a socket pair and nothing
> > > > > ever reads from it. It eventually fills, and writing to it fails
> > > > > indefinitely here.
> > > > >
> > > > > It can be reproduced with:
> > > > >
> > > > > make check-avocado
> > > > > AVOCADO_TESTS=tests/avocado/reverse_debugging.py:test_ppc64_pseries
> > > > >
> > > > >
> > > >
> > > > How reliably? I tried 10/10.
> > >
> > > It used to fail for me every time I tried - but the fix has already been
> > > merged yesterday (commit cd43f00524070c026), so if you updated today, you'll
> > > see the test passing again.
> >
> > Ok so the "frontend" is spapr-vty and there:
> >
> > void vty_putchars(SpaprVioDevice *sdev, uint8_t *buf, int len)
> > {
> > SpaprVioVty *dev = VIO_SPAPR_VTY_DEVICE(sdev);
> >
> > /* XXX this blocks entire thread. Rewrite to use
> > * qemu_chr_fe_write and background I/O callbacks */
> > qemu_chr_fe_write_all(&dev->chardev, buf, len);
> > }
> >
> > (grep "XXX this blocks", we have a lot...)
> >
> > Can H_PUT_TERM_CHAR return the number of bytes written?
>
> You can find the definition of the hypercall in the LoPAPR spec:
>
> https://elinux.org/images/a/a4/LoPAPR_DRAFT_v11_24March2016.pdf
>
> ... and if I get it right, it does not have a way to tell the guest the
> amount of accepted characters. But it could return H_BUSY if it is not able
> to enqueue all characters at once. As far as I can see, this will make the
> guest spin until it can finally send out the characters... not sure whether
> that's so much better...?
If the rest of the guest can get on with useful work that's better. If we
block in QEMU, the entire guest hardware emulation is blocked so nothing
can make progress if it exits from vCPU run context.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2023-11-22 10:43 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-16 11:53 [PATCH 1/3] tests/avocado: reverse_debugging drain console to prevent hang Nicholas Piggin
2023-11-16 11:53 ` [PATCH 2/3] chardev: report blocked write to chardev backend Nicholas Piggin
2023-11-20 12:06 ` Marc-André Lureau
2023-11-20 13:35 ` Nicholas Piggin
2023-11-21 9:39 ` Marc-André Lureau
2023-11-21 9:42 ` Daniel P. Berrangé
2023-11-21 9:44 ` Thomas Huth
2023-11-21 11:47 ` Marc-André Lureau
2023-11-22 9:55 ` Alex Bennée
2023-11-22 10:38 ` Thomas Huth
2023-11-22 10:42 ` Daniel P. Berrangé [this message]
2023-11-16 11:53 ` [PATCH 3/3] tests/avocado: Enable reverse_debugging.py tests in gitlab CI Nicholas Piggin
2023-11-16 12:33 ` Thomas Huth
2023-11-16 18:11 ` Thomas Huth
2023-11-17 7:35 ` Nicholas Piggin
2023-11-21 8:56 ` Thomas Huth
2023-11-21 9:14 ` Daniel P. Berrangé
2023-11-21 9:40 ` Thomas Huth
2023-11-16 13:26 ` [PATCH 1/3] tests/avocado: reverse_debugging drain console to prevent hang Ani Sinha
2023-11-16 13:31 ` Ani Sinha
2023-11-16 13:39 ` Ani Sinha
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=ZV3bJXOy4vxyHTWK@redhat.com \
--to=berrange@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=anisinha@redhat.com \
--cc=bleal@redhat.com \
--cc=crosa@redhat.com \
--cc=jsnow@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=npiggin@gmail.com \
--cc=pavel.dovgaluk@ispras.ru \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=thuth@redhat.com \
--cc=wainersm@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).