Re: [PATCH v3 4/7] iommu: Let a driver mark an IOMMU as confidential
From: Jason Gunthorpe
Date: Wed Nov 25 2026 - 13:08:12 EST
> 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().
>
> Signed-off-by: Nicolin Chen <nicolinc@xxxxxxxxxx>
> ---
> include/linux/iommu.h | 10 ++++++++++
> drivers/iommu/iommu.c | 20 ++++++++++++++++++++
> 2 files changed, 30 insertions(+)
>
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index b486b8bbd1fcdc..ba98a0bb800a58 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)
> +{
I might suggest "cc_private" here to keep with the naming theme.
> + 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++)
> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index ef5043752a3651..e8fb5ee59883e6 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -824,6 +824,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;
> @@ -833,6 +835,7 @@ struct iommu_device {
> struct iommu_group *singleton_group;
> u32 max_pasids;
> bool ready;
> + bool confidential;
> };
And Linus isn't a fan of lists of bools..
But otherwise seems OK
Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
--
Jason