From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.19 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796068704; b=abEgZnYSuNDtGXUmp2FeU4b5d5XVSc6u3pa038xwpTWgZJgkhXcfk9VKRR/lyGn+KWnF xQJreAZNMcTE4+qNi4BxxrJ6iXgrnhuP8+x7NOjMN4SaEIZ7U8bmHCOZ16axaZJ3Bwz0E NhP2enFneCEc1HdXrYEx5I2JWs/RaF6UTNcnccKbuM3ivmVC73s0neM0do9IGNZ0/NfNE AA8qmfeuA007upM7mBVWBYhTLt9xs2ZHoWOSytD+8hlv2WZQPtdtldK00McW+Qvf/oqDN OWMfarBVCbEK/2M+UkRiEtdLVoCGraj8lJ+Kko+vXOuIrIOHyksGxM217PDvaJnpoXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796068704; 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=D53pSVgPF19mHHLTG+OJj4c1QOA+8DFWMWIx5pLbDco=; b=dEi+AJYT3DJ1pGl9pNvCYFdyr7hbKH2hXzKyW8EkLL66FI+iOzR2Cz71h1CLyqZCUzZ6 PeZIu+UmByf4HgsCB3MZtEvpQ0xFsdxM9JQTwAF9gEdJv8HebsFBbu/rOIDSzaYErRJyp j3DRPEiG1YJzJIdqY+7UF/w2e3XvWzIAfr7xk1+2KG0KFV4opZP4zNmsA35TYt+iKv2ai S46by1LbcdqJSPCFJdsTePcIz+W8Q7yGGc1FUFTadaXsVNsblyk1h6FubavXkyFX06nVY zckYsZeDHEqvXllNfDhe+uBrdbhHrh9QcYrOAy5n+jU1HF6FQOx9qHx8IbzNC1ic3Gw== 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=M0ZjBSGg; arc=none smtp.remote-ip=192.198.163.19 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 BF8B5606A333; Mon, 30 Nov 2026 19:58:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BF8B5606A333 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=M0ZjBSGg DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796068704; x=1827604704; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D53pSVgPF19mHHLTG+OJj4c1QOA+8DFWMWIx5pLbDco=; b=M0ZjBSGgFwFR/p1JeHqxLYFAKuvILGLHGZynq8oLjYvtreYFy2dajFEh XWFeuRwY1ghn2vnfQuUQI8BswNfcZ2/INwJiEL2GQd9mXK+IevRywUMru 5bZID4qXF+3cHgwsAfn3h5NKSwbhWpugmoUkTyQEYBM5n2E8vASUUeDPK ggE4kekUw6/htTX2AX6F8g2dupQnCY5PTK3QUTujgbkMhExkHIAtTGWSK J8PZvbMxQvJUDLrKjPkIUdEPCNk94VfisvuezPTB7Z8NPK/+sRv4n1sn9 xu93oM02qFWkMhDfBurRTjgUBVKao+0pLTwZLHCO3Q9W0wv5IH6mhw9io g==; X-CSE-ConnectionGUID: wZjgPpcNROe/m9TAIKpvzA== X-CSE-MsgGUID: Sf1ZAdBkQmew7WiLh88WgQ== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4936899" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4936899" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 11:58:22 -0800 X-CSE-ConnectionGUID: mKBvJ8NIQHC/yAUyV+lUzA== X-CSE-MsgGUID: tBJIueqkSFqR3GX7NW9QcA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4517794" Received: from jf5300-15a101203tc.jf.intel.com (HELO meta-crater2c.jf.intel.com) ([10.54.113.49]) by orviesa010.jf.intel.com with ESMTP; 30 Nov 2026 11:58:22 -0800 From: Daniel Byrne To: Vinod Koul , dmaengine@vger.kernel.org Cc: Vinicius Costa Gomes , Dave Jiang , Frank Li , Dan Williams , Ruoyu Wang , Zhejun Huang , Changyul Lee , linux-kernel@vger.kernel.org, Daniel Byrne , stable@vger.kernel.org Subject: [PATCH v2 3/4] dmaengine: idxd: unlink a channel under dma_list_mutex before removing it Date: Mon, 30 Nov 2026 11:52:02 -0800 Message-ID: <20261130195203.1901143-4-daniel1.byrne@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130195203.1901143-1-daniel1.byrne@intel.com> References: <20261130195203.1901143-1-daniel1.byrne@intel.com> X-Mailing-List: linux-kernel@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 The unbind of a work queue unlinks its channel from the dma_device's channel list after the core has unregistered the channel, and without dma_list_mutex. A channel request walks that list under the mutex and may hand out any listed channel without a client, so it can still take a channel whose sysfs device is gone and whose idxd_chan the unbind is about to free, and the unlocked list_del() races the locked link of another queue's channel. The quiesce that precedes the unregistration kills the queue's submissions, not the channel's presence on the list. Add dma_async_device_channel_remove(), the counterpart of dma_async_device_channel_add(). It unlinks the channel under the mutex first and unregisters it afterwards, which the core can do and the driver cannot, since the mutex is private to it. Use it in the unbind. After the locked unlink no walker under the mutex finds the channel. A client that took the channel between the quiesce and the unlink still holds idxd_chan across the kfree(). This is a broader lifetime problem of a channel unbound under its clients, and is left for the change that reworks the unbind for channels that clients still hold. Fixes: 397862855619 ("dmaengine: idxd: fix dma device lifetime") Cc: stable@vger.kernel.org # 5.13+ Signed-off-by: Daniel Byrne --- New in v2. drivers/dma/dmaengine.c | 26 ++++++++++++++++++++++++++ drivers/dma/dmaengine.h | 2 ++ drivers/dma/idxd/dma.c | 3 +-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 1d8d2949a810..85a98aae6a97 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -1231,6 +1231,32 @@ void dma_async_device_channel_unregister(struct dma_device *device, } EXPORT_SYMBOL_GPL(dma_async_device_channel_unregister); +/** + * dma_async_device_channel_remove - unlink and unregister a channel + * @device: the channel's device + * @chan: the channel, added with dma_async_device_channel_add() + * + * The channel is unlinked from the device's list under dma_list_mutex + * before it is unregistered, so that a request that walks the list under + * the mutex cannot hand out a channel whose sysfs device is gone and whose + * memory the driver is about to free, and so that the unlink does not race + * the locked link of another channel. The driver must have quiesced the + * channel. As with dma_async_device_channel_unregister(), a client that + * already holds the channel is not handled here. + */ +void dma_async_device_channel_remove(struct dma_device *device, + struct dma_chan *chan) +{ + mutex_lock(&dma_list_mutex); + list_del(&chan->device_node); + mutex_unlock(&dma_list_mutex); + __dma_async_device_channel_unregister(device, chan); + mutex_lock(&dma_list_mutex); + dma_channel_rebalance(); + mutex_unlock(&dma_list_mutex); +} +EXPORT_SYMBOL_GPL(dma_async_device_channel_remove); + /** * dma_async_device_register - registers DMA devices found * @device: pointer to &struct dma_device diff --git a/drivers/dma/dmaengine.h b/drivers/dma/dmaengine.h index 371509b26e6b..c6c03174c97a 100644 --- a/drivers/dma/dmaengine.h +++ b/drivers/dma/dmaengine.h @@ -215,6 +215,8 @@ int dma_async_device_channel_register(struct dma_device *device, const char *name); void dma_async_device_channel_unregister(struct dma_device *device, struct dma_chan *chan); +void dma_async_device_channel_remove(struct dma_device *device, + struct dma_chan *chan); #ifdef CONFIG_DEBUG_FS #include diff --git a/drivers/dma/idxd/dma.c b/drivers/dma/idxd/dma.c index 6293842689fb..bed71e66eca6 100644 --- a/drivers/dma/idxd/dma.c +++ b/drivers/dma/idxd/dma.c @@ -312,8 +312,7 @@ static void idxd_unregister_dma_channel(struct idxd_wq *wq) struct dma_chan *chan = &idxd_chan->chan; struct idxd_dma_dev *idxd_dma = wq->idxd->idxd_dma; - dma_async_device_channel_unregister(&idxd_dma->dma, chan); - list_del(&chan->device_node); + dma_async_device_channel_remove(&idxd_dma->dma, chan); kfree(wq->idxd_chan); wq->idxd_chan = NULL; put_device(wq_confdev(wq)); -- 2.43.0