[PATCH v2 00/10] Add a host IOMMU device abstraction

Zhenzhong Duan posted 10 patches 3 weeks, 1 day ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20240408081230.1030078-1-zhenzhong.duan@intel.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Yi Liu <yi.l.liu@intel.com>, Eric Auger <eric.auger@redhat.com>, Zhenzhong Duan <zhenzhong.duan@intel.com>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Alex Williamson <alex.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>
MAINTAINERS                        |  2 +
include/hw/pci/pci.h               | 40 +++++++++++++-
include/hw/vfio/vfio-common.h      | 23 ++++++++
include/sysemu/host_iommu_device.h | 29 ++++++++++
include/sysemu/iommufd.h           | 33 ++++++++++++
backends/host_iommu_device.c       | 19 +++++++
backends/iommufd.c                 | 85 ++++++++++++++++++++++++------
hw/pci/pci.c                       | 75 ++++++++++++++++++++++++--
hw/vfio/container.c                | 40 +++++++++++++-
hw/vfio/iommufd.c                  | 19 ++++++-
hw/vfio/pci.c                      | 20 +++++--
backends/Kconfig                   |  5 ++
backends/meson.build               |  1 +
13 files changed, 364 insertions(+), 27 deletions(-)
create mode 100644 include/sysemu/host_iommu_device.h
create mode 100644 backends/host_iommu_device.c
[PATCH v2 00/10] Add a host IOMMU device abstraction
Posted by Zhenzhong Duan 3 weeks, 1 day ago
Based on Joao's suggestion, the iommufd nesting prerequisite series [1]
is further splitted to host IOMMU device abstract part and vIOMMU
check part. This series implements the 1st part.

This split also faciliates the dirty tracking series [2] and virtio-iommu
series [3] to depend on 1st part.

The major change in this version is to use QOM, the class tree is as below:

                        HostIOMMUDevice
                               | .get_host_iommu_info()
                               |
                               |
            .------------------------------------.
            |                  |                 |
      HIODLegacyVFIO    [HIODLegacyVDPA]    HIODIOMMUFD
            | .vdev            | [.vdev]         | .iommufd
                                                 | .devid
                                                 | [.ioas_id]
                                                 | [.attach_hwpt()]
                                                 | [.detach_hwpt()]
                                                 |
                                    .----------------------.
                                    |                      |
                           HIODIOMMUFDVFIO         [HIODIOMMUFDVDPA]
                                    | .vdev                | [.vdev]

* The classes in [] will be implemented in future.
* .ioas_id, .attach/detach_hwpt() will be implemented in nesting series.
* .vdev in different class points to different agent device,
* i.e., for VFIO it points to VFIODevice.

PATCH1-4: Introduce HostIOMMUDevice and its sub classes
PATCH5-7: Implement get_host_iommu_info() callback
PATCH8-10: Create HostIOMMUDevice instance and pass to vIOMMU

Qemu code can be found at:
https://github.com/yiliu1765/qemu/tree/zhenzhong/iommufd_nesting_preq_part1_v2

[1] https://lore.kernel.org/qemu-devel/20240201072818.327930-1-zhenzhong.duan@intel.com/
[2] https://lore.kernel.org/qemu-devel/20240212135643.5858-1-joao.m.martins@oracle.com/
[3] https://lore.kernel.org/qemu-devel/20240117080414.316890-1-eric.auger@redhat.com/

Thanks
Zhenzhong

Changelog:
v2:
- use QOM to abstract host IOMMU device and its sub-classes (Cédric)
- move host IOMMU device creation in attach_device() (Cédric)
- refine pci_device_set/unset_iommu_device doc futher (Eric)
- define host IOMMU info format of different backend
- implement get_host_iommu_info() for different backend (Cédric)

v1:
- use HostIOMMUDevice handle instead of union in VFIODevice (Eric)
- change host_iommu_device_init to host_iommu_device_create
- allocate HostIOMMUDevice in host_iommu_device_create callback
  and set the VFIODevice base_hdev handle (Eric)
- refine pci_device_set/unset_iommu_device doc (Eric)
- use HostIOMMUDevice handle instead of union in VTDHostIOMMUDevice (Eric)

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 (1):
  hw/pci: Introduce pci_device_set/unset_iommu_device()

Zhenzhong Duan (9):
  backends: Introduce abstract HostIOMMUDevice
  vfio: Introduce HIODLegacyVFIO device
  backends/iommufd: Introduce abstract HIODIOMMUFD device
  vfio/iommufd: Introduce HIODIOMMUFDVFIO device
  vfio: Implement get_host_iommu_info() callback
  backends/iommufd: Introduce helper function
    iommufd_backend_get_device_info()
  backends/iommufd: Implement get_host_iommu_info() callback
  vfio: Create host IOMMU device instance
  vfio: Pass HostIOMMUDevice to vIOMMU

 MAINTAINERS                        |  2 +
 include/hw/pci/pci.h               | 40 +++++++++++++-
 include/hw/vfio/vfio-common.h      | 23 ++++++++
 include/sysemu/host_iommu_device.h | 29 ++++++++++
 include/sysemu/iommufd.h           | 33 ++++++++++++
 backends/host_iommu_device.c       | 19 +++++++
 backends/iommufd.c                 | 85 ++++++++++++++++++++++++------
 hw/pci/pci.c                       | 75 ++++++++++++++++++++++++--
 hw/vfio/container.c                | 40 +++++++++++++-
 hw/vfio/iommufd.c                  | 19 ++++++-
 hw/vfio/pci.c                      | 20 +++++--
 backends/Kconfig                   |  5 ++
 backends/meson.build               |  1 +
 13 files changed, 364 insertions(+), 27 deletions(-)
 create mode 100644 include/sysemu/host_iommu_device.h
 create mode 100644 backends/host_iommu_device.c

-- 
2.34.1