mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ziheng Wei <zihengw03@163.com>
To: Cheng Xu <chengyou@linux.alibaba.com>,
	Kai Shen <kaishen@linux.alibaba.com>,
	Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>
Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH] RDMA/erdma: free common IRQ before destroying CMDQ and AEQ
Date: Sun,  6 Dec 2026 16:40:19 +0800	[thread overview]
Message-ID: <20261206084019.4331-1-zihengw03@163.com> (raw)

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


                 reply	other threads:[~2026-12-06  8:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261206084019.4331-1-zihengw03@163.com \
    --to=zihengw03@163.com \
    --cc=chengyou@linux.alibaba.com \
    --cc=jgg@ziepe.ca \
    --cc=kaishen@linux.alibaba.com \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®