Add an interface to override the default irq offset (KVM_IRQ_OFFSET) as long as no interrupt lines have been allocated. By default, KVM_IRQ_OFFSET is applied to all allocated interrupt lines, but calling irq__init_irq_offset() prior to allocating any interrupt lines allows this default offset to be overridden. Attempts to change the offset once lines have been allocated are intentionally rejected. This is part of GICv5-enablement as GICv5 SPIs count from 0, whilst older Arm GICs count from 32. Therefore, on a GICv5 system there is no shift that gets applied to the SPI ID, and hence we need to start counting from 0 to ensure correct alignment between kvmtool and Linux. Signed-off-by: Sascha Bischoff --- include/kvm/irq.h | 1 + irq.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/kvm/irq.h b/include/kvm/irq.h index 2a3f8c9d..17113979 100644 --- a/include/kvm/irq.h +++ b/include/kvm/irq.h @@ -23,6 +23,7 @@ extern struct msi_routing_ops *msi_routing_ops; extern struct kvm_irq_routing *irq_routing; extern int next_gsi; +int irq__init_irq_offset(u8 offset); int irq__alloc_line(void); int irq__get_nr_allocated_lines(void); diff --git a/irq.c b/irq.c index cdcf9923..8b9daa91 100644 --- a/irq.c +++ b/irq.c @@ -8,6 +8,7 @@ #include "kvm/irq.h" #include "kvm/kvm-arch.h" +static u8 irq_offset = KVM_IRQ_OFFSET; static u8 next_line = KVM_IRQ_OFFSET; static int allocated_gsis = 0; @@ -18,6 +19,19 @@ struct msi_routing_ops *msi_routing_ops = &irq__default_routing_ops; struct kvm_irq_routing *irq_routing = NULL; +/* Override the default KVM_IRQ_OFFSET */ +int irq__init_irq_offset(u8 offset) +{ + /* Block attempt to do this too late */ + if (irq__get_nr_allocated_lines()) + return -EBUSY; + + irq_offset = offset; + next_line = offset; + + return 0; +} + int irq__alloc_line(void) { return next_line++; @@ -25,7 +39,7 @@ int irq__alloc_line(void) int irq__get_nr_allocated_lines(void) { - return next_line - KVM_IRQ_OFFSET; + return next_line - irq_offset; } int irq__allocate_routing_entry(void) -- 2.34.1