diff mbox series

[2/2] cxl/test: Replace ENXIO with EBUSY for inject poison limit reached

Message ID e13e59c43a456f56e275d039cd0f67c6117230c8.1720052137.git.alison.schofield@intel.com
State Superseded
Headers show
Series Return EBUSY on inject poison limit reached | expand

Commit Message

Alison Schofield July 4, 2024, 12:38 a.m. UTC
From: Alison Schofield <alison.schofield@intel.com>

The CXL driver was recently updated to return EBUSY rather than
ENXIO when the device reports that an injection request exceeds
the device's limit. That change to EBUSY allows debug users to
differentiate between limit reached and inject failures for any
other reason.

Do the same here in cxl-test.

Reminder: the cxl-test per device injection limit is a configurable
attribute: /sys/bus/platform/drivers/cxl_mock_mem/poison_inject_max

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
 tools/testing/cxl/test/mem.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

Comments

Xingtao Yao (Fujitsu) July 5, 2024, 6:15 a.m. UTC | #1
> -----Original Message-----
> From: alison.schofield@intel.com <alison.schofield@intel.com>
> Sent: Thursday, July 4, 2024 8:38 AM
> To: Davidlohr Bueso <dave@stgolabs.net>; Jonathan Cameron
> <Jonathan.Cameron@huawei.com>; Dave Jiang <dave.jiang@intel.com>; Alison
> Schofield <alison.schofield@intel.com>; Vishal Verma
> <vishal.l.verma@intel.com>; Ira Weiny <ira.weiny@intel.com>; Dan Williams
> <dan.j.williams@intel.com>
> Cc: linux-cxl@vger.kernel.org
> Subject: [PATCH 2/2] cxl/test: Replace ENXIO with EBUSY for inject poison limit
> reached
> 
> From: Alison Schofield <alison.schofield@intel.com>
> 
> The CXL driver was recently updated to return EBUSY rather than
> ENXIO when the device reports that an injection request exceeds
> the device's limit. That change to EBUSY allows debug users to
> differentiate between limit reached and inject failures for any
> other reason.
> 
> Do the same here in cxl-test.
> 
> Reminder: the cxl-test per device injection limit is a configurable
> attribute: /sys/bus/platform/drivers/cxl_mock_mem/poison_inject_max
> 
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> ---
>  tools/testing/cxl/test/mem.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
> index eaf091a3d331..5e0c84d4d9f8 100644
> --- a/tools/testing/cxl/test/mem.c
> +++ b/tools/testing/cxl/test/mem.c
> @@ -1131,27 +1131,28 @@ static bool mock_poison_dev_max_injected(struct
> cxl_dev_state *cxlds)
>  	return (count >= poison_inject_dev_max);
>  }
> 
> -static bool mock_poison_add(struct cxl_dev_state *cxlds, u64 dpa)
> +static int mock_poison_add(struct cxl_dev_state *cxlds, u64 dpa)
>  {
> +	/* Return EBUSY to match the CXL driver handling */
>  	if (mock_poison_dev_max_injected(cxlds)) {
>  		dev_dbg(cxlds->dev,
>  			"Device poison injection limit has been reached: %d\n",
>  			MOCK_INJECT_DEV_MAX);
There is a tiny issue here, we'd better replace MOCK_INJECT_DEV_MAX with 
poison_inject_dev_max, as this value can be configured through 
/sys/bus/platform/drivers/cxl_mock_mem/poison_inject_max

like:
# echo 128 > /sys/bus/platform/drivers/cxl_mock_mem/poison_inject_max

after injecting 129 poisons, the “Device or resource busy” occurred, but the debug message
still output:
[ 7664.280587] cxl_mock_mem cxl_mem.0: Device poison injection limit has been reached: 8
[ 7664.280591] cxl_mock_mem cxl_mem.0: opcode: 0x4301 sz_in: 8 sz_out: 0 rc: -16


Tested-by: Xingtao Yao <yaoxt.fnst@fujitsu.com>

> -		return false;
> +		return -EBUSY;
>  	}
> 
>  	for (int i = 0; i < MOCK_INJECT_TEST_MAX; i++) {
>  		if (!mock_poison_list[i].cxlds) {
>  			mock_poison_list[i].cxlds = cxlds;
>  			mock_poison_list[i].dpa = dpa;
> -			return true;
> +			return 0;
>  		}
>  	}
>  	dev_dbg(cxlds->dev,
>  		"Mock test poison injection limit has been reached: %d\n",
>  		MOCK_INJECT_TEST_MAX);
> 
> -	return false;
> +	return -ENXIO;
>  }
> 
>  static bool mock_poison_found(struct cxl_dev_state *cxlds, u64 dpa)
> @@ -1175,10 +1176,8 @@ static int mock_inject_poison(struct cxl_dev_state
> *cxlds,
>  		dev_dbg(cxlds->dev, "DPA: 0x%llx already poisoned\n", dpa);
>  		return 0;
>  	}
> -	if (!mock_poison_add(cxlds, dpa))
> -		return -ENXIO;
> 
> -	return 0;
> +	return mock_poison_add(cxlds, dpa);
>  }
> 
>  static bool mock_poison_del(struct cxl_dev_state *cxlds, u64 dpa)
> --
> 2.37.3
>
Alison Schofield July 7, 2024, 1:48 a.m. UTC | #2
On Fri, Jul 05, 2024 at 06:15:24AM +0000, Xingtao Yao (Fujitsu) wrote:
> > -----Original Message-----
> > From: alison.schofield@intel.com <alison.schofield@intel.com>

snip

> > 
> > -static bool mock_poison_add(struct cxl_dev_state *cxlds, u64 dpa)
> > +static int mock_poison_add(struct cxl_dev_state *cxlds, u64 dpa)
> >  {
> > +	/* Return EBUSY to match the CXL driver handling */
> >  	if (mock_poison_dev_max_injected(cxlds)) {
> >  		dev_dbg(cxlds->dev,
> >  			"Device poison injection limit has been reached: %d\n",
> >  			MOCK_INJECT_DEV_MAX);
> There is a tiny issue here, we'd better replace MOCK_INJECT_DEV_MAX with 
> poison_inject_dev_max, as this value can be configured through 
> /sys/bus/platform/drivers/cxl_mock_mem/poison_inject_max
> 
> like:
> # echo 128 > /sys/bus/platform/drivers/cxl_mock_mem/poison_inject_max
> 
> after injecting 129 poisons, the “Device or resource busy” occurred, but the debug message
> still output:
> [ 7664.280587] cxl_mock_mem cxl_mem.0: Device poison injection limit has been reached: 8
> [ 7664.280591] cxl_mock_mem cxl_mem.0: opcode: 0x4301 sz_in: 8 sz_out: 0 rc: -16
> 
> 
> Tested-by: Xingtao Yao <yaoxt.fnst@fujitsu.com>
> 

Thanks for testing and thanks for finding this issue.

I've folded this fixup into v2 of this patch. Since it's cxl-test, and
it's a dev_dbg() message, and it's directly adjacent to what this patch
touches, I expect that will be OK. (as opposed to a seperate fixup)

--Alison
diff mbox series

Patch

diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
index eaf091a3d331..5e0c84d4d9f8 100644
--- a/tools/testing/cxl/test/mem.c
+++ b/tools/testing/cxl/test/mem.c
@@ -1131,27 +1131,28 @@  static bool mock_poison_dev_max_injected(struct cxl_dev_state *cxlds)
 	return (count >= poison_inject_dev_max);
 }
 
-static bool mock_poison_add(struct cxl_dev_state *cxlds, u64 dpa)
+static int mock_poison_add(struct cxl_dev_state *cxlds, u64 dpa)
 {
+	/* Return EBUSY to match the CXL driver handling */
 	if (mock_poison_dev_max_injected(cxlds)) {
 		dev_dbg(cxlds->dev,
 			"Device poison injection limit has been reached: %d\n",
 			MOCK_INJECT_DEV_MAX);
-		return false;
+		return -EBUSY;
 	}
 
 	for (int i = 0; i < MOCK_INJECT_TEST_MAX; i++) {
 		if (!mock_poison_list[i].cxlds) {
 			mock_poison_list[i].cxlds = cxlds;
 			mock_poison_list[i].dpa = dpa;
-			return true;
+			return 0;
 		}
 	}
 	dev_dbg(cxlds->dev,
 		"Mock test poison injection limit has been reached: %d\n",
 		MOCK_INJECT_TEST_MAX);
 
-	return false;
+	return -ENXIO;
 }
 
 static bool mock_poison_found(struct cxl_dev_state *cxlds, u64 dpa)
@@ -1175,10 +1176,8 @@  static int mock_inject_poison(struct cxl_dev_state *cxlds,
 		dev_dbg(cxlds->dev, "DPA: 0x%llx already poisoned\n", dpa);
 		return 0;
 	}
-	if (!mock_poison_add(cxlds, dpa))
-		return -ENXIO;
 
-	return 0;
+	return mock_poison_add(cxlds, dpa);
 }
 
 static bool mock_poison_del(struct cxl_dev_state *cxlds, u64 dpa)