From: "Michael S. Tsirkin" <mst@redhat.com>
To: Asias He <asias@redhat.com>
Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
target-devel@vger.kernel.org,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v7 2/3] tcm_vhost: Add helper to check if endpoint is setup
Date: Mon, 22 Apr 2013 16:28:07 +0300 [thread overview]
Message-ID: <20130422132807.GC5777@redhat.com> (raw)
In-Reply-To: <20130422085327.GA21692@hj.localdomain>
On Mon, Apr 22, 2013 at 04:53:27PM +0800, Asias He wrote:
> On Thu, Apr 18, 2013 at 10:38:23AM +0300, Michael S. Tsirkin wrote:
> > On Thu, Apr 18, 2013 at 04:32:30PM +0800, Asias He wrote:
> > > On Thu, Apr 18, 2013 at 10:09:53AM +0300, Michael S. Tsirkin wrote:
> > > > On Thu, Apr 18, 2013 at 09:05:53AM +0800, Asias He wrote:
> > > > > Signed-off-by: Asias He <asias@redhat.com>
> > > > > ---
> > > > > drivers/vhost/tcm_vhost.c | 18 ++++++++++++++++++
> > > > > 1 file changed, 18 insertions(+)
> > > > >
> > > > > diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c
> > > > > index 88ebb79..8f05528 100644
> > > > > --- a/drivers/vhost/tcm_vhost.c
> > > > > +++ b/drivers/vhost/tcm_vhost.c
> > > > > @@ -111,6 +111,24 @@ static bool tcm_vhost_check_feature(struct vhost_scsi *vs, int feature)
> > > > > return ret;
> > > > > }
> > > > >
> > > > > +static bool tcm_vhost_check_endpoint(struct vhost_virtqueue *vq)
> > > > > +{
> > > > > + bool ret = false;
> > > > > +
> > > > > + /*
> > > > > + * We can handle the vq only after the endpoint is setup by calling the
> > > > > + * VHOST_SCSI_SET_ENDPOINT ioctl.
> > > > > + *
> > > > > + * TODO: Check that we are running from vhost_worker which acts
> > > > > + * as read-side critical section for vhost kind of RCU.
> > > > > + * See the comments in struct vhost_virtqueue in drivers/vhost/vhost.h
> > > > > + */
> > > > > + if (rcu_dereference_check(vq->private_data, 1))
> > > > > + ret = true;
> > > > > +
> > > > > + return ret;
> > > > > +}
> > > > > +
> > > >
> > > > You can't use RCU in this way. You need to actually
> > > > derefence. Instead, just move this within vq mutex
> > > > and do rcu_dereference_protected. document that this function
> > > > requires vq mutex.
> > >
> > > Any difference with:
> > >
> > > vs_tpg = rcu_dereference_check(vq->private_data, 1);
> >
> > Yes, it's not the same. rcu_dereference_protected says
> > "this is generally RCU but here I use it under lock".
> > rcu_dereference_check can only be used if you
> > really dereference later, and you don't.
>
> So you want the helper to be this?
>
> static bool tcm_vhost_check_endpoint()
> {
> struct tcm_vhost_tpg **vs_tpg;
>
> vs_tpg = rcu_dereference_check(vq->private_data, 1);
> if (vs_tpg)
> return true;
> else
> return false
> }
>
> And what difference code the compiler will generate with this:
>
> static bool tcm_vhost_check_endpoint()
> {
>
> if (rcu_dereference_check(vq->private_data, 1))
> return true
> else
> return false
> }
>
No, what I want is that private data is
either dereferenced (not tested against NULL)
or used under vq mutex.
In this case the second option is the easiest
and the cleanest. So move it under mutex
and then test it safely without rcu.
> >
> > > if (vs_tpg)
> > > return ture
> > > else
> > > return false;
> > >
> > > Note, tcm_vhost_check_endpoint() is called in multiple places. Having a
> > > helper is more convenient.
> >
> > I'm fine with the helper, but fix the implementation
> > and fix all callers to have vq mutex when calling.
>
> All the caller are in the vhost thread. Why need vq mutex to be taken?
vhost thread is an implementation detail, people are experimenting with
various threading strategies. In particular, code must
keep working when we move it to use a workqueue.
> > > > > static int tcm_vhost_check_true(struct se_portal_group *se_tpg)
> > > > > {
> > > > > return 1;
> > > > > --
> > > > > 1.8.1.4
> > >
> > > --
> > > Asias
>
> --
> Asias
next prev parent reply other threads:[~2013-04-22 13:28 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-09 8:51 [PATCH v5 0/3] tcm_vhost hotplug Asias He
2013-04-09 8:51 ` [PATCH v5 1/3] tcm_vhost: Introduce tcm_vhost_check_feature() Asias He
2013-04-09 8:51 ` [PATCH v5 2/3] tcm_vhost: Add helper to check if endpoint is setup Asias He
2013-04-09 8:51 ` [PATCH v5 3/3] tcm_vhost: Add hotplug/hotunplug support Asias He
2013-04-12 23:10 ` [PATCH v5 0/3] tcm_vhost hotplug Nicholas A. Bellinger
[not found] ` <1365808250.26011.68.camel@haakon2.linux-iscsi.org>
2013-04-13 3:20 ` [PATCH v6 " Asias He
2013-04-13 3:20 ` [PATCH v6 1/3] tcm_vhost: Introduce tcm_vhost_check_feature() Asias He
2013-04-13 3:20 ` [PATCH v6 2/3] tcm_vhost: Add helper to check if endpoint is setup Asias He
2013-04-13 3:20 ` [PATCH v6 3/3] tcm_vhost: Add hotplug/hotunplug support Asias He
2013-04-14 8:53 ` [PATCH v5 0/3] tcm_vhost hotplug Michael S. Tsirkin
2013-04-17 13:17 ` Michael S. Tsirkin
2013-04-18 1:05 ` [PATCH v7 " Asias He
2013-04-18 1:05 ` [PATCH v7 1/3] tcm_vhost: Introduce tcm_vhost_check_feature() Asias He
2013-04-18 7:06 ` Michael S. Tsirkin
[not found] ` <20130418070606.GC13787@redhat.com>
2013-04-18 8:25 ` Asias He
2013-04-18 7:44 ` Michael S. Tsirkin
2013-04-18 1:05 ` [PATCH v7 2/3] tcm_vhost: Add helper to check if endpoint is setup Asias He
2013-04-18 1:05 ` [PATCH v7 3/3] tcm_vhost: Add hotplug/hotunplug support Asias He
2013-04-18 1:09 ` [PATCH v5 0/3] tcm_vhost hotplug Asias He
[not found] ` <1366247154-3136-3-git-send-email-asias@redhat.com>
2013-04-18 7:09 ` [PATCH v7 2/3] tcm_vhost: Add helper to check if endpoint is setup Michael S. Tsirkin
2013-04-18 8:32 ` Asias He
2013-04-18 7:38 ` Michael S. Tsirkin
2013-04-22 8:53 ` Asias He
[not found] ` <20130422085327.GA21692@hj.localdomain>
2013-04-22 13:28 ` Michael S. Tsirkin [this message]
2013-04-22 15:00 ` Asias He
2013-04-22 16:21 ` Michael S. Tsirkin
[not found] ` <1366247154-3136-4-git-send-email-asias@redhat.com>
2013-04-18 7:34 ` [PATCH v7 3/3] tcm_vhost: Add hotplug/hotunplug support Michael S. Tsirkin
2013-04-18 8:59 ` Asias He
2013-04-18 8:21 ` Michael S. Tsirkin
2013-04-19 2:34 ` Asias He
2013-04-20 19:01 ` Michael S. Tsirkin
2013-04-22 9:20 ` Asias He
2013-04-22 13:17 ` Michael S. Tsirkin
2013-04-22 15:22 ` Asias He
2013-04-23 4:18 ` Rusty Russell
2013-04-23 4:45 ` Asias He
[not found] ` <1366247154-3136-1-git-send-email-asias@redhat.com>
2013-04-18 7:36 ` [PATCH v7 0/3] tcm_vhost hotplug Michael S. Tsirkin
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=20130422132807.GC5777@redhat.com \
--to=mst@redhat.com \
--cc=asias@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=stefanha@redhat.com \
--cc=target-devel@vger.kernel.org \
--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).