Re: [PATCH 03/24] iommu/amd: Detect and initialize AMD vIOMMU feature
From: Suthikulpanit, Suravee
Date: Tue Sep 01 2026 - 12:43:38 EST
Hi
On 8/10/2026 3:13 PM, Vasant Hegde wrote:
.../...
}
static int __init amd_iommu_init_pci(void)
diff --git a/drivers/iommu/amd/viommu.c b/drivers/iommu/amd/viommu.c
new file mode 100644
index 000000000000..f4b5f96d4785
--- /dev/null
+++ b/drivers/iommu/amd/viommu.c
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 Advanced Micro Devices, Inc.
+ */
+
+#define pr_fmt(fmt) "AMD-Vi: " fmt
+#define dev_fmt(fmt) pr_fmt(fmt)
+
+#include <linux/iommu.h>
+#include <linux/iommufd.h>
+#include <linux/amd-iommu.h>
+#include <uapi/linux/iommufd.h>
+
+#include <asm/iommu.h>
+#include <asm/set_memory.h>
+
+#include "iommufd.h"
+#include "amd_iommu.h"
+#include "amd_iommu_types.h"
+#include "amd_viommu.h"
+
+int __init amd_viommu_init(struct amd_iommu *iommu)
+{
+ if (!amd_iommu_viommu ||
+ !check_feature(FEATURE_VIOMMU))
If check_feature returns false, then return -ENOSUPPORT so that called sets
amd_iommu_viommu to false.
Actually, that would print "Failed to initialize vIOMMU" in dmesg on older systems, which does not support the feature. We don't want that.
For v5, I will clean up this logic to make sure that the amd_iommu_viommu is false when the feature is not supporte.
Also how about renaming it as "amd_iommu_viommu_present" ? Because following
patches defines another structure with same name. It works, but add confusion.
I'll change this to amd_iommu_viommu_enabled in v5
Thanks,
Suravee
-Vasant