From: Greg Kurz <groug@kaod.org>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
qemu-devel@nongnu.org, Vivek Goyal <vgoyal@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [PATCH 1/4] vhost-user: Introduce nested event loop in vhost_user_read()
Date: Tue, 9 Mar 2021 19:35:42 +0100 [thread overview]
Message-ID: <20210309193542.1d64eeec@bahia.lan> (raw)
In-Reply-To: <YEeOGE7x7QJNITxd@stefanha-x1.localdomain>
[-- Attachment #1: Type: text/plain, Size: 2442 bytes --]
On Tue, 9 Mar 2021 15:02:48 +0000
Stefan Hajnoczi <stefanha@redhat.com> wrote:
> On Mon, Mar 08, 2021 at 01:31:38PM +0100, Greg Kurz wrote:
> > A deadlock condition potentially exists if a vhost-user process needs
> > to request something to QEMU on the slave channel while processing a
> > vhost-user message.
> >
> > This doesn't seem to affect any vhost-user implementation so far, but
> > this is currently biting the upcoming enablement of DAX with virtio-fs.
> > The issue is being observed when the guest does an emergency reboot while
> > a mapping still exits in the DAX window, which is very easy to get with
> > a busy enough workload (e.g. as simulated by blogbench [1]) :
> >
> > - QEMU sends VHOST_USER_GET_VRING_BASE to virtiofsd.
> >
> > - In order to complete the request, virtiofsd then asks QEMU to remove
> > the mapping on the slave channel.
> >
> > All these dialogs are synchronous, hence the deadlock.
> >
> > As pointed out by Stefan Hajnoczi:
> >
> > When QEMU's vhost-user master implementation sends a vhost-user protocol
> > message, vhost_user_read() does a "blocking" read during which slave_fd
> > is not monitored by QEMU.
> >
> > As a preliminary step to address this, split vhost_user_read() into a
> > nested even loop and a one-shot callback that does the actual reading.
>
> In case you respin:
> s/even/event/
>
Fixed.
> > +static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
> > +{
> > + struct vhost_user *u = dev->opaque;
> > + CharBackend *chr = u->user->chr;
> > + GMainContext *prev_ctxt = chr->chr->gcontext;
> > + GMainContext *ctxt = g_main_context_new();
> > + GMainLoop *loop = g_main_loop_new(ctxt, FALSE);
> > + struct vhost_user_read_cb_data data = {
> > + .dev = dev,
> > + .loop = loop,
> > + .msg = msg,
> > + .ret = 0
> > + };
> > +
> > + /* Switch context and add a new watch to monitor chardev activity */
> > + qemu_chr_be_update_read_handlers(chr->chr, ctxt);
> > + qemu_chr_fe_add_watch(chr, G_IO_IN | G_IO_HUP, vhost_user_read_cb, &data);
>
> This comment could be expanded to explain why the nested event loop is
> necessary. The goal is to monitor the slave_fd while waiting for chr
> I/O so we'll need an event loop. prev_ctxt cannot be run nested since
> its fd handlers may not be prepared (e.g. re-entrancy).
Ok, will do.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-03-09 19:48 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-08 12:31 [PATCH 0/4] virtiofsd: Avoid potential deadlocks Greg Kurz
2021-03-08 12:31 ` [PATCH 1/4] vhost-user: Introduce nested event loop in vhost_user_read() Greg Kurz
2021-03-09 15:02 ` Stefan Hajnoczi
2021-03-09 18:35 ` Greg Kurz [this message]
2021-03-08 12:31 ` [PATCH 2/4] vhost-user: Convert slave channel to QIOChannelSocket Greg Kurz
2021-03-09 15:17 ` Stefan Hajnoczi
2021-03-09 20:23 ` Greg Kurz
2021-03-10 11:27 ` Stefan Hajnoczi
2021-03-10 13:08 ` Greg Kurz
2021-03-10 11:43 ` Daniel P. Berrangé
2021-03-10 13:45 ` Greg Kurz
2021-03-10 13:48 ` Daniel P. Berrangé
2021-03-08 12:31 ` [PATCH 3/4] vhost-user: Monitor slave channel in vhost_user_read() Greg Kurz
2021-03-09 15:18 ` Stefan Hajnoczi
2021-03-09 22:56 ` Greg Kurz
2021-03-08 12:31 ` [PATCH 4/4] virtiofsd: Release vu_dispatch_lock when stopping queue Greg Kurz
2021-03-09 14:00 ` Vivek Goyal
2021-03-09 15:20 ` Stefan Hajnoczi
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=20210309193542.1d64eeec@bahia.lan \
--to=groug@kaod.org \
--cc=dgilbert@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vgoyal@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).