Skip to content

Commit ed0691c

Browse files
sagigrimbergChristoph Hellwig
authored andcommitted
nvmet-tcp: fix regression in data_digest calculation
Data digest calculation iterates over command mapped iovec. However since commit bac0445 we unmap the iovec before we handle the data digest, and since commit 69b85e1 we clear nr_mapped when we unmap the iov. Instead of open-coding the command iov traversal, simply call crypto_ahash_digest with the command sg that is already allocated (we already do that for the send path). Rename nvmet_tcp_send_ddgst to nvmet_tcp_calc_ddgst and call it from send and recv paths. Fixes: 69b85e1 ("nvmet-tcp: add an helper to free the cmd buffers") Fixes: bac0445 ("nvmet-tcp: fix kmap leak when data digest in use") Signed-off-by: Sagi Grimberg <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent fbb564a commit ed0691c

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

drivers/nvme/target/tcp.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -405,31 +405,14 @@ static int nvmet_tcp_map_data(struct nvmet_tcp_cmd *cmd)
405405
return NVME_SC_INTERNAL;
406406
}
407407

408-
static void nvmet_tcp_send_ddgst(struct ahash_request *hash,
408+
static void nvmet_tcp_calc_ddgst(struct ahash_request *hash,
409409
struct nvmet_tcp_cmd *cmd)
410410
{
411411
ahash_request_set_crypt(hash, cmd->req.sg,
412412
(void *)&cmd->exp_ddgst, cmd->req.transfer_len);
413413
crypto_ahash_digest(hash);
414414
}
415415

416-
static void nvmet_tcp_recv_ddgst(struct ahash_request *hash,
417-
struct nvmet_tcp_cmd *cmd)
418-
{
419-
struct scatterlist sg;
420-
struct kvec *iov;
421-
int i;
422-
423-
crypto_ahash_init(hash);
424-
for (i = 0, iov = cmd->iov; i < cmd->nr_mapped; i++, iov++) {
425-
sg_init_one(&sg, iov->iov_base, iov->iov_len);
426-
ahash_request_set_crypt(hash, &sg, NULL, iov->iov_len);
427-
crypto_ahash_update(hash);
428-
}
429-
ahash_request_set_crypt(hash, NULL, (void *)&cmd->exp_ddgst, 0);
430-
crypto_ahash_final(hash);
431-
}
432-
433416
static void nvmet_setup_c2h_data_pdu(struct nvmet_tcp_cmd *cmd)
434417
{
435418
struct nvme_tcp_data_pdu *pdu = cmd->data_pdu;
@@ -454,7 +437,7 @@ static void nvmet_setup_c2h_data_pdu(struct nvmet_tcp_cmd *cmd)
454437

455438
if (queue->data_digest) {
456439
pdu->hdr.flags |= NVME_TCP_F_DDGST;
457-
nvmet_tcp_send_ddgst(queue->snd_hash, cmd);
440+
nvmet_tcp_calc_ddgst(queue->snd_hash, cmd);
458441
}
459442

460443
if (cmd->queue->hdr_digest) {
@@ -1137,7 +1120,7 @@ static void nvmet_tcp_prep_recv_ddgst(struct nvmet_tcp_cmd *cmd)
11371120
{
11381121
struct nvmet_tcp_queue *queue = cmd->queue;
11391122

1140-
nvmet_tcp_recv_ddgst(queue->rcv_hash, cmd);
1123+
nvmet_tcp_calc_ddgst(queue->rcv_hash, cmd);
11411124
queue->offset = 0;
11421125
queue->left = NVME_TCP_DIGEST_LENGTH;
11431126
queue->rcv_state = NVMET_TCP_RECV_DDGST;

0 commit comments

Comments
 (0)