Skip to content

Commit a8de663

Browse files
Alexey Dobriyanaxboe
authored andcommitted
nvme-pci: fix "slimmer CQ head update"
Pre-incrementing ->cq_head can't be done in memory because OOB value can be observed by another context. This devalues space savings compared to original code :-\ $ ./scripts/bloat-o-meter ../vmlinux-000 ../obj/vmlinux add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-32 (-32) Function old new delta nvme_poll_irqdisable 464 456 -8 nvme_poll 455 447 -8 nvme_irq 388 380 -8 nvme_dev_disable 955 947 -8 But the code is minimal now: one read for head, one read for q_depth, one increment, one comparison, single instruction phase bit update and one write for new head. Signed-off-by: Alexey Dobriyan <[email protected]> Reported-by: John Garry <[email protected]> Tested-by: John Garry <[email protected]> Fixes: e2a366a ("nvme-pci: slimmer CQ head update") Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 6bd87ee commit a8de663

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/nvme/host/pci.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,13 @@ static inline void nvme_handle_cqe(struct nvme_queue *nvmeq, u16 idx)
973973

974974
static inline void nvme_update_cq_head(struct nvme_queue *nvmeq)
975975
{
976-
if (++nvmeq->cq_head == nvmeq->q_depth) {
976+
u16 tmp = nvmeq->cq_head + 1;
977+
978+
if (tmp == nvmeq->q_depth) {
977979
nvmeq->cq_head = 0;
978980
nvmeq->cq_phase ^= 1;
981+
} else {
982+
nvmeq->cq_head = tmp;
979983
}
980984
}
981985

0 commit comments

Comments
 (0)