Skip to content

Commit 30549a5

Browse files
gzhai7lijinxia
authored andcommitted
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 <edwin.zhai@intel.com> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com> Reviewed-by: Eddie Dong <eddie.dong@intel.com> Reviewed-by: Anthony Xu <anthony.xu@intel.com>
1 parent e1bb372 commit 30549a5

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

devicemodel/core/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ vm_init_vdevs(struct vmctx *ctx)
501501
ioc_deinit(ctx);
502502
atkbdc_deinit(ctx);
503503
pci_irq_deinit(ctx);
504+
ioapic_deinit();
504505
return -1;
505506
}
506507

@@ -514,6 +515,7 @@ vm_deinit_vdevs(struct vmctx *ctx)
514515
ioc_deinit(ctx);
515516
atkbdc_deinit(ctx);
516517
pci_irq_deinit(ctx);
518+
ioapic_deinit();
517519
}
518520

519521
static void

devicemodel/core/vmmapi.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -618,13 +618,6 @@ vm_isa_pulse_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq)
618618
return vm_isa_irq(ctx, atpic_irq, ioapic_irq, IC_PULSE_IRQLINE);
619619
}
620620

621-
int
622-
vm_ioapic_pincount(struct vmctx *ctx, int *pincount)
623-
{
624-
*pincount = 24;
625-
return 0;
626-
}
627-
628621
int
629622
vm_assign_ptdev(struct vmctx *ctx, int bus, int slot, int func)
630623
{

devicemodel/hw/platform/ioapic.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#include "pci_core.h"
3737
#include "lpc.h"
3838

39+
/* 16 IRQs reserved for kdb/mouse, COM1/2, RTC... */
40+
#define LEGACY_IRQ_NUM 16
41+
3942
/*
4043
* Assign PCI INTx interrupts to I/O APIC pins in a round-robin
4144
* fashion. Note that we have no idea what the HPET is using, but the
@@ -46,29 +49,27 @@
4649
* PCI devices.
4750
*/
4851
static int pci_pins;
52+
static int last_pin;
4953

5054
void
5155
ioapic_init(struct vmctx *ctx)
5256
{
53-
if (vm_ioapic_pincount(ctx, &pci_pins) < 0) {
54-
pci_pins = 0;
55-
return;
56-
}
57+
last_pin = 0;
58+
59+
/* Ignore the first 16 pins for legacy IRQ. */
60+
pci_pins = VIOAPIC_RTE_NUM - LEGACY_IRQ_NUM;
61+
}
5762

58-
/* Ignore the first 16 pins. */
59-
if (pci_pins <= 16) {
60-
pci_pins = 0;
61-
return;
62-
}
63-
pci_pins -= 16;
63+
void ioapic_deinit(void)
64+
{
65+
last_pin = 0;
6466
}
6567

6668
int
6769
ioapic_pci_alloc_irq(struct pci_vdev *dev)
6870
{
69-
static int last_pin;
71+
/* No support of vGSI sharing */
72+
assert(last_pin < pci_pins);
7073

71-
if (pci_pins == 0)
72-
return -1;
73-
return (16 + (last_pin++ % pci_pins));
74+
return (LEGACY_IRQ_NUM + (last_pin++ % pci_pins));
7475
}

devicemodel/include/ioapic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct pci_vdev;
3636
* Allocate a PCI IRQ from the I/O APIC.
3737
*/
3838
void ioapic_init(struct vmctx *ctx);
39+
void ioapic_deinit(void);
3940
int ioapic_pci_alloc_irq(struct pci_vdev *pi);
4041

4142
#endif

devicemodel/include/public/acrn_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@
8282
#define REQUEST_READ 0
8383
#define REQUEST_WRITE 1
8484

85+
/* IOAPIC device model info */
86+
#define VIOAPIC_RTE_NUM 48 /* vioapic pins */
87+
88+
#if VIOAPIC_RTE_NUM < 24
89+
#error "VIOAPIC_RTE_NUM must be larger than 23"
90+
#endif
91+
8592
/* Generic VM flags from guest OS */
8693
#define SECURE_WORLD_ENABLED (1UL<<0) /* Whether secure world is enabled */
8794

devicemodel/include/vmmapi.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ int vm_apicid2vcpu(struct vmctx *ctx, int apicid);
140140
int vm_lapic_msi(struct vmctx *ctx, uint64_t addr, uint64_t msg);
141141
int vm_ioapic_assert_irq(struct vmctx *ctx, int irq);
142142
int vm_ioapic_deassert_irq(struct vmctx *ctx, int irq);
143-
int vm_ioapic_pincount(struct vmctx *ctx, int *pincount);
144143
int vm_isa_assert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
145144
int vm_isa_deassert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
146145
int vm_isa_pulse_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);

0 commit comments

Comments
 (0)