From patchwork Wed Jul 6 16:46:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 12908308 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 3E45FC43334 for ; Wed, 6 Jul 2022 16:49:37 +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: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:References: List-Owner; bh=dx4DHcC2DdCPYW0XW5P+GTyk2U5cSp6d3MhWgVSSjWA=; b=NV86h4zxjtMlJN sFe/nnlghFinsnZds8uGttbKrcEJ/7IgRWCpf5kq//Q7IulHPeuoITDUTYajFYz8czEsOYHZ2oLQR yVSj9Z/yxq4I6uatTdTAIC682Kc0gq+1mFE8ti9zLm3fcNOi9MMm+CSrEAN6emZQpKwLmYjbwhgyz RuBe+KomG93/d0pvmuvn6Oi0SxA1C5xa9XQYfnAo9oT0hrUBiTmwHjOh1JH4njd5PrtN1DGQZm7NX +BkWSdQYwnOTr3633IxZREzqpGtFbo6mWfDeMGv4TOO5RXGMjK/uNNvWVdGEaRsss+LziFqa0djIx hFSh4vLdU+9d5Ymj/EmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o98CG-00BSZw-9A; Wed, 06 Jul 2022 16:48:16 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o98AK-00BRWq-AV for linux-arm-kernel@lists.infradead.org; Wed, 06 Jul 2022 16:46:17 +0000 Received: by mail-pj1-x102a.google.com with SMTP id g20-20020a17090a579400b001ed52939d72so16328759pji.4 for ; Wed, 06 Jul 2022 09:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=T6h4OXZQzG/asYA1Xhet59Cfd+Yad4rt+k1tqeixPrk=; b=De2uO9CQ5L4IinSS9lNjF/ybUMyCNO/YriA8s+55skSi4g+zi714vlbOwMmlS6z4LI EbBrS1t3Zag2WNj7j7cYtIGtEWaj2XU55Ck5zMhmUoYVz2bJguVc/AQSplRg84pPQQ4J 2glPhD6VnbUlZQpFxRqYuIickekcGecpH1jY7afR119n6Q3tB/R/jkXw8v0kqWX+w43o z69r7fl8THK9m6YsETr+f+QFBTt+K4mKRWocWgjuHOqq6jJa0QNWDTOuF9/Goox5unaZ eHu7Cz6d133HhRySEPz2CU8Igs4SBFtpLuXEbyOlO2Idhl7e4uDaAH5Bsg9HpOAX8kYf czLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=T6h4OXZQzG/asYA1Xhet59Cfd+Yad4rt+k1tqeixPrk=; b=Q52kbn0uvgoaAMnPHgmma3/YhbX4h9kEmmlLz/xMQi1aCNVkw0/ZWTpf+/ipri/ACm UlCm8KoUd/mflvV7WxFjD9w7WlQ4e6wYLsiMmZik5SEBBhNC/MTa+yb+hmILfFeud8Mi dcgCLCbnfsAblddKbsJgJT11Iq6Y/3UQwz0q8ZVTTxvYY6Gg6SsdcpBCDnVRu5OCadKo cYXKTLfsbRp+cujX7hqlI+sguIe2HvqgcG0hkLbKJYA97ycYSqEWU7MA52BNzD/VIUkg AwAmHtNnpOOLPX3P++Ak9jD0tG3BBY9QE+sGHgXZEEdF/tucldkoaVDeQoHWa0qzRC7S vClQ== X-Gm-Message-State: AJIora+UPUQ4VNYEyCn9C0v5GpUXEELyLSSeEsGllAeuf1LG6Mf7isRv CmHWW+kvzRNRGV39Vw/Z+N7y4IRk92s= X-Google-Smtp-Source: AGRyM1s7AZd0vr/XZymwLu9du7fU96fJXpCPY9tl0IZc+G5d2bdtoysfx0eL0yJNRapfvhsqHsYiGQ== X-Received: by 2002:a17:902:d5d3:b0:16b:e3ed:966f with SMTP id g19-20020a170902d5d300b0016be3ed966fmr16945531plh.156.1657125970522; Wed, 06 Jul 2022 09:46:10 -0700 (PDT) Received: from localhost.localdomain (ip72-194-116-95.oc.oc.cox.net. [72.194.116.95]) by smtp.gmail.com with ESMTPSA id z184-20020a6265c1000000b005286697ec68sm3911000pfb.133.2022.07.06.09.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 09:46:10 -0700 (PDT) From: Florian Fainelli To: linux-arm-kernel@lists.infradead.org Cc: Florian Fainelli , Russell King , Andrew Morton , Grygorii Strashko , linux-kernel@vger.kernel.org (open list), ssantosh@kernel.org, ardb@kernel.org, linus.walleij@linaro.org, geert+renesas@glider.be Subject: [PATCH v2] ARM: Fix MAX_DMA_ADDRESS overflow Date: Wed, 6 Jul 2022 09:46:06 -0700 Message-Id: <20220706164606.68528-1-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220706_094616_426328_5096B961 X-CRM114-Status: GOOD ( 17.25 ) 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 Commit 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis") added a check to determine whether arm_dma_zone_size is exceeding the amount of kernel virtual address space available between the upper 4GB virtual address limit and PAGE_OFFSET in order to provide a suitable definition of MAX_DMA_ADDRESS that should fit within the 32-bit virtual address space. The quantity used for comparison was off by a missing trailing 0, leading to MAX_DMA_ADDRESS to be overflowing a 32-bit quantity. This was caught with the bcm2711 platforms which defines a dma_zone_size of 1GB, and using a PAGE_OFFSET of 0xc000_0000 (CONFIG_VMSPLIT_3G) with CONFIG_DEBUG_VIRTUAL enabled would lead to MAX_DMA_ADDRESS being 0x1_0000_0000 which overflows the unsigned long type used throughout __pa() and __virt_addr_valid(). Because the virtual address passed to __virt_addr_valid() would now be 0, the function would loudly warn, thus making the platform unable to boot properly. Fixes: 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis") Signed-off-by: Florian Fainelli --- Changes in v2: - simplify the patch and drop the first patch that attempted to fix an off by one in the calculation. arch/arm/include/asm/dma.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/include/asm/dma.h b/arch/arm/include/asm/dma.h index a81dda65c576..1ffa75beb709 100644 --- a/arch/arm/include/asm/dma.h +++ b/arch/arm/include/asm/dma.h @@ -10,7 +10,7 @@ #else #define MAX_DMA_ADDRESS ({ \ extern phys_addr_t arm_dma_zone_size; \ - arm_dma_zone_size && arm_dma_zone_size < (0x10000000 - PAGE_OFFSET) ? \ + arm_dma_zone_size && arm_dma_zone_size < (0x100000000 - PAGE_OFFSET) ? \ (PAGE_OFFSET + arm_dma_zone_size) : 0xffffffffUL; }) #endif