preserve pending interrupts during cpr on arm
cover preserve pending interrupts during cpr on arm
Close a race condition that causes cpr-transfer to lose VFIO interrupts on ARM. See commit messages for details.
Steve Sistare (2):
hw/intc/arm_gicv3_kvm: subroutine for save pending hw/intc/arm_gicv3_kvm: preserve pending interrupts during cpr
hw/intc/arm_gicv3_kvm.c | 40 ++++++++++++++++++++++-------- include/hw/intc/arm_gicv3_common.h | 3 +++ 2 files changed, 33 insertions(+), 10 deletions(-)
Signature · 1 line
2.39.3
PATCH 1/2 hw/intc/arm_gicv3_kvm: subroutine for save pending
Extract a subroutine for KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES. No functional change.
--- hw/intc/arm_gicv3_kvm.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
hw/intc/arm_gicv3_kvm.c +15 -9
@@ -749,6 +749,20 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = { }, }; +static int kvm_arm_save_pending_tables (GICv3State *s) +{ +Error *err =NULL ; +int ret; + + ret =kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CTRL , +KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES , +NULL , true, &err); +if (err) { +error_report_err (err); + } +return ret; +} +/** * vm_change_state_handler - VM change state callback aiming at flushing * RDIST pending tables into guest RAM
@@ -758,20 +772,12 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {static void vm_change_state_handler (void *opaque,bool running,RunState state) { -GICv3State *s = (GICv3State *)opaque; -Error *err =NULL ;int ret;if (running) {return ; } - - ret =kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CTRL , -KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES , -NULL , true, &err); -if (err) { -error_report_err (err); - } + ret =kvm_arm_save_pending_tables (opaque);if (ret <0 && ret != -EFAULT ) {abort (); }
Signature · 1 line
2.39.3
PATCH 2/2 hw/intc/arm_gicv3_kvm: preserve pending interrupts during cpr
In reply to Steve SistareClose a race condition that causes cpr-transfer to lose VFIO interrupts on ARM.
CPR stops VCPUs but does not disable VFIO interrupts, which may continue to arrive throughout the transition to new QEMU.
CPR calls kvm_irqchip_remove_irqfd_notifier_gsi in old QEMU to force future interrupts to the producer eventfd, where they are preserved. Old QEMU then destroys the old KVM instance. However, interrupts may already be pended in KVM state. To preserve them, call ioctl KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES to flush them to guest RAM, where they will be picked up when the new KVM+VCPU instance is created.
--- hw/intc/arm_gicv3_kvm.c | 16 +++++++++++++++- include/hw/intc/arm_gicv3_common.h | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-)
hw/intc/arm_gicv3_kvm.c +15 -1
@@ -30,6 +30,7 @@#include "gicv3_internal.h" #include "vgic_common.h" #include "migration/blocker.h" +#include "migration/misc.h" #include "qom/object.h" #include "target/arm/cpregs.h"
@@ -783,6 +784,15 @@ static void vm_change_state_handler(void *opaque, bool running, } } +static int kvm_arm_gicv3_notifier (NotifierWithReturn *notifier, +MigrationEvent *e,Error **errp) +{ +if (e->type ==MIG_EVENT_PRECOPY_DONE ) { +GICv3State *s =container_of (notifier, GICv3State, cpr_notifier); +kvm_arm_save_pending_tables (s); + } +return 0 ; +}static void kvm_arm_gicv3_realize (DeviceState *dev,Error **errp) {
@@ -889,13 +899,17 @@ static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp) GICD_CTLR)) {error_setg (&s->migration_blocker,"This operating system kernel does " "not support vGICv3 migration" ); -if (migrate_add_blocker (&s->migration_blocker, errp) <0 ) { +if (migrate_add_blocker_modes (&s->migration_blocker,MIG_MODE_NORMAL , +MIG_MODE_CPR_TRANSFER , errp) <0 ) {return ; } }if (kvm_device_check_attr (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CTRL ,KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES )) {qemu_add_vm_change_state_handler (vm_change_state_handler, s); +migration_add_notifier_mode (&s->cpr_notifier, + kvm_arm_gicv3_notifier, +MIG_MODE_CPR_TRANSFER ); } }
include/hw/intc/arm_gicv3_common.h +3 -0
@@ -27,6 +27,7 @@#include "hw/sysbus.h" #include "hw/intc/arm_gic_common.h" #include "qom/object.h" +#include "qemu/notify.h" /* * Maximum number of possible interrupts, determined by the GIC architecture.
@@ -270,6 +271,8 @@ struct GICv3State {GICv3CPUState *cpu;/* List of all ITSes connected to this GIC */ GPtrArray *itslist; + +NotifierWithReturn cpr_notifier; };#define GICV3_BITMAP_ACCESSORS (BMP ) \
Signature · 1 line
2.39.3
Re: [PATCH V1 2/2] hw/intc/arm_gicv3_kvm: preserve pending interrupts during cpr
Quoted 33 lines · Steve Sistare
Close a race condition that causes cpr-transfer to lose VFIO interrupts on ARM.
CPR stops VCPUs but does not disable VFIO interrupts, which may continue to arrive throughout the transition to new QEMU.
CPR calls
kvm_irqchip_remove_irqfd_notifier_gsiin old QEMU to force future interrupts to the producer eventfd, where they are preserved. Old QEMU then destroys the old KVM instance. However, interrupts may already be pended in KVM state. To preserve them, call ioctlKVM_DEV_ARM_VGIC_SAVE_PENDING_TABLESto flush them to guest RAM, where they will be picked up when the new KVM+VCPU instance is created.Signed-off-by Steve Sistare <[email protected]>--- hw/intc/arm_gicv3_kvm.c | 16 +++++++++++++++- include/hw/intc/arm_gicv3_common.h | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-)hw/intc/arm_gicv3_kvm.c +1
-0@@ -30,6 +30,7 @@#include "gicv3_internal.h" #include "vgic_common.h" #include "migration/blocker.h" +#include "migration/misc.h" #include "qom/object.h" #include "target/arm/cpregs.h"
hw/intc/arm_gicv3_kvm.c static void vm_change_state_handler(void *opaque, bool running, · line 792
Quoted 9 lines
hw/intc/arm_gicv3_kvm.c +6
-0@@ -783,6 +784,15 @@ static void vm_change_state_handler(void *opaque, bool running, } } +static int kvm_arm_gicv3_notifier (NotifierWithReturn *notifier, +MigrationEvent *e,Error **errp) +{ +if (e->type ==MIG_EVENT_PRECOPY_DONE ) { +GICv3State *s =container_of (notifier, GICv3State, cpr_notifier); +kvm_arm_save_pending_tables (s);
This kvm_arm_gicv3_notifier() function reports an error via an Error pointer, and the function we call inside kvm_arm_save_pending_tables() can report errors via an Error pointer. So I think kvm_arm_save_pending_tables() should propagate the Error up, not ignore it.
(Or if there's a good reason we should silently ignore the error here, we should have a comment saying why.)
hw/intc/arm_gicv3_kvm.c static void vm_change_state_handler(void *opaque, bool running, · line 795
Quoted 3 lines
hw/intc/arm_gicv3_kvm.c +3
-0+ } +return 0 ; +}
thanks
-- PMM
Re: [PATCH V1 2/2] hw/intc/arm_gicv3_kvm: preserve pending interrupts during cpr
Quoted 50 lines · Peter Maydell
Quoted 33 lines · Steve Sistare
Close a race condition that causes cpr-transfer to lose VFIO interrupts on ARM.
CPR stops VCPUs but does not disable VFIO interrupts, which may continue to arrive throughout the transition to new QEMU.
CPR calls
kvm_irqchip_remove_irqfd_notifier_gsiin old QEMU to force future interrupts to the producer eventfd, where they are preserved. Old QEMU then destroys the old KVM instance. However, interrupts may already be pended in KVM state. To preserve them, call ioctlKVM_DEV_ARM_VGIC_SAVE_PENDING_TABLESto flush them to guest RAM, where they will be picked up when the new KVM+VCPU instance is created.Signed-off-by Steve Sistare <[email protected]>--- hw/intc/arm_gicv3_kvm.c | 16 +++++++++++++++- include/hw/intc/arm_gicv3_common.h | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-)hw/intc/arm_gicv3_kvm.c +1
-0@@ -30,6 +30,7 @@#include "gicv3_internal.h" #include "vgic_common.h" #include "migration/blocker.h" +#include "migration/misc.h" #include "qom/object.h" #include "target/arm/cpregs.h" hw/intc/arm_gicv3_kvm.c static void vm_change_state_handler(void *opaque, bool running, · line 792
Quoted 9 lines
hw/intc/arm_gicv3_kvm.c +6
-0@@ -783,6 +784,15 @@ static void vm_change_state_handler(void *opaque, bool running, } } +static int kvm_arm_gicv3_notifier (NotifierWithReturn *notifier, +MigrationEvent *e,Error **errp) +{ +if (e->type ==MIG_EVENT_PRECOPY_DONE ) { +GICv3State *s =container_of (notifier, GICv3State, cpr_notifier); +kvm_arm_save_pending_tables (s);This
kvm_arm_gicv3_notifier()function reports an error via an Error pointer, and the function we call insidekvm_arm_save_pending_tables()can report errors via an Error pointer. So I thinkkvm_arm_save_pending_tables()should propagate the Error up, not ignore it.
Quoted 2 lines
(Or if there's a good reason we should silently ignore the error here, we should have a comment saying why.)
No good reason, I was just mirroring the behavior of vm_change_state_handler. I'll propagate the error.
- Steve
Re: [PATCH V1 2/2] hw/intc/arm_gicv3_kvm: preserve pending interrupts during cpr
Quoted 51 lines · Steven Sistare
Quoted 50 lines · Peter Maydell
Quoted 33 lines · Steve Sistare
Close a race condition that causes cpr-transfer to lose VFIO interrupts on ARM.
CPR stops VCPUs but does not disable VFIO interrupts, which may continue to arrive throughout the transition to new QEMU.
CPR calls
kvm_irqchip_remove_irqfd_notifier_gsiin old QEMU to force future interrupts to the producer eventfd, where they are preserved. Old QEMU then destroys the old KVM instance. However, interrupts may already be pended in KVM state. To preserve them, call ioctlKVM_DEV_ARM_VGIC_SAVE_PENDING_TABLESto flush them to guest RAM, where they will be picked up when the new KVM+VCPU instance is created.Signed-off-by Steve Sistare <[email protected]>---
hw/intc/arm_gicv3_kvm.c | 16 +++++++++++++++-include/hw/intc/arm_gicv3_common.h| 3 +++2 files changed, 18 insertions(+), 1 deletion(-)hw/intc/arm_gicv3_kvm.c +1
-0@@ -30,6 +30,7 @@ #include "gicv3_internal.h" #include "vgic_common.h" #include "migration/blocker.h" +#include "migration/misc.h" #include "qom/object.h" #include "target/arm/cpregs.h"hw/intc/arm_gicv3_kvm.c static void vm_change_state_handler(void *opaque, bool running, · line 792
Quoted 9 lines
hw/intc/arm_gicv3_kvm.c +6
-0@@ -783,6 +784,15 @@ static void vm_change_state_handler(void *opaque, bool running, } } +static int kvm_arm_gicv3_notifier (NotifierWithReturn *notifier, + MigrationEvent *e, Error **errp) +{ + if (e->type == MIG_EVENT_PRECOPY_DONE) { + GICv3State *s = container_of(notifier, GICv3State, cpr_notifier); + kvm_arm_save_pending_tables(s);This
kvm_arm_gicv3_notifier()function reports an error via an Error pointer, and the function we call insidekvm_arm_save_pending_tables()can report errors via an Error pointer. So I thinkkvm_arm_save_pending_tables()should propagate the Error up, not ignore it.
Quoted 5 lines
Quoted 2 lines
(Or if there's a good reason we should silently ignore the error here, we should have a comment saying why.)
No good reason, I was just mirroring the behavior of
vm_change_state_handler. I'll propagate the error.
The kvm_arm_save_pending_tables becomes trivial, so I will just delete it, and delete patch 1. I will submit a V2 for patch 2 alone shortly.
- Steve