Skip to contentSkip to conversation

nvme: always return IRQ_HANDLED

RFC PATCH In review Jens Axboe 3 participants 6 messages Aug 17, 2017 – Aug 18, 2017

Subsystems (2)
lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

RFC PATCH 1/1 nvme: always return IRQ_HANDLED

We currently have an issue with nvme when polling is used. Just ran some testing on 4.13-rc5, and it's trivial to trigger an IRQ disable ala:

[   52.412851] irq 77: nobody cared (try booting with the "irqpoll" option)
[   52.415310] irq 70: nobody cared (try booting with the "irqpoll" option)

when running a few processes polling. The reason is pretty obvious - if we're effective at polling, the triggered IRQ will never find any events. If this happens enough times in a row, the kernel disables our IRQ since we keep returning IRQ_NONE.

Question is, what's the best way to solve this. Ideally we should not be triggering an IRQ at all, but that's still not in mainline. Can we safely just return IRQ_HANDLED always? That should work except for the case where we happen to run into an IRQ flood where DO want to turn off the nvme irq. For now, I think that's small price to pay, since the current issue is much worse and leaves the device in a weird non-working state where some queue interrupts are turned off.

drivers/nvme/host/pci.c +4 -8
index 74a124a06264..21a35faff86f 100644
@@ -160,7 +160,6 @@ struct nvme_queue {
 	u16 cq_head;
 	u16 qid;
 	u8 cq_phase;
-	u8 cqe_seen;
 	u32 *dbbuf_sq_db;
 	u32 *dbbuf_cq_db;
 	u32 *dbbuf_sq_ei;
@@ -830,22 +829,19 @@ static void nvme_process_cq(struct nvme_queue *nvmeq)
 		consumed++;
 	}
 
-	if (consumed) {
+	if (consumed)
 		nvme_ring_cq_doorbell(nvmeq);
-		nvmeq->cqe_seen = 1;
-	}
 }
 
 static irqreturn_t nvme_irq(int irq, void *data)
 {
-	irqreturn_t result;
 	struct nvme_queue *nvmeq = data;
+
 	spin_lock(&nvmeq->q_lock);
 	nvme_process_cq(nvmeq);
-	result = nvmeq->cqe_seen ? IRQ_HANDLED : IRQ_NONE;
-	nvmeq->cqe_seen = 0;
 	spin_unlock(&nvmeq->q_lock);
-	return result;
+
+	return IRQ_HANDLED;
 }
 
 static irqreturn_t nvme_irq_check(int irq, void *data)
Signature · 1 line
Jens Axboe
#1 lore raw
Quoted 11 lines · Jens Axboe

We currently have an issue with nvme when polling is used. Just ran some testing on 4.13-rc5, and it's trivial to trigger an IRQ disable ala:

[   52.412851] irq 77: nobody cared (try booting with the "irqpoll" option)
[   52.415310] irq 70: nobody cared (try booting with the "irqpoll" option)

when running a few processes polling. The reason is pretty obvious - if we're effective at polling, the triggered IRQ will never find any events. If this happens enough times in a row, the kernel disables our IRQ since we keep returning IRQ_NONE.

If you're seeing IRQ_NONE returned, the NVMe driver didn't poll any completions since the last time nvme_irq was called. The cqe_seen on polled compeletions is sticky until the IRQ handler is run, in which case it returns IRQ_HANDLED even when no completions were handled during that interrupt.

The only way it should be able to return IRQ_NONE is if no completions were observed (polled or otherwise) since the last time the IRQ handler was called.

Quoted 7 lines

Question is, what's the best way to solve this. Ideally we should not be triggering an IRQ at all, but that's still not in mainline. Can we safely just return IRQ_HANDLED always? That should work except for the case where we happen to run into an IRQ flood where DO want to turn off the nvme irq. For now, I think that's small price to pay, since the current issue is much worse and leaves the device in a weird non-working state where some queue interrupts are turned off.

My recommended way to get this handled is to enable interrupt coalescing and have controllers behave as the specification describes to suppress interrupts when polling is active. From section 5.21.1.8:

Specifically, if the Completion Queue Head Doorbell register is being updated that is associated with a particular interrupt vector, then the controller has a positive indication that completion queue entries are already being processed. In this case, the aggregation time and/or the aggregation threshold may be reset/restarted upon the associated register write. This may result in interrupts being delayed indefinitely in certain workloads where the aggregation time or aggregation threshold is non-zero.

Quoted 44 lines
drivers/nvme/host/pci.c +4 -8
index 74a124a06264..21a35faff86f 100644
@@ -160,7 +160,6 @@ struct nvme_queue {
 	u16 cq_head;
 	u16 qid;
 	u8 cq_phase;
-	u8 cqe_seen;
 	u32 *dbbuf_sq_db;
 	u32 *dbbuf_cq_db;
 	u32 *dbbuf_sq_ei;
@@ -830,22 +829,19 @@ static void nvme_process_cq(struct nvme_queue *nvmeq)
 		consumed++;
 	}
 
-	if (consumed) {
+	if (consumed)
 		nvme_ring_cq_doorbell(nvmeq);
-		nvmeq->cqe_seen = 1;
-	}
 }
 
 static irqreturn_t nvme_irq(int irq, void *data)
 {
-	irqreturn_t result;
 	struct nvme_queue *nvmeq = data;
+
 	spin_lock(&nvmeq->q_lock);
 	nvme_process_cq(nvmeq);
-	result = nvmeq->cqe_seen ? IRQ_HANDLED : IRQ_NONE;
-	nvmeq->cqe_seen = 0;
 	spin_unlock(&nvmeq->q_lock);
-	return result;
+
+	return IRQ_HANDLED;
 }
 
 static irqreturn_t nvme_irq_check(int irq, void *data)
Signature · 2 lines
-- 
Jens Axboe
author maintainer
#2 lore raw
Quoted 19 lines · Keith Busch
Quoted 11 lines · Jens Axboe

We currently have an issue with nvme when polling is used. Just ran some testing on 4.13-rc5, and it's trivial to trigger an IRQ disable ala:

[   52.412851] irq 77: nobody cared (try booting with the "irqpoll" option)
[   52.415310] irq 70: nobody cared (try booting with the "irqpoll" option)

when running a few processes polling. The reason is pretty obvious - if we're effective at polling, the triggered IRQ will never find any events. If this happens enough times in a row, the kernel disables our IRQ since we keep returning IRQ_NONE.

If you're seeing IRQ_NONE returned, the NVMe driver didn't poll any completions since the last time nvme_irq was called. The cqe_seen on polled compeletions is sticky until the IRQ handler is run, in which case it returns IRQ_HANDLED even when no completions were handled during that interrupt.

Quoted 3 lines

The only way it should be able to return IRQ_NONE is if no completions were observed (polled or otherwise) since the last time the IRQ handler was called.

The polling do not update the cqe_seen. So it's possible that every time the IRQ handler does trigger, there are no entries found. Maybe a better or simpler fix would be to have the polling set cqe_seen to true, and leave the clearing to the interrupt handler as is done now.

Quoted 12 lines
Quoted 7 lines

Question is, what's the best way to solve this. Ideally we should not be triggering an IRQ at all, but that's still not in mainline. Can we safely just return IRQ_HANDLED always? That should work except for the case where we happen to run into an IRQ flood where DO want to turn off the nvme irq. For now, I think that's small price to pay, since the current issue is much worse and leaves the device in a weird non-working state where some queue interrupts are turned off.

My recommended way to get this handled is to enable interrupt coalescing and have controllers behave as the specification describes to suppress interrupts when polling is active. From section 5.21.1.8:

Quoted 8 lines

Specifically, if the Completion Queue Head Doorbell register is being updated that is associated with a particular interrupt vector, then the controller has a positive indication that completion queue entries are already being processed. In this case, the aggregation time and/or the aggregation threshold may be reset/restarted upon the associated register write. This may result in interrupts being delayed indefinitely in certain workloads where the aggregation time or aggregation threshold is non-zero.

That would indeed be much better, and not require is to fiddle with IRQ less completion queues for more efficient polling. Of the test devices that I do use, not all of them support coalescing, and of the ones that do, some of them implement it in a pretty poor fashion.

Signature · 1 line
Jens Axboe
author maintainer
#4 lore raw
In reply to Keith Busch
Quoted 25 lines · Keith Busch
Quoted 24 lines · Jens Axboe
Quoted 22 lines · Keith Busch
Quoted 11 lines · Jens Axboe

We currently have an issue with nvme when polling is used. Just ran some testing on 4.13-rc5, and it's trivial to trigger an IRQ disable ala:

[   52.412851] irq 77: nobody cared (try booting with the "irqpoll" option)
[   52.415310] irq 70: nobody cared (try booting with the "irqpoll" option)

when running a few processes polling. The reason is pretty obvious - if we're effective at polling, the triggered IRQ will never find any events. If this happens enough times in a row, the kernel disables our IRQ since we keep returning IRQ_NONE.

If you're seeing IRQ_NONE returned, the NVMe driver didn't poll any completions since the last time nvme_irq was called. The cqe_seen on polled compeletions is sticky until the IRQ handler is run, in which case it returns IRQ_HANDLED even when no completions were handled during that interrupt.

The only way it should be able to return IRQ_NONE is if no completions were observed (polled or otherwise) since the last time the IRQ handler was called.

Quoted 8 lines
Quoted 4 lines

The polling do not update the cqe_seen. So it's possible that every time the IRQ handler does trigger, there are no entries found. Maybe a better or simpler fix would be to have the polling set cqe_seen to true, and leave the clearing to the interrupt handler as is done now.

Oops, that looks like a mistake. I don't think we want to suppress spurious interrupt detection, though. How about this patch to set cq_seen on polling like we used to have?

Yes, that will work. We need to get this into 4.13.

Signature · 1 line
Jens Axboe
#3 lore raw
In reply to Jens Axboe
Quoted 20 lines · Jens Axboe
Quoted 19 lines · Keith Busch
Quoted 11 lines · Jens Axboe

We currently have an issue with nvme when polling is used. Just ran some testing on 4.13-rc5, and it's trivial to trigger an IRQ disable ala:

[   52.412851] irq 77: nobody cared (try booting with the "irqpoll" option)
[   52.415310] irq 70: nobody cared (try booting with the "irqpoll" option)

when running a few processes polling. The reason is pretty obvious - if we're effective at polling, the triggered IRQ will never find any events. If this happens enough times in a row, the kernel disables our IRQ since we keep returning IRQ_NONE.

If you're seeing IRQ_NONE returned, the NVMe driver didn't poll any completions since the last time nvme_irq was called. The cqe_seen on polled compeletions is sticky until the IRQ handler is run, in which case it returns IRQ_HANDLED even when no completions were handled during that interrupt.

Quoted 8 lines
Quoted 3 lines

The only way it should be able to return IRQ_NONE is if no completions were observed (polled or otherwise) since the last time the IRQ handler was called.

The polling do not update the cqe_seen. So it's possible that every time the IRQ handler does trigger, there are no entries found. Maybe a better or simpler fix would be to have the polling set cqe_seen to true, and leave the clearing to the interrupt handler as is done now.

Oops, that looks like a mistake. I don't think we want to suppress spurious interrupt detection, though. How about this patch to set cq_seen on polling like we used to have?

Fixes 920d13a884 ("nvme-pci: factor out the cqe reading mechanics from __nvme_process_cq")

---

drivers/nvme/host/pci.c +2 -3
index ea5eb4c..e9886e1 100644
@@ -795,6 +795,7 @@ static inline void nvme_handle_cqe(struct nvme_queue *nvmeq,
 		return;
 	}
 
+	nvmeq->cqe_seen = 1;
 	req = blk_mq_tag_to_rq(*nvmeq->tags, cqe->command_id);
 	nvme_end_request(req, cqe->status, cqe->result);
 }
@@ -824,10 +825,8 @@ static void nvme_process_cq(struct nvme_queue *nvmeq)
 		consumed++;
 	}
 
-	if (consumed) {
+	if (consumed)
 		nvme_ring_cq_doorbell(nvmeq);
-		nvmeq->cqe_seen = 1;
-	}
 }
 
 static irqreturn_t nvme_irq(int irq, void *data)

--