Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3428823rdb; Wed, 27 Dec 2023 07:12:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IENYUHUtQHthadVEsPeqsDS60werOj0ka8X2oBFFHHQIFy0bS1dOgabvqHCmaXoOZzUephj X-Received: by 2002:a19:f010:0:b0:50e:56ae:3538 with SMTP id p16-20020a19f010000000b0050e56ae3538mr1915288lfc.51.1703689968412; Wed, 27 Dec 2023 07:12:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703689968; cv=none; d=google.com; s=arc-20160816; b=L1mXW/kHcNVbuzhxfUqtd7ZgfgLt7kXaeXcp5fMfGM/Aqg/2Tz33WEe5gLCRoADNcZ ThKcXV2Z42UWGxSjr0s42qeIloG+nHrgjPTymkKphBUPh1OOh9GAkMh0u02TIPvBpNkh zYLTtMxHtkGBXNcwnh6TFdj21TAiNM7SmplTWYxyu4I/rsUT6Jo8CyaeUEukUob9Kc5H bLs/qHpPyTTk9hiOb/sLPyuCdvJcMpfka73d5PLwaUj4dGDG4zlMobcgqbGEZXX6j3/d lTON8ws5uSQ54tt9vwh2MLsHvFyWzR9GIRirS/tLCRW5J6dRWA7W8zDD9ix+HA7YOTds oIuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=UpeQjVcIvIDTirwrvD24BariIFRBko8olSTXSbStkLI=; fh=4ESZ1c62iMGhYlhC2pjn9wB4qPFQ2ZNstb13IlN3w/8=; b=EyNS4/M1OJZdUyqQU4v1p6o52FQWahcattPwW8jx3qpfSyF/66NfCeY/WycMT8QBge qxtxQYzTiGUzx/cBzmQ2poijs+6rN+dZodVYIUbYj0UnDsQhvdmNrYoUpR1WnpY1ZVOW PuB6VNR2S6h2snYQ93w7TwLsXXMr503JD42maWJg/noc8XZASfsLEnJqExQmhyNrCKL7 vh4JAqZoRx/LXbe7d2alFozbl3dZMgfrWpsmVLbcqclk/txT8U2vjv6f5vzmUfU1Kty+ 50uYPfosbruHHyp7vbw1XphJwFJdyaYfY+ZiyoMKoO/u/Ml6n6IMLJ+TQrewpEhRZ6UV 9H2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tkos.co.il header.s=default header.b=YoaHfAea; spf=pass (google.com: domain of linux-kernel+bounces-12078-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12078-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f21-20020a50d555000000b0054cde444dfesi6251573edj.374.2023.12.27.07.12.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 07:12:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12078-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@tkos.co.il header.s=default header.b=YoaHfAea; spf=pass (google.com: domain of linux-kernel+bounces-12078-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12078-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0164A1F21EEE for ; Wed, 27 Dec 2023 15:12:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD52E45C19; Wed, 27 Dec 2023 15:12:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tkos.co.il header.i=@tkos.co.il header.b="YoaHfAea" X-Original-To: linux-kernel@vger.kernel.org Received: from mail.tkos.co.il (mail.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 smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A8C345957; Wed, 27 Dec 2023 15:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tkos.co.il Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tkos.co.il 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 14300440F4B; Wed, 27 Dec 2023 17:02:44 +0200 (IST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tkos.co.il; s=default; t=1703689364; bh=st9CHgymVQhW3AqOhh2Rin5cH7JUg2qvgO/LnRxoumc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YoaHfAeaNk4IPaAWZfUwbo1ubF56b+leDPEd4c4QmVuIHJy/OFHORP1tdrd0ZBHih GEeHhUgDHV1h40Dm0kVpFDVWGczdYLfWSqAG1frkc4xywnvHxHbuv1SeJJ1tlepZBs tKuxvMy56I8tNUFNZT88w+a/5nPWUwhaJZEgjiYkF4VbUxsNB2VHAlhGp63I8f+btv SFUEnGnn4fgpmh7m10km6y4VqfClzcNVQpB+7O9paBCoYgKksirVPXIh+fcV0xikaj z5Qcpw1ROUGDFlH8BBsmv/kKhaz7blHANDbenLCXGPyyEFuEI/nQStojzw5fwt4pw+ ONZwK5p79Fhbw== From: Baruch Siach To: Christoph Hellwig , Marek Szyprowski , Rob Herring , Frank Rowand , Catalin Marinas , Will Deacon Cc: Baruch Siach , Robin Murphy , iommu@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Petr=20Tesa=C5=99=C3=ADk?= , Ramon Fried Subject: [PATCH RFC 3/4] dma-direct: add offset to zone_dma_bits Date: Wed, 27 Dec 2023 17:04:27 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Current code using zone_dma_bits assume that all addresses range in the bits mask are suitable for DMA. For some existing platforms this assumption is not correct. DMA range might have non zero lower limit. Add 'zone_dma_off' for platform code to set base address for DMA zone. Rename the dma_direct_supported() local 'min_mask' variable to better describe its use as limit. Suggested-by: Catalin Marinas Signed-off-by: Baruch Siach --- include/linux/dma-direct.h | 1 + kernel/dma/direct.c | 10 ++++++---- kernel/dma/pool.c | 2 +- kernel/dma/swiotlb.c | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h index 18aade195884..77c52019c1ff 100644 --- a/include/linux/dma-direct.h +++ b/include/linux/dma-direct.h @@ -13,6 +13,7 @@ #include extern unsigned int zone_dma_bits; +extern phys_addr_t zone_dma_off; /* * Record the mapping of CPU physical to DMA addresses for a given region. diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 73c95815789a..7a54fa71a174 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -21,6 +21,7 @@ * override the variable below for dma-direct to work properly. */ unsigned int zone_dma_bits __ro_after_init = 24; +phys_addr_t zone_dma_off __ro_after_init; static inline dma_addr_t phys_to_dma_direct(struct device *dev, phys_addr_t phys) @@ -59,7 +60,7 @@ 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 <= zone_dma_off + DMA_BIT_MASK(zone_dma_bits)) return GFP_DMA; if (*phys_limit <= DMA_BIT_MASK(32)) return GFP_DMA32; @@ -566,7 +567,7 @@ int dma_direct_mmap(struct device *dev, struct vm_area_struct *vma, int dma_direct_supported(struct device *dev, u64 mask) { - u64 min_mask = (max_pfn - 1) << PAGE_SHIFT; + u64 min_limit = (max_pfn - 1) << PAGE_SHIFT; /* * Because 32-bit DMA masks are so common we expect every architecture @@ -583,8 +584,9 @@ int dma_direct_supported(struct device *dev, u64 mask) * part of the check. */ if (IS_ENABLED(CONFIG_ZONE_DMA)) - min_mask = min_t(u64, min_mask, DMA_BIT_MASK(zone_dma_bits)); - return mask >= phys_to_dma_unencrypted(dev, min_mask); + min_limit = min_t(u64, min_limit, + zone_dma_off + DMA_BIT_MASK(zone_dma_bits)); + return mask >= phys_to_dma_unencrypted(dev, min_limit); } /* diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c index b481c48a31a6..0103e932444d 100644 --- a/kernel/dma/pool.c +++ b/kernel/dma/pool.c @@ -70,7 +70,7 @@ static bool cma_in_zone(gfp_t gfp) /* CMA can't cross zone boundaries, see cma_activate_area() */ end = cma_get_base(cma) + size - 1; if (IS_ENABLED(CONFIG_ZONE_DMA) && (gfp & GFP_DMA)) - return end <= DMA_BIT_MASK(zone_dma_bits); + return end <= zone_dma_off + DMA_BIT_MASK(zone_dma_bits); if (IS_ENABLED(CONFIG_ZONE_DMA32) && (gfp & GFP_DMA32)) return end <= DMA_BIT_MASK(32); return true; diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 33d942615be5..bd3071894d2b 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -446,7 +446,8 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask, if (!remap) io_tlb_default_mem.can_grow = true; if (IS_ENABLED(CONFIG_ZONE_DMA) && (gfp_mask & __GFP_DMA)) - io_tlb_default_mem.phys_limit = DMA_BIT_MASK(zone_dma_bits); + io_tlb_default_mem.phys_limit = + zone_dma_off + DMA_BIT_MASK(zone_dma_bits); else if (IS_ENABLED(CONFIG_ZONE_DMA32) && (gfp_mask & __GFP_DMA32)) io_tlb_default_mem.phys_limit = DMA_BIT_MASK(32); else @@ -625,7 +626,7 @@ 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 <= zone_dma_off + DMA_BIT_MASK(zone_dma_bits)) gfp |= __GFP_DMA; else if (phys_limit <= DMA_BIT_MASK(32)) gfp |= __GFP_DMA32; -- 2.43.0