public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Bart Van Assche <Bart.VanAssche@wdc.com>
Cc: "mingo@kernel.org" <mingo@kernel.org>,
	"jthumshirn@suse.de" <jthumshirn@suse.de>,
	"hch@lst.de" <hch@lst.de>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
	"hare@suse.de" <hare@suse.de>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"shane.seymour@hpe.com" <shane.seymour@hpe.com>,
	"jejb@linux.vnet.ibm.com" <jejb@linux.vnet.ibm.com>
Subject: Re: [PATCH v3 1/3] rcu: Introduce rcu_swap_protected()
Date: Mon, 28 Aug 2017 14:58:47 -0700	[thread overview]
Message-ID: <20170828215847.GE11320@linux.vnet.ibm.com> (raw)
In-Reply-To: <1503956357.2841.68.camel@wdc.com>

On Mon, Aug 28, 2017 at 09:39:18PM +0000, Bart Van Assche wrote:
> On Mon, 2017-08-28 at 14:26 -0700, Paul E. McKenney wrote:
> > On Mon, Aug 28, 2017 at 01:46:13PM -0700, Bart Van Assche wrote:
> > > A common pattern in RCU code is to assign a new value to an RCU
> > > pointer after having read and stored the old value. Introduce a
> > > macro for this pattern.
> > > 
> > > Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> > > Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > > Cc: Ingo Molnar <mingo@kernel.org>
> > > Cc: Christoph Hellwig <hch@lst.de>
> > > Cc: Hannes Reinecke <hare@suse.de>
> > > Cc: Johannes Thumshirn <jthumshirn@suse.de>
> > > Cc: Shane M Seymour <shane.seymour@hpe.com>
> > > ---
> > >  include/linux/rcupdate.h | 20 ++++++++++++++++++++
> > >  1 file changed, 20 insertions(+)
> > > 
> > > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> > > index f816fc72b51e..555815ce2e57 100644
> > > --- a/include/linux/rcupdate.h
> > > +++ b/include/linux/rcupdate.h
> > > @@ -561,6 +561,26 @@ static inline void rcu_preempt_sleep_check(void) { }
> > >   */
> > >  #define rcu_pointer_handoff(p) (p)
> > > 
> > > +/**
> > > + * rcu_swap_protected() - swap an RCU and a regular pointer
> > > + * @rcu_ptr: RCU pointer
> > > + * @ptr: regular pointer
> > > + * @c: the conditions under which the dereference will take place
> > > + *
> > > + * Perform swap(@rcu_ptr, @ptr) where @rcu_ptr is an RCU-annotated pointer and
> > > + * @c is the argument that is passed to the rcu_dereference_protected() call
> > > + * used to read that pointer.
> > > + */
> > > +#define rcu_swap_protected(rcu_ptr, ptr, c) do {			\
> > > +	typeof(ptr) __tmp;						\
> > > +									\
> > > +	BUILD_BUG_ON(!__same_type(typeof(rcu_ptr), typeof(*(ptr)) __rcu *)); \
> > > +	BUILD_BUG_ON(!__same_type(typeof(ptr), typeof(*(rcu_ptr)) *));	\
> > 
> > Hmmm...
> > 
> > What kinds of bugs have these two BUILD_BUG_ON() instances have caught
> > that would not be caught by the assignments below?
> 
> Hello Paul,
> 
> These two BUILD_BUG_ON() statements can be left out. The purpose of these
> statements is to complain as early as possible if the type of rcu_ptr and/or
> ptr is incorrect. As we all know error messages that are triggered by macros
> used inside a macro definition can be hard to read. My hope is that these
> two BUILD_BUG_ON() macros will cause the compiler to report easier to read
> diagnostic messages.
> 
> > > +	__tmp = rcu_dereference_protected((rcu_ptr), (c));		\
> > > +	rcu_assign_pointer((rcu_ptr), (ptr));				\
> > > +	(ptr) = __tmp;							\
> > > +} while (0)
> > > +
> > 
> > Could you please put this after rcu_assign_pointer() and before
> > rcu_access_pointer()?  That way the things that assign to RCU-protected
> > pointers are together.
> 
> Something like the patch below (compile-tested only)?

Looks good!

I suspect that you would like to push this with your changes, so,
assuming 0day test robot and -next are OK with it:

Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>

I am not necessarily inalterably opposed to the extra BUILD_BUG_ON()
statements, and in fact I do like improved diagnostics, but those need to
go up via my tree as a separate patch.  That way, any unexpected gotchas
can be handled without risking your rcu_swap_protected() functionality.

							Thanx, Paul

> Thanks,
> 
> Bart.
> 
> 
> [PATCH] rcu: Introduce rcu_swap_protected()
> ---
>  include/linux/rcupdate.h | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> index f816fc72b51e..8e920f0ecb07 100644
> --- a/include/linux/rcupdate.h
> +++ b/include/linux/rcupdate.h
> @@ -407,6 +407,22 @@ static inline void rcu_preempt_sleep_check(void) { }
>  	_r_a_p__v;							      \
>  })
>  
> +/**
> + * rcu_swap_protected() - swap an RCU and a regular pointer
> + * @rcu_ptr: RCU pointer
> + * @ptr: regular pointer
> + * @c: the conditions under which the dereference will take place
> + *
> + * Perform swap(@rcu_ptr, @ptr) where @rcu_ptr is an RCU-annotated pointer and
> + * @c is the argument that is passed to the rcu_dereference_protected() call
> + * used to read that pointer.
> + */
> +#define rcu_swap_protected(rcu_ptr, ptr, c) do {			\
> +	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
> +	rcu_assign_pointer((rcu_ptr), (ptr));				\
> +	(ptr) = __tmp;							\
> +} while (0)
> +
>  /**
>   * rcu_access_pointer() - fetch RCU pointer with no dereferencing
>   * @p: The pointer to read

  reply	other threads:[~2017-08-28 21:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-28 20:46 [PATCH v3 0/3] Rework handling of scsi_device.vpd_pg8[03] Bart Van Assche
2017-08-28 20:46 ` [PATCH v3 1/3] rcu: Introduce rcu_swap_protected() Bart Van Assche
2017-08-28 21:26   ` Paul E. McKenney
2017-08-28 21:39     ` Bart Van Assche
2017-08-28 21:58       ` Paul E. McKenney [this message]
2017-08-28 20:46 ` [PATCH v3 2/3] Rework the code for caching Vital Product Data (VPD) Bart Van Assche
2017-08-28 20:46 ` [PATCH v3 3/3] Rework handling of scsi_device.vpd_pg8[03] Bart Van Assche
  -- strict thread matches above, loose matches on Subject: below --
2017-08-28 20:45 [PATCH v3 0/3] " Bart Van Assche
2017-08-28 20:45 ` [PATCH v3 1/3] rcu: Introduce rcu_swap_protected() Bart Van Assche
2017-08-28 20:45 ` Bart Van Assche
2017-08-28 20:44 [PATCH v3 0/3] Rework handling of scsi_device.vpd_pg8[03] Bart Van Assche
2017-08-28 20:44 ` [PATCH v3 1/3] rcu: Introduce rcu_swap_protected() Bart Van Assche
2017-08-28 20:44 ` Bart Van Assche

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=20170828215847.GE11320@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=Bart.VanAssche@wdc.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=jthumshirn@suse.de \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mingo@kernel.org \
    --cc=shane.seymour@hpe.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