[PATCH v9 12/13] cxl/region: Factor out code into cxl_region_setup_poison()

Robert Richter posted 13 patches 4 weeks, 1 day ago
There is a newer version of this series
[PATCH v9 12/13] cxl/region: Factor out code into cxl_region_setup_poison()
Posted by Robert Richter 4 weeks, 1 day ago
Poison injection setup code is embedded in cxl_region_probe(). For
improved encapsulation, readability, and maintainability, factor out
code into function cxl_region_setup_poison().

This patch is a prerequisit to disable poison injection for Normalized
Addressing.

No functional changes.

Signed-off-by: Robert Richter <rrichter@amd.com>
---
 drivers/cxl/core/region.c | 53 +++++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 25 deletions(-)

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index ed8469fa55a9..80cd77f0842e 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -3916,6 +3916,31 @@ static int cxl_region_debugfs_poison_clear(void *data, u64 offset)
 DEFINE_DEBUGFS_ATTRIBUTE(cxl_poison_clear_fops, NULL,
 			 cxl_region_debugfs_poison_clear, "%llx\n");
 
+static int cxl_region_setup_poison(struct cxl_region *cxlr)
+{
+	struct device *dev = &cxlr->dev;
+	struct cxl_region_params *p = &cxlr->params;
+	struct dentry *dentry;
+
+	/* Create poison attributes if all memdevs support the capabilities */
+	for (int i = 0; i < p->nr_targets; i++) {
+		struct cxl_endpoint_decoder *cxled = p->targets[i];
+		struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
+
+		if (!cxl_memdev_has_poison_cmd(cxlmd, CXL_POISON_ENABLED_INJECT) ||
+		    !cxl_memdev_has_poison_cmd(cxlmd, CXL_POISON_ENABLED_CLEAR))
+			return 0;
+	}
+
+	dentry = cxl_debugfs_create_dir(dev_name(dev));
+	debugfs_create_file("inject_poison", 0200, dentry, cxlr,
+			    &cxl_poison_inject_fops);
+	debugfs_create_file("clear_poison", 0200, dentry, cxlr,
+			    &cxl_poison_clear_fops);
+
+	return devm_add_action_or_reset(dev, remove_debugfs, dentry);
+}
+
 static int cxl_region_can_probe(struct cxl_region *cxlr)
 {
 	struct cxl_region_params *p = &cxlr->params;
@@ -3945,7 +3970,6 @@ static int cxl_region_probe(struct device *dev)
 {
 	struct cxl_region *cxlr = to_cxl_region(dev);
 	struct cxl_region_params *p = &cxlr->params;
-	bool poison_supported = true;
 	int rc;
 
 	rc = cxl_region_can_probe(cxlr);
@@ -3969,30 +3993,9 @@ static int cxl_region_probe(struct device *dev)
 	if (rc)
 		return rc;
 
-	/* Create poison attributes if all memdevs support the capabilities */
-	for (int i = 0; i < p->nr_targets; i++) {
-		struct cxl_endpoint_decoder *cxled = p->targets[i];
-		struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
-
-		if (!cxl_memdev_has_poison_cmd(cxlmd, CXL_POISON_ENABLED_INJECT) ||
-		    !cxl_memdev_has_poison_cmd(cxlmd, CXL_POISON_ENABLED_CLEAR)) {
-			poison_supported = false;
-			break;
-		}
-	}
-
-	if (poison_supported) {
-		struct dentry *dentry;
-
-		dentry = cxl_debugfs_create_dir(dev_name(dev));
-		debugfs_create_file("inject_poison", 0200, dentry, cxlr,
-				    &cxl_poison_inject_fops);
-		debugfs_create_file("clear_poison", 0200, dentry, cxlr,
-				    &cxl_poison_clear_fops);
-		rc = devm_add_action_or_reset(dev, remove_debugfs, dentry);
-		if (rc)
-			return rc;
-	}
+	rc = cxl_region_setup_poison(cxlr);
+	if (rc)
+		return rc;
 
 	switch (cxlr->mode) {
 	case CXL_PARTMODE_PMEM:
-- 
2.47.3
Re: [PATCH v9 12/13] cxl/region: Factor out code into cxl_region_setup_poison()
Posted by Alison Schofield 3 weeks, 4 days ago
On Sat, Jan 10, 2026 at 12:46:57PM +0100, Robert Richter wrote:
> Poison injection setup code is embedded in cxl_region_probe(). For
> improved encapsulation, readability, and maintainability, factor out
> code into function cxl_region_setup_poison().
> 
> This patch is a prerequisit to disable poison injection for Normalized
> Addressing.

I prefer we be clearer about intent. Poison injection altogether is not
being disabled, only by region offset. 

Replace this:
> This patch is a prerequisit to disable poison injection for Normalized
> Addressing.

With this:
This patch is a prerequisite to disable poison by region offset for
Normalized Addressing.

With that,
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Re: [PATCH v9 12/13] cxl/region: Factor out code into cxl_region_setup_poison()
Posted by Jonathan Cameron 3 weeks, 4 days ago
On Tue, 13 Jan 2026 19:32:54 -0800
Alison Schofield <alison.schofield@intel.com> wrote:

> On Sat, Jan 10, 2026 at 12:46:57PM +0100, Robert Richter wrote:
> > Poison injection setup code is embedded in cxl_region_probe(). For
> > improved encapsulation, readability, and maintainability, factor out
> > code into function cxl_region_setup_poison().
> > 
> > This patch is a prerequisit to disable poison injection for Normalized
> > Addressing.  
> 
> I prefer we be clearer about intent. Poison injection altogether is not
> being disabled, only by region offset. 
> 
> Replace this:
> > This patch is a prerequisit to disable poison injection for Normalized
> > Addressing.  
> 
> With this:
> This patch is a prerequisite to disable poison by region offset for
> Normalized Addressing.
> 
> With that,
> Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Alison's request seems sensible to me.  Otherwise looks good.
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>

> 
> 
>
Re: [PATCH v9 12/13] cxl/region: Factor out code into cxl_region_setup_poison()
Posted by Dave Jiang 3 weeks, 4 days ago

On 1/10/26 4:46 AM, Robert Richter wrote:
> Poison injection setup code is embedded in cxl_region_probe(). For
> improved encapsulation, readability, and maintainability, factor out
> code into function cxl_region_setup_poison().
> 
> This patch is a prerequisit to disable poison injection for Normalized
> Addressing.
> 
> No functional changes.
> 
> Signed-off-by: Robert Richter <rrichter@amd.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

Funny how I created the same patch yesterday for something else and didn't realize you already posted it.

> ---
>  drivers/cxl/core/region.c | 53 +++++++++++++++++++++------------------
>  1 file changed, 28 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index ed8469fa55a9..80cd77f0842e 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -3916,6 +3916,31 @@ static int cxl_region_debugfs_poison_clear(void *data, u64 offset)
>  DEFINE_DEBUGFS_ATTRIBUTE(cxl_poison_clear_fops, NULL,
>  			 cxl_region_debugfs_poison_clear, "%llx\n");
>  
> +static int cxl_region_setup_poison(struct cxl_region *cxlr)
> +{
> +	struct device *dev = &cxlr->dev;
> +	struct cxl_region_params *p = &cxlr->params;
> +	struct dentry *dentry;
> +
> +	/* Create poison attributes if all memdevs support the capabilities */
> +	for (int i = 0; i < p->nr_targets; i++) {
> +		struct cxl_endpoint_decoder *cxled = p->targets[i];
> +		struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
> +
> +		if (!cxl_memdev_has_poison_cmd(cxlmd, CXL_POISON_ENABLED_INJECT) ||
> +		    !cxl_memdev_has_poison_cmd(cxlmd, CXL_POISON_ENABLED_CLEAR))
> +			return 0;
> +	}
> +
> +	dentry = cxl_debugfs_create_dir(dev_name(dev));
> +	debugfs_create_file("inject_poison", 0200, dentry, cxlr,
> +			    &cxl_poison_inject_fops);
> +	debugfs_create_file("clear_poison", 0200, dentry, cxlr,
> +			    &cxl_poison_clear_fops);
> +
> +	return devm_add_action_or_reset(dev, remove_debugfs, dentry);
> +}
> +
>  static int cxl_region_can_probe(struct cxl_region *cxlr)
>  {
>  	struct cxl_region_params *p = &cxlr->params;
> @@ -3945,7 +3970,6 @@ static int cxl_region_probe(struct device *dev)
>  {
>  	struct cxl_region *cxlr = to_cxl_region(dev);
>  	struct cxl_region_params *p = &cxlr->params;
> -	bool poison_supported = true;
>  	int rc;
>  
>  	rc = cxl_region_can_probe(cxlr);
> @@ -3969,30 +3993,9 @@ static int cxl_region_probe(struct device *dev)
>  	if (rc)
>  		return rc;
>  
> -	/* Create poison attributes if all memdevs support the capabilities */
> -	for (int i = 0; i < p->nr_targets; i++) {
> -		struct cxl_endpoint_decoder *cxled = p->targets[i];
> -		struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
> -
> -		if (!cxl_memdev_has_poison_cmd(cxlmd, CXL_POISON_ENABLED_INJECT) ||
> -		    !cxl_memdev_has_poison_cmd(cxlmd, CXL_POISON_ENABLED_CLEAR)) {
> -			poison_supported = false;
> -			break;
> -		}
> -	}
> -
> -	if (poison_supported) {
> -		struct dentry *dentry;
> -
> -		dentry = cxl_debugfs_create_dir(dev_name(dev));
> -		debugfs_create_file("inject_poison", 0200, dentry, cxlr,
> -				    &cxl_poison_inject_fops);
> -		debugfs_create_file("clear_poison", 0200, dentry, cxlr,
> -				    &cxl_poison_clear_fops);
> -		rc = devm_add_action_or_reset(dev, remove_debugfs, dentry);
> -		if (rc)
> -			return rc;
> -	}
> +	rc = cxl_region_setup_poison(cxlr);
> +	if (rc)
> +		return rc;
>  
>  	switch (cxlr->mode) {
>  	case CXL_PARTMODE_PMEM: