From patchwork Wed Jul 6 20:33:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 12908581 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 165B0C433EF for ; Wed, 6 Jul 2022 20:35:08 +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=QcO7Zt7J+QgaR2GH2QaY3l1HxGlus7GirBsgLjpUJJ8=; b=yE9SHiXEOaFLXm 6KV7rxmm8uW77br/BKUzJ2l1Hvs1OuBQ/5HUS3PkCVXGuKTtbbCS0csKBLRk7qzz2PvAOTJEKfPno pFvrE0DFMzjXVLNmkBNwgO9cxk3GTrILmUhFEZNBuMty5YrQISJ/3OmF4QoYejmShlpLs9+yX9Arl HSsmQ8YruJP8incUmTv+4la5GSuPD8yPgWxIndRks4+n4OnRrwEGoycA3m+FJvqxf9p3/kSPbk0p0 +ST5BxzAa6TWmYmiQIP2Cu1U0PaLhCgZj6IFG8V+EQfA6et9Tnpu+5PaE4D+xGG088CZ1WY2Hmicm 56bF5KFqCAdGH4lskMuw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o9Bin-00CKDu-RG; Wed, 06 Jul 2022 20:34:05 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o9Bik-00CKD2-SM for linux-arm-kernel@lists.infradead.org; Wed, 06 Jul 2022 20:34:04 +0000 Received: by mail-pj1-x102c.google.com with SMTP id x18-20020a17090a8a9200b001ef83b332f5so11246732pjn.0 for ; Wed, 06 Jul 2022 13:34:00 -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=CWCLa+dTVXWwsrUUTc1ULWbuRRtRrFjABx527QYlRYE=; b=N3mfqfa8QIYI2oMOnSFfuS+ztGJzFRckUNR60Rg7uj0J6KdS5RiNyoKRlYbfh0xKDP miNEQDrvOEAW5HkFaO++0utAkCCH4gvrj/JSV4V/RhCKNpcq+NyoHrCPSI3rIYG6GNlu v27ODgmoQE9bllvvKMUdP06XIFx+LSlfYDQVU/3lEeBY9WKcEpq3SZ7ln8frW8plw0Bm um0LZ33TKl333MX/RChX0fqReTrqXLAklWNN1yr6CvsDolJFGpEtHn8CnniukAzvPIbZ nNZpd/YBLec0jEJNkaUHiIQLAh6Nl+VF1BrCEerL2s4AAIkyZH6S+1a88bX6lwVOozYe Equg== 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=CWCLa+dTVXWwsrUUTc1ULWbuRRtRrFjABx527QYlRYE=; b=N1F4ZtyWHcbs5qsJ8JhKamMtT11/4sjrmiyF/uRWuN/n6ugfYe1xNmENb8eqBAmiBh /dtdfCUB1IwJlsVmcU5+sGV7Tgm+tDihwUvA/wVhE8FcikEclp3F3IFQYdIaXeFtDzBf gNr+dspIu11biOqVHpAej3yQGo3R3QY+ZFZMVtFoSRGjuPG8+m+X01MDlmQRTiwNGBGS e32jz58c8JDFGG8yox4qpDavV4mD6xo6uc+Xjz+TK5r08pNoDG8fLaR5NoVSwEBUqrzC fE49gkxWb0xV12TKSmhyucCyPWnfcCAu/By58ay952H9OxZLjurJzEg0bieK0uah1Kj3 gYzA== X-Gm-Message-State: AJIora88CXy9a6zop1j3nM8+Hzo+XSTvlHyTjo4InVdyxP8Yd+hpJbwE LHVFDnclNZ7VS87rMe67LGQwDDATdEE= X-Google-Smtp-Source: AGRyM1tXewrWxIrfYGjV6cq7zTptlUMB++mYEvJvssDzXJFuaW8LXUuYbRWfiGSaFp1zNFRn47dwkA== X-Received: by 2002:a17:902:dace:b0:16b:e8d4:2955 with SMTP id q14-20020a170902dace00b0016be8d42955mr15758494plx.135.1657139639489; Wed, 06 Jul 2022 13:33:59 -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 v11-20020a17090a4ecb00b001ef863193f4sm7797248pjl.33.2022.07.06.13.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 13:33:58 -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 v3] ARM: Fix MAX_DMA_ADDRESS overflow Date: Wed, 6 Jul 2022 13:33:53 -0700 Message-Id: <20220706203353.247633-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_133402_969966_C4EA8A75 X-CRM114-Status: GOOD ( 18.55 ) 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 thanks to CONFIG_DEBUG_VIRTUAL on the bcm2711 platform where we define a dma_zone_size of 1GB and we have a PAGE_OFFSET value of 0xc000_0000 (CONFIG_VMSPLIT_3G) leading to MAX_DMA_ADDRESS being 0x1_0000_0000 which overflows the unsigned long type used throughout __pa() and then __virt_addr_valid(). Because the virtual address passed to __virt_addr_valid() would now be 0, the function would loudly warn and flood the kernel log, thus making the platform unable to boot properly. Fixes: 26f09e9b3a06 ("mm/memblock: add memblock memory allocation apis") Signed-off-by: Florian Fainelli Reviewed-by: Linus Walleij --- Changes in v3: - added ULL suffix to the constant - reworded the commit message to be clearer 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..45180a2cc47c 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 < (0x100000000ULL - PAGE_OFFSET) ? \ (PAGE_OFFSET + arm_dma_zone_size) : 0xffffffffUL; }) #endif