Linux CXL
 help / color / mirror / Atom feed
* [PATCH v3 0/2] Allow out of order auto-region assembly
@ 2024-01-31 21:59 alison.schofield
  2024-01-31 21:59 ` [PATCH v3 1/2] cxl/region: Handle endpoint decoders in cxl_region_find_decoder() alison.schofield
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: alison.schofield @ 2024-01-31 21:59 UTC (permalink / raw)
  To: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
	Vishal Verma, Ira Weiny, Dan Williams
  Cc: linux-cxl, Wonjae Lee

From: Alison Schofield <alison.schofield@intel.com>

Add a precursor tidy-up patch to existing Patch 2.


Alison Schofield (2):
  cxl/region: Handle endpoint decoders in cxl_region_find_decoder()
  cxl/region: Allow out of order assembly of autodiscovered regions

 drivers/cxl/core/region.c | 62 +++++++++++++++++++++++++++++----------
 1 file changed, 46 insertions(+), 16 deletions(-)


base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d
-- 
2.37.3


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

* [PATCH v3 1/2] cxl/region: Handle endpoint decoders in cxl_region_find_decoder()
  2024-01-31 21:59 [PATCH v3 0/2] Allow out of order auto-region assembly alison.schofield
@ 2024-01-31 21:59 ` alison.schofield
  2024-01-31 21:59 ` [PATCH v3 2/2] cxl/region: Allow out of order assembly of autodiscovered regions alison.schofield
  2024-01-31 22:24 ` [PATCH v3 0/2] Allow out of order auto-region assembly Dan Williams
  2 siblings, 0 replies; 5+ messages in thread
From: alison.schofield @ 2024-01-31 21:59 UTC (permalink / raw)
  To: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
	Vishal Verma, Ira Weiny, Dan Williams
  Cc: linux-cxl, Wonjae Lee

From: Alison Schofield <alison.schofield@intel.com>

In preparation for adding a new caller of cxl_region_find_decoders()
teach it to find a decoder from a cxl_endpoint_decoder structure.

Combining switch and endpoint decoder lookup in one function prevents
code duplication in call sites.

Update the existing caller.

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
 drivers/cxl/core/region.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 0f05692bfec3..7af40d9cf80a 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -730,12 +730,17 @@ static int match_auto_decoder(struct device *dev, void *data)
 	return 0;
 }
 
-static struct cxl_decoder *cxl_region_find_decoder(struct cxl_port *port,
-						   struct cxl_region *cxlr)
+static struct cxl_decoder *
+cxl_region_find_decoder(struct cxl_port *port,
+			struct cxl_endpoint_decoder *cxled,
+			struct cxl_region *cxlr)
 {
 	struct device *dev;
 	int id = 0;
 
+	if (port == cxled_to_port(cxled))
+		return &cxled->cxld;
+
 	if (test_bit(CXL_REGION_F_AUTO, &cxlr->flags))
 		dev = device_find_child(&port->dev, &cxlr->params,
 					match_auto_decoder);
@@ -853,10 +858,7 @@ static int cxl_rr_alloc_decoder(struct cxl_port *port, struct cxl_region *cxlr,
 {
 	struct cxl_decoder *cxld;
 
-	if (port == cxled_to_port(cxled))
-		cxld = &cxled->cxld;
-	else
-		cxld = cxl_region_find_decoder(port, cxlr);
+	cxld = cxl_region_find_decoder(port, cxled, cxlr);
 	if (!cxld) {
 		dev_dbg(&cxlr->dev, "%s: no decoder available\n",
 			dev_name(&port->dev));
-- 
2.37.3


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

* [PATCH v3 2/2] cxl/region: Allow out of order assembly of autodiscovered regions
  2024-01-31 21:59 [PATCH v3 0/2] Allow out of order auto-region assembly alison.schofield
  2024-01-31 21:59 ` [PATCH v3 1/2] cxl/region: Handle endpoint decoders in cxl_region_find_decoder() alison.schofield
@ 2024-01-31 21:59 ` alison.schofield
  2024-01-31 22:24 ` [PATCH v3 0/2] Allow out of order auto-region assembly Dan Williams
  2 siblings, 0 replies; 5+ messages in thread
From: alison.schofield @ 2024-01-31 21:59 UTC (permalink / raw)
  To: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
	Vishal Verma, Ira Weiny, Dan Williams
  Cc: linux-cxl, Wonjae Lee

From: Alison Schofield <alison.schofield@intel.com>

Autodiscovered regions can fail to assemble if they are not discovered
in HPA decode order. The user will see failure messages like:

[] cxl region0: endpoint5: HPA order violation region1
[] cxl region0: endpoint5: failed to allocate region reference

The check that is causing the failure helps the CXL driver enforce
a CXL spec mandate that decoders be committed in HPA order. The
check is needless for autodiscovered regions since their decoders
are already programmed. Trying to enforce order in the assembly of
these regions is useless because they are assembled once all their
member endpoints arrive, and there is no guarantee on the order in
which endpoints are discovered during probe.

Keep the existing check, but for autodiscovered regions, allow the
out of order assembly after a sanity check that the lesser numbered
decoder has the lesser HPA starting address.

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---

Changes in v3:
- Get correct endpoint or switch decoders (Dan)


 drivers/cxl/core/region.c | 48 +++++++++++++++++++++++++++++++--------
 1 file changed, 38 insertions(+), 10 deletions(-)

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 7af40d9cf80a..0b37e2e674e5 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -758,8 +758,31 @@ cxl_region_find_decoder(struct cxl_port *port,
 	return to_cxl_decoder(dev);
 }
 
-static struct cxl_region_ref *alloc_region_ref(struct cxl_port *port,
-					       struct cxl_region *cxlr)
+static bool auto_order_ok(struct cxl_port *port, struct cxl_region *cxlr_iter,
+			  struct cxl_decoder *cxld)
+{
+	struct cxl_region_ref *rr = cxl_rr_load(port, cxlr_iter);
+	struct cxl_decoder *cxld_iter = rr->decoder;
+
+	/*
+	 * Allow the out of order assembly of auto-discovered regions.
+	 * Per CXL Spec 3.1 8.2.4.20.12 software must commit decoders
+	 * in HPA order. Confirm that the decoder with the lesser HPA
+	 * starting address has the lesser id.
+	 */
+	dev_dbg(&cxld->dev, "check for HPA violation %s:%d < %s:%d\n",
+		dev_name(&cxld->dev), cxld->id,
+		dev_name(&cxld_iter->dev), cxld_iter->id);
+
+	if (cxld_iter->id > cxld->id)
+		return true;
+
+	return false;
+}
+
+static struct cxl_region_ref *
+alloc_region_ref(struct cxl_port *port, struct cxl_region *cxlr,
+		 struct cxl_endpoint_decoder *cxled)
 {
 	struct cxl_region_params *p = &cxlr->params;
 	struct cxl_region_ref *cxl_rr, *iter;
@@ -769,16 +792,21 @@ static struct cxl_region_ref *alloc_region_ref(struct cxl_port *port,
 	xa_for_each(&port->regions, index, iter) {
 		struct cxl_region_params *ip = &iter->region->params;
 
-		if (!ip->res)
+		if (!ip->res || ip->res->start < p->res->start)
 			continue;
 
-		if (ip->res->start > p->res->start) {
-			dev_dbg(&cxlr->dev,
-				"%s: HPA order violation %s:%pr vs %pr\n",
-				dev_name(&port->dev),
-				dev_name(&iter->region->dev), ip->res, p->res);
-			return ERR_PTR(-EBUSY);
+		if (test_bit(CXL_REGION_F_AUTO, &cxlr->flags)) {
+			struct cxl_decoder *cxld;
+
+			cxld = cxl_region_find_decoder(port, cxled, cxlr);
+			if (auto_order_ok(port, iter->region, cxld))
+				continue;
 		}
+		dev_dbg(&cxlr->dev, "%s: HPA order violation %s:%pr vs %pr\n",
+			dev_name(&port->dev),
+			dev_name(&iter->region->dev), ip->res, p->res);
+
+		return ERR_PTR(-EBUSY);
 	}
 
 	cxl_rr = kzalloc(sizeof(*cxl_rr), GFP_KERNEL);
@@ -955,7 +983,7 @@ static int cxl_port_attach_region(struct cxl_port *port,
 			nr_targets_inc = true;
 		}
 	} else {
-		cxl_rr = alloc_region_ref(port, cxlr);
+		cxl_rr = alloc_region_ref(port, cxlr, cxled);
 		if (IS_ERR(cxl_rr)) {
 			dev_dbg(&cxlr->dev,
 				"%s: failed to allocate region reference\n",
-- 
2.37.3


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

* RE: [PATCH v3 0/2] Allow out of order auto-region assembly
  2024-01-31 21:59 [PATCH v3 0/2] Allow out of order auto-region assembly alison.schofield
  2024-01-31 21:59 ` [PATCH v3 1/2] cxl/region: Handle endpoint decoders in cxl_region_find_decoder() alison.schofield
  2024-01-31 21:59 ` [PATCH v3 2/2] cxl/region: Allow out of order assembly of autodiscovered regions alison.schofield
@ 2024-01-31 22:24 ` Dan Williams
  2024-02-01  5:31   ` Wonjae Lee
  2 siblings, 1 reply; 5+ messages in thread
From: Dan Williams @ 2024-01-31 22:24 UTC (permalink / raw)
  To: alison.schofield, Davidlohr Bueso, Jonathan Cameron, Dave Jiang,
	Vishal Verma, Ira Weiny, Dan Williams
  Cc: linux-cxl, Wonjae Lee

alison.schofield@ wrote:
> From: Alison Schofield <alison.schofield@intel.com>
> 
> Add a precursor tidy-up patch to existing Patch 2.
> 
> 
> Alison Schofield (2):
>   cxl/region: Handle endpoint decoders in cxl_region_find_decoder()
>   cxl/region: Allow out of order assembly of autodiscovered regions

These look good to me now. It would be nice to get a Tested-by from
Wonjae to close the loop. I'll give that a day or so to show up.

Thanks, Alison!

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

* RE:(2) [PATCH v3 0/2] Allow out of order auto-region assembly
  2024-01-31 22:24 ` [PATCH v3 0/2] Allow out of order auto-region assembly Dan Williams
@ 2024-02-01  5:31   ` Wonjae Lee
  0 siblings, 0 replies; 5+ messages in thread
From: Wonjae Lee @ 2024-02-01  5:31 UTC (permalink / raw)
  To: Dan Williams, alison.schofield@intel.com, Davidlohr Bueso,
	Jonathan Cameron, Dave Jiang, Vishal Verma, Ira Weiny
  Cc: linux-cxl@vger.kernel.org, KyungSan Kim, Hojin Nam

On Wed, Jan 31, 2024 at 02:24:06PM -0800, Dan Williams wrote:
> alison.schofield@ wrote:
> > From: Alison Schofield <alison.schofield@intel.com>
> >
> > Add a precursor tidy-up patch to existing Patch 2.
> >
> >
> > Alison Schofield (2):
> >   cxl/region: Handle endpoint decoders in cxl_region_find_decoder()
> >   cxl/region: Allow out of order assembly of autodiscovered regions
>
> These look good to me now. It would be nice to get a Tested-by from
> Wonjae to close the loop. I'll give that a day or so to show up.
>
> Thanks, Alison!
>

Hello,

I found that it worked fine with a "check for HPA violation" log when I
applied the patch in the same environment where the problem occurred
previously. Thanks for your help!

Tested-by: Wonjae Lee <wj28.lee@samsung.com>

Thanks,
Wonjae

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

end of thread, other threads:[~2024-02-01  5:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-31 21:59 [PATCH v3 0/2] Allow out of order auto-region assembly alison.schofield
2024-01-31 21:59 ` [PATCH v3 1/2] cxl/region: Handle endpoint decoders in cxl_region_find_decoder() alison.schofield
2024-01-31 21:59 ` [PATCH v3 2/2] cxl/region: Allow out of order assembly of autodiscovered regions alison.schofield
2024-01-31 22:24 ` [PATCH v3 0/2] Allow out of order auto-region assembly Dan Williams
2024-02-01  5:31   ` Wonjae Lee

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