cxl/mem: Fix synchronization mechanism for device removal vs ioctl operations
authorDan Williams <dan.j.williams@intel.com>
Thu, 1 Apr 2021 14:33:19 +0000 (07:33 -0700)
committerDan Williams <dan.j.williams@intel.com>
Tue, 6 Apr 2021 18:41:30 +0000 (11:41 -0700)
commit5877515912cc4f0d67071b7cee15076ebef24708
tree26d67ea57a15e33606c0a064f76b6f0f6ca51caf
parent6eff5721933c08c3b76d6126aee24d8f134518ef
cxl/mem: Fix synchronization mechanism for device removal vs ioctl operations

The percpu_ref to gate whether cxl_memdev_ioctl() is free to use the
driver context (@cxlm) to issue I/O is overkill, implemented incorrectly
(missing a device reference before accessing the percpu_ref), and the
complexities of shutting down a percpu_ref contributed to a bug in the
error unwind in cxl_mem_add_memdev() (missing put_device() to be fixed
separately).

Use an rwsem to explicitly synchronize the usage of cxlmd->cxlm, and add
the missing reference counting for cxlmd in cxl_memdev_open() and
cxl_memdev_release_file().

Fixes: b39cb1052a5c ("cxl/mem: Register CXL memX devices")
Reported-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/161728759948.2474381.17481500816783671817.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/cxl/mem.c