From: Jason Gunthorpe <jgg@nvidia.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: linux-cxl@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Vishal L Verma <vishal.l.verma@intel.com>,
"Weiny, Ira" <ira.weiny@intel.com>,
"Schofield, Alison" <alison.schofield@intel.com>
Subject: Re: [PATCH v2 2/4] cxl/mem: Fix synchronization mechanism for device removal vs ioctl operations
Date: Tue, 30 Mar 2021 14:54:31 -0300 [thread overview]
Message-ID: <20210330175431.GX2356281@nvidia.com> (raw)
In-Reply-To: <CAPcyv4ixD=+PejHErT_FLtEyXsm4mk+93R7mQ0uFtd_kd-fs1w@mail.gmail.com>
On Tue, Mar 30, 2021 at 10:31:15AM -0700, Dan Williams wrote:
> On Tue, Mar 30, 2021 at 10:03 AM Jason Gunthorpe <jgg@nvidia.com> wrote:
> >
> > On Tue, Mar 30, 2021 at 09:05:29AM -0700, Dan Williams wrote:
> >
> > > > If you can't clearly point to the *data* under RCU protection it is
> > > > being used wrong.
> > >
> > > Agree.
> > >
> > > The data being protected is the value of
> > > dev->kobj.state_in_sysfs. The
> >
> > So where is that read under:
> >
> > + idx = srcu_read_lock(&cxl_memdev_srcu);
> > + rc = __cxl_memdev_ioctl(cxlmd, cmd, arg);
> > + srcu_read_unlock(&cxl_memdev_srcu, idx);
> >
> > ?
>
> device_is_registered() inside __cxl_memdev_ioctl().
Oh, I see, I missed that
> > It can't read the RCU protected data outside the RCU critical region,
> > and it can't read/write RCU protected data without using the helper
> > macros which insert the required barriers.
>
> The required barriers are there. srcu_read_lock() +
> device_is_registered() is paired with cdev_device_del() +
> synchronize_rcu().
RCU needs barriers on the actual load/store just a naked
device_is_registered() alone is not strong enough.
> > IMHO this can't use 'dev->kobj.state_in_sysfs' as the RCU protected data.
>
> This usage of srcu is functionally equivalent to replacing
> srcu_read_lock() with down_read() and the shutdown path with:
Sort of, but the rules for load/store under RCU are different than for
load/store under a normal barriered lock. All the data is unstable for
instance and minimially needs READ_ONCE.
> cdev_device_del(...);
> down_write(...):
> up_write(...);
The lock would have to enclose the store to state_in_sysfs, otherwise
as written it has the same data race problems.
Jason
next prev parent reply other threads:[~2021-03-30 17:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-30 2:47 [PATCH v2 0/4] cxl/mem: Fix memdev device setup Dan Williams
2021-03-30 2:47 ` [PATCH v2 1/4] cxl/mem: Use sysfs_emit() for attribute show routines Dan Williams
2021-03-30 2:47 ` [PATCH v2 2/4] cxl/mem: Fix synchronization mechanism for device removal vs ioctl operations Dan Williams
2021-03-30 11:16 ` Jason Gunthorpe
2021-03-30 15:37 ` Dan Williams
2021-03-30 15:47 ` Jason Gunthorpe
2021-03-30 16:05 ` Dan Williams
2021-03-30 17:02 ` Jason Gunthorpe
2021-03-30 17:31 ` Dan Williams
2021-03-30 17:54 ` Jason Gunthorpe [this message]
2021-03-30 19:00 ` Dan Williams
2021-03-30 19:26 ` Jason Gunthorpe
2021-03-30 19:43 ` Dan Williams
2021-03-30 19:51 ` Jason Gunthorpe
2021-03-30 21:00 ` Dan Williams
2021-03-30 22:09 ` Jason Gunthorpe
2021-03-30 2:47 ` [PATCH v2 3/4] cxl/mem: Do not rely on device_add() side effects for dev_set_name() failures Dan Williams
2021-03-30 2:48 ` [PATCH v2 4/4] cxl/mem: Disable cxl device power management Dan Williams
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=20210330175431.GX2356281@nvidia.com \
--to=jgg@nvidia.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=ira.weiny@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vishal.l.verma@intel.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;
as well as URLs for NNTP newsgroup(s).