All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: "ira.weiny" <ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Mike Marciniszyn
	<mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] IB/hfi1,IB/qib: Fix qp_stats sleep with rcu read lock held
Date: Wed, 10 Aug 2016 11:24:27 +0300	[thread overview]
Message-ID: <20160810082427.GI23921@leon.nu> (raw)
In-Reply-To: <20160810055151.GB32695-W4f6Xiosr+yv7QzWx2u06xL4W9x8LtSr@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 2203 bytes --]

On Wed, Aug 10, 2016 at 01:51:52AM -0400, ira.weiny wrote:
> On Tue, Aug 09, 2016 at 09:11:46PM +0300, Leon Romanovsky wrote:
> > On Tue, Aug 09, 2016 at 11:16:26AM -0400, ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org wrote:
> > > From: Mike Marciniszyn <mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> > > 
> 
> [snip]
> 
> > > diff --git a/drivers/infiniband/hw/hfi1/debugfs.c b/drivers/infiniband/hw/hfi1/debugfs.c
> > > index dbab9d9cc288..c35bef8dd5aa 100644
> > > --- a/drivers/infiniband/hw/hfi1/debugfs.c
> > > +++ b/drivers/infiniband/hw/hfi1/debugfs.c
> > > @@ -223,28 +223,35 @@ DEBUGFS_SEQ_FILE_OPEN(ctx_stats)
> > >  DEBUGFS_FILE_OPS(ctx_stats);
> > >  
> > >  static void *_qp_stats_seq_start(struct seq_file *s, loff_t *pos)
> > > -__acquires(RCU)
> > > +	__acquires(RCU)
> > >  {
> > >  	struct qp_iter *iter;
> > >  	loff_t n = *pos;
> > >  
> > > -	rcu_read_lock();
> > >  	iter = qp_iter_init(s->private);
> > > +
> > > +	/* stop calls rcu_read_unlock */
> > > +	rcu_read_lock();
> > 
> > IMHO, it should be placed after your if(!iter) check below.
> 
> I know this seems weird but this makes the rcu locking "balanced".  Returning
> NULL here still calls "stop" which is going to call rcu_read_unlock.  If we
> move rcu_read_lock we need to maintain state to determine if we called lock or
> not.  This is easier.  To me it does seem odd that the sequence operation does
> not stop on its own when NULL is returned but that is the way it works.

Thanks for the explanation.

> 
> > 
> > > +
> > >  	if (!iter)
> > >  		return NULL;
> > >  
> > > -	while (n--) {
> > > +	if (qp_iter_next(iter)) {
> > > +		kfree(iter);
> > > +		return NULL;
> > > +	}
> > > +	while (n--)
> > >  		if (qp_iter_next(iter)) {
> > >  			kfree(iter);
> > >  			return NULL;
> > >  		}
> > 
> > It looks like you forgot to remove the lines above.
> 
> Nope this replaces a call to qp_iter_next which was in qp_iter_init.
> 
> As the commit messages says we move the implict next's back into the respective
> start functions.

Did you consider as an option to use do{...}while(...) construction
instead of this duplicated code?

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Leon Romanovsky <leon@kernel.org>
To: "ira.weiny" <ira.weiny@intel.com>
Cc: dledford@redhat.com, linux-rdma@vger.kernel.org,
	Mike Marciniszyn <mike.marciniszyn@intel.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH] IB/hfi1,IB/qib: Fix qp_stats sleep with rcu read lock held
Date: Wed, 10 Aug 2016 11:24:27 +0300	[thread overview]
Message-ID: <20160810082427.GI23921@leon.nu> (raw)
In-Reply-To: <20160810055151.GB32695@phlsvsds.ph.intel.com>

[-- Attachment #1: Type: text/plain, Size: 2143 bytes --]

On Wed, Aug 10, 2016 at 01:51:52AM -0400, ira.weiny wrote:
> On Tue, Aug 09, 2016 at 09:11:46PM +0300, Leon Romanovsky wrote:
> > On Tue, Aug 09, 2016 at 11:16:26AM -0400, ira.weiny@intel.com wrote:
> > > From: Mike Marciniszyn <mike.marciniszyn@intel.com>
> > > 
> 
> [snip]
> 
> > > diff --git a/drivers/infiniband/hw/hfi1/debugfs.c b/drivers/infiniband/hw/hfi1/debugfs.c
> > > index dbab9d9cc288..c35bef8dd5aa 100644
> > > --- a/drivers/infiniband/hw/hfi1/debugfs.c
> > > +++ b/drivers/infiniband/hw/hfi1/debugfs.c
> > > @@ -223,28 +223,35 @@ DEBUGFS_SEQ_FILE_OPEN(ctx_stats)
> > >  DEBUGFS_FILE_OPS(ctx_stats);
> > >  
> > >  static void *_qp_stats_seq_start(struct seq_file *s, loff_t *pos)
> > > -__acquires(RCU)
> > > +	__acquires(RCU)
> > >  {
> > >  	struct qp_iter *iter;
> > >  	loff_t n = *pos;
> > >  
> > > -	rcu_read_lock();
> > >  	iter = qp_iter_init(s->private);
> > > +
> > > +	/* stop calls rcu_read_unlock */
> > > +	rcu_read_lock();
> > 
> > IMHO, it should be placed after your if(!iter) check below.
> 
> I know this seems weird but this makes the rcu locking "balanced".  Returning
> NULL here still calls "stop" which is going to call rcu_read_unlock.  If we
> move rcu_read_lock we need to maintain state to determine if we called lock or
> not.  This is easier.  To me it does seem odd that the sequence operation does
> not stop on its own when NULL is returned but that is the way it works.

Thanks for the explanation.

> 
> > 
> > > +
> > >  	if (!iter)
> > >  		return NULL;
> > >  
> > > -	while (n--) {
> > > +	if (qp_iter_next(iter)) {
> > > +		kfree(iter);
> > > +		return NULL;
> > > +	}
> > > +	while (n--)
> > >  		if (qp_iter_next(iter)) {
> > >  			kfree(iter);
> > >  			return NULL;
> > >  		}
> > 
> > It looks like you forgot to remove the lines above.
> 
> Nope this replaces a call to qp_iter_next which was in qp_iter_init.
> 
> As the commit messages says we move the implict next's back into the respective
> start functions.

Did you consider as an option to use do{...}while(...) construction
instead of this duplicated code?

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2016-08-10  8:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-09 15:16 [PATCH] IB/hfi1,IB/qib: Fix qp_stats sleep with rcu read lock held ira.weiny
2016-08-09 15:16 ` ira.weiny
2016-08-09 18:11 ` Leon Romanovsky
2016-08-10  5:51   ` ira.weiny
     [not found]     ` <20160810055151.GB32695-W4f6Xiosr+yv7QzWx2u06xL4W9x8LtSr@public.gmane.org>
2016-08-10  8:24       ` Leon Romanovsky [this message]
2016-08-10  8:24         ` Leon Romanovsky
2016-08-10 10:17       ` Leon Romanovsky
2016-08-10 10:17         ` Leon Romanovsky
2016-08-22 18:21       ` Doug Ledford
2016-08-22 18:21         ` Doug Ledford

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=20160810082427.GI23921@leon.nu \
    --to=leon-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.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.