Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH] RDMA/erdma: free common IRQ before destroying CMDQ and AEQ
@ 2026-12-06  8:40 Ziheng Wei
  2026-12-06  8:56 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Ziheng Wei @ 2026-12-06  8:40 UTC (permalink / raw)
  To: Cheng Xu, Kai Shen, Jason Gunthorpe, Leon Romanovsky
  Cc: linux-rdma, linux-kernel, stable

erdma_remove_dev() and the error unwind path of erdma_probe_dev() call
erdma_cmdq_destroy() and erdma_eq_destroy(dev, &dev->aeq) before
erdma_comm_irq_uninit().  Because erdma_hw_reset() does not wait for an
already in-flight erdma_comm_irq_handler() to finish, freeing the CMDQ
and AEQ DMA rings before free_irq() can cause a use-after-free in
erdma_cmdq_completion_handler() or erdma_aeq_event_handler().

Similarly, erdma_probe_dev() requests the common IRQ before initializing
the AEQ and CMDQ.

Request the common IRQ after initializing the AEQ and CMDQ, and call
erdma_comm_irq_uninit() before destroying the CMDQ and AEQ in both
erdma_probe_dev() error unwind and erdma_remove_dev().

Found by LLM-assisted static analysis. Compile-tested on x86_64.

Fixes: d55e6fb4803c ("RDMA/erdma: Add the erdma module")
Cc: stable@vger.kernel.org
Signed-off-by: Ziheng Wei <zihengw03@163.com>
---
 drivers/infiniband/hw/erdma/erdma_main.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/infiniband/hw/erdma/erdma_main.c b/drivers/infiniband/hw/erdma/erdma_main.c
index 62dc22388..49dd79e7f 100644
--- a/drivers/infiniband/hw/erdma/erdma_main.c
+++ b/drivers/infiniband/hw/erdma/erdma_main.c
@@ -295,22 +295,22 @@ static int erdma_probe_dev(struct pci_dev *pdev)
 	if (err)
 		goto err_uninit_device;
 
-	err = erdma_comm_irq_init(dev);
-	if (err)
-		goto err_free_vectors;
-
 	err = erdma_aeq_init(dev);
 	if (err)
-		goto err_uninit_comm_irq;
+		goto err_free_vectors;
 
 	err = erdma_cmdq_init(dev);
 	if (err)
 		goto err_uninit_aeq;
 
-	err = erdma_wait_hw_init_done(dev);
+	err = erdma_comm_irq_init(dev);
 	if (err)
 		goto err_uninit_cmdq;
 
+	err = erdma_wait_hw_init_done(dev);
+	if (err)
+		goto err_uninit_comm_irq;
+
 	err = erdma_ceqs_init(dev);
 	if (err)
 		goto err_reset_hw;
@@ -322,15 +322,15 @@ static int erdma_probe_dev(struct pci_dev *pdev)
 err_reset_hw:
 	erdma_hw_reset(dev);
 
+err_uninit_comm_irq:
+	erdma_comm_irq_uninit(dev);
+
 err_uninit_cmdq:
 	erdma_cmdq_destroy(dev);
 
 err_uninit_aeq:
 	erdma_eq_destroy(dev, &dev->aeq);
 
-err_uninit_comm_irq:
-	erdma_comm_irq_uninit(dev);
-
 err_free_vectors:
 	pci_free_irq_vectors(dev->pdev);
 
@@ -358,9 +358,9 @@ static void erdma_remove_dev(struct pci_dev *pdev)
 
 	erdma_ceqs_uninit(dev);
 	erdma_hw_reset(dev);
+	erdma_comm_irq_uninit(dev);
 	erdma_cmdq_destroy(dev);
 	erdma_eq_destroy(dev, &dev->aeq);
-	erdma_comm_irq_uninit(dev);
 	pci_free_irq_vectors(dev->pdev);
 	erdma_device_uninit(dev);
 

base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] RDMA/erdma: free common IRQ before destroying CMDQ and AEQ
  2026-12-06  8:40 [PATCH] RDMA/erdma: free common IRQ before destroying CMDQ and AEQ Ziheng Wei
@ 2026-12-06  8:56 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-06  8:56 UTC (permalink / raw)
  To: Ziheng Wei; +Cc: linux-rdma

> erdma_remove_dev() and the error unwind path of erdma_probe_dev() call
> erdma_cmdq_destroy() and erdma_eq_destroy(dev, &dev->aeq) before
> erdma_comm_irq_uninit().  Because erdma_hw_reset() does not wait for an
> already in-flight erdma_comm_irq_handler() to finish, freeing the CMDQ
> and AEQ DMA rings before free_irq() can cause a use-after-free in
> erdma_cmdq_completion_handler() or erdma_aeq_event_handler().
> 
> Similarly, erdma_probe_dev() requests the common IRQ before initializing
> the AEQ and CMDQ.
> 
> Request the common IRQ after initializing the AEQ and CMDQ, and call
> erdma_comm_irq_uninit() before destroying the CMDQ and AEQ in both
> erdma_probe_dev() error unwind and erdma_remove_dev().
> 
> Found by LLM-assisted static analysis. Compile-tested on x86_64.
> 
> Fixes: d55e6fb4803c ("RDMA/erdma: Add the erdma module")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ziheng Wei <zihengw03@163.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206084019.4331-1-zihengw03@163.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-06  8:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06  8:40 [PATCH] RDMA/erdma: free common IRQ before destroying CMDQ and AEQ Ziheng Wei
2026-12-06  8:56 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox