* [PATCH v3 1/3] cxl: Make region type based on endpoint type
2026-02-28 17:36 [PATCH v3 0/3] cxl region changes for Type2 support alejandro.lucero-palau
@ 2026-02-28 17:36 ` alejandro.lucero-palau
2026-02-28 17:36 ` [PATCH v3 2/3] cxl/region: Factor out interleave ways setup alejandro.lucero-palau
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: alejandro.lucero-palau @ 2026-02-28 17:36 UTC (permalink / raw)
To: linux-cxl, dan.j.williams, dave.jiang
Cc: Alejandro Lucero, Zhi Wang, Jonathan Cameron, Ben Cheatham,
Alison Schofield, Davidlohr Bueso, Gregory Price
From: Alejandro Lucero <alucerop@amd.com>
Current code is expecting Type3 or CXL_DECODER_HOSTONLYMEM devices only.
Support for Type2 implies region type needs to be based on the endpoint
type HDM-D[B] instead.
Signed-off-by: Alejandro Lucero <alucerop@amd.com>
Reviewed-by: Zhi Wang <zhiw@nvidia.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Ben Cheatham <benjamin.cheatham@amd.com>
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Davidlohr Bueso <daves@stgolabs.net>
Reviewed-by: Gregory Price <gourry@gourry.net>
Tested-by: Gregory Price <gourry@gourry.net>
---
drivers/cxl/core/region.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index fec37af1dfbf..cac33c99fe6a 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -2650,7 +2650,8 @@ static ssize_t create_ram_region_show(struct device *dev,
}
static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd,
- enum cxl_partition_mode mode, int id)
+ enum cxl_partition_mode mode, int id,
+ enum cxl_decoder_type target_type)
{
int rc;
@@ -2672,7 +2673,7 @@ static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd,
return ERR_PTR(-EBUSY);
}
- return devm_cxl_add_region(cxlrd, id, mode, CXL_DECODER_HOSTONLYMEM);
+ return devm_cxl_add_region(cxlrd, id, mode, target_type);
}
static ssize_t create_region_store(struct device *dev, const char *buf,
@@ -2686,7 +2687,7 @@ static ssize_t create_region_store(struct device *dev, const char *buf,
if (rc != 1)
return -EINVAL;
- cxlr = __create_region(cxlrd, mode, id);
+ cxlr = __create_region(cxlrd, mode, id, CXL_DECODER_HOSTONLYMEM);
if (IS_ERR(cxlr))
return PTR_ERR(cxlr);
@@ -3902,7 +3903,8 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,
do {
cxlr = __create_region(cxlrd, cxlds->part[part].mode,
- atomic_read(&cxlrd->region_id));
+ atomic_read(&cxlrd->region_id),
+ cxled->cxld.target_type);
} while (IS_ERR(cxlr) && PTR_ERR(cxlr) == -EBUSY);
if (IS_ERR(cxlr)) {
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 2/3] cxl/region: Factor out interleave ways setup
2026-02-28 17:36 [PATCH v3 0/3] cxl region changes for Type2 support alejandro.lucero-palau
2026-02-28 17:36 ` [PATCH v3 1/3] cxl: Make region type based on endpoint type alejandro.lucero-palau
@ 2026-02-28 17:36 ` alejandro.lucero-palau
2026-03-02 15:26 ` Jonathan Cameron
2026-03-03 1:01 ` Alison Schofield
2026-02-28 17:36 ` [PATCH v3 3/3] cxl/region: Factor out interleave granularity setup alejandro.lucero-palau
2026-03-16 23:57 ` [PATCH v3 0/3] cxl region changes for Type2 support Dave Jiang
3 siblings, 2 replies; 7+ messages in thread
From: alejandro.lucero-palau @ 2026-02-28 17:36 UTC (permalink / raw)
To: linux-cxl, dan.j.williams, dave.jiang; +Cc: Alejandro Lucero, Gregory Price
From: Alejandro Lucero <alucerop@amd.com>
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>
---
drivers/cxl/core/region.c | 41 +++++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index cac33c99fe6a..01c358b3795f 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -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;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v3 2/3] cxl/region: Factor out interleave ways setup
2026-02-28 17:36 ` [PATCH v3 2/3] cxl/region: Factor out interleave ways setup alejandro.lucero-palau
@ 2026-03-02 15:26 ` Jonathan Cameron
2026-03-03 1:01 ` Alison Schofield
1 sibling, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2026-03-02 15:26 UTC (permalink / raw)
To: alejandro.lucero-palau
Cc: linux-cxl, dan.j.williams, dave.jiang, Alejandro Lucero,
Gregory Price
On Sat, 28 Feb 2026 17:36:02 +0000
alejandro.lucero-palau@amd.com wrote:
> From: Alejandro Lucero <alucerop@amd.com>
>
> 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>
Maybe we should take this opportunity to make ->interleave_ways
unsigned and move all logic to assume this is never negative.
However this is a more minimal change so I'm fine with this and
potentially a future tidy up to make all ways values unsigned.
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/3] cxl/region: Factor out interleave ways setup
2026-02-28 17:36 ` [PATCH v3 2/3] cxl/region: Factor out interleave ways setup alejandro.lucero-palau
2026-03-02 15:26 ` Jonathan Cameron
@ 2026-03-03 1:01 ` Alison Schofield
1 sibling, 0 replies; 7+ messages in thread
From: Alison Schofield @ 2026-03-03 1:01 UTC (permalink / raw)
To: alejandro.lucero-palau
Cc: linux-cxl, dan.j.williams, dave.jiang, Alejandro Lucero,
Gregory Price
On Sat, Feb 28, 2026 at 05:36:02PM +0000, alejandro.lucero-palau@amd.com wrote:
> From: Alejandro Lucero <alucerop@amd.com>
>
> 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.
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 3/3] cxl/region: Factor out interleave granularity setup
2026-02-28 17:36 [PATCH v3 0/3] cxl region changes for Type2 support alejandro.lucero-palau
2026-02-28 17:36 ` [PATCH v3 1/3] cxl: Make region type based on endpoint type alejandro.lucero-palau
2026-02-28 17:36 ` [PATCH v3 2/3] cxl/region: Factor out interleave ways setup alejandro.lucero-palau
@ 2026-02-28 17:36 ` alejandro.lucero-palau
2026-03-16 23:57 ` [PATCH v3 0/3] cxl region changes for Type2 support Dave Jiang
3 siblings, 0 replies; 7+ messages in thread
From: alejandro.lucero-palau @ 2026-02-28 17:36 UTC (permalink / raw)
To: linux-cxl, dan.j.williams, dave.jiang
Cc: Alejandro Lucero, Gregory Price, Alison Schofield,
Jonathan Cameron
From: Alejandro Lucero <alucerop@amd.com>
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
granularity.
Signed-off-by: Alejandro Lucero <alucerop@amd.com>
Reviewed-by: Gregory Price <gourry@gourry.net>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Tested-by: Gregory Price <gourry@gourry.net>
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
---
drivers/cxl/core/region.c | 36 ++++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 01c358b3795f..4d3baa760d9e 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -559,21 +559,14 @@ static ssize_t interleave_granularity_show(struct device *dev,
return sysfs_emit(buf, "%d\n", p->interleave_granularity);
}
-static ssize_t interleave_granularity_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t len)
+static int set_interleave_granularity(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;
- int rc, val;
+ int rc;
u16 ig;
- rc = kstrtoint(buf, 0, &val);
- if (rc)
- return rc;
-
rc = granularity_to_eig(val, &ig);
if (rc)
return rc;
@@ -589,14 +582,33 @@ static ssize_t interleave_granularity_store(struct device *dev,
if (cxld->interleave_ways > 1 && val != cxld->interleave_granularity)
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;
p->interleave_granularity = val;
+ return 0;
+}
+
+static ssize_t interleave_granularity_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct cxl_region *cxlr = to_cxl_region(dev);
+ int rc, val;
+
+ 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_granularity(cxlr, val);
+ if (rc)
+ return rc;
return len;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v3 0/3] cxl region changes for Type2 support
2026-02-28 17:36 [PATCH v3 0/3] cxl region changes for Type2 support alejandro.lucero-palau
` (2 preceding siblings ...)
2026-02-28 17:36 ` [PATCH v3 3/3] cxl/region: Factor out interleave granularity setup alejandro.lucero-palau
@ 2026-03-16 23:57 ` Dave Jiang
3 siblings, 0 replies; 7+ messages in thread
From: Dave Jiang @ 2026-03-16 23:57 UTC (permalink / raw)
To: alejandro.lucero-palau, linux-cxl, dan.j.williams; +Cc: Alejandro Lucero
On 2/28/26 10:36 AM, alejandro.lucero-palau@amd.com wrote:
> From: Alejandro Lucero <alucerop@amd.com>
>
> In preparation for Type2 devices/drivers support, these next patches
> adapt the cxl region code for required Type2 functionality preserving
> current functionality.
>
> v3 changes:
> - fix type conversion in patch 2 (Allison)
> -fix commit (Jonathan)
>
> v2 changes:
> - fix commit in patches 2 and 3 (Dave)
>
> Alejandro Lucero (3):
> cxl: Make region type based on endpoint type
> cxl/region: Factor out interleave ways setup
> cxl/region: Factor out interleave granularity setup
>
> drivers/cxl/core/region.c | 87 +++++++++++++++++++++++++--------------
> 1 file changed, 56 insertions(+), 31 deletions(-)
>
>
> base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
Applied to cxl/next.
64584273dfb8 cxl/region: Factor out interleave granularity setup
29f0724c4592 cxl/region: Factor out interleave ways setup
09d065d256b1 cxl: Make region type based on endpoint type
d537d953c478 cxl/pci: Remove redundant cxl_pci_find_port() call
^ permalink raw reply [flat|nested] 7+ messages in thread