[PATCH v3 2/2] iommu/hyperv: Keep a new domain's page tables if it cannot be deleted
From: Yuho Choi
Date: Mon Nov 23 2026 - 01:04:38 EST
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(). The
page tables are freed even if the delete fails and the hypervisor
still has the domain.
The current Hyper-V implementation does not adopt the page table root
when HVCALL_CONFIGURE_DEVICE_DOMAIN fails, so the page tables are not
referenced in this case today. This change is defensive: it avoids
relying on that while the hypervisor still has the domain.
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.
Reported-by: Jacob Pan <jacob.pan@xxxxxxxxxxxxxxxxxxx>
Closes: https://lore.kernel.org/all/20261105141427.00005946@xxxxxxxxxxxxxxxxxxx/
Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
Reviewed-by: Easwar Hariharan <easwar.hariharan@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Yuho Choi <oss.patchbox@xxxxxxxxx>
---
drivers/iommu/hyperv/hv-iommu-guest.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/hyperv/hv-iommu-guest.c b/drivers/iommu/hyperv/hv-iommu-guest.c
index aa1db9db1e97..0110a1529a23 100644
--- a/drivers/iommu/hyperv/hv-iommu-guest.c
+++ b/drivers/iommu/hyperv/hv-iommu-guest.c
@@ -540,10 +540,23 @@ 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) {
+ /*
+ * The current hypervisor does not adopt the page table root
+ * when the configure call fails. Still, keep the page tables
+ * while it has the domain, as hv_iommu_paging_domain_free()
+ * does.
+ */
+ if (hv_delete_device_domain(hv_domain))
+ return ERR_PTR(ret);
+ goto err_pt_deinit;
+ }
+
return &hv_domain->domain;
err_pt_deinit:
--
2.56.1