Linux virtualization list
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Peng Yang" <peng.yang@oss.qualcomm.com>,
	"Amit Shah" <amit@kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Cc: kernel@quicinc.com, virtualization@lists.linux.dev,
	linux-kernel@vger.kernel.org, kernel@oss.qualcomm.com
Subject: Re: [PATCH] virtio_console: add timeout to __send_to_port() spin loop
Date: Tue, 21 Apr 2026 14:14:42 +0200	[thread overview]
Message-ID: <9e5be98b-3035-4e61-8325-52ed8fcf65fa@app.fastmail.com> (raw)
In-Reply-To: <d6908885-7f87-442c-86de-3a08eadf417f@oss.qualcomm.com>

On Tue, Apr 21, 2026, at 11:18, Peng Yang wrote:
> On 4/21/2026 3:38 PM, Arnd Bergmann wrote:
>> 
>> Which host implementation do you use? The way the virtio_console
>> driver works really assumes that virtqueue_kick() consumes the
>> buffer synchronously. Even though that is not how virtio is
>> specified, this does tend to work. ;-)
>> 
> We are using crosvm as the host VMM with its virtio-console backend,
> running on Android. The trigger is Android host reboot/shutdown: when
> Android initiates a reboot, the crosvm process exits and tears down
> the virtio-console backend. At that point, the TX virtqueue is no
> longer being drained by the host and will never be consumed again.

I see, so the normal behavior is likely just fine, but the error
handling is what goes wrong. Maybe there is a way for the guest
to detect the device being turn down already so it does not
actually have to wait any more?

> The crash dump from the actual failure confirms the exact deadlock
> scenario:
>
> Core 3 holds outvq_lock and spins forever in virtqueue_get_buf waiting
> for the host to consume the buffer:
>
> virtqueue_get_buf
> __send_to_port
> put_chars
> hvc_push
> hvc_write
> n_tty_write
>   <- writev() syscall

This current loop here is

        while (!virtqueue_get_buf(out_vq, &len)
                && !virtqueue_is_broken(out_vq))
                cpu_relax();

which looks like the virtqueue_is_broken() check is meant to
catch this exact case. Do you know why this does not break
out of the loop after crosvm tears down the virtio-console
device?

> Core 0 has a watchdog bark ISR fire and attempts printk, holds the
> console lock, but spins on _raw_spin_lock_irqsave waiting to acquire
> outvq_lock:
>
> queued_spin_lock_slowpath
> _raw_spin_lock_irqsave
> __send_to_port
> put_chars
> hvc_console_print
> console_flush_all
> console_unlock
> vprintk_emit
>   <- printk (watchdog bark handler)

My first thought here was that __send_to_port() should perhaps
release the lock during the while() loop, which should avoid
blocking the other threads on the spin_lock_irqsave() but
would not avoid blocking on the loop.

> The 200 ms timeout is intended as a minimal, targeted workaround to prevent
> the watchdog bite in our specific scenario. We are open to suggestions on a
> better long-term approach.

Not sure how to do it, but I think finding a way to call
virtio_break_device() at the point the host device goes away is
the best solution here. Ideally there would just be a notification
from the host, but since __send_to_port() may be called with
interrupts disabled and may be running on the only CPU, that
would still be unreliable.

Maybe there is a way for virtio_console to read a status
register in the virtio config that tells it whether the
host has turned it off? I was thinking vdev->config->get_status(vdev)
but that seems to only get updated by the guest.

      Arnd

  reply	other threads:[~2026-04-21 12:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-21  6:57 [PATCH] virtio_console: add timeout to __send_to_port() spin loop Peng Yang
2026-04-21  7:38 ` Arnd Bergmann
2026-04-21  9:18   ` Peng Yang
2026-04-21 12:14     ` Arnd Bergmann [this message]
2026-04-21 14:11       ` Peng Yang
2026-04-21 14:23       ` Peng Yang

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=9e5be98b-3035-4e61-8325-52ed8fcf65fa@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=amit@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@oss.qualcomm.com \
    --cc=kernel@quicinc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peng.yang@oss.qualcomm.com \
    --cc=virtualization@lists.linux.dev \
    /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