From patchwork Wed Aug 9 17:27:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 13348259 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E5DF1C001E0 for ; Wed, 9 Aug 2023 17:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:References:MIME-Version: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:In-Reply-To: List-Owner; bh=Q1l+X9BMkGaupDZIG/dtoPzo0hRcZp6ai1NOQ07z8us=; b=J47sFkO/LT0TVQ tgMzKnPKK2KOj+FPNsXvQBXIPeeHIQXtzZbyJhInq5T1bEQnHs4VnEHLNPKHX4mV4CluDxOcMf05A e7pEMiwMmyitkZfQ1hb833P9YIClYEWjxPEd7a7cay85lzgioerUT1hmuK9pTv4+VCjCBK2bTPD6c nMSzYkWls8FYx9ITPn+RlJoFxpa+bOyWW5N9uEKzhSmAwK1/XXGeghSgKAHy2YNmp8OxS0+RBSj65 zO4j6uQhHO2SEBwWxvQ1fvJ09DISU09uUMRb14OcYCYglMT4APeCJBlMA9YyAumum0PG2oobqMjoY ei/CKQZ+ikbhZMYnmomw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qTmyT-005WrY-0Z; Wed, 09 Aug 2023 17:27:57 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qTmyO-005WpQ-1W for linux-arm-kernel@lists.infradead.org; Wed, 09 Aug 2023 17:27:55 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230809172745euoutp01a550b66307c7e5553e9df22752dce940~5xx25T1Ab0631006310euoutp01y for ; Wed, 9 Aug 2023 17:27:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230809172745euoutp01a550b66307c7e5553e9df22752dce940~5xx25T1Ab0631006310euoutp01y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1691602065; bh=r06de4D63b8frXEVcw+XDAi4mGuA65SoHz+XltAyTVg=; h=From:To:Cc:Subject:Date:References:From; b=Uz5r8N5lxNXlr89ZEVDT50eFUyu9KwrFyelf/dBHUiCJEGwue7YqvvBsADTJvVkVV pf9RWXB9URfQulEU7ZEsXGGKyND7wr79EiOzczeJ0YQe3jrL9U667BrMGLVCRyA6jo L7Ouc1A6pfsdDk97NY1zRl8MMHrKDseJgKsfOQYo= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230809172744eucas1p185e8257402a48f5756571be6ffdcf30d~5xx2A0Dpp1100311003eucas1p1T; Wed, 9 Aug 2023 17:27:44 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 2B.9A.37758.09CC3D46; Wed, 9 Aug 2023 18:27:44 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20230809172744eucas1p2ebe6dcda40499c179dcf4985eb809c69~5xx1ku8WZ2535725357eucas1p2d; Wed, 9 Aug 2023 17:27:44 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230809172744eusmtrp1e121bf93f9ab11162a8ad9e5c34de8fd~5xx1kLTZd1719717197eusmtrp1m; Wed, 9 Aug 2023 17:27:44 +0000 (GMT) X-AuditID: cbfec7f5-7ffff7000002937e-79-64d3cc90bfbd Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 52.70.10549.F8CC3D46; Wed, 9 Aug 2023 18:27:44 +0100 (BST) Received: from AMDC4653.eu.corp.samsungelectronics.net (unknown [106.120.51.32]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230809172743eusmtip134542942e78838a37e440e559a135d52~5xx1IP4TL0594805948eusmtip1k; Wed, 9 Aug 2023 17:27:43 +0000 (GMT) From: Marek Szyprowski To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Russell King , "Matthew Wilcox (Oracle)" , Andrew Morton , Mike Rapoport Subject: [PATCH v2] arm: dma-mapping: fix potential endless loop in __dma_page_dev_to_cpu() Date: Wed, 9 Aug 2023 19:27:37 +0200 Message-Id: <20230809172737.3574190-1-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFKsWRmVeSWpSXmKPExsWy7djPc7oTzlxOMTjQI2sxZ/0aNotNj6+x WlzeNYfN4tDUvYwWa4/cZbc4sn47k8XvH3PYHNg9Ll+7yOyxeYWWx6ZVnWweJ2b8ZvHYvKTe o2/LKkaPz5vkAtijuGxSUnMyy1KL9O0SuDJ2T5/AXLBWqOJGyxOWBsa9/F2MHBwSAiYS99/Z djFycQgJrGCUePWggxnC+cIoceX5XyjnM6NEw5R7jF2MnGAdR/ZvYYdILGeUWHO+GaqqlUni 952nTCBVbAKGEl1vu9hAbB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bsYOTkkBEwkjuzfwt7FyMUhJLCUUeJ3/zE2iISM xMlpDawQtrDEn2tdbBBFzUwSC46sYARJsAkYSnS97QJrEBHwkGj7d48ZpIhZ4BajxITt79hB EsIC0RIHDq5hAbFZBFQlrjSuApvKK2AvsflWAxPEBnmJ/QfPMkPEBSVOznwCVs8MFG/eOpt5 AiPfLCSpWUhSCxiZVjGKpJYW56bnFhvqFSfmFpfmpesl5+duYgSG/bZjPzfvYJz36qPeIUYm DsZDjBIczEoivLbBl1KEeFMSK6tSi/Lji0pzUosPMZoC3TeRWUo0OR8YeXkl8YZmBqaGJmaW BqaWZsZK4ryeBR2JQgLpiSWp2ampBalFMH1MHJxSDUxG/8zc9h8o3Xj/58PcR3vvr2aYd6X3 EYtt0f7qvoWvFeo371yssX+h5f0nnybrH/5i4+eZV83HYzV/4qtE5wMek9O2PDerqpgfmXSF O+7lhF/v5M/+VRN8yh93KpvJ6N2Vs9/eeU9YmrQ5Z/MpZoYA/RRT5Qx3kZ1BS1arf/fyCN9R fT6s4x7jlwiRY4vmn64+eeu5Q+HHVflCEUmrj669eFWl/qv50pNbvLb9ebJaxKXEsINhyye9 3vvl59edX/mv7fY692Pvf/Cqb63zl34+p+ibfPePcJnELSpcfLPl/69aa/Rb2nnrrCcnnpmX H5x/xHaHmOldps82vk1bJwvvf2Visazh1drTZivW33ov0qzEUpyRaKjFXFScCADL0YX9BAMA AA== X-CMS-MailID: 20230809172744eucas1p2ebe6dcda40499c179dcf4985eb809c69 X-Msg-Generator: CA X-RootMTR: 20230809172744eucas1p2ebe6dcda40499c179dcf4985eb809c69 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230809172744eucas1p2ebe6dcda40499c179dcf4985eb809c69 References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230809_102752_879799_538D1452 X-CRM114-Status: GOOD ( 18.18 ) 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 D-cache cleaning loop should not call folio_next() beyond the requested region and rely on its parameters. Simply stop looping if left counter reaches zero. This fixes the following endless loop observed by RCU stall on the ARM 32bit Exynos5422-based Odroid-XU3lite board: --->8--- rcu: INFO: rcu_sched self-detected stall on CPU rcu: 0-....: (27320 ticks this GP) idle=e414/1/0x40000002 softirq=36/36 fqs=13044 rcu: (t=27385 jiffies g=-1067 q=34 ncpus=8) CPU: 0 PID: 93 Comm: kworker/0:1H Not tainted 6.5.0-rc5-next-20230807 #6981 Hardware name: Samsung Exynos (Flattened Device Tree) Workqueue: mmc_complete mmc_blk_mq_complete_work PC is at _set_bit+0x28/0x44 LR is at __dma_page_dev_to_cpu+0xdc/0x170 .. _set_bit from __dma_page_dev_to_cpu+0xdc/0x170 __dma_page_dev_to_cpu from dma_direct_unmap_sg+0x100/0x130 dma_direct_unmap_sg from dw_mci_post_req+0x68/0x6c dw_mci_post_req from mmc_blk_mq_post_req+0x34/0x100 mmc_blk_mq_post_req from mmc_blk_mq_complete_work+0x50/0x60 mmc_blk_mq_complete_work from process_one_work+0x20c/0x4d8 process_one_work from worker_thread+0x58/0x54c worker_thread from kthread+0xe0/0xfc kthread from ret_from_fork+0x14/0x2c --->8--- While touching this code, move the set_bit() operation, which deals with atomics, a bit up in the call chain. The new order helps a bit compiler to produce code computing folio_size() only once. Fixes: cc24e9c0895c ("arm: implement the new page table range API") Signed-off-by: Marek Szyprowski --- v2: - changed the code and explaiation as suggested by Russell and Matthew v1: - https://lore.kernel.org/all/20230807152657.1692414-1-m.szyprowski@samsung.com/ --- arch/arm/mm/dma-mapping.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 70cb7e63a9a5..0474840224d9 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -719,8 +719,10 @@ static void __dma_page_dev_to_cpu(struct page *page, unsigned long off, } while (left >= (ssize_t)folio_size(folio)) { - set_bit(PG_dcache_clean, &folio->flags); left -= folio_size(folio); + set_bit(PG_dcache_clean, &folio->flags); + if (!left) + break; folio = folio_next(folio); } }