From: Dave Jiang <dave.jiang@intel.com>
To: vishal.l.verma@intel.com
Cc: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev
Subject: [NDCTL PATCH v2] cxl/region: Add -f option for disable-region
Date: Wed, 20 Sep 2023 15:57:29 -0700 [thread overview]
Message-ID: <169525064907.3085225.2583864429793298106.stgit@djiang5-mobl3> (raw)
The current operation for disable_region does not check if the memory
covered by a region is online before attempting to disable the cxl region.
Provide a -f option for the region to force offlining of currently online
memory before disabling the region. Also add a check to fail the operation
entirely if the memory is non-movable.
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
v2:
- Update documentation and help output. (Vishal)
---
Documentation/cxl/cxl-disable-region.txt | 7 ++++
cxl/region.c | 49 +++++++++++++++++++++++++++++-
2 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/Documentation/cxl/cxl-disable-region.txt b/Documentation/cxl/cxl-disable-region.txt
index 6a39aee6ea69..9b98d4d8745a 100644
--- a/Documentation/cxl/cxl-disable-region.txt
+++ b/Documentation/cxl/cxl-disable-region.txt
@@ -25,6 +25,13 @@ OPTIONS
-------
include::bus-option.txt[]
+-f::
+--force::
+ Attempt to offline any memory that has been hot-added into the system
+ via the CXL region before disabling the region. This won't be attempted
+ if the memory was not added as 'movable', and may still fail even if it
+ was movable.
+
include::decoder-option.txt[]
include::debug-option.txt[]
diff --git a/cxl/region.c b/cxl/region.c
index bcd703956207..f8303869727a 100644
--- a/cxl/region.c
+++ b/cxl/region.c
@@ -14,6 +14,7 @@
#include <util/parse-options.h>
#include <ccan/minmax/minmax.h>
#include <ccan/short_types/short_types.h>
+#include <daxctl/libdaxctl.h>
#include "filter.h"
#include "json.h"
@@ -95,6 +96,8 @@ static const struct option enable_options[] = {
static const struct option disable_options[] = {
BASE_OPTIONS(),
+ OPT_BOOLEAN('f', "force", ¶m.force,
+ "attempt to offline memory before disabling the region"),
OPT_END(),
};
@@ -789,13 +792,57 @@ static int destroy_region(struct cxl_region *region)
return cxl_region_delete(region);
}
+static int disable_region(struct cxl_region *region)
+{
+ const char *devname = cxl_region_get_devname(region);
+ struct daxctl_region *dax_region;
+ struct daxctl_memory *mem;
+ struct daxctl_dev *dev;
+ int rc;
+
+ dax_region = cxl_region_get_daxctl_region(region);
+ if (!dax_region)
+ goto out;
+
+ daxctl_dev_foreach(dax_region, dev) {
+ mem = daxctl_dev_get_memory(dev);
+ if (!mem)
+ return -ENXIO;
+
+ if (daxctl_memory_online_no_movable(mem)) {
+ log_err(&rl, "%s: memory unmovable for %s\n",
+ devname,
+ daxctl_dev_get_devname(dev));
+ return -EPERM;
+ }
+
+ /*
+ * If memory is still online and user wants to force it, attempt
+ * to offline it.
+ */
+ if (daxctl_memory_is_online(mem) && param.force) {
+ rc = daxctl_memory_offline(mem);
+ if (rc) {
+ log_err(&rl, "%s: unable to offline %s: %s\n",
+ devname,
+ daxctl_dev_get_devname(dev),
+ strerror(abs(rc)));
+ return rc;
+ }
+ }
+ }
+
+out:
+ return cxl_region_disable(region);
+}
+
static int do_region_xable(struct cxl_region *region, enum region_actions action)
{
switch (action) {
case ACTION_ENABLE:
return cxl_region_enable(region);
case ACTION_DISABLE:
- return cxl_region_disable(region);
+ return disable_region(region);
case ACTION_DESTROY:
return destroy_region(region);
default:
next reply other threads:[~2023-09-20 22:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-20 22:57 Dave Jiang [this message]
2023-09-21 2:58 ` [NDCTL PATCH v2] cxl/region: Add -f option for disable-region Zhijian Li (Fujitsu)
2023-09-21 23:19 ` Dave Jiang
2023-09-22 1:26 ` Zhijian Li (Fujitsu)
2023-10-09 10:52 ` Xiao Yang
2023-10-13 22:38 ` Dave Jiang
2023-10-30 4:33 ` Xiao Yang
2023-10-30 16:24 ` Dave Jiang
2023-10-30 18:31 ` Dan Williams
2023-10-30 21:30 ` Dave Jiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=169525064907.3085225.2583864429793298106.stgit@djiang5-mobl3 \
--to=dave.jiang@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
--cc=vishal.l.verma@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).