Hi, Based on Joao's suggestion, the iommufd nesting prerequisite series [1] is further splitted to host IOMMU device abstract part [2] and vIOMMU check part. This series implements the 2nd part.
1st part implements get_host_iommu_info() callback which vIOMMU can call to get host IOMMU info. For legacy VFIO or VDPA device, aw_bits is provided; for IOMMUFD backed device, IOMMUFD uAPI provides detailed cap/ecap bits from host. vIOMMU implements set/unset_iommu_device() callback to get HostIOMMUDevice and call get_host_iommu_info(). So vIOMMU can do compatibility check with the return host IOMMU info. This is also a prerequisite for incoming iommufd nesting series: 'intel_iommu: Enable stage-1 translation' where HostIOMMUDevice provides more data such as iommufd/devid/ioas_id and callback attach/detach_hwpt() for vIOMMU to create nested hwpt, attaching/detaching hwpt, etc. The major change of this version is dropping the cap/ecap update logic based on MST's suggestion. We can add property for any cap/ecap bit when necessary just like "aw-bits". This way we don't need to concern about migration compatibility and code is cleaner. Qemu code can be found at: https://github.com/yiliu1765/qemu/tree/zhenzhong/iommufd_nesting_preq_part2_v2 [1] https://lore.kernel.org/qemu-devel/20240201072818.327930-1-zhenzhong.d...@intel.com/ [2] https://lists.gnu.org/archive/html/qemu-devel/2024-04/msg00763.html Thanks Zhenzhong Changelog: v2: - drop cap/ecap update logic (MST) - check aw-bits from get_host_iommu_info() in legacy mode v1: - convert HostIOMMUDevice to sub object pointer in vtd_check_hdev rfcv2: - introduce common abstract HostIOMMUDevice and sub struct for different BEs (Eric, Cédric) - remove iommufd_device.[ch] (Cédric) - remove duplicate iommufd/devid define from VFIODevice (Eric) - drop the p in aliased_pbus and aliased_pdevfn (Eric) - assert devfn and iommu_bus in pci_device_get_iommu_bus_devfn (Cédric, Eric) - use errp in iommufd_device_get_info (Eric) - split and simplify cap/ecap check/sync code in intel_iommu.c (Cédric) - move VTDHostIOMMUDevice declaration to intel_iommu_internal.h (Cédric) - make '(vtd->cap_reg >> 16) & 0x3fULL' a MACRO and add missed '+1' (Cédric) - block migration if vIOMMU cap/ecap updated based on host IOMMU cap/ecap - add R-B Yi Liu (2): intel_iommu: Implement set/unset_iommu_device() callback intel_iommu: Add a framework to do compatibility check with host IOMMU cap/ecap Zhenzhong Duan (3): intel_iommu: Extract out vtd_cap_init() to initialize cap/ecap intel_iommu: Check for compatibility with legacy device intel_iommu: Check for compatibility with iommufd backed device hw/i386/intel_iommu_internal.h | 8 ++ include/hw/i386/intel_iommu.h | 3 + hw/i386/intel_iommu.c | 242 +++++++++++++++++++++++++++------ 3 files changed, 211 insertions(+), 42 deletions(-) -- 2.34.1