Skip to content

Commit 92f35b7

Browse files
author
Marc Zyngier
committed
KVM: arm/arm64: vgic: Allow more than 256 vcpus for KVM_IRQ_LINE
While parts of the VGIC support a large number of vcpus (we bravely allow up to 512), other parts are more limited. One of these limits is visible in the KVM_IRQ_LINE ioctl, which only allows 256 vcpus to be signalled when using the CPU or PPI types. Unfortunately, we've cornered ourselves badly by allocating all the bits in the irq field. Since the irq_type subfield (8 bit wide) is currently only taking the values 0, 1 and 2 (and we have been careful not to allow anything else), let's reduce this field to only 4 bits, and allocate the remaining 4 bits to a vcpu2_index, which acts as a multiplier: vcpu_id = 256 * vcpu2_index + vcpu_index With that, and a new capability (KVM_CAP_ARM_IRQ_LINE_LAYOUT_2) allowing this to be discovered, it becomes possible to inject PPIs to up to 4096 vcpus. But please just don't. Whilst we're there, add a clarification about the use of KVM_IRQ_LINE on arm, which is not completely conditionned by KVM_CAP_IRQCHIP. Reported-by: Zenghui Yu <yuzenghui@huawei.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Reviewed-by: Zenghui Yu <yuzenghui@huawei.com> Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent e8688ba commit 92f35b7

5 files changed

Lines changed: 19 additions & 4 deletions

File tree

‎Documentation/virt/kvm/api.txt‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,8 @@ in-kernel irqchip (GIC), and for in-kernel irqchip can tell the GIC to
753753
use PPIs designated for specific cpus. The irq field is interpreted
754754
like this:
755755

756-
 bits: | 31 ... 24 | 23 ... 16 | 15 ... 0 |
757-
field: | irq_type | vcpu_index | irq_id |
756+
 bits: | 31 ... 28 | 27 ... 24 | 23 ... 16 | 15 ... 0 |
757+
field: | vcpu2_index | irq_type | vcpu_index | irq_id |
758758

759759
The irq_type field has the following values:
760760
- irq_type[0]: out-of-kernel GIC: irq_id 0 is IRQ, irq_id 1 is FIQ
@@ -766,6 +766,14 @@ The irq_type field has the following values:
766766

767767
In both cases, level is used to assert/deassert the line.
768768

769+
When KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 is supported, the target vcpu is
770+
identified as (256 * vcpu2_index + vcpu_index). Otherwise, vcpu2_index
771+
must be zero.
772+
773+
Note that on arm/arm64, the KVM_CAP_IRQCHIP capability only conditions
774+
injection of interrupts for the in-kernel irqchip. KVM_IRQ_LINE can always
775+
be used for a userspace interrupt controller.
776+
769777
struct kvm_irq_level {
770778
union {
771779
__u32 irq; /* GSI */

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,10 @@ struct kvm_vcpu_events {
266266
#define KVM_DEV_ARM_ITS_CTRL_RESET 4
267267

268268
/* KVM_IRQ_LINE irq field index values */
269+
#define KVM_ARM_IRQ_VCPU2_SHIFT 28
270+
#define KVM_ARM_IRQ_VCPU2_MASK 0xf
269271
#define KVM_ARM_IRQ_TYPE_SHIFT 24
270-
#define KVM_ARM_IRQ_TYPE_MASK 0xff
272+
#define KVM_ARM_IRQ_TYPE_MASK 0xf
271273
#define KVM_ARM_IRQ_VCPU_SHIFT 16
272274
#define KVM_ARM_IRQ_VCPU_MASK 0xff
273275
#define KVM_ARM_IRQ_NUM_SHIFT 0

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ struct kvm_vcpu_events {
325325
#define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1
326326

327327
/* KVM_IRQ_LINE irq field index values */
328+
#define KVM_ARM_IRQ_VCPU2_SHIFT 28
329+
#define KVM_ARM_IRQ_VCPU2_MASK 0xf
328330
#define KVM_ARM_IRQ_TYPE_SHIFT 24
329-
#define KVM_ARM_IRQ_TYPE_MASK 0xff
331+
#define KVM_ARM_IRQ_TYPE_MASK 0xf
330332
#define KVM_ARM_IRQ_VCPU_SHIFT 16
331333
#define KVM_ARM_IRQ_VCPU_MASK 0xff
332334
#define KVM_ARM_IRQ_NUM_SHIFT 0

‎include/uapi/linux/kvm.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ struct kvm_ppc_resize_hpt {
996996
#define KVM_CAP_ARM_PTRAUTH_ADDRESS 171
997997
#define KVM_CAP_ARM_PTRAUTH_GENERIC 172
998998
#define KVM_CAP_PMU_EVENT_FILTER 173
999+
#define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
9991000

10001001
#ifdef KVM_CAP_IRQ_ROUTING
10011002

‎virt/kvm/arm/arm.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
196196
case KVM_CAP_MP_STATE:
197197
case KVM_CAP_IMMEDIATE_EXIT:
198198
case KVM_CAP_VCPU_EVENTS:
199+
case KVM_CAP_ARM_IRQ_LINE_LAYOUT_2:
199200
r = 1;
200201
break;
201202
case KVM_CAP_ARM_SET_DEVICE_ADDR:
@@ -888,6 +889,7 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
888889

889890
irq_type = (irq >> KVM_ARM_IRQ_TYPE_SHIFT) & KVM_ARM_IRQ_TYPE_MASK;
890891
vcpu_idx = (irq >> KVM_ARM_IRQ_VCPU_SHIFT) & KVM_ARM_IRQ_VCPU_MASK;
892+
vcpu_idx += ((irq >> KVM_ARM_IRQ_VCPU2_SHIFT) & KVM_ARM_IRQ_VCPU2_MASK) * (KVM_ARM_IRQ_VCPU_MASK + 1);
891893
irq_num = (irq >> KVM_ARM_IRQ_NUM_SHIFT) & KVM_ARM_IRQ_NUM_MASK;
892894

893895
trace_kvm_irq_line(irq_type, vcpu_idx, irq_num, irq_level->level);

0 commit comments

Comments
 (0)