Re: [PATCH v2 22/31] iommu/vt-d: Export a helper to do function for each dmar_drhd_unit

From: Ackerley Tng

Date: Mon Jul 06 2026 - 14:35:51 EST


Xu Yilun <yilun.xu@xxxxxxxxxxxxxxx> writes:

> Enable the tdx-host module to get VTBAR address for every IOMMU device.
> The VTBAR address is for TDX Module to identify the IOMMU device and
> setup its trusted configuraion.
>

I think this commit message doesn't match the commit subject or the
change, unless I'm misunderstanding something

> Suggested-by: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
> Signed-off-by: Xu Yilun <yilun.xu@xxxxxxxxxxxxxxx>
> ---
> include/linux/dmar.h | 2 ++
> drivers/iommu/intel/dmar.c | 16 ++++++++++++++++
> 2 files changed, 18 insertions(+)
>
> diff --git a/include/linux/dmar.h b/include/linux/dmar.h
> index 692b2b445761..cd8d9f440975 100644
> --- a/include/linux/dmar.h
> +++ b/include/linux/dmar.h
> @@ -86,6 +86,8 @@ extern struct list_head dmar_drhd_units;
> dmar_rcu_check()) \
> if (i=drhd->iommu, 0) {} else
>
> +int do_for_each_drhd_unit(int (*fn)(struct dmar_drhd_unit *));
> +
> static inline bool dmar_rcu_check(void)
> {
> return rwsem_is_locked(&dmar_global_lock) ||
> diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
> index 4f9571eee1d4..eea9ba691f99 100644
> --- a/drivers/iommu/intel/dmar.c
> +++ b/drivers/iommu/intel/dmar.c
> @@ -2452,3 +2452,19 @@ bool dmar_platform_optin(void)
> return ret;
> }
> EXPORT_SYMBOL_GPL(dmar_platform_optin);
> +
> +int do_for_each_drhd_unit(int (*fn)(struct dmar_drhd_unit *))
> +{
> + struct dmar_drhd_unit *drhd;
> + int ret;
> +
> + guard(rwsem_read)(&dmar_global_lock);
> +
> + for_each_drhd_unit(drhd) {
> + ret = fn(drhd);
> + if (ret)
> + return ret;
> + }
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(do_for_each_drhd_unit);
> --
> 2.25.1