From nobody Thu Apr 2 22:17:39 2026 Received: from outbound.baidu.com (jpmx.baidu.com [119.63.196.201]) by smtp.subspace.kernel.org (Postfix) with SMTP id 25CF8381C4 for ; Thu, 26 Mar 2026 09:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=119.63.196.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774517905; cv=none; b=bySxzRmDFZEVCcGChUIjSh7TCf6tgwCPWP12EUFQojqeJSnS1mRjuEQOVYtlJmD0Y6h9aB6EcVgcIGHwVopBHzB+HmU+XbScyokhIYGfO70J7/XUEOBp9Zk+8fl7LjjWryCQGDJjSHJq5NqHy9JTLsNJT0sShh8I6JLCP3O9Q9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774517905; c=relaxed/simple; bh=ioiU3gOaBcPfvl5jFvkiKhx3goMxrfnQtCjfPnNt9UY=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=LbwYOwS2AHI7sJv6GxkYygsYpcNHG3/SC0BXUCUjPdwPFmIeAlVh8LR0+Kb6E4TY3jZMyqvX6lnR2aOhlxg9VrCzZtlepUyaIoY3RrdJWLUsNRLJODpeqTpzrwP172rus9o0t+zqeJzBWZPtbIVNczZPatTJXE+N56Tn2f62Qf8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com; spf=pass smtp.mailfrom=baidu.com; dkim=pass (2048-bit key) header.d=baidu.com header.i=@baidu.com header.b=a7Cxw5hP; arc=none smtp.client-ip=119.63.196.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baidu.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baidu.com header.i=@baidu.com header.b="a7Cxw5hP" X-MD-Sfrom: lirongqing@baidu.com X-MD-SrcIP: 172.31.50.47 From: lirongqing To: Joerg Roedel , Suravee Suthikulpanit , Will Deacon , Robin Murphy , , CC: Li RongQing Subject: [PATCH] iommu/amd: Default to passthrough mode for improved performance Date: Thu, 26 Mar 2026 05:38:01 -0400 Message-ID: <20260326093801.2213-1-lirongqing@baidu.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: bjkjy-exc11.internal.baidu.com (172.31.51.11) To bjkjy-exc3.internal.baidu.com (172.31.50.47) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baidu.com; s=selector1; t=1774517898; bh=8fGkhPCA9mlhNmbdPn/04ARmhqDqXHG/Uemd0fNdiJo=; h=From:To:CC:Subject:Date:Message-ID:Content-Type; b=a7Cxw5hP7MrruFb/IBGgfq7D7cliyoXIc/hiUYtTok8+6dn7wg8ZYVI/PblY6+AJ4 DfxTwwhkojIgCn7U15fiJWgVxSWYWnWNEtJ6nlYG2AmDc9i6+2qU4Z/zePAo86TU2o s5wnLv72OXEzHpar0+g9C/CLo7H+wNoWoR5jTunoISQbYMun44zerrivkOa8T2q7T4 a7A0IfSz+KhZlzWAz4sH0tS282/eaBAan5s5+zInCp0IrvTZdwso2jN5wRWKJc69wn DYDRdBbFnrMKuS4NmVBjlfuWJ3HQKxeJtdShisN+9w9PfBHmgFXIcAK9Hrl8OrvwgF x4YASInrm4Whw== Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Li RongQing On x86 platforms, AMD IOMMU is typically enabled by default. When the kernel is compiled with CONFIG_IOMMU_DEFAULT_DMA_LAZY, the IOMMU operates in translated mode with deferred TLB flushing. While this provides a security layer, it introduces measurable performance overhead compared to Intel systems where the IOMMU often defaults to a disabled state. To optimize out-of-the-box performance for AMD users, shift the default to passthrough mode when the following conditions are met: 1. No explicit IOMMU mode was requested via the command line. 2. The kernel was configured to use 'lazy' DMA remapping by default. 3. Memory encryption (SME/SEV) is not active, as these features require translation for security. This change allows standard DMA operations to bypass remapping overhead while maintaining the ability for users to explicitly enable translation if required. To support this, export iommu_dma_is_user_configured() from the IOMMU core to allow vendor drivers to check if the DMA API configuration was overridden by the user. Signed-off-by: Li RongQing --- drivers/iommu/amd/init.c | 9 +++++++++ drivers/iommu/iommu.c | 6 ++++++ include/linux/iommu.h | 1 + 3 files changed, 16 insertions(+) diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index f3fd7f3..e89a5ce 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -3619,6 +3619,15 @@ void __init amd_iommu_detect(void) amd_iommu_detected =3D true; iommu_detected =3D 1; x86_init.iommu.iommu_init =3D amd_iommu_init; + + if (!iommu_dma_is_user_configured()) { + if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT) && + IS_ENABLED(CONFIG_IOMMU_DEFAULT_DMA_LAZY)) { + pr_info("Defaulting to Passthrough mode for performance\n"); + iommu_set_default_passthrough(false); + } + } + return; =20 disable_snp: diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 50718ab..a950dbb 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -4091,3 +4091,9 @@ int iommu_dma_prepare_msi(struct msi_desc *desc, phys= _addr_t msi_addr) return ret; } #endif /* CONFIG_IRQ_MSI_IOMMU */ + +bool iommu_dma_is_user_configured(void) +{ + return !!(iommu_cmd_line & IOMMU_CMD_LINE_DMA_API); +} +EXPORT_SYMBOL_GPL(iommu_dma_is_user_configured); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 54b8b48..c3ff8a9 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -967,6 +967,7 @@ int iommu_set_pgtable_quirks(struct iommu_domain *domai= n, unsigned long quirks); =20 void iommu_set_dma_strict(void); +bool iommu_dma_is_user_configured(void); =20 extern int report_iommu_fault(struct iommu_domain *domain, struct device *= dev, unsigned long iova, int flags); --=20 2.9.4