From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C44E3D3CEA for ; Fri, 29 May 2026 11:51:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780055481; cv=none; b=m0PiK9cI5qEZFT1WtjzhLmtHdZR0P0qyADhlBOcYZyrZR5Uhg3blyKMkaIhNSZXhiQbRbzaotHcv0j3P1/OfuHHqWpzofoyPcdBsTK/toqm+ThnesGbCMMTzOXp0hABBAnaGAC09UjwndtEdTrM/HqChwd4ay5jcTgexaw0kfS4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780055481; c=relaxed/simple; bh=54vAzaIEYqsXM3xuiGWXl2HbeuhzM33ptPMT3OM8+FI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OgPADlm297Pt+VT1MmnAbjNUZSUnP90L4UukJ1JSmeEaQo20Zuyw5NPK7CTucWbvsS5EKZkoUtO3eLVcem/BvPjRoN2EjvxPNXlcIeQ7DvfswPEGxJFa/egEyTlaUBaRunMYrhQc6UKjIWy0WP28MQc/MJ9h9xASFyI8iCp/UMo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=nnHv6LJe; arc=none smtp.client-ip=209.85.219.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="nnHv6LJe" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-8ccd2c0fa7aso18926346d6.0 for ; Fri, 29 May 2026 04:51:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1780055478; x=1780660278; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=MawsOr5g5TsZEGLcgJS401SzBvbOX6ouP0Fchc3e/Ro=; b=nnHv6LJehQFeXHR9/Y2SMmJ+oPZJtGjG1k2lSfSoHTdL2aGHgg7pUNGXXsIfwkqrK8 G4dp2tNvwBJDcI/lnIBco2+/1mFZpHVpxOB0UwMrpU8SjvLS9zMCXiac/ucr+5A7YFNM lSfdag8WR4FEhslRDpS1ToPHA1f03nwF6WrVsWKrb1PgXpi2f2PR1heL5TAV3KGih3Ai MQ8NICS2yk2T3oCIe3sZDmnahfkp230bEU3ND0xjsyZkZeuaVVttthwmEoEfghV/goHZ aU01gJ15/kNGQnAWlV77Wk7wLOCP0Q2PKekVcbDa6uiHLHONsTKTMPh3jYgwQCBFLWbQ z4HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780055478; x=1780660278; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MawsOr5g5TsZEGLcgJS401SzBvbOX6ouP0Fchc3e/Ro=; b=IvXjQcNTTPZ5atMDt3+yVOpnftzTdTy5RL+E77KOBypygiBoLF5f00rWrfkWGnd1XH l3A67KK/uU4FIrmo6diacNJYXFcZJZKfRMx+8QN/xf9RIR/255/W3ZUwFvX3RtqWHWmn If9VJpDPnaIB4Pg6jBb0JTn3eU4fCx1yqx8N7DsWu80JiOyi0j07UAR6uMShf+gmsCvB pfCyWu3oiloM2CAOLFw7jFgLI6jkCcr1EIbwBKBZHWMW+zSqHhlxYpimbTZRPXPutq5u t0ZINy4YvRtqhaKKXLnfuJbaXdgrOzZlp2lRL80TzFWsmpdikkDiJpbygwAckVzXJX+9 izdg== X-Forwarded-Encrypted: i=1; AFNElJ/Av6WInqA6KoKbJ3uxlGu7knKQZphHmLJ/kJz5SP9oANL6bp42mn9vJeL16ZrTKWNIgogWV7sD2HRfmqk=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3EcfXM7hRFLVyyeJCXBzdlMLJRRxhpsuoiONdVUBNitAMEBdR ynkW5VhjKm6e74k8+AmkL4KN14bcNO/Lv7IvyPerZ6W3sBeymBWJOgeqMpcpvJ1SoU0= X-Gm-Gg: Acq92OFqZZCftTN6idRX2nvJWlUClBynKGQj6alGTEnvsLNmt4yOU/WJ31uETEdWWBM 3x2HPwovoci8iqA+zdOyMIdsfsnRs4xTcI+lSyYFktW+CNTaZDyOrfZ3zQXm1doAKIsivqflmzH SLpoxDDJHEnx3sSQpz9DQhjAUi++zs5jC8Z80Job4JNPeH7mm8JzWje24TOxHvc0LsYKoylpjGD heYwinvbHRSDvfirxIOy0yRMIup3scZZfqvPq9SBDHuY8z4l5zSqrq50QKfDCJNuj8dQg44sfft i9biRBxhiiCe6PvsertJaDNA4/uTqgcJW1MHQRJ4IIJFO4XUueqipGqbi+8S8A/7okQcja79AwL xYF0/Hj0aUAf/MukOizFiAfdmBiWc3IeTeZ/cYZ4QnSomV2M/KW4TuqzRtGFfiPhfw3E+T8+7La yDR633Ags0kbBOwcTJfuszvmDujUwE0NANsUtmioD8q3hmL2pt6t/Zuvp4Sq/QLeAvy7tovCHCe jKy3Q0OyuYkqn05 X-Received: by 2002:a05:6214:3d08:b0:8cc:e14:9594 with SMTP id 6a1803df08f44-8cce829b0admr31409816d6.33.1780055478649; Fri, 29 May 2026 04:51:18 -0700 (PDT) Received: from ziepe.ca (crbknf0213w-47-54-130-67.pppoe-dynamic.high-speed.nl.bellaliant.net. [47.54.130.67]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ccea0451c7sm12666566d6.6.2026.05.29.04.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 04:51:17 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wSvkC-00000000SKF-3RtJ; Fri, 29 May 2026 08:51:16 -0300 Date: Fri, 29 May 2026 08:51:16 -0300 From: Jason Gunthorpe To: Guanghui Feng Cc: joro@8bytes.org, suravee.suthikulpanit@amd.com, will@kernel.org, robin.murphy@arm.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, alex@shazbot.org, kevin.tian@intel.com, skhawaja@google.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [RFC PATCH] Optimize VFIO and IOMMU mapping traversal Message-ID: <20260529115116.GR2487554@ziepe.ca> References: <20260529070932.2632907-1-guanghuifeng@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260529070932.2632907-1-guanghuifeng@linux.alibaba.com> On Fri, May 29, 2026 at 03:09:32PM +0800, Guanghui Feng wrote: > In VFIO, vfio_unmap_unpin requires performing iommu unmap and mm > unpin on the address space. However, VFIO doesn't record the PHY > address corresponding to iova, but instead obtains the iova-PHY > mapping through iommu_iommu_iova_to_phys. > > In IOMMU, under conditions such as address alignment, it prioritizes > mapping iova-PHY based on bigpages. Therefore, during the > vfio_unmap_unpin process, traversal can be performed at the > granularity of the IOMMU map, reducing the number of > iommu_iova_to_phys queries and significantly improving conversion > efficiency. > > Therefore, an iommu_iova_to_pgsize implementation is added to the > IOMMU driver to return the pagesize used for the iova mapping. This is the wrong API, what we need here is an iova_to_phys variation that returns a size so physically contiguous IOPTEs can be joined. > drivers/iommu/amd/iommu.c | 2 ++ > drivers/iommu/generic_pt/iommu_pt.h | 53 +++++++++++++++++++++++++++++ > drivers/iommu/intel/iommu.c | 2 ++ > drivers/iommu/iommu.c | 25 ++++++++++++++ > drivers/vfio/vfio_iommu_type1.c | 17 +++++++-- If you care about performance use iommufd, and patches like this have to update iommfd too. > static const struct iommu_domain_ops amdv1_ops = { > IOMMU_PT_DOMAIN_OPS(amdv1), > + IOMMU_PT_PGSIZE_OPS(amdv1), > .iotlb_sync_map = amd_iommu_iotlb_sync_map, > .flush_iotlb_all = amd_iommu_flush_iotlb_all, > .iotlb_sync = amd_iommu_iotlb_sync, It should be routed through the private ops structure, and even if not no reason to make another macro. This would also need to be split into a patch adding the core API function and then updating callers. Jason