Skip to content

Commit cc21441

Browse files
davejiangdjbw
authored andcommitted
cxl: Fix sysfs export of qos_class for memdev
Current implementation exports only to /sys/bus/cxl/devices/.../memN/qos_class. With both ram and pmem exposed, the second registered sysfs attribute is rejected as duplicate. It's not possible to create qos_class under the dev_groups via the driver due to the ram and pmem sysfs sub-directories already created by the device sysfs groups. Move the ram and pmem qos_class to the device sysfs groups and add a call to sysfs_update() after the perf data are validated so the qos_class can be visible. The end results should be /sys/bus/cxl/devices/.../memN/ram/qos_class and /sys/bus/cxl/devices/.../memN/pmem/qos_class. Signed-off-by: Dave Jiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent 10cb393 commit cc21441

File tree

4 files changed

+66
-36
lines changed

4 files changed

+66
-36
lines changed

drivers/cxl/core/cdat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ void cxl_endpoint_parse_cdat(struct cxl_port *port)
382382

383383
cxl_memdev_set_qos_class(cxlds, dsmas_xa);
384384
cxl_qos_class_verify(cxlmd);
385+
cxl_memdev_update_perf(cxlmd);
385386
}
386387
EXPORT_SYMBOL_NS_GPL(cxl_endpoint_parse_cdat, CXL);
387388

drivers/cxl/core/memdev.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,41 @@ static struct attribute *cxl_memdev_attributes[] = {
447447
NULL,
448448
};
449449

450+
static ssize_t pmem_qos_class_show(struct device *dev,
451+
struct device_attribute *attr, char *buf)
452+
{
453+
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
454+
struct cxl_dev_state *cxlds = cxlmd->cxlds;
455+
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
456+
457+
return sysfs_emit(buf, "%d\n", mds->pmem_perf.qos_class);
458+
}
459+
460+
static struct device_attribute dev_attr_pmem_qos_class =
461+
__ATTR(qos_class, 0444, pmem_qos_class_show, NULL);
462+
450463
static struct attribute *cxl_memdev_pmem_attributes[] = {
451464
&dev_attr_pmem_size.attr,
465+
&dev_attr_pmem_qos_class.attr,
452466
NULL,
453467
};
454468

469+
static ssize_t ram_qos_class_show(struct device *dev,
470+
struct device_attribute *attr, char *buf)
471+
{
472+
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
473+
struct cxl_dev_state *cxlds = cxlmd->cxlds;
474+
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
475+
476+
return sysfs_emit(buf, "%d\n", mds->ram_perf.qos_class);
477+
}
478+
479+
static struct device_attribute dev_attr_ram_qos_class =
480+
__ATTR(qos_class, 0444, ram_qos_class_show, NULL);
481+
455482
static struct attribute *cxl_memdev_ram_attributes[] = {
456483
&dev_attr_ram_size.attr,
484+
&dev_attr_ram_qos_class.attr,
457485
NULL,
458486
};
459487

@@ -477,14 +505,42 @@ static struct attribute_group cxl_memdev_attribute_group = {
477505
.is_visible = cxl_memdev_visible,
478506
};
479507

508+
static umode_t cxl_ram_visible(struct kobject *kobj, struct attribute *a, int n)
509+
{
510+
struct device *dev = kobj_to_dev(kobj);
511+
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
512+
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
513+
514+
if (a == &dev_attr_ram_qos_class.attr)
515+
if (mds->ram_perf.qos_class == CXL_QOS_CLASS_INVALID)
516+
return 0;
517+
518+
return a->mode;
519+
}
520+
480521
static struct attribute_group cxl_memdev_ram_attribute_group = {
481522
.name = "ram",
482523
.attrs = cxl_memdev_ram_attributes,
524+
.is_visible = cxl_ram_visible,
483525
};
484526

527+
static umode_t cxl_pmem_visible(struct kobject *kobj, struct attribute *a, int n)
528+
{
529+
struct device *dev = kobj_to_dev(kobj);
530+
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
531+
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
532+
533+
if (a == &dev_attr_pmem_qos_class.attr)
534+
if (mds->pmem_perf.qos_class == CXL_QOS_CLASS_INVALID)
535+
return 0;
536+
537+
return a->mode;
538+
}
539+
485540
static struct attribute_group cxl_memdev_pmem_attribute_group = {
486541
.name = "pmem",
487542
.attrs = cxl_memdev_pmem_attributes,
543+
.is_visible = cxl_pmem_visible,
488544
};
489545

490546
static umode_t cxl_memdev_security_visible(struct kobject *kobj,
@@ -519,6 +575,13 @@ static const struct attribute_group *cxl_memdev_attribute_groups[] = {
519575
NULL,
520576
};
521577

578+
void cxl_memdev_update_perf(struct cxl_memdev *cxlmd)
579+
{
580+
sysfs_update_group(&cxlmd->dev.kobj, &cxl_memdev_ram_attribute_group);
581+
sysfs_update_group(&cxlmd->dev.kobj, &cxl_memdev_pmem_attribute_group);
582+
}
583+
EXPORT_SYMBOL_NS_GPL(cxl_memdev_update_perf, CXL);
584+
522585
static const struct device_type cxl_memdev_type = {
523586
.name = "cxl_memdev",
524587
.release = cxl_memdev_release,

drivers/cxl/cxl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,8 @@ void cxl_switch_parse_cdat(struct cxl_port *port);
880880
int cxl_endpoint_get_perf_coordinates(struct cxl_port *port,
881881
struct access_coordinate *coord);
882882

883+
void cxl_memdev_update_perf(struct cxl_memdev *cxlmd);
884+
883885
/*
884886
* Unit test builds overrides this to __weak, find the 'strong' version
885887
* of these symbols in tools/testing/cxl/.

drivers/cxl/mem.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -215,32 +215,6 @@ static ssize_t trigger_poison_list_store(struct device *dev,
215215
}
216216
static DEVICE_ATTR_WO(trigger_poison_list);
217217

218-
static ssize_t ram_qos_class_show(struct device *dev,
219-
struct device_attribute *attr, char *buf)
220-
{
221-
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
222-
struct cxl_dev_state *cxlds = cxlmd->cxlds;
223-
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
224-
225-
return sysfs_emit(buf, "%d\n", mds->ram_perf.qos_class);
226-
}
227-
228-
static struct device_attribute dev_attr_ram_qos_class =
229-
__ATTR(qos_class, 0444, ram_qos_class_show, NULL);
230-
231-
static ssize_t pmem_qos_class_show(struct device *dev,
232-
struct device_attribute *attr, char *buf)
233-
{
234-
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
235-
struct cxl_dev_state *cxlds = cxlmd->cxlds;
236-
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
237-
238-
return sysfs_emit(buf, "%d\n", mds->pmem_perf.qos_class);
239-
}
240-
241-
static struct device_attribute dev_attr_pmem_qos_class =
242-
__ATTR(qos_class, 0444, pmem_qos_class_show, NULL);
243-
244218
static umode_t cxl_mem_visible(struct kobject *kobj, struct attribute *a, int n)
245219
{
246220
struct device *dev = kobj_to_dev(kobj);
@@ -252,21 +226,11 @@ static umode_t cxl_mem_visible(struct kobject *kobj, struct attribute *a, int n)
252226
mds->poison.enabled_cmds))
253227
return 0;
254228

255-
if (a == &dev_attr_pmem_qos_class.attr)
256-
if (mds->pmem_perf.qos_class == CXL_QOS_CLASS_INVALID)
257-
return 0;
258-
259-
if (a == &dev_attr_ram_qos_class.attr)
260-
if (mds->ram_perf.qos_class == CXL_QOS_CLASS_INVALID)
261-
return 0;
262-
263229
return a->mode;
264230
}
265231

266232
static struct attribute *cxl_mem_attrs[] = {
267233
&dev_attr_trigger_poison_list.attr,
268-
&dev_attr_ram_qos_class.attr,
269-
&dev_attr_pmem_qos_class.attr,
270234
NULL
271235
};
272236

0 commit comments

Comments
 (0)