Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

cxl/memdev: fix deadlock in cxl_memdev_autoremove() on attach failure

cxl_memdev_autoremove() takes device_lock(&cxlmd->dev) via guard(device)
and then calls cxl_memdev_unregister() when the attach callback was
provided but cxl_mem_probe() failed to bind.

cxl_memdev_unregister() calls
cdev_device_del()
device_del()
bus_remove_device()
device_release_driver()

This path is reached when a driver uses the @attach parameter to
devm_cxl_add_memdev() and the CXL topology fails to enumerate (e.g.
DVSEC range registers decode outside platform-defined CXL ranges,
causing the endpoint port probe to fail).

Add cxl_memdev_attach_failed() to set the scope of the check correctly.

Reported-by: kreview-c94b85d6d2
Fixes: 29317f8dc6ed ("cxl/mem: Introduce cxl_memdev_attach for CXL-dependent operation")
Signed-off-by: Gregory Price <gourry@gourry.net>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Link: https://patch.msgid.link/20260211192228.2148713-1-gourry@gourry.net
Signed-off-by: Dave Jiang <dave.jiang@intel.com>

authored by

Gregory Price and committed by
Dave Jiang
318c5885 6de23f81

+9 -4
+9 -4
drivers/cxl/core/memdev.c
··· 1089 1089 DEFINE_FREE(put_cxlmd, struct cxl_memdev *, 1090 1090 if (!IS_ERR_OR_NULL(_T)) put_device(&_T->dev)) 1091 1091 1092 - static struct cxl_memdev *cxl_memdev_autoremove(struct cxl_memdev *cxlmd) 1092 + static bool cxl_memdev_attach_failed(struct cxl_memdev *cxlmd) 1093 1093 { 1094 - int rc; 1095 - 1096 1094 /* 1097 1095 * If @attach is provided fail if the driver is not attached upon 1098 1096 * return. Note that failure here could be the result of a race to ··· 1098 1100 * succeeded and then cxl_mem unbound before the lock is acquired. 1099 1101 */ 1100 1102 guard(device)(&cxlmd->dev); 1101 - if (cxlmd->attach && !cxlmd->dev.driver) { 1103 + return (cxlmd->attach && !cxlmd->dev.driver); 1104 + } 1105 + 1106 + static struct cxl_memdev *cxl_memdev_autoremove(struct cxl_memdev *cxlmd) 1107 + { 1108 + int rc; 1109 + 1110 + if (cxl_memdev_attach_failed(cxlmd)) { 1102 1111 cxl_memdev_unregister(cxlmd); 1103 1112 return ERR_PTR(-ENXIO); 1104 1113 }