Linux CXL
 help / color / mirror / Atom feed
* [PATCH 1/2] cxl/region: Timeout auto region assembly waiting for endpoints
@ 2026-01-30  4:23 Alison Schofield
  2026-01-30  4:23 ` [PATCH 2/2] cxl/region: Unregister auto-created region when assembly fails Alison Schofield
  2026-01-30  4:58 ` [PATCH 1/2] cxl/region: Timeout auto region assembly waiting for endpoints dan.j.williams
  0 siblings, 2 replies; 15+ messages in thread
From: Alison Schofield @ 2026-01-30  4:23 UTC (permalink / raw)
  To: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
	Vishal Verma, Ira Weiny, Dan Williams
  Cc: linux-cxl

Currently, if not all expected endpoints arrive for an auto-created
region, the region remains registered but disabled indefinitely. The
region continues to reserve its memory resource, preventing DAX from
registering the memory, and provides no indication that endpoints
failed to arrive (useful for non-DAX configurations).

Start a 30 second timeout when the first endpoint attaches. If the
remaining endpoints have not attached before the timeout expires,
abort region assembly and unregister the region.

Cancel the timeout when all expected endpoints attach or the region is
unregistered for any reason.

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
 drivers/cxl/core/region.c | 51 ++++++++++++++++++++++++++++++++++++++-
 drivers/cxl/cxl.h         |  2 ++
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index ae899f68551f..183cb0b49d8b 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -1968,6 +1968,35 @@ static int cxl_region_sort_targets(struct cxl_region *cxlr)
 	return rc;
 }
 
+static void unregister_region(void *dev);
+
+#define CXL_REGION_EP_WAIT_MS (30 * 1000) /* 30 seconds */
+
+static void cxl_region_endpoint_wait_work(struct work_struct *work)
+{
+	struct delayed_work *dwork = to_delayed_work(work);
+	struct cxl_region *cxlr =
+		container_of(dwork, struct cxl_region, endpoint_wait_work);
+	struct cxl_region_params *p = &cxlr->params;
+	bool timeout_expired;
+
+	scoped_guard(rwsem_read, &cxl_rwsem.region)
+	{
+		timeout_expired = (p->nr_targets < p->interleave_ways);
+	}
+
+	if (timeout_expired) {
+		struct cxl_root_decoder *cxlrd =
+			to_cxl_root_decoder(cxlr->dev.parent);
+		struct cxl_port *port = cxlrd_to_port(cxlrd);
+
+		dev_err(&cxlr->dev,
+			"timeout waiting for endpoints: %d of %d arrived, unregistering region\n",
+			p->nr_targets, p->interleave_ways);
+		devm_release_action(port->uport_dev, unregister_region, cxlr);
+	}
+}
+
 static int cxl_region_attach(struct cxl_region *cxlr,
 			     struct cxl_endpoint_decoder *cxled, int pos)
 {
@@ -2059,8 +2088,23 @@ static int cxl_region_attach(struct cxl_region *cxlr,
 			return rc;
 
 		/* await more targets to arrive... */
-		if (p->nr_targets < p->interleave_ways)
+		if (p->nr_targets < p->interleave_ways) {
+			if (cxlr->endpoint_wait_armed)
+				return 0;
+
+			INIT_DELAYED_WORK(&cxlr->endpoint_wait_work,
+					  cxl_region_endpoint_wait_work);
+			schedule_delayed_work(
+				&cxlr->endpoint_wait_work,
+				msecs_to_jiffies(CXL_REGION_EP_WAIT_MS));
+			cxlr->endpoint_wait_armed = true;
+			dev_dbg(&cxlr->dev,
+				"waiting %d ms for %d more endpoints\n",
+				CXL_REGION_EP_WAIT_MS,
+				p->interleave_ways - p->nr_targets);
+
 			return 0;
+		}
 
 		/*
 		 * All targets are here, which implies all PCI enumeration that
@@ -2444,6 +2488,11 @@ static void unregister_region(void *_cxlr)
 	struct cxl_region_params *p = &cxlr->params;
 	int i;
 
+	if (cxlr->endpoint_wait_armed) {
+		cancel_delayed_work_sync(&cxlr->endpoint_wait_work);
+		cxlr->endpoint_wait_armed = false;
+	}
+
 	device_del(&cxlr->dev);
 
 	/*
diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
index ba17fa86d249..f6441a18b3bb 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -551,6 +551,8 @@ struct cxl_region {
 	struct access_coordinate coord[ACCESS_COORDINATE_MAX];
 	struct notifier_block node_notifier;
 	struct notifier_block adist_notifier;
+	struct delayed_work endpoint_wait_work;
+	bool endpoint_wait_armed;
 };
 
 struct cxl_nvdimm_bridge {

base-commit: 0f61b1860cc3f52aef9036d7235ed1f017632193
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-02-05  4:22 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-30  4:23 [PATCH 1/2] cxl/region: Timeout auto region assembly waiting for endpoints Alison Schofield
2026-01-30  4:23 ` [PATCH 2/2] cxl/region: Unregister auto-created region when assembly fails Alison Schofield
2026-01-30 17:45   ` dan.j.williams
2026-01-31  1:04     ` Alison Schofield
2026-01-31 15:49       ` Gregory Price
2026-02-05  0:32         ` Alison Schofield
2026-02-05  4:22           ` Gregory Price
2026-02-03  3:07       ` dan.j.williams
2026-02-05  0:20         ` Alison Schofield
2026-02-05  1:03           ` dan.j.williams
2026-01-30  4:58 ` [PATCH 1/2] cxl/region: Timeout auto region assembly waiting for endpoints dan.j.williams
2026-01-30 17:42   ` Gregory Price
2026-01-30 18:26     ` dan.j.williams
2026-01-30 19:03       ` Gregory Price
2026-01-30 22:46         ` dan.j.williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox