Skip to contentSkip to conversation

cxl/region: Add support to indicate region has extended linear cache

PATCH Superseded Dave Jiang 2 participants 3 messages Oct 17, 2025 – Oct 21, 2025 CXL

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Dave Jiang

author maintainer
#0 lore raw

PATCH v2 1/1 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.

---
v2:
- Add documentation. (Alison)

---
 Documentation/ABI/testing/sysfs-bus-cxl |  8 ++++
 drivers/cxl/core/region.c               | 63 +++++++++++++++++++------
 2 files changed, 56 insertions(+), 15 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +8 -0
index 6b4e8c7a963d..8d529d68dfcd 100644
@@ -498,6 +498,14 @@ Description:
 		there is no guarantee that a free followed by an allocate
 		results in the same address being allocated.
 
+What:		/sys/bus/cxl/devices/regionZ/extended_linear_cache_size
+Date:		October, 2025
+KernelVersion:	v6.19
+Contact:	[email protected]
+Description:
+		(RO) The size of extended linear cache if there is one present.
+		The region 'size' attribute would reflect the total size where
+		the CXL region size plus the extended linear cache size.
 
 What:		/sys/bus/cxl/devices/regionZ/mode
 Date:		January, 2023
drivers/cxl/core/region.c +48 -15

95 lines not on this page · raw message

base-commit: a4bbb493a3247ef32f6191fd8b2a0657139f8e08

Signature · 1 line
2.51.0
#1 lore raw
Quoted 21 lines · Dave Jiang

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.

---
v2:
- Add documentation. (Alison)

---
 Documentation/ABI/testing/sysfs-bus-cxl |  8 ++++
 drivers/cxl/core/region.c               | 63 +++++++++++++++++++------
 2 files changed, 56 insertions(+), 15 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +0 -0
index 6b4e8c7a963d..8d529d68dfcd 100644

Documentation/ABI/testing/sysfs-bus-cxl Description: · line 506

Quoted 9 lines
Documentation/ABI/testing/sysfs-bus-cxl +6 -0
@@ -498,6 +498,14 @@ Description:
 		there is no guarantee that a free followed by an allocate
 		results in the same address being allocated.
 
+What:		/sys/bus/cxl/devices/regionZ/extended_linear_cache_size
+Date:		October, 2025
+KernelVersion:	v6.19
+Contact:	[email protected]
+Description:
+		(RO) The size of extended linear cache if there is one present.

s/if there is one present/if present

Documentation/ABI/testing/sysfs-bus-cxl Description: · line 508

Quoted 2 lines
Documentation/ABI/testing/sysfs-bus-cxl +2 -0
+		The region 'size' attribute would reflect the total size where
+		the CXL region size plus the extended linear cache size.

Bit messy, maybe: "The region 'size' attribute is the CXL region size plus the extended linear cache size."

You should probably add a blurb to the size attribute's description about the extended linear cache size. Changing the meaning of the size attribute outside its own description seems wrong.

At that point you could probably drop the second sentence altogether (I'll leave that one up to you though).

Quoted 83 lines
Documentation/ABI/testing/sysfs-bus-cxl +0 -0
 What:		/sys/bus/cxl/devices/regionZ/mode
 Date:		January, 2023
drivers/cxl/core/region.c +40 -15
index b06fee1978ba..531f790b9510 100644
@@ -461,21 +461,6 @@ static ssize_t commit_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RW(commit);
 
-static umode_t cxl_region_visible(struct kobject *kobj, struct attribute *a,
-				  int n)
-{
-	struct device *dev = kobj_to_dev(kobj);
-	struct cxl_region *cxlr = to_cxl_region(dev);
-
-	/*
-	 * Support tooling that expects to find a 'uuid' attribute for all
-	 * regions regardless of mode.
-	 */
-	if (a == &dev_attr_uuid.attr && cxlr->mode != CXL_PARTMODE_PMEM)
-		return 0444;
-	return a->mode;
-}
-
 static ssize_t interleave_ways_show(struct device *dev,
 				    struct device_attribute *attr, char *buf)
 {
@@ -754,6 +739,21 @@ static ssize_t size_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RW(size);
 
+static ssize_t extended_linear_cache_size_show(struct device *dev,
+					       struct device_attribute *attr,
+					       char *buf)
+{
+	struct cxl_region *cxlr = to_cxl_region(dev);
+	struct cxl_region_params *p = &cxlr->params;
+	ssize_t rc;
+
+	ACQUIRE(rwsem_read_intr, rwsem)(&cxl_rwsem.region);
+	if ((rc = ACQUIRE_ERR(rwsem_read_intr, &rwsem)))
+		return rc;
+	return sysfs_emit(buf, "%#llx\n", p->cache_size);
+}
+static DEVICE_ATTR_RO(extended_linear_cache_size);
+
 static struct attribute *cxl_region_attrs[] = {
 	&dev_attr_uuid.attr,
 	&dev_attr_commit.attr,
@@ -762,14 +762,44 @@ static struct attribute *cxl_region_attrs[] = {
 	&dev_attr_resource.attr,
 	&dev_attr_size.attr,
 	&dev_attr_mode.attr,
+	&dev_attr_extended_linear_cache_size.attr,
 	NULL,
 };
 
+static umode_t cxl_region_visible(struct kobject *kobj, struct attribute *a,
+				  int n)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct cxl_region *cxlr = to_cxl_region(dev);
+
+	/*
+	 * Support tooling that expects to find a 'uuid' attribute for all
+	 * regions regardless of mode.
+	 */
+	if (a == &dev_attr_uuid.attr && cxlr->mode != CXL_PARTMODE_PMEM)
+		return 0444;
+
+	/*
+	 * Don't dispaly extended linear cache attribute if there is no
+	 * extended linear cache.
+	 */
+	if (a == &dev_attr_extended_linear_cache_size.attr &&
+	    cxlr->params.cache_size == 0)
+		return 0;
+
+	return a->mode;
+}
+

drivers/cxl/core/region.c static struct attribute *cxl_region_attrs[] = { · line 802

Quoted 10 lines
drivers/cxl/core/region.c +5 -0
 static const struct attribute_group cxl_region_group = {
 	.attrs = cxl_region_attrs,
 	.is_visible = cxl_region_visible,
 };
 
+static const struct attribute_group *get_cxl_region_group(void)
+{
+	return &cxl_region_group;
+}
+

Why introduce this function instead of using &cxl_region_group directly? I see there's a precedent with the target group functions, but only get_cxl_region_target_group() needs the function. The other two (get_cxl_region_accessX_group()) are only ever called after the attribute definition and should probably get cleaned up at some point.

drivers/cxl/core/region.c static int __construct_region(struct cxl_region *cxlr, · line 3511

Quoted 8 lines
drivers/cxl/core/region.c +1 -0
 static size_t show_targetN(struct cxl_region *cxlr, char *buf, int pos)
 {
 	struct cxl_region_params *p = &cxlr->params;
@@ -3478,6 +3508,9 @@ static int __construct_region(struct cxl_region *cxlr,
 		dev_warn(cxlmd->dev.parent,
 			 "Extended linear cache calculation failed rc:%d\n", rc);
 	}
+	rc = sysfs_update_group(&cxlr->dev.kobj, get_cxl_region_group());

Missing whitespace above this line?

Thanks,
Ben

Quoted 7 lines
drivers/cxl/core/region.c +2 -0
+	if (rc)
+		return rc;
 
 	rc = insert_resource(cxlrd->res, res);
 	if (rc) {

base-commit: a4bbb493a3247ef32f6191fd8b2a0657139f8e08

author maintainer
#2 lore raw
Quoted 25 lines · Benjamin
Quoted 24 lines · Dave Jiang

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.

---
v2:
- Add documentation. (Alison)

---
 Documentation/ABI/testing/sysfs-bus-cxl |  8 ++++
 drivers/cxl/core/region.c               | 63 +++++++++++++++++++------
 2 files changed, 56 insertions(+), 15 deletions(-)
Documentation/ABI/testing/sysfs-bus-cxl +0 -0
index 6b4e8c7a963d..8d529d68dfcd 100644
@@ -498,6 +498,14 @@ Description:
 		there is no guarantee that a free followed by an allocate
 		results in the same address being allocated.
 
Quoted 8 lines

Documentation/ABI/testing/sysfs-bus-cxl Description: · line 506

Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-cxl +6 -0
+What:		/sys/bus/cxl/devices/regionZ/extended_linear_cache_size
+Date:		October, 2025
+KernelVersion:	v6.19
+Contact:	[email protected]
+Description:
+		(RO) The size of extended linear cache if there is one present.

s/if there is one present/if present

ok

Quoted 5 lines

Documentation/ABI/testing/sysfs-bus-cxl Description: · line 508

Quoted 3 lines
Documentation/ABI/testing/sysfs-bus-cxl +2 -0
+		The region 'size' attribute would reflect the total size where
+		the CXL region size plus the extended linear cache size.

Bit messy, maybe: "The region 'size' attribute is the CXL region size plus the extended linear cache size."

ok

Quoted 5 lines

You should probably add a blurb to the size attribute's description about the extended linear cache size. Changing the meaning of the size attribute outside its own description seems wrong.

At that point you could probably drop the second sentence altogether (I'll leave that one up to you though).

I'll add something to 'size' and drop the additional stuff here.

Quoted 89 lines
Quoted 89 lines
Documentation/ABI/testing/sysfs-bus-cxl +0 -0
 What:		/sys/bus/cxl/devices/regionZ/mode
 Date:		January, 2023
drivers/cxl/core/region.c +40 -15
index b06fee1978ba..531f790b9510 100644
@@ -461,21 +461,6 @@ static ssize_t commit_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RW(commit);
 
-static umode_t cxl_region_visible(struct kobject *kobj, struct attribute *a,
-				  int n)
-{
-	struct device *dev = kobj_to_dev(kobj);
-	struct cxl_region *cxlr = to_cxl_region(dev);
-
-	/*
-	 * Support tooling that expects to find a 'uuid' attribute for all
-	 * regions regardless of mode.
-	 */
-	if (a == &dev_attr_uuid.attr && cxlr->mode != CXL_PARTMODE_PMEM)
-		return 0444;
-	return a->mode;
-}
-
 static ssize_t interleave_ways_show(struct device *dev,
 				    struct device_attribute *attr, char *buf)
 {
@@ -754,6 +739,21 @@ static ssize_t size_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RW(size);
 
+static ssize_t extended_linear_cache_size_show(struct device *dev,
+					       struct device_attribute *attr,
+					       char *buf)
+{
+	struct cxl_region *cxlr = to_cxl_region(dev);
+	struct cxl_region_params *p = &cxlr->params;
+	ssize_t rc;
+
+	ACQUIRE(rwsem_read_intr, rwsem)(&cxl_rwsem.region);
+	if ((rc = ACQUIRE_ERR(rwsem_read_intr, &rwsem)))
+		return rc;
+	return sysfs_emit(buf, "%#llx\n", p->cache_size);
+}
+static DEVICE_ATTR_RO(extended_linear_cache_size);
+
 static struct attribute *cxl_region_attrs[] = {
 	&dev_attr_uuid.attr,
 	&dev_attr_commit.attr,
@@ -762,14 +762,44 @@ static struct attribute *cxl_region_attrs[] = {
 	&dev_attr_resource.attr,
 	&dev_attr_size.attr,
 	&dev_attr_mode.attr,
+	&dev_attr_extended_linear_cache_size.attr,
 	NULL,
 };
 
+static umode_t cxl_region_visible(struct kobject *kobj, struct attribute *a,
+				  int n)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct cxl_region *cxlr = to_cxl_region(dev);
+
+	/*
+	 * Support tooling that expects to find a 'uuid' attribute for all
+	 * regions regardless of mode.
+	 */
+	if (a == &dev_attr_uuid.attr && cxlr->mode != CXL_PARTMODE_PMEM)
+		return 0444;
+
+	/*
+	 * Don't dispaly extended linear cache attribute if there is no
+	 * extended linear cache.
+	 */
+	if (a == &dev_attr_extended_linear_cache_size.attr &&
+	    cxlr->params.cache_size == 0)
+		return 0;
+
+	return a->mode;
+}
+
 static const struct attribute_group cxl_region_group = {
 	.attrs = cxl_region_attrs,
 	.is_visible = cxl_region_visible,
 };
 
Quoted 10 lines

drivers/cxl/core/region.c static struct attribute *cxl_region_attrs[] = { · line 802

Quoted 5 lines
drivers/cxl/core/region.c +5 -0
+static const struct attribute_group *get_cxl_region_group(void)
+{
+	return &cxl_region_group;
+}
+

Why introduce this function instead of using &cxl_region_group directly? I see there's a precedent with the target group functions, but only get_cxl_region_target_group() needs the function. The other two (get_cxl_region_accessX_group()) are only ever called after the attribute definition and should probably get cleaned up at some point.

Yeah I can drop that.

Quoted 11 lines

drivers/cxl/core/region.c static int __construct_region(struct cxl_region *cxlr, · line 3511

Quoted 9 lines
drivers/cxl/core/region.c +1 -0
 static size_t show_targetN(struct cxl_region *cxlr, char *buf, int pos)
 {
 	struct cxl_region_params *p = &cxlr->params;
@@ -3478,6 +3508,9 @@ static int __construct_region(struct cxl_region *cxlr,
 		dev_warn(cxlmd->dev.parent,
 			 "Extended linear cache calculation failed rc:%d\n", rc);
 	}
+	rc = sysfs_update_group(&cxlr->dev.kobj, get_cxl_region_group());

Missing whitespace above this line?

yes.

Thanks for the review Ben.

DJ

Quoted 12 lines

Thanks,
Ben

Quoted 7 lines
drivers/cxl/core/region.c +2 -0
+	if (rc)
+		return rc;
 
 	rc = insert_resource(cxlrd->res, res);
 	if (rc) {

base-commit: a4bbb493a3247ef32f6191fd8b2a0657139f8e08