Commit Graph

19 Commits

Author SHA1 Message Date
Lei Wang
1227330e7e migration: cleanup using tdx_mig.nr_streams to avoid segfault
It will segfault when cleanup migration streams before they are setup, to
avoid this, use tdx_mig.nr_streams rather than nr_channels.

Opportunistically remove the unnecessary parameter "nr_channels" in
following 2 callback functions in cgs_mig:

    cgs_mig.savevm_state_cleanup
    cgs_mig.loadvm_state_cleanup

This fixes LFE-9211 and LFE-9481.

Signed-off-by: Lei Wang <lei4.wang@intel.com>
2023-11-28 17:14:58 +02:00
Wei Wang
1331bb66ee migration/cgs: fix a issue about live migration self check hangs
Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:56 +02:00
Wei Wang
225e6bd582 migration/cgs: fix the downstream mistake in cgs_mig_loadvm_state_setup
Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:56 +02:00
Wei Wang
c3ada4bc28 migration: postcopy support for private pages
Signed-off-by: Wei Wang <wei.w.wang@intel.com>

migration: fix td postcopy migration

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:56 +02:00
Wei Wang
e6d1beea29 migration: add multifd support for TD guest
Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:56 +02:00
Wei Wang
b581c14b8f migration: fix cgs-tdx to support migration cancel
Set nr_channels at migration runtime
Pass the gfn_end to KVM, no need to align on blocked size.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:55 +02:00
Wei Wang
acf8c03629 migration/cgs: add cgs_mig_init
cgs_mig_init calls the vendor specific init function based the vm type
to initialize the cgs_mig callbacks.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:55 +02:00
Wei Wang
3635086ab7 migration/savevm: add cgs_mig_loadvm_state_cleanup
cgs_mig_loadvm_state_cleanup in invoked on the destination side when
migration is done to invoke vendor specific cleanup function to do the
cleanup work.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:54 +02:00
Wei Wang
7af92ba959 migration/cgs: add cgs_mig_loadvm_state
The private states (memory data, vcpu states etc) are usually received
as a bundle of data, which need to be parsed by each vendor specific
implementation. cgs_mig_loadvm_state is invoked to call into the vendor
specific functions to parse and import the states.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:54 +02:00
Wei Wang
468732dd24 migration/cgs: add cgs_mig_loadvm_state_setup
cgs_mig_loadvm_state_setup is invoked on the destination side at the
migration setup phase to call into the vendor specific implementation
to do the setup work. Similar to the source side setup, current
implementation doesn't support multifd.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:54 +02:00
Wei Wang
d1d88a351a migration/cgs: add cgs_mig_savevm_state_cleanup
cgs_mig_savevm_state_cleanup is invoked after migration is done or
cancelled to invoke the vendor specific cleanup to do some house keeping
work.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:54 +02:00
Wei Wang
1bf0585f28 migration/cgs: add cgs_mig_savevm_state_ram_cancel
cgs_mig_savevm_state_ram_cancel in invoked to notify the vendor specific
implementation to cancel the migration process. This is required by some
vendor specific implementation to restore the states of the private pages
that have been migrated. The input parameter gfn_end tells which gfn was
last migrated, so that private pages of a gfn larger than gfn_end don't
need to be restored.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:54 +02:00
Wei Wang
d5f6f88616 migration/cgs: add cgs_mig_savevm_state_end
cgs_mig_savevm_state_end is invoked after the guest is paused to save
the private non-iterable states (e.g. vCPU states) owned by each vendor
specific implementation. The states are sent following the new flage,
QEMU_VM_SECTION_CGS_END, which indicates to the destination about the
end of the private states migration.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:53 +02:00
Wei Wang
46f97395b2 migration/cgs: add cgs_mig_savevm_state_downtime
cgs_mig_savevm_state_downtime is invoked at the end of the precopy phase
to notify the vendor specific implementation to enter downtime.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:53 +02:00
Wei Wang
95a29643ee migration/cgs: add cgs_mig_savevm_state_ram
cgs_mig_savevm_state_ram saves one or more guest private pages. The
private pages' gfns are provided in an array of gfns with the gfn_num
to specify the size of the array. On success, the call returns the
number of bytes, including the 8-bytes header, that have been saved,
and on failures, a negative error code is returned.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:53 +02:00
Wei Wang
17f8f07a5a migration/cgs: add cgs_ram_save_start_epoch
cgs_ram_save_start_epoch is invoked at the beginning of each memory save
iteration to migrate an epoch data from verndor specific implementations
if needed. For example, Intel TDX migration architecture requires such
an epoch data to be migrated to enforce each guest private page to be
migrated once during a migration epoch.

RAM_SAVE_FLAG_CGS_EPOCH is added to flag the destination side that the
migration data is cgs epoch data. Add and expose ram_save_cgs_epoch_header
to have cgs.c to send the header+epoch data.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:53 +02:00
Wei Wang
9681bed760 migration/cgs: add cgs_mig_savevm_state_start
cgs_mig_savevm_state_start is invoked at the beginning of the migration
flow to send a kickoff message (i.e. QEMU_VM_SECTION_CGS_START flag +
vendor specific kickoff data if there is) to the destination.

The kickoff message is added, because some vendor specific implementation
(e.g. TDX live migration) requires such a kickoff message to start the
migration session and some preparation work on the destination side as
soon as possible.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:53 +02:00
Wei Wang
9442e343af migration/cgs: add cgs_mig_savevm_state_setup
cgs_mig_savevm_state_setup is invoked on the source side at the migration
setup phase to call into the vendor specific setup function to do the
setup work. The default migration flow only have one channel to migrate
data, so cgs_mig_savevm_state_setup is called only once in the migration
thread's qemu_savevm_satate_setup. The multifd case is different and it
hasn't been supported, so skip cgs_mig_savevm_state_setup for the multifd
case.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:53 +02:00
Wei Wang
67fe309f29 migration/cgs: add cgs_mig_is_ready
cgs_mig_is_ready is used to check if cgs migration is ready when required.
This is done by the framwork API calling to each vendor specific function
to check, and the check is performed at the time when user requests
migration to start. For the legacy VM migration case and the vendor
specific implementation that don't require the check, just return true
to have the migration flow continue.

cgs.c file is created to hold all the cgs migration framwork APIs,
and cgs.h exposes the APIs to the migration flow.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:53 +02:00