Skip to contentSkip to conversation

nvmet-tcp: fix a segmentation fault during io parsing error

PATCH Superseded [email protected] 3 participants 7 messages Mar 26, 2021 – Mar 30, 2021

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nvmet-tcp: fix a segmentation fault during io parsing error

From: Elad Grupi <[email protected]>

In case there is an io that contains inline data and it goes to parsing error flow, command response will free command and iov before clearing the data on the socket buffer.
This will delay the command response until receive flow is completed.

Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
---
 drivers/nvme/target/tcp.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)
drivers/nvme/target/tcp.c +23 -6
index 70cc507d1565..3bc0caa47873 100644
@@ -702,6 +702,17 @@ static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue,
 			return 0;
 	}
 
+	if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
+			nvmet_tcp_has_data_in(cmd) &&
+			nvmet_tcp_has_inline_data(cmd))) {
+		/*
+		 * wait for inline data before processing the response
+		 * so the iov will not be freed
+		 */
+		queue->snd_cmd = NULL;
+		goto done_send;
+	}
+
 	if (cmd->state == NVMET_TCP_SEND_DATA_PDU) {
 		ret = nvmet_try_send_data_pdu(cmd);
 		if (ret <= 0)
@@ -1103,9 +1114,11 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue)
 		return 0;
 	}
 
-	if (!(cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
-	    cmd->rbytes_done == cmd->req.transfer_len) {
-		cmd->req.execute(&cmd->req);
+	if (cmd->rbytes_done == cmd->req.transfer_len) {
+		if (unlikely(cmd->flags & NVMET_TCP_F_INIT_FAILED))
+			nvmet_tcp_queue_response(&cmd->req);
+		else
+			cmd->req.execute(&cmd->req);
 	}
 
 	nvmet_prepare_receive_pdu(queue);
@@ -1143,9 +1156,13 @@ static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue)
 		goto out;
 	}
 
-	if (!(cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
-	    cmd->rbytes_done == cmd->req.transfer_len)
-		cmd->req.execute(&cmd->req);
+	if (cmd->rbytes_done == cmd->req.transfer_len) {
+		if (unlikely(cmd->flags & NVMET_TCP_F_INIT_FAILED))
+			nvmet_tcp_queue_response(&cmd->req);
+		else
+			cmd->req.execute(&cmd->req);
+	}
+
 	ret = 0;
 out:
 	nvmet_prepare_receive_pdu(queue);
Signature · 7 lines
2.18.2


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
maintainer
#1 lore raw
Quoted 37 lines · On 3/26/21 10:59 AM, [email protected] wrote:

From: Elad Grupi <[email protected]>

In case there is an io that contains inline data and it goes to parsing error flow, command response will free command and iov before clearing the data on the socket buffer.
This will delay the command response until receive flow is completed.

Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
---
  drivers/nvme/target/tcp.c | 29 +++++++++++++++++++++++------
  1 file changed, 23 insertions(+), 6 deletions(-)
drivers/nvme/target/tcp.c +11 -0
index 70cc507d1565..3bc0caa47873 100644
@@ -702,6 +702,17 @@ static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue,
  			return 0;
  	}
 
+	if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
+			nvmet_tcp_has_data_in(cmd) &&
+			nvmet_tcp_has_inline_data(cmd))) {
+		/*
+		 * wait for inline data before processing the response
+		 * so the iov will not be freed
+		 */
+		queue->snd_cmd = NULL;
+		goto done_send;
+	}
+
  	if (cmd->state == NVMET_TCP_SEND_DATA_PDU) {
  		ret = nvmet_try_send_data_pdu(cmd);
  		if (ret <= 0)
@@ -1103,9 +1114,11 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue)
  		return 0;

drivers/nvme/target/tcp.c static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue) · line 1121

Quoted 10 lines
drivers/nvme/target/tcp.c +5 -3
  	}
 
-	if (!(cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
-	    cmd->rbytes_done == cmd->req.transfer_len) {
-		cmd->req.execute(&cmd->req);
+	if (cmd->rbytes_done == cmd->req.transfer_len) {
+		if (unlikely(cmd->flags & NVMET_TCP_F_INIT_FAILED))
+			nvmet_tcp_queue_response(&cmd->req);
+		else
+			cmd->req.execute(&cmd->req);

Given that this is called twice, care to move it to a new helper nvme_tcp_execute_request?

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#2 lore raw

Sure. Done.

Also avoided queueing failed REQ as discussed with Hou.

Elad

-----Original Message-----
From: Sagi Grimberg <[email protected]>
Sent: Saturday, 27 March 2021 0:03
To: Grupi, Elad; [email protected]
Subject: Re: [PATCH v2] nvmet-tcp: fix a segmentation fault during io parsing error

[EXTERNAL EMAIL]

Quoted 37 lines · On 3/26/21 10:59 AM, [email protected] wrote:

From: Elad Grupi <[email protected]>

In case there is an io that contains inline data and it goes to parsing error flow, command response will free command and iov before clearing the data on the socket buffer.
This will delay the command response until receive flow is completed.

Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
---
  drivers/nvme/target/tcp.c | 29 +++++++++++++++++++++++------
  1 file changed, 23 insertions(+), 6 deletions(-)
drivers/nvme/target/tcp.c +11 -0
index 70cc507d1565..3bc0caa47873 100644
@@ -702,6 +702,17 @@ static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue,
  			return 0;
  	}
 
+	if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
+			nvmet_tcp_has_data_in(cmd) &&
+			nvmet_tcp_has_inline_data(cmd))) {
+		/*
+		 * wait for inline data before processing the response
+		 * so the iov will not be freed
+		 */
+		queue->snd_cmd = NULL;
+		goto done_send;
+	}
+
  	if (cmd->state == NVMET_TCP_SEND_DATA_PDU) {
  		ret = nvmet_try_send_data_pdu(cmd);
  		if (ret <= 0)
@@ -1103,9 +1114,11 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue)
  		return 0;

drivers/nvme/target/tcp.c static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue) · line 1121

Quoted 10 lines
drivers/nvme/target/tcp.c +5 -3
  	}
 
-	if (!(cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
-	    cmd->rbytes_done == cmd->req.transfer_len) {
-		cmd->req.execute(&cmd->req);
+	if (cmd->rbytes_done == cmd->req.transfer_len) {
+		if (unlikely(cmd->flags & NVMET_TCP_F_INIT_FAILED))
+			nvmet_tcp_queue_response(&cmd->req);
+		else
+			cmd->req.execute(&cmd->req);

Given that this is called twice, care to move it to a new helper nvme_tcp_execute_request?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#3 lore raw
In reply to [email protected]
Quoted 10 lines · Elad Grupi

In case there is an io that contains inline data and it goes to parsing error flow, command response will free command and iov before clearing the data on the socket buffer.
This will delay the command response until receive flow is completed.

Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
---
 drivers/nvme/target/tcp.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

Hi Elad,
Just noticed that we still queue the failed REQ to the response queue in this version. Am I missing something?

Is this still needed? (I think it is).
@@ -526,6 +527,12 @@ static void nvmet_tcp_queue_response(struct nvmet_req *req)
container_of(req, struct nvmet_tcp_cmd, req);
struct nvmet_tcp_queue *queue = cmd->queue;

+ if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
+ nvmet_tcp_has_inline_data(cmd))) {
+ /* fail the cmd when we finish processing the inline data */
+ return;
+ }
+

Thanks,
Hou

Quoted 44 lines
drivers/nvme/target/tcp.c +16 -6
index 70cc507d1565..3bc0caa47873 100644
@@ -702,6 +702,17 @@ static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue,
 			return 0;
 	}
 
+	if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
+			nvmet_tcp_has_data_in(cmd) &&
+			nvmet_tcp_has_inline_data(cmd))) {
+		/*
+		 * wait for inline data before processing the response
+		 * so the iov will not be freed
+		 */
+		queue->snd_cmd = NULL;
+		goto done_send;
+	}
+
 	if (cmd->state == NVMET_TCP_SEND_DATA_PDU) {
 		ret = nvmet_try_send_data_pdu(cmd);
 		if (ret <= 0)
@@ -1103,9 +1114,11 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue)
 		return 0;
 	}
 
-	if (!(cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
-	    cmd->rbytes_done == cmd->req.transfer_len) {
-		cmd->req.execute(&cmd->req);
+	if (cmd->rbytes_done == cmd->req.transfer_len) {
+		if (unlikely(cmd->flags & NVMET_TCP_F_INIT_FAILED))
+			nvmet_tcp_queue_response(&cmd->req);
+		else
+			cmd->req.execute(&cmd->req);
 	}
 
 	nvmet_prepare_receive_pdu(queue);
@@ -1143,9 +1156,13 @@ static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue)
 		goto out;
 	}
 
-	if (!(cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
-	    cmd->rbytes_done == cmd->req.transfer_len)
-		cmd->req.execute(&cmd->req);

drivers/nvme/target/tcp.c static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue) · line 1168

Quoted 10 lines
drivers/nvme/target/tcp.c +7 -0
+	if (cmd->rbytes_done == cmd->req.transfer_len) {
+		if (unlikely(cmd->flags & NVMET_TCP_F_INIT_FAILED))
+			nvmet_tcp_queue_response(&cmd->req);
+		else
+			cmd->req.execute(&cmd->req);
+	}
+
 	ret = 0;
 out:
 	nvmet_prepare_receive_pdu(queue);

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#4 lore raw

Hi Hou

Even with the code below we will still queue the failed REQ for the first time.

Please mind the code in nvmet_tcp_done_recv_pdu:
1. nvmet_req_init will call __nvmet_req_complete with an error status 1.1. __nvmet_req_complete will call nvmet_tcp_queue_response
2. nvmet_tcp_handle_req_failure will set the flag NVMET_TCP_F_INIT_FAILED

In step 1.1, the failed REQ will be added to the queue anyway because the flag wasn't set yet.

In the previous patch I was adding the REQ back to the queue on nvmet_tcp_fetch_cmd, so it was useful to prevent queueing the REQ over and over again. Now I removed that part from the patch, so it means that the REQ will be added only once.

Elad

-----Original Message-----
From: Hou Pu <[email protected]>
Sent: Sunday, 28 March 2021 7:04
To: Grupi, Elad
Cc: [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v2] nvmet-tcp: fix a segmentation fault during io parsing error

[EXTERNAL EMAIL]

Quoted 10 lines · Elad Grupi

In case there is an io that contains inline data and it goes to parsing error flow, command response will free command and iov before clearing the data on the socket buffer.
This will delay the command response until receive flow is completed.

Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
---
 drivers/nvme/target/tcp.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

Hi Elad,
Just noticed that we still queue the failed REQ to the response queue in this version. Am I missing something?

Is this still needed? (I think it is).
@@ -526,6 +527,12 @@ static void nvmet_tcp_queue_response(struct nvmet_req *req)
container_of(req, struct nvmet_tcp_cmd, req);
struct nvmet_tcp_queue *queue = cmd->queue;

+ if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
+ nvmet_tcp_has_inline_data(cmd))) {
+ /* fail the cmd when we finish processing the inline data */
+ return;
+ }
+

Thanks,
Hou

Quoted 44 lines
drivers/nvme/target/tcp.c +16 -6
index 70cc507d1565..3bc0caa47873 100644
@@ -702,6 +702,17 @@ static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue,
 			return 0;
 	}
 
+	if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
+			nvmet_tcp_has_data_in(cmd) &&
+			nvmet_tcp_has_inline_data(cmd))) {
+		/*
+		 * wait for inline data before processing the response
+		 * so the iov will not be freed
+		 */
+		queue->snd_cmd = NULL;
+		goto done_send;
+	}
+
 	if (cmd->state == NVMET_TCP_SEND_DATA_PDU) {
 		ret = nvmet_try_send_data_pdu(cmd);
 		if (ret <= 0)
@@ -1103,9 +1114,11 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue)
 		return 0;
 	}
 
-	if (!(cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
-	    cmd->rbytes_done == cmd->req.transfer_len) {
-		cmd->req.execute(&cmd->req);
+	if (cmd->rbytes_done == cmd->req.transfer_len) {
+		if (unlikely(cmd->flags & NVMET_TCP_F_INIT_FAILED))
+			nvmet_tcp_queue_response(&cmd->req);
+		else
+			cmd->req.execute(&cmd->req);
 	}
 
 	nvmet_prepare_receive_pdu(queue);
@@ -1143,9 +1156,13 @@ static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue)
 		goto out;
 	}
 
-	if (!(cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
-	    cmd->rbytes_done == cmd->req.transfer_len)
-		cmd->req.execute(&cmd->req);

drivers/nvme/target/tcp.c static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue) · line 1168

Quoted 10 lines
drivers/nvme/target/tcp.c +7 -0
+	if (cmd->rbytes_done == cmd->req.transfer_len) {
+		if (unlikely(cmd->flags & NVMET_TCP_F_INIT_FAILED))
+			nvmet_tcp_queue_response(&cmd->req);
+		else
+			cmd->req.execute(&cmd->req);
+	}
+
 	ret = 0;
 out:
 	nvmet_prepare_receive_pdu(queue);

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#5 lore raw
Quoted 9 lines · Elad

Hi Hou

Even with the code below we will still queue the failed REQ for the first time.

Please mind the code in nvmet_tcp_done_recv_pdu:
1. nvmet_req_init will call __nvmet_req_complete with an error status 1.1. __nvmet_req_complete will call nvmet_tcp_queue_response
2. nvmet_tcp_handle_req_failure will set the flag NVMET_TCP_F_INIT_FAILED

Quoted 4 lines

In step 1.1, the failed REQ will be added to the queue anyway because the flag wasn't set yet.

In the previous patch I was adding the REQ back to the queue on nvmet_tcp_fetch_cmd, so it was useful to prevent queueing the REQ over and over again. Now I removed that part from the patch, so it means that the REQ will be added only once.

Thanks for the detailed explanation.

I'm fine with v2 or the new version.

Thanks,

Hou

Quoted 84 lines

Elad

-----Original Message-----
From: Hou Pu <[email protected]>
Sent: Sunday, 28 March 2021 7:04
To: Grupi, Elad
Cc: [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v2] nvmet-tcp: fix a segmentation fault during io parsing error

[EXTERNAL EMAIL]

Quoted 10 lines · Elad Grupi

In case there is an io that contains inline data and it goes to parsing error flow, command response will free command and iov before clearing the data on the socket buffer.
This will delay the command response until receive flow is completed.

Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
---
  drivers/nvme/target/tcp.c | 29 +++++++++++++++++++++++------
  1 file changed, 23 insertions(+), 6 deletions(-)

Hi Elad,
Just noticed that we still queue the failed REQ to the response queue in this version. Am I missing something?

Is this still needed? (I think it is).

(quoted diff) +6 -0
@@ -526,6 +527,12 @@ static void nvmet_tcp_queue_response(struct nvmet_req *req)
  		container_of(req, struct nvmet_tcp_cmd, req);
  	struct nvmet_tcp_queue	*queue = cmd->queue;
 
+	if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
+			nvmet_tcp_has_inline_data(cmd))) {
+		/* fail the cmd when we finish processing the inline data */
+		return;
+	}
+
 
 
 Thanks,

Hou

Quoted 41 lines
drivers/nvme/target/tcp.c +16 -3
index 70cc507d1565..3bc0caa47873 100644
@@ -702,6 +702,17 @@ static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue,
  			return 0;
  	}
 
+	if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
+			nvmet_tcp_has_data_in(cmd) &&
+			nvmet_tcp_has_inline_data(cmd))) {
+		/*
+		 * wait for inline data before processing the response
+		 * so the iov will not be freed
+		 */
+		queue->snd_cmd = NULL;
+		goto done_send;
+	}
+
  	if (cmd->state == NVMET_TCP_SEND_DATA_PDU) {
  		ret = nvmet_try_send_data_pdu(cmd);
  		if (ret <= 0)
@@ -1103,9 +1114,11 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue)
  		return 0;
  	}
 
-	if (!(cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
-	    cmd->rbytes_done == cmd->req.transfer_len) {
-		cmd->req.execute(&cmd->req);
+	if (cmd->rbytes_done == cmd->req.transfer_len) {
+		if (unlikely(cmd->flags & NVMET_TCP_F_INIT_FAILED))
+			nvmet_tcp_queue_response(&cmd->req);
+		else
+			cmd->req.execute(&cmd->req);
  	}
 
  	nvmet_prepare_receive_pdu(queue);
@@ -1143,9 +1156,13 @@ static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue)
  		goto out;
  	}
 
Quoted 13 lines

drivers/nvme/target/tcp.c static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue) · line 1168

Quoted 13 lines
drivers/nvme/target/tcp.c +7 -3
-	if (!(cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
-	    cmd->rbytes_done == cmd->req.transfer_len)
-		cmd->req.execute(&cmd->req);
+	if (cmd->rbytes_done == cmd->req.transfer_len) {
+		if (unlikely(cmd->flags & NVMET_TCP_F_INIT_FAILED))
+			nvmet_tcp_queue_response(&cmd->req);
+		else
+			cmd->req.execute(&cmd->req);
+	}
+
  	ret = 0;
  out:
  	nvmet_prepare_receive_pdu(queue);

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#6 lore raw

I sent an update to patch v2 which includes the -EAGAIN fix and another fix to prevent queueing the request twice.

Elad

-----Original Message-----
From: Hou Pu <[email protected]>
Sent: Tuesday, 30 March 2021 9:12
To: Grupi, Elad
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v2] nvmet-tcp: fix a segmentation fault during io parsing error

[EXTERNAL EMAIL]

Quoted 9 lines · Elad

Hi Hou

Even with the code below we will still queue the failed REQ for the first time.

Please mind the code in nvmet_tcp_done_recv_pdu:
1. nvmet_req_init will call __nvmet_req_complete with an error status 1.1. __nvmet_req_complete will call nvmet_tcp_queue_response 2. nvmet_tcp_handle_req_failure will set the flag NVMET_TCP_F_INIT_FAILED

Quoted 4 lines

In step 1.1, the failed REQ will be added to the queue anyway because the flag wasn't set yet.

In the previous patch I was adding the REQ back to the queue on nvmet_tcp_fetch_cmd, so it was useful to prevent queueing the REQ over and over again. Now I removed that part from the patch, so it means that the REQ will be added only once.

Thanks for the detailed explanation.

I'm fine with v2 or the new version.

Thanks,

Hou

Quoted 86 lines

Elad

-----Original Message-----
From: Hou Pu <[email protected]>
Sent: Sunday, 28 March 2021 7:04
To: Grupi, Elad
Cc: [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v2] nvmet-tcp: fix a segmentation fault during io parsing error

[EXTERNAL EMAIL]

Quoted 10 lines · Elad Grupi

In case there is an io that contains inline data and it goes to parsing error flow, command response will free command and iov before clearing the data on the socket buffer.
This will delay the command response until receive flow is completed.

Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
---
  drivers/nvme/target/tcp.c | 29 +++++++++++++++++++++++------
  1 file changed, 23 insertions(+), 6 deletions(-)

Hi Elad,
Just noticed that we still queue the failed REQ to the response queue in this version. Am I missing something?

Is this still needed? (I think it is).

(quoted diff) +6 -0
@@ -526,6 +527,12 @@ static void nvmet_tcp_queue_response(struct nvmet_req *req)
  		container_of(req, struct nvmet_tcp_cmd, req);
  	struct nvmet_tcp_queue	*queue = cmd->queue;
 
+	if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
+			nvmet_tcp_has_inline_data(cmd))) {
+		/* fail the cmd when we finish processing the inline data */
+		return;
+	}
+
 
 
 Thanks,

Hou

Quoted 41 lines
drivers/nvme/target/tcp.c +16 -3
index 70cc507d1565..3bc0caa47873 100644
@@ -702,6 +702,17 @@ static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue,
  			return 0;
  	}
 
+	if (unlikely((cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
+			nvmet_tcp_has_data_in(cmd) &&
+			nvmet_tcp_has_inline_data(cmd))) {
+		/*
+		 * wait for inline data before processing the response
+		 * so the iov will not be freed
+		 */
+		queue->snd_cmd = NULL;
+		goto done_send;
+	}
+
  	if (cmd->state == NVMET_TCP_SEND_DATA_PDU) {
  		ret = nvmet_try_send_data_pdu(cmd);
  		if (ret <= 0)
@@ -1103,9 +1114,11 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue)
  		return 0;
  	}
 
-	if (!(cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
-	    cmd->rbytes_done == cmd->req.transfer_len) {
-		cmd->req.execute(&cmd->req);
+	if (cmd->rbytes_done == cmd->req.transfer_len) {
+		if (unlikely(cmd->flags & NVMET_TCP_F_INIT_FAILED))
+			nvmet_tcp_queue_response(&cmd->req);
+		else
+			cmd->req.execute(&cmd->req);
  	}
 
  	nvmet_prepare_receive_pdu(queue);
@@ -1143,9 +1156,13 @@ static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue)
  		goto out;
  	}
 
Quoted 13 lines

drivers/nvme/target/tcp.c static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue) · line 1168

Quoted 13 lines
drivers/nvme/target/tcp.c +7 -3
-	if (!(cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
-	    cmd->rbytes_done == cmd->req.transfer_len)
-		cmd->req.execute(&cmd->req);
+	if (cmd->rbytes_done == cmd->req.transfer_len) {
+		if (unlikely(cmd->flags & NVMET_TCP_F_INIT_FAILED))
+			nvmet_tcp_queue_response(&cmd->req);
+		else
+			cmd->req.execute(&cmd->req);
+	}
+
  	ret = 0;
  out:
  	nvmet_prepare_receive_pdu(queue);

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme