mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Byrne <daniel1.byrne@intel.com>
To: Vinod Koul <vkoul@kernel.org>, dmaengine@vger.kernel.org
Cc: Vinicius Costa Gomes <vinicius.gomes@intel.com>,
	Dave Jiang <dave.jiang@intel.com>, Frank Li <Frank.Li@kernel.org>,
	Fenghua Yu <fenghuay@nvidia.com>, Dan Williams <djbw@kernel.org>,
	linux-kernel@vger.kernel.org,
	Daniel Byrne <daniel1.byrne@intel.com>,
	stable@vger.kernel.org
Subject: [PATCH v2 10/10] dmaengine: idxd: test a queue under its lock before quiescing it
Date: Mon, 30 Nov 2026 11:47:21 -0800	[thread overview]
Message-ID: <20261130194721.1900266-11-daniel1.byrne@intel.com> (raw)
In-Reply-To: <20261130194721.1900266-1-daniel1.byrne@intel.com>

idxd_wqs_quiesce() tests a queue's state and type without wq_lock and
takes the lock only for the quiesce itself. The enable and the disable
of a queue run under that lock from end to end, so the test can pass
while one of them is under way, and the quiesce then runs once it is
through. An enable that failed after it had stored the queue enabled
never initialized wq_active, and a disable has released it by then.
Either way percpu_ref_kill() works on a reference that has no data and
dereferences NULL.

The halt handler calls this for a halt that a system reset recovers
from, and the interrupt thread calls it when it cannot allocate the
work item for a revoked interrupt handle.

Test the queue again once the lock is held. A queue that reads enabled
there has its reference. The test without the lock stays, as a filter
that keeps the thread off a lock it must not wait for. Both callers run
in the interrupt thread that also completes the device commands, and a
queue's lock is held across such commands. The enable of a kernel queue
and a cdev open issue theirs under the lock of a queue that does not
read as an enabled kernel queue yet, so the filter skips that queue and
the thread never waits for its lock. Taking every queue's lock here
would let the thread and such a waiter wait for each other. An unbind
issues its commands under the lock of a queue that does read as one, and
the thread waits behind it, as it did before.

Fixes: 5b0c68c473a1 ("dmaengine: idxd: support reporting of halt interrupt")
Cc: stable@vger.kernel.org # 5.13+
Signed-off-by: Daniel Byrne <daniel1.byrne@intel.com>
---
New in v2.

 drivers/dma/idxd/init.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index 4b827a329756..4f3693fb7975 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -1242,8 +1242,26 @@ void idxd_wqs_quiesce(struct idxd_device *idxd)
 
 	for (i = 0; i < idxd->max_wqs; i++) {
 		wq = idxd->wqs[i];
+		/*
+		 * Skip a queue that does not read as an enabled kernel
+		 * queue without taking its lock. This runs in the thread
+		 * that completes the device commands, and the enable of a
+		 * kernel queue and a cdev open hold the lock of such a
+		 * queue while they wait for a command. An unbind holds the
+		 * lock of an enabled kernel queue across its commands, and
+		 * this waits behind it.
+		 */
+		if (wq->state != IDXD_WQ_ENABLED || wq->type != IDXD_WQT_KERNEL)
+			continue;
+		/*
+		 * Test again under the lock. The enable and the disable of
+		 * a queue hold it from end to end, so a queue that reads
+		 * enabled here has its reference.
+		 */
+		mutex_lock(&wq->wq_lock);
 		if (wq->state == IDXD_WQ_ENABLED && wq->type == IDXD_WQT_KERNEL)
-			idxd_wq_quiesce(wq);
+			__idxd_wq_quiesce(wq);
+		mutex_unlock(&wq->wq_lock);
 	}
 }
 
-- 
2.43.0


      parent reply	other threads:[~2026-11-30 19:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 19:47 [PATCH v2 00/10] dmaengine: idxd: event log, cdev and prep fixes Daniel Byrne
2026-11-30 19:47 ` [PATCH v2 01/10] dmaengine: idxd: don't queue EVL fault work for kernel WQs Daniel Byrne
2026-11-30 19:47 ` [PATCH v2 02/10] dmaengine: idxd: detach the user fault workqueue under the event log lock Daniel Byrne
2026-11-30 19:47 ` [PATCH v2 03/10] dmaengine: idxd: free the event log fault item when no record is copied Daniel Byrne
2026-11-30 19:47 ` [PATCH v2 04/10] dmaengine: idxd: refuse a memcpy longer than the WQ max transfer size Daniel Byrne
2026-11-30 19:47 ` [PATCH v2 05/10] dmaengine: idxd: take an mm_users reference for the completion record copy Daniel Byrne
2026-11-30 19:47 ` [PATCH v2 06/10] dmaengine: idxd: read GENCFG before clearing the event log enable Daniel Byrne
2026-11-30 19:47 ` [PATCH v2 07/10] dmaengine: idxd: don't sleep for a descriptor in the prep callbacks Daniel Byrne
2026-11-30 19:47 ` [PATCH v2 08/10] dmaengine: idxd: read the event log size under its lock in the setup Daniel Byrne
2026-11-30 19:47 ` [PATCH v2 09/10] dmaengine: idxd: free the queue interrupt when the percpu_ref setup fails Daniel Byrne
2026-11-30 19:47 ` Daniel Byrne [this message]

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=20261130194721.1900266-11-daniel1.byrne@intel.com \
    --to=daniel1.byrne@intel.com \
    --cc=Frank.Li@kernel.org \
    --cc=dave.jiang@intel.com \
    --cc=djbw@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=fenghuay@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@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®