mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ziyu Zhang <ziyuzhang201@gmail.com>
To: vinicius.gomes@intel.com, vkoul@kernel.org
Cc: dave.jiang@intel.com, Frank.Li@kernel.org, kevin.tian@intel.com,
	dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
	baijiaju1990@gmail.com, ziyuzhang201@gmail.com
Subject: [PATCH v2] dmaengine: idxd: Fix deadlock on interrupt handle revocation
Date: Wed, 25 Nov 2026 21:31:23 +0800	[thread overview]
Message-ID: <20261125133123.98687-1-ziyuzhang201@gmail.com> (raw)

idxd_misc_thread() handles the misc MSI-X vector and completes device
commands when IDXD_INTC_CMD is set. On an IDXD_INTC_INT_HANDLE_REVOKED
interrupt, it allocates a work item with GFP_ATOMIC. If that allocation
fails, it calls idxd_wqs_quiesce() inline. This takes wq_lock for each
enabled kernel work queue and can block behind a command submitter
holding that lock while waiting for cmd_done. The misc thread cannot
complete the command while blocked on the lock, resulting in a deadlock.

This potential deadlock was found by our experimental static analysis
tool, which analyzes lock usage and completion-based synchronization.

Embed the work item in struct idxd_device and queue it asynchronously,
removing the allocation and its synchronous quiesce fallback.

Revokes received while the work is pending are coalesced; the queued
work refreshes all valid interrupt handles. A revoke received while the
work is running can queue another execution to refresh handles that
have already been processed. Reusing the same work item on the same
workqueue also serialises revoke handling.

Initialize the work once in idxd_setup_internals(), since interrupt
setup runs again during FLR recovery. During interrupt cleanup, block
new revoke enqueues and synchronize the misc IRQ before cancelling the
work. This accounts for IRQ handlers that have already passed the stop
check. Cancel the work before releasing the misc IRQ so that the IRQ
handler remains available for command completions while waiting for a
running work item to finish.

Fixes: 56fc39f5a367 ("dmaengine: idxd: handle interrupt handle revoked event")
Signed-off-by: Ziyu Zhang <ziyuzhang201@gmail.com>
---
Changes in v2:
- Initialize the embedded work once, rather than on each interrupt setup.
- Stop new enqueues and synchronize the misc IRQ before cancelling work.
- Cancel revoke work before freeing the misc IRQ.

v1: https://lore.kernel.org/r/20261125113553.94215-1-ziyuzhang201@gmail.com

 drivers/dma/idxd/idxd.h |  3 +++
 drivers/dma/idxd/init.c | 10 ++++++++++
 drivers/dma/idxd/irq.c  | 28 +++++-----------------------
 3 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h
index ce78b9a7c641..88921f07b439 100644
--- a/drivers/dma/idxd/idxd.h
+++ b/drivers/dma/idxd/idxd.h
@@ -366,6 +366,8 @@ struct idxd_device {
 	struct idxd_dma_dev *idxd_dma;
 	struct workqueue_struct *wq;
 	struct work_struct work;
+	struct work_struct int_handle_revoke_work;
+	bool int_handle_revoke_stop;
 
 	struct idxd_pmu *idxd_pmu;
 
@@ -762,6 +764,7 @@ int idxd_load_iaa_device_defaults(struct idxd_device *idxd);
 
 /* device interrupt control */
 irqreturn_t idxd_misc_thread(int vec, void *data);
+void idxd_int_handle_revoke(struct work_struct *work);
 irqreturn_t idxd_wq_thread(int irq, void *data);
 void idxd_mask_error_interrupts(struct idxd_device *idxd);
 void idxd_unmask_error_interrupts(struct idxd_device *idxd);
diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index 4b827a329756..620de170ff18 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -153,8 +153,16 @@ static void idxd_cleanup_interrupts(struct idxd_device *idxd)
 
 	ie = idxd_get_ie(idxd, 0);
 	idxd_mask_error_interrupts(idxd);
+
+	/* Drain IRQ enqueues before cancelling work, keeping command IRQs live. */
+	WRITE_ONCE(idxd->int_handle_revoke_stop, true);
+	synchronize_irq(ie->vector);
+	cancel_work_sync(&idxd->int_handle_revoke_work);
+
 	free_irq(ie->vector, ie);
 	pci_free_irq_vectors(pdev);
+
+	WRITE_ONCE(idxd->int_handle_revoke_stop, false);
 }
 
 static void idxd_clean_wqs(struct idxd_device *idxd)
@@ -433,6 +441,8 @@ static int idxd_setup_internals(struct idxd_device *idxd)
 	int rc;
 
 	init_waitqueue_head(&idxd->cmd_waitq);
+	/* Once per device: idxd_setup_interrupts() runs again after FLR */
+	INIT_WORK(&idxd->int_handle_revoke_work, idxd_int_handle_revoke);
 
 	rc = idxd_setup_wqs(idxd);
 	if (rc < 0)
diff --git a/drivers/dma/idxd/irq.c b/drivers/dma/idxd/irq.c
index 6a25e1fd0e62..26b06a47680a 100644
--- a/drivers/dma/idxd/irq.c
+++ b/drivers/dma/idxd/irq.c
@@ -24,11 +24,6 @@ struct idxd_resubmit {
 	struct idxd_desc *desc;
 };
 
-struct idxd_int_handle_revoke {
-	struct work_struct work;
-	struct idxd_device *idxd;
-};
-
 static void idxd_device_reinit(struct work_struct *work)
 {
 	struct idxd_device *idxd = container_of(work, struct idxd_device, work);
@@ -127,17 +122,15 @@ static void idxd_abort_invalid_int_handle_descs(struct idxd_irq_entry *ie)
 	}
 }
 
-static void idxd_int_handle_revoke(struct work_struct *work)
+void idxd_int_handle_revoke(struct work_struct *work)
 {
-	struct idxd_int_handle_revoke *revoke =
-		container_of(work, struct idxd_int_handle_revoke, work);
-	struct idxd_device *idxd = revoke->idxd;
+	struct idxd_device *idxd =
+		container_of(work, struct idxd_device, int_handle_revoke_work);
 	struct pci_dev *pdev = idxd->pdev;
 	struct device *dev = &pdev->dev;
 	int i, new_handle, rc;
 
 	if (!idxd->request_int_handles) {
-		kfree(revoke);
 		dev_warn(dev, "Unexpected int handle refresh interrupt.\n");
 		return;
 	}
@@ -216,7 +209,6 @@ static void idxd_int_handle_revoke(struct work_struct *work)
 			udelay(100);
 		idxd_int_handle_revoke_drain(ie);
 	}
-	kfree(revoke);
 }
 
 static void idxd_evl_fault_work(struct work_struct *work)
@@ -504,20 +496,10 @@ irqreturn_t idxd_misc_thread(int vec, void *data)
 	}
 
 	if (cause & IDXD_INTC_INT_HANDLE_REVOKED) {
-		struct idxd_int_handle_revoke *revoke;
-
 		val |= IDXD_INTC_INT_HANDLE_REVOKED;
 
-		revoke = kzalloc_obj(*revoke, GFP_ATOMIC);
-		if (revoke) {
-			revoke->idxd = idxd;
-			INIT_WORK(&revoke->work, idxd_int_handle_revoke);
-			queue_work(idxd->wq, &revoke->work);
-
-		} else {
-			dev_err(dev, "Failed to allocate work for int handle revoke\n");
-			idxd_wqs_quiesce(idxd);
-		}
+		if (!READ_ONCE(idxd->int_handle_revoke_stop))
+			queue_work(idxd->wq, &idxd->int_handle_revoke_work);
 	}
 
 	if (cause & IDXD_INTC_CMD) {
-- 
2.34.1


                 reply	other threads:[~2026-11-25 13:32 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=20261125133123.98687-1-ziyuzhang201@gmail.com \
    --to=ziyuzhang201@gmail.com \
    --cc=Frank.Li@kernel.org \
    --cc=baijiaju1990@gmail.com \
    --cc=dave.jiang@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vinicius.gomes@intel.com \
    --cc=vkoul@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®