All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cxl/hdm: Account for a firmware-armed Lock On Commit
@ 2026-10-28 21:18 Davidlohr Bueso
  2026-10-28 21:32 ` sashiko-bot
  2026-10-29  2:11 ` Li Ming
  0 siblings, 2 replies; 3+ messages in thread
From: Davidlohr Bueso @ 2026-10-28 21:18 UTC (permalink / raw)
  To: dave.jiang; +Cc: jic23, alison.schofield, ming.li, icheng, linux-cxl, dave

A corner case (yet valid) where firmware sets the the locked bit
without committing the decoder. setup_hw_decoder() carries the bit
through.

A later region teardown then writes a reset the hardware ignores and
clears CXL_DECODER_F_ENABLE anyway, so the flags claim a decoder is
free that still decodes: cxl_dpa_free() releases its DPA, and a new
region committed on it appears to succeed, cxld_await_commit()
returning as soon as Committed reads 1, while the old mapping stays
in effect.

Read the control register back after the commit so the decoder is
treated like one found locked at probe.

Tested on qemu modified to enforce locked semantics, setting the bit
behind the driver on an uncommitted endpoint decoder, committing and
deleting a 256M region on it, then creating a 512M one. Before, the
decoder sysfs reads locked=0, its DPA is freed and the second region
reports committed while the hardware still decodes the first; after,
locked=1, the DPA release fails with -EBUSY and the second region
cannot allocate DPA.

Fixes: 176baefb2eb5 ("cxl/hdm: Commit decoder state to hardware")
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
---
Found while battle-testing BI locked decoders.

 drivers/cxl/core/hdm.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c
index fdcef20e01ba..d23076aabb89 100644
--- a/drivers/cxl/core/hdm.c
+++ b/drivers/cxl/core/hdm.c
@@ -856,6 +856,7 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)
 	struct cxl_hdm *cxlhdm = dev_get_drvdata(&port->dev);
 	void __iomem *hdm = cxlhdm->regs.hdm_decoder;
 	int id = cxld->id, rc;
+	u32 ctrl;
 
 	if (cxld->flags & CXL_DECODER_F_ENABLE)
 		return 0;
@@ -899,6 +900,14 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)
 	port->commit_end++;
 	cxld->flags |= CXL_DECODER_F_ENABLE;
 
+	/*
+	 * Lock On Commit armed by firmware engages on this commit and
+	 * makes the decoder read-only, like one found locked at probe.
+	 */
+	ctrl = readl(hdm + CXL_HDM_DECODER0_CTRL_OFFSET(id));
+	if (ctrl & CXL_HDM_DECODER0_CTRL_LOCK)
+		cxld->flags |= CXL_DECODER_F_LOCK;
+
 	return 0;
 }
 
-- 
2.39.5


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

end of thread, other threads:[~2026-10-29  2:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-28 21:18 [PATCH] cxl/hdm: Account for a firmware-armed Lock On Commit Davidlohr Bueso
2026-10-28 21:32 ` sashiko-bot
2026-10-29  2:11 ` Li Ming

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.