nvmet pci-epf fixes
Subsystems (2)
v2 cover nvmet pci-epf fixes
Five patches to fix and improve IRQ handling in the PCI endpoint target driver. The issues fixed by the first 2 patches where discovered with testing with polling queues set on the host side. The following 2 patches are small improvements/cleanup in the same IRQ handling area. The last patch removes dead code.
Changes from v1:
- Fixed typos in patch 1 and 2
- Removed Fixes tag from patch 2 as a backport to 6.14 would lead to compilation errors
- Added Review tags to patch 3 and 4
- Added patch 5
Damien Le Moal (5):
nvmet: pci-epf: Clear completion queue IRQ flag on delete
nvmet: pci-epf: Do not fall back to using INTX if not supported
nvmet: pci-epf: Cleanup nvmet_pci_epf_raise_irq()
nvmet: pci-epf: Improve debug message
nvmet: pci-epf: Remove NVMET_PCI_EPF_Q_IS_SQ
drivers/nvme/target/pci-epf.c | 39 +++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-)
Signature · 1 line
2.49.0
PATCH v2 1/5 nvmet: pci-epf: Clear completion queue IRQ flag on delete
The function nvmet_pci_epf_delete_cq() unconditionally calls nvmet_pci_epf_remove_irq_vector() even for completion queues that do not have interrupts enabled. Furthermore, for completion queues that do have IRQ enabled, deleting and re-creating the completion queue leaves the flag NVMET_PCI_EPF_Q_IRQ_ENABLED set, even if the completion queue is being re-created with IRQ disabled.
Fix these issues by calling nvmet_pci_epf_remove_irq_vector() only if NVMET_PCI_EPF_Q_IRQ_ENABLED is set and make sure to always clear that flag.
--- drivers/nvme/target/pci-epf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/target/pci-epf.c +2 -1
@@ -1344,7 +1344,8 @@ static u16 nvmet_pci_epf_delete_cq(struct nvmet_ctrl *tctrl, u16 cqid)cancel_delayed_work_sync (&cq->work);nvmet_pci_epf_drain_queue (cq); -nvmet_pci_epf_remove_irq_vector (ctrl, cq->vector); +if (test_and_clear_bit (NVMET_PCI_EPF_Q_IRQ_ENABLED , &cq->flags)) +nvmet_pci_epf_remove_irq_vector (ctrl, cq->vector);nvmet_pci_epf_mem_unmap (ctrl->nvme_epf, &cq->pci_map);return NVME_SC_SUCCESS ;
Signature · 1 line
2.49.0
PATCH v2 2/5 nvmet: pci-epf: Do not fall back to using INTX if not supported
In reply to Damien Le MoalSome endpoint PCIe controllers do not support raising legacy INTX interrupts. This support is indicated by the intx_capable field of struct pci_epc_features. Modify nvmet_pci_epf_raise_irq() to not automatically fallback to trying raising an INTX interrupt after an MSI or MSI-X error if the controller does not support INTX.
--- drivers/nvme/target/pci-epf.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/nvme/target/pci-epf.c +7 -5
@@ -636,14 +636,16 @@ static void nvmet_pci_epf_raise_irq(struct nvmet_pci_epf_ctrl *ctrl,switch (nvme_epf->irq_type) {case PCI_IRQ_MSIX :case PCI_IRQ_MSI : +/* +* If we fail to raise an MSI or MSI-X interrupt, it is likely +* because the host is using legacy INTX IRQs (e.g. BIOS, +* grub), but we can fallback to the INTX type only if the +* endpoint controller supports this type. +*/ ret =pci_epc_raise_irq (epf->epc, epf->func_no, epf->vfunc_no, nvme_epf->irq_type, cq->vector +1 ); -if (!ret) +if (!ret || !nvme_epf->epc_features->intx_capable)break ; -/* -* If we got an error, it is likely because the host is using -* legacy IRQs (e.g. BIOS, grub). -*/ fallthrough;case PCI_IRQ_INTX : ret = pci_epc_raise_irq(epf->epc, epf->func_no, epf->vfunc_no,
Signature · 1 line
2.49.0
PATCH v2 3/5 nvmet: pci-epf: Cleanup nvmet_pci_epf_raise_irq()
In reply to Damien Le MoalThere is no point in taking the controller irq_lock and calling nvmet_pci_epf_should_raise_irq() for a completion queue which does not have IRQ enabled (NVMET_PCI_EPF_Q_IRQ_ENABLED flag is not set). Move the test for the NVMET_PCI_EPF_Q_IRQ_ENABLED flag out of nvmet_pci_epf_should_raise_irq() to the top of nvmet_pci_epf_raise_irq() to return early when no IRQ should be raised.
Also, use dev_err_ratelimited() to avoid a message storm under load when raising IRQs is failing.
--- drivers/nvme/target/pci-epf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/nvme/target/pci-epf.c +5 -5
@@ -596,9 +596,6 @@ static bool nvmet_pci_epf_should_raise_irq(struct nvmet_pci_epf_ctrl *ctrl,struct nvmet_pci_epf_irq_vector *iv = cq->iv;bool ret; -if (!test_bit (NVMET_PCI_EPF_Q_IRQ_ENABLED , &cq->flags)) -return false; -/* IRQ coalescing for the admin queue is not allowed. */ if (!cq->qid)return true;
@@ -625,7 +622,8 @@ static void nvmet_pci_epf_raise_irq(struct nvmet_pci_epf_ctrl *ctrl,struct pci_epf *epf = nvme_epf->epf;int ret =0 ; -if (!test_bit (NVMET_PCI_EPF_Q_LIVE , &cq->flags)) +if (!test_bit (NVMET_PCI_EPF_Q_LIVE , &cq->flags) || + !test_bit (NVMET_PCI_EPF_Q_IRQ_ENABLED , &cq->flags))return ;mutex_lock (&ctrl->irq_lock);
@@ -658,7 +656,9 @@ static void nvmet_pci_epf_raise_irq(struct nvmet_pci_epf_ctrl *ctrl, }if (ret) -dev_err (ctrl->dev,"Failed to raise IRQ (err=%d)\n" , ret); +dev_err_ratelimited (ctrl->dev, +"CQ[%u]: Failed to raise IRQ (err=%d)\n" , + cq->qid, ret); unlock:mutex_unlock (&ctrl->irq_lock);
Signature · 1 line
2.49.0
PATCH v2 4/5 nvmet: pci-epf: Improve debug message
In reply to Damien Le MoalImprove the debug message of nvmet_pci_epf_create_cq() to indicate if a completion queue IRQ is disabled.
--- drivers/nvme/target/pci-epf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/nvme/target/pci-epf.c +8 -2
@@ -1321,8 +1321,14 @@ static u16 nvmet_pci_epf_create_cq(struct nvmet_ctrl *tctrl,set_bit (NVMET_PCI_EPF_Q_LIVE , &cq->flags); -dev_dbg (ctrl->dev,"CQ[%u]: %u entries of %zu B, IRQ vector %u\n" , - cqid, qsize, cq->qes, cq->vector); +if (test_bit (NVMET_PCI_EPF_Q_IRQ_ENABLED , &cq->flags)) +dev_dbg (ctrl->dev, +"CQ[%u]: %u entries of %zu B, IRQ vector %u\n" , + cqid, qsize, cq->qes, cq->vector); +else +dev_dbg (ctrl->dev, +"CQ[%u]: %u entries of %zu B, IRQ disabled\n" , + cqid, qsize, cq->qes);return NVME_SC_SUCCESS ;
Signature · 1 line
2.49.0
PATCH v2 5/5 nvmet: pci-epf: Remove NVMET_PCI_EPF_Q_IS_SQ
In reply to Damien Le MoalThe flag NVMET_PCI_EPF_Q_IS_SQ is set but never used. Remove it.
--- drivers/nvme/target/pci-epf.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/nvme/target/pci-epf.c +1 -3
@@ -62,8 +62,7 @@ static DEFINE_MUTEX(nvmet_pci_epf_ports_mutex);#define NVMET_PCI_EPF_CQ_RETRY_INTERVAL msecs_to_jiffies(1)enum nvmet_pci_epf_queue_flags { -NVMET_PCI_EPF_Q_IS_SQ =0 ,/* The queue is a submission queue */ -NVMET_PCI_EPF_Q_LIVE ,/* The queue is live */ +NVMET_PCI_EPF_Q_LIVE =0 ,/* The queue is live */ NVMET_PCI_EPF_Q_IRQ_ENABLED ,/* IRQ is enabled for this queue */ };
@@ -1542,7 +1541,6 @@ static void nvmet_pci_epf_init_queue(struct nvmet_pci_epf_ctrl *ctrl,if (sq) { queue = &ctrl->sq[qid]; -set_bit (NVMET_PCI_EPF_Q_IS_SQ , &queue->flags); }else { queue = &ctrl->cq[qid];INIT_DELAYED_WORK (&queue->work, nvmet_pci_epf_cq_work);
Signature · 1 line
2.49.0
Thanks,
applied to nvme-6.15.