]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cxl/region: Factor out interleave ways setup
authorAlejandro Lucero <alucerop@amd.com>
Sat, 28 Feb 2026 17:36:02 +0000 (17:36 +0000)
committerDave Jiang <dave.jiang@intel.com>
Mon, 16 Mar 2026 23:32:05 +0000 (16:32 -0700)
Region creation based on Type3 devices can be triggered from user space
allowing memory combination through interleaving.

In preparation for kernel driven region creation, that is Type2 drivers
triggering region creation backed with its advertised CXL memory, factor
out a common helper from the user-sysfs region setup for interleave ways.

Signed-off-by: Alejandro Lucero <alucerop@amd.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Gregory Price <gourry@gourry.net>
Tested-by: Gregory Price <gourry@gourry.net>
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Link: https://patch.msgid.link/20260228173603.1125109-3-alejandro.lucero-palau@amd.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
drivers/cxl/core/region.c

index d1ce4deae4996e22f7dc7db86ef73cd688cd5121..55cbad38ec898712e5e8d6b37e855bdecc9b7778 100644 (file)
@@ -485,22 +485,14 @@ static ssize_t interleave_ways_show(struct device *dev,
 
 static const struct attribute_group *get_cxl_region_target_group(void);
 
-static ssize_t interleave_ways_store(struct device *dev,
-                                    struct device_attribute *attr,
-                                    const char *buf, size_t len)
+static int set_interleave_ways(struct cxl_region *cxlr, int val)
 {
-       struct cxl_region *cxlr = to_cxl_region(dev);
        struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
        struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld;
        struct cxl_region_params *p = &cxlr->params;
-       unsigned int val, save;
-       int rc;
+       int save, rc;
        u8 iw;
 
-       rc = kstrtouint(buf, 0, &val);
-       if (rc)
-               return rc;
-
        rc = ways_to_eiw(val, &iw);
        if (rc)
                return rc;
@@ -515,9 +507,7 @@ static ssize_t interleave_ways_store(struct device *dev,
                return -EINVAL;
        }
 
-       ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region);
-       if ((rc = ACQUIRE_ERR(rwsem_write_kill, &rwsem)))
-               return rc;
+       lockdep_assert_held_write(&cxl_rwsem.region);
 
        if (p->state >= CXL_CONFIG_INTERLEAVE_ACTIVE)
                return -EBUSY;
@@ -525,10 +515,31 @@ static ssize_t interleave_ways_store(struct device *dev,
        save = p->interleave_ways;
        p->interleave_ways = val;
        rc = sysfs_update_group(&cxlr->dev.kobj, get_cxl_region_target_group());
-       if (rc) {
+       if (rc)
                p->interleave_ways = save;
+
+       return rc;
+}
+
+static ssize_t interleave_ways_store(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t len)
+{
+       struct cxl_region *cxlr = to_cxl_region(dev);
+       int val;
+       int rc;
+
+       rc = kstrtoint(buf, 0, &val);
+       if (rc)
+               return rc;
+
+       ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region);
+       if ((rc = ACQUIRE_ERR(rwsem_write_kill, &rwsem)))
+               return rc;
+
+       rc = set_interleave_ways(cxlr, val);
+       if (rc)
                return rc;
-       }
 
        return len;
 }