forked from luck/tmp_suning_uos_patched
KVM: arm/arm64: vgic-its: Implement KVM_DEV_ARM_ITS_CTRL_RESET
On reset we clear the valid bits of GITS_CBASER and GITS_BASER<n>. We also clear command queue registers and free the cache (device, collection, and lpi lists). As we need to take the same locks as save/restore functions, we create a vgic_its_ctrl() wrapper that handles KVM_DEV_ARM_VGIC_GRP_CTRL group functions. Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Eric Auger <eric.auger@redhat.com> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
This commit is contained in:
parent
ae204f80ca
commit
3eb4271b4a
|
@ -221,6 +221,7 @@ struct kvm_arch_memory_slot {
|
||||||
#define KVM_DEV_ARM_ITS_SAVE_TABLES 1
|
#define KVM_DEV_ARM_ITS_SAVE_TABLES 1
|
||||||
#define KVM_DEV_ARM_ITS_RESTORE_TABLES 2
|
#define KVM_DEV_ARM_ITS_RESTORE_TABLES 2
|
||||||
#define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3
|
#define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3
|
||||||
|
#define KVM_DEV_ARM_ITS_CTRL_RESET 4
|
||||||
|
|
||||||
/* KVM_IRQ_LINE irq field index values */
|
/* KVM_IRQ_LINE irq field index values */
|
||||||
#define KVM_ARM_IRQ_TYPE_SHIFT 24
|
#define KVM_ARM_IRQ_TYPE_SHIFT 24
|
||||||
|
|
|
@ -233,6 +233,7 @@ struct kvm_arch_memory_slot {
|
||||||
#define KVM_DEV_ARM_ITS_SAVE_TABLES 1
|
#define KVM_DEV_ARM_ITS_SAVE_TABLES 1
|
||||||
#define KVM_DEV_ARM_ITS_RESTORE_TABLES 2
|
#define KVM_DEV_ARM_ITS_RESTORE_TABLES 2
|
||||||
#define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3
|
#define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3
|
||||||
|
#define KVM_DEV_ARM_ITS_CTRL_RESET 4
|
||||||
|
|
||||||
/* Device Control API on vcpu fd */
|
/* Device Control API on vcpu fd */
|
||||||
#define KVM_ARM_VCPU_PMU_V3_CTRL 0
|
#define KVM_ARM_VCPU_PMU_V3_CTRL 0
|
||||||
|
|
|
@ -2273,29 +2273,13 @@ static int vgic_its_restore_collection_table(struct vgic_its *its)
|
||||||
*/
|
*/
|
||||||
static int vgic_its_save_tables_v0(struct vgic_its *its)
|
static int vgic_its_save_tables_v0(struct vgic_its *its)
|
||||||
{
|
{
|
||||||
struct kvm *kvm = its->dev->kvm;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
mutex_lock(&kvm->lock);
|
|
||||||
mutex_lock(&its->its_lock);
|
|
||||||
|
|
||||||
if (!lock_all_vcpus(kvm)) {
|
|
||||||
mutex_unlock(&its->its_lock);
|
|
||||||
mutex_unlock(&kvm->lock);
|
|
||||||
return -EBUSY;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = vgic_its_save_device_tables(its);
|
ret = vgic_its_save_device_tables(its);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
return ret;
|
||||||
|
|
||||||
ret = vgic_its_save_collection_table(its);
|
return vgic_its_save_collection_table(its);
|
||||||
|
|
||||||
out:
|
|
||||||
unlock_all_vcpus(kvm);
|
|
||||||
mutex_unlock(&its->its_lock);
|
|
||||||
mutex_unlock(&kvm->lock);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2305,29 +2289,13 @@ static int vgic_its_save_tables_v0(struct vgic_its *its)
|
||||||
*/
|
*/
|
||||||
static int vgic_its_restore_tables_v0(struct vgic_its *its)
|
static int vgic_its_restore_tables_v0(struct vgic_its *its)
|
||||||
{
|
{
|
||||||
struct kvm *kvm = its->dev->kvm;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
mutex_lock(&kvm->lock);
|
|
||||||
mutex_lock(&its->its_lock);
|
|
||||||
|
|
||||||
if (!lock_all_vcpus(kvm)) {
|
|
||||||
mutex_unlock(&its->its_lock);
|
|
||||||
mutex_unlock(&kvm->lock);
|
|
||||||
return -EBUSY;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = vgic_its_restore_collection_table(its);
|
ret = vgic_its_restore_collection_table(its);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
return ret;
|
||||||
|
|
||||||
ret = vgic_its_restore_device_tables(its);
|
return vgic_its_restore_device_tables(its);
|
||||||
out:
|
|
||||||
unlock_all_vcpus(kvm);
|
|
||||||
mutex_unlock(&its->its_lock);
|
|
||||||
mutex_unlock(&kvm->lock);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vgic_its_commit_v0(struct vgic_its *its)
|
static int vgic_its_commit_v0(struct vgic_its *its)
|
||||||
|
@ -2346,6 +2314,19 @@ static int vgic_its_commit_v0(struct vgic_its *its)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void vgic_its_reset(struct kvm *kvm, struct vgic_its *its)
|
||||||
|
{
|
||||||
|
/* We need to keep the ABI specific field values */
|
||||||
|
its->baser_coll_table &= ~GITS_BASER_VALID;
|
||||||
|
its->baser_device_table &= ~GITS_BASER_VALID;
|
||||||
|
its->cbaser = 0;
|
||||||
|
its->creadr = 0;
|
||||||
|
its->cwriter = 0;
|
||||||
|
its->enabled = 0;
|
||||||
|
vgic_its_free_device_list(kvm, its);
|
||||||
|
vgic_its_free_collection_list(kvm, its);
|
||||||
|
}
|
||||||
|
|
||||||
static int vgic_its_has_attr(struct kvm_device *dev,
|
static int vgic_its_has_attr(struct kvm_device *dev,
|
||||||
struct kvm_device_attr *attr)
|
struct kvm_device_attr *attr)
|
||||||
{
|
{
|
||||||
|
@ -2360,6 +2341,8 @@ static int vgic_its_has_attr(struct kvm_device *dev,
|
||||||
switch (attr->attr) {
|
switch (attr->attr) {
|
||||||
case KVM_DEV_ARM_VGIC_CTRL_INIT:
|
case KVM_DEV_ARM_VGIC_CTRL_INIT:
|
||||||
return 0;
|
return 0;
|
||||||
|
case KVM_DEV_ARM_ITS_CTRL_RESET:
|
||||||
|
return 0;
|
||||||
case KVM_DEV_ARM_ITS_SAVE_TABLES:
|
case KVM_DEV_ARM_ITS_SAVE_TABLES:
|
||||||
return 0;
|
return 0;
|
||||||
case KVM_DEV_ARM_ITS_RESTORE_TABLES:
|
case KVM_DEV_ARM_ITS_RESTORE_TABLES:
|
||||||
|
@ -2372,6 +2355,41 @@ static int vgic_its_has_attr(struct kvm_device *dev,
|
||||||
return -ENXIO;
|
return -ENXIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int vgic_its_ctrl(struct kvm *kvm, struct vgic_its *its, u64 attr)
|
||||||
|
{
|
||||||
|
const struct vgic_its_abi *abi = vgic_its_get_abi(its);
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if (attr == KVM_DEV_ARM_VGIC_CTRL_INIT) /* Nothing to do */
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
mutex_lock(&kvm->lock);
|
||||||
|
mutex_lock(&its->its_lock);
|
||||||
|
|
||||||
|
if (!lock_all_vcpus(kvm)) {
|
||||||
|
mutex_unlock(&its->its_lock);
|
||||||
|
mutex_unlock(&kvm->lock);
|
||||||
|
return -EBUSY;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (attr) {
|
||||||
|
case KVM_DEV_ARM_ITS_CTRL_RESET:
|
||||||
|
vgic_its_reset(kvm, its);
|
||||||
|
break;
|
||||||
|
case KVM_DEV_ARM_ITS_SAVE_TABLES:
|
||||||
|
ret = abi->save_tables(its);
|
||||||
|
break;
|
||||||
|
case KVM_DEV_ARM_ITS_RESTORE_TABLES:
|
||||||
|
ret = abi->restore_tables(its);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
unlock_all_vcpus(kvm);
|
||||||
|
mutex_unlock(&its->its_lock);
|
||||||
|
mutex_unlock(&kvm->lock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int vgic_its_set_attr(struct kvm_device *dev,
|
static int vgic_its_set_attr(struct kvm_device *dev,
|
||||||
struct kvm_device_attr *attr)
|
struct kvm_device_attr *attr)
|
||||||
{
|
{
|
||||||
|
@ -2397,19 +2415,8 @@ static int vgic_its_set_attr(struct kvm_device *dev,
|
||||||
|
|
||||||
return vgic_register_its_iodev(dev->kvm, its, addr);
|
return vgic_register_its_iodev(dev->kvm, its, addr);
|
||||||
}
|
}
|
||||||
case KVM_DEV_ARM_VGIC_GRP_CTRL: {
|
case KVM_DEV_ARM_VGIC_GRP_CTRL:
|
||||||
const struct vgic_its_abi *abi = vgic_its_get_abi(its);
|
return vgic_its_ctrl(dev->kvm, its, attr->attr);
|
||||||
|
|
||||||
switch (attr->attr) {
|
|
||||||
case KVM_DEV_ARM_VGIC_CTRL_INIT:
|
|
||||||
/* Nothing to do */
|
|
||||||
return 0;
|
|
||||||
case KVM_DEV_ARM_ITS_SAVE_TABLES:
|
|
||||||
return abi->save_tables(its);
|
|
||||||
case KVM_DEV_ARM_ITS_RESTORE_TABLES:
|
|
||||||
return abi->restore_tables(its);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case KVM_DEV_ARM_VGIC_GRP_ITS_REGS: {
|
case KVM_DEV_ARM_VGIC_GRP_ITS_REGS: {
|
||||||
u64 __user *uaddr = (u64 __user *)(long)attr->addr;
|
u64 __user *uaddr = (u64 __user *)(long)attr->addr;
|
||||||
u64 reg;
|
u64 reg;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user