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 93C3CC433EF for ; Wed, 23 Mar 2022 20:37:34 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FSAOwgWi+chTDK6Di0zumUHMgsISDOZp2ZTssiWKzHQ=; b=EJLAGTdAZd90UD S2n3ZvaREtiGySxVSW7X/d2xhukDOABUiFMJCoUmJ1uiqHh4mh5ltCCZLJvDaKTwa5OCoNB8dLK0h KJbju1tiC2+vjNUb2u+TnpezeL//UvUR6st598KNNoDGk/o0cXb2ge46MlHqmoih2QnKf9WdYp4gN 6A9S1loyQrkCZ09KkKku93XX5rXRZBNEbH+wOiV7GuTnv+8WNjuUI/aBiFTFoqFF9scp2K5kZe6Ca QZCiOH7/lESjA0B1pkM9tIfrkZ/hVoHOM3XBlfhntHehHTG43X+eidFYrtVP86YnrV/RgeJFdYFvD 99iDxHiXcYswo8W3lsqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nX7iW-00EpT2-Jk; Wed, 23 Mar 2022 20:36:28 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nX7iT-00EpSW-2B for linux-arm-kernel@lists.infradead.org; Wed, 23 Mar 2022 20:36:26 +0000 Received: by mail-pf1-x42e.google.com with SMTP id h19so1353498pfv.1 for ; Wed, 23 Mar 2022 13:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=kcnC6Mpslq3YwckZ1Iu0Ai3ZUjgPcGx2J4aymFTBiZc=; b=Y4kjifTLVHmGRmxojMipZepW3SfDiIaFLE1mnLnJ5yw9duhV1QoKE16XRH3V6PHBr/ KJQ3cjsMO1brkWytHnenjQZ9BSYoEuAr+z1xdKeH3MuISLd2wmfVYOU67UP1plcp2stt AN3+r7ShBSAte8E09/ciUWlg+MA8WO1KJA6vumckKwh9VACJaDvcTzUhkp9Rw+F+v9g7 t7u6JZwCgCnPQmI4ns3d4/FyYLGH76A9qghYCnBj3SLpuhnSxRRgbWLZpyHdCwcMZgMw RUNCGw7ltAjryhcRAsUxcZlEx95j1I6TpHgfD0VG0lj7AlhTZR+z6DrJX22lAHnj7W2/ EG/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=kcnC6Mpslq3YwckZ1Iu0Ai3ZUjgPcGx2J4aymFTBiZc=; b=gu5kkENB/g9rxpUUeVSa+CjZgynrPLBwvxzFd5Y8GFc6BHBXWuvDzquKt8+gvzogEj EjiHXCu8WfKztFqkD2OLg07w0qicoYO/Mq1Nu7F4bGF/ibYCNS0WZgGRxXorW/1tAa4U wPnGxxbdtdkd4mr9gxQuzstBcNCtnNVCr5tHGzX7NhImWB9Sa1tp4LquGJqxN5V92Pc4 akk0cEfKwQ+Xcl6BTCZBX35BjQeGS6bEa6zWb/mLIK5xiPYWrToZBU3sDiI8onzJEreA Up7gl0Wxbye/gtGuaKeDP5X6Xj6JKvp0m9pewliLqRiAmlUtTp5ErhFBTWxuToeG9GqB ZWjg== X-Gm-Message-State: AOAM530CW1/m8fRMprxIajwVc6+hbWOn8zxfDKnQysfC8Tb4ryk6/s9X jAF1fsuLKrBI5WAXPH+Q6Qw= X-Google-Smtp-Source: ABdhPJyiectVj0GseISJOn530BiO74Zwu9+SkTpUqfzJxnlF+RAWsfk89MpC5w/ity3NWl0rxci7QQ== X-Received: by 2002:a63:4e26:0:b0:386:1839:3bde with SMTP id c38-20020a634e26000000b0038618393bdemr1281812pgb.603.1648067783895; Wed, 23 Mar 2022 13:36:23 -0700 (PDT) Received: from [10.67.48.245] ([192.19.223.252]) by smtp.googlemail.com with ESMTPSA id v13-20020a17090a088d00b001c64d30fa8bsm5554513pjc.1.2022.03.23.13.36.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Mar 2022 13:36:23 -0700 (PDT) Message-ID: <8cdf4780-f704-e23f-9ba6-34ae61cfef62@gmail.com> Date: Wed, 23 Mar 2022 13:36:21 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: MAX_DMA_ADDRESS overflow with non-zero arm_dma_zone_size and VMSPLIT_3G Content-Language: en-US To: Geert Uytterhoeven Cc: Linus Walleij , Rob Herring , Arnd Bergmann , Ard Biesheuvel , linux-arm-kernel , Russell King , Nicolas Pitre References: <41c9bb67-3f80-510f-9904-a568a865b0ea@gmail.com> <2ec1a649-6fa0-f5c6-4246-589c0bb44d4a@gmail.com> From: Florian Fainelli In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220323_133625_145809_87F2DE05 X-CRM114-Status: GOOD ( 23.97 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 3/23/22 13:28, Geert Uytterhoeven wrote: > Hi Florian, > > On Wed, Mar 23, 2022 at 8:52 PM Florian Fainelli wrote: >> On 3/23/22 09:53, Geert Uytterhoeven wrote: >>> On Wed, Mar 23, 2022 at 4:02 PM Linus Walleij wrote: >>>> On Mon, Mar 21, 2022 at 4:46 AM Florian Fainelli wrote: >>>>> All of the virt_to_phys() and related functions either take a pointer >>>>> size argument (const volatile void *) or an unsigned long argument and >>>>> these are virtual addresses so unable to go over 32-bit anyway. >>>> >>>> Oh I ran into that too, in some different context that I since forgot. >>>> A macro that works the same on pointers and unsigned long but with >>>> slightly different semantics :P >>>> >>>> I don't know what is the proper thing to do here. Let's involve Arnd >>>> and Ard and Geert! >>>> >>>>> Since MAX_DMA_ADDRESS is intended to be "This is the maximum virtual >>>>> address which can be DMA'd from.", should we make sure that we clamp it >>>>> below 32-bit in case it overflows? >>>> >>>> Hmmmm.... I don't know what that would mean in practice? >>> >>>>> While debugging numerous KASAN splats with CONFIG_DEBUG_VIRTUAL on ARM >>>>> 32-bit with a Raspberry Pi 4B 4GB, it finally clicked that the problem >>>>> is with the use of __virt_to_phys(MAX_DMA_ADDRESS). Since that platform >>>>> has CONFIG_ZONE_DMA enabled, we end-up with: >>>>> >>>>> #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; }) >>> >>> I guess that should be "PAGE_OFFSET + (arm_dma_zone_size - 1)"? >> >> Yes, we are definitively off by one here, so this is a good catch and >> this will work for bcm2711 and any platform whereby PAGE_OFFSET + >> arm_dma_zone_size < 0xffff_ffff. >> >> There are a few that will still overflow that quantity: >> >> arch/arm/mach-highbank/highbank.c: .dma_zone_size = (4ULL * SZ_1G), >> arch/arm/mach-keystone/keystone.c: .dma_zone_size = SZ_2G, >> arch/arm/mach-omap2/board-generic.c: .dma_zone_size = SZ_2G, >> arch/arm/mach-omap2/board-generic.c: .dma_zone_size = SZ_2G, >> arch/arm/mach-omap2/board-generic.c: .dma_zone_size = SZ_2G, > > Better show some context: > > $ git grep -W "\ arch/arm/mach-bcm/bcm2711.c=DT_MACHINE_START(BCM2711, "BCM2711") > arch/arm/mach-bcm/bcm2711.c-#ifdef CONFIG_ZONE_DMA > arch/arm/mach-bcm/bcm2711.c: .dma_zone_size = SZ_1G, > > So this is the problematic one? The one that prompted this email yes, definitively problematic :D > > arch/arm/mach-bcm/bcm2711.c-#endif > arch/arm/mach-bcm/bcm2711.c- .dt_compat = bcm2711_compat, > arch/arm/mach-bcm/bcm2711.c- .smp = smp_ops(bcm2836_smp_ops), > -- > arch/arm/mach-highbank/highbank.c=DT_MACHINE_START(HIGHBANK, "Highbank") > arch/arm/mach-highbank/highbank.c-#if defined(CONFIG_ZONE_DMA) && > defined(CONFIG_ARM_LPAE) > arch/arm/mach-highbank/highbank.c: .dma_zone_size = (4ULL * SZ_1G), > > This is fine, as LPAE implies physaddr_t is 64-bit. > > arch/arm/mach-highbank/highbank.c-#endif > > The omap ones are fine for the same reason (LPAE). Well it is fine except that MAX_DMA_ADDRESS is supposed to be a *virtual* address so it will be 32-bit only even with LPAE, if it was a physical one, we would be fine. By adding PAGE_OFFSET to get a virtual address, we are definitively going above 32-bits. -- Florian _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel