From patchwork Sun Aug 11 07:09:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 13759710 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 D5425C3DA4A for ; Sun, 11 Aug 2024 07:11:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=x+Wb1RTgr5UesB4AYeGyadbn2kLr+hP404O0HkbL4zk=; b=ROmJZEJO8go9XqgmozWcNXZWgF fgZyLoxJgk/tYf7MUQA4NBNHypqvmsRCuqA7JGUQXaypv+I4CuNlELYnhIzTP0L8b9uCoTJVLcNU+ fbhSIxESJiGPaUN1WalQWdaMcvW9kmfUaS/l0v4NBn+d98y3i5JhvcmC40LqmuOSgGJeplSiPJBDf dyYONJpZRSMRTlvUKT9jebkv0+T2pgA5+LUx9Pdc55OkTKxn+M/81Lh7eTLyZ6VN7IcYz2faT5VPi e7yNVEsqUyNHhuN9XATi48SB90XImrC+JgecCfspImp3xO+IH6I60k+ykSlF5dgoqt36SCNOahDsn Lz3xRdIQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sd2jC-0000000FBxk-3sfm; Sun, 11 Aug 2024 07:10:58 +0000 Received: from guitar.tkos.co.il ([84.110.109.230] helo=mail.tkos.co.il) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sd2i4-0000000FBhK-0hKA for linux-arm-kernel@lists.infradead.org; Sun, 11 Aug 2024 07:09:50 +0000 Received: from tarshish.tkos.co.il (unknown [10.0.8.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tkos.co.il (Postfix) with ESMTPS id AC632440F36; Sun, 11 Aug 2024 10:08:13 +0300 (IDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tkos.co.il; s=default; t=1723360094; bh=nf/MkqeBwiD3TKhf52jrg5yDi7MiKiiAJynae1NoHxY=; h=From:To:Cc:Subject:Date:From; b=u9t9D4D4GOVGPdIf3j4rCxiYr4On/te/G7ibLcCPJd1L3xwINzoEOnQObJFuTX579 Jps5mdQfaS1pDDDpDr4we09WWJ3Z1c3mXIL2KgjqyBT/MRAVg8BaESBpfO3hauuxSb tBftApeC1T5mj/hC7zPK/ux9AG/Nbrbw3aFtxfvhXiNVb3XbkluI8U2J2fvdPPDxP3 vEc757+0bvOeip9isMvhTi3zHGt5vqSN2WT/AzeRR4S+xyu0bWhWcM1cR9WGVsoZJm 6yjlgw27UOu2t7BolltOtgvs1Ws4PsybaMjcirEk+nQCCR+dHv1Cc3jSHx9pcdaph6 fQDCCPoFH0q/g== From: Baruch Siach To: Christoph Hellwig , Marek Szyprowski , Catalin Marinas , Will Deacon Cc: Baruch Siach , Robin Murphy , iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, =?utf-8?b?UGV0ciBUZXNhxZnDrWs=?= , Ramon Fried , Elad Nachman Subject: [PATCH v6 RESED 0/2] dma: support DMA zone starting above 4GB Date: Sun, 11 Aug 2024 10:09:34 +0300 Message-ID: X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240811_000948_679118_72C73A0B X-CRM114-Status: GOOD ( 15.17 ) 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 [ Resend series with correct Cc list. Sorry for the spam. ] DMA zones code assumes that DMA lower limit is zero. When there is no RAM below 4GB, arm64 platform code sets DMA/DMA32 zone limits to cover the entire RAM[0]. My target platform has RAM starting at 32GB. Devices with 30-bit DMA mask are mapped to 1GB at the bottom of RAM, between 32GB - 33GB. DMA zone over the entire RAM breaks DMA allocation for these devices. In response to a previous RFC hack[1] Catalin Marinas suggested to add a separate offset value as base address for the DMA zone, and then refined the suggestion to use start of RAM[3]. This series attempts to implement that suggestion. With this series applied, the DMA zone covers the right RAM range for my platform. v6: * Drop the first patch; existing logic is just fine * Modify powerpc code to avoid off by one issue v5: * Test the correct kernel * Add missing patch that actually makes DMA zone work * Extend the treatment of zone_dma_limit > DMA_BIT_MASK(32) * Use max() to make the code somewhat more readable * Change zone_dma_limit type to u64 to match DMA_BIT_MASK() v4: * Drop last patch. zone_dma_limit includes RAM base address. * Adjust DMA zone selection in swiotlb as well. * Don't change max_zone_phys() behaviour * Update code to fallback to DMA zone when zone_dma_limit > DMA_BIT_MASK(32) v3: * Rebase on v6.11-rc1. * Drop zone_dma_base. Use memblock_start_of_DRAM() instead. * Drop DT patches. Low DMA range limit no longer needed. * Add patch to improve dma_direct_optimal_gfp_mask() heuristics as Catalin suggested. RFC v2: * Add patch from Catalin[2] changing zone_dma_bits to zone_dma_limit to simplify subsequent patches * Test on real hardware RFC v1: https://lore.kernel.org/all/cover.1703683642.git.baruch@tkos.co.il/ [0] See commit 791ab8b2e3db ("arm64: Ignore any DMA offsets in the max_zone_phys() calculation") [1] https://lore.kernel.org/all/9af8a19c3398e7dc09cfc1fbafed98d795d9f83e.1699464622.git.baruch@tkos.co.il/ [2] https://lore.kernel.org/all/ZZ2HnHJV3gdzu1Aj@arm.com/ [3] https://lore.kernel.org/all/ZnH-VU2iz9Q2KLbr@arm.com/ Catalin Marinas (2): dma: replace zone_dma_bits by zone_dma_limit arm64: support DMA zone above 4GB arch/arm64/mm/init.c | 32 ++++++++++---------------------- arch/powerpc/mm/mem.c | 5 ++++- arch/s390/mm/init.c | 2 +- include/linux/dma-direct.h | 2 +- kernel/dma/direct.c | 6 +++--- kernel/dma/pool.c | 4 ++-- kernel/dma/swiotlb.c | 6 +++--- 7 files changed, 24 insertions(+), 33 deletions(-) base-commit: 8400291e289ee6b2bf9779ff1c83a291501f017b