[PATCH 08/22] iommu/amd: Introduce Reset vMMIO Command

Suravee Suthikulpanit
2026-03-30T08:43:22Z

Introduce new IOMMU commands for vIOMMU to reset
virtualized MMIO registers of a particular guest.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
drivers/iommu/amd/amd_iommu.h | 1 +
drivers/iommu/amd/amd_iommu_types.h | 1 +
drivers/iommu/amd/iommu.c | 22 ++++++++++++++++++++++
drivers/iommu/amd/iommufd.c | 3 +++
4 files changed, 27 insertions(+)

diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h
index 470e5d98c52b..f1fafa21777d 100644
--- a/drivers/iommu/amd/amd_iommu.h
+++ b/drivers/iommu/amd/amd_iommu.h
@@ -11,6 +11,7 @@

#include "amd_iommu_types.h"

+void iommu_reset_vmmio(struct amd_iommu *iommu, u16 gid);
irqreturn_t amd_iommu_int_thread(int irq, void *data);
irqreturn_t amd_iommu_int_thread_evtlog(int irq, void *data);
irqreturn_t amd_iommu_int_thread_pprlog(int irq, void *data);
diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
index f0e18a7dd7f2..53854a4f4307 100644
--- a/drivers/iommu/amd/amd_iommu_types.h
+++ b/drivers/iommu/amd/amd_iommu_types.h
@@ -221,6 +221,7 @@
#define CMD_INV_IRT 0x05
#define CMD_COMPLETE_PPR 0x07
#define CMD_INV_ALL 0x08
+#define CMD_RESET_VMMIO 0x0A

#define CMD_COMPL_WAIT_STORE_MASK 0x01
#define CMD_COMPL_WAIT_INT_MASK 0x02
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 037a50397f31..191a52b657c1 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -1429,6 +1429,18 @@ static void build_inv_irt(struct iommu_cmd *cmd, u16 devid)
CMD_SET_TYPE(cmd, CMD_INV_IRT);
}

+static void build_reset_vmmio(struct iommu_cmd *cmd, u16 gid,
+ bool vcmd, bool all)
+{
+ memset(cmd, 0, sizeof(*cmd));
+ cmd->data[0] = gid;
+ if (all)
+ cmd->data[0] |= (1 << 28);
+ if (vcmd)
+ cmd->data[0] |= (1 << 31);
+ CMD_SET_TYPE(cmd, CMD_RESET_VMMIO);
+}
+
/*
* Writes the command to the IOMMUs command buffer and informs the
* hardware about the new command.
@@ -1663,6 +1675,16 @@ void amd_iommu_flush_all_caches(struct amd_iommu *iommu)
}
}

+void iommu_reset_vmmio(struct amd_iommu *iommu, u16 gid)
+{
+ struct iommu_cmd cmd;
+
+ build_reset_vmmio(&cmd, gid, 1, 1);
+
+ iommu_queue_command(iommu, &cmd);
+ amd_iommu_completion_wait(iommu);
+}
+
/*
* Command send function for flushing on-device TLB
*/
diff --git a/drivers/iommu/amd/iommufd.c b/drivers/iommu/amd/iommufd.c
index 5dcd3fc3ba99..06d6aa87cdcd 100644
--- a/drivers/iommu/amd/iommufd.c
+++ b/drivers/iommu/amd/iommufd.c
@@ -79,6 +79,9 @@ int amd_iommufd_viommu_init(struct iommufd_viommu *viommu, struct iommu_domain *
if (ret)
goto err_out;

+ /* Reset vIOMMU MMIOs to initialize the vIOMMU */
+ iommu_reset_vmmio(iommu, aviommu->gid);
+
ret = iommu_copy_struct_to_user(user_data, &data,
IOMMU_VIOMMU_TYPE_AMD,
reserved);
--
2.34.1