public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Alison Schofield <alison.schofield@intel.com>,
	Wonjae Lee <wj28.lee@samsung.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Sasha Levin <sashal@kernel.org>,
	dave@stgolabs.net, jonathan.cameron@huawei.com,
	dave.jiang@intel.com, vishal.l.verma@intel.com,
	ira.weiny@intel.com, jim.harris@samsung.com,
	linux-cxl@vger.kernel.org
Subject: [PATCH AUTOSEL 6.7 14/24] cxl/region: Allow out of order assembly of autodiscovered regions
Date: Thu, 29 Feb 2024 15:36:54 -0500	[thread overview]
Message-ID: <20240229203729.2860356-14-sashal@kernel.org> (raw)
In-Reply-To: <20240229203729.2860356-1-sashal@kernel.org>

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

[ Upstream commit cb66b1d60c283bb340a2fc19deff7de8acea74b1 ]

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>
Tested-by: Wonjae Lee <wj28.lee@samsung.com>
Link: https://lore.kernel.org/r/3dec69ee97524ab229a20c6739272c3000b18408.1706736863.git.alison.schofield@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 764998fe03edc..8f0a2507ddecf 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -757,8 +757,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;
@@ -768,16 +791,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);
@@ -954,7 +982,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.43.0


  parent reply	other threads:[~2024-02-29 20:37 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 20:36 [PATCH AUTOSEL 6.7 01/24] soc: microchip: Fix POLARFIRE_SOC_SYS_CTRL input prompt Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 02/24] arm64: dts: rockchip: mark system power controller on rk3588-evb1 Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 03/24] RDMA/mlx5: Fix fortify source warning while accessing Eth segment Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 04/24] RDMA/mlx5: Relax DEVX access upon modify commands Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 05/24] ARM: dts: rockchip: Drop interrupts property from pwm-rockchip nodes Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 06/24] bpf: Fix warning for bpf_cpumask in verifier Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 07/24] riscv: dts: sifive: add missing #interrupt-cells to pmic Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 08/24] x86/mm: Move is_vsyscall_vaddr() into asm/vsyscall.h Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 09/24] x86/mm: Disallow vsyscall page read for copy_from_kernel_nofault() Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 10/24] net/iucv: fix the allocation size of iucv_path_table array Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 11/24] parisc/ftrace: add missing CONFIG_DYNAMIC_FTRACE check Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 12/24] block: sed-opal: handle empty atoms when parsing response Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 13/24] cxl/region: Handle endpoint decoders in cxl_region_find_decoder() Sasha Levin
2024-02-29 20:36 ` Sasha Levin [this message]
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 15/24] enic: Avoid false positive under FORTIFY_SOURCE Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 16/24] perf: CXL: fix CPMU filter value mask length Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 17/24] platform/x86: x86-android-tablets: Fix acer_b1_750_goodix_gpios name Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 18/24] dm-verity, dm-crypt: align "struct bvec_iter" correctly Sasha Levin
2024-02-29 20:36 ` [PATCH AUTOSEL 6.7 19/24] arm: dts: Fix dtc interrupt_provider warnings Sasha Levin
2024-02-29 20:37 ` [PATCH AUTOSEL 6.7 20/24] arm64: " Sasha Levin
2024-02-29 20:37 ` [PATCH AUTOSEL 6.7 21/24] arm: dts: Fix dtc interrupt_map warnings Sasha Levin
2024-02-29 20:37 ` [PATCH AUTOSEL 6.7 22/24] arm64: dts: qcom: Fix interrupt-map cell sizes Sasha Levin
2024-02-29 20:37 ` [PATCH AUTOSEL 6.7 23/24] ARM: dts: renesas: rcar-gen2: Add missing #interrupt-cells to DA9063 nodes Sasha Levin
2024-02-29 20:37 ` [PATCH AUTOSEL 6.7 24/24] drm/amd/display: fix input states translation error for dcn35 & dcn351 Sasha Levin

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=20240229203729.2860356-14-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=ira.weiny@intel.com \
    --cc=jim.harris@samsung.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=vishal.l.verma@intel.com \
    --cc=wj28.lee@samsung.com \
    /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