Skip to content

Commit a98f26f

Browse files
Marc Zyngierchazy
authored andcommitted
arm/arm64: KVM: vgic: make number of irqs a configurable attribute
In order to make the number of interrupts configurable, use the new fancy device management API to add KVM_DEV_ARM_VGIC_GRP_NR_IRQS as a VGIC configurable attribute. Userspace can now specify the exact size of the GIC (by increments of 32 interrupts). Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent 4956f2b commit a98f26f

4 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎Documentation/virtual/kvm/devices/arm-vgic.txt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,13 @@ Groups:
7171
Errors:
7272
-ENODEV: Getting or setting this register is not yet supported
7373
-EBUSY: One or more VCPUs are running
74+
75+
KVM_DEV_ARM_VGIC_GRP_NR_IRQS
76+
Attributes:
77+
A value describing the number of interrupts (SGI, PPI and SPI) for
78+
this GIC instance, ranging from 64 to 1024, in increments of 32.
79+
80+
Errors:
81+
-EINVAL: Value set is out of the expected range
82+
-EBUSY: Value has already be set, or GIC has already been initialized
83+
with default values.

‎arch/arm/include/uapi/asm/kvm.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ struct kvm_arch_memory_slot {
174174
#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT)
175175
#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0
176176
#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)
177+
#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3
177178

178179
/* KVM_IRQ_LINE irq field index values */
179180
#define KVM_ARM_IRQ_TYPE_SHIFT 24

‎arch/arm64/include/uapi/asm/kvm.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ struct kvm_arch_memory_slot {
160160
#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT)
161161
#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0
162162
#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)
163+
#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3
163164

164165
/* KVM_IRQ_LINE irq field index values */
165166
#define KVM_ARM_IRQ_TYPE_SHIFT 24

‎virt/kvm/arm/vgic.c‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,6 +2253,36 @@ static int vgic_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
22532253

22542254
return vgic_attr_regs_access(dev, attr, &reg, true);
22552255
}
2256+
case KVM_DEV_ARM_VGIC_GRP_NR_IRQS: {
2257+
u32 __user *uaddr = (u32 __user *)(long)attr->addr;
2258+
u32 val;
2259+
int ret = 0;
2260+
2261+
if (get_user(val, uaddr))
2262+
return -EFAULT;
2263+
2264+
/*
2265+
* We require:
2266+
* - at least 32 SPIs on top of the 16 SGIs and 16 PPIs
2267+
* - at most 1024 interrupts
2268+
* - a multiple of 32 interrupts
2269+
*/
2270+
if (val < (VGIC_NR_PRIVATE_IRQS + 32) ||
2271+
val > VGIC_MAX_IRQS ||
2272+
(val & 31))
2273+
return -EINVAL;
2274+
2275+
mutex_lock(&dev->kvm->lock);
2276+
2277+
if (vgic_initialized(dev->kvm) || dev->kvm->arch.vgic.nr_irqs)
2278+
ret = -EBUSY;
2279+
else
2280+
dev->kvm->arch.vgic.nr_irqs = val;
2281+
2282+
mutex_unlock(&dev->kvm->lock);
2283+
2284+
return ret;
2285+
}
22562286

22572287
}
22582288

@@ -2289,6 +2319,11 @@ static int vgic_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
22892319
r = put_user(reg, uaddr);
22902320
break;
22912321
}
2322+
case KVM_DEV_ARM_VGIC_GRP_NR_IRQS: {
2323+
u32 __user *uaddr = (u32 __user *)(long)attr->addr;
2324+
r = put_user(dev->kvm->arch.vgic.nr_irqs, uaddr);
2325+
break;
2326+
}
22922327

22932328
}
22942329

@@ -2325,6 +2360,8 @@ static int vgic_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
23252360
case KVM_DEV_ARM_VGIC_GRP_CPU_REGS:
23262361
offset = attr->attr & KVM_DEV_ARM_VGIC_OFFSET_MASK;
23272362
return vgic_has_attr_regs(vgic_cpu_ranges, offset);
2363+
case KVM_DEV_ARM_VGIC_GRP_NR_IRQS:
2364+
return 0;
23282365
}
23292366
return -ENXIO;
23302367
}

0 commit comments

Comments
 (0)