diff mbox series

[ndctl,1/3] libcxl: add memdev inject poison support

Message ID 20230220045709.94027-2-junhyeok.im@samsung.com
State New, archived
Headers show
Series Support for inject poison | expand

Commit Message

Junhyeok Im Feb. 20, 2023, 4:57 a.m. UTC
Add ability to inject poison based on the kernel inject poison sysfs interface.

This interface trigger inject poison function by writing DPA to the memory device
sysfs attribute ('inject_poison').

Link to corresponding kernel patchset:
  https://lore.kernel.org/linux-cxl/cover.1674101475.git.alison.schofield@intel.com/

Signed-off-by: Junhyeok Im <junhyeok.im@samsung.com>
---
 cxl/lib/libcxl.c   | 26 ++++++++++++++++++++++++++
 cxl/lib/libcxl.sym |  5 +++++
 cxl/libcxl.h       |  1 +
 3 files changed, 32 insertions(+)

Comments

Alison Schofield Feb. 27, 2023, 2:43 a.m. UTC | #1
Commit message needs to include PATCH for all of these.
ie [ndctl PATCH 1/3]

On Mon, Feb 20, 2023 at 01:57:07PM +0900, Junhyeok Im wrote:
> Add ability to inject poison based on the kernel inject poison sysfs interface.
> 
> This interface trigger inject poison function by writing DPA to the memory device
> sysfs attribute ('inject_poison').

I'm not so sure about no validation on that address, but I'll comment on
that in the next patch.

Alison

> 
> Link to corresponding kernel patchset:
>   https://lore.kernel.org/linux-cxl/cover.1674101475.git.alison.schofield@intel.com/
> 
> Signed-off-by: Junhyeok Im <junhyeok.im@samsung.com>
> ---
>  cxl/lib/libcxl.c   | 26 ++++++++++++++++++++++++++
>  cxl/lib/libcxl.sym |  5 +++++
>  cxl/libcxl.h       |  1 +
>  3 files changed, 32 insertions(+)
> 
> diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
> index 4859bd5..d2b8e19 100644
> --- a/cxl/lib/libcxl.c
> +++ b/cxl/lib/libcxl.c
> @@ -1407,6 +1407,32 @@ CXL_EXPORT int cxl_memdev_enable(struct cxl_memdev *memdev)
>  	return 0;
>  }
>  
> +CXL_EXPORT int cxl_memdev_inject_poison(struct cxl_memdev *memdev,
> +					const char *address)
> +{
> +	struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev);
> +	char *path = memdev->dev_buf;
> +	int len = memdev->buf_len, rc;
> +
> +	if (snprintf(path, len, "%s/inject_poison",
> +		     memdev->dev_path) >= len) {
> +		err(ctx, "%s: buffer too small\n",
> +		    cxl_memdev_get_devname(memdev));
> +		return -ENXIO;
> +	}

git clang-format suggests this reformatting:
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index 08ee9e61c4ca..8d8a01330891 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -1459,8 +1459,7 @@ CXL_EXPORT int cxl_memdev_inject_poison(struct cxl_memdev *memdev,
        char *path = memdev->dev_buf;
        int len = memdev->buf_len, rc;

-       if (snprintf(path, len, "%s/inject_poison",
-                    memdev->dev_path) >= len) {
+       if (snprintf(path, len, "%s/inject_poison", memdev->dev_path) >= len) {
                err(ctx, "%s: buffer too small\n",
                    cxl_memdev_get_devname(memdev));
                return -ENXIO;


> +	rc = sysfs_write_attr(ctx, path, address);
> +	if (rc < 0) {
> +		fprintf(stderr, "%s: Failed write sysfs attr inject_poison\n",
> +			cxl_memdev_get_devname(memdev));
> +		return rc;
> +	}
> +
> +	dbg(ctx, "%s: poison injected at %s\n", cxl_memdev_get_devname(memdev),
> +	    address);
> +
> +	return 0;
> +}
> +
>  static struct cxl_endpoint *cxl_port_find_endpoint(struct cxl_port *parent_port,
>  						   struct cxl_memdev *memdev)
>  {
> diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
> index 6bc0810..c6ba248 100644
> --- a/cxl/lib/libcxl.sym
> +++ b/cxl/lib/libcxl.sym
> @@ -242,3 +242,8 @@ global:
>  	cxl_target_get_firmware_node;
>  	cxl_dport_get_firmware_node;
>  } LIBCXL_3;
> +
> +LIBCXL_5 {
> +global:
> +        cxl_memdev_inject_poison;
> +} LIBCXL_4;
> diff --git a/cxl/libcxl.h b/cxl/libcxl.h
> index d699af8..7a2cc5f 100644
> --- a/cxl/libcxl.h
> +++ b/cxl/libcxl.h
> @@ -68,6 +68,7 @@ int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, size_t length,
>  		size_t offset);
>  int cxl_memdev_write_label(struct cxl_memdev *memdev, void *buf, size_t length,
>  		size_t offset);
> +int cxl_memdev_inject_poison(struct cxl_memdev *memdev, const char *address);
>  
>  #define cxl_memdev_foreach(ctx, memdev) \
>          for (memdev = cxl_memdev_get_first(ctx); \
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index 4859bd5..d2b8e19 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -1407,6 +1407,32 @@  CXL_EXPORT int cxl_memdev_enable(struct cxl_memdev *memdev)
 	return 0;
 }
 
+CXL_EXPORT int cxl_memdev_inject_poison(struct cxl_memdev *memdev,
+					const char *address)
+{
+	struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev);
+	char *path = memdev->dev_buf;
+	int len = memdev->buf_len, rc;
+
+	if (snprintf(path, len, "%s/inject_poison",
+		     memdev->dev_path) >= len) {
+		err(ctx, "%s: buffer too small\n",
+		    cxl_memdev_get_devname(memdev));
+		return -ENXIO;
+	}
+	rc = sysfs_write_attr(ctx, path, address);
+	if (rc < 0) {
+		fprintf(stderr, "%s: Failed write sysfs attr inject_poison\n",
+			cxl_memdev_get_devname(memdev));
+		return rc;
+	}
+
+	dbg(ctx, "%s: poison injected at %s\n", cxl_memdev_get_devname(memdev),
+	    address);
+
+	return 0;
+}
+
 static struct cxl_endpoint *cxl_port_find_endpoint(struct cxl_port *parent_port,
 						   struct cxl_memdev *memdev)
 {
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
index 6bc0810..c6ba248 100644
--- a/cxl/lib/libcxl.sym
+++ b/cxl/lib/libcxl.sym
@@ -242,3 +242,8 @@  global:
 	cxl_target_get_firmware_node;
 	cxl_dport_get_firmware_node;
 } LIBCXL_3;
+
+LIBCXL_5 {
+global:
+        cxl_memdev_inject_poison;
+} LIBCXL_4;
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
index d699af8..7a2cc5f 100644
--- a/cxl/libcxl.h
+++ b/cxl/libcxl.h
@@ -68,6 +68,7 @@  int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, size_t length,
 		size_t offset);
 int cxl_memdev_write_label(struct cxl_memdev *memdev, void *buf, size_t length,
 		size_t offset);
+int cxl_memdev_inject_poison(struct cxl_memdev *memdev, const char *address);
 
 #define cxl_memdev_foreach(ctx, memdev) \
         for (memdev = cxl_memdev_get_first(ctx); \