Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4756257rdh; Wed, 29 Nov 2023 09:44:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHwlyP+LtM9jwrXo8no4zX0bEWnGXDgwdvGglZoNXdf8aVNE7hwUW/8gqz38ETv+SYFuXdN X-Received: by 2002:a05:6a20:7d98:b0:18c:3260:e223 with SMTP id v24-20020a056a207d9800b0018c3260e223mr15237377pzj.18.1701279852927; Wed, 29 Nov 2023 09:44:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701279852; cv=none; d=google.com; s=arc-20160816; b=l4SZ3TtSbI0Jnr8283quZxde8lO2jjM4r+FWER0zJsl5My0RCTwrBaZuSas1Ej91ag IDGgi7LBkXXrFNy/O26QfEaVH8IoN4/ULtdQA/bI4Zcdj8Ja72v2tgB1n+W4jgfQiErp ozhLo9F4+0wU8CUCzYDn3oTonbJxIEeGDaMfpglMol27CLe7bGOhAPeXIwqezm8Cj2z7 BI9G3qOb97+xKUcKA0bKpgfPqkGcKfDZZkUNIx+aS6f06vw8mbNZL8ltb6+xcxI5j4eX wYjo/9HzC8TrKxjM28VIPczSnj+qfcxsrHnEC94cMiwIK4qg0tBQlEO0VVOVKRT8ERjQ Wfcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=HXPHeO5zlYwKKBn0RLdeJC/XBr9v2i1aSk48kOEWBQs=; fh=GNBXEYaBv/m3jVEMpTGTRjnFoUB0WOii+EMJk4vaWPQ=; b=hy+bTC/TX5K74GLF57u7j+XjEZXb2dvgBOe7M+AfDCbTeq2nmhr9/LXOxYY7UC052O +JLNEAfnioaRdbvchHqxVUD0XMa0HZr8e87B8fYGpqgnlzU+VjyvD+k58OIVQY4H1Cyf kfWfc+fc04oVEt2YUUcHpAHzk/kmqqud6u/hdAaPn0VgPxejmoFciu3ORFnOTkTZ8Zbr DDh4921ezMIFboynVcmpq1Xx23swVaGOCLcsHEaoCIiGtqgq7YCngbRQFuD96YxdrETL kkAX9x2OmyKQksje7YTRLKOhRzhuGktDEcCVS/2EaAL9ISkd754rVSA4SyvbHs0+9A33 JSoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id o127-20020a62cd85000000b006cdd3d27aa6si1459952pfg.260.2023.11.29.09.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 09:44:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id EE10680C5CA0; Wed, 29 Nov 2023 09:44:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231302AbjK2Rno (ORCPT + 99 others); Wed, 29 Nov 2023 12:43:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231293AbjK2Rnc (ORCPT ); Wed, 29 Nov 2023 12:43:32 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DF4D0F4; Wed, 29 Nov 2023 09:43:37 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 69D1F1756; Wed, 29 Nov 2023 09:44:24 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 631263F73F; Wed, 29 Nov 2023 09:43:33 -0800 (PST) From: Robin Murphy To: Joerg Roedel , Christoph Hellwig Cc: Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Suravee Suthikulpanit , David Woodhouse , Lu Baolu , Niklas Schnelle , Matthew Rosato , Gerald Schaefer , Jean-Philippe Brucker , Rob Herring , Frank Rowand , Marek Szyprowski , Jason Gunthorpe , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux.dev, devicetree@vger.kernel.org Subject: [PATCH 5/7] iommu/dma: Make limit checks self-contained Date: Wed, 29 Nov 2023 17:43:02 +0000 Message-Id: <951f52b59b401418a7ccc00beed15632d1aabd7a.1701268753.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 29 Nov 2023 09:44:07 -0800 (PST) It's now easy to retrieve the device's DMA limits if we want to check them against the domain aperture, so do that ourselves instead of relying on them being passed through the callchain. Signed-off-by: Robin Murphy --- drivers/iommu/dma-iommu.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 5dc012220ca9..7745e7e17010 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -659,8 +659,6 @@ static void iommu_dma_init_options(struct iommu_dma_options *options, /** * iommu_dma_init_domain - Initialise a DMA mapping domain * @domain: IOMMU domain previously prepared by iommu_get_dma_cookie() - * @base: IOVA at which the mappable address space starts - * @limit: Last address of the IOVA space * @dev: Device the domain is being initialised for * * @base and @limit + 1 should be exact multiples of IOMMU page granularity to @@ -668,10 +666,10 @@ static void iommu_dma_init_options(struct iommu_dma_options *options, * to ensure it is an invalid IOVA. It is safe to reinitialise a domain, but * any change which could make prior IOVAs invalid will fail. */ -static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, - dma_addr_t limit, struct device *dev) +static int iommu_dma_init_domain(struct iommu_domain *domain, struct device *dev) { struct iommu_dma_cookie *cookie = domain->iova_cookie; + const struct bus_dma_region *map = dev->dma_range_map; unsigned long order, base_pfn; struct iova_domain *iovad; int ret; @@ -683,18 +681,18 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, /* Use the smallest supported page size for IOVA granularity */ order = __ffs(domain->pgsize_bitmap); - base_pfn = max_t(unsigned long, 1, base >> order); + base_pfn = 1; /* Check the domain allows at least some access to the device... */ - if (domain->geometry.force_aperture) { + if (map) { + dma_addr_t base = dma_range_map_min(map); if (base > domain->geometry.aperture_end || - limit < domain->geometry.aperture_start) { + dma_range_map_max(map) < domain->geometry.aperture_start) { pr_warn("specified DMA range outside IOMMU capability\n"); return -EFAULT; } /* ...then finally give it a kicking to make sure it fits */ - base_pfn = max_t(unsigned long, base_pfn, - domain->geometry.aperture_start >> order); + base_pfn = max(base, domain->geometry.aperture_start) >> order; } /* start_pfn is always nonzero for an already-initialised domain */ @@ -1743,7 +1741,7 @@ void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 dma_limit) * underlying IOMMU driver needs to support via the dma-iommu layer. */ if (iommu_is_dma_domain(domain)) { - if (iommu_dma_init_domain(domain, dma_base, dma_limit, dev)) + if (iommu_dma_init_domain(domain, dev)) goto out_err; dev->dma_ops = &iommu_dma_ops; } -- 2.39.2.101.g768bb238c484.dirty