qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: qemu-devel@nongnu.org, Ohad Ben-Cohen <ohad@wizery.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	virtualization@lists.linux-foundation.org
Subject: Re: [Qemu-devel] [PATCH] virtio_rpmsg: set DRIVER_OK before using device
Date: Mon, 9 Mar 2015 09:27:31 +0100	[thread overview]
Message-ID: <20150309082731.GB21823@redhat.com> (raw)
In-Reply-To: <87zj7mwstb.fsf@rustcorp.com.au>

On Mon, Mar 09, 2015 at 05:39:20PM +1030, Rusty Russell wrote:
> "Michael S. Tsirkin" <mst@redhat.com> writes:
> > virtio spec requires that all drivers set DRIVER_OK
> > before using devices. While rpmsg isn't yet
> > included in the virtio 1 spec, previous spec versions
> > also required this.
> >
> > virtio rpmsg violates this rule: is calls kick
> > before setting DRIVER_OK.
> >
> > The fix isn't trivial since simply calling virtio_device_ready earlier
> > would mean we might get an interrupt in parallel with adding buffers.
> >
> > Instead, split kick out to prepare+notify calls.  prepare before
> > virtio_device_ready - when we know we won't get interrupts. notify right
> > afterwards.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> 
> Applied.  I'll wait for Ohad to ack before sending to Linus.
> 
> BTW I assume you have a version of qemu which warns on these kind of
> failures?  That'd be nice to have!
> 
> Thanks,
> Rusty.

Yes but it's hacky ATM - it's just a one-liner that checks
the status on kick and does fprintf(stderr).
I'm trying to rework the code so it'll actually
set the status automatically, but there are some difficulties there
when ioeventfd is used,
in particular we need a way to re-inject the kick
after status update.


> > ---
> >
> > Note: compile-tested only.
> >
> >  drivers/rpmsg/virtio_rpmsg_bus.c | 17 ++++++++++++++++-
> >  1 file changed, 16 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
> > index 92f6af6..73354ee 100644
> > --- a/drivers/rpmsg/virtio_rpmsg_bus.c
> > +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
> > @@ -951,6 +951,7 @@ static int rpmsg_probe(struct virtio_device *vdev)
> >  	void *bufs_va;
> >  	int err = 0, i;
> >  	size_t total_buf_space;
> > +	bool notify;
> >  
> >  	vrp = kzalloc(sizeof(*vrp), GFP_KERNEL);
> >  	if (!vrp)
> > @@ -1030,8 +1031,22 @@ static int rpmsg_probe(struct virtio_device *vdev)
> >  		}
> >  	}
> >  
> > +	/*
> > +	 * Prepare to kick but don't notify yet - we can't do this before
> > +	 * device is ready.
> > +	 */
> > +	notify = virtqueue_kick_prepare(vrp->rvq);
> > +
> > +	/* From this point on, we can notify and get callbacks. */
> > +	virtio_device_ready(vdev);
> > +
> >  	/* tell the remote processor it can start sending messages */
> > -	virtqueue_kick(vrp->rvq);
> > +	/*
> > +	 * this might be concurrent with callbacks, but we are only
> > +	 * doing notify, not a full kick here, so that's ok.
> > +	 */
> > +	if (notify)
> > +		virtqueue_notify(vrp->rvq);
> >  
> >  	dev_info(&vdev->dev, "rpmsg host is online\n");
> >  
> > -- 
> > MST

  reply	other threads:[~2015-03-09  8:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-07 19:06 [Qemu-devel] [PATCH] virtio_rpmsg: set DRIVER_OK before using device Michael S. Tsirkin
2015-03-09  7:09 ` Rusty Russell
2015-03-09  8:27   ` Michael S. Tsirkin [this message]
2015-03-09  8:41 ` Michael S. Tsirkin
2015-03-11 12:45   ` Ohad Ben-Cohen
2015-03-12  1:05     ` Rusty Russell

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=20150309082731.GB21823@redhat.com \
    --to=mst@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ohad@wizery.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rusty@rustcorp.com.au \
    --cc=virtualization@lists.linux-foundation.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 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).