[PATCH 2/2] cxl/region: skip default driver attach for memdev with attach callbacks

Gregory Price
2026-02-21T04:30:20Z

When a CXL memdev has a custom attach callback, cxl_add_to_region()
should not call device_attach() on the auto-discovered region.

The default device_attach() binds the dax driver, which may online
memory via dax_kmem. The custom attach callback then has to tear down
the dax stack to convert the region to sysram, but dax_kmem refuses to
offline memory during its remove path, leaving regions stuck online.

Skip device_attach() when cxlmd->attach is set. The attach callback
is responsible for setting up the region after auto-discovery completes
(e.g. adding it as sysram directly).

Signed-off-by: Gregory Price <gourry@gourry.net>
---
drivers/cxl/core/region.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 276046d49f88..e5edeabd9262 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -3971,6 +3971,12 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)
}

if (attach) {
+ struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
+
+ /* Skip device_attach if memdev has is own attach callback */
+ if (cxlmd->attach)
+ return 0;
+
/*
* If device_attach() fails the range may still be active via
* the platform-firmware memory map, otherwise the driver for
--
2.47.3