Skip to contentSkip to conversation

cxl: Fix premature commit_end increment on decoder commit failure

PATCH Applied Yuxiong Wang 3 participants 4 messages Jan 29 – Jan 30 CXL

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cxl: Fix premature commit_end increment on decoder commit failure

In cxl_decoder_commit(), commit_end is incremented before verifying whether the commit succeeded, and the CXL_DECODER_F_ENABLE bit in cxld->flags is only set after a successful commit. As a result, if the commit fails, commit_end has been incremented and cxld->reset() has no effect since the flag is not set, so commit_end remains incorrectly incremented. The inconsistency between commit_end and CXL_DECODER_F_ENABLE causes failure during subsequent either commit or reset operations.

Fix this by incrementing commit_end only after confirming the commit succeeded. Also, remove the ineffective cxld->reset() call. According to CXL 3.2 Spec 8.2.4.20.12 Committing Decoder Programming, since cxld_await_commit() has cleared the decoder commit bit on failure, no additional reset is required.

Fixes 176baef ("cxl/hdm: Commit decoder state to hardware")

---
Change log:
* Added CXL 3.2 Spec 8.2.4.20.12 Committing Decoder Programming statement. Thanks Alison.
* Collected reviewed-by. Thanks Dave and Alison.
RFC Link: https://lore.kernel.org/linux-cxl/[email protected]/

---
 drivers/cxl/core/hdm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cxl/core/hdm.c +1 -2
index eb5a3a7640c6..912f648a6b7a 100644
@@ -844,14 +844,13 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)
 	scoped_guard(rwsem_read, &cxl_rwsem.dpa)
 		setup_hw_decoder(cxld, hdm);
 
-	port->commit_end++;
 	rc = cxld_await_commit(hdm, cxld->id);
 	if (rc) {
 		dev_dbg(&port->dev, "%s: error %d committing decoder\n",
 			dev_name(&cxld->dev), rc);
-		cxld->reset(cxld);
 		return rc;
 	}
+	port->commit_end++;
 	cxld->flags |= CXL_DECODER_F_ENABLE;
 
 	return 0;
Signature · 1 line
2.50.1 (Apple Git-155)
maintainer
#1 lore raw
Quoted 10 lines · Yuxiong Wang

In cxl_decoder_commit(), commit_end is incremented before verifying whether the commit succeeded, and the CXL_DECODER_F_ENABLE bit in cxld->flags is only set after a successful commit. As a result, if the commit fails, commit_end has been incremented and cxld->reset() has no effect since the flag is not set, so commit_end remains incorrectly incremented. The inconsistency between commit_end and CXL_DECODER_F_ENABLE causes failure during subsequent either commit or reset operations.

Fix this by incrementing commit_end only after confirming the commit succeeded. Also, remove the ineffective cxld->reset() call. According to CXL 3.2 Spec 8.2.4.20.12

DaveJ - Maybe s/3.2/4.0 above on applying please.

It's the same section either way but lets encourage new references to use the latest version of CXL Spec.

Quoted 41 lines

Committing Decoder Programming, since cxld_await_commit() has cleared the decoder commit bit on failure, no additional reset is required.

Fixes 176baef ("cxl/hdm: Commit decoder state to hardware")

---
Change log:
* Added CXL 3.2 Spec 8.2.4.20.12 Committing Decoder Programming statement. Thanks Alison.
* Collected reviewed-by. Thanks Dave and Alison.
RFC Link: https://lore.kernel.org/linux-cxl/[email protected]/

---
 drivers/cxl/core/hdm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cxl/core/hdm.c +1 -2
index eb5a3a7640c6..912f648a6b7a 100644
@@ -844,14 +844,13 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)
 	scoped_guard(rwsem_read, &cxl_rwsem.dpa)
 		setup_hw_decoder(cxld, hdm);
 
-	port->commit_end++;
 	rc = cxld_await_commit(hdm, cxld->id);
 	if (rc) {
 		dev_dbg(&port->dev, "%s: error %d committing decoder\n",
 			dev_name(&cxld->dev), rc);
-		cxld->reset(cxld);
 		return rc;
 	}
+	port->commit_end++;
 	cxld->flags |= CXL_DECODER_F_ENABLE;
 
 	return 0;
Signature · 1 line
2.50.1 (Apple Git-155)
#2 lore raw
Quoted 9 lines · Alison Schofield
Quoted 8 lines · Yuxiong Wang

In cxl_decoder_commit(), commit_end is incremented before verifying whether the commit succeeded, and the CXL_DECODER_F_ENABLE bit in cxld->flags is only set after a successful commit. As a result, if the commit fails, commit_end has been incremented and cxld->reset() has no effect since the flag is not set, so commit_end remains incorrectly incremented. The inconsistency between commit_end and CXL_DECODER_F_ENABLE causes failure during subsequent either commit or reset operations.

Quoted 7 lines
Quoted 2 lines

Fix this by incrementing commit_end only after confirming the commit succeeded. Also, remove the ineffective cxld->reset() call. According to CXL 3.2 Spec 8.2.4.20.12

DaveJ - Maybe s/3.2/4.0 above on applying please.

It's the same section either way but lets encourage new references to use the latest version of CXL Spec.

Thanks for the advice! I'll refer to the latest version of CXL Spec in future work.

Best Regards,
Yuxiong

Quoted 42 lines
Quoted 42 lines

Committing Decoder Programming, since cxld_await_commit() has cleared the decoder commit bit on failure, no additional reset is required.

Fixes 176baef ("cxl/hdm: Commit decoder state to hardware")

---
Change log:
* Added CXL 3.2 Spec 8.2.4.20.12 Committing Decoder Programming statement. Thanks Alison.
* Collected reviewed-by. Thanks Dave and Alison.
RFC Link: https://lore.kernel.org/linux-cxl/[email protected]/

---
 drivers/cxl/core/hdm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cxl/core/hdm.c +1 -2
index eb5a3a7640c6..912f648a6b7a 100644
@@ -844,14 +844,13 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)
 	scoped_guard(rwsem_read, &cxl_rwsem.dpa)
 		setup_hw_decoder(cxld, hdm);
 
-	port->commit_end++;
 	rc = cxld_await_commit(hdm, cxld->id);
 	if (rc) {
 		dev_dbg(&port->dev, "%s: error %d committing decoder\n",
 			dev_name(&cxld->dev), rc);
-		cxld->reset(cxld);
 		return rc;
 	}
+	port->commit_end++;
 	cxld->flags |= CXL_DECODER_F_ENABLE;
 
 	return 0;
Signature · 1 line
2.50.1 (Apple Git-155)
maintainer Applied
#3 lore raw
In reply to Yuxiong Wang
Quoted 13 lines · Yuxiong Wang

In cxl_decoder_commit(), commit_end is incremented before verifying whether the commit succeeded, and the CXL_DECODER_F_ENABLE bit in cxld->flags is only set after a successful commit. As a result, if the commit fails, commit_end has been incremented and cxld->reset() has no effect since the flag is not set, so commit_end remains incorrectly incremented. The inconsistency between commit_end and CXL_DECODER_F_ENABLE causes failure during subsequent either commit or reset operations.

Fix this by incrementing commit_end only after confirming the commit succeeded. Also, remove the ineffective cxld->reset() call. According to CXL 3.2 Spec 8.2.4.20.12 Committing Decoder Programming, since cxld_await_commit() has cleared the decoder commit bit on failure, no additional reset is required.

Quoted 5 lines
Fixes 176baef ("cxl/hdm: Commit decoder state to hardware")

Applied to cxl/next
7b6f9d9b1ea05c9c22570126547c780e8c6c3f62

Quoted 30 lines

---
Change log:
* Added CXL 3.2 Spec 8.2.4.20.12 Committing Decoder Programming statement. Thanks Alison.
* Collected reviewed-by. Thanks Dave and Alison.
RFC Link: https://lore.kernel.org/linux-cxl/[email protected]/

---
 drivers/cxl/core/hdm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cxl/core/hdm.c +1 -2
index eb5a3a7640c6..912f648a6b7a 100644
@@ -844,14 +844,13 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)
 	scoped_guard(rwsem_read, &cxl_rwsem.dpa)
 		setup_hw_decoder(cxld, hdm);
 
-	port->commit_end++;
 	rc = cxld_await_commit(hdm, cxld->id);
 	if (rc) {
 		dev_dbg(&port->dev, "%s: error %d committing decoder\n",
 			dev_name(&cxld->dev), rc);
-		cxld->reset(cxld);
 		return rc;
 	}
+	port->commit_end++;
 	cxld->flags |= CXL_DECODER_F_ENABLE;
 
 	return 0;