Skip to content

Commit a340635

Browse files
sagigrimbergChristoph Hellwig
authored andcommitted
nvme-tcp: fix opcode reporting in the timeout handler
For non in-capsule writes we reuse the request pdu space for a h2cdata pdu in order to avoid over allocating space (either preallocate or dynamically upon receving an r2t pdu). However if the request times out the core expects to find the opcode in the start of the request, which we override. In order to prevent that, without sacrificing additional 24 bytes per request, we just use the tail of the command pdu space instead (last 24 bytes from the 72 bytes command pdu). That should make the command opcode always available, and we get away from allocating more space. If in the future we would need the last 24 bytes of the nvme command available we would need to allocate a dedicated space for it in the request, but until then we can avoid doing so. Reported-by: Akinobu Mita <[email protected]> Signed-off-by: Sagi Grimberg <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Tested-by: Akinobu Mita <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent b65d44f commit a340635

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

drivers/nvme/host/tcp.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ static inline u8 nvme_tcp_ddgst_len(struct nvme_tcp_queue *queue)
208208
return queue->data_digest ? NVME_TCP_DIGEST_LENGTH : 0;
209209
}
210210

211+
static inline void *nvme_tcp_req_cmd_pdu(struct nvme_tcp_request *req)
212+
{
213+
return req->pdu;
214+
}
215+
216+
static inline void *nvme_tcp_req_data_pdu(struct nvme_tcp_request *req)
217+
{
218+
/* use the pdu space in the back for the data pdu */
219+
return req->pdu + sizeof(struct nvme_tcp_cmd_pdu) -
220+
sizeof(struct nvme_tcp_data_pdu);
221+
}
222+
211223
static inline size_t nvme_tcp_inline_data_size(struct nvme_tcp_request *req)
212224
{
213225
if (nvme_is_fabrics(req->req.cmd))
@@ -614,7 +626,7 @@ static int nvme_tcp_handle_comp(struct nvme_tcp_queue *queue,
614626

615627
static void nvme_tcp_setup_h2c_data_pdu(struct nvme_tcp_request *req)
616628
{
617-
struct nvme_tcp_data_pdu *data = req->pdu;
629+
struct nvme_tcp_data_pdu *data = nvme_tcp_req_data_pdu(req);
618630
struct nvme_tcp_queue *queue = req->queue;
619631
struct request *rq = blk_mq_rq_from_pdu(req);
620632
u32 h2cdata_sent = req->pdu_len;
@@ -1038,7 +1050,7 @@ static int nvme_tcp_try_send_data(struct nvme_tcp_request *req)
10381050
static int nvme_tcp_try_send_cmd_pdu(struct nvme_tcp_request *req)
10391051
{
10401052
struct nvme_tcp_queue *queue = req->queue;
1041-
struct nvme_tcp_cmd_pdu *pdu = req->pdu;
1053+
struct nvme_tcp_cmd_pdu *pdu = nvme_tcp_req_cmd_pdu(req);
10421054
bool inline_data = nvme_tcp_has_inline_data(req);
10431055
u8 hdgst = nvme_tcp_hdgst_len(queue);
10441056
int len = sizeof(*pdu) + hdgst - req->offset;
@@ -1077,7 +1089,7 @@ static int nvme_tcp_try_send_cmd_pdu(struct nvme_tcp_request *req)
10771089
static int nvme_tcp_try_send_data_pdu(struct nvme_tcp_request *req)
10781090
{
10791091
struct nvme_tcp_queue *queue = req->queue;
1080-
struct nvme_tcp_data_pdu *pdu = req->pdu;
1092+
struct nvme_tcp_data_pdu *pdu = nvme_tcp_req_data_pdu(req);
10811093
u8 hdgst = nvme_tcp_hdgst_len(queue);
10821094
int len = sizeof(*pdu) - req->offset + hdgst;
10831095
int ret;
@@ -2284,7 +2296,7 @@ static enum blk_eh_timer_return nvme_tcp_timeout(struct request *rq)
22842296
{
22852297
struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq);
22862298
struct nvme_ctrl *ctrl = &req->queue->ctrl->ctrl;
2287-
struct nvme_tcp_cmd_pdu *pdu = req->pdu;
2299+
struct nvme_tcp_cmd_pdu *pdu = nvme_tcp_req_cmd_pdu(req);
22882300
u8 opc = pdu->cmd.common.opcode, fctype = pdu->cmd.fabrics.fctype;
22892301
int qid = nvme_tcp_queue_id(req->queue);
22902302

@@ -2323,7 +2335,7 @@ static blk_status_t nvme_tcp_map_data(struct nvme_tcp_queue *queue,
23232335
struct request *rq)
23242336
{
23252337
struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq);
2326-
struct nvme_tcp_cmd_pdu *pdu = req->pdu;
2338+
struct nvme_tcp_cmd_pdu *pdu = nvme_tcp_req_cmd_pdu(req);
23272339
struct nvme_command *c = &pdu->cmd;
23282340

23292341
c->common.flags |= NVME_CMD_SGL_METABUF;
@@ -2343,7 +2355,7 @@ static blk_status_t nvme_tcp_setup_cmd_pdu(struct nvme_ns *ns,
23432355
struct request *rq)
23442356
{
23452357
struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq);
2346-
struct nvme_tcp_cmd_pdu *pdu = req->pdu;
2358+
struct nvme_tcp_cmd_pdu *pdu = nvme_tcp_req_cmd_pdu(req);
23472359
struct nvme_tcp_queue *queue = req->queue;
23482360
u8 hdgst = nvme_tcp_hdgst_len(queue), ddgst = 0;
23492361
blk_status_t ret;

0 commit comments

Comments
 (0)