From 30549a59c74e09e3cad8fc0bd9df7eebe21d4ad8 Mon Sep 17 00:00:00 2001 From: Edwin Zhai Date: Tue, 15 May 2018 09:32:29 +0800 Subject: [PATCH] DM: increase vioapic pin count Current only 8 vioapic pins for pci irq (total 24 with 16 reserved), which easily leads virtual GSI sharing with more and more passthrough devices. This patch doulbes vioapic pin count and adds reboot hooks to allocate from same pin after each reboot. Signed-off-by: Edwin Zhai Reviewed-by: Yin Fengwei Reviewed-by: Jason Chen CJ Reviewed-by: Eddie Dong Reviewed-by: Anthony Xu --- devicemodel/core/main.c | 2 ++ devicemodel/core/vmmapi.c | 7 ------ devicemodel/hw/platform/ioapic.c | 29 ++++++++++++------------ devicemodel/include/ioapic.h | 1 + devicemodel/include/public/acrn_common.h | 7 ++++++ devicemodel/include/vmmapi.h | 1 - 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index e4e568e24..d1d693bdb 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -501,6 +501,7 @@ vrtc_fail: ioc_deinit(ctx); atkbdc_deinit(ctx); pci_irq_deinit(ctx); + ioapic_deinit(); return -1; } @@ -514,6 +515,7 @@ vm_deinit_vdevs(struct vmctx *ctx) ioc_deinit(ctx); atkbdc_deinit(ctx); pci_irq_deinit(ctx); + ioapic_deinit(); } static void diff --git a/devicemodel/core/vmmapi.c b/devicemodel/core/vmmapi.c index 870429dd6..1c09f6257 100644 --- a/devicemodel/core/vmmapi.c +++ b/devicemodel/core/vmmapi.c @@ -618,13 +618,6 @@ vm_isa_pulse_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq) return vm_isa_irq(ctx, atpic_irq, ioapic_irq, IC_PULSE_IRQLINE); } -int -vm_ioapic_pincount(struct vmctx *ctx, int *pincount) -{ - *pincount = 24; - return 0; -} - int vm_assign_ptdev(struct vmctx *ctx, int bus, int slot, int func) { diff --git a/devicemodel/hw/platform/ioapic.c b/devicemodel/hw/platform/ioapic.c index ff5cb4b27..728679d6f 100644 --- a/devicemodel/hw/platform/ioapic.c +++ b/devicemodel/hw/platform/ioapic.c @@ -36,6 +36,9 @@ #include "pci_core.h" #include "lpc.h" +/* 16 IRQs reserved for kdb/mouse, COM1/2, RTC... */ +#define LEGACY_IRQ_NUM 16 + /* * Assign PCI INTx interrupts to I/O APIC pins in a round-robin * fashion. Note that we have no idea what the HPET is using, but the @@ -46,29 +49,27 @@ * PCI devices. */ static int pci_pins; +static int last_pin; void ioapic_init(struct vmctx *ctx) { - if (vm_ioapic_pincount(ctx, &pci_pins) < 0) { - pci_pins = 0; - return; - } + last_pin = 0; - /* Ignore the first 16 pins. */ - if (pci_pins <= 16) { - pci_pins = 0; - return; - } - pci_pins -= 16; + /* Ignore the first 16 pins for legacy IRQ. */ + pci_pins = VIOAPIC_RTE_NUM - LEGACY_IRQ_NUM; +} + +void ioapic_deinit(void) +{ + last_pin = 0; } int ioapic_pci_alloc_irq(struct pci_vdev *dev) { - static int last_pin; + /* No support of vGSI sharing */ + assert(last_pin < pci_pins); - if (pci_pins == 0) - return -1; - return (16 + (last_pin++ % pci_pins)); + return (LEGACY_IRQ_NUM + (last_pin++ % pci_pins)); } diff --git a/devicemodel/include/ioapic.h b/devicemodel/include/ioapic.h index 8c18ca88a..a120a3054 100644 --- a/devicemodel/include/ioapic.h +++ b/devicemodel/include/ioapic.h @@ -36,6 +36,7 @@ struct pci_vdev; * Allocate a PCI IRQ from the I/O APIC. */ void ioapic_init(struct vmctx *ctx); +void ioapic_deinit(void); int ioapic_pci_alloc_irq(struct pci_vdev *pi); #endif diff --git a/devicemodel/include/public/acrn_common.h b/devicemodel/include/public/acrn_common.h index e7844022f..f6b689c7e 100644 --- a/devicemodel/include/public/acrn_common.h +++ b/devicemodel/include/public/acrn_common.h @@ -82,6 +82,13 @@ #define REQUEST_READ 0 #define REQUEST_WRITE 1 +/* IOAPIC device model info */ +#define VIOAPIC_RTE_NUM 48 /* vioapic pins */ + +#if VIOAPIC_RTE_NUM < 24 +#error "VIOAPIC_RTE_NUM must be larger than 23" +#endif + /* Generic VM flags from guest OS */ #define SECURE_WORLD_ENABLED (1UL<<0) /* Whether secure world is enabled */ diff --git a/devicemodel/include/vmmapi.h b/devicemodel/include/vmmapi.h index 2cf9e6c30..fcf8ab3b5 100644 --- a/devicemodel/include/vmmapi.h +++ b/devicemodel/include/vmmapi.h @@ -140,7 +140,6 @@ int vm_apicid2vcpu(struct vmctx *ctx, int apicid); int vm_lapic_msi(struct vmctx *ctx, uint64_t addr, uint64_t msg); int vm_ioapic_assert_irq(struct vmctx *ctx, int irq); int vm_ioapic_deassert_irq(struct vmctx *ctx, int irq); -int vm_ioapic_pincount(struct vmctx *ctx, int *pincount); int vm_isa_assert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq); int vm_isa_deassert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq); int vm_isa_pulse_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);