Linux CXL
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dave Jiang" <dave.jiang@intel.com>, linux-cxl@vger.kernel.org
Subject: Re: [PATCH] cxl/region: Keep a decoder staged when its auto attach fails
Date: Fri, 20 Nov 2026 18:39:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-225857@kernel.org> (raw)
In-Reply-To: <20261120181228.1466310-1-dave.jiang@intel.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] cxl/region: duplicate target attach corrupts region refs in
  cxl_region_attach() [1]
--

commit bb73ffca81dd406b180098a77a7d18645c37f8a1
Author: Dave Jiang <dave.jiang@intel.com>

cxl/region: Keep a decoder staged when its auto attach fails

This commit restores an endpoint decoder's state to
CXL_DECODER_STATE_AUTO_STAGED if cxl_region_attach_position() fails and
unwinds its region attachment.

> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index a048bd5c06cb6..f1083976592f9 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -1830,6 +1830,14 @@ static int cxl_region_attach_position(struct cxl_region *cxlr,
>  	for (iter = cxled_to_port(cxled); !is_cxl_root(iter);
>  	     iter = to_cxl_port(iter->dev.parent))
>  		cxl_port_detach_region(iter, cxlr, cxled);
> +
> +	/*
> +	 * Attaching at the endpoint port moved a staged decoder to AUTO, and
> +	 * the unwind above cleared its region again. It is still listed as a
> +	 * target, so keep it staged for cxl_cancel_auto_attach() to find.
> +	 */
> +	if (cxled->state == CXL_DECODER_STATE_AUTO && !cxled->cxld.region)
> +		cxled->state = CXL_DECODER_STATE_AUTO_STAGED;
>  	return rc;
>  }

[Severity: High]
This problem wasn't introduced by this patch, but can a duplicate write to
a targetN sysfs attribute cause this unwind loop to detach an already
attached target [1]?

In cxl_region_validate_position(), if p->targets[pos] == cxled, it returns
0:

drivers/cxl/core/region.c:cxl_region_validate_position() {
    ...
	if (p->targets[pos] == cxled)
		return 0;
    ...
}

cxl_region_attach() treats that 0 return as success and calls
cxl_region_attach_position() a second time for the same decoder instead of
returning early.  When configuring a manual region with interleave_ways >= 2,
attaching succeeds again at the endpoint port (incrementing nr_eps to 2)
and then fails at the parent port (for example with -EBUSY in
cxl_rr_ep_add() because cxled is already in cxl_rr->endpoints).

The err unwind in cxl_region_attach_position() then detaches cxled across
all ports up to the root and frees the ancestor ports' cxl_region_ref while
p->targets[pos] remains set.  Once the remaining targets are attached,
cxl_port_setup_targets() gets NULL from cxl_rr_load() on the ancestor port
and dereferences cxl_rr->decoder.

[1] https://sashiko.dev/#/bug/linux-bc3dac83-96b6-4b99-8e2f-b2f4ad93b98b

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120181228.1466310-1-dave.jiang@intel.com?part=1

      reply	other threads:[~2026-11-20 18:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 18:12 [PATCH] cxl/region: Keep a decoder staged when its auto attach fails Dave Jiang
2026-11-20 18:39 ` sashiko-bot [this message]

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=sashiko-outbox-225857@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dave.jiang@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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