| From 389f10cd2b0c7b2648be5a761accc09af8601ca5 Mon Sep 17 00:00:00 2001 |
| From: Christoph Hellwig <hch@lst.de> |
| Date: Thu, 30 Jan 2020 19:40:24 +0100 |
| Subject: [PATCH] nvme-pci: remove nvmeq->tags |
| |
| commit cfa27356f835dc7755192e7b941d4f4851acbcc7 upstream. |
| |
| There is no real need to have a pointer to the tagset in |
| struct nvme_queue, as we only need it in a single place, and that place |
| can derive the used tagset from the device and qid trivially. This |
| fixes a problem with stale pointer exposure when tagsets are reset, |
| and also shrinks the nvme_queue structure. It also matches what most |
| other transports have done since day 1. |
| |
| Reported-by: Edmund Nadolski <edmund.nadolski@intel.com> |
| Signed-off-by: Christoph Hellwig <hch@lst.de> |
| Signed-off-by: Keith Busch <kbusch@kernel.org> |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c |
| index 9cd438e528f9..94194da1c07b 100644 |
| --- a/drivers/nvme/host/pci.c |
| +++ b/drivers/nvme/host/pci.c |
| @@ -183,7 +183,6 @@ struct nvme_queue { |
| /* only used for poll queues: */ |
| spinlock_t cq_poll_lock ____cacheline_aligned_in_smp; |
| volatile struct nvme_completion *cqes; |
| - struct blk_mq_tags **tags; |
| dma_addr_t sq_dma_addr; |
| dma_addr_t cq_dma_addr; |
| u32 __iomem *q_db; |
| @@ -392,29 +391,17 @@ static int nvme_admin_init_hctx(struct blk_mq_hw_ctx *hctx, void *data, |
| |
| WARN_ON(hctx_idx != 0); |
| WARN_ON(dev->admin_tagset.tags[0] != hctx->tags); |
| - WARN_ON(nvmeq->tags); |
| |
| hctx->driver_data = nvmeq; |
| - nvmeq->tags = &dev->admin_tagset.tags[0]; |
| return 0; |
| } |
| |
| -static void nvme_admin_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int hctx_idx) |
| -{ |
| - struct nvme_queue *nvmeq = hctx->driver_data; |
| - |
| - nvmeq->tags = NULL; |
| -} |
| - |
| static int nvme_init_hctx(struct blk_mq_hw_ctx *hctx, void *data, |
| unsigned int hctx_idx) |
| { |
| struct nvme_dev *dev = data; |
| struct nvme_queue *nvmeq = &dev->queues[hctx_idx + 1]; |
| |
| - if (!nvmeq->tags) |
| - nvmeq->tags = &dev->tagset.tags[hctx_idx]; |
| - |
| WARN_ON(dev->tagset.tags[hctx_idx] != hctx->tags); |
| hctx->driver_data = nvmeq; |
| return 0; |
| @@ -963,6 +950,13 @@ static inline void nvme_ring_cq_doorbell(struct nvme_queue *nvmeq) |
| writel(head, nvmeq->q_db + nvmeq->dev->db_stride); |
| } |
| |
| +static inline struct blk_mq_tags *nvme_queue_tagset(struct nvme_queue *nvmeq) |
| +{ |
| + if (!nvmeq->qid) |
| + return nvmeq->dev->admin_tagset.tags[0]; |
| + return nvmeq->dev->tagset.tags[nvmeq->qid - 1]; |
| +} |
| + |
| static inline void nvme_handle_cqe(struct nvme_queue *nvmeq, u16 idx) |
| { |
| volatile struct nvme_completion *cqe = &nvmeq->cqes[idx]; |
| @@ -988,7 +982,7 @@ static inline void nvme_handle_cqe(struct nvme_queue *nvmeq, u16 idx) |
| return; |
| } |
| |
| - req = blk_mq_tag_to_rq(*nvmeq->tags, cqe->command_id); |
| + req = blk_mq_tag_to_rq(nvme_queue_tagset(nvmeq), cqe->command_id); |
| trace_nvme_sq(req, cqe->sq_head, nvmeq->sq_tail); |
| nvme_end_request(req, cqe->status, cqe->result); |
| } |
| @@ -1591,7 +1585,6 @@ static const struct blk_mq_ops nvme_mq_admin_ops = { |
| .queue_rq = nvme_queue_rq, |
| .complete = nvme_pci_complete_rq, |
| .init_hctx = nvme_admin_init_hctx, |
| - .exit_hctx = nvme_admin_exit_hctx, |
| .init_request = nvme_init_request, |
| .timeout = nvme_timeout, |
| }; |
| -- |
| 2.7.4 |
| |