Message ID | 20230806032511.45263-1-duoming@zju.edu.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp743763vqr; Sat, 5 Aug 2023 20:47:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGm4HgEUwXLUPCX/m/TbFR+Uqfm6na5yG8IYjqbzrxiBuTMyeqAEcURASeMc4XKmpi10z/P X-Received: by 2002:a17:906:847b:b0:992:872:76d4 with SMTP id hx27-20020a170906847b00b00992087276d4mr5239949ejc.17.1691293653300; Sat, 05 Aug 2023 20:47:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293653; cv=none; d=google.com; s=arc-20160816; b=mcAeZqQIYqZVkj9ZnOX6zvzl6zFzGDpbfbcoRyHSnFzTk4fQKTIibcOQRvVPKko7/M QAjWcnTBgcnZ3yfNXEAnSQWJCEkveERf3vwqJcAzisP1a12/pPTVJXqdOTMVh21dLbmS HhwfquSq2FAa8OVM6C5RC8Wx9kVgUobBQ9DSuTNosQH0u3BsRrddnvp/fYBhvljIXZzc WLoy6f2kh7x1gH1N+YD97eVcyoLCjiB/6k4kz+KYIAWBUKbMa3I14AwuwBU0dxAJ9HOq cJlcIgue+U/5cnmv9AAX0pHaDm7KGdfg696jkoN+TL8MJrQ8a3jr4WZpqknrDVyTaK7r CN+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=whpOHeAcCcjjqwU/OvON8VF060T2SRGxq+DJKQd8260=; fh=1EOgWjZBS0OD0PngDsUvyKdR95tbprCRtos2x9Ng7cM=; b=U8Dh7kibbzIUygY+SDY1rxqzSZ921pTM5+zFmThek6Lps2OWrC6IDWdVIKqajNxUv/ x7IFR25Jx5+Uv3huF/1sLrD4mwpvDP0i94r8O8SJQEXftIcU5+7CLYdhx/kPdSL82qGv +nVF5IRNccPJBjE9ovf7fUK/HQce5UcHVJxsGsaHGUVE8If+ghwU6Q4twdH3Q/ZEyN2l XgJTIvtKtQ3rXu3pIRIf9ttkrMJOyDWFAQvvtkI80Y4qiB7/7Xp3RfR3CqsJuSTGqweO hrqVAE+G6Ule6CjDK9ClreSVJXV0DCqzDKoB6B6qksM1g7d7uFejDNcobJkJS7uKjEkU JqnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz20-20020a170906cd1400b0098d2f81bceasi3720795ejb.934.2023.08.05.20.47.10; Sat, 05 Aug 2023 20:47:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229723AbjHFDZp (ORCPT <rfc822;david.simonyants@gmail.com> + 99 others); Sat, 5 Aug 2023 23:25:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjHFDZo (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 5 Aug 2023 23:25:44 -0400 Received: from zg8tndyumtaxlji0oc4xnzya.icoremail.net (zg8tndyumtaxlji0oc4xnzya.icoremail.net [46.101.248.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F407F1FE4; Sat, 5 Aug 2023 20:25:39 -0700 (PDT) Received: from ubuntu.localdomain (unknown [218.12.19.97]) by mail-app4 (Coremail) with SMTP id cS_KCgCnrBSYEs9kXASjCg--.63926S2; Sun, 06 Aug 2023 11:25:21 +0800 (CST) From: Duoming Zhou <duoming@zju.edu.cn> To: sean.wang@mediatek.com Cc: vkoul@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Duoming Zhou <duoming@zju.edu.cn> Subject: [PATCH] dmaengine: mediatek: Fix deadlock caused by synchronize_irq() Date: Sun, 6 Aug 2023 11:25:11 +0800 Message-Id: <20230806032511.45263-1-duoming@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: cS_KCgCnrBSYEs9kXASjCg--.63926S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Zryxuw4rJF4ktw1UtrWfGrg_yoW8GFy3pF WDJa45CFWqyr1Dua1UCr42qFWrC3WfGrW7Gr4fXw43Ca4rJryYvr1FyayavF4jqr9rKa97 Kr4UtrWrCF4jyr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUym14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1l42xK82IYc2Ij64vI r41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8Gjc xK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0 cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E 14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x0JUdHUDUUUUU= X-CM-SenderInfo: qssqjiasttq6lmxovvfxof0/1tbiAwQSAWTNp-sHcgAhs1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773449933685892537 X-GMAIL-MSGID: 1773449933685892537 |
Series |
dmaengine: mediatek: Fix deadlock caused by synchronize_irq()
|
|
Commit Message
Duoming Zhou
Aug. 6, 2023, 3:25 a.m. UTC
The synchronize_irq(c->irq) will not return until the IRQ handler
mtk_uart_apdma_irq_handler() is completed. If the synchronize_irq()
holds a spin_lock and waits the IRQ handler to complete, but the
IRQ handler also needs the same spin_lock. The deadlock will happen.
The process is shown below:
cpu0 cpu1
mtk_uart_apdma_device_pause() | mtk_uart_apdma_irq_handler()
spin_lock_irqsave() |
| spin_lock_irqsave()
//hold the lock to wait |
synchronize_irq() |
This patch reorders the synchronize_irq(c->irq) outside the spin_lock
in order to mitigate the bug.
Fixes: 9135408c3ace ("dmaengine: mediatek: Add MediaTek UART APDMA support")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
---
drivers/dma/mediatek/mtk-uart-apdma.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
Comments
On 8/6/23 06:25, Duoming Zhou wrote: > The synchronize_irq(c->irq) will not return until the IRQ handler > mtk_uart_apdma_irq_handler() is completed. If the synchronize_irq() > holds a spin_lock and waits the IRQ handler to complete, but the > IRQ handler also needs the same spin_lock. The deadlock will happen. > The process is shown below: > > cpu0 cpu1 > mtk_uart_apdma_device_pause() | mtk_uart_apdma_irq_handler() > spin_lock_irqsave() | > | spin_lock_irqsave() > //hold the lock to wait | > synchronize_irq() | > > This patch reorders the synchronize_irq(c->irq) outside the spin_lock > in order to mitigate the bug. > > Fixes: 9135408c3ace ("dmaengine: mediatek: Add MediaTek UART APDMA support") > Signed-off-by: Duoming Zhou <duoming@zju.edu.cn> > --- > drivers/dma/mediatek/mtk-uart-apdma.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c > index a1517ef1f4a..0acf6a92a4a 100644 > --- a/drivers/dma/mediatek/mtk-uart-apdma.c > +++ b/drivers/dma/mediatek/mtk-uart-apdma.c > @@ -451,9 +451,8 @@ static int mtk_uart_apdma_device_pause(struct dma_chan *chan) > mtk_uart_apdma_write(c, VFF_EN, VFF_EN_CLR_B); > mtk_uart_apdma_write(c, VFF_INT_EN, VFF_INT_EN_CLR_B); > > - synchronize_irq(c->irq); > - > spin_unlock_irqrestore(&c->vc.lock, flags); > + synchronize_irq(c->irq); > > return 0; > } Reviewed-by: Eugen Hristev <eugen.hristev@collabora.com>
On Sun, 06 Aug 2023 11:25:11 +0800, Duoming Zhou wrote: > The synchronize_irq(c->irq) will not return until the IRQ handler > mtk_uart_apdma_irq_handler() is completed. If the synchronize_irq() > holds a spin_lock and waits the IRQ handler to complete, but the > IRQ handler also needs the same spin_lock. The deadlock will happen. > The process is shown below: > > cpu0 cpu1 > mtk_uart_apdma_device_pause() | mtk_uart_apdma_irq_handler() > spin_lock_irqsave() | > | spin_lock_irqsave() > //hold the lock to wait | > synchronize_irq() | > > [...] Applied, thanks! [1/1] dmaengine: mediatek: Fix deadlock caused by synchronize_irq() commit: 01f1ae2733e2bb4de92fefcea5fda847d92aede1 Best regards,
diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c index a1517ef1f4a..0acf6a92a4a 100644 --- a/drivers/dma/mediatek/mtk-uart-apdma.c +++ b/drivers/dma/mediatek/mtk-uart-apdma.c @@ -451,9 +451,8 @@ static int mtk_uart_apdma_device_pause(struct dma_chan *chan) mtk_uart_apdma_write(c, VFF_EN, VFF_EN_CLR_B); mtk_uart_apdma_write(c, VFF_INT_EN, VFF_INT_EN_CLR_B); - synchronize_irq(c->irq); - spin_unlock_irqrestore(&c->vc.lock, flags); + synchronize_irq(c->irq); return 0; }