* [PATCH] cxl/region: Remove the AUTO_STAGED endpoint decoder state
@ 2026-12-01 20:14 Alison Schofield
2026-12-01 20:52 ` Dave Jiang
0 siblings, 1 reply; 2+ messages in thread
From: Alison Schofield @ 2026-12-01 20:14 UTC (permalink / raw)
To: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Li Ming, Richard Cheng, Ben Cheatham
Cc: linux-cxl
Dan added a new decoder state, AUTO_STAGED, to trigger cleanup when
an endpoint decoder was unregistered while waiting for its peers.
The cleanup used cxled->pos to find the target entry.
Since commit cbda6a2c2bec ("cxl/region: Fix out-of-bounds access in
cxl_cancel_auto_attach()"), the cleanup scans for the decoder pointer
and no longer depends on cxled->pos.
Dave Jiang [1] reported a use-after-free during region teardown
because AUTO_STAGED is lost when an upstream attach fails and unwinds.
That prompted another look at the state. The scan already determines
whether there is a target entry to remove, so AUTO_STAGED is redundant.
Drop the state and run the lookup when an AUTO decoder is unregistered
with no cxld->region. This covers both decoders waiting for peers
(Dan's case) and decoders left in the array after unwind (Dave's case).
[1] https://patch.msgid.link/20261120181228.1466310-1-dave.jiang@intel.com
Fixes: 87805c32e6ad ("cxl/region: Fix use-after-free from auto assembly failure")
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
drivers/cxl/core/region.c | 12 +-----------
drivers/cxl/cxl.h | 6 ++----
2 files changed, 3 insertions(+), 15 deletions(-)
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index f8c88113de35..b30d9705fb00 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -1105,14 +1105,6 @@ static int cxl_rr_ep_add(struct cxl_region_ref *cxl_rr,
if (!cxld->region) {
cxld->region = cxlr;
-
- /*
- * Now that cxld->region is set the intermediate staging state
- * can be cleared.
- */
- if (cxld == &cxled->cxld &&
- cxled->state == CXL_DECODER_STATE_AUTO_STAGED)
- cxled->state = CXL_DECODER_STATE_AUTO;
get_device(&cxlr->dev);
}
@@ -1876,7 +1868,6 @@ static int cxl_region_attach_auto(struct cxl_region *cxlr,
p->targets[pos] = cxled;
cxled->pos = pos;
- cxled->state = CXL_DECODER_STATE_AUTO_STAGED;
p->nr_targets++;
return 0;
@@ -2247,7 +2238,6 @@ static int cxl_region_remove_target(struct device *dev, void *data)
for (i = 0; i < p->interleave_ways; i++) {
if (p->targets[i] == cxled) {
p->nr_targets--;
- cxled->state = CXL_DECODER_STATE_AUTO;
cxled->pos = -1;
p->targets[i] = NULL;
@@ -2264,7 +2254,7 @@ static int cxl_region_remove_target(struct device *dev, void *data)
*/
static void cxl_cancel_auto_attach(struct cxl_endpoint_decoder *cxled)
{
- if (cxled->state != CXL_DECODER_STATE_AUTO_STAGED)
+ if (cxled->state != CXL_DECODER_STATE_AUTO)
return;
bus_for_each_dev(&cxl_bus_type, NULL, cxled, cxl_region_remove_target);
diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
index baa6df2d362a..ceabc9dfba47 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -314,14 +314,12 @@ struct cxl_decoder {
};
/*
- * Track whether this decoder is free for userspace provisioning, reserved for
- * region autodiscovery, whether it is started connecting (awaiting other
- * peers), or has completed auto assembly.
+ * Track whether this decoder is reserved for region autodiscovery, or
+ * free for userspace provisioning.
*/
enum cxl_decoder_state {
CXL_DECODER_STATE_MANUAL,
CXL_DECODER_STATE_AUTO,
- CXL_DECODER_STATE_AUTO_STAGED,
};
/**
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
--
2.37.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] cxl/region: Remove the AUTO_STAGED endpoint decoder state
2026-12-01 20:14 [PATCH] cxl/region: Remove the AUTO_STAGED endpoint decoder state Alison Schofield
@ 2026-12-01 20:52 ` Dave Jiang
0 siblings, 0 replies; 2+ messages in thread
From: Dave Jiang @ 2026-12-01 20:52 UTC (permalink / raw)
To: Alison Schofield, Davidlohr Bueso, Jonathan Cameron, Vishal Verma,
Ira Weiny, Li Ming, Richard Cheng, Ben Cheatham
Cc: linux-cxl
On 12/1/26 1:14 PM, Alison Schofield wrote:
> Dan added a new decoder state, AUTO_STAGED, to trigger cleanup when
> an endpoint decoder was unregistered while waiting for its peers.
> The cleanup used cxled->pos to find the target entry.
>
> Since commit cbda6a2c2bec ("cxl/region: Fix out-of-bounds access in
> cxl_cancel_auto_attach()"), the cleanup scans for the decoder pointer
> and no longer depends on cxled->pos.
>
> Dave Jiang [1] reported a use-after-free during region teardown
> because AUTO_STAGED is lost when an upstream attach fails and unwinds.
> That prompted another look at the state. The scan already determines
> whether there is a target entry to remove, so AUTO_STAGED is redundant.
>
> Drop the state and run the lookup when an AUTO decoder is unregistered
> with no cxld->region. This covers both decoders waiting for peers
> (Dan's case) and decoders left in the array after unwind (Dave's case).
>
> [1] https://patch.msgid.link/20261120181228.1466310-1-dave.jiang@intel.com
>
> Fixes: 87805c32e6ad ("cxl/region: Fix use-after-free from auto assembly failure")
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> drivers/cxl/core/region.c | 12 +-----------
> drivers/cxl/cxl.h | 6 ++----
> 2 files changed, 3 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index f8c88113de35..b30d9705fb00 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -1105,14 +1105,6 @@ static int cxl_rr_ep_add(struct cxl_region_ref *cxl_rr,
>
> if (!cxld->region) {
> cxld->region = cxlr;
> -
> - /*
> - * Now that cxld->region is set the intermediate staging state
> - * can be cleared.
> - */
> - if (cxld == &cxled->cxld &&
> - cxled->state == CXL_DECODER_STATE_AUTO_STAGED)
> - cxled->state = CXL_DECODER_STATE_AUTO;
> get_device(&cxlr->dev);
> }
>
> @@ -1876,7 +1868,6 @@ static int cxl_region_attach_auto(struct cxl_region *cxlr,
>
> p->targets[pos] = cxled;
> cxled->pos = pos;
> - cxled->state = CXL_DECODER_STATE_AUTO_STAGED;
> p->nr_targets++;
>
> return 0;
> @@ -2247,7 +2238,6 @@ static int cxl_region_remove_target(struct device *dev, void *data)
> for (i = 0; i < p->interleave_ways; i++) {
> if (p->targets[i] == cxled) {
> p->nr_targets--;
> - cxled->state = CXL_DECODER_STATE_AUTO;
> cxled->pos = -1;
> p->targets[i] = NULL;
>
> @@ -2264,7 +2254,7 @@ static int cxl_region_remove_target(struct device *dev, void *data)
> */
> static void cxl_cancel_auto_attach(struct cxl_endpoint_decoder *cxled)
> {
> - if (cxled->state != CXL_DECODER_STATE_AUTO_STAGED)
> + if (cxled->state != CXL_DECODER_STATE_AUTO)
> return;
>
> bus_for_each_dev(&cxl_bus_type, NULL, cxled, cxl_region_remove_target);
> diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
> index baa6df2d362a..ceabc9dfba47 100644
> --- a/drivers/cxl/cxl.h
> +++ b/drivers/cxl/cxl.h
> @@ -314,14 +314,12 @@ struct cxl_decoder {
> };
>
> /*
> - * Track whether this decoder is free for userspace provisioning, reserved for
> - * region autodiscovery, whether it is started connecting (awaiting other
> - * peers), or has completed auto assembly.
> + * Track whether this decoder is reserved for region autodiscovery, or
> + * free for userspace provisioning.
> */
> enum cxl_decoder_state {
> CXL_DECODER_STATE_MANUAL,
> CXL_DECODER_STATE_AUTO,
> - CXL_DECODER_STATE_AUTO_STAGED,
> };
>
> /**
>
> base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 20:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 20:14 [PATCH] cxl/region: Remove the AUTO_STAGED endpoint decoder state Alison Schofield
2026-12-01 20:52 ` Dave Jiang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.