Skip to contentSkip to conversation

cxl/region: Add a region sysfs interface for region lock status

PATCH Applied Li Ming 3 participants 3 messages Apr 1 CXL

lore
Share & tools
lore

Li Ming

author reviewer
#0 lore raw

PATCH v2 1/1 cxl/region: Add a region sysfs interface for region lock status

If a region is created on a root decoder with Fixed Device Confiuration attribute, the region will be locked, meaning region destroy operations are not permitted. CXL region driver returns -EPERM for region destroy operations.

Although the locked status of the corresponding root decoder implies the region is also locked, exposing the region lock status directly to userspace improves usability for users who may not be aware of this relationship.

---
v2:
* Add more info to the interface description. (Alison)

---
 Documentation/ABI/testing/sysfs-bus-cxl | 13 +++++++++++++
 drivers/cxl/core/region.c               | 17 +++++++++++++++++
 2 files changed, 30 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +13 -0
index c80a1b5a03db..16a9b3d2e2c0 100644
@@ -508,6 +508,19 @@ Description:
 		(RO) The size of extended linear cache, if there is an extended
 		linear cache. Otherwise the attribute will not be visible.
 
+
+What:		/sys/bus/cxl/devices/regionZ/locked
+Date:		Mar, 2026
+KernelVersion:	v7.1
+Contact:	[email protected]
+Description:
+		(RO) The CXL driver has the capability to lock a region based on
+		a BIOS or platform dependent configuration. Regions created as
+		locked are never permitted to be destroyed. Resets to participating
+		decoders will not result in a region destroy and will not free the
+		decoder resources.
+
+
 What:		/sys/bus/cxl/devices/regionZ/mode
 Date:		January, 2023
 KernelVersion:	v6.3
drivers/cxl/core/region.c +17 -0
index 42874948b589..95d81816008e 100644
@@ -767,6 +767,22 @@ static ssize_t extended_linear_cache_size_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(extended_linear_cache_size);
 
+static ssize_t locked_show(struct device *dev,
+			   struct device_attribute *attr,
+			   char *buf)
+{
+	struct cxl_region *cxlr = to_cxl_region(dev);
+	int rc;
+
+	ACQUIRE(rwsem_read_intr, rwsem)(&cxl_rwsem.region);
+	if ((rc = ACQUIRE_ERR(rwsem_read_intr, &rwsem)))
+		return rc;
+
+	rc = test_bit(CXL_REGION_F_LOCK, &cxlr->flags);
+	return sysfs_emit(buf, "%d\n", rc);
+}
+static DEVICE_ATTR_RO(locked);
+
 static struct attribute *cxl_region_attrs[] = {
 	&dev_attr_uuid.attr,
 	&dev_attr_commit.attr,
@@ -776,6 +792,7 @@ static struct attribute *cxl_region_attrs[] = {
 	&dev_attr_size.attr,
 	&dev_attr_mode.attr,
 	&dev_attr_extended_linear_cache_size.attr,
+	&dev_attr_locked.attr,
 	NULL,
 };
 
Signature · 1 line
2.43.0
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 4 lines · Li Ming

If a region is created on a root decoder with Fixed Device Confiuration attribute, the region will be locked, meaning region destroy operations are not permitted. CXL region driver returns -EPERM for region destroy operations.

The above intro is too narrow for why region may be locked. See v1 comments. Let's keep it similar to the sysfs 'Description:' field, like this:

The CXL driver has the capability to lock a region based on a BIOS or platform dependent configuration. Region destroy operations are not permitted on locked regions and the CXL region driver returns -EPERM for region destroy operations.

Otherwise, LGTM

Quoted 79 lines

Although the locked status of the corresponding root decoder implies the region is also locked, exposing the region lock status directly to userspace improves usability for users who may not be aware of this relationship.

---
v2:
* Add more info to the interface description. (Alison)

---
 Documentation/ABI/testing/sysfs-bus-cxl | 13 +++++++++++++
 drivers/cxl/core/region.c               | 17 +++++++++++++++++
 2 files changed, 30 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +13 -0
index c80a1b5a03db..16a9b3d2e2c0 100644
@@ -508,6 +508,19 @@ Description:
 		(RO) The size of extended linear cache, if there is an extended
 		linear cache. Otherwise the attribute will not be visible.
 
+
+What:		/sys/bus/cxl/devices/regionZ/locked
+Date:		Mar, 2026
+KernelVersion:	v7.1
+Contact:	[email protected]
+Description:
+		(RO) The CXL driver has the capability to lock a region based on
+		a BIOS or platform dependent configuration. Regions created as
+		locked are never permitted to be destroyed. Resets to participating
+		decoders will not result in a region destroy and will not free the
+		decoder resources.
+
+
 What:		/sys/bus/cxl/devices/regionZ/mode
 Date:		January, 2023
 KernelVersion:	v6.3
drivers/cxl/core/region.c +17 -0
index 42874948b589..95d81816008e 100644
@@ -767,6 +767,22 @@ static ssize_t extended_linear_cache_size_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(extended_linear_cache_size);
 
+static ssize_t locked_show(struct device *dev,
+			   struct device_attribute *attr,
+			   char *buf)
+{
+	struct cxl_region *cxlr = to_cxl_region(dev);
+	int rc;
+
+	ACQUIRE(rwsem_read_intr, rwsem)(&cxl_rwsem.region);
+	if ((rc = ACQUIRE_ERR(rwsem_read_intr, &rwsem)))
+		return rc;
+
+	rc = test_bit(CXL_REGION_F_LOCK, &cxlr->flags);
+	return sysfs_emit(buf, "%d\n", rc);
+}
+static DEVICE_ATTR_RO(locked);
+
 static struct attribute *cxl_region_attrs[] = {
 	&dev_attr_uuid.attr,
 	&dev_attr_commit.attr,
@@ -776,6 +792,7 @@ static struct attribute *cxl_region_attrs[] = {
 	&dev_attr_size.attr,
 	&dev_attr_mode.attr,
 	&dev_attr_extended_linear_cache_size.attr,
+	&dev_attr_locked.attr,
 	NULL,
 };
 
Signature · 1 line
2.43.0
maintainer Applied
#2 lore raw
In reply to Li Ming
Quoted 5 lines · Li Ming

If a region is created on a root decoder with Fixed Device Confiuration attribute, the region will be locked, meaning region destroy operations are not permitted. CXL region driver returns -EPERM for region destroy operations.

Quoted 8 lines

Although the locked status of the corresponding root decoder implies the region is also locked, exposing the region lock status directly to userspace improves usability for users who may not be aware of this relationship.

Applied to cxl/next with commit log ammended per Alison. d585bc86fb9f

Quoted 67 lines

---
v2:
* Add more info to the interface description. (Alison)

---
 Documentation/ABI/testing/sysfs-bus-cxl | 13 +++++++++++++
 drivers/cxl/core/region.c               | 17 +++++++++++++++++
 2 files changed, 30 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +13 -0
index c80a1b5a03db..16a9b3d2e2c0 100644
@@ -508,6 +508,19 @@ Description:
 		(RO) The size of extended linear cache, if there is an extended
 		linear cache. Otherwise the attribute will not be visible.
 
+
+What:		/sys/bus/cxl/devices/regionZ/locked
+Date:		Mar, 2026
+KernelVersion:	v7.1
+Contact:	[email protected]
+Description:
+		(RO) The CXL driver has the capability to lock a region based on
+		a BIOS or platform dependent configuration. Regions created as
+		locked are never permitted to be destroyed. Resets to participating
+		decoders will not result in a region destroy and will not free the
+		decoder resources.
+
+
 What:		/sys/bus/cxl/devices/regionZ/mode
 Date:		January, 2023
 KernelVersion:	v6.3
drivers/cxl/core/region.c +17 -0
index 42874948b589..95d81816008e 100644
@@ -767,6 +767,22 @@ static ssize_t extended_linear_cache_size_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(extended_linear_cache_size);
 
+static ssize_t locked_show(struct device *dev,
+			   struct device_attribute *attr,
+			   char *buf)
+{
+	struct cxl_region *cxlr = to_cxl_region(dev);
+	int rc;
+
+	ACQUIRE(rwsem_read_intr, rwsem)(&cxl_rwsem.region);
+	if ((rc = ACQUIRE_ERR(rwsem_read_intr, &rwsem)))
+		return rc;
+
+	rc = test_bit(CXL_REGION_F_LOCK, &cxlr->flags);
+	return sysfs_emit(buf, "%d\n", rc);
+}
+static DEVICE_ATTR_RO(locked);
+
 static struct attribute *cxl_region_attrs[] = {
 	&dev_attr_uuid.attr,
 	&dev_attr_commit.attr,
@@ -776,6 +792,7 @@ static struct attribute *cxl_region_attrs[] = {
 	&dev_attr_size.attr,
 	&dev_attr_mode.attr,
 	&dev_attr_extended_linear_cache_size.attr,
+	&dev_attr_locked.attr,
 	NULL,
 };