vfio: Split migration ops from main device ops
authorYishai Hadas <yishaih@nvidia.com>
Tue, 28 Jun 2022 15:59:10 +0000 (18:59 +0300)
committerAlex Williamson <alex.williamson@redhat.com>
Thu, 30 Jun 2022 16:47:22 +0000 (10:47 -0600)
commit6e97eba8ad8748fabb795cffc5d9e1a7dcfd7367
tree2e2f703336ab9f5d80ae5e7bcecd16dc5fdcf463
parent2b1c1906286fa547845f5385ee72db74b2b0251d
vfio: Split migration ops from main device ops

vfio core checks whether the driver sets some migration op (e.g.
set_state/get_state) and accordingly calls its op.

However, currently mlx5 driver sets the above ops without regards to its
migration caps.

This might lead to unexpected usage/Oops if user space may call to the
above ops even if the driver doesn't support migration. As for example,
the migration state_mutex is not initialized in that case.

The cleanest way to manage that seems to split the migration ops from
the main device ops, this will let the driver setting them separately
from the main ops when it's applicable.

As part of that, validate ops construction on registration and include a
check for VFIO_MIGRATION_STOP_COPY since the uAPI claims it must be set
in migration_flags.

HISI driver was changed as well to match this scheme.

This scheme may enable down the road to come with some extra group of
ops (e.g. DMA log) that can be set without regards to the other options
based on driver caps.

Fixes: 6fadb021266d ("vfio/mlx5: Implement vfio_pci driver for mlx5 devices")
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
Link: https://lore.kernel.org/r/20220628155910.171454-3-yishaih@nvidia.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
drivers/vfio/pci/mlx5/cmd.c
drivers/vfio/pci/mlx5/cmd.h
drivers/vfio/pci/mlx5/main.c
drivers/vfio/pci/vfio_pci_core.c
drivers/vfio/vfio.c
include/linux/vfio.h