qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 00/12] hw/iommufd: IOMMUFD Dirty Tracking
@ 2024-07-12 11:46 Joao Martins
  2024-07-12 11:46 ` [PATCH v4 01/12] vfio/pci: Extract mdev check into an helper Joao Martins
                   ` (12 more replies)
  0 siblings, 13 replies; 82+ messages in thread
From: Joao Martins @ 2024-07-12 11:46 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yi Liu, Eric Auger, Zhenzhong Duan, Alex Williamson,
	Cedric Le Goater, Jason Gunthorpe, Avihai Horon, Joao Martins

This small series adds support for IOMMU dirty tracking support via the
IOMMUFD backend. The hardware capability is available on most recent x86
hardware. The series is divided organized as follows:

* Patch 1-2: Fixes a regression into mdev support with IOMMUFD. This
             one is independent of the series but happened to cross it
             while testing mdev with this series

* Patch 3: Adds a support to iommufd_get_device_info() for capabilities

* Patches 4 - 10: IOMMUFD backend support for dirty tracking;

Introduce auto domains -- Patch 5 goes into more detail, but the gist is that
we will find and attach a device to a compatible IOMMU domain, or allocate a new
hardware pagetable *or* rely on kernel IOAS attach (for mdevs). Afterwards the
workflow is relatively simple:

1) Probe device and allow dirty tracking in the HWPT
2) Toggling dirty tracking on/off
3) Read-and-clear of Dirty IOVAs

The heuristics selected for (1) were to always request the HWPT for
dirty tracking if supported, or rely on device dirty page tracking. This
is a little simplistic and we aren't necessarily utilizing IOMMU dirty
tracking even if we ask during hwpt allocation.

The unmap case is deferred until further vIOMMU support with migration
is added[3] which will then introduce the usage of
IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR in GET_DIRTY_BITMAP ioctl in the
dma unmap bitmap flow.

* Patches 11-12: Don't block live migration where there's no VF dirty
tracker, considering that we have IOMMU dirty tracking.

Comments and feedback appreciated. Thanks for all the review thus far!

Cheers,
    Joao

P.S. Suggest linux-next (or future v6.11) as hypervisor kernel as there's
some bugs fixed there with regards to IOMMU hugepage dirty tracking.

Changes since v3[5]:
* Skip HostIOMMUDevice::realize for mdev, and introduce a helper to check if the VFIO
  device is mdev. (Zhenzhong)
* Skip setting IOMMU device for mdev (Zhenzhong)
* Add Zhenzhong review tag in patch 3
* Utilize vbasedev::bcontainer::dirty_pages_supported instead of introducing
  a new HostIOMMUDevice capability and thus remove the cap patch from the series (Zhenzhong)
* Move the HostIOMMUDevice::realize() to be part of VFIODevice initialization in attach_device()
while skipping it all together for mdev. (Cedric)
* Due to the previous item, had to remove aw_bits because it depends on device attach being
finished, instead defer it to when get_cap() gets called.
* Skip auto domains for mdev instead of purposedly erroring out (Zhenzhong)
* Pass errp in all cases, and instead just free the error in case of -EINVAL
  in most of all patches, and also pass Error* in iommufd_backend_alloc_hwpt() amd
  set/query dirty. This is made better thanks in part to skipping auto domains for mdev (Cedric)

Changes since RFCv2[4]:
* Always allocate hwpt with IOMMU_HWPT_ALLOC_DIRTY_TRACKING even if
we end up not actually toggling dirty tracking. (Avihai)
* Fix error handling widely in auto domains logic and all patches (Avihai)
* Reuse iommufd_backend_get_device_info() for capabilities (Zhenzhong)
* New patches 1 and 2 taking into consideration previous comments.
* Store hwpt::flags to know if we have dirty tracking (Avihai)
* New patch 8, that allows to query dirty tracking support after
provisioning. This is a cleaner way to check IOMMU dirty tracking support
when vfio::migration is iniitalized, as opposed to RFCv2 via device caps.
device caps way is still used because at vfio attach we aren't yet with
a fully initialized migration state.
* Adopt error propagation in query,set dirty tracking
* Misc improvements overall broadly and Avihai
* Drop hugepages as it's a bit unrelated; I can pursue that patch
* separately. The main motivation is to provide a way to test
without hugepages similar to what vfio_type1_iommu.disable_hugepages=1
does.

Changes since RFCv1[2]:
* Remove intel/amd dirty tracking emulation enabling
* Remove the dirtyrate improvement for VF/IOMMU dirty tracking
[Will pursue these two in separate series]
* Introduce auto domains support
* Enforce dirty tracking following the IOMMUFD UAPI for this
* Add support for toggling hugepages in IOMMUFD
* Auto enable support when VF supports migration to use IOMMU
when it doesn't have VF dirty tracking
* Add a parameter to toggle VF dirty tracking

[0] https://lore.kernel.org/qemu-devel/20240201072818.327930-1-zhenzhong.duan@intel.com/
[1] https://lore.kernel.org/qemu-devel/20240201072818.327930-10-zhenzhong.duan@intel.com/
[2] https://lore.kernel.org/qemu-devel/20220428211351.3897-1-joao.m.martins@oracle.com/
[3] https://lore.kernel.org/qemu-devel/20230622214845.3980-1-joao.m.martins@oracle.com/
[4] https://lore.kernel.org/qemu-devel/20240212135643.5858-1-joao.m.martins@oracle.com/
[5] https://lore.kernel.org/qemu-devel/20240708143420.16953-1-joao.m.martins@oracle.com/

Joao Martins (12):
  vfio/pci: Extract mdev check into an helper
  vfio/iommufd: Don't initialize nor set a HOST_IOMMU_DEVICE with mdev
  backends/iommufd: Extend iommufd_backend_get_device_info() to fetch HW
    capabilities
  vfio/iommufd: Return errno in iommufd_cdev_attach_ioas_hwpt()
  vfio/iommufd: Introduce auto domain creation
  vfio/{iommufd,container}: Remove caps::aw_bits
  vfio/{iommufd,container}: Initialize HostIOMMUDeviceCaps during
    attach_device()
  vfio/iommufd: Probe and request hwpt dirty tracking capability
  vfio/iommufd: Implement VFIOIOMMUClass::set_dirty_tracking support
  vfio/iommufd: Implement VFIOIOMMUClass::query_dirty_bitmap support
  vfio/migration: Don't block migration device dirty tracking is
    unsupported
  vfio/common: Allow disabling device dirty page tracking

 include/hw/vfio/vfio-common.h      |  13 +++
 include/sysemu/host_iommu_device.h |   2 +-
 include/sysemu/iommufd.h           |  14 ++-
 backends/iommufd.c                 |  89 ++++++++++++++-
 hw/vfio/common.c                   |  17 +--
 hw/vfio/container.c                |  11 +-
 hw/vfio/helpers.c                  |  18 +++
 hw/vfio/iommufd.c                  | 178 ++++++++++++++++++++++++++++-
 hw/vfio/migration.c                |   4 +-
 hw/vfio/pci.c                      |  22 ++--
 backends/trace-events              |   3 +
 11 files changed, 339 insertions(+), 32 deletions(-)

-- 
2.17.2



^ permalink raw reply	[flat|nested] 82+ messages in thread

end of thread, other threads:[~2024-07-19  6:06 UTC | newest]

Thread overview: 82+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-12 11:46 [PATCH v4 00/12] hw/iommufd: IOMMUFD Dirty Tracking Joao Martins
2024-07-12 11:46 ` [PATCH v4 01/12] vfio/pci: Extract mdev check into an helper Joao Martins
2024-07-16  9:21   ` Cédric Le Goater
2024-07-16  9:33     ` Joao Martins
2024-07-12 11:46 ` [PATCH v4 02/12] vfio/iommufd: Don't initialize nor set a HOST_IOMMU_DEVICE with mdev Joao Martins
2024-07-16  9:21   ` Cédric Le Goater
2024-07-16 13:26   ` Eric Auger
2024-07-17  1:34   ` Duan, Zhenzhong
2024-07-12 11:46 ` [PATCH v4 03/12] backends/iommufd: Extend iommufd_backend_get_device_info() to fetch HW capabilities Joao Martins
2024-07-16  9:22   ` Cédric Le Goater
2024-07-16 13:34   ` Eric Auger
2024-07-12 11:46 ` [PATCH v4 04/12] vfio/iommufd: Return errno in iommufd_cdev_attach_ioas_hwpt() Joao Martins
2024-07-16  9:27   ` Cédric Le Goater
2024-07-16 13:36   ` Eric Auger
2024-07-17  1:37   ` Duan, Zhenzhong
2024-07-12 11:46 ` [PATCH v4 05/12] vfio/iommufd: Introduce auto domain creation Joao Martins
2024-07-16  9:39   ` Cédric Le Goater
2024-07-16  9:47     ` Joao Martins
2024-07-16 12:54   ` Cédric Le Goater
2024-07-16 16:04   ` Eric Auger
2024-07-16 16:44     ` Joao Martins
2024-07-16 16:46       ` Joao Martins
2024-07-17  2:52         ` Duan, Zhenzhong
2024-07-17  9:09           ` Joao Martins
2024-07-17  9:28             ` Cédric Le Goater
2024-07-17  9:31               ` Joao Martins
2024-07-18 13:47                 ` Joao Martins
2024-07-19  6:06                   ` Cédric Le Goater
2024-07-17  9:48             ` Duan, Zhenzhong
2024-07-17  9:53               ` Joao Martins
2024-07-16 17:32       ` Eric Auger
2024-07-17  2:18   ` Duan, Zhenzhong
2024-07-17  9:04     ` Joao Martins
2024-07-17 10:05       ` Duan, Zhenzhong
2024-07-17 11:04         ` Joao Martins
2024-07-18  7:44           ` Duan, Zhenzhong
2024-07-18  9:16             ` Joao Martins
2024-07-19  2:36               ` Duan, Zhenzhong
2024-07-12 11:46 ` [PATCH v4 06/12] vfio/{iommufd,container}: Remove caps::aw_bits Joao Martins
2024-07-16 10:19   ` Cédric Le Goater
2024-07-16 17:40   ` Eric Auger
2024-07-16 18:22     ` Joao Martins
2024-07-17 11:48       ` Eric Auger
2024-07-12 11:46 ` [PATCH v4 07/12] vfio/{iommufd, container}: Initialize HostIOMMUDeviceCaps during attach_device() Joao Martins via
2024-07-16 10:20   ` [PATCH v4 07/12] vfio/{iommufd,container}: " Cédric Le Goater
2024-07-16 10:40     ` Joao Martins
2024-07-17  2:05   ` Duan, Zhenzhong
2024-07-17  8:55     ` Joao Martins
2024-07-17 12:19   ` Eric Auger
2024-07-17 12:33     ` Joao Martins
2024-07-17 13:41       ` Eric Auger
2024-07-17 15:34         ` Joao Martins
2024-07-12 11:47 ` [PATCH v4 08/12] vfio/iommufd: Probe and request hwpt dirty tracking capability Joao Martins
2024-07-16 12:21   ` Cédric Le Goater
2024-07-17 12:27   ` Eric Auger
2024-07-17 12:38     ` Joao Martins
2024-07-17 13:43       ` Eric Auger
2024-07-12 11:47 ` [PATCH v4 09/12] vfio/iommufd: Implement VFIOIOMMUClass::set_dirty_tracking support Joao Martins
2024-07-16 12:24   ` Cédric Le Goater
2024-07-17  2:24   ` Duan, Zhenzhong
2024-07-17  9:14     ` Joao Martins
2024-07-17 12:36   ` Eric Auger
2024-07-17 12:41     ` Joao Martins
2024-07-17 13:34       ` Eric Auger
2024-07-17 15:18         ` Joao Martins
2024-07-12 11:47 ` [PATCH v4 10/12] vfio/iommufd: Implement VFIOIOMMUClass::query_dirty_bitmap support Joao Martins
2024-07-16 12:31   ` Cédric Le Goater
2024-07-16 12:53   ` Cédric Le Goater
2024-07-17 12:50   ` Eric Auger
2024-07-12 11:47 ` [PATCH v4 11/12] vfio/migration: Don't block migration device dirty tracking is unsupported Joao Martins
2024-07-17  2:38   ` Duan, Zhenzhong
2024-07-17  9:20     ` Joao Martins
2024-07-17 15:35       ` Joao Martins
2024-07-17 16:02         ` Joao Martins
2024-07-17 16:54           ` Joao Martins
2024-07-18  7:20       ` Duan, Zhenzhong
2024-07-18  9:05         ` Joao Martins
2024-07-17 12:57   ` Eric Auger
2024-07-12 11:47 ` [PATCH v4 12/12] vfio/common: Allow disabling device dirty page tracking Joao Martins
2024-07-16  8:20 ` [PATCH v4 00/12] hw/iommufd: IOMMUFD Dirty Tracking Duan, Zhenzhong
2024-07-16  9:22   ` Joao Martins
2024-07-18  7:50     ` Duan, Zhenzhong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).