From patchwork Thu Mar 24 17:54:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 12790947 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 A2BA7C433EF for ; Thu, 24 Mar 2022 17:56:39 +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: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=xXrEWP1mwb0+Kim8ZQL3nE/KCkxChcQpwi22oICDKLk=; b=Cgps5QnUI8dw4V v/YSjvTYlOG2qDmyX0yyNLObzV+p97WDAiJ+vTyGTCznGLKr+ZVa0TYcQoIQqJgdcCGHFtmxmH1Jc 7AZ/UV3bo0KOkzailuahPMLni76ZmsJiQk6udV08EAO8pW46iV/vWQK9vQ4XzXKqIVzEx7fx9sI4V 7NLGz8yGX6m08EHBdnMfB8PqwfS5VeesgXNKdFhm5rqxIurMDY4OBS/l2i3eOY0E8EIoqCyt3um5O HqcKAkxzWTzZq6tESjjjGU4RLHrvTYPUmfiGik8lfG1+QfaV1vFGvhJGphvH5CuYY/9rGR6DiMoRO q2oXMugm5ByPQi9SPMMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nXRgE-00HT7P-PI; Thu, 24 Mar 2022 17:55:27 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nXRfE-00HSmq-6O for linux-arm-kernel@lists.infradead.org; Thu, 24 Mar 2022 17:54:25 +0000 Received: by mail-pj1-x1031.google.com with SMTP id o68-20020a17090a0a4a00b001c686a48263so5840658pjo.1 for ; Thu, 24 Mar 2022 10:54:23 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gm+N+de+ywCT6zySGwW3DpE5hrvwRPG1W5+NjCS8u20=; b=LANaYHwar9TlXM6EfRwBq1ZGJHXeEamyb40OwWw1/pRque7M/nmxIWLW1h602zyd02 ou3oBNg+VlwVaOZjpAi8Yrk6OVg4UJ3quiBegvOWOgh1LcYH8z+9SOp+MTqeOG5MfkN/ WiapD9HDIw9YKPcyLie6Grz1Fv5F8Dk5oBJdBp2PtlBOEmQatdMxckDk0xACYcD1Tauy DFlUFju5KRrnUCdof7RYpNjNFBGmQMUeIfeHKtgBuY1WxRopGF55VMwE1PVdYFXEihYV 5qywqlx+iQlqAbu2c2E2aVEsuPpL9/7jIZr3pEypEbS2ci9Fppn9C4mUIG7JgRpnmrV0 S8BQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gm+N+de+ywCT6zySGwW3DpE5hrvwRPG1W5+NjCS8u20=; b=oErl5nO3Tq/FUapE/JYZ79eHFXHDmRp40PV+91lsY+fYjx3cYIN4upWvdmFZ4haMqf rvpAJy/se8ulbpeoFAAilv6A0sGEkIvwqy/KDIS6dktqwPsUhMyZq3iL+2bTkkT79joE NjFjtbrhHohTTNsad7JEPALjofuG/14g+JOuW2CyGB1wyJ4+N+gtMBl16lIzWS3CRTQQ HZEWf3OQIOR+WHPr4y6Fc95Pp+CnwX+qttZqQZoNUWymp4+1YoepUPEGXqIRcxpCqGw+ wLiYn18+jMHsox/otLpFsFPzlE6TbhHFSGagZiXqivktzXAovNnoP7EF4Fw0qvpDYnVz Ahyw== X-Gm-Message-State: AOAM533+nD8mt8bxeDcA6KGybddNEicBERuQmlkth+i9dPaVsl8TvGJs 2/acSiVZbvxjcAByL+x8S041+LaMxMw= X-Google-Smtp-Source: ABdhPJzAAuA5N8ACSqo+esBu2LrJPnNgvZu+UoLuWbJMrahfS/0XVVqmttHSUrbeiOqcJc9rJTtp3A== X-Received: by 2002:a17:903:244b:b0:154:2cb2:86d with SMTP id l11-20020a170903244b00b001542cb2086dmr7081997pls.123.1648144462674; Thu, 24 Mar 2022 10:54:22 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id f21-20020a056a00239500b004fb02a7a45bsm1003193pfc.214.2022.03.24.10.54.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 10:54:22 -0700 (PDT) From: Florian Fainelli To: linux-arm-kernel@lists.infradead.org Cc: Florian Fainelli , Geert Uytterhoeven , Russell King , Nicolas Pitre , Catalin Marinas , linux-kernel@vger.kernel.org (open list), linus.walleij@linaro.org, Rob Herring , Ard Biesheuvel Subject: [PATCH 1/2] ARM: Fix off by one in checking DMA zone size Date: Thu, 24 Mar 2022 10:54:16 -0700 Message-Id: <20220324175417.1014562-2-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220324175417.1014562-1-f.fainelli@gmail.com> References: <20220324175417.1014562-1-f.fainelli@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220324_105424_277460_7F0F8205 X-CRM114-Status: GOOD ( 13.47 ) 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 maximum DMA address is PAGE_OFFSET + arm_dma_zone_size - 1, fix this by doing the appropriate subtraction. Fixes: 650320181a08 ("ARM: change ARM_DMA_ZONE_SIZE into a variable") Suggested-by: Geert Uytterhoeven Signed-off-by: Florian Fainelli Reviewed-by: Linus Walleij --- 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..f244ee68e814 100644 --- a/arch/arm/include/asm/dma.h +++ b/arch/arm/include/asm/dma.h @@ -11,7 +11,7 @@ #define MAX_DMA_ADDRESS ({ \ extern phys_addr_t arm_dma_zone_size; \ arm_dma_zone_size && arm_dma_zone_size < (0x10000000 - PAGE_OFFSET) ? \ - (PAGE_OFFSET + arm_dma_zone_size) : 0xffffffffUL; }) + (PAGE_OFFSET + arm_dma_zone_size - 1) : 0xffffffffUL; }) #endif #ifdef CONFIG_ISA_DMA_API From patchwork Thu Mar 24 17:54:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 12790948 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 3FA40C433F5 for ; Thu, 24 Mar 2022 17:57:16 +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: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=Yhe4D1rx73qCemXwmpWVbrHkpHVjZ7xn+efSvaEap5c=; b=XTfBb2+yBHuNop NU9H5DIK/J8qrgxgGvnFo/WXIhjJFxKYhfQQy5sfXjZJIsBnghe1U4z1Vgvt/QIRybNUGWGGimGpv FyCwuX76WVRQLAaINwI7GPDNbn0AUE1zsnq7Y9qNpNjCfOVjvMYtV5e335pXkcbUswY51iYBasX2I nKj13aNiNRj0c1stFOpWXILxMAh1/2YFkh6Wm36eGcIylEObiDkofTZmdDaWryYRcV7GXZPLsBvYA dDVibw1I3nlBy0+vuX/eRaXwtFnt+7AYD1olOK1OX84DW4GY7umrC6WVEn2hEdJF0n06Vj2I1qW6Y e2Sa37BpsoaEFKrrhfxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nXRgo-00HTLZ-9K; Thu, 24 Mar 2022 17:56:02 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nXRfF-00HSnb-Ls for linux-arm-kernel@lists.infradead.org; Thu, 24 Mar 2022 17:54:27 +0000 Received: by mail-pj1-x1029.google.com with SMTP id gb19so5357342pjb.1 for ; Thu, 24 Mar 2022 10:54:25 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=jKyYn/8x1r3aq5yDhbWNBcNW8nQVJUhymtL9BdNTCak=; b=JHR9OsnDe32cYkFuQG30yVf4IIy04Gd4f4cS9Jfup69kp9HQcphhKnJ9CHj6uixQ13 hCGK9/5Ttevrc7XvcWHiC0scEoQDhXQFSSWqeiGoC3MDEtSyHwBjQ1Sb2oneayNShOY0 1dsdJa33UfBu/6nqLkKH7N0K6bW6A5fnAMOTQNg7U0558UBoJBGEAt2NBevAbQFrR/2I 6WJX36SjgAEDj/5ePihT4GV2pu7uEYxt6RCvYXTL31WL67j0yui7njsX0CXRYq25H7N2 dONEMRWxZZvqSN77t3l/MSkpJgdMDpZfAHF+CshzVekdT+0U49za42nq71qdUaOaXcYB sm2A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=jKyYn/8x1r3aq5yDhbWNBcNW8nQVJUhymtL9BdNTCak=; b=f02g2H2kJYFo+oiYZRAh/DrhCt4rcCOnrZ4Fe9n/zxgS+0Au5bdkafftOAlIdLYDNJ xvs89so/qGrCsmtEsvnXC8GouiBYWG2vovYiwB85/lBRlkBFGSsg8K7/e6jpHKfN/KcE EBpj1MLOM3FAwkhzQZZaau5eLqxBx2pqcjSGfmAQiHD+rIfkvJ0bPLpnBCKGSg+7x9dO fhzOJDf4jZfGPUyf0MNiF7ANIx8dHM1r9CNA2rqjU9VR9JIIUR7lW+HY90Waj3Y4eP5Q Y/Rup/QrI0hiWsKxu0pkpbZyaZ2r25Plbz7gP6mzR7xqOYA0vZ7SkuKpRZCUYXvTR67+ xBhQ== X-Gm-Message-State: AOAM531uPKYes8olL+lD0+wPtGaESX1jREkvQ42NGnHZEBJscvP7plyu sXyBoKSEFlPeO2lKTX4v7DqomApHuOA= X-Google-Smtp-Source: ABdhPJzXDtBnQmmfVzd/7DM+GwJdkOhngZyeyhrF6BjpSvFW2oCpd/etdNVcxpTwK7WvQFb2wzWrsw== X-Received: by 2002:a17:902:f60f:b0:151:4f66:55b4 with SMTP id n15-20020a170902f60f00b001514f6655b4mr7048785plg.127.1648144464284; Thu, 24 Mar 2022 10:54:24 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id f21-20020a056a00239500b004fb02a7a45bsm1003193pfc.214.2022.03.24.10.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 10:54:23 -0700 (PDT) From: Florian Fainelli To: linux-arm-kernel@lists.infradead.org Cc: Florian Fainelli , Russell King , Nicolas Pitre , Catalin Marinas , linux-kernel@vger.kernel.org (open list), linus.walleij@linaro.org, Geert Uytterhoeven , Rob Herring , Ard Biesheuvel Subject: [PATCH 2/2] ARM: Clamp MAX_DMA_ADDRESS to 32-bit Date: Thu, 24 Mar 2022 10:54:17 -0700 Message-Id: <20220324175417.1014562-3-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220324175417.1014562-1-f.fainelli@gmail.com> References: <20220324175417.1014562-1-f.fainelli@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220324_105425_767228_6C436408 X-CRM114-Status: GOOD ( 14.27 ) 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 MAX_DMA_ADDRESS is a virtual address, therefore it needs to fit within a 32-bit unsigned quantity. Platforms defining a DMA zone size in their machine descriptor can easily overflow this quantity depending on the DMA zone size and/or the PAGE_OFFSET setting. In most cases this is harmless, however in the case of a CONFIG_DEBUG_VIRTUAL enabled, __virt_addr_valid() will be unable to return that MAX_DMA_ADDRESS is valid because the value passed to that function is an unsigned long which has already overflowed. Fixes: e377cd8221eb ("ARM: 8640/1: Add support for CONFIG_DEBUG_VIRTUAL") Fixes: 2fb3ec5c9503 ("ARM: Replace platform definition of ISA_DMA_THRESHOLD/MAX_DMA_ADDRESS") Signed-off-by: Florian Fainelli Reviewed-by: Linus Walleij --- arch/arm/include/asm/dma.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/dma.h b/arch/arm/include/asm/dma.h index f244ee68e814..ea47420babd4 100644 --- a/arch/arm/include/asm/dma.h +++ b/arch/arm/include/asm/dma.h @@ -8,10 +8,12 @@ #ifndef CONFIG_ZONE_DMA #define MAX_DMA_ADDRESS 0xffffffffUL #else +#include #define MAX_DMA_ADDRESS ({ \ extern phys_addr_t arm_dma_zone_size; \ arm_dma_zone_size && arm_dma_zone_size < (0x10000000 - PAGE_OFFSET) ? \ - (PAGE_OFFSET + arm_dma_zone_size - 1) : 0xffffffffUL; }) + min_t(phys_addr_t, (PAGE_OFFSET + arm_dma_zone_size - 1), 0xffffffffUL) : \ + 0xffffffffUL; }) #endif #ifdef CONFIG_ISA_DMA_API