Skip to content

Commit 7d980e2

Browse files
committed
Merge: cxl/mem: Fix no cxl_nvd during pmem region auto-assembling
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4936 ## Summary of Changes cxl/mem: Fix no cxl_nvd during pmem region auto-assembling ## Approved Development Ticket JIRA: https://issues.redhat.com/browse/RHEL-51364 CVE: CVE-2024-41085 Signed-off-by: John W. Linville <linville@redhat.com> Approved-by: Myron Stowe <mstowe@redhat.com> Approved-by: Charles Mirabile <cmirabil@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Lucas Zampieri <lzampier@redhat.com>
2 parents 9e9d0e6 + 1809a00 commit 7d980e2

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

drivers/cxl/core/pmem.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,21 @@ static int match_nvdimm_bridge(struct device *dev, void *data)
6262
return is_cxl_nvdimm_bridge(dev);
6363
}
6464

65-
struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_memdev *cxlmd)
65+
/**
66+
* cxl_find_nvdimm_bridge() - find a bridge device relative to a port
67+
* @port: any descendant port of an nvdimm-bridge associated
68+
* root-cxl-port
69+
*/
70+
struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_port *port)
6671
{
67-
struct cxl_port *port = find_cxl_root(cxlmd->endpoint);
72+
struct cxl_port *root_port = find_cxl_root(port);
6873
struct device *dev;
6974

70-
if (!port)
75+
if (!root_port)
7176
return NULL;
7277

73-
dev = device_find_child(&port->dev, NULL, match_nvdimm_bridge);
74-
put_device(&port->dev);
78+
dev = device_find_child(&root_port->dev, NULL, match_nvdimm_bridge);
79+
put_device(&root_port->dev);
7580

7681
if (!dev)
7782
return NULL;
@@ -242,18 +247,20 @@ static void cxlmd_release_nvdimm(void *_cxlmd)
242247

243248
/**
244249
* devm_cxl_add_nvdimm() - add a bridge between a cxl_memdev and an nvdimm
250+
* @parent_port: parent port for the (to be added) @cxlmd endpoint port
245251
* @cxlmd: cxl_memdev instance that will perform LIBNVDIMM operations
246252
*
247253
* Return: 0 on success negative error code on failure.
248254
*/
249-
int devm_cxl_add_nvdimm(struct cxl_memdev *cxlmd)
255+
int devm_cxl_add_nvdimm(struct cxl_port *parent_port,
256+
struct cxl_memdev *cxlmd)
250257
{
251258
struct cxl_nvdimm_bridge *cxl_nvb;
252259
struct cxl_nvdimm *cxl_nvd;
253260
struct device *dev;
254261
int rc;
255262

256-
cxl_nvb = cxl_find_nvdimm_bridge(cxlmd);
263+
cxl_nvb = cxl_find_nvdimm_bridge(parent_port);
257264
if (!cxl_nvb)
258265
return -ENODEV;
259266

drivers/cxl/core/region.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2547,7 +2547,7 @@ static struct cxl_pmem_region *cxl_pmem_region_alloc(struct cxl_region *cxlr)
25472547
* bridge for one device is the same for all.
25482548
*/
25492549
if (i == 0) {
2550-
cxl_nvb = cxl_find_nvdimm_bridge(cxlmd);
2550+
cxl_nvb = cxl_find_nvdimm_bridge(cxlmd->endpoint);
25512551
if (!cxl_nvb) {
25522552
kfree(cxlr_pmem);
25532553
cxlr_pmem = ERR_PTR(-ENODEV);

drivers/cxl/cxl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,8 @@ struct cxl_nvdimm_bridge *devm_cxl_add_nvdimm_bridge(struct device *host,
798798
struct cxl_nvdimm *to_cxl_nvdimm(struct device *dev);
799799
bool is_cxl_nvdimm(struct device *dev);
800800
bool is_cxl_nvdimm_bridge(struct device *dev);
801-
int devm_cxl_add_nvdimm(struct cxl_memdev *cxlmd);
802-
struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_memdev *cxlmd);
801+
int devm_cxl_add_nvdimm(struct cxl_port *parent_port, struct cxl_memdev *cxlmd);
802+
struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_port *port);
803803

804804
#ifdef CONFIG_CXL_REGION
805805
bool is_cxl_pmem_region(struct device *dev);

drivers/cxl/mem.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ static int cxl_mem_probe(struct device *dev)
152152
return -ENXIO;
153153
}
154154

155+
if (resource_size(&cxlds->pmem_res) && IS_ENABLED(CONFIG_CXL_PMEM)) {
156+
rc = devm_cxl_add_nvdimm(parent_port, cxlmd);
157+
if (rc) {
158+
if (rc == -ENODEV)
159+
dev_info(dev, "PMEM disabled by platform\n");
160+
return rc;
161+
}
162+
}
163+
155164
if (dport->rch)
156165
endpoint_parent = parent_port->uport_dev;
157166
else
@@ -174,14 +183,6 @@ static int cxl_mem_probe(struct device *dev)
174183
if (rc)
175184
return rc;
176185

177-
if (resource_size(&cxlds->pmem_res) && IS_ENABLED(CONFIG_CXL_PMEM)) {
178-
rc = devm_cxl_add_nvdimm(cxlmd);
179-
if (rc == -ENODEV)
180-
dev_info(dev, "PMEM disabled by platform\n");
181-
else
182-
return rc;
183-
}
184-
185186
/*
186187
* The kernel may be operating out of CXL memory on this device,
187188
* there is no spec defined way to determine whether this device

0 commit comments

Comments
 (0)