From patchwork Thu May 13 19:26:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Ranquet X-Patchwork-Id: 12256337 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=-17.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,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 C99B4C433B4 for ; Thu, 13 May 2021 19:32:34 +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 260E161406 for ; Thu, 13 May 2021 19:32:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 260E161406 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:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Q4AX5/vw2rQwKQExdDPffHHFGLkf8PLBd6kmad67MzU=; b=LcHPoVneLyKg3k16fZDdEJqhh wIjNIFfXVuYgf/cdDCQ9aQaSOvc7oJFuiqX4g+Cdhp3O4u4MeTeILlK40Jr8unNbSttJl/SBPe1nG cOIqtAQeZKDoXN5ff9ru59DynnoqKHrPBIpG9uudfhkL3F1c1sU8qUOfE3jo2RW2dE0WAIiG56OXF Nr0wDZWeXJt59Eo0XT8AyIpdKDoFVPEoUBpcjmfAoNWF+ql+LT7J4N9Up2lpTyRKIC5ZjZ1XYV7EA m6pKFi9l8lSAbJagk7wkkEVx4Ve0xcG6Er3lQBmCqn1WTlkouPS5o6ExLBqg0sIyEXszWc0a8BwOy f7CbET7kw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lhH2E-006Gkw-98; Thu, 13 May 2021 19:30: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 1lhGzF-006GVZ-Ug for linux-arm-kernel@desiato.infradead.org; Thu, 13 May 2021 19:27:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=eRxz/pWXTALO6H3I0wjEAHHa6qtt4usgfqtoKz5U3Bw=; b=J/nSNykdlPmLSs2d31Ng9LgxcU yYCDV06i0SRljli5h6BpNTF+W7ups6Pn71NYlpzeVPZni1QwhQqaN5t3oH618zCTvCzGv5APlWYku o9GmssXME3BBrQlGCqG2mMMWrAMcwkPXgrM9zsXTqiVIx+f/0Gg+vmKqp/AFzqK3tYnduTWHpGkFm 9rDkT4IzSuckDFPsyNJNuSP7lZjKoa9hESc0XeTbD1u4iqCzkt6cUpBu4b+OX5GybdDfwhfYnmGYU acDWTEkufyut49VUHnOQIdQRI5vrsfxPI8NfkQq4fPVtmFy5f9Z59NhQqzX3qlufJq6ZyJhYkxKdS UBLK1ndQ==; Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lhGzB-00BTXm-R3 for linux-arm-kernel@lists.infradead.org; Thu, 13 May 2021 19:27:08 +0000 Received: by mail-wm1-x32d.google.com with SMTP id o6-20020a05600c4fc6b029015ec06d5269so397897wmq.0 for ; Thu, 13 May 2021 12:27:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eRxz/pWXTALO6H3I0wjEAHHa6qtt4usgfqtoKz5U3Bw=; b=SDoVIViQbUjjhanbrPpBJslUuhhXuGOUixKLM4aM/Xni8UB3PfZUwBqSdnqyXcHmOE QWegUOH0EPxlW+QrYpS4iyzpXPEZoGmDQzlxAglfvi6Y1N6q4Dn67gbq7WZQRM5drQXL rmrjV3vScos/2VteiR6GuJdaSi0YT8btL3MaVof9zulzqm7UOk9M+9IIDdkkAcm2BlQ7 5M1mJ8U+FCQyn8PDVJwjITjPifC5lD21oM5IVKdHUghZ6Dt/gM+NI029xI4uAJDlae5F QHLJODjN4XMl7VO4eNkJxB/yi/CjBPnHCwWn4qymufqvhK+nWYB9o8ueMSXS3ZdbfrPz s8Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eRxz/pWXTALO6H3I0wjEAHHa6qtt4usgfqtoKz5U3Bw=; b=KPANAFHl/QmhXjlIEmvH+Pxeo1nkgvZFDwt8dj/hLpE/ubnAeHWABROGnynqbgX8wP TBbRmdhY5V5CUPb2miD1yboiBbAgq8xzQ73At/CjV4KWntryL9aky85t5Uy5S8Y5tnuA wx69W3Pn0rNfmTSkG7V63rOPGDfXcYyTc1fbj5ceJ69n/rVta9fvPtaLcTlqQcU0BPxs qO922vZF87Z76w2Dqp7ha7hOdqz+QIyv2hwv8+OBEbYu/qMIlPCVtvWNBbgm0QLj0IBz EibQ5y5Xcs+8N7Q6AfVxHPP4U2BTsAUoQL88E6T8ki56ka2wECdSZynE2qDZ3RAFqgH2 /50w== X-Gm-Message-State: AOAM532QTIt15YXUHulmTk4tKzbbmkvZUvbvS6hiDcN+/Y7rR0jLWnfQ /4LUveE5dbysFuOjhPVwhiD/jQ== X-Google-Smtp-Source: ABdhPJzyMLZTPcPNKyhY5TxDvljyGM7Bn/ftFSKMJZJ7ETtYuncFkrWBVj7udx7AfFFx7pB9Mel9Nw== X-Received: by 2002:a05:600c:4f04:: with SMTP id l4mr45170585wmq.18.1620934024035; Thu, 13 May 2021 12:27:04 -0700 (PDT) Received: from localhost.localdomain (2a02-8440-6341-d842-3074-96af-9642-0002.rev.sfr.net. [2a02:8440:6341:d842:3074:96af:9642:2]) by smtp.gmail.com with ESMTPSA id h9sm3053621wmb.35.2021.05.13.12.27.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 12:27:03 -0700 (PDT) From: Guillaume Ranquet To: Cc: Sean Wang , Vinod Koul , Matthias Brugger , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] dmaengine: mediatek: free the proper desc in desc_free handler Date: Thu, 13 May 2021 21:26:40 +0200 Message-Id: <20210513192642.29446-2-granquet@baylibre.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210513192642.29446-1-granquet@baylibre.com> References: <20210513192642.29446-1-granquet@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210513_122705_896558_FD22043D X-CRM114-Status: UNSURE ( 9.90 ) 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 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 diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c index 27c07350971d..e38b67fc0c0c 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)); } static void mtk_uart_apdma_start_tx(struct mtk_chan *c) From patchwork Thu May 13 19:26:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Ranquet X-Patchwork-Id: 12256377 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=-17.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,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 D2987C433ED for ; Thu, 13 May 2021 19:34:50 +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 3110B61406 for ; Thu, 13 May 2021 19:34:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3110B61406 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:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Xm2V7vlM0HkkbFt4AXn5+a2mRu9zyoxeDwWQGzX/4yQ=; b=Kv1/FQ0rATkDWsOE0lINDTh/J PspKSlQ+o5mgz9GFMPiDyO5dEn9xnQwNlQx3/3lASdJtQ5n+BgXIIPrHLPSr8ERtPgvy2YoRTR/UL 5srG8iEF5TwRC8tMGXgx7aBOQEgRiWz55Pu+piFff4vDO3FjiRIHtn0avLMSE32ZkkwJYVZKHkD/X KQdJN9hpMINzV1Xa6cix3W2F2DxgjvAzsSS12EZuheTfna8PRI3r5F0klLxEKikuCnhO9ZXSSRtRz wjZmL+/IgeGlnD4B9dpJ7FGRMmqh8UAC08ZitREYREKTeyIwjNnyjT2uvLvF5CeFYT5+3BQFTc1x8 cjPEh+HKg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lhH3F-006Gvh-1N; Thu, 13 May 2021 19:31: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 1lhGzG-006GVd-27 for linux-arm-kernel@desiato.infradead.org; Thu, 13 May 2021 19:27:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=j3rMCST+HXWYznkK+d1QOqqcV5rur8wbxkYAuvymJ68=; b=AV0/e+c3ipXz/T5PJRr5Rsveev lP9Wk07CUuNh8X4MPRmjVf6nn1a1qD2i3Q6PgtuzcyYSHp/LHuDp/WNp1U5pTW+mLe+hAUluycCJr ClDea8rq5OBcdIRURAfmYepuSU2XlZb2iWIP8JXlWleKcKt6poIh5SCIW+t3EWY/ZFUhl4rCUvq78 eMsuRoVBG+sqAQpUkkx0Ib/YeXOa7xDePAFKvtgoTxAfwnxHh3s5ORaeFoa3YwCW4FhuDYk4qh5yP ltfo4ncAfZD7kXqe9HiqyNGPd6Y+ZMrBNl1ZWCHPMwaT0Gl6lp+1F7a5GUcejAZm8qVt0cZKjjhjQ SMoIGQrA==; Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lhGzD-00BTYG-28 for linux-arm-kernel@lists.infradead.org; Thu, 13 May 2021 19:27:08 +0000 Received: by mail-wm1-x32b.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso328065wmh.4 for ; Thu, 13 May 2021 12:27:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j3rMCST+HXWYznkK+d1QOqqcV5rur8wbxkYAuvymJ68=; b=iXGsYQ3aCos5lh8Flu1CH3c2WhrNHPiobWA3CJU8S2Zz8hNAfgpCHFOZebov7jBkbF Wn2unDtn96RcYqNoxyyGGPD6cB7p5z7kbh+o7UPYKb92JhQHnaNnxLaRDB6euEqC2xlq WHPQdkleg4+U4bXIRxja/rnK9wDkRugP0Qlr3/pZ8An6N/QxpiV/2TpPtseqvZYh1bA9 bJCWMYW4pHloFhJdImpV4B9182jUG7IbZlnadtCsoePmJ++T/G+eDes89+5sRrmhAh6r rfX2dOKLlck8NjWQv5xIlCbBzdsMzzO7PTmdmB315QSM3ttPdpjRwQBqT4rr7ld3o4+t xkag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j3rMCST+HXWYznkK+d1QOqqcV5rur8wbxkYAuvymJ68=; b=TkFV+QEyNsHCxgx5XFVydelJQE1zXeUW71YckaiRNxGCfqSJPJ6CcAdj5cVpIeYynL 9cfQj78m7tT3OzLjUFiOtK0JJtI4GWKMaq1/z64Ms0V+ylwzepl9F+YK4uR4XsAMFWhL gvV6c17vHM1lUsBdL3v3Cx2bjt4yIsJKh6G49jJlf52xY/Irz31ni0yxEVuD2WkS9JDb MX7Vsr3WjwEhGcJI5WmIulDmSbGB5ejWw9zaODVMY1mM4br03Mgc/xX2UYTi0/uCYMQ/ t5vAyeOtTpfYMDnKFZN0O2HoV77OxZZpTRcCbBBrRGb9vtwdpVctGeT3TVF2XYZ0z2eS 2ipA== X-Gm-Message-State: AOAM531H6jsPosvDox72gKg9vqFztclfwDZzri28dI8v9IJWZWPTZqCd 3GAOSPHapkmffkA4RXNSTecasQ== X-Google-Smtp-Source: ABdhPJyX9nit3J47iZ6CZSouR97dqQsMArptT4kaSpWbjbao2AoF2xLXk9D9A8B8xJ4iYXcXD+LbXA== X-Received: by 2002:a05:600c:4f4d:: with SMTP id m13mr45992727wmq.4.1620934025298; Thu, 13 May 2021 12:27:05 -0700 (PDT) Received: from localhost.localdomain (2a02-8440-6341-d842-3074-96af-9642-0002.rev.sfr.net. [2a02:8440:6341:d842:3074:96af:9642:2]) by smtp.gmail.com with ESMTPSA id h9sm3053621wmb.35.2021.05.13.12.27.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 12:27:04 -0700 (PDT) From: Guillaume Ranquet To: Cc: Sean Wang , Vinod Koul , Matthias Brugger , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] dmaengine: mediatek: do not issue a new desc if one is still current Date: Thu, 13 May 2021 21:26:41 +0200 Message-Id: <20210513192642.29446-3-granquet@baylibre.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210513192642.29446-1-granquet@baylibre.com> References: <20210513192642.29446-1-granquet@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210513_122707_109370_BD248BA0 X-CRM114-Status: GOOD ( 13.36 ) 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 diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c index e38b67fc0c0c..a09ab2dd3b46 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); 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); From patchwork Thu May 13 19:26:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Ranquet X-Patchwork-Id: 12256375 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=-17.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,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 3D6C1C433B4 for ; Thu, 13 May 2021 19:33:07 +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 CC11F61404 for ; Thu, 13 May 2021 19:33:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC11F61404 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:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EOmr+boTQuYuJhpvUlkViqJo8y9RXFe7ZpencmwUtAI=; b=JufcLw8B/sueggV3mAZBeQT33 Pn7ygRI3YZVIgRFuGAte+58SRtuJVEDFpIpgp6uFHzaxMGazv9qTIcmRXVOJ6UmKNW8D+4pDyibCh Y/pjwtwdAV3Eq+/PC6noE6xG09bAbvORqKUlydlJhDmi0yFvQY18gT11yCtJN/kc3GxdXTYl6W0A6 5jSq5tV9SF7ILVsA7aO8KWDItpHX/8AVamnXyIT7V/perQuleYA8HoW2cjswDnupdguB2aLh9sO2y vSyl5uuOL8F8Is0Vseu3Kku0A5EhoPtpnZLvjCfEljGFF3DI75RaP2QhuJ1yUyIacrw1lBZJUThYY 8KgghdKIw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lhH2h-006Gp2-2m; Thu, 13 May 2021 19:30: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 1lhGzG-006GVf-NZ for linux-arm-kernel@desiato.infradead.org; Thu, 13 May 2021 19:27:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Hz2oyLCaodXd740ljA7xd9Idy1mmKCo0jqV0VyN8IUY=; b=dohBC+DlhmegBqYOuRHjw3ztXp K62yiqq3NPd14EsAcP9CQXQU8LGETJ4aP+y2t81MDLehvmfPgp2YaxY2hUPd3uyb4JpbDUJww8D2n B3s5/QyoPiiE/9211hTF72zPSPRx6EXr75+/ZDGntFjuis0JKbGNgtTaIqqnY90X3OLQ/fw8EoIhi N8B1cUGMWTvsyyLu8ocbsJCMnrBzbJ5GQDWhsTlFryDC4B781j3pXIlDPoBkNxfspVOApRXMBZCV0 yT5n3fd04XyjK+WQlIm4C0f8QvSJx5XxXTbrGND6fy1ZgTRAvfTtWUK3I18IRmDmhd45vTL17T4/m 6ShBZ0Aw==; Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lhGzE-00BTYr-6r for linux-arm-kernel@lists.infradead.org; Thu, 13 May 2021 19:27:09 +0000 Received: by mail-wm1-x32f.google.com with SMTP id n84so15139756wma.0 for ; Thu, 13 May 2021 12:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hz2oyLCaodXd740ljA7xd9Idy1mmKCo0jqV0VyN8IUY=; b=sZXPaAsyf4ffDKyjs8O74Zge/X6jI76n+7YbKvJU+8109bI8MJgtyqcVubGJ1uWW3E yDI9/5+ruZ4+gDkA88wjjw7c7yGdcOc5GeYdkAgSZE/HDGkj6E54ITAKOUGug7YWoeGE 2hPNROBUj4fBoXzzlqCyO0VisN7iG4jbaHqw0FyrMUMX2IRNx9ztDhzXBMP+JLfD8ZlD +J/1MFdbJ1AZEiyMFKQhzoXwkDk/uzYp0cQv1BIz/zE3RbspfofQ8QqrzLHd5CH5i6Jb 5X1We59Js9IgROMufEwo3ZfD24fE47qy+g0tKH0ENk02rjwb0aKMBHniaUD5g41LYQC1 zIag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hz2oyLCaodXd740ljA7xd9Idy1mmKCo0jqV0VyN8IUY=; b=qPtWeDfcVXMGmJPgMpUK1yi0KyW5Dp36IUS8qz3v512VXMpVyDecyYpud17Zfgtm7a z+AFS4cMmsubhdm9m1sQC+3cpOU/B4QVkJ19ziLTmYJzr+AEs55gkVz0I2iF0+wNN1zI pL96gXpfNKqpSqSSY9y5sQgcazQhAotB2uPFPKCEp+C/N/6iV13GaZLW/P7dDQvQPlc/ 5bOhmIF33tnahEnn8G76Ejtd2O4dp0a5S0lAKACudvRQgThIrhTcFEWxdPHXulyVhTu8 4NZh5bj9VPQBN3B78kL4hkdJcOcDx2VenyttDe0dLgDsoVofwECBnH2+tnWjycMQy4h5 N3Ew== X-Gm-Message-State: AOAM532fWF0VF2AD04nsLUCV6RCDBnTDuq1wzE4GYQFIg6HfX63rb2s+ r2uCSCtPg1kH9ZPGYbDhoEtk3A== X-Google-Smtp-Source: ABdhPJyzpUQgQL+VR9Dht+XY5fDnyA8jmiEPMMbUTAkreqWtyug65TxodZHPUV0tmb60GFcF2HSkQg== X-Received: by 2002:a1c:b342:: with SMTP id c63mr46096700wmf.162.1620934026480; Thu, 13 May 2021 12:27:06 -0700 (PDT) Received: from localhost.localdomain (2a02-8440-6341-d842-3074-96af-9642-0002.rev.sfr.net. [2a02:8440:6341:d842:3074:96af:9642:2]) by smtp.gmail.com with ESMTPSA id h9sm3053621wmb.35.2021.05.13.12.27.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 12:27:06 -0700 (PDT) From: Guillaume Ranquet To: Cc: Sean Wang , Vinod Koul , Matthias Brugger , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] dmaengine: mediatek: use GFP_NOWAIT instead of GFP_ATOMIC in prep_dma Date: Thu, 13 May 2021 21:26:42 +0200 Message-Id: <20210513192642.29446-4-granquet@baylibre.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210513192642.29446-1-granquet@baylibre.com> References: <20210513192642.29446-1-granquet@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210513_122708_268772_CC797A6D X-CRM114-Status: UNSURE ( 9.90 ) 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 a09ab2dd3b46..375e7e647df6 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;