Skip to content

Commit d3953c7

Browse files
committed
Merge branch 'for-6.8/cxl-cdat' into for-6.8/cxl
Pick up some follow-on fixes for 'cxl_root' reference count leaks.
2 parents 11c8393 + 321dd36 commit d3953c7

6 files changed

Lines changed: 44 additions & 27 deletions

File tree

drivers/cxl/acpi.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,12 @@ cxl_acpi_evaluate_qtg_dsm(acpi_handle handle, struct access_coordinate *coord,
295295
return rc;
296296
}
297297

298-
static int cxl_acpi_qos_class(struct cxl_port *root_port,
298+
static int cxl_acpi_qos_class(struct cxl_root *cxl_root,
299299
struct access_coordinate *coord, int entries,
300300
int *qos_class)
301301
{
302+
struct device *dev = cxl_root->port.uport_dev;
302303
acpi_handle handle;
303-
struct device *dev;
304-
305-
dev = root_port->uport_dev;
306304

307305
if (!dev_is_platform(dev))
308306
return -ENODEV;

drivers/cxl/core/cdat.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
162162
struct xarray *dsmas_xa)
163163
{
164164
struct access_coordinate c;
165-
struct cxl_port *root_port;
166-
struct cxl_root *cxl_root;
167165
struct dsmas_entry *dent;
168166
int valid_entries = 0;
169167
unsigned long index;
@@ -175,8 +173,11 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
175173
return rc;
176174
}
177175

178-
root_port = find_cxl_root(port);
179-
cxl_root = to_cxl_root(root_port);
176+
struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
177+
178+
if (!cxl_root)
179+
return -ENODEV;
180+
180181
if (!cxl_root->ops || !cxl_root->ops->qos_class)
181182
return -EOPNOTSUPP;
182183

@@ -193,7 +194,8 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
193194
dent->coord.write_bandwidth);
194195

195196
dent->entries = 1;
196-
rc = cxl_root->ops->qos_class(root_port, &dent->coord, 1, &qos_class);
197+
rc = cxl_root->ops->qos_class(cxl_root, &dent->coord, 1,
198+
&qos_class);
197199
if (rc != 1)
198200
continue;
199201

@@ -349,15 +351,19 @@ static int cxl_qos_class_verify(struct cxl_memdev *cxlmd)
349351
{
350352
struct cxl_dev_state *cxlds = cxlmd->cxlds;
351353
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
352-
struct cxl_port *root_port __free(put_device) = NULL;
353354
LIST_HEAD(__discard);
354355
struct list_head *discard __free(dpa_perf) = &__discard;
356+
struct cxl_port *root_port;
355357
int rc;
356358

357-
root_port = find_cxl_root(cxlmd->endpoint);
358-
if (!root_port)
359+
struct cxl_root *cxl_root __free(put_cxl_root) =
360+
find_cxl_root(cxlmd->endpoint);
361+
362+
if (!cxl_root)
359363
return -ENODEV;
360364

365+
root_port = &cxl_root->port;
366+
361367
/* Check that the QTG IDs are all sane between end device and root decoders */
362368
cxl_qos_match(root_port, &mds->ram_perf_list, discard);
363369
cxl_qos_match(root_port, &mds->pmem_perf_list, discard);

drivers/cxl/core/pmem.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ static int match_nvdimm_bridge(struct device *dev, void *data)
6464

6565
struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_memdev *cxlmd)
6666
{
67-
struct cxl_port *port = find_cxl_root(cxlmd->endpoint);
67+
struct cxl_root *cxl_root __free(put_cxl_root) =
68+
find_cxl_root(cxlmd->endpoint);
6869
struct device *dev;
6970

70-
if (!port)
71+
if (!cxl_root)
7172
return NULL;
7273

73-
dev = device_find_child(&port->dev, NULL, match_nvdimm_bridge);
74-
put_device(&port->dev);
74+
dev = device_find_child(&cxl_root->port.dev, NULL, match_nvdimm_bridge);
7575

7676
if (!dev)
7777
return NULL;

drivers/cxl/core/port.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ static bool dev_is_cxl_root_child(struct device *dev)
972972
return false;
973973
}
974974

975-
struct cxl_port *find_cxl_root(struct cxl_port *port)
975+
struct cxl_root *find_cxl_root(struct cxl_port *port)
976976
{
977977
struct cxl_port *iter = port;
978978

@@ -982,10 +982,19 @@ struct cxl_port *find_cxl_root(struct cxl_port *port)
982982
if (!iter)
983983
return NULL;
984984
get_device(&iter->dev);
985-
return iter;
985+
return to_cxl_root(iter);
986986
}
987987
EXPORT_SYMBOL_NS_GPL(find_cxl_root, CXL);
988988

989+
void put_cxl_root(struct cxl_root *cxl_root)
990+
{
991+
if (!cxl_root)
992+
return;
993+
994+
put_device(&cxl_root->port.dev);
995+
}
996+
EXPORT_SYMBOL_NS_GPL(put_cxl_root, CXL);
997+
989998
static struct cxl_dport *find_dport(struct cxl_port *port, int id)
990999
{
9911000
struct cxl_dport *dport;

drivers/cxl/cxl.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -617,12 +617,6 @@ struct cxl_port {
617617
long pci_latency;
618618
};
619619

620-
struct cxl_root_ops {
621-
int (*qos_class)(struct cxl_port *root_port,
622-
struct access_coordinate *coord, int entries,
623-
int *qos_class);
624-
};
625-
626620
/**
627621
* struct cxl_root - logical collection of root cxl_port items
628622
*
@@ -640,6 +634,12 @@ to_cxl_root(const struct cxl_port *port)
640634
return container_of(port, struct cxl_root, port);
641635
}
642636

637+
struct cxl_root_ops {
638+
int (*qos_class)(struct cxl_root *cxl_root,
639+
struct access_coordinate *coord, int entries,
640+
int *qos_class);
641+
};
642+
643643
static inline struct cxl_dport *
644644
cxl_find_dport_by_dev(struct cxl_port *port, const struct device *dport_dev)
645645
{
@@ -734,7 +734,10 @@ struct cxl_port *devm_cxl_add_port(struct device *host,
734734
struct cxl_dport *parent_dport);
735735
struct cxl_root *devm_cxl_add_root(struct device *host,
736736
const struct cxl_root_ops *ops);
737-
struct cxl_port *find_cxl_root(struct cxl_port *port);
737+
struct cxl_root *find_cxl_root(struct cxl_port *port);
738+
void put_cxl_root(struct cxl_root *cxl_root);
739+
DEFINE_FREE(put_cxl_root, struct cxl_root *, if (_T) put_cxl_root(_T))
740+
738741
int devm_cxl_enumerate_ports(struct cxl_memdev *cxlmd);
739742
void cxl_bus_rescan(void);
740743
void cxl_bus_drain(void);

drivers/cxl/port.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,15 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)
130130
* This can't fail in practice as CXL root exit unregisters all
131131
* descendant ports and that in turn synchronizes with cxl_port_probe()
132132
*/
133-
root = find_cxl_root(port);
133+
struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
134+
135+
root = &cxl_root->port;
134136

135137
/*
136138
* Now that all endpoint decoders are successfully enumerated, try to
137139
* assemble regions from committed decoders
138140
*/
139141
device_for_each_child(&port->dev, root, discover_region);
140-
put_device(&root->dev);
141142

142143
return 0;
143144
}

0 commit comments

Comments
 (0)