| Message ID | 20260705082105.13325-1-zenghongling@kylinos.cn (mailing list archive) |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-sunxi+bounces-24168-sunxi=pue.re@lists.linux.dev> X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 5E78A1C3FFE for <noreply@patchwork.local>; Sun, 5 Jul 2026 10:21:36 +0200 (CEST) Authentication-Results: mxe881; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-24168-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-24168-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id 6ADAC300FB7D for <noreply@patchwork.local>; Sun, 5 Jul 2026 08:21:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1232B36E46F; Sun, 5 Jul 2026 08:21:22 +0000 (UTC) X-Original-To: linux-sunxi@lists.linux.dev Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8088E363084 for <linux-sunxi@lists.linux.dev>; Sun, 5 Jul 2026 08:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783239682; cv=none; b=u0OEE9at/6cEEGVtgF7kp7O12iOX0xCayRlZylD9BsV+k67OZM3rtrHJWQRPekDjr/1cJLFM1AHsEVG8O/GmRXEDMcZ4m0+yIH6ZLb7MpkWJu0KwQT3GoVWP50LQ8oEaqfDgu4myYq8AEBgD4GtlrCPULaPEMF6WdcslxSWyfyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783239682; c=relaxed/simple; bh=YbdgeRuX3ynm03Agwub6U+huy0SG0DYvhedvkV8qgHw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=UhtYMzNil9yZDq8xpRkKhYgR6t98P+aS74i8RiKkINrtBkNfzSiWqxlfZUA8Ai7rcPk/O1xa/xoMBy5ycJ/9VnfiCBzXEaEh0lNb/QVO0/rzYlrCfsQTvf+x8J9p6lAhQO6mHWrbzyo9AJfbDPE0OopqQty+xq+FQK1WqqD4sak= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 7a7b9f32784a11f1aa26b74ffac11d73-20260705 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:a6398748-fa9e-407b-8b50-4517535e9794,IP:0,U RL:0,TC:0,Content:-25,EDM:-25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-50 X-CID-META: VersionHash:e7bac3a,CLOUDID:58474abc3c0e55c9a55465de6d67677f,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:102|850|865|898,TC:nil,Content:0|15|50,E DM:2,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA: 0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 7a7b9f32784a11f1aa26b74ffac11d73-20260705 X-User: zenghongling@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from <zenghongling@kylinos.cn>) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1580939437; Sun, 05 Jul 2026 16:21:10 +0800 From: Hongling Zeng <zenghongling@kylinos.cn> To: vkoul@kernel.org, Frank.Li@kernel.org, wens@kernel.org, jernej.skrabec@gmail.com, samuel@sholland.org Cc: dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, zhongling0719@126.com, Hongling Zeng <zenghongling@kylinos.cn>, stable@vger.kernel.org Subject: [PATCH] dmaengine: sun6i: Fix potential deadlock in dma_terminate_all and pause Date: Sun, 5 Jul 2026 16:21:05 +0800 Message-Id: <20260705082105.13325-1-zenghongling@kylinos.cn> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: <linux-sunxi.lists.linux.dev> List-Subscribe: <mailto:linux-sunxi+subscribe@lists.linux.dev> List-Unsubscribe: <mailto:linux-sunxi+unsubscribe@lists.linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= |
| Series |
dmaengine: sun6i: Fix potential deadlock in dma_terminate_all and pause
|
|
Commit Message
Hongling Zeng
July 5, 2026, 8:21 a.m. UTC
sun6i_dma_terminate_all() and sun6i_dma_pause() acquire sdev->lock
with plain spin_lock() from process context. If a DMA interrupt fires
on the same CPU while the lock is held, the interrupt handler schedules
sun6i_dma_tasklet(), which runs in softirq context and attempts to
acquire the same lock with spin_lock_irq(), causing a deadlock.
Fix by using spin_lock_irq() to disable interrupts while holding
sdev->lock, consistent with other call sites.
Fixes: ba489fd46ab6 ("dmaengine: sun6i: Add support for Allwinner A31 DMA controller")
Cc: stable@vger.kernel.org
Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
---
drivers/dma/sun6i-dma.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
Comments
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: New issues: - [High] Use of spin_lock_irq()/spin_unlock_irq() unconditionally re-enables hardware interrupts, breaking caller atomic contexts. Pre-existing issues: - [High] Lockless reads of vchan->phy introduce Time-of-Check to Time-of-Use (TOCTOU) races causing cross-channel interference. - [High] Active, non-cyclic DMA descriptors are leaked upon channel termination. -- commit 5ad36fe6cb5ac09d034a98b6efc7e6a3152d1705 Author: Hongling Zeng <zenghongling@kylinos.cn> dmaengine: sun6i: Fix potential deadlock in dma_terminate_all and pause This patch addresses a deadlock between process context and the DMA tasklet in softirq context. It replaces plain spin_lock() and spin_unlock() with their irq variants for sdev->lock in sun6i_dma_pause() and sun6i_dma_terminate_all(). > diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c > index a9a254dbf8cb9..37b143a8f75e2 100644 > --- a/drivers/dma/sun6i-dma.c > +++ b/drivers/dma/sun6i-dma.c > @@ -898,9 +898,9 @@ static int sun6i_dma_pause(struct dma_chan *chan) > writel(DMA_CHAN_PAUSE_PAUSE, > pchan->base + DMA_CHAN_PAUSE); > } else { > - spin_lock(&sdev->lock); > + spin_lock_irq(&sdev->lock); > list_del_init(&vchan->node); > - spin_unlock(&sdev->lock); > + spin_unlock_irq(&sdev->lock); [Severity: High] Does spin_unlock_irq() unintentionally enable hardware interrupts for callers that enter this function with interrupts disabled? DMA engine API functions like dmaengine_pause() are frequently called by client drivers from atomic contexts where interrupts are already disabled (for example, while holding a lock via spin_lock_irqsave()). Since spin_unlock_irq() unconditionally re-enables hardware interrupts, could this destroy the caller's atomicity and lead to scheduling while atomic panics or deadlocks? Would it be safer to use spin_lock_irqsave() and spin_unlock_irqrestore() here instead? [ ... ] > @@ -939,9 +939,9 @@ static int sun6i_dma_terminate_all(struct dma_chan *chan) > unsigned long flags; > LIST_HEAD(head); [Severity: High] This is a pre-existing issue, but does fetching the physical channel pointer locklessly at the start of this function introduce a race condition? At the top of sun6i_dma_terminate_all(), we have: struct sun6i_pchan *pchan = vchan->phy; If a DMA transfer completes concurrently on another CPU, the tasklet might clear vchan->phy and reassign the same pchan to a different virtual channel. When sun6i_dma_terminate_all() later acquires the lock and calls writel() to stop the channel, could it mistakenly stop an unrelated transfer that was just started on that physical channel? [Severity: High] This is a pre-existing issue, but does sun6i_dma_terminate_all() leak active non-cyclic descriptors? When terminating, the function has logic to rescue cyclic descriptors and move them to the completed list: if (vchan->cyclic) { vchan->cyclic = false; if (pchan && pchan->desc) { ... list_add_tail(&vd->node, &vc->desc_completed); } } However, for non-cyclic transfers, it ignores the active descriptor entirely and sets pchan->desc = NULL. Because vchan_get_all_descriptors() only grabs descriptors from the tracking lists, the active non-cyclic descriptor is bypassed and lost. Could this lead to a permanent memory leak of sun6i_desc structures and their associated hardware pools when non-cyclic transfers are aborted? > - spin_lock(&sdev->lock); > + spin_lock_irq(&sdev->lock); > list_del_init(&vchan->node); > - spin_unlock(&sdev->lock); > + spin_unlock_irq(&sdev->lock); [Severity: High] Similar to sun6i_dma_pause(), will this spin_unlock_irq() unconditionally enable hardware interrupts and break the caller's atomic context? Also, because it re-enables interrupts before the immediately following spin_lock_irqsave(&vchan->vc.lock, flags) call, could it corrupt the IRQ state saved in flags? > > spin_lock_irqsave(&vchan->vc.lock, flags); >
diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c index a9a254dbf8cb..37b143a8f75e 100644 --- a/drivers/dma/sun6i-dma.c +++ b/drivers/dma/sun6i-dma.c @@ -898,9 +898,9 @@ static int sun6i_dma_pause(struct dma_chan *chan) writel(DMA_CHAN_PAUSE_PAUSE, pchan->base + DMA_CHAN_PAUSE); } else { - spin_lock(&sdev->lock); + spin_lock_irq(&sdev->lock); list_del_init(&vchan->node); - spin_unlock(&sdev->lock); + spin_unlock_irq(&sdev->lock); } return 0; @@ -939,9 +939,9 @@ static int sun6i_dma_terminate_all(struct dma_chan *chan) unsigned long flags; LIST_HEAD(head); - spin_lock(&sdev->lock); + spin_lock_irq(&sdev->lock); list_del_init(&vchan->node); - spin_unlock(&sdev->lock); + spin_unlock_irq(&sdev->lock); spin_lock_irqsave(&vchan->vc.lock, flags);