diff options
author | Keith Busch <keith.busch@intel.com> | 2015-10-15 15:38:48 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2015-10-15 15:38:48 -0400 |
commit | 0dfc70c33409afc232ef0b9ec210535dfbf9bc61 (patch) | |
tree | 3ce38a73734b4a16364b1f2ba59a45df95dcdb6b | |
parent | b02176f30cd30acccd3b633ab7d9aed8b5da52ff (diff) |
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: stable@vger.kernel.org
Cc: <stable@vger.kernel.org> # 4.0.x-
Signed-off-by: Keith Busch <keith.busch@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r-- | drivers/block/nvme-core.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c index 84e4a8088386..ccc0c1f93daa 100644 --- a/drivers/block/nvme-core.c +++ b/drivers/block/nvme-core.c | |||
@@ -604,6 +604,7 @@ static void req_completion(struct nvme_queue *nvmeq, void *ctx, | |||
604 | struct request *req = iod_get_private(iod); | 604 | struct request *req = iod_get_private(iod); |
605 | struct nvme_cmd_info *cmd_rq = blk_mq_rq_to_pdu(req); | 605 | struct nvme_cmd_info *cmd_rq = blk_mq_rq_to_pdu(req); |
606 | u16 status = le16_to_cpup(&cqe->status) >> 1; | 606 | u16 status = le16_to_cpup(&cqe->status) >> 1; |
607 | bool requeue = false; | ||
607 | int error = 0; | 608 | int error = 0; |
608 | 609 | ||
609 | if (unlikely(status)) { | 610 | if (unlikely(status)) { |
@@ -611,12 +612,13 @@ static void req_completion(struct nvme_queue *nvmeq, void *ctx, | |||
611 | && (jiffies - req->start_time) < req->timeout) { | 612 | && (jiffies - req->start_time) < req->timeout) { |
612 | unsigned long flags; | 613 | unsigned long flags; |
613 | 614 | ||
615 | requeue = true; | ||
614 | blk_mq_requeue_request(req); | 616 | blk_mq_requeue_request(req); |
615 | spin_lock_irqsave(req->q->queue_lock, flags); | 617 | spin_lock_irqsave(req->q->queue_lock, flags); |
616 | if (!blk_queue_stopped(req->q)) | 618 | if (!blk_queue_stopped(req->q)) |
617 | blk_mq_kick_requeue_list(req->q); | 619 | blk_mq_kick_requeue_list(req->q); |
618 | spin_unlock_irqrestore(req->q->queue_lock, flags); | 620 | spin_unlock_irqrestore(req->q->queue_lock, flags); |
619 | return; | 621 | goto release_iod; |
620 | } | 622 | } |
621 | 623 | ||
622 | if (req->cmd_type == REQ_TYPE_DRV_PRIV) { | 624 | if (req->cmd_type == REQ_TYPE_DRV_PRIV) { |
@@ -639,6 +641,7 @@ static void req_completion(struct nvme_queue *nvmeq, void *ctx, | |||
639 | "completing aborted command with status:%04x\n", | 641 | "completing aborted command with status:%04x\n", |
640 | error); | 642 | error); |
641 | 643 | ||
644 | release_iod: | ||
642 | if (iod->nents) { | 645 | if (iod->nents) { |
643 | dma_unmap_sg(nvmeq->dev->dev, iod->sg, iod->nents, | 646 | dma_unmap_sg(nvmeq->dev->dev, iod->sg, iod->nents, |
644 | rq_data_dir(req) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | 647 | rq_data_dir(req) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); |
@@ -651,7 +654,8 @@ static void req_completion(struct nvme_queue *nvmeq, void *ctx, | |||
651 | } | 654 | } |
652 | nvme_free_iod(nvmeq->dev, iod); | 655 | nvme_free_iod(nvmeq->dev, iod); |
653 | 656 | ||
654 | blk_mq_complete_request(req, error); | 657 | if (likely(!requeue)) |
658 | blk_mq_complete_request(req, error); | ||
655 | } | 659 | } |
656 | 660 | ||
657 | /* length is in bytes. gfp flags indicates whether we may sleep. */ | 661 | /* length is in bytes. gfp flags indicates whether we may sleep. */ |