uq/master: Introduce basic irqchip support
v4 cover uq/master: Introduce basic irqchip support
Changes in v4:
- rebased of current uq/master
- fixed stupid bugs that broke bisectability and user space irqchip mode
- integrated NMI-over-LINT1 injection logic
Jan Kiszka (15):
msi: Generalize msix_supported to msi_supported
kvm: Move kvmclock into hw/kvm folder
apic: Stop timer on reset
apic: Inject external NMI events via LINT1
apic: Introduce backend/frontend infrastructure for KVM reuse
apic: Open-code timer save/restore
i8259: Introduce backend/frontend infrastructure for KVM reuse
ioapic: Introduce backend/frontend infrastructure for KVM reuse
memory: Introduce memory_region_init_reservation
kvm: Introduce core services for in-kernel irqchip support
kvm: x86: Establish IRQ0 override control
kvm: x86: Add user space part for in-kernel APIC
kvm: x86: Add user space part for in-kernel i8259
kvm: x86: Add user space part for in-kernel IOAPIC
kvm: Arm in-kernel irqchip support
Makefile.objs | 2 +-
Makefile.target | 6 +-
configure | 1 +
hw/apic.c | 309 ++++-----------------------------------
hw/apic.h | 1 +
hw/apic_common.c | 312 ++++++++++++++++++++++++++++++++++++++++
hw/apic_internal.h | 122 ++++++++++++++++
hw/i8259.c | 127 ++--------------
hw/i8259_common.c | 173 ++++++++++++++++++++++
hw/i8259_internal.h | 82 +++++++++++
hw/ioapic.c | 130 ++---------------
hw/ioapic_common.c | 138 ++++++++++++++++++
hw/ioapic_internal.h | 106 ++++++++++++++
hw/kvm/apic.c | 154 ++++++++++++++++++++
hw/{kvmclock.c => kvm/clock.c} | 4 +-
hw/{kvmclock.h => kvm/clock.h} | 0
hw/kvm/i8259.c | 126 ++++++++++++++++
hw/kvm/ioapic.c | 101 +++++++++++++
hw/msi.c | 8 +
hw/msi.h | 2 +
hw/msix.c | 9 +-
hw/msix.h | 2 -
hw/pc.c | 19 ++-
hw/pc.h | 1 +
hw/pc_piix.c | 66 ++++++++-
kvm-all.c | 154 ++++++++++++++++++++
kvm-stub.c | 5 +
kvm.h | 13 ++
memory.c | 36 +++++
memory.h | 16 ++
monitor.c | 6 +-
qemu-config.c | 4 +
qemu-options.hx | 5 +-
sysemu.h | 1 -
target-i386/kvm.c | 19 +++
trace-events | 2 +-
vl.c | 1 -
37 files changed, 1724 insertions(+), 539 deletions(-)
create mode 100644 hw/apic_common.c
create mode 100644 hw/apic_internal.h
create mode 100644 hw/i8259_common.c
create mode 100644 hw/i8259_internal.h
create mode 100644 hw/ioapic_common.c
create mode 100644 hw/ioapic_internal.h
create mode 100644 hw/kvm/apic.c
rename hw/{kvmclock.c => kvm/clock.c} (98%)
rename hw/{kvmclock.h => kvm/clock.h} (100%)
create mode 100644 hw/kvm/i8259.c
create mode 100644 hw/kvm/ioapic.cSignature · 1 line
1.7.3.4
PATCH v4 1/15 msi: Generalize msix_supported to msi_supported
Rename msix_supported to msi_supported and control MSI and MSI-X activation this way. That was likely to original intention for this flag, but MSI support came after MSI-X.
--- hw/msi.c | 8 ++++++++ hw/msi.h | 2 ++ hw/msix.c | 9 ++++----- hw/msix.h | 2 -- hw/pc.c | 4 ++-- 5 files changed, 16 insertions(+), 9 deletions(-)
hw/msi.c +8 -0
@@ -36,6 +36,9 @@#define PCI_MSI_VECTORS_MAX 32 +/* Flag for interrupt controller to declare MSI/MSI-X support */ +bool msi_supported; +/* If we get rid of cap allocator, we won't need this. */ static inline uint8_t msi_cap_sizeof (uint16_t flags) {
@@ -116,6 +119,11 @@ int msi_init(struct PCIDevice *dev, uint8_t offset,uint16_t flags;uint8_t cap_size;int config_offset; + +if (!msi_supported) { +return -ENOTSUP ; + } + MSI_DEV_PRINTF(dev, "init offset: 0x%"PRIx8" vector: %"PRId8 " 64bit %d mask %d\n",
hw/msi.h +2 -0
@@ -24,6 +24,8 @@#include "qemu-common.h" #include "pci.h" +extern bool msi_supported; +bool msi_enabled (const PCIDevice *dev);int msi_init (struct PCIDevice *dev,uint8_t offset,unsigned int nr_vectors,bool msi64bit,bool msi_per_vector_mask);
hw/msix.c +4 -5
@@ -12,6 +12,7 @@*/ #include "hw.h" +#include "msi.h" #include "msix.h" #include "pci.h" #include "range.h"
@@ -32,9 +33,6 @@#define MSIX_MAX_ENTRIES 32 -/* Flag for interrupt controller to declare MSI-X support */ -int msix_supported; -/* Add MSI-X capability to the config space for the device. */ /* Given a bar and its size, add MSI-X table on top of it * and fill MSI-X capability in the config space.
@@ -235,10 +233,11 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries, unsigned bar_nr, unsigned bar_size) { int ret; +/* Nothing to do if MSI is not supported by interrupt controller */ -if (!msix_supported) +if (!msi_supported) {return -ENOTSUP ; - + }if (nentries >MSIX_MAX_ENTRIES )return -EINVAL ;
hw/msix.h +0 -2
@@ -29,6 +29,4 @@ void msix_notify(PCIDevice *dev, unsigned vector);void msix_reset (PCIDevice *dev); -extern int msix_supported; -#endif
hw/pc.c +2 -2
@@ -36,7 +36,7 @@#include "elf.h" #include "multiboot.h" #include "mc146818rtc.h" -#include "msix.h" +#include "msi.h" #include "sysbus.h" #include "sysemu.h" #include "blockdev.h"
@@ -896,7 +896,7 @@ static DeviceState *apic_init(void *env, uint8_t apic_id) apic_mapped =1 ; } - msix_supported =1 ; + msi_supported = true;return dev; }
Signature · 1 line
1.7.3.4
PATCH v4 2/15 kvm: Move kvmclock into hw/kvm folder
In reply to Jan KiszkaMore KVM-specific devices will come, so let's start with moving the kvmclock into a dedicated folder.
---
Makefile.target | 4 ++--
configure | 1 +
hw/{kvmclock.c => kvm/clock.c} | 4 ++--
hw/{kvmclock.h => kvm/clock.h} | 0
hw/pc_piix.c | 2 +-
5 files changed, 6 insertions(+), 5 deletions(-)
rename hw/{kvmclock.c => kvm/clock.c} (98%)
rename hw/{kvmclock.h => kvm/clock.h} (100%)Makefile.target +2 -2
@@ -236,7 +236,7 @@ obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o obj-i386-y += pc_piix.o -obj-i386-$(CONFIG_KVM) += kvmclock.o +obj-i386-$(CONFIG_KVM) += kvm/clock.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o # shared objects
@@ -428,7 +428,7 @@ qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx clean: rm -f *.o *.a *~ $(PROGS) nwfpe/*.o fpu/*.o - rm -f *.d */*.d tcg/*.o ide/*.o 9pfs/*.o + rm -f *.d */*.d tcg/*.o ide/*.o 9pfs/*.o kvm/*.o rm -f hmp-commands.h qmp-commands-old.h gdbstub-xml.c ifdef CONFIG_TRACE_SYSTEMTAP rm -f *.stp
configure +1 -0
@@ -3338,6 +3338,7 @@ mkdir -p $target_dir/fpu mkdir -p $target_dir/tcg mkdir -p $target_dir/ide mkdir -p $target_dir/9pfs +mkdir -p $target_dir/kvm if test "$target" = "arm-linux-user" -o "$target" = "armeb-linux-user" -o "$target" = "arm-bsd-user" -o "$target" = "armeb-bsd-user" ; then mkdir -p $target_dir/nwfpe fi
hw/kvm/clock.c renamed from hw/kvmclock.c +2 -2
@@ -13,9 +13,9 @@#include "qemu-common.h" #include "sysemu.h" -#include "sysbus.h" #include "kvm.h" -#include "kvmclock.h" +#include "hw/sysbus.h" +#include "hw/kvm/clock.h" #include <linux/kvm.h> #include <linux/kvm_para.h>
hw/kvm/clock.h renamed from hw/kvmclock.h +0 -0
hw/pc_piix.c +1 -1
@@ -34,7 +34,7 @@#include "boards.h" #include "ide.h" #include "kvm.h" -#include "kvmclock.h" +#include "kvm/clock.h" #include "sysemu.h" #include "sysbus.h" #include "arch_init.h"
Signature · 1 line
1.7.3.4
PATCH v4 3/15 apic: Stop timer on reset
In reply to Jan KiszkaAll LVTs are masked on reset, so the timer becomes ineffective. Letting it tick nevertheless is harmless, but will at least create a spurious trace event.
--- hw/apic.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
hw/apic.c +2 -0
@@ -528,6 +528,8 @@ void apic_init_reset(DeviceState *d) s->initial_count_load_time =0 ; s->next_time =0 ; s->wait_for_sipi =1 ; + +qemu_del_timer (s->timer); }static void apic_startup (APICState *s,int vector_num)
Signature · 1 line
1.7.3.4
PATCH v4 4/15 apic: Inject external NMI events via LINT1
In reply to Jan KiszkaOn real hardware, NMI button events are injected via the LINT1 line of the APICs. E.g. kdump expect this wiring and gets upset if the per-APIC LINT1 mask is not respected, i.e. if NMIs are injected to VCPUs that should not receive them. Change the APIC emulation code to reflect this.
Based on qemu-kvm patch by Lai Jiangshan.
--- hw/apic.c | 7 +++++++ hw/apic.h | 1 + monitor.c | 6 +++++- 3 files changed, 13 insertions(+), 1 deletions(-)
hw/apic.c +7 -0
@@ -205,6 +205,13 @@ void apic_deliver_pic_intr(DeviceState *d, int level) } } +void apic_deliver_nmi (DeviceState *d) +{ +APICState *s =DO_UPCAST (APICState, busdev.qdev, d); + +apic_local_deliver (s,APIC_LVT_LINT1 ); +} +#define foreach_apic (apic, deliver_bitmask, code) \ {\ int __i, __j, __mask;\
hw/apic.h +1 -0
@@ -8,6 +8,7 @@ void apic_deliver_irq(uint8_t dest, uint8_t dest_mode, uint8_t delivery_mode, uint8_t vector_num, uint8_t trigger_mode);int apic_accept_pic_intr (DeviceState *s);void apic_deliver_pic_intr (DeviceState *s,int level); +void apic_deliver_nmi (DeviceState *d);int apic_get_interrupt (DeviceState *s);void apic_reset_irq_delivered (void );int apic_get_irq_delivered (void );
monitor.c +5 -1
@@ -2354,7 +2354,11 @@ static int do_inject_nmi(Monitor *mon, const QDict *qdict, QObject **ret_data)CPUState *env;for (env = first_cpu; env !=NULL ; env = env->next_cpu) { -cpu_interrupt (env,CPU_INTERRUPT_NMI ); +if (!env->apic_state) { +cpu_interrupt (env,CPU_INTERRUPT_NMI ); + }else { +apic_deliver_nmi (env->apic_state); + } }return 0 ;
Signature · 1 line
1.7.3.4
PATCH v4 5/15 apic: Introduce backend/frontend infrastructure for KVM reuse
In reply to Jan KiszkaThe KVM in-kernel APIC model will reuse parts of the user space model while providing the same frontend view to guest and most management interfaces. Introduce an APIC backend concept to encapsulate those parts that will tell user space and KVM model apart. The backend offers callback hooks for init, base/tpr setting, and the external NMI delivery that will be implemented accordingly.
--- Makefile.target | 2 +- hw/apic.c | 282 +++------------------------------------------------- hw/apic_common.c | 265 ++++++++++++++++++++++++++++++++++++++++++++++++ hw/apic_internal.h | 119 ++++++++++++++++++++++ hw/pc.c | 1 + trace-events | 2 +- 6 files changed, 403 insertions(+), 268 deletions(-) create mode 100644 hw/apic_common.c create mode 100644 hw/apic_internal.h
Makefile.target +1 -1
@@ -231,7 +231,7 @@ obj-$(CONFIG_IVSHMEM) += ivshmem.o # Hardware support obj-i386-y += vga.o obj-i386-y += mc146818rtc.o pc.o -obj-i386-y += cirrus_vga.o sga.o apic.o ioapic.o piix_pci.o +obj-i386-y += cirrus_vga.o sga.o apic_common.o apic.o ioapic.o piix_pci.o obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o
hw/apic.c +16 -266
362 lines not on this page · raw message
hw/apic_common.c new file +265 -0
265 lines not on this page · raw message
hw/apic_internal.h new file +119 -0
119 lines not on this page · raw message
hw/pc.c +1 -0
@@ -884,6 +884,7 @@ static DeviceState *apic_init(void *env, uint8_t apic_id) dev =qdev_create (NULL ,"apic" );qdev_prop_set_uint8 (dev,"id" , apic_id);qdev_prop_set_ptr (dev,"cpu_env" , env); +qdev_prop_set_string (dev,"backend" ,g_strdup ("QEMU" ));qdev_init_nofail (dev); d =sysbus_from_qdev (dev);
trace-events +1 -1
@@ -98,7 +98,7 @@ apic_mem_writel(uint64_t addr, uint32_t val) "%"PRIx64" = %08x" # coalescing apic_reset_irq_delivered(int apic_irq_delivered) "old coalescing %d" apic_get_irq_delivered(int apic_irq_delivered) "returning coalescing %d" -apic_set_irq(int apic_irq_delivered) "coalescing %d" +apic_set_irq_delivered(int apic_irq_delivered) "coalescing %d" # hw/cs4231.c cs4231_mem_readl_dreg(uint32_t reg, uint32_t ret) "read dreg %d: 0x%02x"
Signature · 1 line
1.7.3.4
PATCH v4 6/15 apic: Open-code timer save/restore
In reply to Jan KiszkaTo enable migration between accelerated and non-accelerated APIC models, we will need to handle the timer saving and restoring specially and can no longer rely on the automatics of VMSTATE_TIMER. Specifically, accelerated model will not start any QEMUTimer.
This patch therefore factors out the generic bits into apic_next_timer and introduces a post-load callback that can be implemented differently by both models.
--- hw/apic.c | 30 ++++++++++++------------------ hw/apic_common.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- hw/apic_internal.h | 3 +++ 3 files changed, 64 insertions(+), 20 deletions(-)
hw/apic.c +12 -18
@@ -521,25 +521,9 @@ static uint32_t apic_get_current_count(APICState *s)static void apic_timer_update (APICState *s,int64_t current_time) { -int64_t next_time, d; - -if (!(s->lvt[APIC_LVT_TIMER ] &APIC_LVT_MASKED )) { - d = (current_time - s->initial_count_load_time) >> - s->count_shift; -if (s->lvt[APIC_LVT_TIMER ] &APIC_LVT_TIMER_PERIODIC ) { -if (!s->initial_count) - goto no_timer; - d = ((d / ((uint64_t )s->initial_count +1 )) +1 ) * ((uint64_t )s->initial_count +1 ); - }else { -if (d >= s->initial_count) - goto no_timer; - d = (uint64_t )s->initial_count +1 ; - } - next_time = s->initial_count_load_time + (d << s->count_shift); -qemu_mod_timer (s->timer, next_time); - s->next_time = next_time; +if (apic_next_timer (s, current_time)) { +qemu_mod_timer (s->timer, s->next_time); }else { - no_timer:qemu_del_timer (s->timer); } }
@@ -770,12 +754,22 @@ static void apic_backend_init(APICState *s) local_apics[s->idx] = s; } +static void apic_post_load (APICState *s) +{ +if (s->timer_expiry !=-1 ) { +qemu_mod_timer (s->timer, s->timer_expiry); + }else { +qemu_del_timer (s->timer); + } +} +static APICBackend apic_backend = { .name ="QEMU" , .init = apic_backend_init, .set_base = apic_set_base, .set_tpr = apic_set_tpr, .external_nmi = apic_external_nmi, + .post_load = apic_post_load, };static void apic_register_devices (void )
hw/apic_common.c +49 -2
81 lines not on this page · raw message
hw/apic_internal.h +3 -0
@@ -75,6 +75,7 @@ struct APICBackend {void (*set_base)(APICState *s,uint64_t val);void (*set_tpr)(APICState *s,uint8_t val);void (*external_nmi)(APICState *s); +void (*post_load)(APICState *s);QSIMPLEQ_ENTRY (APICBackend) entry; };
@@ -104,6 +105,7 @@ struct APICState {int64_t next_time;int idx;QEMUTimer *timer; +int64_t timer_expiry;int sipi_vector;int wait_for_sipi;
@@ -114,6 +116,7 @@ struct APICState {void apic_register_device (void );void apic_register_backend (APICBackend *backend); +bool apic_next_timer (APICState *s,int64_t current_time);void apic_set_irq_delivered (int delivered);#endif /* !QEMU_APIC_INTERNAL_H */
Signature · 1 line
1.7.3.4
PATCH v4 7/15 i8259: Introduce backend/frontend infrastructure for KVM reuse
In reply to Jan KiszkaAnalogously to the APIC, we will reuse some parts of the user space i8259 model for KVM. Again, we create a PIC backend infrastructure and provide hooks for init, reset, and vmload/save. This also introduces a common helper to instantiate a single i8259 chip from the cascade- creating i8259_init function.
--- Makefile.objs | 2 +- hw/i8259.c | 127 +++++--------------------------------- hw/i8259_common.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/i8259_internal.h | 82 ++++++++++++++++++++++++ 4 files changed, 271 insertions(+), 113 deletions(-) create mode 100644 hw/i8259_common.c create mode 100644 hw/i8259_internal.h
Makefile.objs +1 -1
@@ -221,7 +221,7 @@ hw-obj-$(CONFIG_APPLESMC) += applesmc.o hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o hw-obj-$(CONFIG_SMARTCARD_NSS) += ccid-card-emulated.o hw-obj-$(CONFIG_USB_REDIR) += usb-redir.o -hw-obj-$(CONFIG_I8259) += i8259.o +hw-obj-$(CONFIG_I8259) += i8259_common.o i8259.o # PPC devices hw-obj-$(CONFIG_PREP_PCI) += prep_pci.o
hw/i8259.c +15 -112
186 lines not on this page · raw message
hw/i8259_common.c new file +173 -0
173 lines not on this page · raw message
hw/i8259_internal.h new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v4 8/15 ioapic: Introduce backend/frontend infrastructure for KVM reuse
In reply to Jan KiszkaSplit up the IOAPIC analogously to APIC and i8259. KVM will share the device description, reset logic and certain init parts with the user space model.
--- Makefile.target | 2 +- hw/ioapic.c | 130 ++++------------------------------------------- hw/ioapic_common.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/ioapic_internal.h | 105 ++++++++++++++++++++++++++++++++++++++ hw/pc_piix.c | 1 + 5 files changed, 254 insertions(+), 121 deletions(-) create mode 100644 hw/ioapic_common.c create mode 100644 hw/ioapic_internal.h
Makefile.target +1 -1
@@ -231,7 +231,7 @@ obj-$(CONFIG_IVSHMEM) += ivshmem.o # Hardware support obj-i386-y += vga.o obj-i386-y += mc146818rtc.o pc.o -obj-i386-y += cirrus_vga.o sga.o apic_common.o apic.o ioapic.o piix_pci.o +obj-i386-y += cirrus_vga.o sga.o apic_common.o apic.o ioapic_common.o ioapic.o piix_pci.o obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o
hw/ioapic.c +10 -120
164 lines not on this page · raw message
hw/ioapic_common.c new file +137 -0
137 lines not on this page · raw message
hw/ioapic_internal.h new file +105 -0
105 lines not on this page · raw message
hw/pc_piix.c +1 -0
@@ -60,6 +60,7 @@ static void ioapic_init(GSIState *gsi_state)unsigned int i; dev =qdev_create (NULL ,"ioapic" ); +qdev_prop_set_string (dev,"backend" ,g_strdup ("QEMU" ));qdev_init_nofail (dev); d =sysbus_from_qdev (dev);sysbus_mmio_map (d,0 ,0xfec00000 );
Signature · 1 line
1.7.3.4
PATCH v4 9/15 memory: Introduce memory_region_init_reservation
In reply to Jan KiszkaIntroduce a memory region type that can reserve I/O space. Such regions are useful for modeling I/O that is only handled outside of QEMU, i.e. in the context of an accelerator like KVM.
Any access to such a region from QEMU is a bug, but could theoretically be triggered by guest code (DMA to reserved region). So only warning about such events once, then ignore them.
--- memory.c | 36 ++++++++++++++++++++++++++++++++++++ memory.h | 16 ++++++++++++++++ 2 files changed, 52 insertions(+), 0 deletions(-)
memory.c +36 -0
@@ -1031,6 +1031,42 @@ void memory_region_init_rom_device(MemoryRegion *mr, mr->backend_registered = true; } +static uint64_t invalid_read (void *opaque,target_phys_addr_t addr, +unsigned size) +{ +MemoryRegion *mr = opaque; + +if (!mr->warning_printed) { +fprintf (stderr,"Invalid read from memory region %s\n" , mr->name); + mr->warning_printed = true; + } +return -1U ; +} + +static void invalid_write (void *opaque,target_phys_addr_t addr,uint64_t data, +unsigned size) +{ +MemoryRegion *mr = opaque; + +if (!mr->warning_printed) { +fprintf (stderr,"Invalid write to memory region %s\n" , mr->name); + mr->warning_printed = true; + } +} + +static const MemoryRegionOps reservation_ops = { + .read = invalid_read, + .write = invalid_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +void memory_region_init_reservation (MemoryRegion *mr, +const char *name, +uint64_t size) +{ +memory_region_init_io (mr, &reservation_ops, mr, name, size); +} +void memory_region_destroy (MemoryRegion *mr) {assert (QTAILQ_EMPTY (&mr->subregions));
memory.h +16 -0
@@ -123,6 +123,7 @@ struct MemoryRegion {bool terminates;bool readable;bool readonly;/* For RAM regions */ +bool warning_printed;/* For reservations */ MemoryRegion *alias;target_phys_addr_t alias_offset;unsigned priority;
@@ -250,6 +251,21 @@ void memory_region_init_rom_device(MemoryRegion *mr, uint64_t size);/** +* memory_region_init_reservation: Initialize a memory region that reserves +* I/O space. +* +* A reservation region primariy serves debugging purposes. It claims I/O +* space that is not supposed to be handled by QEMU itself. Any access via +* the memory API will cause an abort(). +* +* @mr: the #MemoryRegion to be initialized +* @name: used for debugging; not visible to the user or ABI +* @size: size of the region. +*/ +void memory_region_init_reservation (MemoryRegion *mr, +const char *name, +uint64_t size); +/** * memory_region_destroy: Destroy a memory region and relaim all resources. * * @mr: the region to be destroyed. May not currently be a subregion
Signature · 1 line
1.7.3.4
PATCH v4 10/15 kvm: Introduce core services for in-kernel irqchip support
In reply to Jan KiszkaAdd the basic infrastructure to active in-kernel irqchip support, inject interrupts into these models, and maintain IRQ routes.
Routing is optional and depends on the host arch supporting KVM_CAP_IRQ_ROUTING. When it's not available on x86, we looe the HPET as we can't route GSI0 to IOAPIC pin 2.
In-kernel irqchip support will once be controlled by the machine property 'kernel_irqchip', but this is not yet wired up.
--- kvm-all.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++ kvm.h | 8 +++ target-i386/kvm.c | 11 ++++ 3 files changed, 168 insertions(+), 0 deletions(-)
kvm-all.c +149 -0
@@ -77,6 +77,13 @@ struct KVMStateint pit_in_kernel;int xsave, xcrs;int many_ioeventfds; +int irqchip_inject_ioctl; +#ifdef KVM_CAP_IRQ_ROUTING +struct kvm_irq_routing *irq_routes; +int nr_allocated_irq_routes; +uint32_t *used_gsi_bitmap; +unsigned int max_gsi; +#endif };KVMState *kvm_state;
@@ -693,6 +700,138 @@ static void kvm_handle_interrupt(CPUState *env, int mask) } } +int kvm_irqchip_set_irq (KVMState *s,int irq,int level) +{ +struct kvm_irq_level event; +int ret; + +assert (s->irqchip_in_kernel); + + event.level = level; + event.irq = irq; + ret =kvm_vm_ioctl (s, s->irqchip_inject_ioctl, &event); +if (ret <0 ) { +perror ("kvm_set_irqchip_line" ); +abort (); + } + +return (s->irqchip_inject_ioctl ==KVM_IRQ_LINE ) ?1 : event.status; +} + +#ifdef KVM_CAP_IRQ_ROUTING +static void set_gsi (KVMState *s,unsigned int gsi) +{ +assert (gsi < s->max_gsi); + + s->used_gsi_bitmap[gsi /32 ] |=1U << (gsi %32 ); +} + +static void kvm_init_irq_routing (KVMState *s) +{ +int gsi_count; + + gsi_count =kvm_check_extension (s,KVM_CAP_IRQ_ROUTING ); +if (gsi_count >0 ) { +unsigned int gsi_bits, i; + +/* Round up so we can search ints using ffs */ + gsi_bits = (gsi_count +31 ) /32 ; + s->used_gsi_bitmap =g_malloc0 (gsi_bits /8 ); + s->max_gsi = gsi_bits; + +/* Mark any over-allocated bits as already in use */ +for (i = gsi_count; i < gsi_bits; i++) { +set_gsi (s, i); + } + } + + s->irq_routes =g_malloc0 (sizeof (*s->irq_routes)); + s->nr_allocated_irq_routes =0 ; + +kvm_arch_init_irq_routing (s); +} + +static void kvm_add_routing_entry (KVMState *s, +struct kvm_irq_routing_entry *entry) +{ +struct kvm_irq_routing_entry *new; +int n, size; + +if (s->irq_routes->nr == s->nr_allocated_irq_routes) { + n = s->nr_allocated_irq_routes *2 ; +if (n <64 ) { + n =64 ; + } + size =sizeof (struct kvm_irq_routing ); + size += n *sizeof (*new); + s->irq_routes =g_realloc (s->irq_routes, size); + s->nr_allocated_irq_routes = n; + } + n = s->irq_routes->nr++; + new = &s->irq_routes->entries[n]; +memset (new,0 ,sizeof (*new)); + new->gsi = entry->gsi; + new->type = entry->type; + new->flags = entry->flags; + new->u = entry->u; + +set_gsi (s, entry->gsi); +} + +void kvm_irqchip_add_route (KVMState *s,int irq,int irqchip,int pin) +{ +struct kvm_irq_routing_entry e; + + e.gsi = irq; + e.type =KVM_IRQ_ROUTING_IRQCHIP ; + e.flags =0 ; + e.u.irqchip.irqchip = irqchip; + e.u.irqchip.pin = pin; +kvm_add_routing_entry (s, &e); +} + +int kvm_irqchip_commit_routes (KVMState *s) +{ + s->irq_routes->flags =0 ; +return kvm_vm_ioctl (s,KVM_SET_GSI_ROUTING , s->irq_routes); +} + +#else /* !KVM_CAP_IRQ_ROUTING */ + +static void kvm_init_irq_routing (KVMState *s) +{ +} +#endif /* !KVM_CAP_IRQ_ROUTING */ + +static int kvm_irqchip_create (KVMState *s) +{ +QemuOptsList *list =qemu_find_opts ("machine" ); +int ret; + +if (QTAILQ_EMPTY (&list->head) || + !qemu_opt_get_bool (QTAILQ_FIRST (&list->head), +"kernel_irqchip" , false) || + !kvm_check_extension (s,KVM_CAP_IRQCHIP )) { +return 0 ; + } + + ret =kvm_vm_ioctl (s,KVM_CREATE_IRQCHIP ); +if (ret <0 ) { +fprintf (stderr,"Create kernel irqchip failed\n" ); +return ret; + } + + s->irqchip_inject_ioctl =KVM_IRQ_LINE ; +if (kvm_check_extension (s,KVM_CAP_IRQ_INJECT_STATUS )) { + s->irqchip_inject_ioctl =KVM_IRQ_LINE_STATUS ; + } + s->irqchip_in_kernel =1 ; + +kvm_init_irq_routing (s); + +return 0 ; +} +int kvm_init (void ) { static const char upgrade_note[] =
@@ -788,6 +927,11 @@ int kvm_init(void) goto err; } + ret =kvm_irqchip_create (s); +if (ret <0 ) { + goto err; + } + kvm_state = s;cpu_register_phys_memory_client (&kvm_cpu_phys_memory_client);
@@ -1122,6 +1266,11 @@ int kvm_has_many_ioeventfds(void)return kvm_state->many_ioeventfds; } +int kvm_has_gsi_routing (void ) +{ +return kvm_check_extension (kvm_state,KVM_CAP_IRQ_ROUTING ); +} +void kvm_setup_guest_memory (void *start,size_t size) {if (!kvm_has_sync_mmu ()) {
kvm.h +8 -0
@@ -51,6 +51,7 @@ int kvm_has_debugregs(void);int kvm_has_xsave (void );int kvm_has_xcrs (void );int kvm_has_many_ioeventfds (void ); +int kvm_has_gsi_routing (void );#ifdef NEED_CPU_H int kvm_init_vcpu (CPUState *env);
@@ -124,6 +125,13 @@ void kvm_arch_reset_vcpu(CPUState *env);int kvm_arch_on_sigbus_vcpu (CPUState *env,int code,void *addr);int kvm_arch_on_sigbus (int code,void *addr); +void kvm_arch_init_irq_routing (KVMState *s); + +int kvm_irqchip_set_irq (KVMState *s,int irq,int level); + +void kvm_irqchip_add_route (KVMState *s,int gsi,int irqchip,int pin); +int kvm_irqchip_commit_routes (KVMState *s); +struct kvm_guest_debug ;struct kvm_debug_exit_arch ;
target-i386/kvm.c +11 -0
@@ -1879,3 +1879,14 @@ bool kvm_arch_stop_on_emulation_error(CPUState *env)return !(env->cr[0 ] &CR0_PE_MASK ) || ((env->segs[R_CS ].selector &3 ) !=3 ); } + +void kvm_arch_init_irq_routing (KVMState *s) +{ +if (!kvm_check_extension (s,KVM_CAP_IRQ_ROUTING )) { +/* If kernel can't do irq routing, interrupt source +* override 0->2 cannot be set up as required by HPET. +* So we have to disable it. +*/ + no_hpet =1 ; + } +}
Signature · 1 line
1.7.3.4
PATCH v4 11/15 kvm: x86: Establish IRQ0 override control
In reply to Jan KiszkaKVM is forced to disable the IRQ0 override when we run with in-kernel irqchip but without IRQ routing support of the kernel. Set the fwcfg value correspondingly. This aligns us with qemu-kvm.
--- hw/pc.c | 3 ++- kvm-all.c | 5 +++++ kvm-stub.c | 5 +++++ kvm.h | 2 ++ sysemu.h | 1 - vl.c | 1 - 6 files changed, 14 insertions(+), 3 deletions(-)
hw/pc.c +2 -1
@@ -39,6 +39,7 @@#include "msi.h" #include "sysbus.h" #include "sysemu.h" +#include "kvm.h" #include "blockdev.h" #include "ui/qemu-spice.h" #include "memory.h"
@@ -609,7 +610,7 @@ static void *bochs_bios_init(void)fw_cfg_add_i64 (fw_cfg,FW_CFG_RAM_SIZE , (uint64_t )ram_size);fw_cfg_add_bytes (fw_cfg,FW_CFG_ACPI_TABLES , (uint8_t *)acpi_tables, acpi_tables_len); -fw_cfg_add_bytes (fw_cfg,FW_CFG_IRQ0_OVERRIDE , &irq0override,1 ); +fw_cfg_add_i32 (fw_cfg,FW_CFG_IRQ0_OVERRIDE ,kvm_allows_irq0_override ()); smbios_table =smbios_get_table (&smbios_len);if (smbios_table)
kvm-all.c +5 -0
@@ -1271,6 +1271,11 @@ int kvm_has_gsi_routing(void)return kvm_check_extension (kvm_state,KVM_CAP_IRQ_ROUTING ); } +int kvm_allows_irq0_override (void ) +{ +return !kvm_enabled () || !kvm_irqchip_in_kernel () ||kvm_has_gsi_routing (); +} +void kvm_setup_guest_memory (void *start,size_t size) {if (!kvm_has_sync_mmu ()) {
kvm-stub.c +5 -0
@@ -78,6 +78,11 @@ int kvm_has_many_ioeventfds(void)return 0 ; } +int kvm_allows_irq0_override (void ) +{ +return 1 ; +} +void kvm_setup_guest_memory (void *start,size_t size) { }
kvm.h +2 -0
@@ -53,6 +53,8 @@ int kvm_has_xcrs(void);int kvm_has_many_ioeventfds (void );int kvm_has_gsi_routing (void ); +int kvm_allows_irq0_override (void ); +#ifdef NEED_CPU_H int kvm_init_vcpu (CPUState *env);
sysemu.h +0 -1
@@ -102,7 +102,6 @@ extern int vga_interface_type;extern int graphic_width;extern int graphic_height;extern int graphic_depth; -extern uint8_t irq0override;extern DisplayType display_type;extern const char *keyboard_layout;extern int win2k_install_hack;
vl.c +0 -1
@@ -218,7 +218,6 @@ int no_reboot = 0;int no_shutdown =0 ;int cursor_hide =1 ;int graphic_rotate =0 ; -uint8_t irq0override =1 ;const char *watchdog;QEMUOptionRom option_rom[MAX_OPTION_ROMS ];int nb_option_roms;
Signature · 1 line
1.7.3.4
PATCH v4 12/15 kvm: x86: Add user space part for in-kernel APIC
In reply to Jan KiszkaThis introduces the alternative APIC backend which makes use of KVM's in-kernel device model. External NMI injection via LINT1 is emulated by checking the current state of the in-kernel APIC, only injecting a NMI into the VCPU if LINT1 is unmasked and configured to DM_NMI.
MSI is not yet supported, so we disable this when the in-kernel model is in use.
--- Makefile.target | 2 +- hw/kvm/apic.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pc.c | 15 ++++-- kvm.h | 3 + target-i386/kvm.c | 8 +++ 5 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 hw/kvm/apic.c
Makefile.target +1 -1
@@ -236,7 +236,7 @@ obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o obj-i386-y += pc_piix.o -obj-i386-$(CONFIG_KVM) += kvm/clock.o +obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o # shared objects
hw/kvm/apic.c new file +154 -0
154 lines not on this page · raw message
hw/pc.c +10 -5
@@ -878,27 +878,32 @@ DeviceState *cpu_get_current_apic(void)static DeviceState *apic_init (void *env,uint8_t apic_id) { +const char *backend ="QEMU" ;DeviceState *dev; -SysBusDevice *d;static int apic_mapped; dev =qdev_create (NULL ,"apic" );qdev_prop_set_uint8 (dev,"id" , apic_id);qdev_prop_set_ptr (dev,"cpu_env" , env); -qdev_prop_set_string (dev,"backend" ,g_strdup ("QEMU" )); +if (kvm_enabled () &&kvm_irqchip_in_kernel ()) { + backend ="KVM" ; + } +qdev_prop_set_string (dev,"backend" ,g_strdup (backend));qdev_init_nofail (dev); - d =sysbus_from_qdev (dev);/* XXX: mapping more APICs at the same memory location */ if (apic_mapped ==0 ) {/* NOTE: the APIC is directly connected to the CPU - it is not on the global memory bus. */ /* XXX: what if the base changes? */ -sysbus_mmio_map (d,0 ,MSI_ADDR_BASE ); +sysbus_mmio_map (sysbus_from_qdev (dev),0 ,MSI_ADDR_BASE ); apic_mapped =1 ; } - msi_supported = true; +/* KVM does not support MSI yet. */ +if (!kvm_enabled () || !kvm_irqchip_in_kernel ()) { + msi_supported = true; + }return dev; }
kvm.h +3 -0
@@ -134,6 +134,9 @@ int kvm_irqchip_set_irq(KVMState *s, int irq, int level);void kvm_irqchip_add_route (KVMState *s,int gsi,int irqchip,int pin);int kvm_irqchip_commit_routes (KVMState *s); +int kvm_put_apic (CPUState *env); +int kvm_get_apic (CPUState *env); +struct kvm_guest_debug ;struct kvm_debug_exit_arch ;
target-i386/kvm.c +8 -0
@@ -1450,6 +1450,10 @@ int kvm_arch_put_registers(CPUState *env, int level)if (ret <0 ) {return ret; } + ret =kvm_put_apic (env); +if (ret <0 ) { +return ret; + } } ret =kvm_put_vcpu_events (env, level);if (ret <0 ) {
@@ -1497,6 +1501,10 @@ int kvm_arch_get_registers(CPUState *env)if (ret <0 ) {return ret; } + ret =kvm_get_apic (env); +if (ret <0 ) { +return ret; + } ret =kvm_get_vcpu_events (env);if (ret <0 ) {return ret;
Signature · 1 line
1.7.3.4
Re: [PATCH v4 12/15] kvm: x86: Add user space part for in-kernel APIC
Quoted 57 lines · Jan Kiszka
This introduces the alternative APIC backend which makes use of KVM's in-kernel device model. External NMI injection via LINT1 is emulated by checking the current state of the in-kernel APIC, only injecting a NMI into the VCPU if LINT1 is unmasked and configured to
DM_NMI.MSI is not yet supported, so we disable this when the in-kernel model is in use.
CC Lai Jiangshan <[email protected]>Signed-off-by Jan Kiszka <[email protected]>---
Makefile.target | 2 +-
hw/kvm/apic.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++hw/pc.c| 15 ++++--
kvm.h | 3 +
target-i386/kvm.c | 8 +++5 files changed, 176 insertions(+), 6 deletions(-)create mode 100644
hw/kvm/apic.cMakefile.target +0
-0@@ -236,7 +236,7 @@ obj-i386-y += vmport.oobj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o
obj-i386-y += pc_piix.oMakefile.target +1
-1-obj-i386-$(CONFIG_KVM) += kvm/clock.o +obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.oobj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
# shared objectshw/kvm/apic.c new file +19
-0@@ -0,0 +1,154 @@ +/* +* KVM in-kernel APIC support +* +* Copyright (c) 2011 Siemens AG +* +* Authors: +* Jan Kiszka <[email protected]> +* +* This work is licensed under the terms of the GNU GPL version 2. +* See the COPYING file in the top-level directory. +*/ +#include "hw/apic_internal.h" +#include "kvm.h" + +static inline void kvm_apic_set_reg (struct kvm_lapic_state *kapic, + int reg_id, uint32_t val) +{ + *((uint32_t *)(kapic->regs + (reg_id << 4))) = val; +}
hw/kvm/apic.c line 29
Quoted 10 lines
hw/kvm/apic.c new file +10
-0+ +static inline uint32_t kvm_apic_get_reg (struct kvm_lapic_state *kapic, + int reg_id) +{ + return *((uint32_t *)(kapic->regs + (reg_id << 4))); +} + +int kvm_put_apic (CPUState *env) +{ + APICState *s = DO_UPCAST(APICState, busdev.qdev, env->apic_state);
Please pass APICState instead of CPUState.
Quoted 21 lines
hw/kvm/apic.c new file +21
-0+ struct kvm_lapic_state kapic; + int i; + + if (s && kvm_enabled() && kvm_irqchip_in_kernel()) { + memset(&kapic, 0, sizeof(kapic)); + kvm_apic_set_reg(&kapic, 0x2, s->id << 24); + kvm_apic_set_reg(&kapic, 0x8, s->tpr); + kvm_apic_set_reg(&kapic, 0xd, s->log_dest << 24); + kvm_apic_set_reg(&kapic, 0xe, s->dest_mode << 28 | 0x0fffffff); + kvm_apic_set_reg(&kapic, 0xf, s->spurious_vec); + for (i = 0; i < 8; i++) { + kvm_apic_set_reg(&kapic, 0x10 + i, s->isr[i]); + kvm_apic_set_reg(&kapic, 0x18 + i, s->tmr[i]); + kvm_apic_set_reg(&kapic, 0x20 + i, s->irr[i]); + } + kvm_apic_set_reg(&kapic, 0x28, s->esr); + kvm_apic_set_reg(&kapic, 0x30, s->icr[0]); + kvm_apic_set_reg(&kapic, 0x31, s->icr[1]); + for (i = 0; i < APIC_LVT_NB; i++) { + kvm_apic_set_reg(&kapic, 0x32 + i, s->lvt[i]); + }
hw/kvm/apic.c line 60
Quoted 10 lines
hw/kvm/apic.c new file +10
-0+ kvm_apic_set_reg(&kapic, 0x38, s->initial_count); + kvm_apic_set_reg(&kapic, 0x3e, s->divide_conf); + + return kvm_vcpu_ioctl(env, KVM_SET_LAPIC, &kapic); + } + + return 0; +} + +int kvm_get_apic (CPUState *env)
Same here.
Quoted 62 lines
hw/kvm/apic.c new file +62
-0+{ + APICState *s = DO_UPCAST(APICState, busdev.qdev, env->apic_state); + struct kvm_lapic_state kapic; + int ret, i, v; + + if (s && kvm_enabled() && kvm_irqchip_in_kernel()) { + ret = kvm_vcpu_ioctl(env, KVM_GET_LAPIC, &kapic); + if (ret < 0) { + return ret; + } + + s->id = kvm_apic_get_reg(&kapic, 0x2) >> 24; + s->tpr = kvm_apic_get_reg(&kapic, 0x8); + s->arb_id = kvm_apic_get_reg(&kapic, 0x9); + s->log_dest = kvm_apic_get_reg(&kapic, 0xd) >> 24; + s->dest_mode = kvm_apic_get_reg(&kapic, 0xe) >> 28; + s->spurious_vec = kvm_apic_get_reg(&kapic, 0xf); + for (i = 0; i < 8; i++) { + s->isr[i] = kvm_apic_get_reg(&kapic, 0x10 + i); + s->tmr[i] = kvm_apic_get_reg(&kapic, 0x18 + i); + s->irr[i] = kvm_apic_get_reg(&kapic, 0x20 + i); + } + s->esr = kvm_apic_get_reg(&kapic, 0x28); + s->icr[0] = kvm_apic_get_reg(&kapic, 0x30); + s->icr[1] = kvm_apic_get_reg(&kapic, 0x31); + for (i = 0; i < APIC_LVT_NB; i++) { + s->lvt[i] = kvm_apic_get_reg(&kapic, 0x32 + i); + } + s->initial_count = kvm_apic_get_reg(&kapic, 0x38); + s->divide_conf = kvm_apic_get_reg(&kapic, 0x3e); + + v = (s->divide_conf & 3) | ((s->divide_conf >> 1) & 4); + s->count_shift = (v + 1) & 7; + + s->initial_count_load_time = qemu_get_clock_ns(vm_clock); + apic_next_timer(s, s->initial_count_load_time); + } + return 0; +} + +static void kvm_apic_set_base (APICState *s,uint64_t val) +{ + s->apicbase = val; +} + +static void kvm_apic_set_tpr (APICState *s,uint8_t val) +{ + s->tpr = (val & 0x0f) << 4; +} + +static void do_inject_external_nmi (void *data) +{ + APICState *s = data; + CPUState *env = s->cpu_env; + uint32_t lvt; + int ret; + + cpu_synchronize_state(env); + + lvt = s->lvt[APIC_LVT_LINT1]; + if (!(lvt & APIC_LVT_MASKED) && ((lvt >> 8) & 7) == APIC_DM_NMI) { + ret = kvm_vcpu_ioctl(env, KVM_NMI);
hw/kvm/apic.c line 132
Quoted 10 lines
hw/kvm/apic.c new file +10
-0+ if (ret < 0) { + fprintf(stderr, "KVM: injection failed, NMI lost (%s)\n", + strerror(-ret)); + } + } +} + +static void kvm_apic_external_nmi (APICState *s) +{ + run_on_cpu(s->cpu_env, do_inject_external_nmi, s);
Here probably CPUState would make more sense.
Quoted 107 lines
hw/kvm/apic.c new file +22
-0+} + +static void kvm_apic_backend_init (APICState *s) +{ + memory_region_init_reservation(&s->io_memory, "kvm-apic-msi", + MSI_SPACE_SIZE); +} + +static APICBackend kvm_apic_backend = { + .name = "KVM", + .init = kvm_apic_backend_init, + .set_base = kvm_apic_set_base, + .set_tpr = kvm_apic_set_tpr, + .external_nmi = kvm_apic_external_nmi, +}; + +static void kvm_apic_register_backend (void ) +{ + apic_register_backend(&kvm_apic_backend); +} + +device_init (kvm_apic_register_backend)hw/pc.c +5
-3@@ -878,27 +878,32 @@ DeviceState *cpu_get_current_apic(void) static DeviceState *apic_init(void *env, uint8_t apic_id) { + const char *backend = "QEMU"; DeviceState *dev; - SysBusDevice *d; static int apic_mapped; dev = qdev_create(NULL, "apic"); qdev_prop_set_uint8(dev, "id", apic_id); qdev_prop_set_ptr(dev, "cpu_env", env); - qdev_prop_set_string(dev, "backend", g_strdup("QEMU")); + if (kvm_enabled() && kvm_irqchip_in_kernel()) { + backend = "KVM"; + } + qdev_prop_set_string(dev, "backend", g_strdup(backend)); qdev_init_nofail(dev); - d = sysbus_from_qdev(dev); /* XXX: mapping more APICs at the same memory location */ if (apic_mapped == 0) { /* NOTE: the APIC is directly connected to the CPU - it is noton the global memory bus. */
/* XXX: what if the base changes? */
- sysbus_mmio_map(d, 0,MSI_ADDR_BASE);
+ sysbus_mmio_map(sysbus_from_qdev(dev), 0,MSI_ADDR_BASE);apic_mapped= 1;
}- msi_supported = true;
+ /* KVM does not support MSI yet. */
+ if (!kvm_enabled() || !kvm_irqchip_in_kernel()) {
+ msi_supported = true;
+ }return dev;
}kvm.h +3
-0@@ -134,6 +134,9 @@ int kvm_irqchip_set_irq(KVMState *s, int irq, int level); void kvm_irqchip_add_route(KVMState *s, int gsi, int irqchip, int pin); int kvm_irqchip_commit_routes(KVMState *s); +int kvm_put_apic (CPUState *env); +int kvm_get_apic (CPUState *env); + struct kvm_guest_debug; struct kvm_debug_exit_arch;target-i386/kvm.c +8
-1@@ -1450,6 +1450,10 @@ int kvm_arch_put_registers(CPUState *env, int level) if (ret < 0) { return ret; } + ret = kvm_put_apic(env); + if (ret < 0) { + return ret; + } } ret = kvm_put_vcpu_events(env, level); if (ret < 0) {@@ -1497,6 +1501,10 @@ int kvm_arch_get_registers(CPUState *env) if (ret < 0) { return ret; } + ret = kvm_get_apic(env); + if (ret < 0) { + return ret; + } ret = kvm_get_vcpu_events(env); if (ret < 0) { return ret; --1.7.3.4
Re: [PATCH v4 12/15] kvm: x86: Add user space part for in-kernel APIC
Quoted 62 lines · Blue Swirl
Quoted 61 lines · Jan Kiszka
This introduces the alternative APIC backend which makes use of KVM's in-kernel device model. External NMI injection via LINT1 is emulated by checking the current state of the in-kernel APIC, only injecting a NMI into the VCPU if LINT1 is unmasked and configured to
DM_NMI.MSI is not yet supported, so we disable this when the in-kernel model is in use.
CC Lai Jiangshan <[email protected]>Signed-off-by Jan Kiszka <[email protected]>--- Makefile.target | 2 +- hw/kvm/apic.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pc.c | 15 ++++-- kvm.h | 3 + target-i386/kvm.c | 8 +++ 5 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 hw/kvm/apic.cMakefile.target +1
-1@@ -236,7 +236,7 @@ obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o obj-i386-y += pc_piix.o -obj-i386-$(CONFIG_KVM) += kvm/clock.o +obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o # shared objectshw/kvm/apic.c new file +23
-0@@ -0,0 +1,154 @@ +/* +* KVM in-kernel APIC support +* +* Copyright (c) 2011 Siemens AG +* +* Authors: +* Jan Kiszka <[email protected]> +* +* This work is licensed under the terms of the GNU GPL version 2. +* See the COPYING file in the top-level directory. +*/ +#include "hw/apic_internal.h" +#include "kvm.h" + +static inline void kvm_apic_set_reg (struct kvm_lapic_state *kapic, +int reg_id,uint32_t val) +{ + *((uint32_t *)(kapic->regs + (reg_id <<4 ))) = val; +} + +static inline uint32_t kvm_apic_get_reg (struct kvm_lapic_state *kapic, +int reg_id) +{
Quoted 8 lines
hw/kvm/apic.c line 29
Quoted 6 lines
hw/kvm/apic.c new file +6
-0+return *((uint32_t *)(kapic->regs + (reg_id <<4 ))); +} + +int kvm_put_apic (CPUState *env) +{ +APICState *s =DO_UPCAST (APICState, busdev.qdev, env->apic_state);Please pass APICState instead of CPUState.
DeviceState, I suppose. Yes, makes more sense, update will follow.
Quoted 101 lines
Quoted 22 lines
hw/kvm/apic.c new file +21
-0+struct kvm_lapic_state kapic; +int i; + +if (s &&kvm_enabled () &&kvm_irqchip_in_kernel ()) { +memset (&kapic,0 ,sizeof (kapic)); +kvm_apic_set_reg (&kapic,0x2 , s->id <<24 ); +kvm_apic_set_reg (&kapic,0x8 , s->tpr); +kvm_apic_set_reg (&kapic,0xd , s->log_dest <<24 ); +kvm_apic_set_reg (&kapic,0xe , s->dest_mode <<28 |0x0fffffff ); +kvm_apic_set_reg (&kapic,0xf , s->spurious_vec); +for (i =0 ; i <8 ; i++) { +kvm_apic_set_reg (&kapic,0x10 + i, s->isr[i]); +kvm_apic_set_reg (&kapic,0x18 + i, s->tmr[i]); +kvm_apic_set_reg (&kapic,0x20 + i, s->irr[i]); + } +kvm_apic_set_reg (&kapic,0x28 , s->esr); +kvm_apic_set_reg (&kapic,0x30 , s->icr[0 ]); +kvm_apic_set_reg (&kapic,0x31 , s->icr[1 ]); +for (i =0 ; i <APIC_LVT_NB ; i++) { +kvm_apic_set_reg (&kapic,0x32 + i, s->lvt[i]); + }hw/kvm/apic.c line 60
Quoted 10 lines
hw/kvm/apic.c new file +10
-0+kvm_apic_set_reg (&kapic,0x38 , s->initial_count); +kvm_apic_set_reg (&kapic,0x3e , s->divide_conf); + +return kvm_vcpu_ioctl (env,KVM_SET_LAPIC , &kapic); + } + +return 0 ; +} + +int kvm_get_apic (CPUState *env)Same here.
Quoted 66 lines
hw/kvm/apic.c new file +66
-0+{ +APICState *s =DO_UPCAST (APICState, busdev.qdev, env->apic_state); +struct kvm_lapic_state kapic; +int ret, i, v; + +if (s &&kvm_enabled () &&kvm_irqchip_in_kernel ()) { + ret =kvm_vcpu_ioctl (env,KVM_GET_LAPIC , &kapic); +if (ret <0 ) { +return ret; + } + + s->id =kvm_apic_get_reg (&kapic,0x2 ) >>24 ; + s->tpr =kvm_apic_get_reg (&kapic,0x8 ); + s->arb_id =kvm_apic_get_reg (&kapic,0x9 ); + s->log_dest =kvm_apic_get_reg (&kapic,0xd ) >>24 ; + s->dest_mode =kvm_apic_get_reg (&kapic,0xe ) >>28 ; + s->spurious_vec =kvm_apic_get_reg (&kapic,0xf ); +for (i =0 ; i <8 ; i++) { + s->isr[i] =kvm_apic_get_reg (&kapic,0x10 + i); + s->tmr[i] =kvm_apic_get_reg (&kapic,0x18 + i); + s->irr[i] =kvm_apic_get_reg (&kapic,0x20 + i); + } + s->esr =kvm_apic_get_reg (&kapic,0x28 ); + s->icr[0 ] =kvm_apic_get_reg (&kapic,0x30 ); + s->icr[1 ] =kvm_apic_get_reg (&kapic,0x31 ); +for (i =0 ; i <APIC_LVT_NB ; i++) { + s->lvt[i] =kvm_apic_get_reg (&kapic,0x32 + i); + } + s->initial_count =kvm_apic_get_reg (&kapic,0x38 ); + s->divide_conf =kvm_apic_get_reg (&kapic,0x3e ); + + v = (s->divide_conf &3 ) | ((s->divide_conf >>1 ) &4 ); + s->count_shift = (v +1 ) &7 ; + + s->initial_count_load_time =qemu_get_clock_ns (vm_clock); +apic_next_timer (s, s->initial_count_load_time); + } +return 0 ; +} + +static void kvm_apic_set_base (APICState *s,uint64_t val) +{ + s->apicbase = val; +} + +static void kvm_apic_set_tpr (APICState *s,uint8_t val) +{ + s->tpr = (val &0x0f ) <<4 ; +} + +static void do_inject_external_nmi (void *data) +{ +APICState *s = data; +CPUState *env = s->cpu_env; +uint32_t lvt; +int ret; + +cpu_synchronize_state (env); + + lvt = s->lvt[APIC_LVT_LINT1 ]; +if (!(lvt &APIC_LVT_MASKED ) && ((lvt >>8 ) &7 ) ==APIC_DM_NMI ) { + ret =kvm_vcpu_ioctl (env,KVM_NMI ); +if (ret <0 ) { +fprintf (stderr,"KVM: injection failed, NMI lost (%s)\n" , +strerror (-ret)); + }
Quoted 8 lines
hw/kvm/apic.c line 132
Quoted 6 lines
hw/kvm/apic.c new file +6
-0+ } +} + +static void kvm_apic_external_nmi (APICState *s) +{ +run_on_cpu (s->cpu_env, do_inject_external_nmi, s);Here probably CPUState would make more sense.
But here I think it's more consistent to stay with APICState (for the hook) and DeviceState (for apic_deliver_nmi).
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Re: [PATCH v4 12/15] kvm: x86: Add user space part for in-kernel APIC
Quoted 72 lines · Jan Kiszka
Quoted 62 lines · Blue Swirl
Quoted 61 lines · Jan Kiszka
This introduces the alternative APIC backend which makes use of KVM's in-kernel device model. External NMI injection via LINT1 is emulated by checking the current state of the in-kernel APIC, only injecting a NMI into the VCPU if LINT1 is unmasked and configured to
DM_NMI.MSI is not yet supported, so we disable this when the in-kernel model is in use.
CC Lai Jiangshan <[email protected]>Signed-off-by Jan Kiszka <[email protected]>--- Makefile.target | 2 +- hw/kvm/apic.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pc.c | 15 ++++-- kvm.h | 3 + target-i386/kvm.c | 8 +++ 5 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 hw/kvm/apic.cMakefile.target +1
-1@@ -236,7 +236,7 @@ obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o obj-i386-y += pc_piix.o -obj-i386-$(CONFIG_KVM) += kvm/clock.o +obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o # shared objectshw/kvm/apic.c new file +23
-0@@ -0,0 +1,154 @@ +/* +* KVM in-kernel APIC support +* +* Copyright (c) 2011 Siemens AG +* +* Authors: +* Jan Kiszka <[email protected]> +* +* This work is licensed under the terms of the GNU GPL version 2. +* See the COPYING file in the top-level directory. +*/ +#include "hw/apic_internal.h" +#include "kvm.h" + +static inline void kvm_apic_set_reg (struct kvm_lapic_state *kapic, +int reg_id,uint32_t val) +{ + *((uint32_t *)(kapic->regs + (reg_id <<4 ))) = val; +} + +static inline uint32_t kvm_apic_get_reg (struct kvm_lapic_state *kapic, +int reg_id) +{Quoted 8 lines
hw/kvm/apic.c line 29
Quoted 6 lines
hw/kvm/apic.c new file +6
-0+return *((uint32_t *)(kapic->regs + (reg_id <<4 ))); +} + +int kvm_put_apic (CPUState *env) +{ +APICState *s =DO_UPCAST (APICState, busdev.qdev, env->apic_state);Please pass APICState instead of CPUState.
Quoted 1 line
DeviceState, I suppose. Yes, makes more sense, update will follow.
On second look: no, I'll keep it as is. All kvm_get/put_* helpers have this kind of signature, i.e. are working against env. kvm_get/put_apic just happens to be implemented outside of target-i386/kvm.c. And they require both APIC and CPUState anyway, so it makes no difference.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Re: [PATCH v4 12/15] kvm: x86: Add user space part for in-kernel APIC
Quoted 73 lines · Jan Kiszka
Quoted 72 lines · Jan Kiszka
Quoted 70 lines · Blue Swirl
Quoted 57 lines · Jan Kiszka
This introduces the alternative APIC backend which makes use of KVM's in-kernel device model. External NMI injection via LINT1 is emulated by checking the current state of the in-kernel APIC, only injecting a NMI into the VCPU if LINT1 is unmasked and configured to
DM_NMI.MSI is not yet supported, so we disable this when the in-kernel model is in use.
CC Lai Jiangshan <[email protected]>Signed-off-by Jan Kiszka <[email protected]>---
Makefile.target | 2 +-
hw/kvm/apic.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++hw/pc.c| 15 ++++--
kvm.h | 3 +
target-i386/kvm.c | 8 +++5 files changed, 176 insertions(+), 6 deletions(-)create mode 100644
hw/kvm/apic.cMakefile.target +0
-0@@ -236,7 +236,7 @@ obj-i386-y += vmport.oobj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o
obj-i386-y += pc_piix.oMakefile.target +1
-1-obj-i386-$(CONFIG_KVM) += kvm/clock.o +obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.oobj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
# shared objectshw/kvm/apic.c new file +19
-0@@ -0,0 +1,154 @@ +/* +* KVM in-kernel APIC support +* +* Copyright (c) 2011 Siemens AG +* +* Authors: +* Jan Kiszka <[email protected]> +* +* This work is licensed under the terms of the GNU GPL version 2. +* See the COPYING file in the top-level directory. +*/ +#include "hw/apic_internal.h" +#include "kvm.h" + +static inline void kvm_apic_set_reg (struct kvm_lapic_state *kapic, + int reg_id, uint32_t val) +{ + *((uint32_t *)(kapic->regs + (reg_id << 4))) = val; +}hw/kvm/apic.c line 29
Quoted 10 lines
hw/kvm/apic.c new file +10
-0+ +static inline uint32_t kvm_apic_get_reg (struct kvm_lapic_state *kapic, + int reg_id) +{ + return *((uint32_t *)(kapic->regs + (reg_id << 4))); +} + +int kvm_put_apic (CPUState *env) +{ + APICState *s = DO_UPCAST(APICState, busdev.qdev, env->apic_state);Please pass APICState instead of CPUState.
Quoted 4 lines
Quoted 1 line
DeviceState, I suppose. Yes, makes more sense, update will follow.
On second look: no, I'll keep it as is. All kvm_get/put_* helpers have this kind of signature, i.e. are working against env.
There's kvm_get_supported_msrs for example.
Quoted 3 lines
kvm_get/put_apic
just happens to be implemented outside oftarget-i386/kvm.c. And they require both APIC and CPUState anyway, so it makes no difference.
It does, passing CPUState violates layering. Please split the functions so that the ioctl calls which need CPUState go to kvm.c. For example, the functions in kvm/apic.c could just perform copying from kvm_lapic_state fields to APICstate fields and vice versa.
The KVM interface by the way does not look so clever. Why isn't there just an array of 32 bit fields so the casts can be avoided? Perhaps APICState should be (later) changed to match KVM version so that the structure can be passed directly without copying.
Re: [PATCH v4 12/15] kvm: x86: Add user space part for in-kernel APIC
Quoted 81 lines · Blue Swirl
Quoted 73 lines · Jan Kiszka
Quoted 72 lines · Jan Kiszka
Quoted 70 lines · Blue Swirl
Quoted 57 lines · Jan Kiszka
This introduces the alternative APIC backend which makes use of KVM's in-kernel device model. External NMI injection via LINT1 is emulated by checking the current state of the in-kernel APIC, only injecting a NMI into the VCPU if LINT1 is unmasked and configured to
DM_NMI.MSI is not yet supported, so we disable this when the in-kernel model is in use.
CC Lai Jiangshan <[email protected]>Signed-off-by Jan Kiszka <[email protected]>--- Makefile.target | 2 +- hw/kvm/apic.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pc.c | 15 ++++-- kvm.h | 3 + target-i386/kvm.c | 8 +++ 5 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 hw/kvm/apic.cMakefile.target +1
-1@@ -236,7 +236,7 @@ obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o obj-i386-y += pc_piix.o -obj-i386-$(CONFIG_KVM) += kvm/clock.o +obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o # shared objectshw/kvm/apic.c new file +19
-0@@ -0,0 +1,154 @@ +/* +* KVM in-kernel APIC support +* +* Copyright (c) 2011 Siemens AG +* +* Authors: +* Jan Kiszka <[email protected]> +* +* This work is licensed under the terms of the GNU GPL version 2. +* See the COPYING file in the top-level directory. +*/ +#include "hw/apic_internal.h" +#include "kvm.h" + +static inline void kvm_apic_set_reg (struct kvm_lapic_state *kapic, +int reg_id,uint32_t val) +{ + *((uint32_t *)(kapic->regs + (reg_id <<4 ))) = val; +}hw/kvm/apic.c line 29
Quoted 10 lines
hw/kvm/apic.c new file +10
-0+ +static inline uint32_t kvm_apic_get_reg (struct kvm_lapic_state *kapic, +int reg_id) +{ +return *((uint32_t *)(kapic->regs + (reg_id <<4 ))); +} + +int kvm_put_apic (CPUState *env) +{ +APICState *s =DO_UPCAST (APICState, busdev.qdev, env->apic_state);Please pass APICState instead of CPUState.
Quoted 4 lines
Quoted 1 line
DeviceState, I suppose. Yes, makes more sense, update will follow.
On second look: no, I'll keep it as is. All kvm_get/put_* helpers have this kind of signature, i.e. are working against env.
There's
kvm_get_supported_msrsfor example.
Quoted 8 lines
Quoted 3 lines
kvm_get/put_apic
just happens to be implemented outside oftarget-i386/kvm.c. And they require both APIC and CPUState anyway, so it makes no difference.It does, passing CPUState violates layering. Please split the functions so that the ioctl calls which need CPUState go to
kvm.c. For example, the functions inkvm/apic.ccould just perform copying fromkvm_lapic_statefields to APICstate fields and vice versa.
That's a good idea.
Quoted 5 lines
The KVM interface by the way does not look so clever. Why isn't there just an array of 32 bit fields so the casts can be avoided? Perhaps APICState should be (later) changed to match KVM version so that the structure can be passed directly without copying.
Wouldn't that complicate the use in the user space model again? At least for registers that are used with both backends.
Jan
Re: [PATCH v4 12/15] kvm: x86: Add user space part for in-kernel APIC
Quoted 94 lines · Jan Kiszka
Quoted 81 lines · Blue Swirl
Quoted 73 lines · Jan Kiszka
Quoted 72 lines · Jan Kiszka
Quoted 70 lines · Blue Swirl
Quoted 57 lines · Jan Kiszka
This introduces the alternative APIC backend which makes use of KVM's in-kernel device model. External NMI injection via LINT1 is emulated by checking the current state of the in-kernel APIC, only injecting a NMI into the VCPU if LINT1 is unmasked and configured to
DM_NMI.MSI is not yet supported, so we disable this when the in-kernel model is in use.
CC Lai Jiangshan <[email protected]>Signed-off-by Jan Kiszka <[email protected]>---
Makefile.target | 2 +-
hw/kvm/apic.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++hw/pc.c| 15 ++++--
kvm.h | 3 +
target-i386/kvm.c | 8 +++5 files changed, 176 insertions(+), 6 deletions(-)create mode 100644
hw/kvm/apic.cMakefile.target +0
-0@@ -236,7 +236,7 @@ obj-i386-y += vmport.oobj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o
obj-i386-y += pc_piix.oMakefile.target +1
-1-obj-i386-$(CONFIG_KVM) += kvm/clock.o +obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.oobj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
# shared objectshw/kvm/apic.c new file +19
-0@@ -0,0 +1,154 @@ +/* +* KVM in-kernel APIC support +* +* Copyright (c) 2011 Siemens AG +* +* Authors: +* Jan Kiszka <[email protected]> +* +* This work is licensed under the terms of the GNU GPL version 2. +* See the COPYING file in the top-level directory. +*/ +#include "hw/apic_internal.h" +#include "kvm.h" + +static inline void kvm_apic_set_reg (struct kvm_lapic_state *kapic, + int reg_id, uint32_t val) +{ + *((uint32_t *)(kapic->regs + (reg_id << 4))) = val; +}hw/kvm/apic.c line 29
Quoted 10 lines
hw/kvm/apic.c new file +10
-0+ +static inline uint32_t kvm_apic_get_reg (struct kvm_lapic_state *kapic, + int reg_id) +{ + return *((uint32_t *)(kapic->regs + (reg_id << 4))); +} + +int kvm_put_apic (CPUState *env) +{ + APICState *s = DO_UPCAST(APICState, busdev.qdev, env->apic_state);Please pass APICState instead of CPUState.
Quoted 4 lines
Quoted 1 line
DeviceState, I suppose. Yes, makes more sense, update will follow.
On second look: no, I'll keep it as is. All kvm_get/put_* helpers have this kind of signature, i.e. are working against env.
There's
kvm_get_supported_msrsfor example.Quoted 8 lines
Quoted 3 lines
kvm_get/put_apic
just happens to be implemented outside oftarget-i386/kvm.c. And they require both APIC and CPUState anyway, so it makes no difference.It does, passing CPUState violates layering. Please split the functions so that the ioctl calls which need CPUState go to
kvm.c. For example, the functions inkvm/apic.ccould just perform copying fromkvm_lapic_statefields to APICstate fields and vice versa.That's a good idea.
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
The KVM interface by the way does not look so clever. Why isn't there just an array of 32 bit fields so the casts can be avoided? Perhaps APICState should be (later) changed to match KVM version so that the structure can be passed directly without copying.
Wouldn't that complicate the use in the user space model again? At least for registers that are used with both backends.
Well, we have (at least) two styles how to model devices.
In the first one, the device state structure contains an array of registers, so the functions which use them may need for example to perform some bit field extraction to get what they need.
In the model used by APIC and others, the structure contains cooked values, for example divide_count and count_shift in APICState. This means that the CPU accesses get slightly slower since the fields need to be packed and unpacked but the other functions may be faster.
Which one is better depends on frequency and importance of register accesses by CPU vs. other accesses. But it shouldn't complicate that much either way. Actually design choices like this may have been taken without too much consideration.
Alternatively, KVM interface could be changed to take QEMU structure directly, but I don't suppose that would be a good idea. It would be easier for everyone if QEMU changed instead.
PATCH v4 13/15 kvm: x86: Add user space part for in-kernel i8259
In reply to Jan KiszkaIntroduce the alternative i8259 backend that exploits KVM in-kernel acceleration.
The PIIX3 initialization code is furthermore extended by KVM specific IRQ route setup. GSI injection differs in KVM mode from the user space model. As we can dispatch ISA-range IRQs to both IOAPIC and PIC inside the kernel, we do not need to inject them separately. This is reflected by a KVM-specific GSI handler.
--- Makefile.target | 2 +- hw/kvm/i8259.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pc.h | 1 + hw/pc_piix.c | 50 ++++++++++++++++++++-- 4 files changed, 174 insertions(+), 5 deletions(-) create mode 100644 hw/kvm/i8259.c
Makefile.target +1 -1
@@ -236,7 +236,7 @@ obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o obj-i386-y += pc_piix.o -obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o +obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o kvm/i8259.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o # shared objects
hw/kvm/i8259.c new file +126 -0
126 lines not on this page · raw message
hw/pc.h +1 -0
@@ -64,6 +64,7 @@ bool parallel_mm_init(MemoryRegion *address_space,typedef struct PicState PicState ;extern PicState *isa_pic;qemu_irq *i8259_init (qemu_irq parent_irq); +qemu_irq *kvm_i8259_init (void );int pic_read_irq (PicState *s);int pic_get_output (PicState *s);void pic_info (Monitor *mon);
hw/pc_piix.c +46 -4
70 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v4 14/15 kvm: x86: Add user space part for in-kernel IOAPIC
In reply to Jan KiszkaThis introduces the KVM-accelerated IOAPIC backend and extends the IRQ routing setup by the 0->2 redirection when needed.
The IOAPIC gains a KVM-specific property that allows to define the GSI base for injecting interrupts into the kernel model. This will allow to disentangle PIC and IOAPIC pins for chipsets that support more sophisticated IRQ routes than the PIIX3. So far the base is kept at 0, i.e. PIC and IOAPIC share pins 0..15.
--- Makefile.target | 2 +- hw/ioapic_common.c | 1 + hw/ioapic_internal.h | 1 + hw/kvm/ioapic.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pc_piix.c | 15 +++++++- 5 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 hw/kvm/ioapic.c
Makefile.target +1 -1
@@ -236,7 +236,7 @@ obj-i386-y += vmport.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o obj-i386-y += pc_piix.o -obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o kvm/i8259.o +obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o kvm/i8259.o kvm/ioapic.o obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o # shared objects
hw/ioapic_common.c +1 -0
@@ -122,6 +122,7 @@ static SysBusDeviceInfo ioapic_info = { .qdev.no_user = 1, .qdev.props = (Property []) {DEFINE_PROP_STRING ("backend" , IOAPICState, backend_name), +DEFINE_PROP_UINT32 ("kvm_gsi_base" , IOAPICState, kvm_gsi_base,0 ),DEFINE_PROP_END_OF_LIST (), }, };
hw/ioapic_internal.h +1 -0
@@ -95,6 +95,7 @@ struct IOAPICState {char *backend_name;IOAPICBackend *backend; +uint32_t kvm_gsi_base; };void ioapic_register_device (void );
hw/kvm/ioapic.c new file +101 -0
101 lines not on this page · raw message
hw/pc_piix.c +14 -1
@@ -68,6 +68,15 @@ static void kvm_piix3_setup_irq_routing(bool pci_enabled)for (i =8 ; i <16 ; ++i) {kvm_irqchip_add_route (s, i,KVM_IRQCHIP_PIC_SLAVE , i -8 ); } +if (pci_enabled) { +for (i =0 ; i <24 ; ++i) { +if (i ==0 ) { +kvm_irqchip_add_route (s, i,KVM_IRQCHIP_IOAPIC ,2 ); + }else if (i !=2 ) { +kvm_irqchip_add_route (s, i,KVM_IRQCHIP_IOAPIC , i); + } + } + } ret =kvm_irqchip_commit_routes (s);if (ret <0 ) {hw_error ("KVM IRQ routing setup failed" );
@@ -89,12 +98,16 @@ static void kvm_piix3_gsi_handler(void *opaque, int n, int level)static void ioapic_init (GSIState *gsi_state) { +const char *backend ="QEMU" ;DeviceState *dev;SysBusDevice *d;unsigned int i; dev =qdev_create (NULL ,"ioapic" ); -qdev_prop_set_string (dev,"backend" ,g_strdup ("QEMU" )); +if (kvm_enabled () &&kvm_irqchip_in_kernel ()) { + backend ="KVM" ; + } +qdev_prop_set_string (dev,"backend" ,g_strdup (backend));qdev_init_nofail (dev); d =sysbus_from_qdev (dev);sysbus_mmio_map (d,0 ,0xfec00000 );
Signature · 1 line
1.7.3.4
PATCH v4 15/15 kvm: Arm in-kernel irqchip support
In reply to Jan KiszkaMake the basic in-kernel irqchip support selectable via -machine ...,kernel_irqchip=on. Leave it off by default until it can fully replace user space models.
--- qemu-config.c | 4 ++++ qemu-options.hx | 5 ++++- 2 files changed, 8 insertions(+), 1 deletions(-)
qemu-config.c +4 -0
@@ -490,6 +490,10 @@ static QemuOptsList qemu_machine_opts = { .name = "accel", .type = QEMU_OPT_STRING, .help = "accelerator list", + }, { + .name = "kernel_irqchip", + .type = QEMU_OPT_BOOL, + .help = "use KVM in-kernel irqchip", }, {/* End of list */ } },
qemu-options.hx +4 -1
@@ -31,7 +31,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ "-machine [type=]name[,prop[=value][,...]]\n" " selects emulated machine (-machine ? for list)\n" " property accel=accel1[:accel2[:...]] selects accelerator\n" - " supported accelerators are kvm, xen, tcg (default: tcg)\n", + " supported accelerators are kvm, xen, tcg (default: tcg)\n" + " kernel_irqchip=on|off controls accelerated irqchip support\n", QEMU_ARCH_ALL) STEXI @item -machine [type=]@var{name}[,prop=@var{value}[,...]]
@@ -44,6 +45,8 @@ This is used to enable an accelerator. Depending on the target architecture, kvm, xen, or tcg can be available. By default, tcg is used. If there is more than one accelerator specified, the next one is used if the previous one fails to initialize. +@item kernel_irqchip=on|off +Enables in-kernel irqchip support for the chosen accelerator when available. @end table ETEXI
Signature · 1 line
1.7.3.4
Quoted 4 lines · Jan Kiszka
Changes in v4:
- rebased of current uq/master
- fixed stupid bugs that broke bisectability and user space irqchip mode
- integrated NMI-over-LINT1 injection logic
I had comments to one patch, others look fine.
Overall, string based subtype selection does not somehow seem to be a hot idea, but this could be used as a starting point which should be cleaned up later when we have proper device composition. APIC and x86 interrupt handling need more cleanup anyway.
Quoted 72 lines
CC Lai Jiangshan <[email protected]>Jan Kiszka (15):
msi: Generalizemsix_supportedtomsi_supported
kvm: Move kvmclock into hw/kvm folder
apic: Stop timer on reset
apic: Inject external NMI events via LINT1
apic: Introduce backend/frontend infrastructure for KVM reuse
apic: Open-code timer save/restore
i8259: Introduce backend/frontend infrastructure for KVM reuse
ioapic: Introduce backend/frontend infrastructure for KVM reuse
memory: Introducememory_region_init_reservation
kvm: Introduce core services for in-kernel irqchip support
kvm: x86: Establish IRQ0 override control
kvm: x86: Add user space part for in-kernel APIC
kvm: x86: Add user space part for in-kernel i8259
kvm: x86: Add user space part for in-kernel IOAPIC
kvm: Arm in-kernel irqchip supportMakefile.objs | 2 +-
Makefile.target | 6 +-configure | 1 + hw/apic.c | 309 ++++----------------------------------- hw/apic.h | 1 +hw/apic_common.c | 312 ++++++++++++++++++++++++++++++++++++++++
hw/apic_internal.h| 122 ++++++++++++++++
hw/i8259.c | 127 ++--------------hw/i8259_common.c| 173 ++++++++++++++++++++++hw/i8259_internal.h| 82 +++++++++++
hw/ioapic.c | 130 ++---------------hw/ioapic_common.c| 138 ++++++++++++++++++hw/ioapic_internal.h| 106 ++++++++++++++hw/kvm/apic.c| 154 ++++++++++++++++++++hw/{kvmclock.c=>kvm/clock.c} | 4 +-
hw/{kvmclock.h =>kvm/clock.h} | 0
hw/kvm/i8259.c | 126 ++++++++++++++++hw/kvm/ioapic.c| 101 +++++++++++++hw/msi.c | 8 + hw/msi.h | 2 + hw/msix.c | 9 +- hw/msix.h | 2 -hw/pc.c | 19 ++-
hw/pc.h | 1 +hw/pc_piix.c| 66 ++++++++-kvm-all.c| 154 ++++++++++++++++++++kvm-stub.c| 5 +
kvm.h | 13 ++memory.c | 36 +++++ memory.h | 16 ++ monitor.c | 6 +-qemu-config.c | 4 +
qemu-options.hx | 5 +-
sysemu.h | 1 -
target-i386/kvm.c | 19 +++
trace-events | 2 +-
vl.c | 1 -37 files changed, 1724 insertions(+), 539 deletions(-)create mode 100644
hw/apic_common.c
create mode 100644hw/apic_internal.h
create mode 100644hw/i8259_common.c
create mode 100644hw/i8259_internal.h
create mode 100644hw/ioapic_common.c
create mode 100644hw/ioapic_internal.h
create mode 100644hw/kvm/apic.c
renamehw/{kvmclock.c=>kvm/clock.c} (98%)
renamehw/{kvmclock.h=>kvm/clock.h} (100%)
create mode 100644hw/kvm/i8259.c
create mode 100644hw/kvm/ioapic.c--
1.7.3.4
Quoted 6 lines · Blue Swirl
Quoted 4 lines · Jan Kiszka
Changes in v4:
- rebased of current uq/master
- fixed stupid bugs that broke bisectability and user space irqchip mode
- integrated NMI-over-LINT1 injection logic
Quoted 6 lines
I had comments to one patch, others look fine.
Overall, string based subtype selection does not somehow seem to be a hot idea, but this could be used as a starting point which should be cleaned up later when we have proper device composition. APIC and x86 interrupt handling need more cleanup anyway.
Yes, more than likely. However, I think the string-based selection is the best that can be done right now. It gives us, e.g., pretty-printing of the backend property so that you can easily check what mode is in use.
The next area of ugliness will be the PIT and its relation to the HPET. I started looking into this, found some bugs, but do not really have a nice model for all that yet.
Looking into the remaining remarks now.
Thanks,
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 7 lines · Jan Kiszka
Changes in v4:
- rebased of current uq/master
- fixed stupid bugs that broke bisectability and user space irqchip mode
- integrated NMI-over-LINT1 injection logicCC Lai Jiangshan <[email protected]>
Quoted 16 lines
Jan Kiszka (15):
msi: Generalizemsix_supportedtomsi_supported
kvm: Move kvmclock into hw/kvm folder
apic: Stop timer on reset
apic: Inject external NMI events via LINT1
apic: Introduce backend/frontend infrastructure for KVM reuse
apic: Open-code timer save/restore
i8259: Introduce backend/frontend infrastructure for KVM reuse
ioapic: Introduce backend/frontend infrastructure for KVM reuse
memory: Introducememory_region_init_reservation
kvm: Introduce core services for in-kernel irqchip support
kvm: x86: Establish IRQ0 override control
kvm: x86: Add user space part for in-kernel APIC
kvm: x86: Add user space part for in-kernel i8259
kvm: x86: Add user space part for in-kernel IOAPIC
kvm: Arm in-kernel irqchip support
Looks good to me.
Any thoughts on the qemu-kvm merge plan? Sounds painful.
Quoted 25 lines · Marcelo Tosatti
Quoted 7 lines · Jan Kiszka
Changes in v4:
- rebased of current uq/master
- fixed stupid bugs that broke bisectability and user space irqchip mode
- integrated NMI-over-LINT1 injection logicCC Lai Jiangshan <[email protected]>Quoted 16 lines
Jan Kiszka (15):
msi: Generalizemsix_supportedtomsi_supported
kvm: Move kvmclock into hw/kvm folder
apic: Stop timer on reset
apic: Inject external NMI events via LINT1
apic: Introduce backend/frontend infrastructure for KVM reuse
apic: Open-code timer save/restore
i8259: Introduce backend/frontend infrastructure for KVM reuse
ioapic: Introduce backend/frontend infrastructure for KVM reuse
memory: Introducememory_region_init_reservation
kvm: Introduce core services for in-kernel irqchip support
kvm: x86: Establish IRQ0 override control
kvm: x86: Add user space part for in-kernel APIC
kvm: x86: Add user space part for in-kernel i8259
kvm: x86: Add user space part for in-kernel IOAPIC
kvm: Arm in-kernel irqchip support
Quoted 3 lines
Looks good to me.
Any thoughts on the qemu-kvm merge plan? Sounds painful.
Pain will be where the existing qemu-kvm extensions collide with these refactored upstream devices (backend/frontend split specifically). That's where we have to merge very carefully. Haven't tried this yet, will give it a spin tomorrow or so.
Quoted 1 line
From that point on, disabling the new stuff for now and at some point
switching over from the old one should be simple again.
BTW, PIT+HPET+speaker will cause similar issues for the same reasons.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 8 lines · Jan Kiszka
Quoted 2 lines
Any thoughts on the qemu-kvm merge plan? Sounds painful.
Pain will be where the existing qemu-kvm extensions collide with these refactored upstream devices (backend/frontend split specifically). That's where we have to merge very carefully. Haven't tried this yet, will give it a spin tomorrow or so.
Quoted 5 lines
From that point on, disabling the new stuff for now and at some point switching over from the old one should be simple again.
BTW, PIT+HPET+speaker will cause similar issues for the same reasons.
It's a little late for this, but refactoring qemu-kvm in-tree and then splitting it into patches would have been easier. Let's try it this way for the next batch.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 12 lines · Avi Kivity
Quoted 11 lines · Jan Kiszka
Quoted 2 lines
Any thoughts on the qemu-kvm merge plan? Sounds painful.
Pain will be where the existing qemu-kvm extensions collide with these refactored upstream devices (backend/frontend split specifically). That's where we have to merge very carefully. Haven't tried this yet, will give it a spin tomorrow or so.
From that point on, disabling the new stuff for now and at some point switching over from the old one should be simple again.
Quoted 6 lines
Quoted 2 lines
BTW, PIT+HPET+speaker will cause similar issues for the same reasons.
It's a little late for this, but refactoring qemu-kvm in-tree and then splitting it into patches would have been easier. Let's try it this way for the next batch.
I thought about this, but it definitely takes a clean, qemu-kvm free base as start. The point is to design something free of all the legacy, only looking at the other code base to extract the logic.
Moreover, there was and still is quite some upstream cleanup necessary, and that never goes well with the delta of qemu-kvm.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 7 lines · Jan Kiszka
Quoted 3 lines
It's a little late for this, but refactoring qemu-kvm in-tree and then splitting it into patches would have been easier. Let's try it this way for the next batch.
I thought about this, but it definitely takes a clean, qemu-kvm free base as start. The point is to design something free of all the legacy, only looking at the other code base to extract the logic.
If qemu-kvm was merged into qemu as is, then I'm sure you'd be able to refactor it into good shape (though there might be a little less motivation).
Quoted 2 lines
Moreover, there was and still is quite some upstream cleanup necessary, and that never goes well with the delta of qemu-kvm.
That's a good point.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 26 lines · Jan Kiszka
Quoted 25 lines · Marcelo Tosatti
Quoted 23 lines · Jan Kiszka
Changes in v4:
- rebased of current uq/master
- fixed stupid bugs that broke bisectability and user space irqchip mode
- integrated NMI-over-LINT1 injection logicCC Lai Jiangshan <[email protected]>Jan Kiszka (15):
msi: Generalizemsix_supportedtomsi_supported
kvm: Move kvmclock into hw/kvm folder
apic: Stop timer on reset
apic: Inject external NMI events via LINT1
apic: Introduce backend/frontend infrastructure for KVM reuse
apic: Open-code timer save/restore
i8259: Introduce backend/frontend infrastructure for KVM reuse
ioapic: Introduce backend/frontend infrastructure for KVM reuse
memory: Introducememory_region_init_reservation
kvm: Introduce core services for in-kernel irqchip support
kvm: x86: Establish IRQ0 override control
kvm: x86: Add user space part for in-kernel APIC
kvm: x86: Add user space part for in-kernel i8259
kvm: x86: Add user space part for in-kernel IOAPIC
kvm: Arm in-kernel irqchip support
Quoted 8 lines
Quoted 3 lines
Looks good to me.
Any thoughts on the qemu-kvm merge plan? Sounds painful.
Pain will be where the existing qemu-kvm extensions collide with these refactored upstream devices (backend/frontend split specifically). That's where we have to merge very carefully. Haven't tried this yet, will give it a spin tomorrow or so.
Done yesterday, still seems to work fine. The result can be found at
git://git.kiszka.org/qemu-kvm.git kvm-irqchip-merge
The integration of the upstream irqchip patches was, as expected, not that hard. But the merge of my earlier refactorings, the backend/frontend split-up caused some efforts.
I'm not sure what to do with that branch. We could either try to merge it before pulling in an upstream version that includes the new irqchips. But that won't work without manual conflict resolution as well. Or the branch can serve as a reference for re-doing a merge later on.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 12 lines · Jan Kiszka
Quoted 7 lines
Quoted 2 lines
Any thoughts on the qemu-kvm merge plan? Sounds painful.
Pain will be where the existing qemu-kvm extensions collide with these refactored upstream devices (backend/frontend split specifically). That's where we have to merge very carefully. Haven't tried this yet, will give it a spin tomorrow or so.
Done yesterday, still seems to work fine. The result can be found at
git://git.kiszka.org/qemu-kvm.gitkvm-irqchip-merge
Quoted 8 lines
The integration of the upstream irqchip patches was, as expected, not that hard. But the merge of my earlier refactorings, the backend/frontend split-up caused some efforts.
I'm not sure what to do with that branch. We could either try to merge it before pulling in an upstream version that includes the new irqchips. But that won't work without manual conflict resolution as well. Or the branch can serve as a reference for re-doing a merge later on.
If we merge this before upstream, will the two sides end up equivalent? Sounds like it'll be pretty easy to resolve the conflicts if so.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 17 lines · Avi Kivity
Quoted 16 lines · Jan Kiszka
Quoted 7 lines
Quoted 2 lines
Any thoughts on the qemu-kvm merge plan? Sounds painful.
Pain will be where the existing qemu-kvm extensions collide with these refactored upstream devices (backend/frontend split specifically). That's where we have to merge very carefully. Haven't tried this yet, will give it a spin tomorrow or so.
Done yesterday, still seems to work fine. The result can be found at
git://git.kiszka.org/qemu-kvm.gitkvm-irqchip-mergeThe integration of the upstream irqchip patches was, as expected, not that hard. But the merge of my earlier refactorings, the backend/frontend split-up caused some efforts.
Quoted 6 lines
Quoted 4 lines
I'm not sure what to do with that branch. We could either try to merge it before pulling in an upstream version that includes the new irqchips. But that won't work without manual conflict resolution as well. Or the branch can serve as a reference for re-doing a merge later on.
If we merge this before upstream, will the two sides end up equivalent?
qemu-kvm will carry the new upstream bits but will keep them widely disabled until upstream is feature equivalent. Of course, merging the kvm-irqchip-merge only makes sense once the corresponding upstream queue was actually merged.
Quoted 2 lines
Sounds like it'll be pretty easy to resolve the conflicts if so.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux