From c2d8d311c18b13c5282ab7d7b2ae57e3dd1e7f7d Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Mon, 14 Nov 2011 15:07:01 +0000 Subject: xen: do not initialize the interval timer and PCSPK emulator PIT and PCSPK are emulated by the hypervisor so we don't need to emulate them in Qemu: this patch prevents Qemu from waking up needlessly at PIT_FREQ on Xen. Signed-off-by: Stefano Stabellini --- hw/pc.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index 4d34a335ed..a752a6b2fc 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -47,6 +47,7 @@ #include "ui/qemu-spice.h" #include "memory.h" #include "exec-memory.h" +#include "arch_init.h" /* output Bochs bios info messages */ //#define DEBUG_BIOS @@ -1097,7 +1098,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, qemu_irq pit_alt_irq = NULL; qemu_irq rtc_irq = NULL; qemu_irq *a20_line; - ISADevice *i8042, *port92, *vmmouse, *pit; + ISADevice *i8042, *port92, *vmmouse, *pit = NULL; qemu_irq *cpu_exit_irq; register_ioport_write(0x80, 1, 1, ioport80_write, NULL); @@ -1126,16 +1127,18 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, qemu_register_boot_set(pc_boot_set, *rtc_state); - if (kvm_irqchip_in_kernel()) { - pit = kvm_pit_init(isa_bus, 0x40); - } else { - pit = pit_init(isa_bus, 0x40, pit_isa_irq, pit_alt_irq); - } - if (hpet) { - /* connect PIT to output control line of the HPET */ - qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(&pit->qdev, 0)); + if (!xen_enabled()) { + if (kvm_irqchip_in_kernel()) { + pit = kvm_pit_init(isa_bus, 0x40); + } else { + pit = pit_init(isa_bus, 0x40, pit_isa_irq, pit_alt_irq); + } + if (hpet) { + /* connect PIT to output control line of the HPET */ + qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(&pit->qdev, 0)); + } + pcspk_init(isa_bus, pit); } - pcspk_init(isa_bus, pit); for(i = 0; i < MAX_SERIAL_PORTS; i++) { if (serial_hds[i]) { -- cgit v1.2.3 From 95d5d75ede92c7ae7b47e8de2694db969b7fc06f Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Mon, 21 Nov 2011 11:10:21 +0000 Subject: xen: disable rtc_clock rtc_clock is only used by the RTC emulator (mc146818rtc.c), however Xen has its own RTC emulator in the hypervisor so we can disable it. Signed-off-by: Stefano Stabellini --- xen-all.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xen-all.c b/xen-all.c index bdf9c0fc79..b88ad5ddad 100644 --- a/xen-all.c +++ b/xen-all.c @@ -603,6 +603,10 @@ void xen_vcpu_init(void) qemu_register_reset(xen_reset_vcpu, first_cpu); xen_reset_vcpu(first_cpu); } + /* if rtc_clock is left to default (host_clock), disable it */ + if (rtc_clock == host_clock) { + qemu_clock_enable(rtc_clock, false); + } } /* get the ioreq packets from share mem */ -- cgit v1.2.3 From ba1dffed6342f900595b97435c05646f559b5ea7 Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Fri, 13 Apr 2012 16:44:54 +0000 Subject: xen_disk: remove syncwrite option This patch removes a dead option. The same can be achieved removing BDRV_O_NOCACHE and BDRV_O_CACHE_WB from the flags passed to bdrv_open. Signed-off-by: Stefano Stabellini --- hw/xen_disk.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/hw/xen_disk.c b/hw/xen_disk.c index 22dbd10303..49e53b7e78 100644 --- a/hw/xen_disk.c +++ b/hw/xen_disk.c @@ -48,7 +48,6 @@ /* ------------------------------------------------------------- */ -static int syncwrite = 0; static int batch_maps = 0; static int max_requests = 32; @@ -189,15 +188,10 @@ static int ioreq_parse(struct ioreq *ioreq) ioreq->presync = 1; return 0; } - if (!syncwrite) { - ioreq->presync = ioreq->postsync = 1; - } + ioreq->presync = ioreq->postsync = 1; /* fall through */ case BLKIF_OP_WRITE: ioreq->prot = PROT_READ; /* from memory */ - if (syncwrite) { - ioreq->postsync = 1; - } break; default: xen_be_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n", -- cgit v1.2.3 From c6961b7d38317fd48a8e86a8c2be4b9aeeb71ac0 Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Thu, 26 Apr 2012 16:35:53 +0000 Subject: xen_disk: use bdrv_aio_flush instead of bdrv_flush Use bdrv_aio_flush instead of bdrv_flush. Make sure to call bdrv_aio_writev/readv after the presync bdrv_aio_flush is fully completed and make sure to call the postsync bdrv_aio_flush after bdrv_aio_writev/readv is fully completed. Signed-off-by: Stefano Stabellini --- hw/xen_disk.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/hw/xen_disk.c b/hw/xen_disk.c index 49e53b7e78..cf06243834 100644 --- a/hw/xen_disk.c +++ b/hw/xen_disk.c @@ -66,6 +66,7 @@ struct ioreq { QEMUIOVector v; int presync; int postsync; + uint8_t mapped; /* grant mapping */ uint32_t domids[BLKIF_MAX_SEGMENTS_PER_REQUEST]; @@ -242,7 +243,7 @@ static void ioreq_unmap(struct ioreq *ioreq) XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev; int i; - if (ioreq->v.niov == 0) { + if (ioreq->v.niov == 0 || ioreq->mapped == 0) { return; } if (batch_maps) { @@ -268,6 +269,7 @@ static void ioreq_unmap(struct ioreq *ioreq) ioreq->page[i] = NULL; } } + ioreq->mapped = 0; } static int ioreq_map(struct ioreq *ioreq) @@ -275,7 +277,7 @@ static int ioreq_map(struct ioreq *ioreq) XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev; int i; - if (ioreq->v.niov == 0) { + if (ioreq->v.niov == 0 || ioreq->mapped == 1) { return 0; } if (batch_maps) { @@ -307,9 +309,12 @@ static int ioreq_map(struct ioreq *ioreq) ioreq->blkdev->cnt_map++; } } + ioreq->mapped = 1; return 0; } +static int ioreq_runio_qemu_aio(struct ioreq *ioreq); + static void qemu_aio_complete(void *opaque, int ret) { struct ioreq *ioreq = opaque; @@ -321,11 +326,19 @@ static void qemu_aio_complete(void *opaque, int ret) } ioreq->aio_inflight--; + if (ioreq->presync) { + ioreq->presync = 0; + ioreq_runio_qemu_aio(ioreq); + return; + } if (ioreq->aio_inflight > 0) { return; } if (ioreq->postsync) { - bdrv_flush(ioreq->blkdev->bs); + ioreq->postsync = 0; + ioreq->aio_inflight++; + bdrv_aio_flush(ioreq->blkdev->bs, qemu_aio_complete, ioreq); + return; } ioreq->status = ioreq->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY; @@ -345,7 +358,8 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) ioreq->aio_inflight++; if (ioreq->presync) { - bdrv_flush(blkdev->bs); /* FIXME: aio_flush() ??? */ + bdrv_aio_flush(ioreq->blkdev->bs, qemu_aio_complete, ioreq); + return 0; } switch (ioreq->req.operation) { -- cgit v1.2.3 From ed5477664369c1e9de23b0e7e8f16a418573bd2a Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Mon, 14 May 2012 16:46:33 +0000 Subject: xen_disk: properly update stats in ioreq_release() While for the "normal" case (called from blk_send_response_all()) decrementing requests_finished is correct, doing so in the parse error case is wrong; requests_inflight needs to be decremented instead. Signed-off-by: Jan Beulich Signed-off-by: Stefano Stabellini Reviewed-by: Kevin Wolf --- hw/xen_disk.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/xen_disk.c b/hw/xen_disk.c index cf06243834..07594bc0c8 100644 --- a/hw/xen_disk.c +++ b/hw/xen_disk.c @@ -154,7 +154,7 @@ static void ioreq_finish(struct ioreq *ioreq) blkdev->requests_finished++; } -static void ioreq_release(struct ioreq *ioreq) +static void ioreq_release(struct ioreq *ioreq, bool finish) { struct XenBlkDev *blkdev = ioreq->blkdev; @@ -162,7 +162,11 @@ static void ioreq_release(struct ioreq *ioreq) memset(ioreq, 0, sizeof(*ioreq)); ioreq->blkdev = blkdev; QLIST_INSERT_HEAD(&blkdev->freelist, ioreq, list); - blkdev->requests_finished--; + if (finish) { + blkdev->requests_finished--; + } else { + blkdev->requests_inflight--; + } } /* @@ -457,7 +461,7 @@ static void blk_send_response_all(struct XenBlkDev *blkdev) while (!QLIST_EMPTY(&blkdev->finished)) { ioreq = QLIST_FIRST(&blkdev->finished); send_notify += blk_send_response_one(ioreq); - ioreq_release(ioreq); + ioreq_release(ioreq, true); } if (send_notify) { xen_be_send_notify(&blkdev->xendev); @@ -513,7 +517,7 @@ static void blk_handle_requests(struct XenBlkDev *blkdev) if (blk_send_response_one(ioreq)) { xen_be_send_notify(&blkdev->xendev); } - ioreq_release(ioreq); + ioreq_release(ioreq, false); continue; } -- cgit v1.2.3 From a4f1a7589ad0926fc8db1a6c56d1c3e015be565c Mon Sep 17 00:00:00 2001 From: Anthony PERARD Date: Thu, 17 May 2012 10:31:20 +0000 Subject: xen: Fix PV-on-HVM In the context of PV-on-HVM under Xen, the emulated nics are supposed to be unplug before the guest drivers are initialized, when the guest write to a specific IO port. Without this patch, the guest end up with two nics with the same MAC, the emulated nic and the PV nic. Signed-off-by: Anthony PERARD Signed-off-by: Stefano Stabellini Acked-by: Paolo Bonzini --- hw/xen_platform.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/xen_platform.c b/hw/xen_platform.c index a9c52a6e36..0214f370b2 100644 --- a/hw/xen_platform.c +++ b/hw/xen_platform.c @@ -87,7 +87,10 @@ static void unplug_nic(PCIBus *b, PCIDevice *d) { if (pci_get_word(d->config + PCI_CLASS_DEVICE) == PCI_CLASS_NETWORK_ETHERNET) { - qdev_unplug(&(d->qdev), NULL); + /* Until qdev_free includes a call to object_unparent, we call it here + */ + object_unparent(&d->qdev.parent_obj); + qdev_free(&d->qdev); } } -- cgit v1.2.3 From 180640ea071c98739b6cc55b8d03367bcb442b94 Mon Sep 17 00:00:00 2001 From: "John V. Baboval" Date: Thu, 17 May 2012 10:33:09 +0000 Subject: Call xc_domain_shutdown with the reboot flag when the guest requests a reboot. Signed-off-by: John V. Baboval Signed-off-by: Tom Goetz Signed-off-by: Anthony PERARD Signed-off-by: Stefano Stabellini --- hw/xen_common.h | 2 +- xen-all.c | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/hw/xen_common.h b/hw/xen_common.h index 7043c14cae..fe7f227f92 100644 --- a/hw/xen_common.h +++ b/hw/xen_common.h @@ -148,6 +148,6 @@ static inline int xen_xc_hvm_inject_msi(XenXC xen_xc, domid_t dom, } #endif -void destroy_hvm_domain(void); +void destroy_hvm_domain(bool reboot); #endif /* QEMU_HW_XEN_COMMON_H */ diff --git a/xen-all.c b/xen-all.c index b88ad5ddad..b5220cc6a3 100644 --- a/xen-all.c +++ b/xen-all.c @@ -860,7 +860,7 @@ static void cpu_handle_ioreq(void *opaque) "data: %"PRIx64", count: %" FMT_ioreq_size ", size: %" FMT_ioreq_size "\n", req->state, req->data_is_ptr, req->addr, req->data, req->count, req->size); - destroy_hvm_domain(); + destroy_hvm_domain(false); return; } @@ -874,10 +874,11 @@ static void cpu_handle_ioreq(void *opaque) */ if (runstate_is_running()) { if (qemu_shutdown_requested_get()) { - destroy_hvm_domain(); + destroy_hvm_domain(false); } if (qemu_reset_requested_get()) { qemu_system_reset(VMRESET_REPORT); + destroy_hvm_domain(true); } } @@ -1163,7 +1164,7 @@ int xen_hvm_init(void) return 0; } -void destroy_hvm_domain(void) +void destroy_hvm_domain(bool reboot) { XenXC xc_handle; int sts; @@ -1172,12 +1173,15 @@ void destroy_hvm_domain(void) if (xc_handle == XC_HANDLER_INITIAL_VALUE) { fprintf(stderr, "Cannot acquire xenctrl handle\n"); } else { - sts = xc_domain_shutdown(xc_handle, xen_domid, SHUTDOWN_poweroff); + sts = xc_domain_shutdown(xc_handle, xen_domid, + reboot ? SHUTDOWN_reboot : SHUTDOWN_poweroff); if (sts != 0) { - fprintf(stderr, "? xc_domain_shutdown failed to issue poweroff, " - "sts %d, %s\n", sts, strerror(errno)); + fprintf(stderr, "xc_domain_shutdown failed to issue %s, " + "sts %d, %s\n", reboot ? "reboot" : "poweroff", + sts, strerror(errno)); } else { - fprintf(stderr, "Issued domain %d poweroff\n", xen_domid); + fprintf(stderr, "Issued domain %d %s\n", xen_domid, + reboot ? "reboot" : "poweroff"); } xc_interface_close(xc_handle); } -- cgit v1.2.3