From: Alison Schofield <alison.schofield@intel.com>
To: Pawel Mielimonka <pawel.mielimonka@fujitsu.com>
Cc: <dan.j.williams@intel.com>,
<Smita.KoralahalliChannabasappa@amd.com>,
<linux-cxl@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<dave@stgolabs.net>, <jonathan.cameron@huawei.com>,
<dave.jiang@intel.com>, <vishal.l.verma@intel.com>,
<ira.weiny@intel.com>
Subject: Re: [RFC PATCH v1 2/2] cxl/cli: enforce HPA-descending teardown order for destroy-region
Date: Sat, 6 Dec 2025 16:28:52 -0800 [thread overview]
Message-ID: <aTTKRCUmbNC9jIrG@aschofie-mobl2.lan> (raw)
In-Reply-To: <20251125143826.282312-3-pawel.mielimonka@fujitsu.com>
On Tue, Nov 25, 2025 at 11:38:24PM +0900, Pawel Mielimonka wrote:
> Implement destroy_multiple_regions() and bypass the generic
> do_region_xable() path for ACTION_DESTROY. Regions are collected and
> sorted by HPA, then destroyed from highest to lowest, stopping at the
> first "matching after skipped" to provide user with better error log.
> This prevents attempts on non-last regions and aligns destroy-region
> with required decoder programming order.
Hi Pawel,
It looks like teardown needs another sorting layer that accounts for
endpoint decoders.
While updating the unit test, I used a configuration where a memdev is
targeted by regions under multiple root decoders. In that scenario,
the 'all' or 'all -b bus' teardowns fail because we try to teardown
endpoint decoders out of order.
Appending some debug output from the failing case. Regions 5,10,11,12
use endpoint decoder14.4,3,2,1 and need to be torn down before region3
which uses endpoint14.0.
Also note that with this config, a cxl destroy-region region3 should
fail gracefully with an out of order message.
+ /root/ndctl/build/cxl/cxl destroy-region -f all
cxl region: destroy_multiple_regions: DEBUG: Decoder decoder0.0 - 1 regions collected
cxl region: destroy_multiple_regions: DEBUG: Region[0] = region3
[348.871669] cxl_core:cxl_dpa_free:567: cxl decoder14.0: expected decoder14.4
cxl region: destroy_region: decoder14.0: set_dpa_size failed: Device or resource busy
cxl region: destroy_multiple_regions: region3: failed: Device or resource busy
cxl region: destroy_multiple_regions: DEBUG: Decoder decoder0.1 - 0 regions collected
cxl region: destroy_multiple_regions: DEBUG: Decoder decoder0.2 - 4 regions collected
cxl region: destroy_multiple_regions: DEBUG: Region[0] = region5
cxl region: destroy_multiple_regions: DEBUG: Region[1] = region10
cxl region: destroy_multiple_regions: DEBUG: Region[2] = region11
cxl region: destroy_multiple_regions: DEBUG: Region[3] = region12
cxl region: destroy_multiple_regions: DEBUG: Decoder decoder0.3 - 0 regions collected
cxl region: destroy_multiple_regions: DEBUG: Decoder decoder0.4 - 0 regions collected
cxl region: destroy_multiple_regions: DEBUG: Decoder decoder0.5 - 0 regions collected
cxl region: region_action: one or more failures, last failure: Device or resource busy
cxl region: cmd_destroy_region: destroyed 4 regions
-- Alison
>
> Signed-off-by: Pawel Mielimonka <pawel.mielimonka@fujitsu.com>
> ---
> cxl/region.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 57 insertions(+), 3 deletions(-)
>
> diff --git a/cxl/region.c b/cxl/region.c
> index 58765b3d..1bf1901a 100644
> --- a/cxl/region.c
> +++ b/cxl/region.c
> @@ -950,6 +950,57 @@ static int destroy_region(struct cxl_region *region)
> return cxl_region_delete(region);
> }
>
> +static int destroy_multiple_regions(struct parsed_params *p,
> + struct cxl_decoder *decoder,
> + int *count)
> +{
> + struct cxl_region **list;
> + int nr, rc, i;
> + bool skipped = false;
> +
> + rc = collect_regions_sorted(decoder, NULL, &list, &nr);
> + if (rc) {
> + log_err(&rl, "failed to allocate region list: %s\n", strerror(-rc));
> + return rc;
> + }
> +
> + for (i = nr - 1; i >= 0; --i) {
> + struct cxl_region *region = NULL;
> +
> + for (int j = 0; j < p->argc; j++) {
> + region = util_cxl_region_filter(list[i], p->argv[j]);
> + if (region)
> + break;
> + }
> +
> + if (!region) {
> + skipped = true;
> + continue;
> + }
> +
> + /* if current region matches filter, but previous didn't, destroying would
> + * result in breaking HPA continuity
> + */
> + if (skipped) {
> + log_err(&rl, "failed to destroy %s: not a valid HPA suffix under %s\n",
> + cxl_region_get_devname(region),
> + cxl_decoder_get_devname(decoder));
> + rc = -EINVAL;
> + break;
> + }
> +
> + rc = destroy_region(region);
> + if (rc) {
> + log_err(&rl, "%s: failed: %s\n",
> + cxl_region_get_devname(region), strerror(-rc));
> + break;
> + }
> + ++(*count);
> + }
> + free(list);
> + return rc;
> +}
> +
> static int do_region_xable(struct cxl_region *region, enum region_actions action)
> {
> switch (action) {
> @@ -957,8 +1008,6 @@ static int do_region_xable(struct cxl_region *region, enum region_actions action
> return cxl_region_enable(region);
> case ACTION_DISABLE:
> return disable_region(region);
> - case ACTION_DESTROY:
> - return destroy_region(region);
> default:
> return -EINVAL;
> }
> @@ -1026,7 +1075,12 @@ static int region_action(int argc, const char **argv, struct cxl_ctx *ctx,
> if (!util_cxl_decoder_filter(decoder,
> param.root_decoder))
> continue;
> - rc = decoder_region_action(p, decoder, action, count);
> +
> + if (action == ACTION_DESTROY)
> + rc = destroy_multiple_regions(p, decoder, count);
> + else
> + rc = decoder_region_action(p, decoder, action, count);
> +
> if (rc)
> err_rc = rc;
> }
> --
> 2.45.1.windows.1
>
next prev parent reply other threads:[~2025-12-07 0:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-25 14:38 [RFC PATCH v1 0/2] cxl/cli: HPA-ordered destroy-region teardown Pawel Mielimonka
2025-11-25 14:38 ` [RFC PATCH v1 1/2] cxl/cli: add helpers to collect and sort regions by HPA Pawel Mielimonka
2025-12-03 3:52 ` Alison Schofield
2025-12-03 9:09 ` Paweł Mielimonka
2025-11-25 14:38 ` [RFC PATCH v1 2/2] cxl/cli: enforce HPA-descending teardown order for destroy-region Pawel Mielimonka
2025-12-03 4:15 ` Alison Schofield
2025-12-03 10:13 ` Paweł Mielimonka
2025-12-03 23:46 ` Alison Schofield
2025-12-07 0:28 ` Alison Schofield [this message]
2025-12-03 3:38 ` [RFC PATCH v1 0/2] cxl/cli: HPA-ordered destroy-region teardown Alison Schofield
2026-01-20 14:32 ` [PATCH v2 0/1] " Pawel Mielimonka
2026-01-20 14:32 ` [PATCH v2 1/1] cxl/cli: enforce HPA-descening teardown order for destroy-region Pawel Mielimonka
2026-01-21 18:45 ` [PATCH v2 0/1] cxl/cli: HPA-ordered destroy-region teardown Alison Schofield
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=aTTKRCUmbNC9jIrG@aschofie-mobl2.lan \
--to=alison.schofield@intel.com \
--cc=Smita.KoralahalliChannabasappa@amd.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=ira.weiny@intel.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pawel.mielimonka@fujitsu.com \
--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