libnvme: do not byte swap command dwords
PATCH 1/1 libnvme: do not byte swap command dwords
From: Keith Busch <[email protected]>
The dwords always need to be set in the cpu native format. The driver will handle setting up the SQE in the nvme little-endian order, and big endian is never used, so this byte swapping was wrong.
--- src/nvme/ioctl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
src/nvme/ioctl.c +3 -3
@@ -1920,9 +1920,9 @@ static int nvme_set_var_size_tags(__u32 *cmd_dw2, __u32 *cmd_dw3, __u32 *cmd_dw1return -1 ; } - *cmd_dw2 =cpu_to_be32 (cdw2); - *cmd_dw3 =cpu_to_be32 (cdw3); - *cmd_dw14 =cpu_to_be32 (cdw14); + *cmd_dw2 = cdw2; + *cmd_dw3 = cdw3; + *cmd_dw14 = cdw14;return 0 ; }
Signature · 1 line
2.47.1
Quoted 17 lines · Keith Busch
From: Keith Busch <[email protected]>
The dwords always need to be set in the cpu native format. The driver will handle setting up the SQE in the nvme little-endian order, and big endian is never used, so this byte swapping was wrong.
Signed-off-by Keith Busch <[email protected]>--- src/nvme/ioctl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)src/nvme/ioctl.c +0
-0
src/nvme/ioctl.c static int nvme_set_var_size_tags(__u32 *cmd_dw2, __u32 *cmd_dw3, __u32 *cmd_dw1 · line 1925
Quoted 9 lines
src/nvme/ioctl.c +3
-3@@ -1920,9 +1920,9 @@ static int nvme_set_var_size_tags(__u32 *cmd_dw2, __u32 *cmd_dw3, __u32 *cmd_dw1return -1 ; } - *cmd_dw2 =cpu_to_be32 (cdw2); - *cmd_dw3 =cpu_to_be32 (cdw3); - *cmd_dw14 =cpu_to_be32 (cdw14); + *cmd_dw2 = cdw2; + *cmd_dw3 = cdw3; + *cmd_dw14 = cdw14;
in this case shouldn't we use cpu_to_le32?
Keith Busch
maintainerQuoted 21 lines · Daniel Wagner
Quoted 20 lines · Keith Busch
From: Keith Busch <[email protected]>
The dwords always need to be set in the cpu native format. The driver will handle setting up the SQE in the nvme little-endian order, and big endian is never used, so this byte swapping was wrong.
Signed-off-by Keith Busch <[email protected]>--- src/nvme/ioctl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)src/nvme/ioctl.c +0
-0@@ -1920,9 +1920,9 @@ static int nvme_set_var_size_tags(__u32 *cmd_dw2, __u32 *cmd_dw3, __u32 *cmd_dw1return -1 ; }
Quoted 8 lines
src/nvme/ioctl.c static int nvme_set_var_size_tags(__u32 *cmd_dw2, __u32 *cmd_dw3, __u32 *cmd_dw1 · line 1925
Quoted 6 lines
src/nvme/ioctl.c +3
-3- *cmd_dw2 =cpu_to_be32 (cdw2); - *cmd_dw3 =cpu_to_be32 (cdw3); - *cmd_dw14 =cpu_to_be32 (cdw14); + *cmd_dw2 = cdw2; + *cmd_dw3 = cdw3; + *cmd_dw14 = cdw14;in this case shouldn't we use
cpu_to_le32?
No, user space was only uses cpu native endian when constructing the command. The driver handles the endian conversion if necessary.
That conversion is just for the command control side. The driver doesn't do any such manipulation on the data plane, so endianness in payloads for commands like "copy", "dsm", or PI meatada need to be handled by the application.
Quoted 1 line · Daniel Wagner
in this case shouldn't we use
cpu_to_le32?
Nevermind, just saw your explanation on github. the driver takes care of it...
Daniel Wagner
AppliedQuoted 5 lines · Keith Busch
The dwords always need to be set in the cpu native format. The driver will handle setting up the SQE in the nvme little-endian order, and big endian is never used, so this byte swapping was wrong.
Applied, thanks!
[1/1] libnvme: do not byte swap command dwords
commit: 89ac31f536baf15c1834f877b4c1fb9aca1cf94f
Best regards,
Signature · 1 line
Daniel Wagner <[email protected]>