Re: [PATCH v3] cxl/memdev: fix deadlock in cxl_memdev_autoremove() on attach failure

From: Davidlohr Bueso

Date: Wed Feb 11 2026 - 17:54:28 EST


On Wed, 11 Feb 2026, Gregory Price wrote:

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.

I preferred the "if (!cxl_memdev_did_attach())" but the below still
reads nicely.

Reviewed-by: Davidlohr Bueso <dave@xxxxxxxxxxxx>