Re: [PATCH v2 2/2] iommu/hyperv: Keep a new domain's page tables if it cannot be deleted

From: Yu Zhang

Date: Mon Nov 16 2026 - 11:15:09 EST


On Thu, Nov 12, 2026 at 02:57:00PM -0500, Yuho Choi wrote:
> When hv_iommu_domain_alloc_paging() fails to configure a new device
> domain, hv_create_configure_device_domain() deletes the domain again,
> and the caller then frees the page tables with pt_iommu_deinit(). If
> the delete fails as well, the hypervisor still has the domain, which
> may already point at the page tables, and they are freed anyway.
>
> Create and configure the domain in hv_iommu_domain_alloc_paging()
> itself, and leak the page tables and the domain when the delete fails,
> as hv_iommu_paging_domain_free() does.
>

My understanding is that, for the newly created domain, current Hyper-V
implementation does not adopt the supplied stage-1 page table root if
HVCALL_CONFIGURE_DEVICE_DOMAIN fails. Therefore, a failed configuration
does not leave these page tables referenced. It is different than the
hv_iommu_paging_domain_free() case.

But I'm OK with keeping this as defensive error handling. Could you update
the commit message(the comment above hv_delete_device_domain() as well) to
distinguish that motivation from the behavior of the current implementation?

B.R.
Yu

> Fixes: 2690d4156b51 ("iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest")
> Reported-by: Jacob Pan <jacob.pan@xxxxxxxxxxxxxxxxxxx>
> Closes: https://lore.kernel.org/all/20261105141427.00005946@xxxxxxxxxxxxxxxxxxx/
> Signed-off-by: Yuho Choi <oss.patchbox@xxxxxxxxx>
> ---
> drivers/iommu/hyperv/hv-iommu-guest.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/hyperv/hv-iommu-guest.c b/drivers/iommu/hyperv/hv-iommu-guest.c
> index aa1db9db1e97..ef486ffa0be4 100644
> --- a/drivers/iommu/hyperv/hv-iommu-guest.c
> +++ b/drivers/iommu/hyperv/hv-iommu-guest.c
> @@ -540,10 +540,18 @@ static struct iommu_domain *hv_iommu_domain_alloc_paging(struct device *dev)
> settings.page_table_root = pt_info.gcr3_pt;
> settings.flags.first_stage_paging_mode = pt_info.levels == 5;
>
> - ret = hv_create_configure_device_domain(hv_domain, &settings);
> + ret = hv_create_device_domain(hv_domain);
> if (ret)
> goto err_pt_deinit;
>
> + ret = hv_configure_device_domain(hv_domain, &settings);
> + if (ret) {
> + /* See hv_iommu_paging_domain_free() */
> + if (hv_delete_device_domain(hv_domain))
> + return ERR_PTR(ret);
> + goto err_pt_deinit;
> + }
> +
> return &hv_domain->domain;
>
> err_pt_deinit:
> --
> 2.43.0
>