Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3152241lqo; Tue, 21 May 2024 08:15:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU+4MqwASKxzPrcsXh2kQV5N7BdL5+kSMEhBMx6z8dZ2Zf0cWr4p1jWYAjji/t31M2+JODddAN52XfDszUdnXmw0PjPIOg2ENbTq3S8fg== X-Google-Smtp-Source: AGHT+IEt/PrGGmuPweyofbjxFxq6cRTWh1IaGGWOFQs9IjlWu8lSTpfgfTd7MW6dZsp275j9HyvI X-Received: by 2002:a17:906:358c:b0:a59:b17c:c9d2 with SMTP id a640c23a62f3a-a5d59cbeb91mr795151866b.12.1716304504129; Tue, 21 May 2024 08:15:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716304504; cv=pass; d=google.com; s=arc-20160816; b=hqGkVx+vnr162lkcRbj6pHqEDeI2MZMb+cdi45ZoZP1toYCSCANRPpPxpp7391dL7L No5Oi/hBIGbIAPFEP0Sf3Hwp/HEk9IQVIPTpq1rwagS4bgkSJNWZdHLe0gHXnb72h6Gy uh8mOG4k0XVOXyZsKhcejkwbQap9+dUbeDSl35zGNXjdoEVg49ObAaLfRhn3bTazQIIm +vKXk7LtLOdoGvPLHuNeKzJGrceynPny+RQA5Dg8R8brkbyDSL9WTqmXi7kM8BGh8P90 KfO6ge0/g50VedgKnx1jY9t33nnwGCygL5mvpsqF6/MjyIW0YRNRIVCrS4ro0pWEBKPh Un/w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=bAhG1fHgWGaKii6f9oZ1sn/38zTWqI8ttLVPeUYuyNc=; fh=7h97dVu5zJWH/+fSYpFtDf2f1S9myM8uJE7O6AHOH88=; b=Fa1zuMPJkgZZ+udM6qtGhJdA4lEROTeFGz8fbtk5X2wPOwXtBU7UbYwB7MV9hROCnD 3chFI2TYy8nvGhfKAbjhyPtLFta9ZRanIvYf3m05G22FnzVhjC3980cEPakg8tmMZsSl vvURHFOO1cKpmLOr6ranj/rej571QJ8CAbED+vjToREsa5Aw4SuKElMXrbDTF4izfoET C5PfPmcncUCZH/sp6j/bySaUHWgRV7hceFJokEoALTY0DBTMZwNNZYQoJfHNIdkS5fah JiMk+9Fi1b6GYGe95QbnO4KSOBoHUrQZy9TuKki7eNy9ABpfKxWJkAR5fINwfBTmKGKB zzzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-185141-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185141-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17ba38fasi1456891166b.558.2024.05.21.08.15.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 08:15:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185141-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-185141-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185141-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 DA13A1F2211B for ; Tue, 21 May 2024 15:15:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71C56143C65; Tue, 21 May 2024 15:14:56 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2EF19143C54 for ; Tue, 21 May 2024 15:14:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716304495; cv=none; b=KiXQk8a+LJLE7cG5PUhgsxwyDkhUdON9yWeJ2w6etIAEI/XrDUryhIuQj07yjKrDj2U1Fwf145FYHA3NmVFDp/OdSw1ersUnM2OOfkiD1OIdAFukfrO7W0TL5VeeKLs4EXgXOjal7gHT80G9Gycgn17CDyWBNSqCjVY1rCQkgB0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716304495; c=relaxed/simple; bh=tdOjwBB/EVqP4uS0K9ID2XC+ksP7U3GvDkuPvE6oHXA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=eogON8GLmx0rWIE9AdiRYhD3jtdwJKr8ggh9Q2eklhHChVqhXxXMdQTiWEGA3qH/pfqKbMsuLcTJ9VS1ZMeu1X/oAFuo7F227nzRqdLBI3hv3XNQpG0Lwcx42tfpu5WRp9ERy4gxzchty2wnPj5niVxJdZit5n+tUx/1h1U7jXE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 53BE3DA7; Tue, 21 May 2024 08:15:16 -0700 (PDT) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 877BF3F641; Tue, 21 May 2024 08:14:51 -0700 (PDT) Message-ID: <02ebbb90-84bc-4d8c-a7aa-94cd78e0a2a5@arm.com> Date: Tue, 21 May 2024 16:14:50 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] iommu/dma: Fix domain init To: Jerry Snitselaar Cc: joro@8bytes.org, iommu@lists.linux.dev, will@kernel.org, linux-kernel@vger.kernel.org, Jon Hunter References: <721fa6baebb0924aa40db0b8fb86bcb4538434af.1716232484.git.robin.murphy@arm.com> From: Robin Murphy Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 21/05/2024 5:45 am, Jerry Snitselaar wrote: > On Mon, May 20, 2024 at 08:14:44PM GMT, Robin Murphy wrote: >> Despite carefully rewording the kerneldoc to describe the new direct >> interaction with dma_range_map, it seems I managed to confuse myself in >> removing the redundant force_aperture check and ended up making the code >> not do that at all. This led to dma_range_maps inadvertently being able >> to set iovad->start_pfn = 0, and all the nonsensical chaos which ensues >> from there. Restore the correct behaviour of constraining base_pfn to >> the domain aperture regardless of dma_range_map, and not trying to apply >> dma_range_map constraints to the basic IOVA domain since they will be >> properly handled with reserved regions later. >> >> Reported-by: Jon Hunter >> Reported-by: Jerry Snitselaar >> Fixes: e28a114243d1 ("iommu/dma: Make limit checks self-contained") > > I'm seeing this upstream as ad4750b07d34 ("iommu/dma: Make limit checks self-contained") now. What, you mean when Linus pulls some patches I wrote he *doesn't* also rebase my local development branch for me? /facepalm Joerg, please shout if you'd like a resend for that. >> Signed-off-by: Robin Murphy >> --- > > Tested-by: Jerry Snitselaar > Reviewed-by: Jerry Snitselaar Thanks! Robin. >> drivers/iommu/dma-iommu.c | 8 ++++---- >> 1 file changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c >> index 89a53c2f2cf9..1ec89ca75c59 100644 >> --- a/drivers/iommu/dma-iommu.c >> +++ b/drivers/iommu/dma-iommu.c >> @@ -685,15 +685,15 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, struct device *dev >> >> /* Check the domain allows at least some access to the device... */ >> if (map) { >> - dma_addr_t base = dma_range_map_min(map); >> - if (base > domain->geometry.aperture_end || >> + if (dma_range_map_min(map) > domain->geometry.aperture_end || >> 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(base, domain->geometry.aperture_start) >> order; >> } >> + /* ...then finally give it a kicking to make sure it fits */ >> + base_pfn = max_t(unsigned long, base_pfn, >> + domain->geometry.aperture_start >> order); >> >> /* start_pfn is always nonzero for an already-initialised domain */ >> mutex_lock(&cookie->mutex); >> -- >> 2.39.2.101.g768bb238c484.dirty >> >