vITS save/restore
v6 cover vITS save/restore
This series allows ITS save/restore and migration use cases.
ITS tables are flushed into guest RAM on VM stop while registers are save on pre_save() callback. Tables and registers are restored on ITS post_load().
Redistributor pending tables also are flushed on VM stop, independently on ITS tables.
That work was tested on Cavium ThunderX using virsh save/restore and virt-manager live migration.
Best Regards
Eric
This series can be found at:
https://github.com/eauger/qemu/tree/v2.9.0-its_mig-v6
History:
v5 -> v6:
- RFC -> PATCH as the kernel associated series was pulled for 4.12
- remove linux header update patch file
- added "kvm-all: Pass an error object to kvm_device_access" to avoid aborting if table save fails with -EFAULT
- fix the migration_blocker message (s/vGICv3/vITS)
- use &s->ctlr directly when writing GITS_CTLR
- s->iidr reset in gicv3_its_common_reset
v4 -> v5:
- adapt to the new user API
- new patch "hw/intc/arm_gicv3_kvm: Implement pending table save" as the pending table save now is handled on GICV3 side.
v3 -> v4:
- oversight in v3, missed a last minute correction related to reg useless declaration in kvm_arm_its_pre_save
v2 -> v3:
- GITS_IIDR is now saved and restored to check ABI revision.
- get/put functions renamed into pre_save/post_load
- unmigratable = false removed
- changed the migration blocker message
- remove the extract64 round s->ctlr
- reword some comments
v1 -> v2:
- rebase on 2.9 soft release code
- handle case where migrate_add_blocker fails
- add comments along with ITS and GICv3 migration priorities
Eric Auger (4):
kvm-all: Pass an error object to kvm_device_access hw/intc/arm_gicv3_its: Implement state save/restore hw/intc/arm_gicv3_kvm: Implement pending table save hw/intc/arm_gicv3_its: Allow save/restore
hw/intc/arm_gic_kvm.c | 9 ++- hw/intc/arm_gicv3_common.c | 1 + hw/intc/arm_gicv3_its_common.c | 12 ++- hw/intc/arm_gicv3_its_kvm.c | 131 +++++++++++++++++++++++++++++---- hw/intc/arm_gicv3_kvm.c | 48 ++++++++++-- include/hw/intc/arm_gicv3_its_common.h | 8 ++ include/migration/vmstate.h | 2 + include/sysemu/kvm.h | 11 ++- kvm-all.c | 13 ++-- 9 files changed, 200 insertions(+), 35 deletions(-)
Signature · 1 line
2.5.5
PATCH v6 1/4 kvm-all: Pass an error object to kvm_device_access
In some circumstances, we don't want to abort if the kvm_device_access fails. This will be the case during ITS migration, in case the ITS table save/restore fails because the guest did not program the vITS correctly. So let's pass an error object to the function and return the ioctl value. New callers will be able to make a decision upon this returned value.
Existing callers pass &error_abort which will cause the function to abort on failure.
--- hw/intc/arm_gic_kvm.c | 9 +++++---- hw/intc/arm_gicv3_its_kvm.c | 2 +- hw/intc/arm_gicv3_kvm.c | 14 +++++++------- include/sysemu/kvm.h | 11 +++++++---- kvm-all.c | 13 +++++++------ 5 files changed, 27 insertions(+), 22 deletions(-)
hw/intc/arm_gic_kvm.c +5 -4
@@ -100,14 +100,14 @@ static void kvm_gicd_access(GICState *s, int offset, int cpu, uint32_t *val, bool write) {kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_DIST_REGS , -KVM_VGIC_ATTR (offset, cpu), val, write); +KVM_VGIC_ATTR (offset, cpu), val, write, &error_abort); }static void kvm_gicc_access (GICState *s,int offset,int cpu,uint32_t *val,bool write) {kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CPU_REGS , -KVM_VGIC_ATTR (offset, cpu), val, write); +KVM_VGIC_ATTR (offset, cpu), val, write, &error_abort); }#define for_each_irq_reg (_ctr, _max_irq, _field_width) \
@@ -538,13 +538,14 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)if (kvm_device_check_attr (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_NR_IRQS ,0 )) {uint32_t numirqs = s->num_irq;kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_NR_IRQS ,0 , - &numirqs, true); + &numirqs, true, &error_abort); }/* Tell the kernel to complete VGIC initialization now */ if (kvm_device_check_attr (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CTRL ,KVM_DEV_ARM_VGIC_CTRL_INIT )) {kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CTRL , -KVM_DEV_ARM_VGIC_CTRL_INIT ,NULL , true); +KVM_DEV_ARM_VGIC_CTRL_INIT ,NULL , true, + &error_abort); } }else if (ret != -ENODEV && ret != -ENOTSUP ) {error_setg_errno (errp, -ret,"error creating in-kernel VGIC" );
hw/intc/arm_gicv3_its_kvm.c +1 -1
@@ -78,7 +78,7 @@ static void kvm_arm_its_realize(DeviceState *dev, Error **errp)/* explicit init of the ITS */ kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CTRL , -KVM_DEV_ARM_VGIC_CTRL_INIT ,NULL , true); +KVM_DEV_ARM_VGIC_CTRL_INIT ,NULL , true, &error_abort);/* register the base address */ kvm_arm_register_device(&s->iomem_its_cntrl, -1, KVM_DEV_ARM_VGIC_GRP_ADDR,
hw/intc/arm_gicv3_kvm.c +7 -7
@@ -93,7 +93,7 @@ static inline void kvm_gicd_access(GICv3State *s, int offset, {kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_DIST_REGS ,KVM_VGIC_ATTR (offset,0 ), - val, write); + val, write, &error_abort); } static inline void kvm_gicr_access(GICv3State *s, int offset, int cpu,
@@ -101,7 +101,7 @@ static inline void kvm_gicr_access(GICv3State *s, int offset, int cpu, {kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_REDIST_REGS ,KVM_VGIC_ATTR (offset, s->cpu[cpu].gicr_typer), - val, write); + val, write, &error_abort); } static inline void kvm_gicc_access(GICv3State *s, uint64_t reg, int cpu,
@@ -109,7 +109,7 @@ static inline void kvm_gicc_access(GICv3State *s, uint64_t reg, int cpu, {kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS ,KVM_VGIC_ATTR (reg, s->cpu[cpu].gicr_typer), - val, write); + val, write, &error_abort); } static inline void kvm_gic_line_level_access(GICv3State *s, int irq, int cpu,
@@ -119,7 +119,7 @@ static inline void kvm_gic_line_level_access(GICv3State *s, int irq, int cpu,KVM_VGIC_ATTR (irq, s->cpu[cpu].gicr_typer) | (VGIC_LEVEL_INFO_LINE_LEVEL <<KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT ), - val, write); + val, write, &error_abort); }/* Loop through each distributor IRQ related register; since bits
@@ -630,7 +630,7 @@ static void arm_gicv3_icc_reset(CPUARMState *env, const ARMCPRegInfo *ri)/* Initialize to actual HW supported configuration */ kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS ,KVM_VGIC_ATTR (ICC_CTLR_EL1 , cpu->mp_affinity), - &c->icc_ctlr_el1[GICV3_NS ], false); + &c->icc_ctlr_el1[GICV3_NS ], false, &error_abort); c->icc_ctlr_el1[GICV3_S ] = c->icc_ctlr_el1[GICV3_NS ]; }
@@ -717,11 +717,11 @@ static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp) }kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_NR_IRQS , -0 , &s->num_irq, true); +0 , &s->num_irq, true, &error_abort);/* Tell the kernel to complete VGIC initialization now */ kvm_device_access (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_CTRL , -KVM_DEV_ARM_VGIC_CTRL_INIT ,NULL , true); +KVM_DEV_ARM_VGIC_CTRL_INIT ,NULL , true, &error_abort);kvm_arm_register_device (&s->iomem_dist,-1 ,KVM_DEV_ARM_VGIC_GRP_ADDR ,KVM_VGIC_V3_ADDR_TYPE_DIST , s->dev_fd);
include/sysemu/kvm.h +7 -4
@@ -294,12 +294,15 @@ int kvm_device_check_attr(int fd, uint32_t group, uint64_t attr);* @attr: the attribute of that group to set or get * @val: pointer to a storage area for the value * @write: true for set and false for get operation +* @errp: error object handle * -* This function is not allowed to fail. Use kvm_device_check_attr() -* in order to check for the availability of optional attributes. +* Returns: 0 on success +* < 0 on error +* Use kvm_device_check_attr() in order to check for the availability +* of optional attributes. */ -void kvm_device_access (int fd,int group,uint64_t attr, -void *val,bool write); +int kvm_device_access (int fd,int group,uint64_t attr, +void *val,bool write,Error **errp);/** * kvm_create_device - create a KVM device for the device control API
kvm-all.c +7 -6
@@ -23,6 +23,7 @@#include "qemu/option.h" #include "qemu/config-file.h" #include "qemu/error-report.h" +#include "qapi/error.h" #include "hw/hw.h" #include "hw/pci/msi.h" #include "hw/pci/msix.h"
@@ -2214,8 +2215,8 @@ int kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr)return kvm_device_ioctl (dev_fd,KVM_HAS_DEVICE_ATTR , &attribute) ?0 :1 ; } -void kvm_device_access (int fd,int group,uint64_t attr, -void *val,bool write) +int kvm_device_access (int fd,int group,uint64_t attr, +void *val,bool write,Error **errp) {struct kvm_device_attr kvmattr;int err;
@@ -2229,11 +2230,11 @@ void kvm_device_access(int fd, int group, uint64_t attr, write ?KVM_SET_DEVICE_ATTR :KVM_GET_DEVICE_ATTR , &kvmattr);if (err <0 ) { -error_report ("KVM_%s_DEVICE_ATTR failed: %s" , - write ?"SET" :"GET" ,strerror (-err)); -error_printf ("Group %d attr 0x%016" PRIx64"\n" , group, attr); -abort (); +error_setg_errno (errp, -err, +"KVM_%s_DEVICE_ATTR failed: Group %d attr 0x%016" PRIx64, + write ?"SET" :"GET" , group, attr); } +return err; }/* Return 1 on success, 0 on failure */
Signature · 1 line
2.5.5
PATCH v6 2/4 hw/intc/arm_gicv3_its: Implement state save/restore
In reply to Eric AugerWe need to handle both registers and ITS tables. While register handling is standard, ITS table handling is more challenging since the kernel API is devised so that the tables are flushed into guest RAM and not in vmstate buffers.
Flushing the ITS tables on device pre_save() is too late since the guest RAM is already saved at this point.
Table flushing needs to happen when we are sure the vcpus are stopped and before the last dirty page saving. The right point is RUN_STATE_FINISH_MIGRATE but sometimes the VM gets stopped before migration launch so let's simply flush the tables each time the VM gets stopped.
For regular ITS registers we just can use vmstate pre_save() and post_load() callbacks.
---
v5 -> v6:
- use &s->ctlr directly when writing GITS_CTLR
- don't abort on -EFAULT
- s->iidr reset in gicv3_its_common_reset
--- hw/intc/arm_gicv3_its_common.c | 10 ++++ hw/intc/arm_gicv3_its_kvm.c | 105 +++++++++++++++++++++++++++++++++ include/hw/intc/arm_gicv3_its_common.h | 8 +++ 3 files changed, 123 insertions(+)
hw/intc/arm_gicv3_its_common.c +10 -0
@@ -49,6 +49,15 @@ static const VMStateDescription vmstate_its = { .pre_save = gicv3_its_pre_save, .post_load = gicv3_its_post_load, .unmigratable = true, + .fields = (VMStateField []) { +VMSTATE_UINT32 (ctlr, GICv3ITSState), +VMSTATE_UINT32 (iidr, GICv3ITSState), +VMSTATE_UINT64 (cbaser, GICv3ITSState), +VMSTATE_UINT64 (cwriter, GICv3ITSState), +VMSTATE_UINT64 (creadr, GICv3ITSState), +VMSTATE_UINT64_ARRAY (baser, GICv3ITSState,8 ), +VMSTATE_END_OF_LIST () + }, }; static MemTxResult gicv3_its_trans_read(void *opaque, hwaddr offset,
@@ -118,6 +127,7 @@ static void gicv3_its_common_reset(DeviceState *dev) s->cbaser =0 ; s->cwriter =0 ; s->creadr =0 ; + s->iidr =0 ;memset (&s->baser,0 ,sizeof (s->baser));gicv3_its_post_load (s,0 );
hw/intc/arm_gicv3_its_kvm.c +105 -0
129 lines not on this page · raw message
include/hw/intc/arm_gicv3_its_common.h +8 -0
@@ -28,6 +28,13 @@#define ITS_TRANS_SIZE 0x10000#define ITS_SIZE (ITS_CONTROL_SIZE + ITS_TRANS_SIZE) +#define GITS_CTLR 0x0 +#define GITS_IIDR 0x4 +#define GITS_CBASER 0x80 +#define GITS_CWRITER 0x88 +#define GITS_CREADR 0x90 +#define GITS_BASER 0x100 +struct GICv3ITSState {SysBusDevice parent_obj;
@@ -43,6 +50,7 @@ struct GICv3ITSState {/* Registers */ uint32_t ctlr; +uint32_t iidr;uint64_t cbaser;uint64_t cwriter;uint64_t creadr;
Signature · 1 line
2.5.5
PATCH v6 3/4 hw/intc/arm_gicv3_kvm: Implement pending table save
In reply to Eric AugerThis patch adds the flush of the LPI pending bits into the redistributor pending tables. This happens on VM stop.
There is no explicit restore as the tables are implicitly sync'ed on ITS table restore and on LPI enable at redistributor level.
---
v5 -> v6:
- do not abort on -EFAULT
--- hw/intc/arm_gicv3_kvm.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
hw/intc/arm_gicv3_kvm.c +34 -0
@@ -25,6 +25,7 @@#include "hw/sysbus.h" #include "qemu/error-report.h" #include "sysemu/kvm.h" +#include "sysemu/sysemu.h" #include "kvm_arm.h" #include "gicv3_internal.h" #include "vgic_common.h"
@@ -680,6 +681,35 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = { REGINFO_SENTINEL }; +/** +* vm_change_state_handler - VM change state callback aiming at flushing +* RDIST pending tables into guest RAM +* +* The tables get flushed to guest RAM whenever the VM gets stopped. +*/ +static void vm_change_state_handler (void *opaque,int 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); + } +if (ret <0 && ret != -EFAULT ) { +abort (); + } +} + +static void kvm_arm_gicv3_realize (DeviceState *dev,Error **errp) {GICv3State *s =KVM_ARM_GICV3 (dev);
@@ -751,6 +781,10 @@ static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp)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); + } }static void kvm_arm_gicv3_class_init (ObjectClass *klass,void *data)
Signature · 1 line
2.5.5
PATCH v6 4/4 hw/intc/arm_gicv3_its: Allow save/restore
In reply to Eric AugerWe change the restoration priority of both the GICv3 and ITS. The GICv3 must be restored before the ITS and the ITS needs to be restored before PCIe devices since it translates their MSI transactions.
---
v5 -> v6:
- fix the migration_blocker message (s/vGICv3/vITS)
--- hw/intc/arm_gicv3_common.c | 1 + hw/intc/arm_gicv3_its_common.c | 2 +- hw/intc/arm_gicv3_its_kvm.c | 24 ++++++++++++------------ include/migration/vmstate.h | 2 ++ 4 files changed, 16 insertions(+), 13 deletions(-)
hw/intc/arm_gicv3_common.c +1 -0
@@ -145,6 +145,7 @@ static const VMStateDescription vmstate_gicv3 = { .minimum_version_id = 1, .pre_save = gicv3_pre_save, .post_load = gicv3_post_load, + .priority = MIG_PRI_GICV3, .fields = (VMStateField []) {VMSTATE_UINT32 (gicd_ctlr, GICv3State),VMSTATE_UINT32_ARRAY (gicd_statusr, GICv3State,2 ),
hw/intc/arm_gicv3_its_common.c +1 -1
@@ -48,7 +48,7 @@ static const VMStateDescription vmstate_its = { .name = "arm_gicv3_its", .pre_save = gicv3_its_pre_save, .post_load = gicv3_its_post_load, - .unmigratable = true, + .priority = MIG_PRI_GICV3_ITS, .fields = (VMStateField []) {VMSTATE_UINT32 (ctlr, GICv3ITSState),VMSTATE_UINT32 (iidr, GICv3ITSState),
hw/intc/arm_gicv3_its_kvm.c +12 -12
@@ -85,18 +85,6 @@ static void kvm_arm_its_realize(DeviceState *dev, Error **errp)GICv3ITSState *s =ARM_GICV3_ITS_COMMON (dev);Error *local_err =NULL ; -/* -* Block migration of a KVM GICv3 ITS device: the API for saving and -* restoring the state in the kernel is not yet available -*/ -error_setg (&s->migration_blocker,"vITS migration is not implemented" ); -migrate_add_blocker (s->migration_blocker, &local_err); -if (local_err) { -error_propagate (errp, local_err); -error_free (s->migration_blocker); -return ; - } - s->dev_fd =kvm_create_device (kvm_state,KVM_DEV_TYPE_ARM_VGIC_ITS , false);if (s->dev_fd <0 ) {error_setg_errno (errp, -s->dev_fd,"error creating in-kernel ITS" );
@@ -113,6 +101,18 @@ static void kvm_arm_its_realize(DeviceState *dev, Error **errp)gicv3_its_init_mmio (s,NULL ); +if (!kvm_device_check_attr (s->dev_fd,KVM_DEV_ARM_VGIC_GRP_ITS_REGS , +GITS_CTLR )) { +error_setg (&s->migration_blocker,"This operating system kernel " +"does not support vITS migration" ); +migrate_add_blocker (s->migration_blocker, &local_err); +if (local_err) { +error_propagate (errp, local_err); +error_free (s->migration_blocker); +return ; + } + } + kvm_msi_use_devid = true; kvm_gsi_direct_mapping = false; kvm_msi_via_irqfd_allowed =kvm_irqfds_enabled ();
include/migration/vmstate.h +2 -0
@@ -187,6 +187,8 @@ enum VMStateFlags {typedef enum {MIG_PRI_DEFAULT =0 ,MIG_PRI_IOMMU ,/* Must happen before PCI devices */ +MIG_PRI_GICV3_ITS ,/* Must happen before PCI devices */ +MIG_PRI_GICV3 ,/* Must happen before the ITS */ MIG_PRI_MAX , }MigrationPriority ;
Signature · 1 line
2.5.5
Re: [Qemu-arm] [PATCH v6 1/4] kvm-all: Pass an error object to kvm_device_access
In reply to Eric AugerQuoted 8 lines · Eric Auger
In some circumstances, we don't want to abort if the
kvm_device_accessfails. This will be the case during ITS migration, in case the ITS table save/restore fails because the guest did not program the vITS correctly. So let's pass an error object to the function and return the ioctl value. New callers will be able to make a decision upon this returned value.
Quoted 4 lines
Existing callers pass
&error_abortwhich will cause the function to abort on failure.Signed-off-by Eric Auger <[email protected]>
Re: [Qemu-arm] [Qemu-devel] [PATCH v6 1/4] kvm-all: Pass an error object to kvm_device_access
Hi Juan,
Quoted 9 lines · Juan Quintela
Quoted 8 lines · Eric Auger
In some circumstances, we don't want to abort if the
kvm_device_accessfails. This will be the case during ITS migration, in case the ITS table save/restore fails because the guest did not program the vITS correctly. So let's pass an error object to the function and return the ioctl value. New callers will be able to make a decision upon this returned value.
Quoted 6 lines
Quoted 4 lines
Existing callers pass
&error_abortwhich will cause the function to abort on failure.Signed-off-by Eric Auger <[email protected]>Reviewed-by Juan Quintela <[email protected]>
Thank you for the review!
Eric
Quoted 1 line
Re: [Qemu-arm] [PATCH v6 1/4] kvm-all: Pass an error object to kvm_device_access
In reply to Eric AugerQuoted 8 lines · Eric Auger
In some circumstances, we don't want to abort if the
kvm_device_accessfails. This will be the case during ITS migration, in case the ITS table save/restore fails because the guest did not program the vITS correctly. So let's pass an error object to the function and return the ioctl value. New callers will be able to make a decision upon this returned value.
Quoted 4 lines
Existing callers pass
&error_abortwhich will cause the function to abort on failure.Signed-off-by Eric Auger <[email protected]>
Signature · 1 line
Peter Xu
Peter Maydell
AppliedQuoted 11 lines · Eric Auger
This series allows ITS save/restore and migration use cases.
ITS tables are flushed into guest RAM on VM stop while registers are save on
pre_save()callback. Tables and registers are restored on ITSpost_load().Redistributor pending tables also are flushed on VM stop, independently on ITS tables.
That work was tested on Cavium ThunderX using virsh save/restore and virt-manager live migration.
Applied to target-arm.next, thanks.
-- PMM