From: Dan Williams <dan.j.williams@intel.com>
To: Jason Gunthorpe <jgg@nvidia.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 v3 2/4] cxl/mem: Fix synchronization mechanism for device removal vs ioctl operations
Date: Wed, 31 Mar 2021 08:45:23 -0700 [thread overview]
Message-ID: <CAPcyv4gv3rk+NhdhN=QcJMDwRSziqeDKhYtrnZFa6yOZe-_caQ@mail.gmail.com> (raw)
In-Reply-To: <20210331130720.GF1463678@nvidia.com>
On Wed, Mar 31, 2021 at 6:07 AM Jason Gunthorpe <jgg@nvidia.com> wrote:
>
> On Tue, Mar 30, 2021 at 04:36:37PM -0700, Dan Williams wrote:
> > -static void cxlmdev_unregister(void *_cxlmd)
> > +static void cxl_memdev_activate(struct cxl_memdev *cxlmd, struct cxl_mem *cxlm)
> > {
> > - struct cxl_memdev *cxlmd = _cxlmd;
> > - struct device *dev = &cxlmd->dev;
> > + cxlmd->cxlm = cxlm;
> > + down_write(&cxl_memdev_rwsem);
> > + up_write(&cxl_memdev_rwsem);
> > +}
>
> No reason not to put the assignment inside the lock. Though using the
> lock at all is overkill as the pointer hasn't left the local stack
> frame at this point.
Right, I was considering just leaving it as a bare pointer assignment,
in fact that must be sufficient as publishing the cdev needs to depend
on all cdev init having completed. So if this write somehow leaks into
cdev_device_add() there are much larger problems afoot.
>
> > err_add:
> > - ida_free(&cxl_memdev_ida, cxlmd->id);
> > -err_id:
> > /*
> > - * Theoretically userspace could have already entered the fops,
> > - * so flush ops_active.
> > + * The cdev was briefly live, shutdown any ioctl operations that
> > + * saw that state.
> > */
>
> Wow it is really subtle that cdev_device_add has this tiny hole where
> it can fail but have already allowed open() :<
Yes, this was something I wanted to address in the cdev api proposal
integrating the debugfs fops proxy / reference counting aproach. I
want a cdev api that does not allow open until after the associated
device has registered and fired the KOBJ_ADD event.
>
> Other than the lock it looks OK
>
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Thanks, Jason.
next prev parent reply other threads:[~2021-03-31 15:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-30 23:36 [PATCH v3 0/4] cxl/mem: Fix memdev device setup Dan Williams
2021-03-30 23:36 ` [PATCH v3 1/4] cxl/mem: Use sysfs_emit() for attribute show routines Dan Williams
2021-03-30 23:36 ` [PATCH v3 2/4] cxl/mem: Fix synchronization mechanism for device removal vs ioctl operations Dan Williams
2021-03-31 13:07 ` Jason Gunthorpe
2021-03-31 15:45 ` Dan Williams [this message]
2021-03-30 23:36 ` [PATCH v3 3/4] cxl/mem: Do not rely on device_add() side effects for dev_set_name() failures Dan Williams
2021-03-31 13:09 ` Jason Gunthorpe
2021-03-31 16:04 ` Dan Williams
2021-03-31 16:17 ` Jason Gunthorpe
2021-03-31 16:32 ` Dan Williams
2021-03-30 23:36 ` [PATCH v3 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='CAPcyv4gv3rk+NhdhN=QcJMDwRSziqeDKhYtrnZFa6yOZe-_caQ@mail.gmail.com' \
--to=dan.j.williams@intel.com \
--cc=alison.schofield@intel.com \
--cc=ira.weiny@intel.com \
--cc=jgg@nvidia.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).