Add mlx5 live migration driver and v2 migration protocol

This series adds mlx5 live migration driver for VFs that are migration
 capable and includes the v2 migration protocol definition and mlx5
 implementation.
 
 The mlx5 driver uses the vfio_pci_core split to create a specific VFIO
 PCI driver that matches the mlx5 virtual functions. The driver provides
 the same experience as normal vfio-pci with the addition of migration
 support.
 
 In HW the migration is controlled by the PF function, using its
 mlx5_core driver, and the VFIO PCI VF driver co-ordinates with the PF to
 execute the migration actions.
 
 The bulk of the v2 migration protocol is semantically the same v1,
 however it has been recast into a FSM for the device_state and the
 actual syscall interface uses normal ioctl(), read() and write() instead
 of building a syscall interface using the region.
 
 Several bits of infrastructure work are included here:
  - pci_iov_vf_id() to help drivers like mlx5 figure out the VF index from
    a BDF
  - pci_iov_get_pf_drvdata() to clarify the tricky locking protocol when a
    VF reaches into its PF's driver
  - mlx5_core uses the normal SRIOV lifecycle and disables SRIOV before
    driver remove, to be compatible with pci_iov_get_pf_drvdata()
  - Lifting VFIO_DEVICE_FEATURE into core VFIO code
 
 This series comes after alot of discussion. Some major points:
 - v1 ABI compatible migration defined using the same FSM approach:
    https://lore.kernel.org/all/0-v1-a4f7cab64938+3f-vfio_mig_states_jgg@nvidia.com/
 - Attempts to clarify how the v1 API works:
    Alex's:
      https://lore.kernel.org/kvm/163909282574.728533.7460416142511440919.stgit@omen/
    Jason's:
      https://lore.kernel.org/all/0-v3-184b374ad0a8+24c-vfio_mig_doc_jgg@nvidia.com/
 - Etherpad exploring the scope and questions of general VFIO migration:
      https://lore.kernel.org/kvm/87mtm2loml.fsf@redhat.com/
 
 NOTE: As this series touched mlx5_core parts we need to send this in a
 pull request format to VFIO to avoid conflicts.
 
 Matching qemu changes can be previewed here:
  https://github.com/jgunthorpe/qemu/commits/vfio_migration_v2
 
 Link: https://lore.kernel.org/all/20220224142024.147653-1-yishaih@nvidia.com
 Signed-of-by: Leon Romanovsky <leonro@nvidia.com>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQT1m3YD37UfMCUQBNwp8NhrnBAZsQUCYiCgjAAKCRAp8NhrnBAZ
 sV/IAP4/DwDa3BMWETVzzaaMkQEMphFu/KdSyKoDEE1CW7xckwD8Cp/sO5Ij010W
 tATrzMvWWsdFfMTgraT3D66pPJQVtAU=
 =0g70
 -----END PGP SIGNATURE-----

Merge tag 'mlx5-vfio-v10' of https://git.kernel.org/pub/scm/linux/kernel/git/mellanox/linux into v5.18/vfio/next/mlx5-migration-v10

Add mlx5 live migration driver and v2 migration protocol

This series adds mlx5 live migration driver for VFs that are migration
capable and includes the v2 migration protocol definition and mlx5
implementation.

The mlx5 driver uses the vfio_pci_core split to create a specific VFIO
PCI driver that matches the mlx5 virtual functions. The driver provides
the same experience as normal vfio-pci with the addition of migration
support.

In HW the migration is controlled by the PF function, using its
mlx5_core driver, and the VFIO PCI VF driver co-ordinates with the PF to
execute the migration actions.

The bulk of the v2 migration protocol is semantically the same v1,
however it has been recast into a FSM for the device_state and the
actual syscall interface uses normal ioctl(), read() and write() instead
of building a syscall interface using the region.

Several bits of infrastructure work are included here:
 - pci_iov_vf_id() to help drivers like mlx5 figure out the VF index from
   a BDF
 - pci_iov_get_pf_drvdata() to clarify the tricky locking protocol when a
   VF reaches into its PF's driver
 - mlx5_core uses the normal SRIOV lifecycle and disables SRIOV before
   driver remove, to be compatible with pci_iov_get_pf_drvdata()
 - Lifting VFIO_DEVICE_FEATURE into core VFIO code

This series comes after alot of discussion. Some major points:
- v1 ABI compatible migration defined using the same FSM approach:
   https://lore.kernel.org/all/0-v1-a4f7cab64938+3f-vfio_mig_states_jgg@nvidia.com/
- Attempts to clarify how the v1 API works:
   Alex's:
     https://lore.kernel.org/kvm/163909282574.728533.7460416142511440919.stgit@omen/
   Jason's:
     https://lore.kernel.org/all/0-v3-184b374ad0a8+24c-vfio_mig_doc_jgg@nvidia.com/
- Etherpad exploring the scope and questions of general VFIO migration:
     https://lore.kernel.org/kvm/87mtm2loml.fsf@redhat.com/

NOTE: As this series touched mlx5_core parts we need to send this in a
pull request format to VFIO to avoid conflicts.

Matching qemu changes can be previewed here:
 https://github.com/jgunthorpe/qemu/commits/vfio_migration_v2

Link: https://lore.kernel.org/all/20220224142024.147653-1-yishaih@nvidia.com
Signed-of-by: Leon Romanovsky <leonro@nvidia.com>
This commit is contained in:
Alex Williamson 2022-03-03 09:51:03 -07:00
commit b042b27868
22 changed files with 1847 additions and 291 deletions