[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0c34e66f-7766-4b4f-a04d-77dbc330f1fe@linux.microsoft.com>
Date: Wed, 10 Dec 2025 09:15:18 -0800
From: Easwar Hariharan <easwar.hariharan@...ux.microsoft.com>
To: Yu Zhang <zhangyu1@...ux.microsoft.com>
Cc: linux-kernel@...r.kernel.org, linux-hyperv@...r.kernel.org,
iommu@...ts.linux.dev, linux-pci@...r.kernel.org,
easwar.hariharan@...ux.microsoft.com, kys@...rosoft.com,
haiyangz@...rosoft.com, wei.liu@...nel.org, decui@...rosoft.com,
lpieralisi@...nel.org, kwilczynski@...nel.org, mani@...nel.org,
robh@...nel.org, bhelgaas@...gle.com, arnd@...db.de, joro@...tes.org,
will@...nel.org, robin.murphy@....com, jacob.pan@...ux.microsoft.com,
nunodasneves@...ux.microsoft.com, mrathor@...ux.microsoft.com,
mhklinux@...look.com, peterz@...radead.org, linux-arch@...r.kernel.org
Subject: Re: [RFC v1 5/5] iommu/hyperv: Add para-virtualized IOMMU support for
Hyper-V guest
On 12/8/2025 9:11 PM, Yu Zhang wrote:
> Add a para-virtualized IOMMU driver for Linux guests running on Hyper-V.
> This driver implements stage-1 IO translation within the guest OS.
> It integrates with the Linux IOMMU core, utilizing Hyper-V hypercalls
> for:
> - Capability discovery
> - Domain allocation, configuration, and deallocation
> - Device attachment and detachment
> - IOTLB invalidation
>
> The driver constructs x86-compatible stage-1 IO page tables in the
> guest memory using consolidated IO page table helpers. This allows
> the guest to manage stage-1 translations independently of vendor-
> specific drivers (like Intel VT-d or AMD IOMMU).
>
> Hyper-v consumes this stage-1 IO page table, when a device domain is
> created and configured, and nests it with the host's stage-2 IO page
> tables, therefore elemenating the VM exits for guest IOMMU mapping
> operations.
>
> For guest IOMMU unmapping operations, VM exits to perform the IOTLB
> flush(and possibly the device TLB flush) is still unavoidable. For
> now, HVCALL_FLUSH_DEVICE_DOMAIN is used to implement a domain-selective
> IOTLB flush. New hypercalls for finer-grained hypercall will be provided
> in future patches.
>
> Co-developed-by: Wei Liu <wei.liu@...nel.org>
> Signed-off-by: Wei Liu <wei.liu@...nel.org>
> Co-developed-by: Jacob Pan <jacob.pan@...ux.microsoft.com>
> Signed-off-by: Jacob Pan <jacob.pan@...ux.microsoft.com>
> Co-developed-by: Easwar Hariharan <easwar.hariharan@...ux.microsoft.com>
> Signed-off-by: Easwar Hariharan <easwar.hariharan@...ux.microsoft.com>
> Signed-off-by: Yu Zhang <zhangyu1@...ux.microsoft.com>
> ---
> drivers/iommu/hyperv/Kconfig | 14 +
> drivers/iommu/hyperv/Makefile | 1 +
> drivers/iommu/hyperv/iommu.c | 608 ++++++++++++++++++++++++++++++++++
> drivers/iommu/hyperv/iommu.h | 53 +++
> 4 files changed, 676 insertions(+)
> create mode 100644 drivers/iommu/hyperv/iommu.c
> create mode 100644 drivers/iommu/hyperv/iommu.h
>
<snip>
> +
> +static int __init hv_iommu_init(void)
> +{
> + int ret = 0;
> + struct hv_iommu_dev *hv_iommu = NULL;
> + struct hv_output_get_iommu_capabilities hv_iommu_cap = {0};
> +
> + if (no_iommu || iommu_detected)
> + return -ENODEV;
> +
> + if (!hv_is_hyperv_initialized())
> + return -ENODEV;
> +
> + if (hv_iommu_detect(&hv_iommu_cap) ||
> + !hv_iommu_present(hv_iommu_cap.iommu_cap) ||
> + !hv_iommu_s1_domain_supported(hv_iommu_cap.iommu_cap))
> + return -ENODEV;
> +
> + iommu_detected = 1;
> + pci_request_acs();
> +
> + hv_iommu = kzalloc(sizeof(*hv_iommu), GFP_KERNEL);
> + if (!hv_iommu)
> + return -ENOMEM;
> +
> + hv_init_iommu_device(hv_iommu, &hv_iommu_cap);
> +
> + ret = hv_initialize_static_domains();
> + if (ret) {
> + pr_err("hv_initialize_static_domains failed: %d\n", ret);
> + goto err_sysfs_remove;
This should be goto err_free since we haven't done the sysfs_add yet
> + }
> +
> + ret = iommu_device_sysfs_add(&hv_iommu->iommu, NULL, NULL, "%s", "hv-iommu");
> + if (ret) {
> + pr_err("iommu_device_sysfs_add failed: %d\n", ret);
> + goto err_free;
And this should be probably a goto delete_static_domains that cleans up the allocated static
domains...
> + }
> +
> +
> + ret = iommu_device_register(&hv_iommu->iommu, &hv_iommu_ops, NULL);
> + if (ret) {
> + pr_err("iommu_device_register failed: %d\n", ret);
> + goto err_sysfs_remove;
> + }
> +
> + register_syscore_ops(&hv_iommu_syscore_ops);
> +
> + pr_info("Microsoft Hypervisor IOMMU initialized\n");
> + return 0;
> +
> +err_sysfs_remove:
> + iommu_device_sysfs_remove(&hv_iommu->iommu);
> +err_free:
> + kfree(hv_iommu);
> + return ret;
> +}
> +
> +device_initcall(hv_iommu_init);
<snip>
Powered by blists - more mailing lists