Skip to content

Commit ae201a0

Browse files
djbwdavejiang
authored andcommitted
cxl/port: Arrange for always synchronous endpoint attach
Make it so that upon return from devm_cxl_add_endpoint() that cxl_mem_probe() can assume that the endpoint has had a chance to complete cxl_port_probe(). I.e. cxl_port module loading has completed prior to device registration. Delete the MODULE_SOFTDEP() as it is not sufficient for this purpose, but a hard link-time dependency is reliable. Specifically MODULE_SOFTDEP() does not guarantee that the module loading has completed prior to the completion of the current module's init. 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-4-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 1f1cb7f commit ae201a0

3 files changed

Lines changed: 42 additions & 43 deletions

File tree

drivers/cxl/cxl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,8 @@ struct cxl_port *devm_cxl_add_port(struct device *host,
780780
struct cxl_dport *parent_dport);
781781
struct cxl_root *devm_cxl_add_root(struct device *host,
782782
const struct cxl_root_ops *ops);
783+
int devm_cxl_add_endpoint(struct device *host, struct cxl_memdev *cxlmd,
784+
struct cxl_dport *parent_dport);
783785
struct cxl_root *find_cxl_root(struct cxl_port *port);
784786

785787
DEFINE_FREE(put_cxl_root, struct cxl_root *, if (_T) put_device(&_T->port.dev))

drivers/cxl/mem.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,44 +45,6 @@ static int cxl_mem_dpa_show(struct seq_file *file, void *data)
4545
return 0;
4646
}
4747

48-
static int devm_cxl_add_endpoint(struct device *host, struct cxl_memdev *cxlmd,
49-
struct cxl_dport *parent_dport)
50-
{
51-
struct cxl_port *parent_port = parent_dport->port;
52-
struct cxl_port *endpoint, *iter, *down;
53-
int rc;
54-
55-
/*
56-
* Now that the path to the root is established record all the
57-
* intervening ports in the chain.
58-
*/
59-
for (iter = parent_port, down = NULL; !is_cxl_root(iter);
60-
down = iter, iter = to_cxl_port(iter->dev.parent)) {
61-
struct cxl_ep *ep;
62-
63-
ep = cxl_ep_load(iter, cxlmd);
64-
ep->next = down;
65-
}
66-
67-
/* Note: endpoint port component registers are derived from @cxlds */
68-
endpoint = devm_cxl_add_port(host, &cxlmd->dev, CXL_RESOURCE_NONE,
69-
parent_dport);
70-
if (IS_ERR(endpoint))
71-
return PTR_ERR(endpoint);
72-
73-
rc = cxl_endpoint_autoremove(cxlmd, endpoint);
74-
if (rc)
75-
return rc;
76-
77-
if (!endpoint->dev.driver) {
78-
dev_err(&cxlmd->dev, "%s failed probe\n",
79-
dev_name(&endpoint->dev));
80-
return -ENXIO;
81-
}
82-
83-
return 0;
84-
}
85-
8648
static int cxl_debugfs_poison_inject(void *data, u64 dpa)
8749
{
8850
struct cxl_memdev *cxlmd = data;
@@ -275,8 +237,3 @@ MODULE_DESCRIPTION("CXL: Memory Expansion");
275237
MODULE_LICENSE("GPL v2");
276238
MODULE_IMPORT_NS("CXL");
277239
MODULE_ALIAS_CXL(CXL_DEVICE_MEMORY_EXPANDER);
278-
/*
279-
* create_endpoint() wants to validate port driver attach immediately after
280-
* endpoint registration.
281-
*/
282-
MODULE_SOFTDEP("pre: cxl_port");

drivers/cxl/port.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,50 @@ static struct cxl_driver cxl_port_driver = {
156156
.probe = cxl_port_probe,
157157
.id = CXL_DEVICE_PORT,
158158
.drv = {
159+
.probe_type = PROBE_FORCE_SYNCHRONOUS,
159160
.dev_groups = cxl_port_attribute_groups,
160161
},
161162
};
162163

164+
int devm_cxl_add_endpoint(struct device *host, struct cxl_memdev *cxlmd,
165+
struct cxl_dport *parent_dport)
166+
{
167+
struct cxl_port *parent_port = parent_dport->port;
168+
struct cxl_port *endpoint, *iter, *down;
169+
int rc;
170+
171+
/*
172+
* Now that the path to the root is established record all the
173+
* intervening ports in the chain.
174+
*/
175+
for (iter = parent_port, down = NULL; !is_cxl_root(iter);
176+
down = iter, iter = to_cxl_port(iter->dev.parent)) {
177+
struct cxl_ep *ep;
178+
179+
ep = cxl_ep_load(iter, cxlmd);
180+
ep->next = down;
181+
}
182+
183+
/* Note: endpoint port component registers are derived from @cxlds */
184+
endpoint = devm_cxl_add_port(host, &cxlmd->dev, CXL_RESOURCE_NONE,
185+
parent_dport);
186+
if (IS_ERR(endpoint))
187+
return PTR_ERR(endpoint);
188+
189+
rc = cxl_endpoint_autoremove(cxlmd, endpoint);
190+
if (rc)
191+
return rc;
192+
193+
if (!endpoint->dev.driver) {
194+
dev_err(&cxlmd->dev, "%s failed probe\n",
195+
dev_name(&endpoint->dev));
196+
return -ENXIO;
197+
}
198+
199+
return 0;
200+
}
201+
EXPORT_SYMBOL_FOR_MODULES(devm_cxl_add_endpoint, "cxl_mem");
202+
163203
static int __init cxl_port_init(void)
164204
{
165205
return cxl_driver_register(&cxl_port_driver);

0 commit comments

Comments
 (0)