[PATCH v1 5/8] iommu: Let a driver mark an IOMMU as confidential
From: Nicolin Chen <hidden>
Date: 2026-09-10 03:34:26
Also in:
driver-core, linux-iommu, lkml
Subsystem:
iommu subsystem, the rest · Maintainers:
Joerg Roedel, Will Deacon, Linus Torvalds
An IOMMU inside a confidential VM needs private memory for its queues and tables. Later changes also need to identify it when handling TDISP devices. Add a confidential marker and a helper for IOMMU drivers. The helper also marks the IOMMU device as able to access private memory. Drivers must call it before iommu_device_register(). Assisted-by: Claude:claude-opus-5 Signed-off-by: Nicolin Chen <redacted> --- include/linux/iommu.h | 10 ++++++++++ drivers/iommu/iommu.c | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+)
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index ac43b8b93f14a..bd68532e7f3be 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h@@ -822,6 +822,8 @@ struct iommu_domain_ops { * @singleton_group: Used internally for drivers that have only one group * @max_pasids: number of supported PASIDs * @ready: set once iommu_device_register() has completed successfully + * @confidential: this instance runs inside a confidential VM. Set by the driver + * before any dma allocation. */ struct iommu_device { struct list_head list;
@@ -831,6 +833,7 @@ struct iommu_device { struct iommu_group *singleton_group; u32 max_pasids; bool ready; + bool confidential; }; /**
@@ -890,6 +893,8 @@ struct dev_iommu { int iommu_device_register(struct iommu_device *iommu, const struct iommu_ops *ops, struct device *hwdev); +void iommu_device_set_confidential(struct iommu_device *iommu, + struct device *hwdev); void iommu_device_unregister(struct iommu_device *iommu); int iommu_device_sysfs_add(struct iommu_device *iommu, struct device *parent,
@@ -1423,6 +1428,11 @@ static inline int iommu_device_register(struct iommu_device *iommu, return -ENODEV; } +static inline void iommu_device_set_confidential(struct iommu_device *iommu, + struct device *hwdev) +{ +} + static inline struct iommu_device *dev_to_iommu_device(struct device *dev) { return NULL;
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index cd1bca7ede9af..feff390727d13 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c@@ -17,6 +17,7 @@ #include <linux/slab.h> #include <linux/errno.h> #include <linux/host1x_context_bus.h> +#include <linux/dma-mapping.h> #include <linux/iommu.h> #include <linux/iommufd.h> #include <linux/idr.h>
@@ -313,6 +314,25 @@ int iommu_device_register(struct iommu_device *iommu, } EXPORT_SYMBOL_GPL(iommu_device_register); +/** + * iommu_device_set_confidential - Mark an IOMMU instance as confidential + * @iommu: the IOMMU instance + * @hwdev: the struct device of @iommu, whose own DMA reaches private memory + * + * Declare that @iommu runs inside a confidential VM + * + * Call this before @iommu makes any DMA allocation of its own, and not merely + * before iommu_device_register(). Queues and tables allocated any earlier land + * in shared memory that the hypervisor can read. + */ +void iommu_device_set_confidential(struct iommu_device *iommu, + struct device *hwdev) +{ + iommu->confidential = true; + dma_set_cc_private(hwdev, true); +} +EXPORT_SYMBOL_GPL(iommu_device_set_confidential); + void iommu_device_unregister(struct iommu_device *iommu) { for (int i = 0; i < ARRAY_SIZE(iommu_buses); i++)
--
2.43.0