Skip to content

Commit cfa2735

Browse files
Christoph Hellwigkeithbusch
authored andcommitted
nvme-pci: remove nvmeq->tags
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 <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent b716e68 commit cfa2735

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

drivers/nvme/host/pci.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ struct nvme_queue {
167167
/* only used for poll queues: */
168168
spinlock_t cq_poll_lock ____cacheline_aligned_in_smp;
169169
volatile struct nvme_completion *cqes;
170-
struct blk_mq_tags **tags;
171170
dma_addr_t sq_dma_addr;
172171
dma_addr_t cq_dma_addr;
173172
u32 __iomem *q_db;
@@ -376,29 +375,17 @@ static int nvme_admin_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
376375

377376
WARN_ON(hctx_idx != 0);
378377
WARN_ON(dev->admin_tagset.tags[0] != hctx->tags);
379-
WARN_ON(nvmeq->tags);
380378

381379
hctx->driver_data = nvmeq;
382-
nvmeq->tags = &dev->admin_tagset.tags[0];
383380
return 0;
384381
}
385382

386-
static void nvme_admin_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int hctx_idx)
387-
{
388-
struct nvme_queue *nvmeq = hctx->driver_data;
389-
390-
nvmeq->tags = NULL;
391-
}
392-
393383
static int nvme_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
394384
unsigned int hctx_idx)
395385
{
396386
struct nvme_dev *dev = data;
397387
struct nvme_queue *nvmeq = &dev->queues[hctx_idx + 1];
398388

399-
if (!nvmeq->tags)
400-
nvmeq->tags = &dev->tagset.tags[hctx_idx];
401-
402389
WARN_ON(dev->tagset.tags[hctx_idx] != hctx->tags);
403390
hctx->driver_data = nvmeq;
404391
return 0;
@@ -948,6 +935,13 @@ static inline void nvme_ring_cq_doorbell(struct nvme_queue *nvmeq)
948935
writel(head, nvmeq->q_db + nvmeq->dev->db_stride);
949936
}
950937

938+
static inline struct blk_mq_tags *nvme_queue_tagset(struct nvme_queue *nvmeq)
939+
{
940+
if (!nvmeq->qid)
941+
return nvmeq->dev->admin_tagset.tags[0];
942+
return nvmeq->dev->tagset.tags[nvmeq->qid - 1];
943+
}
944+
951945
static inline void nvme_handle_cqe(struct nvme_queue *nvmeq, u16 idx)
952946
{
953947
volatile struct nvme_completion *cqe = &nvmeq->cqes[idx];
@@ -972,7 +966,7 @@ static inline void nvme_handle_cqe(struct nvme_queue *nvmeq, u16 idx)
972966
return;
973967
}
974968

975-
req = blk_mq_tag_to_rq(*nvmeq->tags, cqe->command_id);
969+
req = blk_mq_tag_to_rq(nvme_queue_tagset(nvmeq), cqe->command_id);
976970
trace_nvme_sq(req, cqe->sq_head, nvmeq->sq_tail);
977971
nvme_end_request(req, cqe->status, cqe->result);
978972
}
@@ -1572,7 +1566,6 @@ static const struct blk_mq_ops nvme_mq_admin_ops = {
15721566
.queue_rq = nvme_queue_rq,
15731567
.complete = nvme_pci_complete_rq,
15741568
.init_hctx = nvme_admin_init_hctx,
1575-
.exit_hctx = nvme_admin_exit_hctx,
15761569
.init_request = nvme_init_request,
15771570
.timeout = nvme_timeout,
15781571
};

0 commit comments

Comments
 (0)