Skip to content

Commit 1f1cb7f

Browse files
djbwdavejiang
authored andcommitted
cxl/mem: Arrange for always-synchronous memdev attach
In preparation for CXL accelerator drivers that have a hard dependency on CXL capability initialization, arrange for cxl_mem_probe() to always run synchronous with the device_add() of cxl_memdev instances. I.e. cxl_mem_driver registration is always complete before the first memdev creation event. At present, cxl_pci does not care about the attach state of the cxl_memdev because all generic memory expansion functionality can be handled by the cxl_core. For accelerators, however, that driver needs to perform driver specific initialization if CXL is available, or execute a fallback to PCIe only operation. This synchronous attach guarantee is also needed for Soft Reserve Recovery, which is an effort that needs to assert that devices have had a chance to attach before making a go / no-go decision on proceeding with CXL subsystem initialization. By moving devm_cxl_add_memdev() to cxl_mem.ko it removes async module loading as one reason that a memdev may not be attached upon return from devm_cxl_add_memdev(). Cc: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com> Cc: Alejandro Lucero <alucerop@amd.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Tested-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Ben Cheatham <benjamin.cheatham@amd.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Tested-by: Alejandro Lucero <alucerop@amd.com> Link: https://patch.msgid.link/20251216005616.3090129-3-dan.j.williams@intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 1001611 commit 1f1cb7f

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

drivers/cxl/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ if CXL_BUS
2222
config CXL_PCI
2323
tristate "PCI manageability"
2424
default CXL_BUS
25+
select CXL_MEM
2526
help
2627
The CXL specification defines a "CXL memory device" sub-class in the
2728
PCI "memory controller" base class of devices. Device's identified by
@@ -89,7 +90,6 @@ config CXL_PMEM
8990

9091
config CXL_MEM
9192
tristate "CXL: Memory Expansion"
92-
depends on CXL_PCI
9393
default CXL_BUS
9494
help
9595
The CXL.mem protocol allows a device to act as a provider of "System

drivers/cxl/core/memdev.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,12 @@ static const struct file_operations cxl_memdev_fops = {
10501050
.llseek = noop_llseek,
10511051
};
10521052

1053-
struct cxl_memdev *devm_cxl_add_memdev(struct device *host,
1054-
struct cxl_dev_state *cxlds)
1053+
/*
1054+
* Core helper for devm_cxl_add_memdev() that wants to both create a device and
1055+
* assert to the caller that upon return cxl_mem::probe() has been invoked.
1056+
*/
1057+
struct cxl_memdev *__devm_cxl_add_memdev(struct device *host,
1058+
struct cxl_dev_state *cxlds)
10551059
{
10561060
struct cxl_memdev *cxlmd;
10571061
struct device *dev;
@@ -1093,7 +1097,7 @@ struct cxl_memdev *devm_cxl_add_memdev(struct device *host,
10931097
put_device(dev);
10941098
return ERR_PTR(rc);
10951099
}
1096-
EXPORT_SYMBOL_NS_GPL(devm_cxl_add_memdev, "CXL");
1100+
EXPORT_SYMBOL_FOR_MODULES(__devm_cxl_add_memdev, "cxl_mem");
10971101

10981102
static void sanitize_teardown_notifier(void *data)
10991103
{

drivers/cxl/cxlmem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ static inline bool is_cxl_endpoint(struct cxl_port *port)
9595
return is_cxl_memdev(port->uport_dev);
9696
}
9797

98+
struct cxl_memdev *__devm_cxl_add_memdev(struct device *host,
99+
struct cxl_dev_state *cxlds);
98100
struct cxl_memdev *devm_cxl_add_memdev(struct device *host,
99101
struct cxl_dev_state *cxlds);
100102
int devm_cxl_sanitize_setup_notifier(struct device *host,

drivers/cxl/mem.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,22 @@ static int cxl_mem_probe(struct device *dev)
201201
return devm_add_action_or_reset(dev, enable_suspend, NULL);
202202
}
203203

204+
/**
205+
* devm_cxl_add_memdev - Add a CXL memory device
206+
* @host: devres alloc/release context and parent for the memdev
207+
* @cxlds: CXL device state to associate with the memdev
208+
*
209+
* Upon return the device will have had a chance to attach to the
210+
* cxl_mem driver, but may fail if the CXL topology is not ready
211+
* (hardware CXL link down, or software platform CXL root not attached)
212+
*/
213+
struct cxl_memdev *devm_cxl_add_memdev(struct device *host,
214+
struct cxl_dev_state *cxlds)
215+
{
216+
return __devm_cxl_add_memdev(host, cxlds);
217+
}
218+
EXPORT_SYMBOL_NS_GPL(devm_cxl_add_memdev, "CXL");
219+
204220
static ssize_t trigger_poison_list_store(struct device *dev,
205221
struct device_attribute *attr,
206222
const char *buf, size_t len)
@@ -248,6 +264,7 @@ static struct cxl_driver cxl_mem_driver = {
248264
.probe = cxl_mem_probe,
249265
.id = CXL_DEVICE_MEMORY_EXPANDER,
250266
.drv = {
267+
.probe_type = PROBE_FORCE_SYNCHRONOUS,
251268
.dev_groups = cxl_mem_groups,
252269
},
253270
};

0 commit comments

Comments
 (0)