From mboxrd@z Thu Jan 1 00:00:00 1970 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 6936FC001B0 for ; Mon, 7 Aug 2023 22:14:44 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9ENKHQaj9SKgtJgxyYoYmBlD2em0XWPj4ax+0hFTRcA=; b=4QyQKM5HoulDu1 Tn1qY6PLb7zkE5HOMJy1Uex4wgBjRuIwGhaq2qoXEqWkHajR0VZTdE8Yax68TGGfTdp97homteVHI 2h4m9hrCgUR+K47urr/wnjOvsBimMgiCWDlT3eZGS88oxFFOuiQeAAQeRm8dF5sVUZlzUVtCChmWx hb5twMBhRnjAZLx1QuNDCrUbYYPQz0vYyHuSMECP+k2eJpvWagZs0yJF+N58ytlBwrV9cLjRvrnSC frQ8QNg0GXdfK5cvfFRz6ELQzzx3hTZU/TFsr2Zrfk3q0XYXTgbQ/gt8nGyZs6FJ5rt7jfdlC7b/q 6YoAS/0GNmvowutKymnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qT8UV-000wdc-13; Mon, 07 Aug 2023 22:14:19 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qT8UT-000wdB-0D for linux-arm-kernel@bombadil.infradead.org; Mon, 07 Aug 2023 22:14:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=48c2F3MjJvgi4JWSUMqr70/KHIBFgCs30cp0A4pwjRU=; b=GTVKHz/r5C5WjK0DjgEdumh5v7 zPVgeXuSkyIE1p4x+hvY5SRDjLRYR7wVdxWcs9v/1nfutaB0atPqAOfCszdUE28AMj2CbQBlhhTJK kxKTTz71f/F9+703baKo2kOmgdo9ywbl25NY2IFt9VNfAvs49rwfKP/LLG0Td/T924jAEw7BcE0gn UaqV5xCgN4kpi1P0Eam7fBW2pUeLNB5dVyYOaYJ2Wcg5i8otE69nTKaxOmUbLvPDaY/ITBgIu/+ML ew1VBhlrVvCRw/JqAwMU50KNpKFKAs1DpPgWLzqXCNsvsMaqdD2eojQ2cUmsxeq0IkA9TVMC1/Zsu 5d6Kmlwg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qT8UP-00DgvF-IT; Mon, 07 Aug 2023 22:14:13 +0000 Date: Mon, 7 Aug 2023 23:14:13 +0100 From: Matthew Wilcox To: Marek Szyprowski Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Russell King , Andrew Morton , Mike Rapoport Subject: Re: [PATCH] arm: dma-mapping: fix potential endless loop in __dma_page_dev_to_cpu() Message-ID: References: <20230807152657.1692414-1-m.szyprowski@samsung.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230807152657.1692414-1-m.szyprowski@samsung.com> 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Aug 07, 2023 at 05:26:57PM +0200, Marek Szyprowski wrote: > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > index 70cb7e63a9a5..02250106e5ed 100644 > --- a/arch/arm/mm/dma-mapping.c > +++ b/arch/arm/mm/dma-mapping.c > @@ -718,7 +718,7 @@ static void __dma_page_dev_to_cpu(struct page *page, unsigned long off, > folio = folio_next(folio); > } > > - while (left >= (ssize_t)folio_size(folio)) { > + while (left && left >= (ssize_t)folio_size(folio)) { > set_bit(PG_dcache_clean, &folio->flags); > left -= folio_size(folio); > folio = folio_next(folio); I've been thinking about this and I think this is the right fix for the wrong reason. I don't understand how it can produce the failure you saw, but we shouldn't be calling folio_next() if left is zero, let alone calling folio_size() on it. So I'd rather see this fix: while (left >= (ssize_t)folio_size(folio)) { set_bit(PG_dcache_clean, &folio->flags); left -= folio_size(folio); + if (!left) + break; folio = folio_next(folio); } _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel