From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796157043; b=oHodxhYABpTTfMAPBaYSZZmMUzWcsCpWSB/Im+SJLgatq9FofRmzxum+pWZS9yTMQc2v 4BLZziTmP3EYjlj0XDt8V0oCPqm5brxrVsmWanfP31NFBmsTItVRB70e1IFwhwP/H8FdH X3LNdiqicaJZqxlDh0RnBMJjVOJsyV9lLdVylH3FenbMe+mtJ8rD5clHw36ed2jJRgdtk 5fCDCtll7Ee/fCZFc/mFYjzT2cswGb7rUaKFDtxv6qqh1Vid6oHs6DTTETfbXAjIyvHcD ozn0ak63ND+/Pp5UI4P2PuTvOsupxq2NA/RdMnmqtqYdZo6LEfnyNV4o0Ztevm2U6tA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796157043; h=DMARC-Filter:Received:Received:DKIM-Signature:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:From: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=ABa35+Jwz5+Iems7oO20yNN6ha6HVYXdK+F05Zcwbxk=; b=pDNYJ7AVxuWLjfL0bBiwFX9R3ONo5cJ3hMws51p8po+CkyNa4xki6ZG25cRXsmWAXLqF TD/VI+lvGO65KHrI8rmPmnjTB1m4vhIC3NjJA0dlasRb36noRZNwKZObsPK3SuaI/CS0b 1u6tWY5l5Y14dPRS1N2lgDNq03+wTjDA6g8y4A4+/f36KX1ORsE9qK4PRlVX/yQsPUOBJ ivfaMMyQINf8jO8ppgcKAPei2tA4nRl03flkO+sS0o6x05odCFFBZV4P7X0nT8SAiqa8e 89h3RXr4oYYlthNhSqNS6aLn8vOtG6FKgNXfhp13lzYjWB+SyMTVs9MQieDuqNrsBAg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=Ny1CFJK8; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3AF30606A31A for ; Tue, 1 Dec 2026 20:30:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3AF30606A31A 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=Ny1CFJK8 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 7CCFF152B; Tue, 1 Dec 2026 12:30:39 -0800 (PST) Received: from [10.57.72.26] (unknown [10.57.72.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 740403F86F; Tue, 1 Dec 2026 12:30:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796157042; bh=XQRv3unmwRdg+nVES7TYVz1RunV2rwLdo9RfSvbQq2Q=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Ny1CFJK80f+CkfPLbRjVfBDUOAdVMNBJYnCUvjgRpQpjFUord+d3WZARQ6kLCLTL+ ICFoXHMZJzzLqqcgbPkz2G/2cQPpPNZs9Zwvj3UovRnjW4/8wvW6c6Meeh1Oz4OZk6 RiLMB87s4VJVfTv6JFyR/OaoqtUdu9fBwokOw63E= Message-ID: <2ca7331a-68b0-4751-a014-f430782e34ca@arm.com> Date: Tue, 1 Dec 2026 20:30:38 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] iommu/dma: Add helper for coherent devs without swiotlb To: Joe Damato , "Joerg Roedel (AMD)" , Will Deacon Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org References: <20261106175745.3362057-1-joe@dama.to> <20261106175745.3362057-2-joe@dama.to> From: Robin Murphy Content-Language: en-GB In-Reply-To: <20261106175745.3362057-2-joe@dama.to> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2026-11-06 5:57 pm, Joe Damato wrote: > Factor out some repeated logic which checks if a device is coherent and > if there is a swiotlb. > > Replace repeated instances of this logic with a call to the helper > instead. dev_use_swiotlb() itself already contains a frankly confusing number of levels of indirection. I guess I can buy the argument for patch #2, but please just make it the trivial 2-liner that doesn't obfuscate the conditions (and thus correlates even more clearly to those same conditions in the map path) i.e.: @@ -1280,7 +1280,8 @@ void iommu_dma_unmap_phys(struct device *dev, dma_addr_t dma_handle, { phys_addr_t phys; - if (attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT)) { + if ((attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT)) || + (dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev, size, dir))) { __iommu_dma_unmap(dev, dma_handle, size); return; } Thanks, Robin. > > Signed-off-by: Joe Damato > --- > drivers/iommu/dma-iommu.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index 78742aeba932..a25ee287a5ac 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -628,6 +628,12 @@ static bool dev_use_sg_swiotlb(struct device *dev, struct scatterlist *sg, > return false; > } > > +static bool dev_is_coherent_no_swiotlb(struct device *dev, size_t size, > + enum dma_data_direction dir) > +{ > + return dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev, size, dir); > +} > + > /** > * iommu_dma_init_options - Initialize dma-iommu options > * @options: The options to be initialized > @@ -1103,7 +1109,7 @@ void iommu_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, > { > phys_addr_t phys; > > - if (dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev, size, dir)) > + if (dev_is_coherent_no_swiotlb(dev, size, dir)) > return; > > phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle); > @@ -1120,7 +1126,7 @@ void iommu_dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, > { > phys_addr_t phys; > > - if (dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev, size, dir)) > + if (dev_is_coherent_no_swiotlb(dev, size, dir)) > return; > > phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle);