Skip to content

Commit cb66b1d

Browse files
AlisonSchofielddjbw
authored andcommitted
cxl/region: Allow out of order assembly of autodiscovered regions
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 <[email protected]> Tested-by: Wonjae Lee <[email protected]> Link: https://lore.kernel.org/r/3dec69ee97524ab229a20c6739272c3000b18408.1706736863.git.alison.schofield@intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent 453a7fd commit cb66b1d

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

drivers/cxl/core/region.c

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,31 @@ cxl_region_find_decoder(struct cxl_port *port,
758758
return to_cxl_decoder(dev);
759759
}
760760

761-
static struct cxl_region_ref *alloc_region_ref(struct cxl_port *port,
762-
struct cxl_region *cxlr)
761+
static bool auto_order_ok(struct cxl_port *port, struct cxl_region *cxlr_iter,
762+
struct cxl_decoder *cxld)
763+
{
764+
struct cxl_region_ref *rr = cxl_rr_load(port, cxlr_iter);
765+
struct cxl_decoder *cxld_iter = rr->decoder;
766+
767+
/*
768+
* Allow the out of order assembly of auto-discovered regions.
769+
* Per CXL Spec 3.1 8.2.4.20.12 software must commit decoders
770+
* in HPA order. Confirm that the decoder with the lesser HPA
771+
* starting address has the lesser id.
772+
*/
773+
dev_dbg(&cxld->dev, "check for HPA violation %s:%d < %s:%d\n",
774+
dev_name(&cxld->dev), cxld->id,
775+
dev_name(&cxld_iter->dev), cxld_iter->id);
776+
777+
if (cxld_iter->id > cxld->id)
778+
return true;
779+
780+
return false;
781+
}
782+
783+
static struct cxl_region_ref *
784+
alloc_region_ref(struct cxl_port *port, struct cxl_region *cxlr,
785+
struct cxl_endpoint_decoder *cxled)
763786
{
764787
struct cxl_region_params *p = &cxlr->params;
765788
struct cxl_region_ref *cxl_rr, *iter;
@@ -769,16 +792,21 @@ static struct cxl_region_ref *alloc_region_ref(struct cxl_port *port,
769792
xa_for_each(&port->regions, index, iter) {
770793
struct cxl_region_params *ip = &iter->region->params;
771794

772-
if (!ip->res)
795+
if (!ip->res || ip->res->start < p->res->start)
773796
continue;
774797

775-
if (ip->res->start > p->res->start) {
776-
dev_dbg(&cxlr->dev,
777-
"%s: HPA order violation %s:%pr vs %pr\n",
778-
dev_name(&port->dev),
779-
dev_name(&iter->region->dev), ip->res, p->res);
780-
return ERR_PTR(-EBUSY);
798+
if (test_bit(CXL_REGION_F_AUTO, &cxlr->flags)) {
799+
struct cxl_decoder *cxld;
800+
801+
cxld = cxl_region_find_decoder(port, cxled, cxlr);
802+
if (auto_order_ok(port, iter->region, cxld))
803+
continue;
781804
}
805+
dev_dbg(&cxlr->dev, "%s: HPA order violation %s:%pr vs %pr\n",
806+
dev_name(&port->dev),
807+
dev_name(&iter->region->dev), ip->res, p->res);
808+
809+
return ERR_PTR(-EBUSY);
782810
}
783811

784812
cxl_rr = kzalloc(sizeof(*cxl_rr), GFP_KERNEL);
@@ -955,7 +983,7 @@ static int cxl_port_attach_region(struct cxl_port *port,
955983
nr_targets_inc = true;
956984
}
957985
} else {
958-
cxl_rr = alloc_region_ref(port, cxlr);
986+
cxl_rr = alloc_region_ref(port, cxlr, cxled);
959987
if (IS_ERR(cxl_rr)) {
960988
dev_dbg(&cxlr->dev,
961989
"%s: failed to allocate region reference\n",

0 commit comments

Comments
 (0)