Introduce a new group aiming at saving/restoring the ITS tables to/from the guest memory. We hold the vcpus lock during the save and restore to make sure no vcpu is running. At this stage the functionality is not yet implemented. Only the skeleton is put in place. The ABI revision supposed to have been set through IIDR user write is checked before the table restoration. This guarantees this vITS knows how to restore the saved tables. Signed-off-by: Eric Auger <eric.auger@xxxxxxxxxx> --- v3 -> v4: - pass kvm struct handle to vgic_its_flush/restore_pending_tables - take the kvm lock and vcpu locks - ABI revision check - check attr->attr is null v1 -> v2: - remove useless kvm parameter --- arch/arm/include/uapi/asm/kvm.h | 1 + arch/arm64/include/uapi/asm/kvm.h | 1 + virt/kvm/arm/vgic/vgic-its.c | 142 +++++++++++++++++++++++++++++++++++++- 3 files changed, 143 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/uapi/asm/kvm.h b/arch/arm/include/uapi/asm/kvm.h index 4beb83b..7b165e9 100644 --- a/arch/arm/include/uapi/asm/kvm.h +++ b/arch/arm/include/uapi/asm/kvm.h @@ -193,6 +193,7 @@ struct kvm_arch_memory_slot { #define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6 #define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 #define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8 +#define KVM_DEV_ARM_VGIC_GRP_ITS_TABLES 9 #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10 #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT) diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index 7e8dd69..166df68 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -213,6 +213,7 @@ struct kvm_arch_memory_slot { #define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6 #define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 #define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8 +#define KVM_DEV_ARM_VGIC_GRP_ITS_TABLES 9 #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10 #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index b275aea..76dd562 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -1627,6 +1627,135 @@ int vgic_its_attr_regs_access(struct kvm_device *dev, return ret; } +/** + * vgic_its_flush_pending_tables - Flush the pending tables into guest RAM + */ +static int vgic_its_flush_pending_tables(struct kvm *kvm) +{ + return -ENXIO; +} + +/** + * vgic_its_restore_pending_tables - Restore the pending tables from guest + * RAM to internal data structs + */ +static int vgic_its_restore_pending_tables(struct kvm *kvm) +{ + return -ENXIO; +} + +/** + * vgic_its_flush_device_tables - flush the device table and all ITT + * into guest RAM + */ +static int vgic_its_flush_device_tables(struct vgic_its *its) +{ + return -ENXIO; +} + +/** + * vgic_its_restore_device_tables - restore the device table and all ITT + * from guest RAM to internal data structs + */ +static int vgic_its_restore_device_tables(struct vgic_its *its) +{ + return -ENXIO; +} + +/** + * vgic_its_flush_collection_table - flush the collection table into + * guest RAM + */ +static int vgic_its_flush_collection_table(struct vgic_its *its) +{ + return -ENXIO; +} + +/** + * vgic_its_restore_collection_table - reads the collection table + * in guest memory and restores the ITS internal state. Requires the + * BASER registers to be restored before. + */ +static int vgic_its_restore_collection_table(struct vgic_its *its) +{ + return -ENXIO; +} + +/** + * vgic_its_table_flush - Flush all the tables into guest RAM + */ +static int vgic_its_table_flush(struct vgic_its *its) +{ + struct kvm *kvm = its->dev->kvm; + int ret; + + mutex_lock(&kvm->lock); + + if (!lock_all_vcpus(kvm)) { + mutex_unlock(&kvm->lock); + return -EBUSY; + } + + ret = vgic_its_flush_pending_tables(kvm); + if (ret) + goto out; + ret = vgic_its_flush_device_tables(its); + if (ret) + goto out; + + ret = vgic_its_flush_collection_table(its); + +out: + unlock_all_vcpus(kvm); + mutex_unlock(&kvm->lock); + return ret; +} + +/** + * vgic_its_table_restore - Restore all tables from guest RAM to internal + * data structs + */ +static int vgic_its_table_restore(struct vgic_its *its) +{ + struct kvm *kvm = its->dev->kvm; + int ret; + + mutex_lock(&kvm->lock); + + if (its->user_revision < REV) { + mutex_unlock(&kvm->lock); + return -EINVAL; + } + + if (!lock_all_vcpus(kvm)) { + mutex_unlock(&kvm->lock); + return -EBUSY; + } + + ret = vgic_its_restore_collection_table(its); + if (ret) + goto out; + + ret = vgic_its_restore_device_tables(its); + if (ret) + goto out; + + ret = vgic_its_restore_pending_tables(kvm); + +out: + unlock_all_vcpus(kvm); + mutex_unlock(&kvm->lock); + + if (ret) + return ret; + + /* + * On restore path, MSI injections can happen before the + * first VCPU run so let's complete the GIC init here. + */ + return kvm_vgic_map_resources(its->dev->kvm); +} + static int vgic_its_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr) { @@ -1645,6 +1774,8 @@ static int vgic_its_has_attr(struct kvm_device *dev, break; case KVM_DEV_ARM_VGIC_GRP_ITS_REGS: return vgic_its_has_attr_regs(dev, attr); + case KVM_DEV_ARM_VGIC_GRP_ITS_TABLES: + return 0; } return -ENXIO; } @@ -1693,6 +1824,10 @@ static int vgic_its_set_attr(struct kvm_device *dev, return vgic_its_attr_regs_access(dev, attr, ®, true); } + case KVM_DEV_ARM_VGIC_GRP_ITS_TABLES: + if (attr->attr) + return -EINVAL; + return vgic_its_table_restore(its); } return -ENXIO; } @@ -1700,9 +1835,10 @@ static int vgic_its_set_attr(struct kvm_device *dev, static int vgic_its_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr) { + struct vgic_its *its = dev->private; + switch (attr->group) { case KVM_DEV_ARM_VGIC_GRP_ADDR: { - struct vgic_its *its = dev->private; u64 addr = its->vgic_its_base; u64 __user *uaddr = (u64 __user *)(long)attr->addr; unsigned long type = (unsigned long)attr->attr; @@ -1723,6 +1859,10 @@ static int vgic_its_get_attr(struct kvm_device *dev, if (ret) return ret; return put_user(reg, uaddr); + case KVM_DEV_ARM_VGIC_GRP_ITS_TABLES: + if (attr->attr) + return -EINVAL; + return vgic_its_table_flush(its); } default: return -ENXIO; -- 2.5.5