Hyper-V: Add para-virtualized IOMMU support for Linux guests
Subsystems (9)
v5 cover Hyper-V: Add para-virtualized IOMMU support for Linux guests
This patch series introduces a para-virtualized IOMMU driver for Linux guests running on Microsoft Hyper-V. The driver enables two primary use cases:
1) In-kernel DMA protection for devices assigned to the guest.
2) Device assignment to guest user space (e.g., via VFIO).
The driver implements the following core functionality:
* Hypercall-based Enumeration
Unlike traditional ACPI-based discovery (e.g., DMAR/IVRS), this driver enumerates the Hyper-V IOMMU capabilities directly via hypercalls. This approach allows the guest to discover IOMMU presence and features without requiring specific virtual firmware extensions or modifications.
* Domain Management
The driver manages IOMMU domains through a new set of Hyper-V hypercall interfaces, handling domain allocation and attachment for endpoint devices.
* Nested Translation Support
This implementation leverages guest-managed stage-1 I/O page tables nested with host stage-2 translations. It is built upon the consolidated IOMMU page table framework (IOMMU_PT). This design eliminates the need for emulating map operations. Both Intel VT-d and AMD IOMMU platforms are supported.
* IOTLB Invalidation
IOTLB invalidation requests are marshaled and issued to the hypervisor through the same hypercall mechanism. Both domain- selective and page-selective flushes are supported.
Implementation Notes:
* Platform Support
The current implementation targets x86 platforms with Intel VT-d and AMD IOMMU hardware.
* MSI Region Handling
The standard x86 MSI interrupt range
(0xfee00000 - 0xfeefffff) is reserved from normal IOVA mappings. Future updates may allow this configuration to be queried via hypercalls if new hardware platforms are to be supported.
* Reserved Regions (RMRR)
There is currently no requirement to support assigned devices with ACPI RMRR limitations. Consequently, this patch series does not specify or query reserved memory regions.
* Guest Hibernation
Guest hibernation and resume are not supported by this initial implementation. The current pvIOMMU interface does not define how Hyper-V device-domain objects and device attachments are restored.
Testing:
Validated with the following configurations:
- NVMe devices assigned to the guest on AMD platforms, tested with fio.
- Intel DSA devices assigned to the guest, tested with dmatest.
- dma_map_benchmark for DMA mapping performance evaluation.
Changelog:
v4[1] -> v5:
- Added Michael Kelley's Reviewed-by tags for patch 1/2/3/4.
- hv: logical device ID registry:
- Used four-digit hexadecimal values to print PCI domain numbers.
- Included the PCI domain number in the unregister failure warning.
- iommu/hyperv: para-virtualized IOMMU:
- Removed the unused per-device endpoint structure, allocation, private pointer, and release_device() callback.
- Clarified the logical device ID lookup failure message.
- Read the ATS capability from the IOMMU associated with the domain instead of the global IOMMU pointer.
- iommu/hyperv: page-selective IOTLB flush:
- Unified normal and full-range descriptor construction around the aligned range start.
- Used max() to express the minimum Hyper-V page granularity.
- Reported Hyper-V status values in warnings when the flush fails.
v3[2] -> v4:
- Added Jacob Pan's Reviewed-by tag for patch 1/4/5.
- hyperv: hypercall interfaces:
- Added the authoritative Hyper-V type names to imported definitions.
- Added HV_STATUS_DEVICE_ALREADY_IN_DOMAIN and mapped it to -EEXIST.
- hv: logical device ID registry:
- Made the registry independent of CONFIG_HYPERV_PVIOMMU.
- Renamed the APIs to hv_pci_xxx_dev_id(),
- Reworked initialization and error cleanup to propagate failures.
- Return -EEXIST with a warning for duplicate registration.
- iommu/x86: architectural MSI reserved region:
- Replaced the exported range constants with
iommu_alloc_resv_x86_msi_region().
- iommu/hyperv: para-virtualized IOMMU:
- Accepted HV_STATUS_DEVICE_ALREADY_IN_DOMAIN as a successful attach, and removed the blocking-domain-specific duplicate check.
- Removed the redundant ATS disable from release_device(); ATS is disabled when attaching the release domain.
- iommu/hyperv: page-selective IOTLB flush:
- Removed the redundant include of linux/hyperv.h.
- Documented that the list flush also invalidates non-leaf page-walk caches before detached page-table pages are freed.
v2[3] -> v3:
- Added a separate patch defining the common x86 architectural MSI reserved range and converted the Intel, AMD, and Hyper-V IOMMU drivers to use it.
- hyperv: hypercall interfaces:
- Used BIT_ULL() for 64-bit capability flags.
- Matched the create-device-domain input layout to the 32-byte Hyper-V ABI.
- Corrected the page-selective flush range layout to 6/6/52 bits.
- hv: logical device ID registry:
- Replaced the linear list with an rhashtable for the sparse PCI domain number mapping.
- Used RCU-protected lookup and deferred freeing on removal.
- Simplified the registration and cleanup paths.
- iommu/hyperv: para-virtualized IOMMU:
- Renamed the guest driver source to hv-iommu-guest.c.
- Enabled ATS only after a device-domain attachment succeeds, and disabled ATS before attaching the blocking domain.
- Removed the obsolete deferred-flush capability, unused geometry, and redundant device-private-data clearing.
- Made the Hyper-V domain settings explicit at each caller instead of deriving them from the Linux domain type.
- Added transactional create/configure domain handling with rollback.
- Required only the base page size and masked the domain page-size bitmap with the Hyper-V-supported bitmap.
- Silenced detection for unsupported hosts while retaining errors for actual hypercall and capability failures.
- Clarified Kconfig support for assigned PCI devices and documented the lack of guest hibernation/resume support.
- iommu/hyperv: page-selective IOTLB flush:
- Removed the inclusive-end overflow and kept the range calculation in byte addresses until the final page conversion.
- Cleared both the fixed hypercall header and the range entry.
- Warned on selective-flush failure before falling back to a full-domain flush.
v1[4] -> v2:
- Dropped the "move to subdirectory" patch; the directory now exists upstream.
- hv: logical device ID registry:
- Moved the registry to hv_common.c so it can be shared, and derived the prefix via a shared helper instead of caching it in pci-hyperv's private struct.
- Moved the lookup out of the irq-disabled region (PREEMPT_RT).
- iommu/hyperv: para-virtualized IOMMU:
- Removed the unused detach_dev op.
- Rejected a hypervisor not advertising x86 page sizes instead of masking and warning.
- Statically initialized the identity and blocking domains.
- Gave the blocking domain its own attach op, which returns the hypercall status and WARNs on failure.
- iommu/hyperv: page-selective IOTLB flush:
- Used a single descriptor covering a slightly larger power-of-two range, instead of splitting the range into multiple descriptors.
- Fixed the inclusive-end corner case in the flush range calculation.
RFC v1[5] -> v1[4]:
- Scoped platform support to x86 only (Intel VT-d and AMD IOMMU); initialization now uses x86_init.iommu.iommu_init
- Added page-selective IOTLB flush support
- Disable device ATS in hv_iommu_release_device()
- Addressed review comments from Michael Kelley:
- Reversed dependency: pvIOMMU exports registration API for pci-hyperv to call, instead of pci-hyperv exporting hv_build_logical_dev_id()
- Dropped separate output page allocation patch; hypercall input and output now share the same per-CPU page
- Cleaned up Kconfig (removed PCI_HYPERV dependency, unnecessary selects)
- Removed dev_list, per-domain spinlock, and syscore_ops
- Removed forward declarations by reordering functions
- Fixed typos, cleaned up Kconfig selects, improved pr_info messages, etc.
[1] v4:
https://lore.kernel.org/linux-hyperv/[email protected]/
[2] v3:
https://lore.kernel.org/linux-hyperv/[email protected]/
[3] v2:
https://lore.kernel.org/linux-hyperv/[email protected]/
[4] v1:
https://lore.kernel.org/linux-hyperv/[email protected]/
[5] RFC v1:
https://lore.kernel.org/linux-hyperv/[email protected]/
Wei Liu (1):
hyperv: Introduce new hypercall interfaces used by Hyper-V guest IOMMU
Yu Zhang (4):
Drivers: hv: Add logical device ID registry for vPCI devices iommu/x86: Add architectural MSI reserved region helper iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest iommu/hyperv: Add page-selective IOTLB flush support
arch/x86/hyperv/hv_init.c | 4 + arch/x86/include/asm/iommu.h | 14 + arch/x86/include/asm/mshyperv.h | 4 + drivers/hv/hv_common.c | 115 +++++ drivers/iommu/Kconfig | 1 + drivers/iommu/amd/iommu.c | 6 +- drivers/iommu/hyperv/Kconfig | 16 + drivers/iommu/hyperv/Makefile | 1 + drivers/iommu/hyperv/hv-iommu-guest.c | 679 ++++++++++++++++++++++++++ drivers/iommu/hyperv/iommu.h | 44 ++ drivers/iommu/intel/iommu.c | 6 +- drivers/pci/controller/pci-hyperv.c | 21 +- include/asm-generic/mshyperv.h | 4 + include/hyperv/hvgdk_mini.h | 10 + include/hyperv/hvhdk_mini.h | 155 ++++++ include/linux/hyperv.h | 8 + 16 files changed, 1073 insertions(+), 15 deletions(-) create mode 100644 drivers/iommu/hyperv/Kconfig create mode 100644 drivers/iommu/hyperv/hv-iommu-guest.c create mode 100644 drivers/iommu/hyperv/iommu.h
Signature · 1 line
2.52.0
PATCH v5 1/5 hyperv: Introduce new hypercall interfaces used by Hyper-V guest IOMMU
From: Wei Liu <[email protected]>
Hyper-V guest IOMMU is a para-virtualized IOMMU based on hypercalls. Introduce the hypercalls used by the child partition to interact with this facility.
These hypercalls fall into below categories:
- Detection and capability: HVCALL_GET_IOMMU_CAPABILITIES is used to detect the existence and capabilities of the guest IOMMU.
- Device management: HVCALL_GET_LOGICAL_DEVICE_PROPERTY is used to check whether an endpoint device is managed by the guest IOMMU.
- Domain management: A set of hypercalls is provided to handle the creation, configuration, and deletion of guest domains, as well as the attachment/detachment of endpoint devices to/from those domains.
- IOTLB flushing: HVCALL_FLUSH_DEVICE_DOMAIN is used to ask Hyper-V for a domain-selective IOTLB flush (which in its handler may flush the device TLB as well).
--- drivers/hv/hv_common.c | 1 + include/hyperv/hvgdk_mini.h | 9 +++ include/hyperv/hvhdk_mini.h | 137 ++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+)
drivers/hv/hv_common.c +1 -0
@@ -808,6 +808,7 @@ static const struct hv_status_info hv_status_infos[] = {_STATUS_INFO (HV_STATUS_PROCESSOR_FEATURE_NOT_SUPPORTED , -EOPNOTSUPP ),_STATUS_INFO (HV_STATUS_INVALID_LP_INDEX , -EINVAL ),_STATUS_INFO (HV_STATUS_INVALID_REGISTER_VALUE , -EINVAL ), +_STATUS_INFO (HV_STATUS_DEVICE_ALREADY_IN_DOMAIN , -EEXIST ),_STATUS_INFO (HV_STATUS_OPERATION_FAILED , -EIO ),_STATUS_INFO (HV_STATUS_TIME_OUT , -EIO ), _STATUS_INFO(HV_STATUS_CALL_PENDING, -EIO),
include/hyperv/hvgdk_mini.h +9 -0
@@ -37,6 +37,7 @@ struct hv_u128 {#define HV_STATUS_PROCESSOR_FEATURE_NOT_SUPPORTED 0x20#define HV_STATUS_INVALID_LP_INDEX 0x41#define HV_STATUS_INVALID_REGISTER_VALUE 0x50 +#define HV_STATUS_DEVICE_ALREADY_IN_DOMAIN 0x66#define HV_STATUS_OPERATION_FAILED 0x71#define HV_STATUS_INSUFFICIENT_ROOT_MEMORY 0x73#define HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY 0x75
@@ -486,10 +487,16 @@ union hv_vp_assist_msr_contents { /* HV_REGISTER_VP_ASSIST_PAGE */#define HVCALL_GET_VP_INDEX_FROM_APIC_ID 0x009a#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0 +#define HVCALL_CREATE_DEVICE_DOMAIN 0x00b1 +#define HVCALL_ATTACH_DEVICE_DOMAIN 0x00b2#define HVCALL_SIGNAL_EVENT_DIRECT 0x00c0#define HVCALL_POST_MESSAGE_DIRECT 0x00c1#define HVCALL_DISPATCH_VP 0x00c2 +#define HVCALL_DETACH_DEVICE_DOMAIN 0x00c4 +#define HVCALL_DELETE_DEVICE_DOMAIN 0x00c5#define HVCALL_GET_GPA_PAGES_ACCESS_STATES 0x00c9 +#define HVCALL_CONFIGURE_DEVICE_DOMAIN 0x00ce +#define HVCALL_FLUSH_DEVICE_DOMAIN 0x00d0#define HVCALL_ACQUIRE_SPARSE_SPA_PAGE_HOST_ACCESS 0x00d7#define HVCALL_RELEASE_SPARSE_SPA_PAGE_HOST_ACCESS 0x00d8#define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db
@@ -502,6 +509,8 @@ union hv_vp_assist_msr_contents { /* HV_REGISTER_VP_ASSIST_PAGE */#define HVCALL_MMIO_READ 0x0106#define HVCALL_MMIO_WRITE 0x0107#define HVCALL_DISABLE_HYP_EX 0x010f +#define HVCALL_GET_IOMMU_CAPABILITIES 0x0125 +#define HVCALL_GET_LOGICAL_DEVICE_PROPERTY 0x0127#define HVCALL_MAP_STATS_PAGE2 0x0131/* HV_HYPERCALL_INPUT */
include/hyperv/hvhdk_mini.h +137 -0
141 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH v5 1/5] hyperv: Introduce new hypercall interfaces used by Hyper-V guest IOMMU
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 21 lines
From: Wei Liu <[email protected]>
Hyper-V guest IOMMU is a para-virtualized IOMMU based on hypercalls. Introduce the hypercalls used by the child partition to interact with this facility.
These hypercalls fall into below categories:
- Detection and capability:HVCALL_GET_IOMMU_CAPABILITIESis used to detect the existence and capabilities of the guest IOMMU.- Device management:
HVCALL_GET_LOGICAL_DEVICE_PROPERTYis used to check whether an endpoint device is managed by the guest IOMMU.- Domain management: A set of hypercalls is provided to handle the creation, configuration, and deletion of guest domains, as well as the attachment/detachment of endpoint devices to/from those domains.
- IOTLB flushing:
HVCALL_FLUSH_DEVICE_DOMAINis used to ask Hyper-V for a domain-selective IOTLB flush (which in its handler may flush the device TLB as well).
Quoted 5 lines
Signed-off-by Wei Liu <[email protected]>Co-developed-by Easwar Hariharan <[email protected]>Signed-off-by Easwar Hariharan <[email protected]>Co-developed-by Yu Zhang <[email protected]>Signed-off-by Yu Zhang <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v5 2/5 Drivers: hv: Add logical device ID registry for vPCI devices
In reply to Yu ZhangHyper-V identifies each PCI pass-thru device by a logical device ID in its hypercall interface. This ID consists of a per-bus prefix, derived from the VMBus device instance GUID, combined with the PCI function number of the endpoint device.
Add a registry in hv_common.c that maps a PCI domain number to its logical device ID prefix. The vPCI bus driver (pci-hyperv) registers the prefix when a bus is probed and unregisters it when the bus is removed. Consumers such as the para-virtualized IOMMU driver look up the prefix by PCI domain number and combine it with the function number to form the complete logical device ID for hypercalls.
Use rhashtable for the sparse exact-match mapping. Lookups copy the prefix while holding the RCU read lock, and removal defers freeing the entry until existing readers have completed.
The prefix construction is shared via hv_build_logical_dev_id_prefix() so that pci-hyperv's interrupt retargeting path and the registry use exactly the same byte layout. It is derived on demand from the constant hv_device instance GUID rather than cached in struct hv_pcibus_device, which is private to the pci-hyperv module; this keeps the interface narrow and avoids depending on pci-hyperv internals.
--- drivers/hv/hv_common.c | 114 ++++++++++++++++++++++++++++ drivers/pci/controller/pci-hyperv.c | 21 +++-- include/asm-generic/mshyperv.h | 4 + include/linux/hyperv.h | 8 ++ 4 files changed, 142 insertions(+), 5 deletions(-)
drivers/hv/hv_common.c +114 -0
@@ -21,6 +21,7 @@#include <linux/panic_notifier.h> #include <linux/ptrace.h> #include <linux/random.h> +#include <linux/rhashtable.h> #include <linux/efi.h> #include <linux/kdebug.h> #include <linux/kmsg_dump.h>
@@ -78,6 +79,22 @@ static struct ctl_table_header *hv_ctl_table_hdr;u8 *__percpu *hv_synic_eventring_tail;EXPORT_SYMBOL_GPL (hv_synic_eventring_tail); +struct hv_pci_busdata { +int pci_domain_nr; +u32 logical_dev_id_prefix; +struct rhash_head node; +struct rcu_head rcu; +}; + +static struct rhashtable hv_pci_bus_ht; +static bool hv_pci_bus_ht_initialized; + +static const struct rhashtable_params hv_pci_bus_ht_params = { + .key_len = sizeof_field(struct hv_pci_busdata, pci_domain_nr), + .key_offset = offsetof(struct hv_pci_busdata , pci_domain_nr), + .head_offset = offsetof(struct hv_pci_busdata , node), +}; +/* * Hyper-V specific initialization and shutdown code that is * common across all architectures. Called from architecture
@@ -86,6 +103,11 @@ EXPORT_SYMBOL_GPL(hv_synic_eventring_tail);void __init hv_common_free (void ) { +if (hv_pci_bus_ht_initialized) { +rhashtable_destroy (&hv_pci_bus_ht); + hv_pci_bus_ht_initialized = false; + } +unregister_sysctl_table (hv_ctl_table_hdr); hv_ctl_table_hdr =NULL ;
@@ -315,6 +337,7 @@ u8 __init get_vtl(void)int __init hv_common_init (void ) {int i; +int ret;union hv_hypervisor_version_info version;/* Get information about the Microsoft Hypervisor version */
@@ -394,6 +417,13 @@ int __init hv_common_init(void)for (i =0 ; i < nr_cpu_ids; i++) hv_vp_index[i] =VP_INVAL ; + ret =rhashtable_init (&hv_pci_bus_ht, &hv_pci_bus_ht_params); +if (ret) { +hv_common_free (); +return ret; + } + hv_pci_bus_ht_initialized = true; +return 0 ; }
@@ -862,3 +892,87 @@ const char *hv_result_to_string(u64 status)return "Unknown" ; }EXPORT_SYMBOL_GPL (hv_result_to_string); + +/* +* Logical device ID registry for Hyper-V PCI buses. The pci-hyperv +* driver registers each bus's logical device ID prefix before scanning +* its devices. Consumers look up the prefix by PCI domain number when +* building logical device IDs for Hyper-V interfaces. +*/ +int hv_pci_register_dev_id (int pci_domain_nr,u32 logical_dev_id_prefix) +{ +struct hv_pci_busdata *bus, *new; +int ret; + + new =kzalloc_obj (*new,GFP_KERNEL ); +if (!new) +return -ENOMEM ; + + new->pci_domain_nr = pci_domain_nr; + new->logical_dev_id_prefix = logical_dev_id_prefix; + + bus =rhashtable_lookup_get_insert_fast (&hv_pci_bus_ht, &new->node, + hv_pci_bus_ht_params); +if (IS_ERR (bus)) { + ret =PTR_ERR (bus); + goto free_new; + } + +if (WARN_ONCE (bus !=NULL , +"Hyper-V PCI domain %04x is already registered\n" , + pci_domain_nr)) { + ret = -EEXIST ; + goto free_new; + } + +return 0 ; + +free_new: +kfree (new); +return ret; +} +EXPORT_SYMBOL_FOR_MODULES (hv_pci_register_dev_id,"pci-hyperv" ); + +void hv_pci_unregister_dev_id (int pci_domain_nr) +{ +struct hv_pci_busdata *bus; +int ret = -ENOENT ; + +rcu_read_lock (); + bus =rhashtable_lookup (&hv_pci_bus_ht, &pci_domain_nr, + hv_pci_bus_ht_params); +if (bus) + ret =rhashtable_remove_fast (&hv_pci_bus_ht, &bus->node, + hv_pci_bus_ht_params); +rcu_read_unlock (); + +if (WARN_ONCE (ret, +"Failed to unregister Hyper-V PCI domain %04x\n" , + pci_domain_nr)) +return ; + +kfree_rcu (bus, rcu); +} +EXPORT_SYMBOL_FOR_MODULES (hv_pci_unregister_dev_id,"pci-hyperv" ); + +/* +* Look up the logical device ID prefix registered for @pci_domain_nr. +* Returns 0 on success with *prefix filled in; -ENODEV if no entry is +* registered for that PCI domain. +*/ +int hv_pci_lookup_dev_id (int pci_domain_nr,u32 *prefix) +{ +struct hv_pci_busdata *bus; +int ret = -ENODEV ; + +rcu_read_lock (); + bus =rhashtable_lookup (&hv_pci_bus_ht, &pci_domain_nr, + hv_pci_bus_ht_params); +if (bus) { + *prefix = bus->logical_dev_id_prefix; + ret =0 ; + } +rcu_read_unlock (); + +return ret; +}
drivers/pci/controller/pci-hyperv.c +16 -5
@@ -641,10 +641,7 @@ static void hv_irq_retarget_interrupt(struct irq_data *data) params->int_entry.source =HV_INTERRUPT_SOURCE_MSI ; params->int_entry.msi_entry.address.as_uint32 = int_desc->address &0xffffffff ; params->int_entry.msi_entry.data.as_uint32 = int_desc->data; - params->device_id = (hbus->hdev->dev_instance.b[5 ] <<24 ) | - (hbus->hdev->dev_instance.b[4 ] <<16 ) | - (hbus->hdev->dev_instance.b[7 ] <<8 ) | - (hbus->hdev->dev_instance.b[6 ] &0xf8 ) | + params->device_id =hv_build_logical_dev_id_prefix (hbus->hdev) |PCI_FUNC (pdev->devfn); params->int_target.vector =hv_msi_get_int_vector (data);
@@ -3716,6 +3713,7 @@ static int hv_pci_probe(struct hv_device *hdev,struct hv_pcibus_device *hbus;int ret, dom;u16 dom_req; +u32 prefix;char *name; bridge =devm_pci_alloc_host_bridge (&hdev->device,0 );
@@ -3858,13 +3856,22 @@ static int hv_pci_probe(struct hv_device *hdev, hbus->state = hv_pcibus_probed; - ret =create_root_hv_pci_bus (hbus); +/* Register the bus before scanning any devices on it. */ + prefix =hv_build_logical_dev_id_prefix (hdev); + + ret =hv_pci_register_dev_id (dom, prefix);if (ret) goto free_windows; + ret =create_root_hv_pci_bus (hbus); +if (ret) + goto unregister_pci_bus; +mutex_unlock (&hbus->state_lock);return 0 ; +unregister_pci_bus: +hv_pci_unregister_dev_id (dom); free_windows:hv_pci_free_bridge_windows (hbus); exit_d0:
@@ -3978,6 +3985,8 @@ static void hv_pci_remove(struct hv_device *hdev) hbus =hv_get_drvdata (hdev);if (hbus->state == hv_pcibus_installed) { +int dom = hbus->bridge->domain_nr; +tasklet_disable (&hdev->channel->callback_event); hbus->state = hv_pcibus_removing;tasklet_enable (&hdev->channel->callback_event);
@@ -3995,6 +4004,8 @@ static void hv_pci_remove(struct hv_device *hdev)hv_pci_remove_slots (hbus);pci_remove_root_bus (hbus->bridge->bus);pci_unlock_rescan_remove (); + +hv_pci_unregister_dev_id (dom); }hv_pci_bus_exit (hdev, false);
include/asm-generic/mshyperv.h +4 -0
@@ -73,6 +73,10 @@ extern enum hv_partition_type hv_curr_partition_type;extern void *__percpu *hyperv_pcpu_input_arg;extern void *__percpu *hyperv_pcpu_output_arg; +int hv_pci_register_dev_id (int pci_domain_nr,u32 logical_dev_id_prefix); +void hv_pci_unregister_dev_id (int pci_domain_nr); +int hv_pci_lookup_dev_id (int pci_domain_nr,u32 *prefix); +u64 hv_do_hypercall (u64 control,void *inputaddr,void *outputaddr);u64 hv_do_fast_hypercall8 (u16 control,u64 input8);u64 hv_do_fast_hypercall16 (u16 control,u64 input1,u64 input2);
include/linux/hyperv.h +8 -0
@@ -1299,6 +1299,14 @@ struct hv_device {#define device_to_hv_device (d) container_of_const(d, struct hv_device, device)#define drv_to_hv_drv (d) container_of_const(d, struct hv_driver, driver) +static inline u32 hv_build_logical_dev_id_prefix (struct hv_device *hdev) +{ +return ((u32 )hdev->dev_instance.b[5 ] <<24 ) | + ((u32 )hdev->dev_instance.b[4 ] <<16 ) | + ((u32 )hdev->dev_instance.b[7 ] <<8 ) | + (hdev->dev_instance.b[6 ] &0xf8u ); +} +static inline void hv_set_drvdata (struct hv_device *dev,void *data) {dev_set_drvdata (&dev->device, data);
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH v5 2/5] Drivers: hv: Add logical device ID registry for vPCI devices
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 23 lines
Hyper-V identifies each PCI pass-thru device by a logical device ID in its hypercall interface. This ID consists of a per-bus prefix, derived from the VMBus device instance GUID, combined with the PCI function number of the endpoint device.
Add a registry in
hv_common.cthat maps a PCI domain number to its logical device ID prefix. The vPCI bus driver (pci-hyperv) registers the prefix when a bus is probed and unregisters it when the bus is removed. Consumers such as the para-virtualized IOMMU driver look up the prefix by PCI domain number and combine it with the function number to form the complete logical device ID for hypercalls.Use rhashtable for the sparse exact-match mapping. Lookups copy the prefix while holding the RCU read lock, and removal defers freeing the entry until existing readers have completed.
The prefix construction is shared via
hv_build_logical_dev_id_prefix()so that pci-hyperv's interrupt retargeting path and the registry use exactly the same byte layout. It is derived on demand from the constanthv_deviceinstance GUID rather than cached in structhv_pcibus_device, which is private to the pci-hyperv module; this keeps the interface narrow and avoids depending on pci-hyperv internals.
Quoted 3 lines
Co-developed-by Easwar Hariharan <[email protected]>Signed-off-by Easwar Hariharan <[email protected]>Signed-off-by Yu Zhang <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v5 3/5 iommu/x86: Add architectural MSI reserved region helper
In reply to Yu ZhangIntel and AMD IOMMU drivers both reserve the x86 architectural MSI address window from normal IOVA mappings, but each open-codes the range and its allocation attributes.
Add iommu_alloc_resv_x86_msi_region() to encapsulate those details, and convert the Intel and AMD drivers to use it.
--- arch/x86/include/asm/iommu.h | 14 ++++++++++++++ drivers/iommu/amd/iommu.c | 6 +----- drivers/iommu/intel/iommu.c | 6 +----- 3 files changed, 16 insertions(+), 10 deletions(-)
arch/x86/include/asm/iommu.h +14 -0
@@ -4,6 +4,11 @@#include <linux/acpi.h> +#ifdef CONFIG_IOMMU_API +#include <linux/iommu.h> +#include <linux/sizes.h> +#endif +#include <asm/e820/api.h> extern int force_iommu, no_iommu;
@@ -21,6 +26,15 @@ extern bool x86_swiotlb_enable;/* 10 seconds */ #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000) +#ifdef CONFIG_IOMMU_API +static inline struct iommu_resv_region * +iommu_alloc_resv_x86_msi_region (void ) +{ +return iommu_alloc_resv_region (0xfee00000 ,SZ_1M ,0 , +IOMMU_RESV_MSI ,GFP_KERNEL ); +} +#endif +static inline int __init arch_rmrr_sanity_check (struct acpi_dmar_reserved_memory *rmrr) {
drivers/iommu/amd/iommu.c +1 -5
@@ -50,8 +50,6 @@#define CMD_SET_TYPE (cmd, t) ((cmd)->data[1] |= ((t) << 28))/* Reserved IOVA ranges */ -#define MSI_RANGE_START (0xfee00000) -#define MSI_RANGE_END (0xfeefffff)#define HT_RANGE_START (0xfd00000000ULL)#define HT_RANGE_END (0xffffffffffULL)
@@ -3140,9 +3138,7 @@ static void amd_iommu_get_resv_regions(struct device *dev,list_add_tail (®ion->list, head); } - region =iommu_alloc_resv_region (MSI_RANGE_START , -MSI_RANGE_END -MSI_RANGE_START +1 , -0 ,IOMMU_RESV_MSI ,GFP_KERNEL ); + region =iommu_alloc_resv_x86_msi_region ();if (!region)return ;list_add_tail (®ion->list, head);
drivers/iommu/intel/iommu.c +1 -5
@@ -39,8 +39,6 @@#define IS_ISA_DEVICE (pdev) ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA)#define IS_AZALIA (pdev) ((pdev)->vendor == 0x8086 && (pdev)->device == 0x3a3e) -#define IOAPIC_RANGE_START (0xfee00000) -#define IOAPIC_RANGE_END (0xfeefffff)#define IOVA_START_ADDR (0x1000)#define DEFAULT_DOMAIN_ADDRESS_WIDTH 57
@@ -3459,9 +3457,7 @@ static void intel_iommu_get_resv_regions(struct device *device, }#endif /* CONFIG_INTEL_IOMMU_FLOPPY_WA */ - reg =iommu_alloc_resv_region (IOAPIC_RANGE_START , -IOAPIC_RANGE_END -IOAPIC_RANGE_START +1 , -0 ,IOMMU_RESV_MSI ,GFP_KERNEL ); + reg =iommu_alloc_resv_x86_msi_region ();if (!reg)return ;list_add_tail (®->list, head);
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH v5 3/5] iommu/x86: Add architectural MSI reserved region helper
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
Intel and AMD IOMMU drivers both reserve the x86 architectural MSI address window from normal IOVA mappings, but each open-codes the range and its allocation attributes.
Add
iommu_alloc_resv_x86_msi_region()to encapsulate those details, and convert the Intel and AMD drivers to use it.Signed-off-by Yu Zhang <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v5 3/5] iommu/x86: Add architectural MSI reserved region helper
In reply to Yu ZhangQuoted 5 lines
[ ... 16 lines skipped ... ]
index3be2451e7bc857..6404f4fbeae817100644
arch/x86/include/asm/iommu.h line 12
Quoted 9 lines
arch/x86/include/asm/iommu.h +5
-0@@ -4,6 +4,11 @@#include <linux/acpi.h> +#ifdef CONFIG_IOMMU_API +#include <linux/iommu.h> +#include <linux/sizes.h> +#endif +#include <asm/e820/api.h>
IDK if this header is the best place, nor do I have a better option, but the overall idea is sound
arch/x86/include/asm/iommu.h extern bool x86_swiotlb_enable; · line 34
Quoted 12 lines
arch/x86/include/asm/iommu.h +6
-0extern int force_iommu, no_iommu;@@ -21,6 +26,15 @@ extern bool x86_swiotlb_enable;/* 10 seconds */ #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000) +#ifdef CONFIG_IOMMU_API +static inline struct iommu_resv_region * +iommu_alloc_resv_x86_msi_region (void ) +{ +return iommu_alloc_resv_region (0xfee00000 ,SZ_1M ,0 , +IOMMU_RESV_MSI ,GFP_KERNEL );
Though I think it would be better to include the list add tail here as well.
Signature · 1 line
Jason
PATCH v5 4/5 iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest
In reply to Yu ZhangAdd 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 eliminating the VM exits for guest IOMMU mapping operations. For unmapping operations, VM exits to perform the IOTLB flush are still unavoidable.
Guest hibernation and resume are not supported by this initial implementation. The guest-owned stage-1 page tables reside in guest memory and are preserved in the hibernation image. However, the image does not by itself preserve the Hyper-V device-domain objects or their device attachments, and the current pvIOMMU interface does not define whether or how Hyper-V restores that state.
To identify a device in its hypercall interface, the driver looks up the logical device ID prefix registered for the device's PCI domain (see the logical device ID registry in hv_common.c) and combines it with the PCI function number of the endpoint device.
--- arch/x86/hyperv/hv_init.c | 4 + arch/x86/include/asm/mshyperv.h | 4 + drivers/iommu/Kconfig | 1 + drivers/iommu/hyperv/Kconfig | 16 + drivers/iommu/hyperv/Makefile | 1 + drivers/iommu/hyperv/hv-iommu-guest.c | 607 ++++++++++++++++++++++++++ drivers/iommu/hyperv/iommu.h | 44 ++ 7 files changed, 677 insertions(+) create mode 100644 drivers/iommu/hyperv/Kconfig create mode 100644 drivers/iommu/hyperv/hv-iommu-guest.c create mode 100644 drivers/iommu/hyperv/iommu.h
arch/x86/hyperv/hv_init.c +4 -0
@@ -579,6 +579,10 @@ void __init hyperv_init(void) old_setup_percpu_clockev = x86_init.timers.setup_percpu_clockev; x86_init.timers.setup_percpu_clockev = hv_stimer_setup_percpu_clockev; +#ifdef CONFIG_HYPERV_PVIOMMU + x86_init.iommu.iommu_init = hv_iommu_init; +#endif +hv_apic_init (); x86_init.pci.arch_init = hv_pci_init;
arch/x86/include/asm/mshyperv.h +4 -0
@@ -313,6 +313,10 @@ static inline void mshv_vtl_return_hypercall(void) {}static inline void __mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) {}#endif +#ifdef CONFIG_HYPERV_PVIOMMU +int __init hv_iommu_init (void ); +#endif +#include <asm-generic/mshyperv.h> #endif
drivers/iommu/Kconfig +1 -0
@@ -195,6 +195,7 @@ config MSM_IOMMU source "drivers/iommu/amd/Kconfig" source "drivers/iommu/arm/Kconfig" source "drivers/iommu/intel/Kconfig" +source "drivers/iommu/hyperv/Kconfig" source "drivers/iommu/iommufd/Kconfig" source "drivers/iommu/riscv/Kconfig"
drivers/iommu/hyperv/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Hyper-V para-virtualized IOMMU driver for Linux guests +config HYPERV_PVIOMMU + bool "Microsoft Hyper-V para-virtualized IOMMU driver for Linux guests" + depends on X86_64 && HYPERV + select IOMMU_API + select GENERIC_PT + select IOMMU_PT + select IOMMU_PT_X86_64 + select IOMMU_IOVA + default HYPERV + help + Para-virtualized IOMMU driver for Linux guests running on + Microsoft Hyper-V. Provides DMA remapping and IOTLB + flush support to enable DMA isolation for PCI devices + assigned to the guest.
drivers/iommu/hyperv/Makefile +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_IRQ_REMAP) += hv-irq-remap-x86.o +obj-$(CONFIG_HYPERV_PVIOMMU) += hv-iommu-guest.o
drivers/iommu/hyperv/hv-iommu-guest.c new file +607 -0
607 lines not on this page · raw message
drivers/iommu/hyperv/iommu.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH v5 4/5] iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The global pointer `hv_iommu_device` is left pointing to freed memory on initialization error…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The global pointer hv_iommu_device is left pointing to freed memory on initialization error paths. --
commit cabf0b0a28725bbdf8a09d64a7c284187b9174dc
Author: Yu Zhang <[email protected]>
iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest
This commit introduces a para-virtualized IOMMU driver for Linux guests on Hyper-V. It implements stage-1 IO translation within the guest OS by utilizing Hyper-V hypercalls.
Quoted 5 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +0
-0
[ ... ]
Quoted 4 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +4
-0+static void __init +hv_init_iommu_device (struct hv_iommu_dev *hv_iommu, +struct hv_output_get_iommu_capabilities *hv_iommu_cap) +{
[ ... ]
Quoted 5 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +5
-0+ hv_iommu_device = hv_iommu; +} + +int __init hv_iommu_init (void ) +{
[ ... ]
Quoted 9 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +9
-0+ hv_iommu =kzalloc_obj (*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) + goto err_free;
[ ... ]
drivers/iommu/hyperv/hv-iommu-guest.c line 605
Quoted 2 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +2
-0+err_free: +kfree (hv_iommu);
[Severity: Low]
If hv_iommu_init() fails after calling hv_init_iommu_device(), the allocated memory is freed here on the err_free path. Does the global pointer hv_iommu_device need to be reset to NULL to avoid leaving a dangling pointer?
While this might currently be unreachable because functions using hv_iommu_device are invoked via callbacks that are only registered on successful init, could this pose a regression risk for future code accessing this global state?
Quoted 2 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +2
-0+return ret; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v5 4/5] iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest
In reply to Yu ZhangQuoted 395 lines · Yu Zhang
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 invalidationThe 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 eliminating the VM exits for guest IOMMU mapping operations. For unmapping operations, VM exits to perform the IOTLB flush are still unavoidable.
Guest hibernation and resume are not supported by this initial implementation. The guest-owned stage-1 page tables reside in guest memory and are preserved in the hibernation image. However, the image does not by itself preserve the Hyper-V device-domain objects or their device attachments, and the current pvIOMMU interface does not define whether or how Hyper-V restores that state.
To identify a device in its hypercall interface, the driver looks up the logical device ID prefix registered for the device's PCI domain (see the logical device ID registry in
hv_common.c) and combines it with the PCI function number of the endpoint device.Co-developed-by Wei Liu <[email protected]>Signed-off-by Wei Liu <[email protected]>Co-developed-by Easwar Hariharan <[email protected]>Signed-off-by Easwar Hariharan <[email protected]>Signed-off-by Yu Zhang <[email protected]>Reviewed-by Jacob Pan <[email protected]>Reviewed-by Michael Kelley <[email protected]>--- arch/x86/hyperv/hv_init.c | 4 + arch/x86/include/asm/mshyperv.h | 4 + drivers/iommu/Kconfig | 1 + drivers/iommu/hyperv/Kconfig | 16 + drivers/iommu/hyperv/Makefile | 1 + drivers/iommu/hyperv/hv-iommu-guest.c | 607 ++++++++++++++++++++++++++ drivers/iommu/hyperv/iommu.h | 44 ++ 7 files changed, 677 insertions(+)create mode 100644
drivers/iommu/hyperv/Kconfigcreate mode 100644drivers/iommu/hyperv/hv-iommu-guest.ccreate mode 100644drivers/iommu/hyperv/iommu.harch/x86/hyperv/hv_init.c +4
-0@@ -579,6 +579,10 @@ void __init hyperv_init(void) old_setup_percpu_clockev = x86_init.timers.setup_percpu_clockev; x86_init.timers.setup_percpu_clockev = hv_stimer_setup_percpu_clockev; +#ifdef CONFIG_HYPERV_PVIOMMU + x86_init.iommu.iommu_init = hv_iommu_init; +#endif +hv_apic_init (); x86_init.pci.arch_init = hv_pci_init;arch/x86/include/asm/mshyperv.h +4
-0@@ -313,6 +313,10 @@ static inline void mshv_vtl_return_hypercall(void) {}static inline void __mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) {}#endif +#ifdef CONFIG_HYPERV_PVIOMMU +int __init hv_iommu_init (void ); +#endif +#include <asm-generic/mshyperv.h> #endif drivers/iommu/Kconfig +1
-0@@ -195,6 +195,7 @@ config MSM_IOMMU source "drivers/iommu/amd/Kconfig" source "drivers/iommu/arm/Kconfig" source "drivers/iommu/intel/Kconfig" +source "drivers/iommu/hyperv/Kconfig" source "drivers/iommu/iommufd/Kconfig" source "drivers/iommu/riscv/Kconfig"drivers/iommu/hyperv/Kconfig new file +16
-0@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Hyper-V para-virtualized IOMMU driver for Linux guests +config HYPERV_PVIOMMU + bool "Microsoft Hyper-V para-virtualized IOMMU driver for Linux guests" + depends on X86_64 && HYPERV + select IOMMU_API + select GENERIC_PT + select IOMMU_PT + select IOMMU_PT_X86_64 + select IOMMU_IOVA + default HYPERV + help + Para-virtualized IOMMU driver for Linux guests running on + Microsoft Hyper-V. Provides DMA remapping and IOTLB + flush support to enable DMA isolation for PCI devices + assigned to the guest.drivers/iommu/hyperv/Makefile +1
-0@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_IRQ_REMAP) += hv-irq-remap-x86.o +obj-$(CONFIG_HYPERV_PVIOMMU) += hv-iommu-guest.odrivers/iommu/hyperv/hv-iommu-guest.c new file +265
-0@@ -0,0 +1,607 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Hyper-V para-virtualized IOMMU driver for Linux guests. +* +* Copyright (C) 2024-2026 Microsoft, Inc. +*/ + +#define pr_fmt (fmt) "Hyper-V pvIOMMU: " fmt +#define dev_fmt (fmt) pr_fmt(fmt) + +#include <linux/iommu.h> +#include <linux/pci.h> +#include <linux/dma-map-ops.h> +#include <linux/generic_pt/iommu.h> +#include <linux/pci-ats.h> + +#include <asm/iommu.h> +#include <asm/hypervisor.h> +#include <asm/mshyperv.h> + +#include "iommu.h" +#include "../iommu-pages.h" + +struct hv_iommu_dev *hv_iommu_device; + +/* +* Identity and blocking domains are static singletons: identity is a 1:1 +* passthrough with no page table, blocking rejects all DMA. Neither holds +* per-IOMMU state, so one instance suffices even with multiple vIOMMUs. +*/ +static const struct iommu_domain_ops hv_iommu_identity_domain_ops; +static const struct iommu_domain_ops hv_iommu_blocking_domain_ops; +static struct iommu_ops hv_iommu_ops; + +static struct hv_iommu_domain hv_identity_domain = { + .domain = { + .type =IOMMU_DOMAIN_IDENTITY , + .ops = &hv_iommu_identity_domain_ops, + .owner = &hv_iommu_ops, + }, +}; + +static struct hv_iommu_domain hv_blocking_domain = { + .domain = { + .type =IOMMU_DOMAIN_BLOCKED , + .ops = &hv_iommu_blocking_domain_ops, + .owner = &hv_iommu_ops, + }, +}; + +static inline bool hv_iommu_present (u64 cap) +{ +return cap &HV_IOMMU_CAP_PRESENT ; +} + +static inline bool hv_iommu_s1_domain_supported (u64 cap) +{ +return cap &HV_IOMMU_CAP_S1 ; +} + +static inline bool hv_iommu_5lvl_supported (u64 cap) +{ +return cap &HV_IOMMU_CAP_S1_5LVL ; +} + +static inline bool hv_iommu_ats_supported (u64 cap) +{ +return cap &HV_IOMMU_CAP_ATS ; +} + +static int hv_create_device_domain (struct hv_iommu_domain *hv_domain) +{ +int ret; +u64 status; +unsigned long flags; +struct hv_input_create_device_domain *input; + + ret =ida_alloc_range (&hv_iommu_device->domain_ids, + hv_iommu_device->first_domain, + hv_iommu_device->last_domain,GFP_KERNEL ); +if (ret <0 ) +return ret; + + hv_domain->device_domain.partition_id =HV_PARTITION_ID_SELF ; + hv_domain->device_domain.domain_id.type =HV_DEVICE_DOMAIN_TYPE_S1 ; + hv_domain->device_domain.domain_id.id = ret; + hv_domain->hv_iommu = hv_iommu_device; + +local_irq_save (flags); + + input = *this_cpu_ptr (hyperv_pcpu_input_arg); +memset (input,0 ,sizeof (*input)); + input->device_domain = hv_domain->device_domain; + input->create_device_domain_flags.forward_progress_required =1 ; + input->create_device_domain_flags.inherit_owning_vtl =0 ; + status =hv_do_hypercall (HVCALL_CREATE_DEVICE_DOMAIN , input,NULL ); + +local_irq_restore (flags); + +if (!hv_result_success (status)) { +hv_status_err (status,"HVCALL_CREATE_DEVICE_DOMAIN failed\n" ); +ida_free (&hv_iommu_device->domain_ids, + hv_domain->device_domain.domain_id.id); + } + +return hv_result_to_errno (status); +} + +static void hv_delete_device_domain (struct hv_iommu_domain *hv_domain) +{ +u64 status; +unsigned long flags; +struct hv_input_delete_device_domain *input; + +local_irq_save (flags); + + input = *this_cpu_ptr (hyperv_pcpu_input_arg); +memset (input,0 ,sizeof (*input)); + input->device_domain = hv_domain->device_domain; + status =hv_do_hypercall (HVCALL_DELETE_DEVICE_DOMAIN , input,NULL ); + +local_irq_restore (flags); + +if (!hv_result_success (status)) +hv_status_err (status,"HVCALL_DELETE_DEVICE_DOMAIN failed\n" ); + +ida_free (&hv_domain->hv_iommu->domain_ids, + hv_domain->device_domain.domain_id.id); +} + +static int +hv_configure_device_domain (struct hv_iommu_domain *hv_domain, +const struct hv_device_domain_settings *settings) +{ +u64 status; +unsigned long flags; +struct hv_input_configure_device_domain *input; + +local_irq_save (flags); + + input = *this_cpu_ptr (hyperv_pcpu_input_arg); +memset (input,0 ,sizeof (*input)); + input->device_domain = hv_domain->device_domain; + input->settings = *settings; + status =hv_do_hypercall (HVCALL_CONFIGURE_DEVICE_DOMAIN , input,NULL ); + +local_irq_restore (flags); + +if (!hv_result_success (status)) +hv_status_err (status, +"HVCALL_CONFIGURE_DEVICE_DOMAIN failed\n" ); + +return hv_result_to_errno (status); +} + +static int +hv_create_configure_device_domain (struct hv_iommu_domain *hv_domain, +const struct hv_device_domain_settings *settings) +{ +int ret; + + ret =hv_create_device_domain (hv_domain); +if (ret) +return ret; + + ret =hv_configure_device_domain (hv_domain, settings); +if (ret) +hv_delete_device_domain (hv_domain); + +return ret; +} + +static bool hv_iommu_capable (struct device *dev,enum iommu_cap cap) +{ +return cap ==IOMMU_CAP_CACHE_COHERENCY ; +} + +static void hv_flush_device_domain (struct hv_iommu_domain *hv_domain) +{ +u64 status; +unsigned long flags; +struct hv_input_flush_device_domain *input; + +local_irq_save (flags); + + input = *this_cpu_ptr (hyperv_pcpu_input_arg); +memset (input,0 ,sizeof (*input)); + input->device_domain = hv_domain->device_domain; + status =hv_do_hypercall (HVCALL_FLUSH_DEVICE_DOMAIN , input,NULL ); + +local_irq_restore (flags); + +WARN_ONCE (!hv_result_success (status), +"HVCALL_FLUSH_DEVICE_DOMAIN failed: %#llx (%s)\n" , + status,hv_result_to_string (status)); +} + +static int hv_iommu_attach_dev (struct iommu_domain *domain,struct device *dev, +struct iommu_domain *old) +{ +u64 status; +u32 prefix; +unsigned long flags; +struct pci_dev *pdev; +struct hv_input_attach_device_domain *input; +struct hv_iommu_domain *hv_domain =to_hv_iommu_domain (domain); +int pci_domain; +int ret; + + pdev =to_pci_dev (dev); +dev_dbg (dev,"attaching to domain %d\n" , + hv_domain->device_domain.domain_id.id); + + pci_domain =pci_domain_nr (pdev->bus); + ret =hv_pci_lookup_dev_id (pci_domain, &prefix); +if (ret) { +dev_err (dev, +"no logical device ID registered for PCI domain %04x\n" , + pci_domain); +return ret; + } + +local_irq_save (flags); + + input = *this_cpu_ptr (hyperv_pcpu_input_arg); +memset (input,0 ,sizeof (*input)); + input->device_domain = hv_domain->device_domain; + input->device_id.as_uint64 = (u64 )prefix |PCI_FUNC (pdev->devfn); + status =hv_do_hypercall (HVCALL_ATTACH_DEVICE_DOMAIN , input,NULL ); + +local_irq_restore (flags); + +if (!hv_result_success (status) && +hv_result (status) !=HV_STATUS_DEVICE_ALREADY_IN_DOMAIN ) { +hv_status_err (status,"HVCALL_ATTACH_DEVICE_DOMAIN failed\n" ); +return hv_result_to_errno (status); + } + +if (domain != &hv_blocking_domain.domain && + !pdev->ats_enabled && +hv_iommu_ats_supported (hv_domain->hv_iommu->cap) && +pci_ats_supported (pdev)) +pci_enable_ats (pdev,PAGE_SHIFT ); + +return 0 ; +} + +static int hv_iommu_blocking_attach_dev (struct iommu_domain *domain, +struct device *dev, +struct iommu_domain *old) +{ +struct pci_dev *pdev =to_pci_dev (dev); +int ret; + +if (pdev->ats_enabled) +pci_disable_ats (pdev); + + ret =hv_iommu_attach_dev (domain, dev, old); + +/* +* Attaching to the blocking domain only asks the hypervisor to +* disable translation and IOPF for the device, so it cannot fail +* unless there is a driver or hypervisor bug. Return the hypercall +* status rather than 0 so that a failure on the DMA ownership claim
drivers/iommu/hyperv/hv-iommu-guest.c line 275
Quoted 10 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +10
-0+* path (VFIO/iommufd) fails the claim instead of leaving the device +* unblocked. WARN since such a failure indicates a bug. +*/ +WARN_ON (ret); +return ret; +} + +static int +hv_iommu_get_logical_device_property (struct device *dev,u32 code, +struct hv_output_get_logical_device_property *property)
Please indent left a bit to avoid line wrap.
Quoted 7 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +7
-0+{ +u64 status; +u32 prefix; +unsigned long flags; +int ret; +struct pci_dev *pdev =to_pci_dev (dev); +struct hv_input_get_logical_device_property *input;
drivers/iommu/hyperv/hv-iommu-guest.c line 292
Quoted 10 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +10
-0+struct hv_output_get_logical_device_property *output; + + ret =hv_pci_lookup_dev_id (pci_domain_nr (pdev->bus), &prefix); +if (ret) +return ret; + +local_irq_save (flags); + + input = *this_cpu_ptr (hyperv_pcpu_input_arg); + output = (struct hv_output_get_logical_device_property *)(input +1 );
Any reason for not using pcpu output arg like we do in all other places? If there is a technical reason, please document it, otherwise when revisited in future for re-design, anyone looking at this will be confused and waste time investigating if there is anything different about this hypercall.
drivers/iommu/hyperv/hv-iommu-guest.c line 297
Quoted 5 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +5
-0+memset (input,0 ,sizeof (*input)); + input->partition_id =HV_PARTITION_ID_SELF ; + input->logical_device_id = (u64 )prefix |PCI_FUNC (pdev->devfn); + input->code = code; + status =hv_do_hypercall (HVCALL_GET_LOGICAL_DEVICE_PROPERTY , input, output);
Please break line here also.
Quoted 12 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +12
-0+ *property = *output; + +local_irq_restore (flags); + +if (!hv_result_success (status)) +hv_status_err (status, +"HVCALL_GET_LOGICAL_DEVICE_PROPERTY failed\n" ); + +return hv_result_to_errno (status); +} + +static struct iommu_device *hv_iommu_probe_device (struct device *dev)
drivers/iommu/hyperv/hv-iommu-guest.c line 319
Quoted 10 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +10
-0+{ +struct hv_output_get_logical_device_property device_iommu_property = {0 }; + +if (!dev_is_pci (dev)) +return ERR_PTR (-ENODEV ); + +if (hv_iommu_get_logical_device_property (dev, +HV_LOGICAL_DEVICE_PROPERTY_PVIOMMU , + &device_iommu_property) || + !(device_iommu_property.device_iommu &HV_DEVICE_IOMMU_ENABLED ))
This is a little hard to read, perhaps indent HV_LOGICAL_DEVICE_PROPERTY_PVIOMMU left or how about :
rc = hv_iommu_get_log_dev_property(dev,
HV_LOGICAL_DEVICE_PROPERTY_PVIOMMU, &device_iommu_property);
if (rc ||
!(device_iommu_property.device_iommu & HV_DEVICE_IOMMU_ENABLED))
what do you think?
Thanks,
-Mukesh
Quoted 50 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +50
-0+return ERR_PTR (-ENODEV ); + +return &hv_iommu_device->iommu; +} + +static struct iommu_group *hv_iommu_device_group (struct device *dev) +{ +if (!dev_is_pci (dev)) +return ERR_PTR (-ENODEV ); + +return pci_device_group (dev); +} + +static int __init hv_initialize_static_domains (void ) +{ +/* +* Clearing translation_enabled bypasses stage-1 translation, so DMA +* addresses are used directly as GPAs. Hyper-V requires paging and +* blocked domains to keep translation_enabled set. +*/ +const struct hv_device_domain_settings identity_settings = { + .flags.translation_enabled =0 , + }; +const struct hv_device_domain_settings blocked_settings = { + .flags = { + .translation_enabled =1 , + .blocked =1 , + }, + }; +int ret; + +/* Default stage-1 identity domain */ + ret =hv_create_configure_device_domain (&hv_identity_domain, + &identity_settings); +if (ret) +return ret; + +/* Default stage-1 blocked domain */ + ret =hv_create_configure_device_domain (&hv_blocking_domain, + &blocked_settings); +if (ret) + goto delete_identity_domain; + +return 0 ; + +delete_identity_domain: +hv_delete_device_domain (&hv_identity_domain); +return ret; +} +
drivers/iommu/hyperv/hv-iommu-guest.c line 379
Quoted 10 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +10
-0+static void hv_iommu_get_resv_regions (struct device *dev, +struct list_head *head) +{ +struct iommu_resv_region *region; + + region =iommu_alloc_resv_x86_msi_region (); +if (!region) +return ; + +list_add_tail (®ion->list, head);
extra tiny nit: you could just do :
if (region)
list_add_tail(®ion->list, head);Quoted 278 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +228
-0+} + +static void hv_iommu_flush_iotlb_all (struct iommu_domain *domain) +{ +hv_flush_device_domain (to_hv_iommu_domain (domain)); +} + +static void hv_iommu_iotlb_sync (struct iommu_domain *domain, +struct iommu_iotlb_gather *iotlb_gather) +{ +hv_flush_device_domain (to_hv_iommu_domain (domain)); + +iommu_put_pages_list (&iotlb_gather->freelist); +} + +static void hv_iommu_paging_domain_free (struct iommu_domain *domain) +{ +struct hv_iommu_domain *hv_domain =to_hv_iommu_domain (domain); + +/* Free all remaining mappings */ +pt_iommu_deinit (&hv_domain->pt_iommu); + +hv_delete_device_domain (hv_domain); + +kfree (hv_domain); +} + +static const struct iommu_domain_ops hv_iommu_identity_domain_ops = { + .attach_dev = hv_iommu_attach_dev, +}; + +static const struct iommu_domain_ops hv_iommu_blocking_domain_ops = { + .attach_dev = hv_iommu_blocking_attach_dev, +}; + +static const struct iommu_domain_ops hv_iommu_paging_domain_ops = { + .attach_dev = hv_iommu_attach_dev, +IOMMU_PT_DOMAIN_OPS (x86_64), + .flush_iotlb_all = hv_iommu_flush_iotlb_all, + .iotlb_sync = hv_iommu_iotlb_sync, + .free = hv_iommu_paging_domain_free, +}; + +static struct iommu_domain *hv_iommu_domain_alloc_paging (struct device *dev) +{ +int ret; +struct hv_iommu_domain *hv_domain; +struct pt_iommu_x86_64_hw_info pt_info; +struct pt_iommu_x86_64_cfg cfg = {}; +struct hv_device_domain_settings settings = { + .flags = { + .translation_enabled =1 , + }, + }; + + hv_domain =kzalloc_obj (*hv_domain,GFP_KERNEL ); +if (!hv_domain) +return ERR_PTR (-ENOMEM ); + + hv_domain->pt_iommu.nid =dev_to_node (dev); + + cfg.common.hw_max_vasz_lg2 = hv_iommu_device->max_iova_width; + cfg.common.hw_max_oasz_lg2 =52 ; +/* +* Hyper-V S1 domains use a 4-level root for IOVA widths up to +* 48 bits. A 5-level root is used only for wider apertures when +* HV_IOMMU_CAP_S1_5LVL is advertised. +*/ + cfg.top_level = (hv_iommu_device->max_iova_width >48 ) ?4 :3 ; + + ret =pt_iommu_x86_64_init (&hv_domain->pt_iommu_x86_64, &cfg,GFP_KERNEL ); +if (ret) + goto err_free; + +/* Constrain to page sizes the hypervisor supports */ + hv_domain->domain.pgsize_bitmap &= hv_iommu_device->pgsize_bitmap; + + hv_domain->domain.ops = &hv_iommu_paging_domain_ops; + +pt_iommu_x86_64_hw_info (&hv_domain->pt_iommu_x86_64, &pt_info); + 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); +if (ret) + goto err_pt_deinit; + +return &hv_domain->domain; + +err_pt_deinit: +pt_iommu_deinit (&hv_domain->pt_iommu); +err_free: +kfree (hv_domain); +return ERR_PTR (ret); +} + +static struct iommu_ops hv_iommu_ops = { + .capable = hv_iommu_capable, + .domain_alloc_paging = hv_iommu_domain_alloc_paging, + .probe_device = hv_iommu_probe_device, + .device_group = hv_iommu_device_group, + .get_resv_regions = hv_iommu_get_resv_regions, + .owner =THIS_MODULE , + .identity_domain = &hv_identity_domain.domain, + .blocked_domain = &hv_blocking_domain.domain, + .release_domain = &hv_blocking_domain.domain, +}; + +static u64 hv_iommu_detect (struct hv_output_get_iommu_capabilities *cap) +{ +u64 status; +unsigned long flags; +struct hv_input_get_iommu_capabilities *input; +struct hv_output_get_iommu_capabilities *output; + +local_irq_save (flags); + + input = *this_cpu_ptr (hyperv_pcpu_input_arg); + output = (struct hv_output_get_iommu_capabilities *)(input +1 ); +memset (input,0 ,sizeof (*input)); + input->partition_id =HV_PARTITION_ID_SELF ; + status =hv_do_hypercall (HVCALL_GET_IOMMU_CAPABILITIES , input, output); + *cap = *output; + +local_irq_restore (flags); + +return status; +} + +static void __init +hv_init_iommu_device (struct hv_iommu_dev *hv_iommu, +struct hv_output_get_iommu_capabilities *hv_iommu_cap) +{ +ida_init (&hv_iommu->domain_ids); + + hv_iommu->cap = hv_iommu_cap->iommu_cap; + hv_iommu->max_iova_width = hv_iommu_cap->max_iova_width; +if (!hv_iommu_5lvl_supported (hv_iommu->cap) && + hv_iommu->max_iova_width >48 ) { +pr_info ("5-level paging not supported, limiting iova width to 48.\n" ); + hv_iommu->max_iova_width =48 ; + } + + hv_iommu->first_domain =HV_DEVICE_DOMAIN_ID_DEFAULT +1 ; + hv_iommu->last_domain =HV_DEVICE_DOMAIN_ID_NULL -1 ; + hv_iommu->pgsize_bitmap = hv_iommu_cap->pgsize_bitmap; + hv_iommu_device = hv_iommu; +} + +int __init hv_iommu_init (void ) +{ +u64 status; +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 ; + + status =hv_iommu_detect (&hv_iommu_cap); +if (!hv_result_success (status)) { +if (hv_result (status) ==HV_STATUS_INVALID_HYPERCALL_CODE ) +return -ENODEV ; + +hv_status_err (status,"HVCALL_GET_IOMMU_CAPABILITIES failed\n" ); +return hv_result_to_errno (status); + } + +if (!hv_iommu_present (hv_iommu_cap.iommu_cap)) +return -ENODEV ; + +if (!hv_iommu_s1_domain_supported (hv_iommu_cap.iommu_cap)) { +pr_err ("stage-1 translation not supported: cap=%#llx\n" , + hv_iommu_cap.iommu_cap); +return -ENODEV ; + } + +/* +* Require the base page size. The domain page-size bitmap is later +* restricted to the sizes supported by both iommupt and Hyper-V. +*/ +if (!(hv_iommu_cap.pgsize_bitmap &PAGE_SIZE )) { +pr_err ("unsupported page sizes: pgsize_bitmap=0x%llx\n" , + hv_iommu_cap.pgsize_bitmap); +return -ENODEV ; + } + + iommu_detected =1 ; +pci_request_acs (); + + hv_iommu =kzalloc_obj (*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) + goto err_free; + + 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_delete_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; + } + +pr_info ("initialized: %u-bit IOVA aperture, page-size bitmap %#llx\n" , + hv_iommu->max_iova_width, hv_iommu->pgsize_bitmap); +return 0 ; + +err_sysfs_remove: +iommu_device_sysfs_remove (&hv_iommu->iommu); +err_delete_static_domains: +hv_delete_device_domain (&hv_blocking_domain); +hv_delete_device_domain (&hv_identity_domain); +err_free: +kfree (hv_iommu); +return ret; +}drivers/iommu/hyperv/iommu.h new file +44
-0@@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Hyper-V IOMMU driver. +* +* Copyright (C) 2024-2026, Microsoft, Inc. +* +*/ + +#ifndef _HYPERV_IOMMU_H +#define _HYPERV_IOMMU_H + +struct hv_iommu_dev { +struct iommu_device iommu; +struct ida domain_ids; + +/* Device configuration */ +u8 max_iova_width; +u8 max_pasid_width; +u64 cap; +u64 pgsize_bitmap; + +u64 first_domain; +u64 last_domain; +}; + +struct hv_iommu_domain { +union { +struct iommu_domain domain; +struct pt_iommu pt_iommu; +struct pt_iommu_x86_64 pt_iommu_x86_64; + }; +struct hv_iommu_dev *hv_iommu; +struct hv_input_device_domain device_domain; +u64 pgsize_bitmap; +}; + +PT_IOMMU_CHECK_DOMAIN(struct hv_iommu_domain, pt_iommu, domain); +PT_IOMMU_CHECK_DOMAIN(struct hv_iommu_domain, pt_iommu_x86_64.iommu, domain); + +#define to_hv_iommu_domain (d) \ + container_of(d, struct hv_iommu_domain, domain) + +#endif /* _HYPERV_IOMMU_H */
Re: [PATCH v5 4/5] iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest
<snip>
Quoted 14 lines
Quoted 14 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +14
-0+{ +u64 status; +u32 prefix; +unsigned long flags; +int ret; +struct pci_dev *pdev =to_pci_dev (dev); +struct hv_input_get_logical_device_property *input; +struct hv_output_get_logical_device_property *output; + + ret =hv_pci_lookup_dev_id (pci_domain_nr (pdev->bus), &prefix); +if (ret) +return ret; + +local_irq_save (flags);
Quoted 10 lines
drivers/iommu/hyperv/hv-iommu-guest.c line 292
Quoted 3 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +3
-0+ + input = *this_cpu_ptr (hyperv_pcpu_input_arg); + output = (struct hv_output_get_logical_device_property *)(input +1 );Any reason for not using pcpu output arg like we do in all other places? If there is a technical reason, please document it, otherwise when revisited in future for re-design, anyone looking at this will be confused and waste time investigating if there is anything different about this hypercall.
Thank you, Mukesh. I had also incorrectly assumed that output required a separate page, which is why the RFC included a separate output-page allocation patch. Michael clarified during that review [1] that input and output can share a page as long as their buffers do not overlap, so I dropped that patch latter.
Actually, there's nothing specific to this hypercall here - it follows the existing usage. E.g., hv_pci_read_mmio() already uses such arrangement, as Michael noted in [2]. pvIOMMU queries fit within the existing per-CPU page, with output placed after input, avoiding an unnecessary allocation.
[1] https://lore.kernel.org/all/SN6PR02MB4157C3EF6617A7BA4CA9E432D485A@SN6PR02MB4157.namprd02.prod.outlook.com/
[2] https://lore.kernel.org/all/SN6PR02MB4157BF936EBDA23AD1EC5183D480A@SN6PR02MB4157.namprd02.prod.outlook.com/
B.R.
Yu
Re: [PATCH v5 4/5] iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest
Quoted 27 lines · Yu Zhang
<snip>
Quoted 14 lines
Quoted 14 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +14
-0+{ +u64 status; +u32 prefix; +unsigned long flags; +int ret; +struct pci_dev *pdev =to_pci_dev (dev); +struct hv_input_get_logical_device_property *input; +struct hv_output_get_logical_device_property *output; + + ret =hv_pci_lookup_dev_id (pci_domain_nr (pdev->bus), &prefix); +if (ret) +return ret; + +local_irq_save (flags);Quoted 10 lines
drivers/iommu/hyperv/hv-iommu-guest.c line 292
Quoted 3 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +3
-0+ + input = *this_cpu_ptr (hyperv_pcpu_input_arg); + output = (struct hv_output_get_logical_device_property *)(input +1 );Any reason for not using pcpu output arg like we do in all other places? If there is a technical reason, please document it, otherwise when revisited in future for re-design, anyone looking at this will be confused and waste time investigating if there is anything different about this hypercall.
Quoted 5 lines
Thank you, Mukesh. I had also incorrectly assumed that output required a separate page, which is why the RFC included a separate output-page allocation patch. Michael clarified during that review [1] that input and output can share a page as long as their buffers do not overlap, so I dropped that patch latter.
They can share a page, but we don't enforce the sizes combined do not overflow a page, and that could be an issue in future. There is a tool on the hyp side i believe to check that input and output struct sizes do not exceed page size.
Also, both the input and output pages are pre-allocated, so there is no extra allocation (otherwise, we'd have changed all places by now). So it's better to just follow the convention we've so far just to avoid confusion during future redesign imo. We def need to revisit this in near/medium future for all hypercalls.
Thanks,
-Mukesh
Quoted 10 lines
Actually, there's nothing specific to this hypercall here - it follows the existing usage. E.g.,
hv_pci_read_mmio()already uses such arrangement, as Michael noted in [2]. pvIOMMU queries fit within the existing per-CPU page, with output placed after input, avoiding an unnecessary allocation.[1] https://lore.kernel.org/all/SN6PR02MB4157C3EF6617A7BA4CA9E432D485A@SN6PR02MB4157.namprd02.prod.outlook.com/
[2] https://lore.kernel.org/all/SN6PR02MB4157BF936EBDA23AD1EC5183D480A@SN6PR02MB4157.namprd02.prod.outlook.com/B.R.
Yu
Re: [PATCH v5 4/5] iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest
Quoted 28 lines · Mukesh R
Quoted 27 lines · Yu Zhang
<snip>
Quoted 24 lines
Quoted 7 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +7
-0+{ +u64 status; +u32 prefix; +unsigned long flags; +int ret; +struct pci_dev *pdev =to_pci_dev (dev); +struct hv_input_get_logical_device_property *input;drivers/iommu/hyperv/hv-iommu-guest.c line 292
Quoted 10 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +10
-0+struct hv_output_get_logical_device_property *output; + + ret =hv_pci_lookup_dev_id (pci_domain_nr (pdev->bus), &prefix); +if (ret) +return ret; + +local_irq_save (flags); + + input = *this_cpu_ptr (hyperv_pcpu_input_arg); + output = (struct hv_output_get_logical_device_property *)(input +1 );Any reason for not using pcpu output arg like we do in all other places? If there is a technical reason, please document it, otherwise when revisited in future for re-design, anyone looking at this will be confused and waste time investigating if there is anything different about this hypercall.
Quoted 8 lines
Quoted 5 lines
Thank you, Mukesh. I had also incorrectly assumed that output required a separate page, which is why the RFC included a separate output-page allocation patch. Michael clarified during that review [1] that input and output can share a page as long as their buffers do not overlap, so I dropped that patch latter.
They can share a page, but we don't enforce the sizes combined do not overflow a page, and that could be an issue in future. There is
The two hypercalls (HVCALL_GET_IOMMU_CAPABILITIES and HVCALL_GET_LOGICAL_DEVICE_PROPERTY) each currently use only 40 bytes of combined input and output. No concrete requirement has been identified that would make either approach 4 KB. A hypothetical future expansion is not sufficient reason to allocate another per-CPU page now.
Quoted 9 lines
a tool on the hyp side i believe to check that input and output struct sizes do not exceed page size.
Also, both the input and output pages are pre-allocated, so there is no extra allocation (otherwise, we'd have changed all places by now). So it's better to just follow the convention we've so far just to avoid confusion during future redesign imo. We def need to revisit this in near/medium future for all hypercalls.
Well, output page is NOT pre-allocated ordinary child partitions. Please see hv_output_page_exists() in hv_common.c.
My RFC included a separate allocation because I had incorrectly assumed that output required its own page. Like I mentioned earlier, this was already discussed during the RFC review [1], and that allocation patch was dropped following the discussion.
Using separate pages is NOT a *convention* either: hv_pci_read_mmio() already places input and output in non-overlapping regions of the same page.
We can certainly reassess which hypercalls need separate output pages in a broader review. I would keep that separate from this series, rather than reopen the RFC discussion without a concrete issue in the current implementation.
B.R.
Yu
Re: [PATCH v5 4/5] iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest
Quoted 35 lines · Yu Zhang
Quoted 34 lines · Mukesh R
Quoted 32 lines · Yu Zhang
<snip>
Quoted 14 lines
Quoted 14 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +14
-0+{ +u64 status; +u32 prefix; +unsigned long flags; +int ret; +struct pci_dev *pdev =to_pci_dev (dev); +struct hv_input_get_logical_device_property *input; +struct hv_output_get_logical_device_property *output; + + ret =hv_pci_lookup_dev_id (pci_domain_nr (pdev->bus), &prefix); +if (ret) +return ret; + +local_irq_save (flags);Quoted 10 lines
drivers/iommu/hyperv/hv-iommu-guest.c line 292
Quoted 3 lines
drivers/iommu/hyperv/hv-iommu-guest.c new file +3
-0+ + input = *this_cpu_ptr (hyperv_pcpu_input_arg); + output = (struct hv_output_get_logical_device_property *)(input +1 );Any reason for not using pcpu output arg like we do in all other places? If there is a technical reason, please document it, otherwise when revisited in future for re-design, anyone looking at this will be confused and waste time investigating if there is anything different about this hypercall.
Thank you, Mukesh. I had also incorrectly assumed that output required a separate page, which is why the RFC included a separate output-page allocation patch. Michael clarified during that review [1] that input and output can share a page as long as their buffers do not overlap, so I dropped that patch latter.
Quoted 8 lines
Quoted 2 lines
They can share a page, but we don't enforce the sizes combined do not overflow a page, and that could be an issue in future. There is
The two hypercalls (
HVCALL_GET_IOMMU_CAPABILITIESandHVCALL_GET_LOGICAL_DEVICE_PROPERTY) each currently use only 40 bytes of combined input and output. No concrete requirement has been identified that would make either approach 4 KB. A hypothetical future expansion is not sufficient reason to allocate another per-CPU page now.
Understood and obvious. But just like you are pointing at hv_pci_read_mmio(), someone could point at this and may not be using small structs. When almost all hyperalls use a certain way, that is the convention. I see that outpage is not always allocated for guest VMs, and if you don't wanna check if it is and just share intput page, that's fine. Like I said earlier, add a comment so that when one looks at redoing all hypercalls that use input and output page, this one doesn't get missed because they might think there is something special about this. It would be ludicrous on my part to suggest that we fix all hypercalls as part of this series.
In a nutshell, a simple comment like this would help:
/*
* This hyperall has small input and output parameters. So to avoid
* checking if output page has been allocated, we just use the input
* page for output. Using the output page would also be correct. */
Thanks,
-Mukesh
Quoted 31 lines
Quoted 9 lines
a tool on the hyp side i believe to check that input and output struct sizes do not exceed page size.
Also, both the input and output pages are pre-allocated, so there is no extra allocation (otherwise, we'd have changed all places by now). So it's better to just follow the convention we've so far just to avoid confusion during future redesign imo. We def need to revisit this in near/medium future for all hypercalls.
Well, output page is NOT pre-allocated ordinary child partitions. Please see
hv_output_page_exists()inhv_common.c.My RFC included a separate allocation because I had incorrectly assumed that output required its own page. Like I mentioned earlier, this was already discussed during the RFC review [1], and that allocation patch was dropped following the discussion.
Using separate pages is NOT a *convention* either:
hv_pci_read_mmio()already places input and output in non-overlapping regions of the same page.We can certainly reassess which hypercalls need separate output pages in a broader review. I would keep that separate from this series, rather than reopen the RFC discussion without a concrete issue in the current implementation.
B.R.
Yu
Re: [PATCH v5 4/5] iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest
In reply to Yu ZhangQuoted 100 lines
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 invalidationThe 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 eliminating the VM exits for guest IOMMU mapping operations. For unmapping operations, VM exits to perform the IOTLB flush are still unavoidable.
Guest hibernation and resume are not supported by this initial implementation. The guest-owned stage-1 page tables reside in guest memory and are preserved in the hibernation image. However, the image does not by itself preserve the Hyper-V device-domain objects or their device attachments, and the current pvIOMMU interface does not define whether or how Hyper-V restores that state.
To identify a device in its hypercall interface, the driver looks up the logical device ID prefix registered for the device's PCI domain (see the logical device ID registry in
hv_common.c) and combines it with the PCI function number of the endpoint device.Co-developed-by Wei Liu <[email protected]>Signed-off-by Wei Liu <[email protected]>Co-developed-by Easwar Hariharan <[email protected]>Signed-off-by Easwar Hariharan <[email protected]>Signed-off-by Yu Zhang <[email protected]>Reviewed-by Jacob Pan <[email protected]>Reviewed-by Michael Kelley <[email protected]>--- arch/x86/hyperv/hv_init.c | 4 + arch/x86/include/asm/mshyperv.h | 4 + drivers/iommu/Kconfig | 1 + drivers/iommu/hyperv/Kconfig | 16 + drivers/iommu/hyperv/Makefile | 1 + drivers/iommu/hyperv/hv-iommu-guest.c | 607 ++++++++++++++++++++++++++ drivers/iommu/hyperv/iommu.h | 44 ++ 7 files changed, 677 insertions(+) create mode 100644 drivers/iommu/hyperv/Kconfig create mode 100644 drivers/iommu/hyperv/hv-iommu-guest.c create mode 100644 drivers/iommu/hyperv/iommu.harch/x86/hyperv/hv_init.c +4
-0@@ -579,6 +579,10 @@ void __init hyperv_init(void) old_setup_percpu_clockev = x86_init.timers.setup_percpu_clockev; x86_init.timers.setup_percpu_clockev = hv_stimer_setup_percpu_clockev; +#ifdef CONFIG_HYPERV_PVIOMMU + x86_init.iommu.iommu_init = hv_iommu_init; +#endif +hv_apic_init (); x86_init.pci.arch_init = hv_pci_init;arch/x86/include/asm/mshyperv.h +4
-0@@ -313,6 +313,10 @@ static inline void mshv_vtl_return_hypercall(void) {}static inline void __mshv_vtl_return_call (struct mshv_vtl_cpu_context *vtl0) {}#endif +#ifdef CONFIG_HYPERV_PVIOMMU +int __init hv_iommu_init (void ); +#endif +#include <asm-generic/mshyperv.h> #endif drivers/iommu/Kconfig +1
-0@@ -195,6 +195,7 @@ config MSM_IOMMU source "drivers/iommu/amd/Kconfig" source "drivers/iommu/arm/Kconfig" source "drivers/iommu/intel/Kconfig" +source "drivers/iommu/hyperv/Kconfig" source "drivers/iommu/iommufd/Kconfig" source "drivers/iommu/riscv/Kconfig"drivers/iommu/hyperv/Kconfig new file +0
-0
drivers/iommu/hyperv/Kconfig line 10
Quoted 10 lines
drivers/iommu/hyperv/Kconfig new file +10
-0@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Hyper-V para-virtualized IOMMU driver for Linux guests +config HYPERV_PVIOMMU + bool "Microsoft Hyper-V para-virtualized IOMMU driver for Linux guests" + depends on X86_64 && HYPERV + select IOMMU_API + select GENERIC_PT + select IOMMU_PT + select IOMMU_PT_X86_64 + select IOMMU_IOVA
Should this be IOMMU_DMA ?
drivers/iommu/hyperv/Kconfig
Quoted 12 lines
[ ... 389 lines skipped ... ]
drivers/iommu/hyperv/Kconfig new file +11
-0+static void hv_iommu_get_resv_regions(struct device *dev, + struct list_head *head) +{ + struct iommu_resv_region *region; + + region = iommu_alloc_resv_x86_msi_region(); + if (!region) + return; + + list_add_tail(®ion->list, head); +}
Maybe the helper should have added to the list too?
It broadly seems OK to me
Signature · 1 line
Jason
Re: [PATCH v5 4/5] iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest
Hi Jason,
Quoted 11 lines · On Tue, 29 Sep 2026 17:04:47 -0300 Jason Gunthorpe <[email protected]> wrote:
drivers/iommu/hyperv/Kconfig line 10
Quoted 9 lines
(quoted diff) +2
-0+config HYPERV_PVIOMMU + bool "Microsoft Hyper-V para-virtualized IOMMU driver forLinux guests"
drivers/iommu/hyperv/Kconfig new file +6
-0+ depends on X86_64 && HYPERV + select IOMMU_API + select GENERIC_PT + select IOMMU_PT + select IOMMU_PT_X86_64 + select IOMMU_IOVAShould this be
IOMMU_DMA?
I agree. I guess we should also delete "select IOMMU_API", since IOMMU_DMA selects both.
Noticed vt-d driver has the same option, maybe it should also be changed. Baolu, is that due to historical reasons?
config INTEL_IOMMU
bool "Support for Intel IOMMU using DMA Remapping Devices" depends on PCI_MSI && ACPI && X86 select IOMMU_API select GENERIC_PT select IOMMU_PT select IOMMU_PT_X86_64 select IOMMU_PT_VTDSS select IOMMU_IOVA
Re: [PATCH v5 4/5] iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest
Quoted 24 lines · Jacob Pan
Hi Jason,
Quoted 11 lines · On Tue, 29 Sep 2026 17:04:47 -0300 Jason Gunthorpe <[email protected]> wrote:
drivers/iommu/hyperv/Kconfig line 10
Quoted 9 lines
(quoted diff) +2
-0+config HYPERV_PVIOMMU + bool "Microsoft Hyper-V para-virtualized IOMMU driver forLinux guests"
drivers/iommu/hyperv/Kconfig new file +6
-0+ depends on X86_64 && HYPERV + select IOMMU_API + select GENERIC_PT + select IOMMU_PT + select IOMMU_PT_X86_64 + select IOMMU_IOVAShould this be
IOMMU_DMA?I agree. I guess we should also delete "select
IOMMU_API", sinceIOMMU_DMAselects both.Noticed vt-d driver has the same option, maybe it should also be changed. Baolu, is that due to historical reasons?
config
INTEL_IOMMU
Quoted 8 lines
bool "Support for Intel IOMMU using DMA Remapping Devices" depends on PCI_MSI && ACPI && X86 select IOMMU_API select GENERIC_PT select IOMMU_PT select IOMMU_PT_X86_64 select IOMMU_PT_VTDSS select IOMMU_IOVA
FWIW, AMD also has the same...
config AMD_IOMMU
bool "AMD IOMMU support"
select SWIOTLB
select PCI_MSI
select PCI_ATS
select PCI_PRI
select PCI_PASID
select IRQ_MSI_LIB
select MMU_NOTIFIER
select IOMMU_API
select IOMMU_IOVA
but ARM doesn't, and doesn't select IOMMU_DMA either.
:confused:
Thanks,
Easwar (he/him)
Vasant Hegde
maintainerRe: [PATCH v5 4/5] iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest
Quoted 36 lines · Easwar Hariharan
Quoted 24 lines · Jacob Pan
Hi Jason,
Quoted 11 lines · On Tue, 29 Sep 2026 17:04:47 -0300 Jason Gunthorpe <[email protected]> wrote:
drivers/iommu/hyperv/Kconfig line 10
Quoted 9 lines
(quoted diff) +2
-0+config HYPERV_PVIOMMU + bool "Microsoft Hyper-V para-virtualized IOMMU driver forLinux guests"
drivers/iommu/hyperv/Kconfig new file +6
-0+ depends on X86_64 && HYPERV + select IOMMU_API + select GENERIC_PT + select IOMMU_PT + select IOMMU_PT_X86_64 + select IOMMU_IOVAShould this be
IOMMU_DMA?I agree. I guess we should also delete "select
IOMMU_API", sinceIOMMU_DMAselects both.Noticed vt-d driver has the same option, maybe it should also be changed. Baolu, is that due to historical reasons?
config
INTEL_IOMMUQuoted 8 lines
bool "Support for Intel IOMMU using DMA Remapping Devices" depends on PCI_MSI && ACPI && X86 select IOMMU_API select GENERIC_PT select IOMMU_PT select IOMMU_PT_X86_64 select IOMMU_PT_VTDSS select IOMMU_IOVAFWIW, AMD also has the same...
Quoted 11 lines
config
AMD_IOMMU
bool "AMD IOMMU support"
select SWIOTLB
selectPCI_MSI
selectPCI_ATS
selectPCI_PRI
selectPCI_PASID
selectIRQ_MSI_LIB
selectMMU_NOTIFIER
selectIOMMU_API
selectIOMMU_IOVA
We should replace IOMMU_API And IOMMU_IOVA with IOMMU_DMA.
also probably we should move PCI_ATS, PCI_PRI, PCI_PASID to CONFIG_IOMMU_SVA and remove it from amd/intel driver code.
-Vasant
PATCH v5 5/5 iommu/hyperv: Add page-selective IOTLB flush support
In reply to Yu ZhangAdd page-selective IOTLB flush using HVCALL_FLUSH_DEVICE_DOMAIN_LIST. This hypercall accepts a list of (page_number, page_mask_shift) entries, enabling finer-grained IOTLB invalidation compared to the domain-wide HVCALL_FLUSH_DEVICE_DOMAIN used by hv_iommu_flush_iotlb_all().
hv_iommu_calc_flush_range() computes the smallest power-of-two aligned range that covers the target IOVA region, producing a single flush descriptor. This may over-flush when the range is not naturally aligned, matching the approach used by Intel VT-d PSI. If the page-selective flush fails, the code falls back to a full domain flush.
--- drivers/iommu/hyperv/hv-iommu-guest.c | 74 ++++++++++++++++++++++++++- include/hyperv/hvgdk_mini.h | 1 + include/hyperv/hvhdk_mini.h | 18 +++++++ 3 files changed, 92 insertions(+), 1 deletion(-)
drivers/iommu/hyperv/hv-iommu-guest.c +73 -1
@@ -384,11 +384,82 @@ static void hv_iommu_flush_iotlb_all(struct iommu_domain *domain)hv_flush_device_domain (to_hv_iommu_domain (domain)); } +/* +* Calculate the minimal power-of-two aligned range that covers [start, end] +* (end is inclusive). Returns a single (page_number, page_mask_shift) +* descriptor that may over-flush when the range is not naturally aligned. +*/ +static void +hv_iommu_calc_flush_range (unsigned long start,unsigned long end, +union hv_iommu_flush_va *va) +{ +unsigned long aligned_start; +unsigned int sz_lg2; + + sz_lg2 =max (fls_long (start ^ end),HV_HYP_PAGE_SHIFT ); + +/* +* A valid IOVA range shall not span bit 63. Use the maximum mask +* so the host can safely perform a full flush. +*/ +if (WARN_ON_ONCE (sz_lg2 ==BITS_PER_LONG )) + aligned_start =0 ; +else + aligned_start = + start &GENMASK (BITS_PER_LONG -1 , sz_lg2); + + va->page_number = aligned_start >>HV_HYP_PAGE_SHIFT ; + va->page_mask_shift = sz_lg2 -HV_HYP_PAGE_SHIFT ; +} + +static void hv_flush_device_domain_list (struct hv_iommu_domain *hv_domain, +struct iommu_iotlb_gather *iotlb_gather) +{ +u64 status; +unsigned long flags; +struct hv_input_flush_device_domain_list *input; + +local_irq_save (flags); + + input = *this_cpu_ptr (hyperv_pcpu_input_arg); +/* Clear the fixed header and the single range entry. */ +memset (input,0 ,struct_size (input, iova_list,1 )); + + input->device_domain = hv_domain->device_domain; + input->flags |=HV_FLUSH_DEVICE_DOMAIN_LIST_IOMMU_FORMAT ; +hv_iommu_calc_flush_range (iotlb_gather->start, iotlb_gather->end, + &input->iova_list[0 ]); + + status =hv_do_rep_hypercall (HVCALL_FLUSH_DEVICE_DOMAIN_LIST , +1 ,0 , input,NULL ); + +if (WARN_ONCE (!hv_result_success (status), +"HVCALL_FLUSH_DEVICE_DOMAIN_LIST failed: %#llx (%s)\n" , + status,hv_result_to_string (status))) { +/* Page-selective flush failed, fall back to full flush. */ +struct hv_input_flush_device_domain *flush_all = (void *)input; + +memset (flush_all,0 ,sizeof (*flush_all)); + flush_all->device_domain = hv_domain->device_domain; + status =hv_do_hypercall (HVCALL_FLUSH_DEVICE_DOMAIN , + flush_all,NULL ); +WARN (!hv_result_success (status), +"HVCALL_FLUSH_DEVICE_DOMAIN fallback also failed: %#llx (%s)\n" , + status,hv_result_to_string (status)); + } + +local_irq_restore (flags); +} +static void hv_iommu_iotlb_sync (struct iommu_domain *domain,struct iommu_iotlb_gather *iotlb_gather) { -hv_flush_device_domain (to_hv_iommu_domain (domain)); +hv_flush_device_domain_list (to_hv_iommu_domain (domain), iotlb_gather); +/* +* The hypercall also invalidates non-leaf page-walk caches, so +* detached page-table pages can now be freed. +*/ iommu_put_pages_list (&iotlb_gather->freelist); }
@@ -440,6 +511,7 @@ static struct iommu_domain *hv_iommu_domain_alloc_paging(struct device *dev) cfg.common.hw_max_vasz_lg2 = hv_iommu_device->max_iova_width; cfg.common.hw_max_oasz_lg2 =52 ; + cfg.common.features |=BIT (PT_FEAT_FLUSH_RANGE );/* * Hyper-V S1 domains use a 4-level root for IOVA widths up to * 48 bits. A 5-level root is used only for wider apertures when
include/hyperv/hvgdk_mini.h +1 -0
@@ -497,6 +497,7 @@ union hv_vp_assist_msr_contents { /* HV_REGISTER_VP_ASSIST_PAGE */#define HVCALL_GET_GPA_PAGES_ACCESS_STATES 0x00c9#define HVCALL_CONFIGURE_DEVICE_DOMAIN 0x00ce#define HVCALL_FLUSH_DEVICE_DOMAIN 0x00d0 +#define HVCALL_FLUSH_DEVICE_DOMAIN_LIST 0x00d1#define HVCALL_ACQUIRE_SPARSE_SPA_PAGE_HOST_ACCESS 0x00d7#define HVCALL_RELEASE_SPARSE_SPA_PAGE_HOST_ACCESS 0x00d8#define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db
include/hyperv/hvhdk_mini.h +18 -0
@@ -685,4 +685,22 @@ struct hv_input_flush_device_domain { u32 reserved; } __packed; +union hv_iommu_flush_va {/* HV_IOMMU_GVA_RANGE */ +u64 as_uint64; +struct { +u64 page_mask_shift :6 ; +u64 reserved :6 ; +u64 page_number :52 ; + }; +} __packed; + +/* HV_INPUT_FLUSH_DEVICE_DOMAIN_LIST */ +struct hv_input_flush_device_domain_list { +struct hv_input_device_domain device_domain; +#define HV_FLUSH_DEVICE_DOMAIN_LIST_IOMMU_FORMAT BIT(0) +u32 flags; +u32 reserved; +union hv_iommu_flush_va iova_list[]; +} __packed; +#endif /* _HV_HVHDK_MINI_H */
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH v5 5/5] iommu/hyperv: Add page-selective IOTLB flush support
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
Add page-selective IOTLB flush using
HVCALL_FLUSH_DEVICE_DOMAIN_LIST. This hypercall accepts a list of (page_number,page_mask_shift) entries, enabling finer-grained IOTLB invalidation compared to the domain-wideHVCALL_FLUSH_DEVICE_DOMAINused byhv_iommu_flush_iotlb_all().
Quoted 8 lines
hv_iommu_calc_flush_range()computes the smallest power-of-two aligned range that covers the target IOVA region, producing a single flush descriptor. This may over-flush when the range is not naturally aligned, matching the approach used by Intel VT-d PSI. If the page-selective flush fails, the code falls back to a full domain flush.Signed-off-by Easwar Hariharan <[email protected]>Signed-off-by Yu Zhang <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
RE: [PATCH v5 5/5] iommu/hyperv: Add page-selective IOTLB flush support
In reply to Yu ZhangFrom: Yu Zhang <[email protected]> Sent: Friday, September 4, 2026 12:55 AM
Quoted 12 lines
Add page-selective IOTLB flush using
HVCALL_FLUSH_DEVICE_DOMAIN_LIST. This hypercall accepts a list of (page_number,page_mask_shift) entries, enabling finer-grained IOTLB invalidation compared to the domain-wideHVCALL_FLUSH_DEVICE_DOMAINused byhv_iommu_flush_iotlb_all().
hv_iommu_calc_flush_range()computes the smallest power-of-two aligned range that covers the target IOVA region, producing a single flush descriptor. This may over-flush when the range is not naturally aligned, matching the approach used by Intel VT-d PSI. If the page-selective flush fails, the code falls back to a full domain flush.
Quoted 3 lines
Signed-off-by Easwar Hariharan <[email protected]>Signed-off-by Yu Zhang <[email protected]>Reviewed-by Jacob Pan <[email protected]>
Quoted 148 lines
--- drivers/iommu/hyperv/hv-iommu-guest.c | 74 ++++++++++++++++++++++++++- include/hyperv/hvgdk_mini.h | 1 + include/hyperv/hvhdk_mini.h | 18 +++++++ 3 files changed, 92 insertions(+), 1 deletion(-)drivers/iommu/hyperv/hv- renamed from drivers/iommu/hyperv/hv-iommu-guest.c +0
-0
iommu-guest.c
index137f232d74fe..13eb85b4a424100644drivers/iommu/hyperv/hv-iommu-guest.c +73
-1@@ -384,11 +384,82 @@ static void hv_iommu_flush_iotlb_all(struct iommu_domain *domain)hv_flush_device_domain (to_hv_iommu_domain (domain)); } +/* +* Calculate the minimal power-of-two aligned range that covers [start, end] +* (end is inclusive). Returns a single (page_number, page_mask_shift) +* descriptor that may over-flush when the range is not naturally aligned. +*/ +static void +hv_iommu_calc_flush_range (unsigned long start,unsigned long end, +union hv_iommu_flush_va *va) +{ +unsigned long aligned_start; +unsigned int sz_lg2; + + sz_lg2 =max (fls_long (start ^ end),HV_HYP_PAGE_SHIFT ); + +/* +* A valid IOVA range shall not span bit 63. Use the maximum mask +* so the host can safely perform a full flush. +*/ +if (WARN_ON_ONCE (sz_lg2 ==BITS_PER_LONG )) + aligned_start =0 ; +else + aligned_start = + start &GENMASK (BITS_PER_LONG -1 , sz_lg2); + + va->page_number = aligned_start >>HV_HYP_PAGE_SHIFT ; + va->page_mask_shift = sz_lg2 -HV_HYP_PAGE_SHIFT ; +} + +static void hv_flush_device_domain_list (struct hv_iommu_domain *hv_domain, +struct iommu_iotlb_gather *iotlb_gather) +{ +u64 status; +unsigned long flags; +struct hv_input_flush_device_domain_list *input; + +local_irq_save (flags); + + input = *this_cpu_ptr (hyperv_pcpu_input_arg); +/* Clear the fixed header and the single range entry. */ +memset (input,0 ,struct_size (input, iova_list,1 )); + + input->device_domain = hv_domain->device_domain; + input->flags |=HV_FLUSH_DEVICE_DOMAIN_LIST_IOMMU_FORMAT ; +hv_iommu_calc_flush_range (iotlb_gather->start, iotlb_gather->end, + &input->iova_list[0 ]); + + status =hv_do_rep_hypercall (HVCALL_FLUSH_DEVICE_DOMAIN_LIST , +1 ,0 , input,NULL ); + +if (WARN_ONCE (!hv_result_success (status), +"HVCALL_FLUSH_DEVICE_DOMAIN_LIST failed: %#llx (%s)\n" , + status,hv_result_to_string (status))) { +/* Page-selective flush failed, fall back to full flush. */ +struct hv_input_flush_device_domain *flush_all = (void *)input; + +memset (flush_all,0 ,sizeof (*flush_all)); + flush_all->device_domain = hv_domain->device_domain; + status =hv_do_hypercall (HVCALL_FLUSH_DEVICE_DOMAIN , + flush_all,NULL ); +WARN (!hv_result_success (status), +"HVCALL_FLUSH_DEVICE_DOMAIN fallback also failed: %#llx (%s)\n" , + status,hv_result_to_string (status)); + } + +local_irq_restore (flags); +} +static void hv_iommu_iotlb_sync (struct iommu_domain *domain,struct iommu_iotlb_gather *iotlb_gather) { -hv_flush_device_domain (to_hv_iommu_domain (domain)); +hv_flush_device_domain_list (to_hv_iommu_domain (domain), iotlb_gather); +/* +* The hypercall also invalidates non-leaf page-walk caches, so +* detached page-table pages can now be freed. +*/ iommu_put_pages_list (&iotlb_gather->freelist); }@@ -440,6 +511,7 @@ static struct iommu_domain *hv_iommu_domain_alloc_paging(struct device *dev) cfg.common.hw_max_vasz_lg2 = hv_iommu_device->max_iova_width; cfg.common.hw_max_oasz_lg2 =52 ; + cfg.common.features |=BIT (PT_FEAT_FLUSH_RANGE );/* * Hyper-V S1 domains use a 4-level root for IOVA widths up to drivers/iommu/hyperv/hv-iommu-guest.c +0
-0* 48 bits. A 5-level root is used only for wider apertures when include/hyperv/hvgdk_mini.h +0
-0@@ -497,6 +497,7 @@ union hv_vp_assist_msr_contents { /*
HV_REGISTER_VP_ASSIST_PAGE*/
#defineHVCALL_GET_GPA_PAGES_ACCESS_STATES0x00c9
#defineHVCALL_CONFIGURE_DEVICE_DOMAIN0x00ce
#defineHVCALL_FLUSH_DEVICE_DOMAIN0x00d0include/hyperv/hvgdk_mini.h +1
-0+#define HVCALL_FLUSH_DEVICE_DOMAIN_LIST 0x00d1#define HVCALL_ACQUIRE_SPARSE_SPA_PAGE_HOST_ACCESS 0x00d7#define HVCALL_RELEASE_SPARSE_SPA_PAGE_HOST_ACCESS 0x00d8#define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00dbinclude/hyperv/hvhdk_mini.h +18
-1@@ -685,4 +685,22 @@ struct hv_input_flush_device_domain { u32 reserved; } __packed; +union hv_iommu_flush_va {/* HV_IOMMU_GVA_RANGE */ +u64 as_uint64; +struct { +u64 page_mask_shift :6 ; +u64 reserved :6 ; +u64 page_number :52 ; + }; +} __packed; + +/* HV_INPUT_FLUSH_DEVICE_DOMAIN_LIST */ +struct hv_input_flush_device_domain_list { +struct hv_input_device_domain device_domain; +#define HV_FLUSH_DEVICE_DOMAIN_LIST_IOMMU_FORMAT BIT(0) +u32 flags; +u32 reserved; +union hv_iommu_flush_va iova_list[]; +} __packed; +#endif /* _HV_HVHDK_MINI_H */ --2.52.0
Re: [PATCH v5 5/5] iommu/hyperv: Add page-selective IOTLB flush support
In reply to Yu ZhangQuoted 5 lines · Yu Zhang
Add page-selective IOTLB flush using
HVCALL_FLUSH_DEVICE_DOMAIN_LIST. This hypercall accepts a list of (page_number,page_mask_shift) entries, enabling finer-grained IOTLB invalidation compared to the domain-wideHVCALL_FLUSH_DEVICE_DOMAINused byhv_iommu_flush_iotlb_all().
Quoted 7 lines
hv_iommu_calc_flush_range()computes the smallest power-of-two aligned range that covers the target IOVA region, producing a single flush descriptor. This may over-flush when the range is not naturally aligned, matching the approach used by Intel VT-d PSI. If the page-selective flush fails, the code falls back to a full domain flush.[...]
Signature · 1 line
Jason
Hi Jason, Joerg,
Do you have any further comments on this version, particularly any remaining issues that would warrant a respin before the series can be considered for inclusion? Thanks a lot!
B.R.
Yu
Quoted 234 lines
This patch series introduces a para-virtualized IOMMU driver for Linux guests running on Microsoft Hyper-V. The driver enables two primary use cases:
1) In-kernel DMA protection for devices assigned to the guest.
2) Device assignment to guest user space (e.g., via VFIO).The driver implements the following core functionality:
* Hypercall-based Enumeration
Unlike traditional ACPI-based discovery (e.g., DMAR/IVRS), this driver enumerates the Hyper-V IOMMU capabilities directly via hypercalls. This approach allows the guest to discover IOMMU presence and features without requiring specific virtual firmware extensions or modifications.* Domain Management
The driver manages IOMMU domains through a new set of Hyper-V hypercall interfaces, handling domain allocation and attachment for endpoint devices.* Nested Translation Support
This implementation leverages guest-managed stage-1 I/O page tables nested with host stage-2 translations. It is built upon the consolidated IOMMU page table framework (IOMMU_PT). This design eliminates the need for emulating map operations. Both Intel VT-d and AMD IOMMU platforms are supported.* IOTLB Invalidation
IOTLB invalidation requests are marshaled and issued to the hypervisor through the same hypercall mechanism. Both domain- selective and page-selective flushes are supported.Implementation Notes:
* Platform Support
The current implementation targets x86 platforms with Intel VT-d and AMD IOMMU hardware.* MSI Region Handling
The standard x86 MSI interrupt range
(0xfee00000-0xfeefffff) is reserved from normal IOVA mappings. Future updates may allow this configuration to be queried via hypercalls if new hardware platforms are to be supported.* Reserved Regions (RMRR)
There is currently no requirement to support assigned devices with ACPI RMRR limitations. Consequently, this patch series does not specify or query reserved memory regions.* Guest Hibernation
Guest hibernation and resume are not supported by this initial implementation. The current pvIOMMU interface does not define how Hyper-V device-domain objects and device attachments are restored.Testing:
Validated with the following configurations:
- NVMe devices assigned to the guest on AMD platforms, tested with fio.
- Intel DSA devices assigned to the guest, tested with dmatest.
-dma_map_benchmarkfor DMA mapping performance evaluation.Changelog:
v4[1] -> v5:
- Added Michael Kelley's Reviewed-by tags for patch 1/2/3/4.- hv: logical device ID registry:
- Used four-digit hexadecimal values to print PCI domain numbers.
- Included the PCI domain number in the unregister failure warning.- iommu/hyperv: para-virtualized IOMMU:
- Removed the unused per-device endpoint structure, allocation, private pointer, andrelease_device()callback.
- Clarified the logical device ID lookup failure message.
- Read the ATS capability from the IOMMU associated with the domain instead of the global IOMMU pointer.- iommu/hyperv: page-selective IOTLB flush:
- Unified normal and full-range descriptor construction around the aligned range start.
- Usedmax()to express the minimum Hyper-V page granularity.
- Reported Hyper-V status values in warnings when the flush fails.v3[2] -> v4:
- Added Jacob Pan's Reviewed-by tag for patch 1/4/5.- hyperv: hypercall interfaces:
- Added the authoritative Hyper-V type names to imported definitions.
- AddedHV_STATUS_DEVICE_ALREADY_IN_DOMAINand mapped it to-EEXIST.- hv: logical device ID registry:
- Made the registry independent ofCONFIG_HYPERV_PVIOMMU.
- Renamed the APIs tohv_pci_xxx_dev_id(),
- Reworked initialization and error cleanup to propagate failures.
- Return-EEXISTwith a warning for duplicate registration.- iommu/x86: architectural MSI reserved region:
- Replaced the exported range constants withiommu_alloc_resv_x86_msi_region().- iommu/hyperv: para-virtualized IOMMU:
- AcceptedHV_STATUS_DEVICE_ALREADY_IN_DOMAINas a successful attach, and removed the blocking-domain-specific duplicate check.
- Removed the redundant ATS disable fromrelease_device(); ATS is disabled when attaching the release domain.- iommu/hyperv: page-selective IOTLB flush:
- Removed the redundant include oflinux/hyperv.h.
- Documented that the list flush also invalidates non-leaf page-walk caches before detached page-table pages are freed.v2[3] -> v3:
- Added a separate patch defining the common x86 architectural MSI reserved range and converted the Intel, AMD, and Hyper-V IOMMU drivers to use it.- hyperv: hypercall interfaces:
- UsedBIT_ULL()for 64-bit capability flags.
- Matched the create-device-domain input layout to the 32-byte Hyper-V ABI.
- Corrected the page-selective flush range layout to 6/6/52 bits.- hv: logical device ID registry:
- Replaced the linear list with an rhashtable for the sparse PCI domain number mapping.
- Used RCU-protected lookup and deferred freeing on removal.
- Simplified the registration and cleanup paths.- iommu/hyperv: para-virtualized IOMMU:
- Renamed the guest driver source tohv-iommu-guest.c.
- Enabled ATS only after a device-domain attachment succeeds, and disabled ATS before attaching the blocking domain.
- Removed the obsolete deferred-flush capability, unused geometry, and redundant device-private-data clearing.
- Made the Hyper-V domain settings explicit at each caller instead of deriving them from the Linux domain type.
- Added transactional create/configure domain handling with rollback.
- Required only the base page size and masked the domain page-size bitmap with the Hyper-V-supported bitmap.
- Silenced detection for unsupported hosts while retaining errors for actual hypercall and capability failures.
- ClarifiedKconfigsupport for assigned PCI devices and documented the lack of guest hibernation/resume support.- iommu/hyperv: page-selective IOTLB flush:
- Removed the inclusive-end overflow and kept the range calculation in byte addresses until the final page conversion.
- Cleared both the fixed hypercall header and the range entry.
- Warned on selective-flush failure before falling back to a full-domain flush.v1[4] -> v2:
- Dropped the "move to subdirectory" patch; the directory now exists upstream.- hv: logical device ID registry:
- Moved the registry tohv_common.cso it can be shared, and derived the prefix via a shared helper instead of caching it in pci-hyperv's private struct.
- Moved the lookup out of the irq-disabled region (PREEMPT_RT).- iommu/hyperv: para-virtualized IOMMU:
- Removed the unuseddetach_devop.
- Rejected a hypervisor not advertising x86 page sizes instead of masking and warning.
- Statically initialized the identity and blocking domains.
- Gave the blocking domain its own attach op, which returns the hypercall status and WARNs on failure.- iommu/hyperv: page-selective IOTLB flush:
- Used a single descriptor covering a slightly larger power-of-two range, instead of splitting the range into multiple descriptors.
- Fixed the inclusive-end corner case in the flush range calculation.RFC v1[5] -> v1[4]:
- Scoped platform support to x86 only (Intel VT-d and AMD IOMMU); initialization now uses x86_init.iommu.iommu_init
- Added page-selective IOTLB flush support
- Disable device ATS inhv_iommu_release_device()
- Addressed review comments from Michael Kelley:
- Reversed dependency: pvIOMMU exports registration API for pci-hyperv to call, instead of pci-hyperv exportinghv_build_logical_dev_id()
- Dropped separate output page allocation patch; hypercall input and output now share the same per-CPU page
- Cleaned upKconfig(removedPCI_HYPERVdependency, unnecessary selects)
- Removeddev_list, per-domain spinlock, andsyscore_ops
- Removed forward declarations by reordering functions
- Fixed typos, cleaned upKconfigselects, improvedpr_infomessages, etc.[1] v4:
https://lore.kernel.org/linux-hyperv/[email protected]/
[2] v3:
https://lore.kernel.org/linux-hyperv/[email protected]/
[3] v2:
https://lore.kernel.org/linux-hyperv/[email protected]/
[4] v1:
https://lore.kernel.org/linux-hyperv/[email protected]/
[5] RFC v1:
https://lore.kernel.org/linux-hyperv/[email protected]/Wei Liu (1):
hyperv: Introduce new hypercall interfaces used by Hyper-V guest IOMMUYu Zhang (4):
Drivers: hv: Add logical device ID registry for vPCI devices iommu/x86: Add architectural MSI reserved region helper iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest iommu/hyperv: Add page-selective IOTLB flush supportarch/x86/hyperv/hv_init.c | 4 + arch/x86/include/asm/iommu.h | 14 + arch/x86/include/asm/mshyperv.h | 4 + drivers/hv/hv_common.c | 115 +++++ drivers/iommu/Kconfig | 1 + drivers/iommu/amd/iommu.c | 6 +- drivers/iommu/hyperv/Kconfig | 16 + drivers/iommu/hyperv/Makefile | 1 + drivers/iommu/hyperv/hv-iommu-guest.c | 679 ++++++++++++++++++++++++++ drivers/iommu/hyperv/iommu.h | 44 ++ drivers/iommu/intel/iommu.c | 6 +- drivers/pci/controller/pci-hyperv.c | 21 +- include/asm-generic/mshyperv.h | 4 + include/hyperv/hvgdk_mini.h | 10 + include/hyperv/hvhdk_mini.h | 155 ++++++ include/linux/hyperv.h | 8 + 16 files changed, 1073 insertions(+), 15 deletions(-) create mode 100644 drivers/iommu/hyperv/Kconfig create mode 100644 drivers/iommu/hyperv/hv-iommu-guest.c create mode 100644 drivers/iommu/hyperv/iommu.hSignature · 1 line
2.52.0
On Mon, Sep 07, 2026 at 04:48:23PM +0800, Yu Zhang wrote:
Hi Joerg, Jason,
A gentle ping on this series. Could you let me know whether it is ready to be picked up, or whether any further changes or acks are needed? Thanks a lot!
B.R.
Yu
Quoted 245 lines
Hi Jason, Joerg,
Do you have any further comments on this version, particularly any remaining issues that would warrant a respin before the series can be considered for inclusion? Thanks a lot!
B.R.
YuQuoted 234 lines
This patch series introduces a para-virtualized IOMMU driver for Linux guests running on Microsoft Hyper-V. The driver enables two primary use cases:
1) In-kernel DMA protection for devices assigned to the guest.
2) Device assignment to guest user space (e.g., via VFIO).The driver implements the following core functionality:
* Hypercall-based Enumeration
Unlike traditional ACPI-based discovery (e.g., DMAR/IVRS), this driver enumerates the Hyper-V IOMMU capabilities directly via hypercalls. This approach allows the guest to discover IOMMU presence and features without requiring specific virtual firmware extensions or modifications.* Domain Management
The driver manages IOMMU domains through a new set of Hyper-V hypercall interfaces, handling domain allocation and attachment for endpoint devices.* Nested Translation Support
This implementation leverages guest-managed stage-1 I/O page tables nested with host stage-2 translations. It is built upon the consolidated IOMMU page table framework (IOMMU_PT). This design eliminates the need for emulating map operations. Both Intel VT-d and AMD IOMMU platforms are supported.* IOTLB Invalidation
IOTLB invalidation requests are marshaled and issued to the hypervisor through the same hypercall mechanism. Both domain- selective and page-selective flushes are supported.Implementation Notes:
* Platform Support
The current implementation targets x86 platforms with Intel VT-d and AMD IOMMU hardware.* MSI Region Handling
The standard x86 MSI interrupt range
(0xfee00000-0xfeefffff) is reserved from normal IOVA mappings. Future updates may allow this configuration to be queried via hypercalls if new hardware platforms are to be supported.* Reserved Regions (RMRR)
There is currently no requirement to support assigned devices with ACPI RMRR limitations. Consequently, this patch series does not specify or query reserved memory regions.* Guest Hibernation
Guest hibernation and resume are not supported by this initial implementation. The current pvIOMMU interface does not define how Hyper-V device-domain objects and device attachments are restored.Testing:
Validated with the following configurations:
- NVMe devices assigned to the guest on AMD platforms, tested with fio.
- Intel DSA devices assigned to the guest, tested with dmatest.
-dma_map_benchmarkfor DMA mapping performance evaluation.Changelog:
v4[1] -> v5:
- Added Michael Kelley's Reviewed-by tags for patch 1/2/3/4.- hv: logical device ID registry:
- Used four-digit hexadecimal values to print PCI domain numbers.
- Included the PCI domain number in the unregister failure warning.- iommu/hyperv: para-virtualized IOMMU:
- Removed the unused per-device endpoint structure, allocation, private pointer, andrelease_device()callback.
- Clarified the logical device ID lookup failure message.
- Read the ATS capability from the IOMMU associated with the domain instead of the global IOMMU pointer.- iommu/hyperv: page-selective IOTLB flush:
- Unified normal and full-range descriptor construction around the aligned range start.
- Usedmax()to express the minimum Hyper-V page granularity.
- Reported Hyper-V status values in warnings when the flush fails.v3[2] -> v4:
- Added Jacob Pan's Reviewed-by tag for patch 1/4/5.- hyperv: hypercall interfaces:
- Added the authoritative Hyper-V type names to imported definitions.
- AddedHV_STATUS_DEVICE_ALREADY_IN_DOMAINand mapped it to-EEXIST.- hv: logical device ID registry:
- Made the registry independent ofCONFIG_HYPERV_PVIOMMU.
- Renamed the APIs tohv_pci_xxx_dev_id(),
- Reworked initialization and error cleanup to propagate failures.
- Return-EEXISTwith a warning for duplicate registration.- iommu/x86: architectural MSI reserved region:
- Replaced the exported range constants withiommu_alloc_resv_x86_msi_region().- iommu/hyperv: para-virtualized IOMMU:
- AcceptedHV_STATUS_DEVICE_ALREADY_IN_DOMAINas a successful attach, and removed the blocking-domain-specific duplicate check.
- Removed the redundant ATS disable fromrelease_device(); ATS is disabled when attaching the release domain.- iommu/hyperv: page-selective IOTLB flush:
- Removed the redundant include oflinux/hyperv.h.
- Documented that the list flush also invalidates non-leaf page-walk caches before detached page-table pages are freed.v2[3] -> v3:
- Added a separate patch defining the common x86 architectural MSI reserved range and converted the Intel, AMD, and Hyper-V IOMMU drivers to use it.- hyperv: hypercall interfaces:
- UsedBIT_ULL()for 64-bit capability flags.
- Matched the create-device-domain input layout to the 32-byte Hyper-V ABI.
- Corrected the page-selective flush range layout to 6/6/52 bits.- hv: logical device ID registry:
- Replaced the linear list with an rhashtable for the sparse PCI domain number mapping.
- Used RCU-protected lookup and deferred freeing on removal.
- Simplified the registration and cleanup paths.- iommu/hyperv: para-virtualized IOMMU:
- Renamed the guest driver source tohv-iommu-guest.c.
- Enabled ATS only after a device-domain attachment succeeds, and disabled ATS before attaching the blocking domain.
- Removed the obsolete deferred-flush capability, unused geometry, and redundant device-private-data clearing.
- Made the Hyper-V domain settings explicit at each caller instead of deriving them from the Linux domain type.
- Added transactional create/configure domain handling with rollback.
- Required only the base page size and masked the domain page-size bitmap with the Hyper-V-supported bitmap.
- Silenced detection for unsupported hosts while retaining errors for actual hypercall and capability failures.
- ClarifiedKconfigsupport for assigned PCI devices and documented the lack of guest hibernation/resume support.- iommu/hyperv: page-selective IOTLB flush:
- Removed the inclusive-end overflow and kept the range calculation in byte addresses until the final page conversion.
- Cleared both the fixed hypercall header and the range entry.
- Warned on selective-flush failure before falling back to a full-domain flush.v1[4] -> v2:
- Dropped the "move to subdirectory" patch; the directory now exists upstream.- hv: logical device ID registry:
- Moved the registry tohv_common.cso it can be shared, and derived the prefix via a shared helper instead of caching it in pci-hyperv's private struct.
- Moved the lookup out of the irq-disabled region (PREEMPT_RT).- iommu/hyperv: para-virtualized IOMMU:
- Removed the unuseddetach_devop.
- Rejected a hypervisor not advertising x86 page sizes instead of masking and warning.
- Statically initialized the identity and blocking domains.
- Gave the blocking domain its own attach op, which returns the hypercall status and WARNs on failure.- iommu/hyperv: page-selective IOTLB flush:
- Used a single descriptor covering a slightly larger power-of-two range, instead of splitting the range into multiple descriptors.
- Fixed the inclusive-end corner case in the flush range calculation.RFC v1[5] -> v1[4]:
- Scoped platform support to x86 only (Intel VT-d and AMD IOMMU); initialization now uses x86_init.iommu.iommu_init
- Added page-selective IOTLB flush support
- Disable device ATS inhv_iommu_release_device()
- Addressed review comments from Michael Kelley:
- Reversed dependency: pvIOMMU exports registration API for pci-hyperv to call, instead of pci-hyperv exportinghv_build_logical_dev_id()
- Dropped separate output page allocation patch; hypercall input and output now share the same per-CPU page
- Cleaned upKconfig(removedPCI_HYPERVdependency, unnecessary selects)
- Removeddev_list, per-domain spinlock, andsyscore_ops
- Removed forward declarations by reordering functions
- Fixed typos, cleaned upKconfigselects, improvedpr_infomessages, etc.[1] v4:
https://lore.kernel.org/linux-hyperv/[email protected]/
[2] v3:
https://lore.kernel.org/linux-hyperv/[email protected]/
[3] v2:
https://lore.kernel.org/linux-hyperv/[email protected]/
[4] v1:
https://lore.kernel.org/linux-hyperv/[email protected]/
[5] RFC v1:
https://lore.kernel.org/linux-hyperv/[email protected]/Wei Liu (1):
hyperv: Introduce new hypercall interfaces used by Hyper-V guest IOMMUYu Zhang (4):
Drivers: hv: Add logical device ID registry for vPCI devices iommu/x86: Add architectural MSI reserved region helper iommu/hyperv: Add para-virtualized IOMMU support for Hyper-V guest iommu/hyperv: Add page-selective IOTLB flush supportarch/x86/hyperv/hv_init.c | 4 + arch/x86/include/asm/iommu.h | 14 + arch/x86/include/asm/mshyperv.h | 4 + drivers/hv/hv_common.c | 115 +++++ drivers/iommu/Kconfig | 1 + drivers/iommu/amd/iommu.c | 6 +- drivers/iommu/hyperv/Kconfig | 16 + drivers/iommu/hyperv/Makefile | 1 + drivers/iommu/hyperv/hv-iommu-guest.c | 679 ++++++++++++++++++++++++++ drivers/iommu/hyperv/iommu.h | 44 ++ drivers/iommu/intel/iommu.c | 6 +- drivers/pci/controller/pci-hyperv.c | 21 +- include/asm-generic/mshyperv.h | 4 + include/hyperv/hvgdk_mini.h | 10 + include/hyperv/hvhdk_mini.h | 155 ++++++ include/linux/hyperv.h | 8 + 16 files changed, 1073 insertions(+), 15 deletions(-) create mode 100644 drivers/iommu/hyperv/Kconfig create mode 100644 drivers/iommu/hyperv/hv-iommu-guest.c create mode 100644 drivers/iommu/hyperv/iommu.hSignature · 1 line
2.52.0