From patchwork Mon May 3 15:26:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Ranquet X-Patchwork-Id: 12236283 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MISSING_HEADERS,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EFF8C433B4 for ; Mon, 3 May 2021 15:27:36 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7E86261040 for ; Mon, 3 May 2021 15:27:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7E86261040 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:Subject:Message-ID:Date:From:MIME-Version: Reply-To:To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Z7yMs/XbhaZuWt91PbKDfRIgy08La7szW735TwP3uas=; b=Y36S//pM8ytN/j yokFkKVrLApnvwjb3NUtMXn4yRChe9HbyE1lqLWrNAwxBJnrjKX8+NyU2H614R3cp7Q0w8WqHMVJp iDm/EGL+rtqdUlRV8cXR1S5EKrXo3UDiKHUWyNGpKCwrW56Q6OVxphIM9YPraVZvQNDiA2mvx2kus y3kK40nK7sMKMhDT6AUGX9YplsR7ePM+/3K/NFtBUjK5XmtDQ+f4yskqY4v51gklP2VszaR9owUU9 lUOoadT0DUfcpkpekLNercQpUVeSPmq2VZhoNfkp2499n+JmQVeoQ0g37tsktiiStcwR1cGzX17eE jNgUb3mdNVNA4zUtVHIw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ldaTW-00EEBr-Ul; Mon, 03 May 2021 15:27:11 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ldaSx-00EE6V-UR for linux-mediatek@desiato.infradead.org; Mon, 03 May 2021 15:26:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:Cc:Subject:Message-ID: Date:From:MIME-Version:Sender:Reply-To:To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To:References; bh=DsCC9gqqI3YCW9ovP0n+UcVOJC+7xZwxFoiL/RkkmZQ=; b=yCoZTzwrj4reFuch2HO01cYoPL dIgKgUJigAs2mLBYa1bIHihpI1CudSmJFC7wveJcsMIv+zElw+43sRsOtwqSo7xKsbI9222yfiRXo V/xkaCQgH052T9WrnA9rCr6Z6VPVYxKSuEHdiEhqGEjGQ0YmmuttgdUJHSbyQ0lYuJIqm1YeiOqKX QZa+UwE21zPvEsh/9Ne09nb/6JtBfRXJX86P0o18oMBKeCBzFuPn/fAlgROoeaEHo3yhs7OD1Y8GF upWwLjbsbyXd3NJXJgXywFqB2kjIAIHApZGA1pdoMpJbMrqYirgpFqq7GNpbJ1+E2HAq8b2fPIOxs RMZ+ETlA==; Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ldaSu-003Auj-B7 for linux-mediatek@lists.infradead.org; Mon, 03 May 2021 15:26:34 +0000 Received: by mail-ot1-x334.google.com with SMTP id g7-20020a9d5f870000b02902a5831ad705so5375716oti.10 for ; Mon, 03 May 2021 08:26:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:cc; bh=DsCC9gqqI3YCW9ovP0n+UcVOJC+7xZwxFoiL/RkkmZQ=; b=dTvWlgasNphbykbaGHMLyLlxm27D+XIBOlYNgL84vlKQzIt2kjc4Kpa53LEJlK56fH CfhhR/nv/DMZ2I5AUGXMjc4GWmsxBfA0tdkAV2H3leyucCOxjQHnq7nh3uGC8MLPG01f waYCxbw9lruqFE0t9nb6eIhAr0jK8vdtTLpyf8Smyux4w3GaYaegAA8OqvMev6QDvrsZ 4pRtlb4cXCcLWcnEVOL/Gr5Xf/XZM+GLQDWWPFsg6cKOSOdNiwgC8uV4kjIZeNNQIgJy Q+awveaVeyz4b4ewr4Iy8AariywFauLqvXNBeUKB5aSNAn51R5lMo3k/com9ahoxXTWE fm8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:cc; bh=DsCC9gqqI3YCW9ovP0n+UcVOJC+7xZwxFoiL/RkkmZQ=; b=Zm6f0JcSS/KHlQGPv8ykoa21smGNfAkxIcrQ9VKWkGMRd6wPWKImcPwWy3Aaz/KjAN I+haix3pfrsg/I28he4dcQr+Ilb7eRT/oxvALrU29JjYT5A6Rfv7Xx1vi9sZnHK2tjvv SBmZSZ2Sz8jN9cgQtJ2NxHIcFmnW+wY1TMeM5wb4qjMzM/mWhpr5XtAzsTml0+CdZQtS +LnVf2sdOdYetzNAaSraQDOIwQa/Ei3N5TN0sMcbagj0NUtg7SdPVvPCpw9QLvdk4yh9 C75jSu0uRruP0j/qqsoN6H8SWdGS/g3+3kOkut3prhnmB80gdfa6BkC4rpLbVrr2Zxor qBoQ== X-Gm-Message-State: AOAM530P30GSTSbRwqxYvqrPi++yKRo/sA1Zsbn0ar1GVHHv1hgJLjY7 Exu1FAeu/SCu3hGH2vt2Bqn1tMjUfVtbpm2ExFIz3w== MIME-Version: 1.0 X-Received: by 2002:a9d:2de3:: with SMTP id g90mt12928708otb.274.1620055588708; Mon, 03 May 2021 08:26:28 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Mon, 3 May 2021 08:26:27 -0700 From: Guillaume Ranquet Date: Mon, 3 May 2021 08:26:27 -0700 Message-ID: Subject: [PATCH 1/4] dmaengine: mediatek: free the proper desc in desc_free handler Cc: Sean Wang , Vinod Koul , Dan Williams , Matthias Brugger , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210503_082632_404467_89A3C7D9 X-CRM114-Status: UNSURE ( 4.77 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org The desc_free handler assumed that the desc we want to free was always the current one associated with the channel. This is seldom the case and this is causing use after free crashes in multiple places (tx/rx/terminate...). BUG: KASAN: use-after-free in mtk_uart_apdma_rx_handler+0x120/0x304 Hardware name: GEA MT8167 ManeFaces (DT) Call trace: dump_backtrace+0x0/0x1b0 show_stack+0x24/0x34 dump_stack+0xe0/0x150 print_address_description+0x8c/0x55c __kasan_report+0x1b8/0x218 kasan_report+0x14/0x20 __asan_load4+0x98/0x9c mtk_uart_apdma_rx_handler+0x120/0x304 mtk_uart_apdma_irq_handler+0x50/0x80 __handle_irq_event_percpu+0xe0/0x210 handle_irq_event+0x8c/0x184 handle_fasteoi_irq+0x1d8/0x3ac __handle_domain_irq+0xb0/0x110 gic_handle_irq+0x50/0xb8 el0_irq_naked+0x60/0x6c Allocated by task 3541: __kasan_kmalloc+0xf0/0x1b0 kasan_kmalloc+0x10/0x1c kmem_cache_alloc_trace+0x90/0x2dc mtk_uart_apdma_prep_slave_sg+0x6c/0x1a0 mtk8250_dma_rx_complete+0x220/0x2e4 vchan_complete+0x290/0x340 tasklet_action_common+0x220/0x298 tasklet_action+0x28/0x34 __do_softirq+0x158/0x35c Freed by task 3541: __kasan_slab_free+0x154/0x224 kasan_slab_free+0x14/0x24 slab_free_freelist_hook+0xf8/0x15c kfree+0xb4/0x278 mtk_uart_apdma_desc_free+0x34/0x44 vchan_complete+0x1bc/0x340 tasklet_action_common+0x220/0x298 tasklet_action+0x28/0x34 __do_softirq+0x158/0x35c The buggy address belongs to the object at ffff000063606800 which belongs to the cache kmalloc-256 of size 256 The buggy address is located 176 bytes inside of 256-byte region [ffff000063606800, ffff000063606900) The buggy address belongs to the page: page:fffffe00016d8180 refcount:1 mapcount:0 mapping:ffff00000302f600 index:0x0 compound_mapcount: 0 flags: 0xffff00000010200(slab|head) raw: 0ffff00000010200 dead000000000100 dead000000000122 ffff00000302f600 raw: 0000000000000000 0000000080100010 00000001ffffffff 0000000000000000 page dumped because: kasan: bad access detected Signed-off-by: Guillaume Ranquet static void mtk_uart_apdma_start_tx(struct mtk_chan *c) diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c index 6bef40f0c9dc..4610dbdde75e 100644 --- a/drivers/dma/mediatek/mtk-uart-apdma.c +++ b/drivers/dma/mediatek/mtk-uart-apdma.c @@ -131,10 +131,7 @@ static unsigned int mtk_uart_apdma_read(struct mtk_chan *c, unsigned int reg) static void mtk_uart_apdma_desc_free(struct virt_dma_desc *vd) { - struct dma_chan *chan = vd->tx.chan; - struct mtk_chan *c = to_mtk_uart_apdma_chan(chan); - - kfree(c->desc); + kfree(container_of(vd, struct mtk_uart_apdma_desc, vd)); } From patchwork Mon May 3 15:26:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Ranquet X-Patchwork-Id: 12236285 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MISSING_HEADERS,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 822DFC433ED for ; Mon, 3 May 2021 15:27:36 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC25561073 for ; Mon, 3 May 2021 15:27:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC25561073 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:Subject:Message-ID:Date:From:MIME-Version: Reply-To:To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=VStLzrQJs0jeaBLBUIAQSrLxFec0Ef/SJeld9aXsQlI=; b=BO9fDI2wcyskUk Jxm6pq7dvcQiCN0lEsUpKUKuULqt8bO3t5YH4GYy9sMom8K0F+NdoJsFRToRYCcTkEA6SyKiugl12 mHUetmiBN+4/h3V0g4Ua4Glio2OH7zzRZppx05GUmxAJY5AFHJQnyAG3rMxyLRff5GQVGBU36WmJ4 1NDRRqGUytDFjLmYCARxGIYz3coZN37z0yzkb3pKC++XkZ/zqhiVPRlCMfqekyCrx7/RHwENKmJtF 7j+eQMdSXajYFX8sB4jzWDTSZhLhu50pku20oOvOZno79gpNfbl8bKMPCtsIcUGUJuy93sXmDC4Wi fOnTbNexRW80xpGZEbSA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ldaTZ-00EECM-Mt; Mon, 03 May 2021 15:27:14 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ldaSy-00EE6h-VN for linux-mediatek@desiato.infradead.org; Mon, 03 May 2021 15:26:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:Cc:Subject:Message-ID: Date:From:MIME-Version:Sender:Reply-To:To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To:References; bh=+0TCMPSPgNnKaQLcoOaFiNFXoz3PHgbrfotliZuGoqU=; b=Gv5l6T9OdC1EPFiPZouWCIwjCN dTzNVmvSn2w7TdVOUTnLME32skB9oEGmatWn2YovWUPSO+hZkFBxpkhGdWfioYilD7K2xtsSGD15+ VfA7LaS7vCQq+33cxgEkzQBeZQZNYE5tcf2F7PlhkaQA0BvqBY4/TR8pR2ICznaj7qLQUJB8R8dVO PFMobeWUaGL7z1E9xgIw3dtrVtnutQEBVMv7jte69J/8m3VYslKPv6+bHHk+S/LvI/XXUH++zMpt1 6onsNnGTsIVse9CU9ceqP4AWUWn+6rDmlUCDTdcXK7U5F/d2lQlyTsWvi4fl95ySNMBHpnaxIbWfc PikiLvZA==; Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ldaSu-003Auo-EQ for linux-mediatek@lists.infradead.org; Mon, 03 May 2021 15:26:35 +0000 Received: by mail-oi1-x231.google.com with SMTP id i26so5743142oii.3 for ; Mon, 03 May 2021 08:26:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:cc; bh=+0TCMPSPgNnKaQLcoOaFiNFXoz3PHgbrfotliZuGoqU=; b=z7g3kLcgZlbrRBtb8CCRI1h9u/bLF74VDrbBqfM72Yarr8dimSBTyLlvUTL1zBDjYN lUG3Ju6NPYHf5r9ez9mmShBUiODfIb5zLctDXgickNqHAmb9FYvkTtbaOcAeSCmLL6RF g72P90/Eo9OBv9wMPqHUnoSlImhyJfoORfu6cs4gBVwqyJXzTp2GrVLfydcz2RZQVVPy X1wtYXCDqm3Ak2HWImonIZaWp9hRBpxduRgoVQttGQLnLOArw9nGHcD8De5dH1AqtumN QR7EGAOUt+E3AHUmsk8vYJC1ZN+G9VKPvxF6sHmUrxXfgZT/HGfEYUWIKp+TTwM6dhES kMBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:cc; bh=+0TCMPSPgNnKaQLcoOaFiNFXoz3PHgbrfotliZuGoqU=; b=bDoj6PmaApPcKK2ta01QdqsRDs4g8ZC8kGMpmRRVS515aa7446lY9zzGbdpuh5J8GK y2FJEi4HEHLFmbHTetLhRTN7xK4I2Lyk71xtL39z8PlindcijPGwjqqIiXxPnzrj2wlN sJ/rymdljWWbykHHw+9C3rwZ7YZP4wN0eS/jwfP780rSAS4s/swTKBBrYnrWjwsQupl0 8SONq6mFd9Kn/MogCCQ9cXhofcPrWpJnOYOogBjUVz466CwungfFzn8zeTLooFxB0wF0 OIdVzqw2YNqxAhCi9UrCTWpYoviN75ZkCVirpv6XssGNyyhqqV4qLZjNSod3Gaijz/sg 4vYg== X-Gm-Message-State: AOAM532cRyxyXe4vkRJx5VpSGUhfPNiWysUBQzZvkk6y5vGYuBghZmro 3psQpbA5AUdwpD6XU/BOeBDbAKgjalu94/GnllDP6Q== MIME-Version: 1.0 X-Received: by 2002:a54:4f07:: with SMTP id e7mt10487611oiy.140.1620055590361; Mon, 03 May 2021 08:26:30 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Mon, 3 May 2021 08:26:29 -0700 From: Guillaume Ranquet Date: Mon, 3 May 2021 08:26:29 -0700 Message-ID: Subject: [PATCH 2/4] dmaengine: mediatek: do not issue a new desc if one is still current Cc: Sean Wang , Vinod Koul , Dan Williams , Matthias Brugger , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210503_082632_511948_73D22785 X-CRM114-Status: UNSURE ( 8.61 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Avoid issuing a new desc if one is still being processed as this can lead to some desc never being marked as completed. Signed-off-by: Guillaume Ranquet return IRQ_HANDLED; @@ -363,7 +367,7 @@ static void mtk_uart_apdma_issue_pending(struct dma_chan *chan) unsigned long flags; spin_lock_irqsave(&c->vc.lock, flags); - if (vchan_issue_pending(&c->vc)) { + if (vchan_issue_pending(&c->vc) && !c->desc) { vd = vchan_next_desc(&c->vc); c->desc = to_mtk_uart_apdma_desc(&vd->tx); diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c index 4610dbdde75e..249cabddb7ee 100644 --- a/drivers/dma/mediatek/mtk-uart-apdma.c +++ b/drivers/dma/mediatek/mtk-uart-apdma.c @@ -204,14 +204,9 @@ static void mtk_uart_apdma_start_rx(struct mtk_chan *c) static void mtk_uart_apdma_tx_handler(struct mtk_chan *c) { - struct mtk_uart_apdma_desc *d = c->desc; - mtk_uart_apdma_write(c, VFF_INT_FLAG, VFF_TX_INT_CLR_B); mtk_uart_apdma_write(c, VFF_INT_EN, VFF_INT_EN_CLR_B); mtk_uart_apdma_write(c, VFF_EN, VFF_EN_CLR_B); - - list_del(&d->vd.node); - vchan_cookie_complete(&d->vd); } static void mtk_uart_apdma_rx_handler(struct mtk_chan *c) @@ -242,9 +237,17 @@ static void mtk_uart_apdma_rx_handler(struct mtk_chan *c) c->rx_status = d->avail_len - cnt; mtk_uart_apdma_write(c, VFF_RPT, wg); +} - list_del(&d->vd.node); - vchan_cookie_complete(&d->vd); +static void mtk_uart_apdma_chan_complete_handler(struct mtk_chan *c) +{ + struct mtk_uart_apdma_desc *d = c->desc; + + if (d) { + list_del(&d->vd.node); + vchan_cookie_complete(&d->vd); + c->desc = NULL; + } } static irqreturn_t mtk_uart_apdma_irq_handler(int irq, void *dev_id) @@ -258,6 +261,7 @@ static irqreturn_t mtk_uart_apdma_irq_handler(int irq, void *dev_id) mtk_uart_apdma_rx_handler(c); else if (c->dir == DMA_MEM_TO_DEV) mtk_uart_apdma_tx_handler(c); + mtk_uart_apdma_chan_complete_handler(c); spin_unlock_irqrestore(&c->vc.lock, flags); From patchwork Mon May 3 15:26:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Ranquet X-Patchwork-Id: 12236289 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MISSING_HEADERS,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 364CEC433B4 for ; Mon, 3 May 2021 15:28:23 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D892A60C3E for ; Mon, 3 May 2021 15:28:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D892A60C3E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:Subject:Message-ID:Date:From:MIME-Version: Reply-To:To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=YoK3s1EW7ZS63p/7tS8RD9AudqfTOSt492X1UbQOOU0=; b=FRjTCOBd/aCYvY cHVH1MzOUNtRk3Cqguni1vFWypvsiH7ehbEKFOpGwnY5xI0pg1vNcOXs6KIYqWm9JRIXCoCZ0NLpe Y1+Rqoyethu08SV2ZVK9u7yCi+JwJrGtea1gIDllHsArhGqTMrrTBNtNA/PFLGfoJPIs/FDZQT7o/ oW7RtTDhofpqkGbkY2OGguJrT+ytiMvjoiz1qk45CHir5yKLYvcbp0yRRG3lrUJOiW6dIugCggTeA 9c9GHEK6dKtlwzGjqiL49tfsM+m6B32iq2SnTv9QixWAFxfN/9/C9ei2So0CURsnf51Bk0aNwgHd/ wdYNszJWP9IgUe8m2mXg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ldaUL-00EEMe-Ea; Mon, 03 May 2021 15:28:05 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ldaT0-00EE6y-37 for linux-mediatek@desiato.infradead.org; Mon, 03 May 2021 15:26:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:Cc:Subject:Message-ID: Date:From:MIME-Version:Sender:Reply-To:To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To:References; bh=EI6bZyecXV+D4mAvyW1zNE2tx9yP9EY1VWyGEKOhGs4=; b=xlkjrfLY9f8I3YRfmAzxDNeBIs 4sOcM+Glzg6gfrLTYCF5DPWWBRjwz4SSP5NrM1JxF+sD3iBLP4D3CJyzRXHAyRUyGgi4FULHa9pDn UaUDrPubiFo3jjpjaPwN2L99tVcqve5p6CCCW3ZWBBkrVtMUM8yC2TJ3Ohcrz8X0APHvaE7fE2ss5 Jn5C0nLET4fKZ8yUAzyxkxDOwZvTjDoiWB2UJAUYJnLbdVwREeQTknIIviFDQmX/8UjkF5hTGaP+Z w2xwIe05sW7nERWo7CZJl14gnYWgmWG/T7XUwcWLL1CgrKd9GF1Jq/2v/r1iSoMBhYmgckhL8PyQg ngmx1BhQ==; Received: from mail-ot1-x329.google.com ([2607:f8b0:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ldaSv-003Av7-6a for linux-mediatek@lists.infradead.org; Mon, 03 May 2021 15:26:36 +0000 Received: by mail-ot1-x329.google.com with SMTP id g7-20020a9d5f870000b02902a5831ad705so5375867oti.10 for ; Mon, 03 May 2021 08:26:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:cc; bh=EI6bZyecXV+D4mAvyW1zNE2tx9yP9EY1VWyGEKOhGs4=; b=qeuOlliDGX/UXrFBQRGA+wZpGmrZ3HwhDOaBcLLbNorJFBQ4hQ9Q/6PhUtBuNeS8Aj au6pVFpGyoJApuOoR9hMvcsM3O/ekucc0pvsmba0X3h/ETYu8raP259toJ+B9EQmVv3U noQ0uvWbA3AQWM/Qk9dBt9TfYB86MQgd8kz3agg/3D5fZKr6N1NOHdVpSHKhVHkpQlbO GeOcTWWtTFUZMM+V3A3Em2sAhxFybQCvJI/ak4a4jeiX+fIB3AtFhVdTWrFtg63tw3xd QOgP2+GbpbYXfLlNvbH5jOyPPPAz8hsNULBRqJWfisA+Pml5+1NmzEMm7R5HvdDBlBGU Wc/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:cc; bh=EI6bZyecXV+D4mAvyW1zNE2tx9yP9EY1VWyGEKOhGs4=; b=lTjWk0L9v26XSIgESE2UyzewBTzrhtlFf5bTv/KcBlLQUi1kYsltS4kWO8dNyancLe HPZ0Ah2d/XgSjDFfgE9GwNlHui0h8lPfp6WLnutdeT4YUVjpg48rnZLw3LbMsaNCtTHW y4MzVkxhMXLNICeHjNQvNNE0Ymz88+EUMqH4l82wlR9mg3xM6zmj6htDL2euCUx3aJnP /nkqpo4EA6wMdBEC42w9N0M+F9OZJfMNppVadgzSZ08X+faAfeGV+qxfma3X8tNKOT/7 PjgP0HvKtuEibKw3dbRoe2T2ST2fOWoEldeU7vqv7x+x6/XSWyZwy0B2T6LSnjl9nROD h3tQ== X-Gm-Message-State: AOAM531NvcBic78mhjEDpVghfZ6dJYFJuiDtTLG/N2k7Fm6Q2GzuCExu V8nMtNqLCczZOwxLKI9M+4FLnhow0zNEG5HTWqXKnQ== MIME-Version: 1.0 X-Received: by 2002:a9d:2f24:: with SMTP id h33mt13304201otb.128.1620055591994; Mon, 03 May 2021 08:26:31 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Mon, 3 May 2021 08:26:31 -0700 From: Guillaume Ranquet Date: Mon, 3 May 2021 08:26:31 -0700 Message-ID: Subject: [PATCH 3/4] dmaengine: mediatek: use GFP_NOWAIT instead of GFP_ATOMIC in prep_dma Cc: Sean Wang , Vinod Koul , Dan Williams , Matthias Brugger , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210503_082633_263459_CCCD83E4 X-CRM114-Status: UNSURE ( 4.86 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org As recommended by the doc in: Documentation/drivers-api/dmaengine/provider.rst Use GFP_NOWAIT to not deplete the emergency pool. Signed-off-by: Guillaume Ranquet diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c index 249cabddb7ee..4711bec04b98 100644 --- a/drivers/dma/mediatek/mtk-uart-apdma.c +++ b/drivers/dma/mediatek/mtk-uart-apdma.c @@ -349,7 +349,7 @@ static struct dma_async_tx_descriptor *mtk_uart_apdma_prep_slave_sg return NULL; /* Now allocate and setup the descriptor */ - d = kzalloc(sizeof(*d), GFP_ATOMIC); + d = kzalloc(sizeof(*d), GFP_NOWAIT); if (!d) return NULL; From patchwork Mon May 3 15:26:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Ranquet X-Patchwork-Id: 12236287 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MISSING_HEADERS,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62DC0C433ED for ; Mon, 3 May 2021 15:28:19 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E7DCE60C3E for ; Mon, 3 May 2021 15:28:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E7DCE60C3E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:Subject:Message-ID:Date:From:MIME-Version: Reply-To:To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=em4Q03K+rZorVc0/ttJDOAaqUS/wku4gnScU1HcyDXU=; b=Yzdgm/9ZOGz/GL EMJPojyjQ9OIeBSNLTmXz1uK1fu9GK18lxYV07aCNssG7vjNa1tlnT9GqyDFYxVdgOTtykwCPj+lc R5HO8TgMsUPUUh2khvd0Kp96kv5CLvyd+qNo+WUqxt4oKVlE7zWsOJkszB1fOgQvvnIXRT5D4p2bI byQXmDKR6FcZM1AUQOmBjRBcBNTPFQxaZGbr6aTb0IUCFRocBToX1BspzhD4rnqb1W30vzlbo7BCI i1rZIshXFguofylURX3CPdbhMTb8UHa13PdPp8N/teviNwQdmG/UDuLo1UvoJS42Y1WxBqbSoS1Ja MrcNFuaPOFLOzZ/TT31A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ldaUI-00EELr-P2; Mon, 03 May 2021 15:27:58 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ldaT0-00EE75-Ae for linux-mediatek@desiato.infradead.org; Mon, 03 May 2021 15:26:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:Cc:Subject:Message-ID: Date:From:MIME-Version:Sender:Reply-To:To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To:References; bh=KYXKPtE2VZh6dALBmahX3Lb0HQq8HVq0AUpkoo7GpCQ=; b=vnRw/PeVv4lBAn6d3uNFt7nNcr OT94Wcqw4SnuA5AGR+eFxjyCigW01HGPWi0/vYMSr+u17XIO/Q5eHDYJ0rBX+BN4I9Cp9wmgh7V32 uAdNMwqCRU8dH3xenjboYYBJnV59I9GFE965JrxQRn8IN1TQKAT1fUIOXZ9xpgrczYTY+BDzAb8Oh SQpqSfG3gozPjAfKx03PYJyKkorZKBHCgFM9MpaNPhJLitm6WoAY8bj79B+u+68XRxzhUbMyP5lJC NlDlF5ZvAQ6fy98YHF6gjczlqy2o0Wey/yTT4QH1X1uotF2ZXfIXEHk6VckFb2kCA4eEflQsLKaVk ZWWXUpNQ==; Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ldaSx-003AwG-22 for linux-mediatek@lists.infradead.org; Mon, 03 May 2021 15:26:36 +0000 Received: by mail-ot1-x32c.google.com with SMTP id n32-20020a9d1ea30000b02902a53d6ad4bdso5409464otn.3 for ; Mon, 03 May 2021 08:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:cc; bh=KYXKPtE2VZh6dALBmahX3Lb0HQq8HVq0AUpkoo7GpCQ=; b=xmbEQhxke5pWHBfmJSrThVbWD6yNloeA2luzWWZqnzEUacHlBE9+p5BdJi3ay7KHeM EuMcX5IaisYJBmG+magxxmg5YuD04Gmwg7zkDBgqouHeuxxIcMUOnP8AYfGwVW3DMeNz RsXqNHfeYCEYU4hJolnlkGJ72xZ+yP8N1Kv5W96RED8BM5BQucoNaDhHjUMwLQZC24wl ZVBvPEqsjSvYY4Ic+mnHQs4tgU0zinx9OPGvC9YH2wQzKGCs+fkp7h5Mh2BpLTxXdXBu RYgOmbb+6IJE9/Eyo2w/veS83rXtUE5tF3PnuxfyHB+uJGQkLVMfY+DoCXkit+rXY+mH tPAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:cc; bh=KYXKPtE2VZh6dALBmahX3Lb0HQq8HVq0AUpkoo7GpCQ=; b=HN5ZDXtDErEyUMSKQ2VznlzT/PCSxEfcAxgxROioXy5TdH38TUbDSEaauOCMkVd+qE QOijxyhF3rLKhYGQIw8ubDhsEl8UzvWhRwW/XOMo8w1AYQxsiqZntk9Yz2sAUId9bb6P lICiy709OSPwLclbqWaWcvCCBhb+HO0Y4QIMceXJ1a1xM7thnzdAmgDlyqUvA9ynSl84 txS8p9R79w1CY4X7t7XtwWIiti4DqqQNr5LYUd5nITfN4gPVGFbFLz5BeZSi5rNXoV2X +uCoXYmzxUcSIFyGThzuNvwC92OOWDjKoXtz3bd2g3YPGlI0FksrJRwl6iuuK9lkEEfb /Feg== X-Gm-Message-State: AOAM533EY/26kLMJlunkrZ0CeDUUCwLvirIKb5XBIIaVqnQYZcwDR0Kd yrwCdGQdHJKlP8BAK7jAS096kbVTCfI5QyiaLGogZw== MIME-Version: 1.0 X-Received: by 2002:a9d:4703:: with SMTP id a3mt12624906otf.136.1620055593857; Mon, 03 May 2021 08:26:33 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Mon, 3 May 2021 08:26:33 -0700 From: Guillaume Ranquet Date: Mon, 3 May 2021 08:26:33 -0700 Message-ID: Subject: [PATCH 4/4] dmaengine: mediatek: do not hold the spinlock for vchan_dma_desc_free_list Cc: Sean Wang , Vinod Koul , Dan Williams , Matthias Brugger , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210503_082635_106591_D2137F59 X-CRM114-Status: UNSURE ( 4.44 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org As there is no need to hold the spinlock for dma_desc_free_list, Move it oustide the spinlock section. Signed-off-by: Guillaume Ranquet } diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c index 4711bec04b98..ba43708f2a93 100644 --- a/drivers/dma/mediatek/mtk-uart-apdma.c +++ b/drivers/dma/mediatek/mtk-uart-apdma.c @@ -431,8 +431,8 @@ static int mtk_uart_apdma_terminate_all(struct dma_chan *chan) spin_lock_irqsave(&c->vc.lock, flags); vchan_get_all_descriptors(&c->vc, &head); - vchan_dma_desc_free_list(&c->vc, &head); spin_unlock_irqrestore(&c->vc.lock, flags); + vchan_dma_desc_free_list(&c->vc, &head); return 0;