[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH V1 14/26] migration: close kvm after cpr
From: |
Steve Sistare |
Subject: |
[PATCH V1 14/26] migration: close kvm after cpr |
Date: |
Wed, 29 Jan 2025 06:43:10 -0800 |
cpr-transfer breaks vfio network connectivity to and from the guest, and
the host system log shows:
irq bypass consumer (token 00000000a03c32e5) registration fails: -16
which is EBUSY. This occurs because KVM descriptors are still open in
the old QEMU process. Close them.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
accel/kvm/kvm-all.c | 20 ++++++++++++++++++++
hw/vfio/common.c | 8 ++++++++
include/hw/vfio/vfio-common.h | 1 +
include/migration/cpr.h | 2 ++
include/system/kvm.h | 1 +
migration/cpr-transfer.c | 18 ++++++++++++++++++
migration/cpr.c | 8 ++++++++
migration/migration.c | 1 +
8 files changed, 59 insertions(+)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index c65b790..f4e341f 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -595,6 +595,26 @@ err:
return ret;
}
+void kvm_close(void)
+{
+ CPUState *cpu;
+
+ CPU_FOREACH(cpu) {
+ cpu_remove_sync(cpu);
+ close(cpu->kvm_fd);
+ cpu->kvm_fd = -1;
+ close(cpu->kvm_vcpu_stats_fd);
+ cpu->kvm_vcpu_stats_fd = -1;
+ }
+
+ if (kvm_state && kvm_state->fd != -1) {
+ close(kvm_state->vmfd);
+ kvm_state->vmfd = -1;
+ close(kvm_state->fd);
+ kvm_state->fd = -1;
+ }
+}
+
/*
* dirty pages logging control
*/
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index c8ee71a..db0498e 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1511,6 +1511,14 @@ int vfio_kvm_device_del_fd(int fd, Error **errp)
return 0;
}
+void vfio_kvm_device_close(void)
+{
+ if (vfio_kvm_device_fd != -1) {
+ close(vfio_kvm_device_fd);
+ vfio_kvm_device_fd = -1;
+ }
+}
+
VFIOAddressSpace *vfio_get_address_space(AddressSpace *as)
{
VFIOAddressSpace *space;
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 8a4a658..5a89aca 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -262,6 +262,7 @@ void vfio_detach_device(VFIODevice *vbasedev);
int vfio_kvm_device_add_fd(int fd, Error **errp);
int vfio_kvm_device_del_fd(int fd, Error **errp);
+void vfio_kvm_device_close(void);
bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **errp);
void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer);
diff --git a/include/migration/cpr.h b/include/migration/cpr.h
index faeb0cc..e8f4aba 100644
--- a/include/migration/cpr.h
+++ b/include/migration/cpr.h
@@ -29,7 +29,9 @@ void cpr_state_close(void);
struct QIOChannel *cpr_state_ioc(void);
bool cpr_needed_for_reuse(void *opaque);
+void cpr_kvm_close(void);
+void cpr_transfer_init(void);
QEMUFile *cpr_transfer_output(MigrationChannel *channel, Error **errp);
QEMUFile *cpr_transfer_input(MigrationChannel *channel, Error **errp);
diff --git a/include/system/kvm.h b/include/system/kvm.h
index ab17c09..ad5c55e 100644
--- a/include/system/kvm.h
+++ b/include/system/kvm.h
@@ -194,6 +194,7 @@ bool kvm_has_sync_mmu(void);
int kvm_has_vcpu_events(void);
int kvm_max_nested_state_length(void);
int kvm_has_gsi_routing(void);
+void kvm_close(void);
/**
* kvm_arm_supports_user_irq
diff --git a/migration/cpr-transfer.c b/migration/cpr-transfer.c
index e1f1403..396558f 100644
--- a/migration/cpr-transfer.c
+++ b/migration/cpr-transfer.c
@@ -17,6 +17,24 @@
#include "migration/vmstate.h"
#include "trace.h"
+static int cpr_transfer_notifier(NotifierWithReturn *notifier,
+ MigrationEvent *e,
+ Error **errp)
+{
+ if (e->type == MIG_EVENT_PRECOPY_DONE) {
+ cpr_kvm_close();
+ }
+ return 0;
+}
+
+void cpr_transfer_init(void)
+{
+ static NotifierWithReturn notifier;
+
+ migration_add_notifier_mode(¬ifier, cpr_transfer_notifier,
+ MIG_MODE_CPR_TRANSFER);
+}
+
QEMUFile *cpr_transfer_output(MigrationChannel *channel, Error **errp)
{
MigrationAddress *addr = channel->addr;
diff --git a/migration/cpr.c b/migration/cpr.c
index e3f27e9..86eb484 100644
--- a/migration/cpr.c
+++ b/migration/cpr.c
@@ -7,12 +7,14 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
+#include "hw/vfio/vfio-common.h"
#include "migration/cpr.h"
#include "migration/misc.h"
#include "migration/options.h"
#include "migration/qemu-file.h"
#include "migration/savevm.h"
#include "migration/vmstate.h"
+#include "system/kvm.h"
#include "system/runstate.h"
#include "trace.h"
@@ -243,3 +245,9 @@ bool cpr_needed_for_reuse(void *opaque)
MigMode mode = migrate_mode();
return mode == MIG_MODE_CPR_TRANSFER;
}
+
+void cpr_kvm_close(void)
+{
+ kvm_close();
+ vfio_kvm_device_close();
+}
diff --git a/migration/migration.c b/migration/migration.c
index 88b0991..7a69782 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -288,6 +288,7 @@ void migration_object_init(void)
ram_mig_init();
dirty_bitmap_mig_init();
+ cpr_transfer_init();
/* Initialize cpu throttle timers */
cpu_throttle_init();
--
1.8.3.1
- [PATCH V1 04/26] vfio/container: register container for cpr, (continued)
- [PATCH V1 04/26] vfio/container: register container for cpr, Steve Sistare, 2025/01/29
- [PATCH V1 02/26] migration: lower handler priority, Steve Sistare, 2025/01/29
- [PATCH V1 07/26] vfio/container: recover from unmap-all-vaddr failure, Steve Sistare, 2025/01/29
- [PATCH V1 11/26] vfio-pci: skip reset during cpr, Steve Sistare, 2025/01/29
- [PATCH V1 03/26] vfio: vfio_find_ram_discard_listener, Steve Sistare, 2025/01/29
- [PATCH V1 20/26] vfio/iommufd: export iommufd_cdev_get_info_iova_range, Steve Sistare, 2025/01/29
- [PATCH V1 08/26] pci: skip reset during cpr, Steve Sistare, 2025/01/29
- [PATCH V1 05/26] vfio/container: preserve descriptors, Steve Sistare, 2025/01/29
- [PATCH V1 09/26] pci: export msix_is_pending, Steve Sistare, 2025/01/29
- [PATCH V1 13/26] vfio-pci: preserve INTx, Steve Sistare, 2025/01/29
- [PATCH V1 14/26] migration: close kvm after cpr,
Steve Sistare <=
- [PATCH V1 19/26] vfio/iommufd: use IOMMU_IOAS_MAP_FILE, Steve Sistare, 2025/01/29
- [PATCH V1 21/26] iommufd: change process ioctl, Steve Sistare, 2025/01/29
- [PATCH V1 12/26] vfio-pci: preserve MSI, Steve Sistare, 2025/01/29
- [PATCH V1 16/26] vfio: return mr from vfio_get_xlat_addr, Steve Sistare, 2025/01/29
- [PATCH V1 17/26] vfio: pass ramblock to vfio_container_dma_map, Steve Sistare, 2025/01/29
- [PATCH V1 15/26] migration: cpr_get_fd_param helper, Steve Sistare, 2025/01/29
- [PATCH V1 18/26] vfio/iommufd: define iommufd_cdev_make_hwpt, Steve Sistare, 2025/01/29
- [PATCH V1 10/26] vfio-pci: refactor for cpr, Steve Sistare, 2025/01/29
- [PATCH V1 23/26] vfio/iommufd: register container for cpr, Steve Sistare, 2025/01/29
- [PATCH V1 22/26] vfio/iommufd: invariant device name, Steve Sistare, 2025/01/29