diff mbox series

[ndctl,RESEND,2/2] cxl/region: Fix memory device teardown in disable-region

Message ID 20231130-fix-region-destroy-v1-2-7f916d2bd379@intel.com (mailing list archive)
State Accepted
Commit 0e78c19a338ff11007fb41b52204a5b6953bebc6
Delegated to: Vishal Verma
Headers show
Series ndctl: Fix ups for region destroy | expand

Commit Message

Ira Weiny Dec. 1, 2023, 4:06 a.m. UTC
When a region is requested to be disabled, memory devices are normally
automatically torn down.  Commit 9399aa667ab0 prevents tear down if
memory is online without a force flag.  However, daxctl_dev_get_memory()
may return NULL if the memory device in question is not system-ram
capable as is the case for a region with only devdax devices.  Such
devices do not need to be off-lined explicitly.

Skip non-system-ram devices rather than error the operation.

Fixes: 9399aa667ab0 ("cxl/region: Add -f option for disable-region")
Cc: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 cxl/region.c             | 3 +++
 daxctl/lib/libdaxctl.c   | 4 ++--
 daxctl/lib/libdaxctl.sym | 5 +++++
 daxctl/libdaxctl.h       | 1 +
 4 files changed, 11 insertions(+), 2 deletions(-)

Comments

Dave Jiang Dec. 1, 2023, 5:39 p.m. UTC | #1
On 11/30/23 21:06, Ira Weiny wrote:
> When a region is requested to be disabled, memory devices are normally
> automatically torn down.  Commit 9399aa667ab0 prevents tear down if
> memory is online without a force flag.  However, daxctl_dev_get_memory()
> may return NULL if the memory device in question is not system-ram
> capable as is the case for a region with only devdax devices.  Such
> devices do not need to be off-lined explicitly.
> 
> Skip non-system-ram devices rather than error the operation.
> 
> Fixes: 9399aa667ab0 ("cxl/region: Add -f option for disable-region")
> Cc: Dave Jiang <dave.jiang@intel.com>
> Signed-off-by: Ira Weiny <ira.weiny@intel.com>

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

> ---
>  cxl/region.c             | 3 +++
>  daxctl/lib/libdaxctl.c   | 4 ++--
>  daxctl/lib/libdaxctl.sym | 5 +++++
>  daxctl/libdaxctl.h       | 1 +
>  4 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/cxl/region.c b/cxl/region.c
> index 5cbbf2749e2d..44ac76b001e9 100644
> --- a/cxl/region.c
> +++ b/cxl/region.c
> @@ -805,6 +805,9 @@ static int disable_region(struct cxl_region *region)
>  		goto out;
>  
>  	daxctl_dev_foreach(dax_region, dev) {
> +		if (!daxctl_dev_is_system_ram_capable(dev))
> +			continue;
> +
>  		mem = daxctl_dev_get_memory(dev);
>  		if (!mem)
>  			return -ENXIO;
> diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c
> index 4f9aba0b09f2..9fbefe2e8329 100644
> --- a/daxctl/lib/libdaxctl.c
> +++ b/daxctl/lib/libdaxctl.c
> @@ -385,7 +385,7 @@ static bool device_model_is_dax_bus(struct daxctl_dev *dev)
>  	return false;
>  }
>  
> -static int dev_is_system_ram_capable(struct daxctl_dev *dev)
> +DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev)
>  {
>  	const char *devname = daxctl_dev_get_devname(dev);
>  	struct daxctl_ctx *ctx = daxctl_dev_get_ctx(dev);
> @@ -432,7 +432,7 @@ static struct daxctl_memory *daxctl_dev_alloc_mem(struct daxctl_dev *dev)
>  	char buf[SYSFS_ATTR_SIZE];
>  	int node_num;
>  
> -	if (!dev_is_system_ram_capable(dev))
> +	if (!daxctl_dev_is_system_ram_capable(dev))
>  		return NULL;
>  
>  	mem = calloc(1, sizeof(*mem));
> diff --git a/daxctl/lib/libdaxctl.sym b/daxctl/lib/libdaxctl.sym
> index fe68fd0a9cde..309881196c86 100644
> --- a/daxctl/lib/libdaxctl.sym
> +++ b/daxctl/lib/libdaxctl.sym
> @@ -99,3 +99,8 @@ global:
>  	daxctl_set_config_path;
>  	daxctl_get_config_path;
>  } LIBDAXCTL_8;
> +
> +LIBDAXCTL_10 {
> +global:
> +	daxctl_dev_is_system_ram_capable;
> +} LIBDAXCTL_9;
> diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h
> index 6876037a9427..53c6bbdae5c3 100644
> --- a/daxctl/libdaxctl.h
> +++ b/daxctl/libdaxctl.h
> @@ -77,6 +77,7 @@ int daxctl_dev_will_auto_online_memory(struct daxctl_dev *dev);
>  int daxctl_dev_has_online_memory(struct daxctl_dev *dev);
>  
>  struct daxctl_memory;
> +int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev);
>  struct daxctl_memory *daxctl_dev_get_memory(struct daxctl_dev *dev);
>  struct daxctl_dev *daxctl_memory_get_dev(struct daxctl_memory *mem);
>  const char *daxctl_memory_get_node_path(struct daxctl_memory *mem);
>
diff mbox series

Patch

diff --git a/cxl/region.c b/cxl/region.c
index 5cbbf2749e2d..44ac76b001e9 100644
--- a/cxl/region.c
+++ b/cxl/region.c
@@ -805,6 +805,9 @@  static int disable_region(struct cxl_region *region)
 		goto out;
 
 	daxctl_dev_foreach(dax_region, dev) {
+		if (!daxctl_dev_is_system_ram_capable(dev))
+			continue;
+
 		mem = daxctl_dev_get_memory(dev);
 		if (!mem)
 			return -ENXIO;
diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c
index 4f9aba0b09f2..9fbefe2e8329 100644
--- a/daxctl/lib/libdaxctl.c
+++ b/daxctl/lib/libdaxctl.c
@@ -385,7 +385,7 @@  static bool device_model_is_dax_bus(struct daxctl_dev *dev)
 	return false;
 }
 
-static int dev_is_system_ram_capable(struct daxctl_dev *dev)
+DAXCTL_EXPORT int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev)
 {
 	const char *devname = daxctl_dev_get_devname(dev);
 	struct daxctl_ctx *ctx = daxctl_dev_get_ctx(dev);
@@ -432,7 +432,7 @@  static struct daxctl_memory *daxctl_dev_alloc_mem(struct daxctl_dev *dev)
 	char buf[SYSFS_ATTR_SIZE];
 	int node_num;
 
-	if (!dev_is_system_ram_capable(dev))
+	if (!daxctl_dev_is_system_ram_capable(dev))
 		return NULL;
 
 	mem = calloc(1, sizeof(*mem));
diff --git a/daxctl/lib/libdaxctl.sym b/daxctl/lib/libdaxctl.sym
index fe68fd0a9cde..309881196c86 100644
--- a/daxctl/lib/libdaxctl.sym
+++ b/daxctl/lib/libdaxctl.sym
@@ -99,3 +99,8 @@  global:
 	daxctl_set_config_path;
 	daxctl_get_config_path;
 } LIBDAXCTL_8;
+
+LIBDAXCTL_10 {
+global:
+	daxctl_dev_is_system_ram_capable;
+} LIBDAXCTL_9;
diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h
index 6876037a9427..53c6bbdae5c3 100644
--- a/daxctl/libdaxctl.h
+++ b/daxctl/libdaxctl.h
@@ -77,6 +77,7 @@  int daxctl_dev_will_auto_online_memory(struct daxctl_dev *dev);
 int daxctl_dev_has_online_memory(struct daxctl_dev *dev);
 
 struct daxctl_memory;
+int daxctl_dev_is_system_ram_capable(struct daxctl_dev *dev);
 struct daxctl_memory *daxctl_dev_get_memory(struct daxctl_dev *dev);
 struct daxctl_dev *daxctl_memory_get_dev(struct daxctl_memory *mem);
 const char *daxctl_memory_get_node_path(struct daxctl_memory *mem);