Skip to content

Commit 619064a

Browse files
author
Marc Zyngier
committed
KVM: arm64: vgic: Tidy-up calls to vgic_{get,set}_common_attr()
The userspace accessors have an early call to vgic_{get,set}_common_attr() that makes the code hard to follow. Move it to the default: clause of the decoding switch statement, which results in a nice cleanup. This requires us to move the handling of the pending table into the common handling, even if it is strictly a GICv3 feature (it has the benefit of keeping the whole control group handling in the same function). Also cleanup vgic_v3_{get,set}_attr() while we're at it, deduplicating the calls to vgic_v3_attr_regs_access(). Suggested-by: Reiji Watanabe <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 4b85080 commit 619064a

File tree

1 file changed

+26
-52
lines changed

1 file changed

+26
-52
lines changed

arch/arm64/kvm/vgic/vgic-kvm-device.c

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,24 @@ static int vgic_set_common_attr(struct kvm_device *dev,
246246
r = vgic_init(dev->kvm);
247247
mutex_unlock(&dev->kvm->lock);
248248
return r;
249+
case KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES:
250+
/*
251+
* OK, this one isn't common at all, but we
252+
* want to handle all control group attributes
253+
* in a single place.
254+
*/
255+
if (vgic_check_type(dev->kvm, KVM_DEV_TYPE_ARM_VGIC_V3))
256+
return -ENXIO;
257+
mutex_lock(&dev->kvm->lock);
258+
259+
if (!lock_all_vcpus(dev->kvm)) {
260+
mutex_unlock(&dev->kvm->lock);
261+
return -EBUSY;
262+
}
263+
r = vgic_v3_save_pending_tables(dev->kvm);
264+
unlock_all_vcpus(dev->kvm);
265+
mutex_unlock(&dev->kvm->lock);
266+
return r;
249267
}
250268
break;
251269
}
@@ -427,37 +445,25 @@ static int vgic_v2_attr_regs_access(struct kvm_device *dev,
427445
static int vgic_v2_set_attr(struct kvm_device *dev,
428446
struct kvm_device_attr *attr)
429447
{
430-
int ret;
431-
432-
ret = vgic_set_common_attr(dev, attr);
433-
if (ret != -ENXIO)
434-
return ret;
435-
436448
switch (attr->group) {
437449
case KVM_DEV_ARM_VGIC_GRP_DIST_REGS:
438450
case KVM_DEV_ARM_VGIC_GRP_CPU_REGS:
439451
return vgic_v2_attr_regs_access(dev, attr, true);
452+
default:
453+
return vgic_set_common_attr(dev, attr);
440454
}
441-
442-
return -ENXIO;
443455
}
444456

445457
static int vgic_v2_get_attr(struct kvm_device *dev,
446458
struct kvm_device_attr *attr)
447459
{
448-
int ret;
449-
450-
ret = vgic_get_common_attr(dev, attr);
451-
if (ret != -ENXIO)
452-
return ret;
453-
454460
switch (attr->group) {
455461
case KVM_DEV_ARM_VGIC_GRP_DIST_REGS:
456462
case KVM_DEV_ARM_VGIC_GRP_CPU_REGS:
457463
return vgic_v2_attr_regs_access(dev, attr, false);
464+
default:
465+
return vgic_get_common_attr(dev, attr);
458466
}
459-
460-
return -ENXIO;
461467
}
462468

463469
static int vgic_v2_has_attr(struct kvm_device *dev,
@@ -618,61 +624,29 @@ static int vgic_v3_attr_regs_access(struct kvm_device *dev,
618624
static int vgic_v3_set_attr(struct kvm_device *dev,
619625
struct kvm_device_attr *attr)
620626
{
621-
int ret;
622-
623-
ret = vgic_set_common_attr(dev, attr);
624-
if (ret != -ENXIO)
625-
return ret;
626-
627627
switch (attr->group) {
628628
case KVM_DEV_ARM_VGIC_GRP_DIST_REGS:
629629
case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS:
630-
return vgic_v3_attr_regs_access(dev, attr, true);
631630
case KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS:
632-
return vgic_v3_attr_regs_access(dev, attr, true);
633631
case KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO:
634632
return vgic_v3_attr_regs_access(dev, attr, true);
635-
case KVM_DEV_ARM_VGIC_GRP_CTRL: {
636-
int ret;
637-
638-
switch (attr->attr) {
639-
case KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES:
640-
mutex_lock(&dev->kvm->lock);
641-
642-
if (!lock_all_vcpus(dev->kvm)) {
643-
mutex_unlock(&dev->kvm->lock);
644-
return -EBUSY;
645-
}
646-
ret = vgic_v3_save_pending_tables(dev->kvm);
647-
unlock_all_vcpus(dev->kvm);
648-
mutex_unlock(&dev->kvm->lock);
649-
return ret;
650-
}
651-
break;
652-
}
633+
default:
634+
return vgic_set_common_attr(dev, attr);
653635
}
654-
return -ENXIO;
655636
}
656637

657638
static int vgic_v3_get_attr(struct kvm_device *dev,
658639
struct kvm_device_attr *attr)
659640
{
660-
int ret;
661-
662-
ret = vgic_get_common_attr(dev, attr);
663-
if (ret != -ENXIO)
664-
return ret;
665-
666641
switch (attr->group) {
667642
case KVM_DEV_ARM_VGIC_GRP_DIST_REGS:
668643
case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS:
669-
return vgic_v3_attr_regs_access(dev, attr, false);
670644
case KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS:
671-
return vgic_v3_attr_regs_access(dev, attr, false);
672645
case KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO:
673646
return vgic_v3_attr_regs_access(dev, attr, false);
647+
default:
648+
return vgic_get_common_attr(dev, attr);
674649
}
675-
return -ENXIO;
676650
}
677651

678652
static int vgic_v3_has_attr(struct kvm_device *dev,

0 commit comments

Comments
 (0)