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=1796229391; b=5SHRnoUi3FlInp6QBr7uFYdtOozsjORVXbYEAcsXrJ52+lfWmUH+k0/7BeBerDEqcnkM lHbjnYZf+APLINWduo+mEmtfGIw7AebLHXY6g9smSEMeyUDnV12VbiZIN3XESj1BO2okc NSlFqe9pRM/U/awmWWBfol0zhbTTOceX2hqz/hq2JKigjdfMdieRMs2kcNOVt732uq4UR 9MeeMmakDWljgr46zPwjYLSvDoZxxUacwyFNEgw5WLR+pj+d/8wQkAy3NxHWQOOQXhFbz uUHsW9aUzStHsHr4EBRnpvHeau2vDaO/JWIVUzJlsgbUkK9dSOnx5M7bV/N0kTN3PNA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796229391; 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=eiDebSGHAKsvlxHMiK+GPTMLAqnrFUMJFOq212edF2A=; b=vbTLISz5ZiSCscR/36tKnUldTo+iGASIeVdOg7mlcZqul0D2LJtabBFAb5wzxM6t4Yws yc4T4cqeL9WREihNv4E4/Gvmm9Msl2ZFH4YJMSb+BJjBIJwG3buMclmKO/nEKR5lnibQc RvBi+7MCYVEpMqgNNa4rV6XJ0pvf/oWjYMnrCmbYTo0Oa4xN0A85APKN5/Q4vMI3EqyJe FOEgugsEIu+aQYFtJGBzc/oc6uTtsMMw3ziV1ZyW5mElz/e3ym/IBvs+GSBfIVNy1yc5k t1NjGqMApwgcfyCMVphAirp/JpuVqviZS10kZHle8cTCW3Em6+2AzfcoLYMLUyNfT6A== 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=SOWDx7ld; 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 BED72606A31A for ; Wed, 2 Dec 2026 16:36:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BED72606A31A 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) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=SOWDx7ld 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 696C71570; Wed, 2 Dec 2026 08:36:27 -0800 (PST) Received: from [10.2.212.23] (e121345-lin.cambridge.arm.com [10.2.212.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 630753F86F; Wed, 2 Dec 2026 08:36:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796229390; bh=LiW8bo2/+55ee6MWe8FJAJ2BUw/T6+8p2EKy9aqbxN0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=SOWDx7ld8sP0dwBfqalC9zwix19avb18cmolIjtRCLoQXKuDiCNF8kRhsBLAK6o86 bhex8H5QP15UIfcGthLmSSNSNDa6ETu/Gbn/H6fa+LP3e6GI493geifcZu/RCKgbJr LOYMpIW1qcRrllqnDGciWkOYP6hhXVHX/FzTHoHk= Message-ID: <38e90198-68c0-4cb3-959b-4f4c7759a18d@arm.com> Date: Wed, 2 Dec 2026 16:36:27 +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 v2] iommu/dma: Skip iova_to_phys() on unmap when unneeded To: Joe Damato , "Joerg Roedel (AMD)" , Will Deacon Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org References: <20261202153325.2819538-1-joe@dama.to> From: Robin Murphy Content-Language: en-GB In-Reply-To: <20261202153325.2819538-1-joe@dama.to> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 02/12/2026 3:33 pm, Joe Damato wrote: > iommu_dma_unmap_phys() looks up the physical address of every mapping > with iommu_iova_to_phys() before unmapping it. > > This is unneeded for a coherent device that does not use a swiotlb. > Skipping this saves a page table walk. > > iommu_dma_sync_single_for_cpu() already skips the walk for these > devices, so do the same in iommu_dma_unmap_phys(). > > For these devices the WARN_ON(!phys) is no longer reached, so unmapping > an IOVA that is not mapped no longer warns there. CONFIG_DMA_API_DEBUG > still catches this class of driver bug. Thanks Joe! Acked-by: Robin Murphy Although now I've made the mistake of remembering we have the higher-level dma_dev_need_sync() thing as well, and starting to wonder how much that now might effectively cover these conditions both here and for iommu_dma_sync_single*()... > Signed-off-by: Joe Damato > --- > v2: > - Squash into one patch and drop the helper; open-code the condition > as Robin suggested. > - Rebase on iommu/core. > > v1: https://lore.kernel.org/20261106175745.3362057-1-joe@dama.to/ > > Measured on prod hosts serving TX heavy network traffic, which unmaps TX > buffers on completion: > > - Intel Xeon Gold 6138 (Skylake), VT-d: iova_to_phys() on unmap was > 119-143 ns per TX packet (~0.5% of busy CPU) before, 0 after. > - AMD EPYC 9334 (Genoa), AMD IOMMU: ~10 ns per TX packet (~0.1% of busy > CPU) before, 0 after. > > drivers/iommu/dma-iommu.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index 7c5abb77f4d6..80448fe533bf 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -1256,7 +1256,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; > } > > base-commit: a0aa8306adbb522f3f2a26393cc1e12a1836f084