Skip to content

Commit d6602e2

Browse files
committed
cxl/region: Add support to indicate region has extended linear cache
Add a region sysfs attribute to show the size of the extended linear cache if there is any. The attribute is invisible when the cache size is 0, which indicates it does not exist. Moved the cxl_region_visible() location in order to pick up the new sysfs attribute definition. [ dj: Fixed spelling errors noted by Benjamin ] Reviewed-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Ben Cheatham <benjamin.cheatham@amd.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Link: https://patch.msgid.link/20251022203052.4078527-1-dave.jiang@intel.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent f0c5d3b commit d6602e2

2 files changed

Lines changed: 54 additions & 16 deletions

File tree

Documentation/ABI/testing/sysfs-bus-cxl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,17 @@ Description:
496496
changed, only freed by writing 0. The kernel makes no guarantees
497497
that data is maintained over an address space freeing event, and
498498
there is no guarantee that a free followed by an allocate
499-
results in the same address being allocated.
499+
results in the same address being allocated. If extended linear
500+
cache is present, the size indicates extended linear cache size
501+
plus the CXL region size.
500502

503+
What: /sys/bus/cxl/devices/regionZ/extended_linear_cache_size
504+
Date: October, 2025
505+
KernelVersion: v6.19
506+
Contact: linux-cxl@vger.kernel.org
507+
Description:
508+
(RO) The size of extended linear cache, if there is an extended
509+
linear cache. Otherwise the attribute will not be visible.
501510

502511
What: /sys/bus/cxl/devices/regionZ/mode
503512
Date: January, 2023

drivers/cxl/core/region.c

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -461,21 +461,6 @@ static ssize_t commit_show(struct device *dev, struct device_attribute *attr,
461461
}
462462
static DEVICE_ATTR_RW(commit);
463463

464-
static umode_t cxl_region_visible(struct kobject *kobj, struct attribute *a,
465-
int n)
466-
{
467-
struct device *dev = kobj_to_dev(kobj);
468-
struct cxl_region *cxlr = to_cxl_region(dev);
469-
470-
/*
471-
* Support tooling that expects to find a 'uuid' attribute for all
472-
* regions regardless of mode.
473-
*/
474-
if (a == &dev_attr_uuid.attr && cxlr->mode != CXL_PARTMODE_PMEM)
475-
return 0444;
476-
return a->mode;
477-
}
478-
479464
static ssize_t interleave_ways_show(struct device *dev,
480465
struct device_attribute *attr, char *buf)
481466
{
@@ -754,6 +739,21 @@ static ssize_t size_show(struct device *dev, struct device_attribute *attr,
754739
}
755740
static DEVICE_ATTR_RW(size);
756741

742+
static ssize_t extended_linear_cache_size_show(struct device *dev,
743+
struct device_attribute *attr,
744+
char *buf)
745+
{
746+
struct cxl_region *cxlr = to_cxl_region(dev);
747+
struct cxl_region_params *p = &cxlr->params;
748+
ssize_t rc;
749+
750+
ACQUIRE(rwsem_read_intr, rwsem)(&cxl_rwsem.region);
751+
if ((rc = ACQUIRE_ERR(rwsem_read_intr, &rwsem)))
752+
return rc;
753+
return sysfs_emit(buf, "%#llx\n", p->cache_size);
754+
}
755+
static DEVICE_ATTR_RO(extended_linear_cache_size);
756+
757757
static struct attribute *cxl_region_attrs[] = {
758758
&dev_attr_uuid.attr,
759759
&dev_attr_commit.attr,
@@ -762,9 +762,34 @@ static struct attribute *cxl_region_attrs[] = {
762762
&dev_attr_resource.attr,
763763
&dev_attr_size.attr,
764764
&dev_attr_mode.attr,
765+
&dev_attr_extended_linear_cache_size.attr,
765766
NULL,
766767
};
767768

769+
static umode_t cxl_region_visible(struct kobject *kobj, struct attribute *a,
770+
int n)
771+
{
772+
struct device *dev = kobj_to_dev(kobj);
773+
struct cxl_region *cxlr = to_cxl_region(dev);
774+
775+
/*
776+
* Support tooling that expects to find a 'uuid' attribute for all
777+
* regions regardless of mode.
778+
*/
779+
if (a == &dev_attr_uuid.attr && cxlr->mode != CXL_PARTMODE_PMEM)
780+
return 0444;
781+
782+
/*
783+
* Don't display extended linear cache attribute if there is no
784+
* extended linear cache.
785+
*/
786+
if (a == &dev_attr_extended_linear_cache_size.attr &&
787+
cxlr->params.cache_size == 0)
788+
return 0;
789+
790+
return a->mode;
791+
}
792+
768793
static const struct attribute_group cxl_region_group = {
769794
.attrs = cxl_region_attrs,
770795
.is_visible = cxl_region_visible,
@@ -3479,6 +3504,10 @@ static int __construct_region(struct cxl_region *cxlr,
34793504
"Extended linear cache calculation failed rc:%d\n", rc);
34803505
}
34813506

3507+
rc = sysfs_update_group(&cxlr->dev.kobj, &cxl_region_group);
3508+
if (rc)
3509+
return rc;
3510+
34823511
rc = insert_resource(cxlrd->res, res);
34833512
if (rc) {
34843513
/*

0 commit comments

Comments
 (0)