Skip to contentSkip to conversation

cxl/mbox: Restore signedness to a mailbox payload variable

PATCH In review [email protected] 2 participants 3 messages Apr 13, 2022 CXL

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH v2 1/1 cxl/mbox: Restore signedness to a mailbox payload variable

From: Alison Schofield <[email protected]>

A mailbox command output size value of (-1) means that a device may return a variable sized output to that command. The device defines a maximum payload size, so the driver will allocate enough memory to receive that maximum payload for variable size mailbox commands.

A recent code refactoring discarded the signedness on 'out_size' before checking it, thereby breaking the handling of mailbox commands with variable sized output. Pass along both in_size and out_size with signedness, and only discard the signedness when building the cxl_mbox_cmd structure.

Smatch warn: unsigned 'out_size' is never less than 0

Fixes be0d0ce77aa3 ("cxl/mbox: Move build of user mailbox cmd to a helper funct

ions")

---

Changes in v2:
- Pass the payload sizes as signed rather than move the check (Dan)
- Signedness is now discarded on ssize_t to size_t assignment.
- Update commit msg. Was 'Handle variable size output while still signed'
- Update commit log.

 drivers/cxl/core/mbox.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/mbox.c +1 -1
index 8a8388599a85..6c6f6a157485 100644
@@ -253,7 +253,7 @@ static bool cxl_payload_from_user_allowed(u16 opcode, void *payload_in)
 
 static int cxl_mbox_cmd_ctor(struct cxl_mbox_cmd *mbox,
 			     struct cxl_dev_state *cxlds, u16 opcode,
-			     size_t in_size, size_t out_size, u64 in_payload)
+			     ssize_t in_size, ssize_t out_size, u64 in_payload)
 {
 	*mbox = (struct cxl_mbox_cmd) {
 		.opcode = opcode,

base-commit: 7dc1d11d7abae52aada5340fb98885f0ddbb7c37

Signature · 1 line
2.31.1
#1 lore raw
Quoted 14 lines · On 22-04-13 12:13:11, [email protected] wrote:

From: Alison Schofield <[email protected]>

A mailbox command output size value of (-1) means that a device may return a variable sized output to that command. The device defines a maximum payload size, so the driver will allocate enough memory to receive that maximum payload for variable size mailbox commands.

A recent code refactoring discarded the signedness on 'out_size' before checking it, thereby breaking the handling of mailbox commands with variable sized output. Pass along both in_size and out_size with signedness, and only discard the signedness when building the cxl_mbox_cmd structure.

Quoted 7 lines

Smatch warn: unsigned 'out_size' is never less than 0

Fixes be0d0ce77aa3 ("cxl/mbox: Move build of user mailbox cmd to a helper funct

ions")

Per internal discussion, do we want to change in_size also? I'm in favor of fixing the ABI.

[snip]

author maintainer
#2 lore raw
Quoted 17 lines · Ben Widawsky
Quoted 16 lines · On 22-04-13 12:13:11, [email protected] wrote:

From: Alison Schofield <[email protected]>

A mailbox command output size value of (-1) means that a device may return a variable sized output to that command. The device defines a maximum payload size, so the driver will allocate enough memory to receive that maximum payload for variable size mailbox commands.

A recent code refactoring discarded the signedness on 'out_size' before checking it, thereby breaking the handling of mailbox commands with variable sized output. Pass along both in_size and out_size with signedness, and only discard the signedness when building the cxl_mbox_cmd structure.

Smatch warn: unsigned 'out_size' is never less than 0

Quoted 9 lines
Quoted 5 lines
Fixes be0d0ce77aa3 ("cxl/mbox: Move build of user mailbox cmd to a helper funct

ions")

Per internal discussion, do we want to change in_size also? I'm in favor of fixing the ABI.

Thanks for reviewing!
OK - next version will removed the signedness from the ABI. Compare to UINT_MAX for the variable size option.

Quoted 2 lines

[snip]