From: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
To: Vincent Whitchurch <vincent.whitchurch@axis.com>
Cc: Ohad Ben-Cohen <ohad@wizery.com>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
"linux-remoteproc@vger.kernel.org"
<linux-remoteproc@vger.kernel.org>,
Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
"virtualization@lists.linux-foundation.org"
<virtualization@lists.linux-foundation.org>,
Liam Girdwood <liam.r.girdwood@linux.intel.com>,
Bjorn Andersson <bjorn.andersson@linaro.org>,
"sound-open-firmware@alsa-project.org"
<sound-open-firmware@alsa-project.org>
Subject: Re: [PATCH v7 3/3] vhost: add an RPMsg API
Date: Fri, 18 Sep 2020 10:39:32 +0200 [thread overview]
Message-ID: <20200918083931.GB19246@ubuntu> (raw)
In-Reply-To: <20200917085559.kxxjrortmhbwpd22@axis.com>
Hi Vincent,
On Thu, Sep 17, 2020 at 10:55:59AM +0200, Vincent Whitchurch wrote:
> On Thu, Sep 10, 2020 at 01:13:51PM +0200, Guennadi Liakhovetski wrote:
> > +int vhost_rpmsg_start_lock(struct vhost_rpmsg *vr, struct vhost_rpmsg_iter *iter,
> > + unsigned int qid, ssize_t len)
> > + __acquires(vq->mutex)
> > +{
> > + struct vhost_virtqueue *vq = vr->vq + qid;
> > + unsigned int cnt;
> > + ssize_t ret;
> > + size_t tmp;
> > +
> > + if (qid >= VIRTIO_RPMSG_NUM_OF_VQS)
> > + return -EINVAL;
> > +
> > + iter->vq = vq;
> > +
> > + mutex_lock(&vq->mutex);
> > + vhost_disable_notify(&vr->dev, vq);
> > +
> > + iter->head = vhost_rpmsg_get_msg(vq, &cnt);
> > + if (iter->head == vq->num)
> > + iter->head = -EAGAIN;
> > +
> > + if (iter->head < 0) {
> > + ret = iter->head;
> > + goto unlock;
> > + }
> > +
> [...]
> > +
> > +return_buf:
> > + vhost_add_used(vq, iter->head, 0);
> > +unlock:
> > + vhost_enable_notify(&vr->dev, vq);
> > + mutex_unlock(&vq->mutex);
> > +
> > + return ret;
> > +}
>
> There is a race condition here. New buffers could have been added while
> notifications were disabled (between vhost_disable_notify() and
> vhost_enable_notify()), so the other vhost drivers check the return
> value of vhost_enable_notify() and rerun their work loops if it returns
> true. This driver doesn't do that so it stops processing requests if
> that condition hits.
You're right, thanks for spotting this!
> Something like the below seems to fix it but the correct fix could maybe
> involve changing this API to account for this case so that it looks more
> like the code in other vhost drivers.
I'll try to use your proposed code, we'll see if it turns out incorrect.
> diff --git a/drivers/vhost/rpmsg.c b/drivers/vhost/rpmsg.c
> index 7c753258d42..673dd4ec865 100644
> --- a/drivers/vhost/rpmsg.c
> +++ b/drivers/vhost/rpmsg.c
> @@ -302,8 +302,14 @@ static void handle_rpmsg_req_kick(struct vhost_work *work)
> struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue,
> poll.work);
> struct vhost_rpmsg *vr = container_of(vq->dev, struct vhost_rpmsg, dev);
> + struct vhost_virtqueue *reqvq = vr->vq + VIRTIO_RPMSG_REQUEST;
This is only called on the request queue, so, we can just use vq here.
>
> - while (handle_rpmsg_req_single(vr, vq))
> + /*
> + * The !vhost_vq_avail_empty() check is needed since the vhost_rpmsg*
> + * APIs don't check the return value of vhost_enable_notify() and retry
> + * if there were buffers added while notifications were disabled.
> + */
> + while (handle_rpmsg_req_single(vr, vq) || !vhost_vq_avail_empty(reqvq->dev, reqvq))
> ;
> }
Thanks
Guennadi
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2020-09-18 8:39 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-10 11:13 [PATCH v7 0/3] Add a vhost RPMsg API Guennadi Liakhovetski
2020-09-10 11:13 ` Guennadi Liakhovetski
2020-09-10 11:13 ` [PATCH v7 1/3] vhost: convert VHOST_VSOCK_SET_RUNNING to a generic ioctl Guennadi Liakhovetski
2020-09-10 11:13 ` Guennadi Liakhovetski
2020-09-10 11:13 ` [PATCH v7 2/3] rpmsg: move common structures and defines to headers Guennadi Liakhovetski
2020-09-10 11:13 ` Guennadi Liakhovetski
2020-09-10 11:13 ` [PATCH v7 3/3] vhost: add an RPMsg API Guennadi Liakhovetski
2020-09-17 8:55 ` Vincent Whitchurch
2020-09-17 8:55 ` Vincent Whitchurch
2020-09-18 8:39 ` Guennadi Liakhovetski [this message]
2020-09-17 22:01 ` Mathieu Poirier
2020-09-18 9:02 ` Guennadi Liakhovetski
2020-09-18 9:02 ` Guennadi Liakhovetski
2020-09-18 15:52 ` Mathieu Poirier
2020-09-21 6:22 ` Guennadi Liakhovetski
2020-09-21 6:22 ` Guennadi Liakhovetski
2020-09-18 23:16 ` Mathieu Poirier
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=20200918083931.GB19246@ubuntu \
--to=guennadi.liakhovetski@linux.intel.com \
--cc=bjorn.andersson@linaro.org \
--cc=kvm@vger.kernel.org \
--cc=liam.r.girdwood@linux.intel.com \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=mst@redhat.com \
--cc=ohad@wizery.com \
--cc=pierre-louis.bossart@linux.intel.com \
--cc=sound-open-firmware@alsa-project.org \
--cc=vincent.whitchurch@axis.com \
--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 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.