All of lore.kernel.org
 help / color / mirror / Atom feed
From: "hch@lst.de" <hch@lst.de>
To: "Seymour, Shane M" <shane.seymour@hpe.com>
Cc: Bart Van Assche <Bart.VanAssche@wdc.com>,
	"hch@lst.de" <hch@lst.de>,
	"jejb@linux.vnet.ibm.com" <jejb@linux.vnet.ibm.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"hare@suse.de" <hare@suse.de>,
	"jthumshirn@suse.de" <jthumshirn@suse.de>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>
Subject: Re: [PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03]
Date: Fri, 25 Aug 2017 08:59:36 +0200	[thread overview]
Message-ID: <20170825065936.GC8866@lst.de> (raw)
In-Reply-To: <AT5PR84MB0308689A9E2AA2461DEB35A0FD9B0@AT5PR84MB0308.NAMPRD84.PROD.OUTLOOK.COM>

On Fri, Aug 25, 2017 at 05:58:16AM +0000, Seymour, Shane M wrote:
> > My understanding of the SCSI VPD code is as follows:
> > * rcu_read_lock() / rcu_read_unlock() is used to prevent that another thread
> >   updates a VPD buffer while it is being read.
> 
> My understanding is that it doesn't do that - you can update an RCU
> pointer with rcu_assign_pointer() after someone has called
> rcu_read_lock() and before they call rcu_read_unlock(). 

Indeed.

> What rcu_read_lock() / rcu_read_unlock() do is mark a read-side critical
> section when accessing an RCU data item. If you have 2 CPUs in a
> read-side critical section and a 3rd CPU replacing the pointer using
> rcu_assign_pointer() one CPU could potentially end up with the old pointer
> and the other one with the new pointer or both old or both new (the only
> guarantee you have is that the pointer won't be partially updated with
> bits of old and the new pointer).

Exactly.

> To free the old pointer directly you have to call synchronize_rcu()
> after which you can call kfree() or if you don't call synchronize_rcu()
> you have to use a delayed freeing mechanism like kfree_rcu()

(or call_rcu for the more general case)

> so you can guarantee that the old pointer is still valid while used in a
> read-side critical section. Using something like kfree_rcu() means that
> you also don’t have to wait like I believe you can do if you call
> synchronize_rcu() since you could be forced to wait for a RCU grace
> period to end before you can call kfree().

Yes, call_rcu (including the kfree_rcu helper) schedules a delayed
action after the grace period, synchronize_rcu synchronously waits
for the end of the grace period.

> > * All code that either updates or reads a VPD buffer holds a reference on
> >   the SCSI device that buffer is associated with. That is why I think it is
> >   not needed to use kfree_rcu() in scsi_device_dev_release_usercontext().

But a reference could be dropped during the grace period.  We'll need
to either wait for the grace period after NULLing out the vpd pointers
or before freeing the allocations for them.  Currently the only rcu
synchronization in the scsi code is after assining the vpd pointers
(in which case we'd only need it whe replacing the previous one, which
should not happen in practice anyway), but I can't find anything in the
free path.

  reply	other threads:[~2017-08-25  6:59 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-23 21:39 [PATCH 00/19] SCSI patches for kernel v4.14 Bart Van Assche
2017-08-23 21:39 ` [PATCH 01/19] Remove an obsolete function declaration Bart Van Assche
2017-08-24  9:02   ` Christoph Hellwig
2017-08-23 21:39 ` [PATCH 02/19] Avoid sign extension of scsi_device.type Bart Van Assche
2017-08-24  6:10   ` Hannes Reinecke
2017-08-24  9:02   ` Christoph Hellwig
2017-08-23 21:39 ` [PATCH 03/19] Suppress gcc 7 fall-through warnings reported with W=1 Bart Van Assche
2017-08-24  9:03   ` Christoph Hellwig
2017-08-23 21:39 ` [PATCH 04/19] Convert a strncmp() call into a strcmp() call Bart Van Assche
2017-08-24  9:03   ` Christoph Hellwig
2017-08-25 15:43   ` Hannes Reinecke
2017-08-23 21:39 ` [PATCH 05/19] scsi_setup_fs_cmnd(): Call scsi_req_init() instead of open-coding it Bart Van Assche
2017-08-24  9:05   ` Christoph Hellwig
2017-08-24 16:17     ` Bart Van Assche
2017-08-23 21:39 ` [PATCH 06/19] Document which queue type a function is intended for Bart Van Assche
2017-08-24  9:05   ` Christoph Hellwig
2017-08-24 16:57     ` Bart Van Assche
2017-08-24 16:58       ` hch
2017-08-24 17:22         ` Bart Van Assche
2017-08-25 15:44   ` Hannes Reinecke
2017-08-23 21:39 ` [PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03] Bart Van Assche
2017-08-24  9:07   ` Christoph Hellwig
2017-08-24 16:54     ` Bart Van Assche
2017-08-25  5:58       ` Seymour, Shane M
2017-08-25  6:59         ` hch [this message]
2017-08-25 20:04         ` Bart Van Assche
2017-08-28  2:02           ` Seymour, Shane M
2017-08-25 15:49   ` Hannes Reinecke
2017-08-25 16:26     ` Bart Van Assche
2017-08-23 21:39 ` [PATCH 08/19] Use blk_mq_rq_to_pdu() to convert a request to a SCSI command pointer Bart Van Assche
2017-08-24  9:07   ` Christoph Hellwig
2017-08-23 21:39 ` [PATCH 09/19] sd, sr: Convert two assignments into warning statements Bart Van Assche
2017-08-24  9:08   ` Christoph Hellwig
2017-08-23 21:40 ` [PATCH 10/19] sd: Fix indentation Bart Van Assche
2017-08-24  9:08   ` Christoph Hellwig
2017-08-25 15:50   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 11/19] sd: Remove a useless comparison Bart Van Assche
2017-08-25 15:50   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 12/19] sg: Fix type of last blk_trace_setup() argument Bart Van Assche
2017-08-24  9:08   ` Christoph Hellwig
2017-08-25 15:51   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 13/19] libiscsi: Fix indentation Bart Van Assche
2017-08-24  9:08   ` Christoph Hellwig
2017-08-25 15:51   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 14/19] libsas: Remove a set-but-not-used variable Bart Van Assche
2017-08-24  9:09   ` Christoph Hellwig
2017-08-25 15:51   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 15/19] libsas: Annotate fall-through in a switch statement Bart Van Assche
2017-08-24  9:09   ` Christoph Hellwig
2017-08-25 15:52   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 16/19] scsi_transport_sas, sas_tlr_supported(): Check kzalloc() return value Bart Van Assche
2017-08-24  9:09   ` Christoph Hellwig
2017-08-25 15:52   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 17/19] scsi_transport_srp: Suppress a W=1 compiler warning Bart Van Assche
2017-08-24  9:11   ` Christoph Hellwig
2017-08-24 16:27     ` Bart Van Assche
2017-08-25 15:29       ` hch
2017-08-25 15:40         ` Bart Van Assche
2017-08-25 15:56           ` hch
2017-08-23 21:40 ` [PATCH 18/19] scsi_debug: Remove a set-but-not-used variable Bart Van Assche
2017-08-24  9:12   ` Christoph Hellwig
2017-08-25 15:53   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 19/19] iscsi_tcp: " Bart Van Assche
2017-08-24  9:12   ` Christoph Hellwig
2017-08-25 15:53   ` Hannes Reinecke

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=20170825065936.GC8866@lst.de \
    --to=hch@lst.de \
    --cc=Bart.VanAssche@wdc.com \
    --cc=hare@suse.de \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=jthumshirn@suse.de \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --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 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.