From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.133 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796178684; b=bsIMcjUo7O6KSH/YR3PxAHP2WaVMKYsZ2WqVYk4JC/ll0IoeckRnczqnVwe6xSOaHCET P7fXBxF65T173akPLi2M7UIBxaZuaoRKQF1/59L2AT/uNAkcH4tdYQg1HfKWTMsDhq9JM fXJEbP6cy+GYfKH5K3fmZvPk/pYyvAe+an0AoCrltbeQfrzLfkmhSiBMMCIQep/vlXdBl WDylFkHAORvnhw1VspZ8TX2fULBEsqqU3NM5KyNwd/GZzQQfHsLEByQ1FjB7gMVEfED+k w1rFBGVCN300K/IHjLU/RKgFsUV7OqnaQ5rUV3XK/wRVUhqYeG8H69cXXZ6oi7yVnuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796178684; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:Cc:References:From: In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=pxAZfa/aphxvG6KK+8lvWhL4BkbYOgmmqK0Zc6qDff8=; b=YkrdASSrV0OaZ17ggMT7HrhLVSkuJvSmBU5nQdv8qM0tarC6X9HHCDf2PjkDGDflGm7L dhQsvtccnlxeV6U+Epp+FQTTnqxT8ReYp+JFM3dOlpsX6J7p4HxCeSAEeyoJZVppx1seY yiaespZ1JDxY0LK3XILSpRzDn+MsSKVAMr5JkJRPDVhZMEXP9L7kiyLiVGqnY8B2JmHac ev+A78Oi+00oPOFQ1KRIPKSaA8N8k8jGKbx2zCss5XH6Nl/9uSGkTQd/2Jw1y9rOqSVcf PNEEmVMGb8YnHeANbo9vPeTi/FJMDsJ7mwrx4RQHy7ayec5pv34/mPLbdCud4yETYoA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=GPphyqlj; arc=none smtp.remote-ip=115.124.30.133 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAEF2606A68B for ; Wed, 2 Dec 2026 02:31:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EAEF2606A68B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=GPphyqlj DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796178678; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=pxAZfa/aphxvG6KK+8lvWhL4BkbYOgmmqK0Zc6qDff8=; b=GPphyqljUZa77BpFSJeZreTcjDlFuuAgd45OA7lQ/O9CHV0URGgZQBE0m5moH7qkXWIMEaSPc9CvRY8G5De9vADvlB8gTCc9bZGqnZA6Zlpkiz+rdokJRrfNdcQ5eQ2N3Zsi6R9nIdwrEFeVkHpNwO0Qh7HrNrYnzK9eGF6XqTE= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045144198;MF=guanghuifeng@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0XG5m3eU_1796178677; Received: from 30.221.133.171(mailfrom:guanghuifeng@linux.alibaba.com fp:SMTPD_---0XG5m3eU_1796178677 cluster:ay36) by smtp.aliyun-inc.com; Wed, 02 Dec 2026 10:31:17 +0800 Message-ID: <3cab44e0-feff-45b4-8565-32e25dbc0da2@linux.alibaba.com> Date: Wed, 2 Dec 2026 10:31:16 +0800 X-Mailing-List: iommu@lists.linux.dev 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 0/2] iommu/amd: Optimize IRT cache invalidation for nested VM workloads To: Sairaj Kodilkar , joro@8bytes.org, vasant.hegde@amd.com, suravee.suthikulpanit@amd.com, will@kernel.org, robin.murphy@arm.com Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org References: <20261113095017.1835921-1-guanghuifeng@linux.alibaba.com> <9bb63df8-29b5-4b0c-9758-3fbbdb61dd06@amd.com> From: "guanghuifeng@linux.alibaba.com" In-Reply-To: <9bb63df8-29b5-4b0c-9758-3fbbdb61dd06@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Sairaj Thanks a lot for running the tests and for the Tested-by. Your numbers actually point at an important detail: the flush path taking 172546 ns *including the COMPLETION_WAIT* means IRT caching was ENABLED in this run (amd_iommu=irtcachedis not set). In that configuration iommu_flush_irt_and_complete() still issues INVALIDATE_INTERRUPT_TABLE + COMPLETION_WAIT, so the lookup is indeed a tiny fraction -- and this patch deliberately keeps that behaviour byte-for-byte identical, it only drops the redundant list walk. The primary target of this patch is the *cache-disabled* configuration (amd_iommu=irtcachedis). There, the function returns early: if (iommu->irtcachedis_enabled) return; so no command and no COMPLETION_WAIT are issued at all, and the search_dev_data() walk becomes the *only* remaining cost of the whole function. On the reported system the dev_data list has grown to 4334 entries, making that walk 22-33 us of pure waste on every nested VMRUN/#VMEXIT that toggles AVIC. This patch removes 100% of it, not 0.2%. So both measurements are correct and consistent -- they are two points on the same O(N) curve: - your setup: short list (~tens of entries) -> 373 ns - reported setup: 4334 entries -> 22-33 us The list is append-only (alloc_dev_data() only does llist_add(), there is no llist_del()/kfree() in the driver, and dev_data is kept across unplug on purpose), so its length grows monotonically with SR-IOV VF churn and hotplug. There is also a second win that applies to *your* configuration as well: v2 removes the search_dev_data() call in amd_ir_set_vcpu_affinity() too. That path is a use_vapic capability check, not an invalidation, so it is unaffected by irtcachedis and saves one O(N) walk on every AVIC vCPU affinity update regardless of the cache setting. Thanks again for the hardware validation -- it is much appreciated. Best regards, Guanghui Feng 在 2026/11/25 13:34, Sairaj Kodilkar 写道: > On 11/13/2026 3:20 PM, Guanghui Feng wrote: >> This series optimizes the AMD IOMMU interrupt remapping table (IRT) >> cache invalidation path for nested virtualization workloads. >> >> When IOMMU AVIC is enabled, every nested VM entry/exit that switches >> interrupt routes between guest and remapping modes calls into >> iommu_flush_irt_and_complete(). A reported workload with 4334 device >> entries shows median lookup latencies of 22-33 us per invocation due >> to a linear search_dev_data() walk, even when IRT caching is disabled >> and the lookup result is unused. >> >> Patch 1 moves the device lookup after the irtcachedis_enabled early >> return, eliminating the unnecessary walk when IRT caching is off. >> >> Patch 2 caches the device data pointer (resolved at IRQ allocation >> time) in struct amd_ir_data and threads it through all IRTE update >> paths: guest-mode toggle, affinity change, IRQ enable/disable, and >> IRTE free. The amd_irte_ops interface is extended to carry the >> pointer, eliminating all search_dev_data() calls at runtime. >> >> Both patches preserve DMA-alias invalidation, command ordering, >> locking, and completion-wait semantics when IRT caching is enabled. >> >> Guanghui Feng (2): >> iommu/amd: Skip device lookup when IRT caching is disabled >> iommu/amd: Reuse device data for IRTE cache invalidation >> >> drivers/iommu/amd/amd_iommu_types.h | 10 ++-- >> drivers/iommu/amd/iommu.c | 73 ++++++++++++++++------------- >> 2 files changed, 48 insertions(+), 35 deletions(-) >> > > Hi Guanghui, > > Thanks for the patches. I ran a few tests to measure their impact. > > Setup: 12 VMs, each with 32 vCPUs and one passthrough NVMe device. Each > VM runs a small nested (L2) guest that executes CPUID in a loop, which > toggles AVIC for every nested VMRUN/#VMEXIT. > > At a 1:1 pCPU:vCPU ratio, averaged across the 12 VMs: > > search_dev_data() lookup: 373.4 ns > iommu_flush_irt_and_complete(): 172546.1 ns (including the > COMPLETION_WAIT) > > So the lookup is about 0.2% of the flush path. The completion wait is > the main bottleneck here, and the overall gain from this change is > minimal for this path. > > The change is still valid, though. It removes a linear walk of the > dev_data list and the may help other places in the driver that call > search_dev_data(). > > Tested-by: Sairaj Kodilkar > > Thanks, > Sairaj