Skip to content

Commit 1ab0cd6

Browse files
axboeKeith Busch
authored andcommitted
nvme-pci: split the nvme queue lock into submission and completion locks
This is now feasible. We protect the submission queue ring with ->sq_lock, and the completion side with ->cq_lock. Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 5cb525c commit 1ab0cd6

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

drivers/nvme/host/pci.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,10 @@ static inline struct nvme_dev *to_nvme_dev(struct nvme_ctrl *ctrl)
147147
struct nvme_queue {
148148
struct device *q_dmadev;
149149
struct nvme_dev *dev;
150-
spinlock_t q_lock;
150+
spinlock_t sq_lock;
151151
struct nvme_command *sq_cmds;
152152
struct nvme_command __iomem *sq_cmds_io;
153+
spinlock_t cq_lock ____cacheline_aligned_in_smp;
153154
volatile struct nvme_completion *cqes;
154155
struct blk_mq_tags **tags;
155156
dma_addr_t sq_dma_addr;
@@ -894,9 +895,9 @@ static blk_status_t nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
894895

895896
blk_mq_start_request(req);
896897

897-
spin_lock_irq(&nvmeq->q_lock);
898+
spin_lock_irq(&nvmeq->sq_lock);
898899
__nvme_submit_cmd(nvmeq, &cmnd);
899-
spin_unlock_irq(&nvmeq->q_lock);
900+
spin_unlock_irq(&nvmeq->sq_lock);
900901
return BLK_STS_OK;
901902
out_cleanup_iod:
902903
nvme_free_iod(dev, req);
@@ -1000,9 +1001,9 @@ static irqreturn_t nvme_irq(int irq, void *data)
10001001
struct nvme_queue *nvmeq = data;
10011002
u16 start, end;
10021003

1003-
spin_lock(&nvmeq->q_lock);
1004+
spin_lock(&nvmeq->cq_lock);
10041005
nvme_process_cq(nvmeq, &start, &end, -1);
1005-
spin_unlock(&nvmeq->q_lock);
1006+
spin_unlock(&nvmeq->cq_lock);
10061007

10071008
if (start == end)
10081009
return IRQ_NONE;
@@ -1026,9 +1027,9 @@ static int __nvme_poll(struct nvme_queue *nvmeq, unsigned int tag)
10261027
if (!nvme_cqe_pending(nvmeq))
10271028
return 0;
10281029

1029-
spin_lock_irq(&nvmeq->q_lock);
1030+
spin_lock_irq(&nvmeq->cq_lock);
10301031
found = nvme_process_cq(nvmeq, &start, &end, tag);
1031-
spin_unlock_irq(&nvmeq->q_lock);
1032+
spin_unlock_irq(&nvmeq->cq_lock);
10321033

10331034
nvme_complete_cqes(nvmeq, start, end);
10341035
return found;
@@ -1051,9 +1052,9 @@ static void nvme_pci_submit_async_event(struct nvme_ctrl *ctrl)
10511052
c.common.opcode = nvme_admin_async_event;
10521053
c.common.command_id = NVME_AQ_BLK_MQ_DEPTH;
10531054

1054-
spin_lock_irq(&nvmeq->q_lock);
1055+
spin_lock_irq(&nvmeq->sq_lock);
10551056
__nvme_submit_cmd(nvmeq, &c);
1056-
spin_unlock_irq(&nvmeq->q_lock);
1057+
spin_unlock_irq(&nvmeq->sq_lock);
10571058
}
10581059

10591060
static int adapter_delete_queue(struct nvme_dev *dev, u8 opcode, u16 id)
@@ -1310,15 +1311,15 @@ static int nvme_suspend_queue(struct nvme_queue *nvmeq)
13101311
{
13111312
int vector;
13121313

1313-
spin_lock_irq(&nvmeq->q_lock);
1314+
spin_lock_irq(&nvmeq->cq_lock);
13141315
if (nvmeq->cq_vector == -1) {
1315-
spin_unlock_irq(&nvmeq->q_lock);
1316+
spin_unlock_irq(&nvmeq->cq_lock);
13161317
return 1;
13171318
}
13181319
vector = nvmeq->cq_vector;
13191320
nvmeq->dev->online_queues--;
13201321
nvmeq->cq_vector = -1;
1321-
spin_unlock_irq(&nvmeq->q_lock);
1322+
spin_unlock_irq(&nvmeq->cq_lock);
13221323

13231324
/*
13241325
* Ensure that nvme_queue_rq() sees it ->cq_vector == -1 without
@@ -1344,9 +1345,9 @@ static void nvme_disable_admin_queue(struct nvme_dev *dev, bool shutdown)
13441345
else
13451346
nvme_disable_ctrl(&dev->ctrl, dev->ctrl.cap);
13461347

1347-
spin_lock_irq(&nvmeq->q_lock);
1348+
spin_lock_irq(&nvmeq->cq_lock);
13481349
nvme_process_cq(nvmeq, &start, &end, -1);
1349-
spin_unlock_irq(&nvmeq->q_lock);
1350+
spin_unlock_irq(&nvmeq->cq_lock);
13501351

13511352
nvme_complete_cqes(nvmeq, start, end);
13521353
}
@@ -1406,7 +1407,8 @@ static int nvme_alloc_queue(struct nvme_dev *dev, int qid, int depth)
14061407

14071408
nvmeq->q_dmadev = dev->dev;
14081409
nvmeq->dev = dev;
1409-
spin_lock_init(&nvmeq->q_lock);
1410+
spin_lock_init(&nvmeq->sq_lock);
1411+
spin_lock_init(&nvmeq->cq_lock);
14101412
nvmeq->cq_head = 0;
14111413
nvmeq->cq_phase = 1;
14121414
nvmeq->q_db = &dev->dbs[qid * 2 * dev->db_stride];
@@ -1442,15 +1444,15 @@ static void nvme_init_queue(struct nvme_queue *nvmeq, u16 qid)
14421444
{
14431445
struct nvme_dev *dev = nvmeq->dev;
14441446

1445-
spin_lock_irq(&nvmeq->q_lock);
1447+
spin_lock_irq(&nvmeq->cq_lock);
14461448
nvmeq->sq_tail = 0;
14471449
nvmeq->cq_head = 0;
14481450
nvmeq->cq_phase = 1;
14491451
nvmeq->q_db = &dev->dbs[qid * 2 * dev->db_stride];
14501452
memset((void *)nvmeq->cqes, 0, CQ_SIZE(nvmeq->q_depth));
14511453
nvme_dbbuf_init(dev, nvmeq, qid);
14521454
dev->online_queues++;
1453-
spin_unlock_irq(&nvmeq->q_lock);
1455+
spin_unlock_irq(&nvmeq->cq_lock);
14541456
}
14551457

14561458
static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)
@@ -2001,14 +2003,14 @@ static void nvme_del_cq_end(struct request *req, blk_status_t error)
20012003
unsigned long flags;
20022004

20032005
/*
2004-
* We might be called with the AQ q_lock held
2005-
* and the I/O queue q_lock should always
2006+
* We might be called with the AQ cq_lock held
2007+
* and the I/O queue cq_lock should always
20062008
* nest inside the AQ one.
20072009
*/
2008-
spin_lock_irqsave_nested(&nvmeq->q_lock, flags,
2010+
spin_lock_irqsave_nested(&nvmeq->cq_lock, flags,
20092011
SINGLE_DEPTH_NESTING);
20102012
nvme_process_cq(nvmeq, &start, &end, -1);
2011-
spin_unlock_irqrestore(&nvmeq->q_lock, flags);
2013+
spin_unlock_irqrestore(&nvmeq->cq_lock, flags);
20122014

20132015
nvme_complete_cqes(nvmeq, start, end);
20142016
}

0 commit comments

Comments
 (0)