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: 12236291 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 D8F5BC433B4 for ; Mon, 3 May 2021 15:28:51 +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 270FA61176 for ; Mon, 3 May 2021 15:28:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 270FA61176 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-arm-kernel-bounces+linux-arm-kernel=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=zTmGUXoQ6uML/HqB6is6iISLFWNYx5E2nV+EUnHQT34=; b=mdYyN0I2FIYFN7 I0DBdBhN6du4WIaYt3pewQX5g+xHbYX35a1O6ty1wAssDIkWKMOlhtiRnl/DASI+LtQDv6igKVOMN P799iW+YCSOLpOHOFe0Dc1xVARxog07x2nKMa7NjtVnnXpETuf9Jl75FZHyFSjy72VmqSDd3P3+Wx LQNh1NPM5DPshsX1ZtbS5y8usm36x2xV+iBsFStqXKWL6LBMSam7jgI4Y84hfTejTqmcDdY7DM2dw LI40sJT4JTJ9e0c+Ph9bFilMqhH/dJcfULJK3rgO8HBnX13clzxUZIxRCJ1EPqJg4FPG/MgNhs1R2 691ddJamg5Zy7G+FAdcQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ldaT2-00EE7R-Jn; Mon, 03 May 2021 15:26:43 +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-00EE6T-UP for linux-arm-kernel@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-x32f.google.com ([2607:f8b0:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ldaSu-003Auk-Bp for linux-arm-kernel@lists.infradead.org; Mon, 03 May 2021 15:26:34 +0000 Received: by mail-ot1-x32f.google.com with SMTP id d3-20020a9d29030000b029027e8019067fso5362377otb.13 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=lIpU5hh7ZrTjPpR+ju65WI3kFqmZYda8frttoyLU93GmkpsVEKJoorDvF/uLoKzVI8 6sm5IeZN7CQ4uP3vRtRxiNrBu7XHoxvV1b6BK8HU3fiVAYJDuLHNxqDeUREBvxYqGv5H BMtRS6et6kRoFsB3RalVLMckL2JnRMcX3qsI4uTHs/Nt0j8Rx+7tFyMSz31K0POBXExG TNVLvD+eA8tdLsBL7PSL3DpNadmguEizziB70X9fO8z8V6plcCIrpcsU3ozJdpMMHtwD WRe9Z6xoSnIoJQFD9mJepzIMsqmVKqWTSE3T2EmkZgacOHjRz3wCLabY5DIAVtBUE73e JaEw== X-Gm-Message-State: AOAM532GlgQ8Hr6aV28zoOq9duVFB6+Skx69dMcnD0aJBRda3aapeUFq 0keOka7lL1aeYE7ZqQGk2SKSwnacvTFLYhRkl88IeX3ZKcs= MIME-Version: 1.0 X-Received: by 2002:a9d:2de3:: with SMTP id g90mt12928707otb.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_415165_72AA8B65 X-CRM114-Status: UNSURE ( 6.08 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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: 12236293 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 63154C433ED for ; Mon, 3 May 2021 15:30:15 +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 AE35561073 for ; Mon, 3 May 2021 15:30:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE35561073 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-arm-kernel-bounces+linux-arm-kernel=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=tXH2nONZ+6JWviTTMsykov4SVZbsJqnyULp/FT44CSs=; b=AluBxZOk5uE5jn Kg+0IkE2sjlOcsm5QlpiBmOUj+hxF+PMbPKPCTlgPDOm66wgv9tXoNAXYNwBQHYKC1D9f36jok0hq /g4woOT4pEf0Zv/iGRO7fqp+RPXzahYYQX2LnbySkv1foteeGZXIGeOxGRS5ACkuodbgklNHCrmUn 1saqKm7kpOrMoa/T12OjDq4tROALXxPMhnn70NkHX2rbvtrrnU/wrHG0OsciB+rrqRGhhWRkuDqWi +3cwB7E8bMc+BlOMOTWh/52XP7ZgvCzp9w24Y+vI3eOWseN8LcTcMmTLmJnJ5fXf0/o6gjKoLV2Pe 9DMT/GcKISzBGwPI7eig==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ldaTc-00EECs-St; Mon, 03 May 2021 15:27:20 +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 1ldaSz-00EE6k-7B for linux-arm-kernel@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-x234.google.com ([2607:f8b0:4864:20::234]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ldaSu-003Aun-EY for linux-arm-kernel@lists.infradead.org; Mon, 03 May 2021 15:26:35 +0000 Received: by mail-oi1-x234.google.com with SMTP id t8so5772491oij.0 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=In6BCKTnmta1Ok4z5I6BkuigYsx3DAVuf4RhTfMc7+WrMlipJ+sFl5N4vfkisY4Yln ogr95dZdtpEHhfjL3ZMQKkYXdGMw7qmYIXiFecgr9n1hyrHJ2CtuHP6VAEEccxOOjmB8 BxbHHL3vQmSfP7WyAURvIZLRBZ069uKQHn3BsarfE7W3Iu21LO+qFezjQ4aIZpGNYW7R 3H9GmOS3ddVtj84q0BhfUQBb02wVImpdvghhO3DPyEml2GMGJZybDPSIfttFoG5/Fh0K 1L/axzuXjcTKlH4xlazrRd6y2kSEDdcHka1Myrr3bdFXy1PFQree7yJGAimP73Stmzdu wn6Q== X-Gm-Message-State: AOAM530+fEW8exWgia7LRAjQO+H5Na0oY7d2YEzg/vlUO2jh97yqoT7I f31/NlpGBuD0M14o+vk2NENYEd6CE+76A0DHOilvww== MIME-Version: 1.0 X-Received: by 2002:a54:4f07:: with SMTP id e7mt10487613oiy.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_520171_747ED90D X-CRM114-Status: UNSURE ( 9.92 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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: 12236295 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 7EA07C433B4 for ; Mon, 3 May 2021 15:30:17 +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 3A7AD61176 for ; Mon, 3 May 2021 15:30:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3A7AD61176 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-arm-kernel-bounces+linux-arm-kernel=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=Gwbr3NTBvHHFv2lrlpii05fznIvWjyHVSP2pDLpDACw=; b=f/BPVa3GotFj0i 1wXakS7KJMP4HHO9TAFgei/ELHGL6Ohq782kcU0tZcDq++6tGAfWg5prHQ/cZZXX6SACyw7F00To0 +hT0xIoEhP12YjPY9S0emmRBM5HoDED2M+D0XvnRR+FBfz3WRgdwd2A/KDyWzRoAd7Gm2KGX+tSyZ foZvMravLv/vmWutFHmCykvA6ruteutyu1rZ2ZyIWWy2Ctk7Ys9tcLGuJnNHBzCx0zaLF83PO527y 3/p+g8sWqQ1yVv46VGjV+ZiqDoZjUUcOD4oZHU8JV8haBXzZB/38EkcBmKlw+RXfq4NgU234ItdIK MlD34z5VZ4ZqGTqfuhwg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ldaTx-00EEHV-2Y; Mon, 03 May 2021 15:27:37 +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-00EE6g-U9 for linux-arm-kernel@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=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-003Av8-6Z for linux-arm-kernel@lists.infradead.org; Mon, 03 May 2021 15:26:35 +0000 Received: by mail-ot1-x329.google.com with SMTP id x54-20020a05683040b6b02902a527443e2fso5410897ott.1 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=pH4DEw4h+egR9Rg2ntHou0AuD6AkpccYRF6qN+yUzUXsJCd9u/an5TTiAx7EvrrQvG Pbr1WSKXjSb5MNZMpG8MJbdrzMkTy55lNdFDfa305J3AARlnf4G/iaf9NWmVyCUX1aMA RTwGygUP/a/PG6ZtZ9l2mUQatcAfch2I9Rec1x31G6ZEX8OAIAoSgOIJkOYEJn2rkfL2 eX7ROUSTPUeDh7b3i1qHQWrSBjvWIlEhwFQ1xy9HGYpNEP3yI42fGUGV8+1w/SlfwcGF 87+idC39bP1HBrJOUp1ixIbeouKSRJ0ld7RN8sawNS1XkRyfV7QOjdSSlDx4v4I5w7uU 362Q== X-Gm-Message-State: AOAM533XojKUg+YpQe+1Bm4Xjc/TFjPxlDK1ZhAw/qe6QCk9to70Oxk0 RWxBFiu26MUjNvH0ABi62/DemfFd1ebkwr0/bn8a4w== MIME-Version: 1.0 X-Received: by 2002:a9d:2f24:: with SMTP id h33mt13304195otb.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_261122_3161DC9C X-CRM114-Status: UNSURE ( 6.17 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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: 12236297 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 B233CC433B4 for ; Mon, 3 May 2021 15:30:44 +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 4A84C61073 for ; Mon, 3 May 2021 15:30:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A84C61073 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-arm-kernel-bounces+linux-arm-kernel=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=a8EylywC+sS3tN+2WbF01TkfRdjOlrW05pNHrjQ6hKM=; b=dTRNF0graZ7EvJ 74tmc4MiB1BjwDrK1jetpTWSClcUktuLllX99947EV31X9SigFpx//spa2IbU9CCzI8riz8XlcjkD 5EKv+vHi1qKjyYoP7TaIk8thJIWdwBkb/7yX4T+Z6oiDZ2PyQL3m28aSVoau3aFCvee2tX+TJ5rJ1 8Htb+dtYsVwqhULEWPw34brkRLPw/jNvAYf9lv4jv6HXt3DJAYNsmL+PS/S1mG2uHZX71V5LeYqC9 Lj1BgVfX/vXhlg0zO2Fvwv2EOcz/T/E6q1dge8C4tfwcT0A26YD97RfKAtu7Dxef6d+drRixxl0Zf VI60W9zYsIoNxj0PK+og==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ldaUW-00EEOf-Ac; Mon, 03 May 2021 15:28:17 +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-00EE74-CJ for linux-arm-kernel@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-x329.google.com ([2607:f8b0:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ldaSw-003AwF-BD for linux-arm-kernel@lists.infradead.org; Mon, 03 May 2021 15:26:36 +0000 Received: by mail-ot1-x329.google.com with SMTP id b5-20020a9d5d050000b02902a5883b0f4bso5415108oti.2 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=Yc+v94qyiQGrCNfZdnx4P/049lGL+G2uVdSuY9hE5RvoJIrdqfc3TDhIcuB1SM4L/Y gr8vLE8GMo/4+KCnyO183PiglZ72USyou62myQmUTgARpI0P8AQTRIr7rdig7UeFR1+b pdTVF1DVaCwLzgfD1IejhN16aNjQShLoDXPBraEMSZcDUs92SCvJLXE4WHoyrkyLPHxP 6Nm/Xbfk7EeZ2KmRXTdpBamDitrVBpODxG/Oq8T8hL8Mm0V/ysSpef0rt5uilzBMIUgV qbutsiMwlJvNKR8Z2irgVmWMTGHKJap4imXD2VUpxN9LhtjXQTLKm5bJdO+nfvAKVDnJ 4F2Q== X-Gm-Message-State: AOAM533E83H8UvxWOUTzY3ur31eo8bt9+vqH+6PzEJURmGVH/Rky8SDk yF+kzLKnw9LR89JfI+ZYGlkSdtiPQwD7OXFoTo83zw== MIME-Version: 1.0 X-Received: by 2002:a9d:4703:: with SMTP id a3mt12624909otf.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_082634_410877_B2639297 X-CRM114-Status: UNSURE ( 5.57 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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;