Skip to content

Commit 0dfc70c

Browse files
Keith Buschaxboe
authored andcommitted
NVMe: Fix memory leak on retried commands
Resources are reallocated for requeued commands, so unmap and release the iod for the failed command. It's a pretty bad memory leak and causes a kernel hang if you remove a drive because of a busy dma pool. You'll get messages spewing like this: nvme 0000:xx:xx.x: dma_pool_destroy prp list 256, ffff880420dec000 busy and lock up pci and the driver since removal never completes while holding a lock. Cc: [email protected] Cc: <[email protected]> # 4.0.x- Signed-off-by: Keith Busch <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent b02176f commit 0dfc70c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/block/nvme-core.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,19 +604,21 @@ static void req_completion(struct nvme_queue *nvmeq, void *ctx,
604604
struct request *req = iod_get_private(iod);
605605
struct nvme_cmd_info *cmd_rq = blk_mq_rq_to_pdu(req);
606606
u16 status = le16_to_cpup(&cqe->status) >> 1;
607+
bool requeue = false;
607608
int error = 0;
608609

609610
if (unlikely(status)) {
610611
if (!(status & NVME_SC_DNR || blk_noretry_request(req))
611612
&& (jiffies - req->start_time) < req->timeout) {
612613
unsigned long flags;
613614

615+
requeue = true;
614616
blk_mq_requeue_request(req);
615617
spin_lock_irqsave(req->q->queue_lock, flags);
616618
if (!blk_queue_stopped(req->q))
617619
blk_mq_kick_requeue_list(req->q);
618620
spin_unlock_irqrestore(req->q->queue_lock, flags);
619-
return;
621+
goto release_iod;
620622
}
621623

622624
if (req->cmd_type == REQ_TYPE_DRV_PRIV) {
@@ -639,6 +641,7 @@ static void req_completion(struct nvme_queue *nvmeq, void *ctx,
639641
"completing aborted command with status:%04x\n",
640642
error);
641643

644+
release_iod:
642645
if (iod->nents) {
643646
dma_unmap_sg(nvmeq->dev->dev, iod->sg, iod->nents,
644647
rq_data_dir(req) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
@@ -651,7 +654,8 @@ static void req_completion(struct nvme_queue *nvmeq, void *ctx,
651654
}
652655
nvme_free_iod(nvmeq->dev, iod);
653656

654-
blk_mq_complete_request(req, error);
657+
if (likely(!requeue))
658+
blk_mq_complete_request(req, error);
655659
}
656660

657661
/* length is in bytes. gfp flags indicates whether we may sleep. */

0 commit comments

Comments
 (0)