From patchwork Fri Aug 2 06:03:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Unknown via Linuxppc-dev X-Patchwork-Id: 1968158 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.ozlabs.org header.i=@lists.ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=QeKCsqfo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZwKT31kpz1yYq for ; Fri, 2 Aug 2024 16:05:01 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ozlabs.org; s=201707; t=1722578701; bh=tf2G3vKfwS9xCyFudIaZcp+Gz7QoJvq2aAGjGmve5gA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=QeKCsqfod4pCXq68EdWRA3Az9KzKQDp2Ju70PQkcr45I3/egKF+zRqYkrmlUHNJdF JzpG4+SLKwsk+b4aKS2uYHsqYKymU23linP72VHLjZoCIrpcIHvfbrYUbyZ5NHjOfs g6TibaXVPO6b94eJDLdPtAF/EYY5MxogfJd+8bj57S87C22AAF2G6+MaE218PUbwOx jGwpQJOerOnySWz0xXlzRuKvp8fs/CiuXh093o3ax/4eE7qCdGqeFJlgGrBGug9DVE Vk0h2dYrMaJftyBYBIVoVBiQ9A9YSvAYtVZ8oH+eh2yA87wmRWWVp2EINj1sJWdiQt HZsVyCC9KdEWA== Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4WZwKT1zFNz3c3y for ; Fri, 2 Aug 2024 16:05:01 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=tkos.co.il Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=tkos.co.il header.i=@tkos.co.il header.a=rsa-sha256 header.s=default header.b=PVdJ6HN7; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=tkos.co.il (client-ip=84.110.109.230; helo=mail.tkos.co.il; envelope-from=baruch@tkos.co.il; receiver=lists.ozlabs.org) Received: from mail.tkos.co.il (hours.tkos.co.il [84.110.109.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4WZwJQ57PDz3cQq for ; Fri, 2 Aug 2024 16:04:06 +1000 (AEST) Received: from tarshish.tkos.co.il (unknown [10.0.8.2]) (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 DC44044076F; Fri, 2 Aug 2024 09:02:39 +0300 (IDT) To: Christoph Hellwig , Marek Szyprowski , Catalin Marinas , Will Deacon Subject: [PATCH v5 1/3] dma: improve DMA zone selection Date: Fri, 2 Aug 2024 09:03:46 +0300 Message-ID: <5200f289af1a9b80dfd329b6ed3d54e1d4a02876.1722578375.git.baruch@tkos.co.il> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Baruch Siach via Linuxppc-dev From: Unknown via Linuxppc-dev Reply-To: Baruch Siach Cc: linux-s390@vger.kernel.org, Baruch Siach , Ramon Fried , =?utf-8?b?UGV0ciBUZXNhxZnDrWs=?= , Robin Murphy , linux-kernel@vger.kernel.org, iommu@lists.linux.dev, Elad Nachman , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" When device DMA limit does not fit in DMA32 zone it should use DMA zone, even when DMA zone is stricter than needed. Same goes for devices that can't allocate from the entire normal zone. Limit to DMA32 in that case. Reported-by: Catalin Marinas Reviewed-by: Catalin Marinas Signed-off-by: Baruch Siach --- kernel/dma/direct.c | 6 +++--- kernel/dma/swiotlb.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 4480a3cd92e0..3b4be4ca3b08 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -4,7 +4,7 @@ * * DMA operations that map physical memory directly without using an IOMMU. */ -#include /* for max_pfn */ +#include #include #include #include @@ -59,9 +59,9 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 *phys_limit) * zones. */ *phys_limit = dma_to_phys(dev, dma_limit); - if (*phys_limit <= DMA_BIT_MASK(zone_dma_bits)) + if (*phys_limit < DMA_BIT_MASK(32)) return GFP_DMA; - if (*phys_limit <= DMA_BIT_MASK(32)) + if (*phys_limit < memblock_end_of_DRAM()) return GFP_DMA32; return 0; } diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index df68d29740a0..043b0ecd3e8d 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -629,9 +629,9 @@ static struct page *swiotlb_alloc_tlb(struct device *dev, size_t bytes, } gfp &= ~GFP_ZONEMASK; - if (phys_limit <= DMA_BIT_MASK(zone_dma_bits)) + if (phys_limit < DMA_BIT_MASK(32)) gfp |= __GFP_DMA; - else if (phys_limit <= DMA_BIT_MASK(32)) + else if (phys_limit < memblock_end_of_DRAM()) gfp |= __GFP_DMA32; while (IS_ERR(page = alloc_dma_pages(gfp, bytes, phys_limit))) {