Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.11 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796068425; b=yl8NwtohUr53jkoTnctcunTHCTC8mtTsHWrPnvOjqpc9zJt9vkeo901C+Q5KMvhuoXcK Q36IgUHd4l9Dnpb/uixY98X4qjRjjaOjAsDCCNSEQjjMCqwflK3FXnv36HnrMJAPIgfWc t98dfN6roske1HYGgd/a9gt/x2fhUu9Z0QDz/Za1hlmYC4wj682TIiTQaTF2n1FV1EPLe tbCMAwGxcURQMdLCW711TdiuM7rOahpCcnTndAsPIfFiRDlKtHBIBoAJlsBM1Mo6j+Vdn tbHnSiwILA2qcxMz5ROuczBk8dm73IrKfkOc4OBvjLRwum2Ke5UQzm9b2rb7S5IS0wg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796068425; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=1vI6jruJbl1MqWej+enM+/W9HgzbIFw1VMUZRyMuzCo=; b=bQD/2WC4p5acgoHM4T2E5ou90EZetre+jeRTZPXwTH8BIhU93Thy+zDcFlZTjKzD0ReU j2+11NeJBmI3yar9plM7OEVFmTTOevmy8yhGWJ/hLbJkoKkpKWBr23auiY54EsGkaNVrb qHuZJls0mGJzHSZJnVLQ3V3uW9GBsvvTMU7cJrhPs9/cvgu7ZHkZk1WeRf2nFU/bqak1r x+Ls3PqLgEGXOGhEjMdixncet+3f8P81L6qc/2ZBO/2sxhDfB2AYv2dtq9MOEO1SGGzVt WSFPVL+aAVpTnzKywe8ySnhgMx0t1gkROjWZTiM06b1+BDIgEZ/TSOS7uYm/K+LcRyg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=YcMXyKp4; arc=none smtp.remote-ip=198.175.65.11 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C9D1606A6B4; Mon, 30 Nov 2026 19:53:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6C9D1606A6B4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=YcMXyKp4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796068425; x=1827604425; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1vI6jruJbl1MqWej+enM+/W9HgzbIFw1VMUZRyMuzCo=; b=YcMXyKp4fbDeFiRQa0v/Tc2Cv7HlHwblmwru0FAF/Ty656jLTsL/wR1f 3+YfZ0V7Z1g85iKxlEoQ/o1SkdRzAXyievY9DVW2b9SP+hDu6jSvYAo5f 7emV/LU74CN0IO2OIAiFVbEBtZ2mOqLp6HGR+pQcEcAxm9bhulFBTiQ81 0AreWlLk6FjHqb7Awz0Wbt+hZi4hldrD2bceX8nQ0wtvv+juD3uOsWr9W Ja49+Cl4GuOMih+ndtfMuYHh9ILtEZ7NNgfepPm/hGqJ+GwnIC3GqG4Xs xGeLpa//LBkLy6ozr0U0pKDX2VocFqWvoXHj7qWoIIUwp74YIHGPwyW+h Q==; X-CSE-ConnectionGUID: x8n8cQJXQRK/i4r3GgxaYg== X-CSE-MsgGUID: otOfQVftSC+hu1j8Hb7PEQ== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4805782" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4805782" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 11:53:41 -0800 X-CSE-ConnectionGUID: 25TPAFFUSnWaQRvXe2y9Vg== X-CSE-MsgGUID: ykGEarn1QUe1wn+TCVTeqg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="13036638" Received: from jf5300-15a101203tc.jf.intel.com (HELO meta-crater2c.jf.intel.com) ([10.54.113.49]) by orviesa002.jf.intel.com with ESMTP; 30 Nov 2026 11:53:40 -0800 From: Daniel Byrne To: Vinod Koul , dmaengine@vger.kernel.org Cc: Vinicius Costa Gomes , Dave Jiang , Frank Li , Fenghua Yu , Dan Williams , linux-kernel@vger.kernel.org, Daniel Byrne , 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 Message-ID: <20261130194721.1900266-11-daniel1.byrne@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130194721.1900266-1-daniel1.byrne@intel.com> References: <20261130194721.1900266-1-daniel1.byrne@intel.com> X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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