[PATCH v12 00/14] s390/vfio-ap: Add live guest migration support
From: Anthony Krowiak
Date: Fri Nov 06 2026 - 10:30:04 EST
This patch series implements live guest migration support for KVM guests
with s390 AP (Adjunct Processor) devices passed through via the VFIO
mediated device framework.
Background
~~~~~~~~~~
The vfio-ap device driver differs from typical VFIO device drivers in that
it does not virtualize a physical device. Instead, it manages AP
configuration metadata identifying the AP adapters, domains, and controls390/vfio-ap: Add live guest migration support
domains to which a guest will be granted access. These AP resources are
configured by assigning them to a vfio-ap mediated device via its sysfs
assignment interfaces. When the fd for the VFIO device is opened by
userspace, the vfio_ap device driver sets the guest's AP configuration
from the metadata stored with the mediated device. As such, the AP devices
are not accessed directly through the vfio_ap driver, so the driver has no
internal AP device state to migrate. What it does migrate is the AP
configuration metadata of the source guest.
Implementation Approach
~~~~~~~~~~~~~~~~~~~~~~~
This series implements the VFIO migration protocol using the STOP_COPY
migration flow. The key aspects are:
1. On transition of the migration state from STOP to STOP_COPY
- The vfio_ap device driver creates a filestream for userspace to use to
read the guest's AP configuration from the mdev
2. During the STOP_COPY phase
- Userspace uses the filestream created in #1 to read the source guest's
AP configuration
- The vfio_ap device driver copies the source guest's AP configuration
information to userspace
3. On transition of the migration state from STOP to RESUMING
- The vfio_ap device driver creates a filestream for userspace to use to
write the source guest's AP configuration information so it can be
restored to the mdev on the destination host.
4. During the RESUMING phase
- Userspace uses the filestream created in #3 to send the source guest's
AP configuration information to the vfio_ap device driver on the
destination host.
- The vfio_ap device driver first verifies the source guest's AP
configuration is compatible with the destination host's.
- The driver restores AP configuration to the mdev on the destination
host which automatically hot plugs the AP resources identified
therein.
5. Documentation
- Add live guest migration chapter to vfio-ap.rst
Compatibility Validation
~~~~~~~~~~~~~~~~~~~~~~~~
The series includes comprehensive validation to ensure source and
destination AP configurations are compatible. For each queue, the following
characteristics must match:
- AP type (target must be same or newer than source)
- Installed facilities (APSC, APQKM, AP4KC, SLCF)
- Operating mode (CCA, Accelerator, XCP)
- APXA facility setting
- Classification (native vs stateless functions)
- Queue usability (binding/associated state)
When incompatibilities are detected, migration fails with detailed error
messages identifying the specific queue and characteristic that caused
the failure.
Configuration Management
~~~~~~~~~~~~~~~~~~~~~~~~
This implementation does not prevent configuration changes during
migration. Configuration stability is an orchestration-layer
responsibility, consistent with other VFIO device types. The driver's
role is to validate configurations and provide clear diagnostics when
incompatibilities are detected, enabling orchestration tools to implement
appropriate policies.
QEMU patches exploiting this series:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
https://lore.kernel.org/qemu-devel/20260409141352.997844-1-akrowiak@xxxxxxxxxxxxx/
Change log v11 => v12:
~~~~~~~~~~~~~~~~~~~~~
Patch 02/14: Data structures for facilitating vfio device migration
* struct vfio_ap_migration_file
~ Changed ap_config field from struct vfio_ap_config * to void *
~ Updated kernel doc for @ap_config
Patch 03/14: Functions to initialize/release vfio device migration data
* Fixed commit message
* vfio_ap_release_mig_files()
~ Fixed kernel doc
~ Rewrote kernel doc to describe that the files are reset, not freed
* vfio_ap_release_migration_data()
~ Added kernel doc stating it is called only from the release callback
* vfio_ap_init_migration_data()
~ Return 0 if mig_data already exists
* vfio_ap_mdev_close_device()
~ Removed call to vfio_ap_release_migration_data()
* vfio_ap_mdev_open_device()
~ Removed call to vfio_ap_release_migration_data() on set_kvm failure
Patch 04/14: Reset migration state on VFIO_DEVICE_RESET and device close
* Changed subject and commit message
* vfio_ap_mdev_unset_kvm()
~ Removed calls to get/release_update_locks_for_kvm()
~ Added lockdep_assert_held() for mdevs_lock, kvm->lock and
lockdep_assert_held_write() for pqap_hook_rwsem
* vfio_ap_mdev_close_device()
~ Take locks with get_update_locks_for_kvm() around unset_kvm
~ Call vfio_ap_reset_migration_state()
* vfio_ap_reset_migration_state()
~ Updated kernel doc
Patch 08/14: Transition device migration state from STOP to RESUMING
* vfio_ap_resuming_init()
~ Dropped ap_config->num_queues initialization to MAX_AP_QUEUES
~ Updated kernel doc
Patch 09/14: File ops called to resume the vfio device migration
* vfio_ap_resuming_write()
~ Copy into mig_file->ap_config buffer without dynamic size bounds
~ Evaluate ap_config header fields after offsetofend check
Anthony Krowiak (14):
s390/vfio-ap: Provide function to get the number of queues assigned to
mdev
s390/vfio-ap: Data structures for facilitating vfio device migration
s390/vfio-ap: Functions to initialize/release vfio device migration
data
s390/vfio-ap: Reset migration state on VFIO_DEVICE_RESET and device
close
s390/vfio-ap: Callback to get/set vfio device mig state during guest
migration
s390/vfio-ap: Transition guest migration state from STOP to STOP_COPY
s390/vfio-ap: File ops called to save the vfio device migration state
s390/vfio-ap: Transition device migration state from STOP to RESUMING
s390/vfio-ap: File ops called to resume the vfio device migration
s390/vfio-ap: Transition device migration state to from/to STOP
s390/vfio-ap: Callback to get the size of data to be migrated during
guest migration
s390/vfio-ap: Set up for vfio-ap device migration
s390/vfio-ap: Add 'migration' feature to sysfs 'features' attribute
s390/vfio-ap: Add live guest migration chapter to vfio-ap.rst
Documentation/arch/s390/vfio-ap.rst | 643 ++++++++--
drivers/s390/crypto/Makefile | 2 +-
drivers/s390/crypto/vfio_ap_drv.c | 14 +-
drivers/s390/crypto/vfio_ap_migration.c | 1456 +++++++++++++++++++++++
drivers/s390/crypto/vfio_ap_ops.c | 71 +-
drivers/s390/crypto/vfio_ap_private.h | 12 +
6 files changed, 2092 insertions(+), 106 deletions(-)
create mode 100644 drivers/s390/crypto/vfio_ap_migration.c
--
2.53.0