Skip to contentSkip to conversation

nvmet-tcp: fix data digest pointer calculation

PATCH In review Varun Prakash 4 participants 12 messages Oct 25, 2021 – Oct 28, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmet-tcp: fix data digest pointer calculation

exp_ddgst is of type __le32, &cmd->exp_ddgst + cmd->offset increases &cmd->exp_ddgst by 4 * cmd->offset, fix this by type casting &cmd->exp_ddgst to u8 *.

Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
---
 drivers/nvme/target/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/tcp.c +1 -1
index 07ee347..d641bfa 100644
@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
 	struct nvmet_tcp_queue *queue = cmd->queue;
 	struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
 	struct kvec iov = {
-		.iov_base = &cmd->exp_ddgst + cmd->offset,
+		.iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,
 		.iov_len = NVME_TCP_DIGEST_LENGTH - cmd->offset
 	};
 	int ret;
Signature · 1 line
2.0.2
#2 lore raw
In reply to Varun Prakash
Quoted 15 lines · Varun Prakash

exp_ddgst is of type __le32, &cmd->exp_ddgst + cmd->offset increases &cmd->exp_ddgst by 4 * cmd->offset, fix this by type casting &cmd->exp_ddgst to u8 *.

Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
---
 drivers/nvme/target/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/tcp.c +0 -0
index 07ee347..d641bfa 100644

drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705

Quoted 5 lines
drivers/nvme/target/tcp.c +1 -1
@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
 	struct nvmet_tcp_queue *queue = cmd->queue;
 	struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
 	struct kvec iov = {
-		.iov_base = &cmd->exp_ddgst + cmd->offset,
+		.iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,

Wouldn't be the better fix to divide cmd->offset by 4 instead of the casts? I can fix this up inline if that is ok.

maintainer
#3 lore raw
Quoted 11 lines
Quoted 11 lines

exp_ddgst is of type __le32, &cmd->exp_ddgst + cmd->offset increases &cmd->exp_ddgst by 4 * cmd->offset, fix this by type casting &cmd->exp_ddgst to u8 *.

Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
---
  drivers/nvme/target/tcp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705

Quoted 10 lines
drivers/nvme/target/tcp.c +1 -1
index 07ee347..d641bfa 100644
@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
  	struct nvmet_tcp_queue *queue = cmd->queue;
  	struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
  	struct kvec iov = {
-		.iov_base = &cmd->exp_ddgst + cmd->offset,
+		.iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,

Wouldn't be the better fix to divide cmd->offset by 4 instead of the casts? I can fix this up inline if that is ok.

Don't really mind, what makes it a better fix?

#4 lore raw
Quoted 14 lines · Sagi Grimberg
Quoted 5 lines
Quoted 5 lines
drivers/nvme/target/tcp.c +0 -0
index 07ee347..d641bfa 100644
@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
Quoted 8 lines

drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705

Quoted 5 lines
drivers/nvme/target/tcp.c +1 -1
  	struct nvmet_tcp_queue *queue = cmd->queue;
  	struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
  	struct kvec iov = {
-		.iov_base = &cmd->exp_ddgst + cmd->offset,
+		.iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,

Wouldn't be the better fix to divide cmd->offset by 4 instead of the casts? I can fix this up inline if that is ok.

Quoted 1 line

Don't really mind, what makes it a better fix?

I generally prefer to avoid casts as they paper over bugs.

maintainer
#5 lore raw
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705

Quoted 11 lines
drivers/nvme/target/tcp.c +1 -1
index 07ee347..d641bfa 100644
@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
   	struct nvmet_tcp_queue *queue = cmd->queue;
   	struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
   	struct kvec iov = {
-		.iov_base = &cmd->exp_ddgst + cmd->offset,
+		.iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,

Wouldn't be the better fix to divide cmd->offset by 4 instead of the casts? I can fix this up inline if that is ok.

Quoted 3 lines
Quoted 1 line

Don't really mind, what makes it a better fix?

I generally prefer to avoid casts as they paper over bugs.

I'm fine either way.

#6 lore raw
Quoted 15 lines · Sagi Grimberg
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705

Quoted 11 lines
drivers/nvme/target/tcp.c +1 -1
index 07ee347..d641bfa 100644
@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
  	struct nvmet_tcp_queue *queue = cmd->queue;
  	struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
  	struct kvec iov = {
-		.iov_base = &cmd->exp_ddgst + cmd->offset,
+		.iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,

Wouldn't be the better fix to divide cmd->offset by 4 instead of the casts? I can fix this up inline if that is ok.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Don't really mind, what makes it a better fix?

I generally prefer to avoid casts as they paper over bugs.

I'm fine either way.

cmd->offset can have value 0,1,2,3. cmd->offset / 4 will always be 0. If 2 bytes of digest are transmitted in the first call to kernel_sendmsg() then in the second call remaining 2 bytes has to be transmitted so data digest buffer pointer should increase by 2 bytes.

There is one more bug in nvmet_try_send_ddgst() it currently does not check whether digest is send successfully. For successful digest send cmd->offset + ret should be equal to NVME_TCP_DIGEST_LENGTH.

maintainer
#7 lore raw
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 14 lines

drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705

Quoted 11 lines
drivers/nvme/target/tcp.c +1 -1
index 07ee347..d641bfa 100644
@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
   	struct nvmet_tcp_queue *queue = cmd->queue;
   	struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
   	struct kvec iov = {
-		.iov_base = &cmd->exp_ddgst + cmd->offset,
+		.iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,

Wouldn't be the better fix to divide cmd->offset by 4 instead of the casts? I can fix this up inline if that is ok.

Don't really mind, what makes it a better fix?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I generally prefer to avoid casts as they paper over bugs.

I'm fine either way.

cmd->offset can have value 0,1,2,3. cmd->offset / 4 will always be 0. If 2 bytes of digest are transmitted in the first call to kernel_sendmsg() then in the second call remaining 2 bytes has to be transmitted so data digest buffer pointer should increase by 2 bytes.

Right, so let's just change the cast to (void *). Varun, can you respin the patches?

#8 lore raw
Quoted 21 lines · Sagi Grimberg
Quoted 21 lines
Quoted 20 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705

Quoted 11 lines
drivers/nvme/target/tcp.c +1 -1
index 07ee347..d641bfa 100644
@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
  	struct nvmet_tcp_queue *queue = cmd->queue;
  	struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
  	struct kvec iov = {
-		.iov_base = &cmd->exp_ddgst + cmd->offset,
+		.iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,

Wouldn't be the better fix to divide cmd->offset by 4 instead of the casts? I can fix this up inline if that is ok.

Quoted 3 lines
Quoted 1 line

Don't really mind, what makes it a better fix?

I generally prefer to avoid casts as they paper over bugs.

I'm fine either way.

Quoted 7 lines
Quoted 4 lines

cmd->offset can have value 0,1,2,3. cmd->offset / 4 will always be 0. If 2 bytes of digest are transmitted in the first call to kernel_sendmsg() then in the second call remaining 2 bytes has to be transmitted so data digest buffer pointer should increase by 2 bytes.

Right, so let's just change the cast to (void *). Varun, can you respin the patches?

Both the patches are already applied to nvme-5.15, should I send v2 or create a new patch for u8 * -> void * change?

#9 lore raw
Quoted 2 lines · Varun Prakash

Both the patches are already applied to nvme-5.15, should I send v2 or create a new patch for u8 * -> void * change?

I'm about to send the pull request with them to Jens. It is too late in the cycle now to respin again.

maintainer
#10 lore raw
Quoted 6 lines
Quoted 3 lines

Both the patches are already applied to nvme-5.15, should I send v2 or create a new patch for u8 * -> void * change?

I'm about to send the pull request with them to Jens. It is too late in the cycle now to respin again.

We can take care of that later...

maintainer
#11 lore raw
In reply to Varun Prakash

drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705

Quoted 6 lines · Varun Prakash
drivers/nvme/target/tcp.c +1 -1
@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
 	struct nvmet_tcp_queue *queue = cmd->queue;
 	struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
 	struct kvec iov = {
-		.iov_base = &cmd->exp_ddgst + cmd->offset,
+		.iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,

This certainly works too (and it's already applied anyway), though everywhere else in this driver casts these to 'void *'.