Skip to contentSkip to conversation

cxl/mbox: Return success for CXL_MBOX_CMD_RC_BACKGROUND

PATCH Superseded Li Ming 3 participants 5 messages Nov 3 – Nov 6 CXL

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Li Ming

author reviewer
#0 lore raw

PATCH v2 1/2 cxl/mbox: Return success for CXL_MBOX_CMD_RC_BACKGROUND

In CXL subsystem, each mbox command hw return code is mapped to a corresponding errno value. Currently, CXL_MBOX_CMD_RC_BACKGROUND is mapped to -ENXIO.

However, per Table-8-208 in CXL r4.0 section 8.2.9.4.5.1, a BACKGROUND HW return code indicates that the command has been accepted by the device and continues execution asynchronously. It does not indicate a command failure.

Return 0 instead of -ENXIO for CXL_MBOX_CMD_RC_BACKGROUND so that callers do not treat a successfully started background operation as an error.

Fixes 92fcc1abab09 ("cxl/mbox: Improve handling of mbox_cmd hw return codes")

---
v2:
- Add a reference to the relevant spec section in the commit log.

---
 drivers/cxl/cxlmem.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/cxlmem.h +1 -1
index c401e3a1af06..cc71d7a84cdc 100644
@@ -160,7 +160,7 @@ static inline struct cxl_ep *cxl_ep_load(struct cxl_port *port,
  */
 #define CMD_CMD_RC_TABLE							\
 	C(SUCCESS, 0, NULL),							\
-	C(BACKGROUND, -ENXIO, "background cmd started successfully"),           \
+	C(BACKGROUND, 0, "background cmd started successfully"),		\
 	C(INPUT, -ENXIO, "cmd input was invalid"),				\
 	C(UNSUPPORTED, -ENXIO, "cmd is not supported"),				\
 	C(INTERNAL, -ENXIO, "internal device error"),				\
Signature · 1 line
2.43.0
author reviewer
#1 lore raw

PATCH v2 2/2 cxl/mbox: Use mapped errno to determine command status

cxl_mbox_cmd_rctable already maps all mailbox command return codes to errno values. Use the returned errno directly instead of checking mailbox return codes separately to determine whether a command succeeded or failed.

---
v2:
- New patch.

---
 drivers/cxl/core/mbox.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cxl/core/mbox.c +3 -3
index 55828a836c01..bd91b03c4d21 100644
@@ -270,9 +270,9 @@ int cxl_internal_send_cmd(struct cxl_mailbox *cxl_mbox,
 	if (rc)
 		return rc;
 
-	if (mbox_cmd->return_code != CXL_MBOX_CMD_RC_SUCCESS &&
-	    mbox_cmd->return_code != CXL_MBOX_CMD_RC_BACKGROUND)
-		return cxl_mbox_cmd_rc2errno(mbox_cmd);
+	rc = cxl_mbox_cmd_rc2errno(mbox_cmd);
+	if (rc)
+		return rc;
 
 	if (!out_size)
 		return 0;
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH v2 2/2] cxl/mbox: Use mapped errno to determine command status

Quoted 18 lines · Li Ming

cxl_mbox_cmd_rctable already maps all mailbox command return codes to errno values. Use the returned errno directly instead of checking mailbox return codes separately to determine whether a command succeeded or failed.

---
v2:
- New patch.

---
 drivers/cxl/core/mbox.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cxl/core/mbox.c +0 -0
index 55828a836c01..bd91b03c4d21 100644

drivers/cxl/core/mbox.c int cxl_internal_send_cmd(struct cxl_mailbox *cxl_mbox, · line 275

Quoted 9 lines
drivers/cxl/core/mbox.c +3 -3
@@ -270,9 +270,9 @@ int cxl_internal_send_cmd(struct cxl_mailbox *cxl_mbox,
 	if (rc)
 		return rc;
 
-	if (mbox_cmd->return_code != CXL_MBOX_CMD_RC_SUCCESS &&
-	    mbox_cmd->return_code != CXL_MBOX_CMD_RC_BACKGROUND)
-		return cxl_mbox_cmd_rc2errno(mbox_cmd);
+	rc = cxl_mbox_cmd_rc2errno(mbox_cmd);
+	if (rc)
+		return rc;

Hi Ming,

The existing code really seemed to want BACKGROUND as a special case, so I searched the history on this one, Davidlohr and you discussed this in 2023 around sanitize[1] .

I do think it is confusing and if we can just follow the table codes, that would be easier.

I'll let Davidlohr dig in on this one.

I read both these patches as cleanups but no bug to be fixed.

[1] https://lore.kernel.org/linux-cxl/mw5bsc5u72fdrgo7qovj6u2npg2asftzp3jeprwtmnvbvg7vet@fayzcxpurjl6/

-- Alison

Quoted 6 lines
drivers/cxl/core/mbox.c +0 -0
 	if (!out_size)
 		return 0;
Signature · 1 line
2.43.0
author reviewer
#3 lore raw

Re: [PATCH v2 2/2] cxl/mbox: Use mapped errno to determine command status

Quoted 30 lines · Alison Schofield
Quoted 18 lines · Li Ming

cxl_mbox_cmd_rctable already maps all mailbox command return codes to errno values. Use the returned errno directly instead of checking mailbox return codes separately to determine whether a command succeeded or failed.

---
v2:
- New patch.

---
  drivers/cxl/core/mbox.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cxl/core/mbox.c +0 -0
index 55828a836c01..bd91b03c4d21 100644

drivers/cxl/core/mbox.c int cxl_internal_send_cmd(struct cxl_mailbox *cxl_mbox, · line 275

Quoted 9 lines
drivers/cxl/core/mbox.c +3 -3
@@ -270,9 +270,9 @@ int cxl_internal_send_cmd(struct cxl_mailbox *cxl_mbox,
  	if (rc)
  		return rc;
 
-	if (mbox_cmd->return_code != CXL_MBOX_CMD_RC_SUCCESS &&
-	    mbox_cmd->return_code != CXL_MBOX_CMD_RC_BACKGROUND)
-		return cxl_mbox_cmd_rc2errno(mbox_cmd);
+	rc = cxl_mbox_cmd_rc2errno(mbox_cmd);
+	if (rc)
+		return rc;

Hi Ming,

Quoted 6 lines

The existing code really seemed to want BACKGROUND as a special case, so I searched the history on this one, Davidlohr and you discussed this in 2023 around sanitize[1] .

I do think it is confusing and if we can just follow the table codes, that would be easier.

Hi Alison,

Thanks for your review.

I checked the link you shared, it is about the return code of a BACKGROUND cmd handling inside __cxl_pci_mbox_send_cmd(), because __cxl_pci_mbox_send_cmd() needs to handle both non-BACKGROUND and BACKGROUND cmds and returns the result. but in cxl_internal_send_cmd(), I think we can consider the cmd done whether it is a BACKGROUND command or not.

Quoted 2 lines

I'll let Davidlohr dig in on this one.

Thanks.

Quoted 2 lines

I read both these patches as cleanups but no bug to be fixed.

Sure, will drop the fixes tag.

Ming

Quoted 16 lines

[1] https://lore.kernel.org/linux-cxl/mw5bsc5u72fdrgo7qovj6u2npg2asftzp3jeprwtmnvbvg7vet@fayzcxpurjl6/

-- Alison

Quoted 6 lines
drivers/cxl/core/mbox.c +0 -0
  	if (!out_size)
  		return 0;
Signature · 1 line
2.43.0
maintainer Reviewed-by
#4 lore raw

Re: [PATCH v2 2/2] cxl/mbox: Use mapped errno to determine command status

In reply to Alison Schofield
Quoted 35 lines · Alison Schofield
Quoted 18 lines · Li Ming

cxl_mbox_cmd_rctable already maps all mailbox command return codes to errno values. Use the returned errno directly instead of checking mailbox return codes separately to determine whether a command succeeded or failed.

---
v2:
- New patch.

---
 drivers/cxl/core/mbox.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cxl/core/mbox.c +0 -0
index 55828a836c01..bd91b03c4d21 100644

drivers/cxl/core/mbox.c int cxl_internal_send_cmd(struct cxl_mailbox *cxl_mbox, · line 275

Quoted 9 lines
drivers/cxl/core/mbox.c +3 -3
@@ -270,9 +270,9 @@ int cxl_internal_send_cmd(struct cxl_mailbox *cxl_mbox,
 	if (rc)
 		return rc;
 
-	if (mbox_cmd->return_code != CXL_MBOX_CMD_RC_SUCCESS &&
-	    mbox_cmd->return_code != CXL_MBOX_CMD_RC_BACKGROUND)
-		return cxl_mbox_cmd_rc2errno(mbox_cmd);
+	rc = cxl_mbox_cmd_rc2errno(mbox_cmd);
+	if (rc)
+		return rc;

Hi Ming,

The existing code really seemed to want BACKGROUND as a special case, so I searched the history on this one, Davidlohr and you discussed this in 2023 around sanitize[1] .

Quoted 6 lines

I do think it is confusing and if we can just follow the table codes, that would be easier.

I'll let Davidlohr dig in on this one.

I read both these patches as cleanups but no bug to be fixed.

Exactly, the Fixes tag in patch 1 should be dropped, but otherwise for the series:

(this patch reminds me that I want to create a cxl-bg-tests + the abortable bg semantics)