Stefano Stabellini
2012-Apr-12 10:20 UTC
[PATCH v2 0/2] MSI/MSIX injection for Xen HVM guests
Hi all, this patch series by Wei Liu implements a simple Xen APIC module and use it to deliver MSI/MSIX for Xen HVM guests. The second version of this series includes the "or later" copyright clause for xen_apic.c and a fix to the return value of xen_apic_mem_read (thanks Peter for finding it out). Stefano Stabellini (2): Xen: basic HVM MSI injection support. Xen: Add xen-apic support and hook it up. Makefile.target | 2 +- hw/pc.c | 8 +++++ hw/xen.h | 1 + hw/xen_apic.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ xen-all.c | 5 +++ xen-stub.c | 4 ++ 6 files changed, 109 insertions(+), 1 deletions(-) Cheers, Stefano
Stefano Stabellini
2012-Apr-12 10:21 UTC
[PATCH v2 1/2] Xen: basic HVM MSI injection support.
From: "Wei Liu" <wei.liu2@citrix.com> Signed-off-by: Wei Liu <wei.liu2@citrix.com> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> --- hw/xen.h | 1 + xen-all.c | 5 +++++ xen-stub.c | 4 ++++ 3 files changed, 10 insertions(+), 0 deletions(-) diff --git a/hw/xen.h b/hw/xen.h index b46879c..e5926b7 100644 --- a/hw/xen.h +++ b/hw/xen.h @@ -34,6 +34,7 @@ static inline int xen_enabled(void) int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num); void xen_piix3_set_irq(void *opaque, int irq_num, int level); void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len); +void xen_hvm_inject_msi(uint64_t addr, uint32_t data); void xen_cmos_set_s3_resume(void *opaque, int irq, int level); qemu_irq *xen_interrupt_controller_init(void); diff --git a/xen-all.c b/xen-all.c index 3e6de41..abd2b2d 100644 --- a/xen-all.c +++ b/xen-all.c @@ -122,6 +122,11 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) } } +void xen_hvm_inject_msi(uint64_t addr, uint32_t data) +{ + xc_hvm_inject_msi(xen_xc, xen_domid, addr, data); +} + static void xen_suspend_notifier(Notifier *notifier, void *data) { xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 3); diff --git a/xen-stub.c b/xen-stub.c index 9ea02d4..8ff2b79 100644 --- a/xen-stub.c +++ b/xen-stub.c @@ -29,6 +29,10 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) { } +void xen_hvm_inject_msi(uint64_t addr, uint32_t data) +{ +} + void xen_cmos_set_s3_resume(void *opaque, int irq, int level) { } -- 1.7.2.5
Stefano Stabellini
2012-Apr-12 10:21 UTC
[PATCH v2 2/2] Xen: Add xen-apic support and hook it up.
From: "Wei Liu" <wei.liu2@citrix.com> Signed-off-by: Wei Liu <wei.liu2@citrix.com> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Acked-by: Paolo Bonzini <pbonzini@redhat.com> CC: Jan Kiszka <jan.kiszka@siemens.com> CC: Peter Maydell <peter.maydell@linaro.org> --- Makefile.target | 2 +- hw/pc.c | 8 +++++ hw/xen_apic.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 1 deletions(-) create mode 100644 hw/xen_apic.c diff --git a/Makefile.target b/Makefile.target index 14c8fa1..0c2d865 100644 --- a/Makefile.target +++ b/Makefile.target @@ -236,7 +236,7 @@ QEMU_CFLAGS += $(VNC_PNG_CFLAGS) obj-$(CONFIG_XEN) += xen-all.o xen_machine_pv.o xen_domainbuild.o xen-mapcache.o obj-$(CONFIG_NO_XEN) += xen-stub.o -obj-i386-$(CONFIG_XEN) += xen_platform.o +obj-i386-$(CONFIG_XEN) += xen_platform.o xen_apic.o # Inter-VM PCI shared memory CONFIG_IVSHMEM diff --git a/hw/pc.c b/hw/pc.c index 67f0479..1f5aacb 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -42,6 +42,7 @@ #include "sysbus.h" #include "sysemu.h" #include "kvm.h" +#include "xen.h" #include "blockdev.h" #include "ui/qemu-spice.h" #include "memory.h" @@ -891,9 +892,12 @@ static DeviceState *apic_init(void *env, uint8_t apic_id) if (kvm_irqchip_in_kernel()) { dev = qdev_create(NULL, "kvm-apic"); + } else if (xen_enabled()) { + dev = qdev_create(NULL, "xen-apic"); } else { dev = qdev_create(NULL, "apic"); } + qdev_prop_set_uint8(dev, "id", apic_id); qdev_prop_set_ptr(dev, "cpu_env", env); qdev_init_nofail(dev); @@ -912,6 +916,10 @@ static DeviceState *apic_init(void *env, uint8_t apic_id) msi_supported = true; } + if (xen_enabled()) { + msi_supported = true; + } + return dev; } diff --git a/hw/xen_apic.c b/hw/xen_apic.c new file mode 100644 index 0000000..1725ff6 --- /dev/null +++ b/hw/xen_apic.c @@ -0,0 +1,90 @@ +/* + * Xen basic APIC support + * + * Copyright (c) 2012 Citrix + * + * Authors: + * Wei Liu <wei.liu2@citrix.com> + * + * This work is licensed under the terms of the GNU GPL version 2 or + * later. See the COPYING file in the top-level directory. + */ +#include "hw/apic_internal.h" +#include "hw/msi.h" +#include "xen.h" + +static uint64_t xen_apic_mem_read(void *opaque, target_phys_addr_t addr, + unsigned size) +{ + return ~(uint64_t)0; +} + +static void xen_apic_mem_write(void *opaque, target_phys_addr_t addr, + uint64_t data, unsigned size) +{ + if (size != sizeof(uint32_t)) { + fprintf(stderr, "Xen: APIC write data size = %d, invalid\n", size); + return; + } + + xen_hvm_inject_msi(addr, data); +} + +static const MemoryRegionOps xen_apic_io_ops = { + .read = xen_apic_mem_read, + .write = xen_apic_mem_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void xen_apic_init(APICCommonState *s) +{ + memory_region_init_io(&s->io_memory, &xen_apic_io_ops, s, "xen-apic-msi", + MSI_SPACE_SIZE); +} + +static void xen_apic_set_base(APICCommonState *s, uint64_t val) +{ +} + +static void xen_apic_set_tpr(APICCommonState *s, uint8_t val) +{ +} + +static uint8_t xen_apic_get_tpr(APICCommonState *s) +{ + return 0; +} + +static void xen_apic_vapic_base_update(APICCommonState *s) +{ +} + +static void xen_apic_external_nmi(APICCommonState *s) +{ +} + +static void xen_apic_class_init(ObjectClass *klass, void *data) +{ + APICCommonClass *k = APIC_COMMON_CLASS(klass); + + k->init = xen_apic_init; + k->set_base = xen_apic_set_base; + k->set_tpr = xen_apic_set_tpr; + k->get_tpr = xen_apic_get_tpr; + k->vapic_base_update = xen_apic_vapic_base_update; + k->external_nmi = xen_apic_external_nmi; +} + +static TypeInfo xen_apic_info = { + .name = "xen-apic", + .parent = TYPE_APIC_COMMON, + .instance_size = sizeof(APICCommonState), + .class_init = xen_apic_class_init, +}; + +static void xen_apic_register_types(void) +{ + type_register_static(&xen_apic_info); +} + +type_init(xen_apic_register_types) -- 1.7.2.5
Seemingly Similar Threads
- [PATCH 0/0] MSI/MSIX injection for Xen HVM guests
- [PATCH BUILD FIX 0/2] build xc_hvm_inject_msi on Xen < 4.2
- [PATCH] qemu-xen: support PV on HVM MSIX remapping
- [PATCHv2 RFC] qemu/msix: remove msix_supported safety flag
- [PATCHv2 RFC] qemu/msix: remove msix_supported safety flag