]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cxl/region: Add a region sysfs interface for region lock status
authorLi Ming <ming.li@zohomail.com>
Wed, 1 Apr 2026 12:49:51 +0000 (20:49 +0800)
committerDave Jiang <dave.jiang@intel.com>
Wed, 1 Apr 2026 16:59:58 +0000 (09:59 -0700)
There are 3 scenarios that leads to a locked region:
1. A region is created on a root decoder with Fixed Device Confiuration
   attribute.
2. CXL_HDM_DECODER0_CTRL_LOCK.

Both 1 & 1 are well described in:
commit 2230c4bdc412 ("cxl: Add handling of locked CXL decoder")

3) Platform that has region creation with PRMT address translation always
   locks the region, regardless of the FIXED attribute or decoder ctrl bit.

Region locked means 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.

[ dj: Amended commit log with additional locking scenarios. ]

Signed-off-by: Li Ming <ming.li@zohomail.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Alejandro Lucero <alucerop@amd.com>
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Link: https://patch.msgid.link/20260401124951.1290041-1-ming.li@zohomail.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Documentation/ABI/testing/sysfs-bus-cxl
drivers/cxl/core/region.c

index c80a1b5a03dbae51a9f14a801235329e1f1c0794..16a9b3d2e2c0516414f92a7fdb7f240d759c5cca 100644 (file)
@@ -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:       linux-cxl@vger.kernel.org
+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
index 42874948b589b95a498230a93f5951f30317c0eb..95d81816008eff0942ebc6f68da3e31d768d8546 100644 (file)
@@ -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,
 };