Skip to contentSkip to conversation

Patch Round-up for stable 1.5.3, freeze on 2013-08-16

Qemu-devel New Michael Roth 2 participants 59 messages Aug 13, 2013 – Aug 14, 2013 Block layer

lore
Share & tools
lore
#0 lore raw

Hi everyone,

The following new patches are queued for QEMU stable v1.5.3:

https://github.com/mdroth/qemu/commits/stable-1.5-staging

The release is planned for 2013-08-21:

http://wiki.qemu.org/Planning/1.5

Please respond here or CC [email protected] on any patches you think should be included in the release. The cut-off date is 2013-08-16 for new patches.

Testing/feedback is greatly appreciated.

Thanks!

Andreas Färber (8):
target-cris: gen_intermediate_code_internal() should be inlined
target-lm32: gen_intermediate_code_internal() should be inlined
target-microblaze: gen_intermediate_code_internal() should be inlined
target-moxie: gen_intermediate_code_internal() should be inlined
target-xtensa: gen_intermediate_code_internal() should be inlined
megasas: Legacy command line handling fix
virtio-console: Use exitfn for virtserialport, too
target-i386: Fix X86CPU error handling

Anthony Liguori (1):
gtk: don't use g_object_unref on GdkCursor

Anthony PERARD (1):
qxl: Fix QXLRam initialisation.

Christian Borntraeger (2):
s390/virtio-ccw: Fix virtio reset
s390/ipl: Fix boot order

Don Koch (1):
pci-bridge: update mappings for migration/restore

Dongxue Zhang (1):
target-openrisc: Fix typename in openrisc_cpu_class_by_name()

Fam Zheng (1):
vmdk: remove wrong calculation of relative path

Gerd Hoffmann (4):
usb-host-libusb: set USB_DEV_FLAG_IS_HOST
xhci: handle USB_RET_IOERROR
xhci: fix segfault
i82801b11: Fix i82801b11 PCI host bridge config space

Hervé Poussineau (1):
ppc: do not register IABR SPR twice for 603e

Izumi Tsutsui (1):
semaphore: fix a hangup problem under load on NetBSD hosts.

KONRAD Frederic (1):
virtio-scsi: forward scsibus for virtio-scsi-pci.

Kevin Wolf (6):
gluster: Return bdrv_has_zero_init = 0
raw-posix: Fix /dev/cdrom magic on OS X
ahci: Fix FLUSH command
block: Add return value for bdrv_flush_all()
cpus: Add return value for vm_stop()
cpus: Let vm_stop[_force_state]() always flush block devices

Luiz Capitulino (1):
qapi: qapi-commands: fix possible leaks on visitor dealloc

MORITA Kazutaka (2):
iov: handle EOF in iov_send_recv
ignore SIGPIPE in qemu-img and qemu-io

Marcelo Tosatti (1):
kvmclock: clock should count only if vm is running

Markus Armbruster (4):
acl: acl_add can't insert before last list element, fix
qemu-char: Fix ID reuse after chardev-remove for qapi-based init
qemu-char: Register ring buffer driver with correct name "ringbuf"
qapi: Rename ChardevBackend member "memory" to "ringbuf"

Martijn van den Broek (1):
Bugfix for loading multiboot kernels

Michael Roth (1):
chardev: fix CHR_EVENT_OPENED events for mux chardevs

Michael S. Tsirkin (1):
vhost: clear signalled_used_valid on vhost stop

Paul Moore (3):
seccomp: add the asynchronous I/O syscalls to the whitelist
seccomp: add arch_prctl() to the syscall whitelist
seccomp: add additional asynchronous I/O syscalls

Peter Crosthwaite (1):
qom: Fix class cast of NULL classes

Peter Lieven (5):
Revert "migration: do not sent zero pages in bulk stage"
migration: do not overwrite zero pages
iscsi: fix -ENOSPC in iscsi_create()
iscsi: remove support for misaligned nb_sectors in aio_readv
iscsi: assert that sectors are aligned to LUN blocksize

Peter Maydell (1):
arm/boot: Free dtb blob memory after use

Richard W.M. Jones (1):
block/ssh: Set bdrv_has_zero_init according to the file type.

Ronnie Sahlberg (1):
Fix iSCSI crash on SG_IO with an iovector

Stefan Hajnoczi (4):
block: fix bdrv_flush() ordering in bdrv_close()
dataplane: refuse to start if device is already in use
dataplane: sync virtio.c and vring.c virtqueue state
virtio: clear signalled_used_valid when switching from dataplane

Stefan Weil (1):
gtk: Fix compiler warning (GTK 3 deprecated function)

 arch_init.c                         |   27 +++++-----
 block.c                             |   15 ++++--
 block/gluster.c                     |   10 ++++
 block/iscsi.c                       |   94 +++++++++++++++++++++++++----------
 block/raw-posix.c                   |    1 +
 block/ssh.c                         |   16 ++++++
 block/vmdk.c                        |   44 +---------------
 cpus.c                              |   25 +++++++---
 hw/arm/boot.c                       |   20 ++++++--
 hw/block/dataplane/virtio-blk.c     |   10 +++-
 hw/char/virtio-console.c            |    1 +
 hw/core/loader.c                    |    7 ++-
 hw/display/qxl.c                    |    1 +
 hw/i386/kvm/clock.c                 |   64 +++++++++++-------------
 hw/i386/pc.c                        |   13 +++--
 hw/ide/ahci.c                       |    8 ++-
 hw/ide/core.c                       |    9 ++++
 hw/ide/internal.h                   |    1 +
 hw/pci-bridge/i82801b11.c           |    1 +
 hw/pci/pci-hotplug.c                |   19 ++++++-
 hw/pci/pci.c                        |    5 ++
 hw/pci/pci_bridge.c                 |    2 +-
 hw/s390x/ipl.c                      |   22 ++++----
 hw/s390x/virtio-ccw.c               |    2 +
 hw/scsi/megasas.c                   |    5 +-
 hw/usb/hcd-xhci.c                   |    6 +--
 hw/usb/host-libusb.c                |    1 +
 hw/virtio/dataplane/vring.c         |    9 ++--
 hw/virtio/vhost.c                   |    1 +
 hw/virtio/virtio.c                  |    5 ++
 include/block/block.h               |    2 +-
 include/hw/pci/pci_bridge.h         |    1 +
 include/hw/virtio/dataplane/vring.h |    2 +-
 include/hw/virtio/virtio.h          |    1 +
 include/qemu/thread-posix.h         |    2 +-
 include/sysemu/char.h               |    1 +
 include/sysemu/sysemu.h             |    4 +-
 qapi-schema.json                    |    6 ++-
 qemu-char.c                         |   65 ++++++++++++++++++++++--
 qemu-img.c                          |    4 ++
 qemu-io.c                           |    4 ++
 qemu-seccomp.c                      |    8 ++-
 qom/object.c                        |    6 +--
 scripts/qapi-commands.py            |   17 ++++---
 stubs/vm-stop.c                     |    2 +-
 target-cris/translate.c             |    2 +-
 target-i386/cpu.c                   |    6 ++-
 target-lm32/translate.c             |    5 +-
 target-microblaze/translate.c       |    2 +-
 target-moxie/translate.c            |    2 +-
 target-openrisc/cpu.c               |    4 +-
 target-ppc/translate_init.c         |    5 --
 target-xtensa/translate.c           |    5 +-
 ui/gtk.c                            |    4 ++
 util/acl.c                          |    4 +-
 util/iov.c                          |    6 +++
 util/qemu-thread-posix.c            |   28 ++++++-----
 57 files changed, 423 insertions(+), 219 deletions(-)
#1 lore raw

PATCH 1/56 s390/virtio-ccw: Fix virtio reset

From: Christian Borntraeger <[email protected]>

On virtio reset we must reset the indicator to avoid stale interrupts, e.g. after a reset.

(cherry picked from commit 6504a93011138458a2e4f67b513c5a77bdb3cae1)
---
 hw/s390x/virtio-ccw.c |    2 ++
 1 file changed, 2 insertions(+)
hw/s390x/virtio-ccw.c +2 -0
index 201a635..de51589 100644
@@ -803,6 +803,8 @@ static void virtio_ccw_reset(DeviceState *d)
 
     virtio_reset(dev->vdev);
     css_reset_sch(dev->sch);
+    dev->indicators = 0;
+    dev->indicators2 = 0;
 }
 
 /**************** Virtio-ccw Bus Device Descriptions *******************/
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/56 arm/boot: Free dtb blob memory after use

In reply to Michael Roth

From: Peter Maydell <[email protected]>

The dtb blob returned by load_device_tree() is in memory allocated with g_malloc(). Free it accordingly once we have copied its contents into the guest memory. To make this easy, we need also to clean up the error handling in load_dtb() so that we consistently handle errors in the same way (by printing a message and then returning -1, rather than either plowing on or exiting immediately).

Message-id: [email protected] (cherry picked from commit c23045ded7571f0eaad95920ab00b6bc9c3a91e6)

Conflicts:

hw/arm/boot.c

* updated to include #ifdef for CONFIG_FDT

---
 hw/arm/boot.c |   20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
hw/arm/boot.c +15 -5
index f451529..6bffc3d 100644
@@ -238,14 +238,14 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo)
     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, binfo->dtb_filename);
     if (!filename) {
         fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename);
-        return -1;
+        goto fail;
     }
 
     fdt = load_device_tree(filename, &size);
     if (!fdt) {
         fprintf(stderr, "Couldn't open dtb file %s\n", filename);
         g_free(filename);
-        return -1;
+        goto fail;
     }
     g_free(filename);
 
@@ -253,7 +253,7 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo)
     scells = qemu_devtree_getprop_cell(fdt, "/", "#size-cells");
     if (acells == 0 || scells == 0) {
         fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 0)\n");
-        return -1;
+        goto fail;
     }
 
     mem_reg_propsize = acells + scells;
@@ -265,7 +265,7 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo)
     } else if (hival != 0) {
         fprintf(stderr, "qemu: dtb file not compatible with "
                 "RAM start address > 4GB\n");
-        exit(1);
+        goto fail;
     }
     mem_reg_property[acells + scells - 1] = cpu_to_be32(binfo->ram_size);
     hival = cpu_to_be32(binfo->ram_size >> 32);
@@ -274,13 +274,14 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo)
     } else if (hival != 0) {
         fprintf(stderr, "qemu: dtb file not compatible with "
                 "RAM size > 4GB\n");
-        exit(1);
+        goto fail;
     }
 
     rc = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
                               mem_reg_propsize * sizeof(uint32_t));
     if (rc < 0) {
         fprintf(stderr, "couldn't set /memory/reg\n");
+        goto fail;
     }
 
     if (binfo->kernel_cmdline && *binfo->kernel_cmdline) {
@@ -288,6 +289,7 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo)
                                           binfo->kernel_cmdline);
         if (rc < 0) {
             fprintf(stderr, "couldn't set /chosen/bootargs\n");
+            goto fail;
         }
     }
 
@@ -296,19 +298,27 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo)
                 binfo->initrd_start);
         if (rc < 0) {
             fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
+            goto fail;
         }
 
         rc = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end",
                     binfo->initrd_start + binfo->initrd_size);
         if (rc < 0) {
             fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
+            goto fail;
         }
     }
 
     cpu_physical_memory_write(addr, fdt, size);
 
+    g_free(fdt);
+
     return 0;
 
+fail:
+    g_free(fdt);
+    return -1;
+
 #else
     fprintf(stderr, "Device tree requested, "
                 "but qemu was compiled without fdt support\n");
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 3/56 ppc: do not register IABR SPR twice for 603e

In reply to Michael Roth

From: Hervé Poussineau <[email protected]>

IABR SPR is already registered in gen_spr_603(), called from init_proc_603E().

(cherry picked from commit 9fea2ae25080ad790d7d904d01a1300a45a634eb)
---
 target-ppc/translate_init.c |    5 -----
 1 file changed, 5 deletions(-)
target-ppc/translate_init.c +0 -5
index 021a31e..2e2bffa 100644
@@ -4980,11 +4980,6 @@ static void init_proc_603E (CPUPPCState *env)
                  SPR_NOACCESS, SPR_NOACCESS,
                  &spr_read_generic, &spr_write_generic,
                  0x00000000);
-    /* XXX : not implemented */
-    spr_register(env, SPR_IABR, "IABR",
-                 SPR_NOACCESS, SPR_NOACCESS,
-                 &spr_read_generic, &spr_write_generic,
-                 0x00000000);
     /* Memory management */
     gen_low_BATs(env);
     gen_6xx_7xx_soft_tlb(env, 64, 2);
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH 4/56 qxl: Fix QXLRam initialisation.

In reply to Michael Roth

From: Anthony PERARD <[email protected]>

The qxl driver expect NULL for QXLRam.memory_configs, but this is never initialized.

If memory is set to 0xc2c2.., it leads to a spice-critical error when trying to start qxl.

(cherry picked from commit 329f97fc4ff4b533fcd2d8f4eab6c9c2568aed27)
---
 hw/display/qxl.c |    1 +
 1 file changed, 1 insertion(+)
hw/display/qxl.c +1 -0
index c475cb1..937a402 100644
@@ -387,6 +387,7 @@ static void init_qxl_ram(PCIQXLDevice *d)
     d->ram->int_pending = cpu_to_le32(0);
     d->ram->int_mask    = cpu_to_le32(0);
     d->ram->update_surface = 0;
+    d->ram->monitors_config = 0;
     SPICE_RING_INIT(&d->ram->cmd_ring);
     SPICE_RING_INIT(&d->ram->cursor_ring);
     SPICE_RING_INIT(&d->ram->release_ring);
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH 5/56 virtio-scsi: forward scsibus for virtio-scsi-pci.

In reply to Michael Roth

From: KONRAD Frederic <[email protected]>

This fix a bug with scsi hotplug on virtio-scsi-pci:

As virtio-scsi-pci doesn't have any scsi bus, we need to forward scsi-hot-add to the virtio-scsi-device plugged on the virtio-bus.

---
 hw/pci/pci-hotplug.c |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
hw/pci/pci-hotplug.c +17 -2
index 12287d1..c708752 100644
@@ -30,6 +30,8 @@
 #include "monitor/monitor.h"
 #include "hw/scsi/scsi.h"
 #include "hw/virtio/virtio-blk.h"
+#include "hw/virtio/virtio-scsi.h"
+#include "hw/virtio/virtio-pci.h"
 #include "qemu/config-file.h"
 #include "sysemu/blockdev.h"
 #include "qapi/error.h"
@@ -79,13 +81,26 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter,
 {
     SCSIBus *scsibus;
     SCSIDevice *scsidev;
+    VirtIOPCIProxy *virtio_proxy;
 
     scsibus = (SCSIBus *)
         object_dynamic_cast(OBJECT(QLIST_FIRST(&adapter->child_bus)),
                             TYPE_SCSI_BUS);
     if (!scsibus) {
-	error_report("Device is not a SCSI adapter");
-	return -1;
+        /*
+         * Check if the adapter is a virtio-scsi-pci, and forward scsi_hot_add
+         * to the virtio-scsi-device.
+         */
+        if (!object_dynamic_cast(OBJECT(adapter), TYPE_VIRTIO_SCSI_PCI)) {
+            error_report("Device is not a SCSI adapter");
+            return -1;
+        }
+        virtio_proxy = VIRTIO_PCI(adapter);
+        adapter = DEVICE(virtio_proxy->bus.vdev);
+        scsibus = (SCSIBus *)
+                  object_dynamic_cast(OBJECT(QLIST_FIRST(&adapter->child_bus)),
+                            TYPE_SCSI_BUS);
+        assert(scsibus);
     }
 
     /*
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH 6/56 acl: acl_add can't insert before last list element, fix

In reply to Michael Roth

From: Markus Armbruster <[email protected]>

Watch this:

    $ upstream-qemu -nodefaults -S -vnc :0,acl,sasl -monitor stdio
    QEMU 1.5.50 monitor - type 'help' for more information
    (qemu) acl_add vnc.username drei allow
    acl: added rule at position 1
    (qemu) acl_show vnc.username
    policy: deny
    1: allow drei
    (qemu) acl_add vnc.username zwei allow 1
    acl: added rule at position 2
    (qemu) acl_show vnc.username
    policy: deny
    1: allow drei
    2: allow zwei
    (qemu) acl_add vnc.username eins allow 1
    acl: added rule at position 1
    (qemu) acl_show vnc.username
    policy: deny
    1: allow eins
    2: allow drei
    3: allow zwei

The second acl_add inserts at position 2 instead of 1.

Root cause is an off-by-one in qemu_acl_insert(): when index == acl->nentries, it appends instead of inserting before the last list element.

(cherry picked from commit 4999f3a8a6009de05ba82e58e723277917f16254)
---
 util/acl.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
util/acl.c +2 -2
index a7f33ff..938b7ae 100644
@@ -138,9 +138,9 @@ int qemu_acl_insert(qemu_acl *acl,
 
     if (index <= 0)
         return -1;
-    if (index >= acl->nentries)
+    if (index > acl->nentries) {
         return qemu_acl_append(acl, deny, match);
-
+    }
 
     entry = g_malloc(sizeof(*entry));
     entry->match = g_strdup(match);
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH 7/56 usb-host-libusb: set USB_DEV_FLAG_IS_HOST

In reply to Michael Roth

From: Gerd Hoffmann <[email protected]>

... like host-{linux,bsd}.c do.

(cherry picked from commit 628e54857a82a3cb65ef96c12640c30d6307a064)
---
 hw/usb/host-libusb.c |    1 +
 1 file changed, 1 insertion(+)
hw/usb/host-libusb.c +1 -0
index 3a582c5..b7bb250 100644
@@ -891,6 +891,7 @@ static int usb_host_initfn(USBDevice *udev)
     USBHostDevice *s = USB_HOST_DEVICE(udev);
 
     loglevel = s->loglevel;
+    udev->flags |= (1 << USB_DEV_FLAG_IS_HOST);
     udev->auto_attach = 0;
     QTAILQ_INIT(&s->requests);
     QTAILQ_INIT(&s->isorings);
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH 8/56 s390/ipl: Fix boot order

In reply to Michael Roth

From: Christian Borntraeger <[email protected]>

The latest ipl code adaptions collided with some of the virtio refactoring rework. This resulted in always booting the first disk. Let's fix booting from a given ID.
The new code also checks for command lines without bootindex to avoid random behaviour when accessing dev_st (==0).

(cherry picked from commit 5c8ded6ef55761e80353f42d8e59c6e233a2f51a)
---
 hw/s390x/ipl.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
hw/s390x/ipl.c +12 -10
index 0aeb003..d69adb2 100644
@@ -154,17 +154,19 @@ static void s390_ipl_reset(DeviceState *dev)
     env->psw.mask = IPL_PSW_MASK;
 
     if (!ipl->kernel) {
-        /* booting firmware, tell what device to boot from */
+        /* Tell firmware, if there is a preferred boot device */
+        env->regs[7] = -1;
         DeviceState *dev_st = get_boot_device(0);
-        VirtioCcwDevice *ccw_dev = (VirtioCcwDevice *) object_dynamic_cast(
-                OBJECT(&(dev_st->parent_obj)), "virtio-blk-ccw");
-
-        if (ccw_dev) {
-            env->regs[7] = ccw_dev->sch->cssid << 24 |
-                           ccw_dev->sch->ssid << 16 |
-                           ccw_dev->sch->devno;
-        } else {
-            env->regs[7] = -1;
+        if (dev_st) {
+            VirtioCcwDevice *ccw_dev = (VirtioCcwDevice *) object_dynamic_cast(
+                OBJECT(qdev_get_parent_bus(dev_st)->parent),
+                TYPE_VIRTIO_CCW_DEVICE);
+
+            if (ccw_dev) {
+                env->regs[7] = ccw_dev->sch->cssid << 24 |
+                               ccw_dev->sch->ssid << 16 |
+                               ccw_dev->sch->devno;
+            }
         }
     }
 
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH 9/56 Fix iSCSI crash on SG_IO with an iovector

In reply to Michael Roth

From: Ronnie Sahlberg <[email protected]>

Don't assume that SG_IO is always invoked with a simple buffer, check the iovec_count and if it is >= 1 then we need to pass an array of iovectors to libiscsi instead of just a plain buffer.

(cherry picked from commit 0a53f010745635c39a83756a948df60a84e88fe5)
---
 block/iscsi.c |   51 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 44 insertions(+), 7 deletions(-)
block/iscsi.c +44 -7
index 0bbf0b1..fa5252c 100644
@@ -32,6 +32,7 @@
 #include "block/block_int.h"
 #include "trace.h"
 #include "block/scsi.h"
+#include "qemu/iov.h"
 
 #include <iscsi/iscsi.h>
 #include <iscsi/scsi-lowlevel.h>
@@ -651,6 +652,9 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status,
 {
     IscsiAIOCB *acb = opaque;
 
+    g_free(acb->buf);
+    acb->buf = NULL;
+
     if (acb->canceled != 0) {
         return;
     }
@@ -727,14 +731,30 @@ static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
     memcpy(&acb->task->cdb[0], acb->ioh->cmdp, acb->ioh->cmd_len);
     acb->task->expxferlen = acb->ioh->dxfer_len;
 
+    data.size = 0;
     if (acb->task->xfer_dir == SCSI_XFER_WRITE) {
-        data.data = acb->ioh->dxferp;
-        data.size = acb->ioh->dxfer_len;
+        if (acb->ioh->iovec_count == 0) {
+            data.data = acb->ioh->dxferp;
+            data.size = acb->ioh->dxfer_len;
+        } else {
+#if defined(LIBISCSI_FEATURE_IOVECTOR)
+            scsi_task_set_iov_out(acb->task,
+                                 (struct scsi_iovec *) acb->ioh->dxferp,
+                                 acb->ioh->iovec_count);
+#else
+            struct iovec *iov = (struct iovec *)acb->ioh->dxferp;
+
+            acb->buf = g_malloc(acb->ioh->dxfer_len);
+            data.data = acb->buf;
+            data.size = iov_to_buf(iov, acb->ioh->iovec_count, 0,
+                                   acb->buf, acb->ioh->dxfer_len);
+#endif
+        }
     }
+
     if (iscsi_scsi_command_async(iscsi, iscsilun->lun, acb->task,
                                  iscsi_aio_ioctl_cb,
-                                 (acb->task->xfer_dir == SCSI_XFER_WRITE) ?
-                                     &data : NULL,
+                                 (data.size > 0) ? &data : NULL,
                                  acb) != 0) {
         scsi_free_scsi_task(acb->task);
         qemu_aio_release(acb);
@@ -743,9 +763,26 @@ static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
 
     /* tell libiscsi to read straight into the buffer we got from ioctl */
     if (acb->task->xfer_dir == SCSI_XFER_READ) {
-        scsi_task_add_data_in_buffer(acb->task,
-                                     acb->ioh->dxfer_len,
-                                     acb->ioh->dxferp);
+        if (acb->ioh->iovec_count == 0) {
+            scsi_task_add_data_in_buffer(acb->task,
+                                         acb->ioh->dxfer_len,
+                                         acb->ioh->dxferp);
+        } else {
+#if defined(LIBISCSI_FEATURE_IOVECTOR)
+            scsi_task_set_iov_in(acb->task,
+                                 (struct scsi_iovec *) acb->ioh->dxferp,
+                                 acb->ioh->iovec_count);
+#else
+            int i;
+            for (i = 0; i < acb->ioh->iovec_count; i++) {
+                struct iovec *iov = (struct iovec *)acb->ioh->dxferp;
+
+                scsi_task_add_data_in_buffer(acb->task,
+                    iov[i].iov_len,
+                    iov[i].iov_base);
+            }
+#endif
+        }
     }
 
     iscsi_set_events(iscsilun);
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH 10/56 block/ssh: Set bdrv_has_zero_init according to the file type.

In reply to Michael Roth

From: "Richard W.M. Jones" <[email protected]>

If the remote is a regular file, set it to true (ie. reads of uninitialized areas in a newly created file will return zeroes). If we can't prove that, return false (a safe default).

Tested by adding a debugging print statement [not part of this commit] and creating a remote file and a remote block device:

  $ ./qemu-img create ssh://localhost/tmp/new 100M
  Formatting 'ssh://localhost/tmp/new', fmt=raw size=104857600
  filename ssh://localhost/tmp/new: has_zero_init = 1
  $ sudo lvcreate -L 1G -n tmp /dev/fedora
    Logical volume "tmp" created
  $ ./qemu-img create ssh://localhost/dev/fedora/tmp 1G
  Formatting 'ssh://localhost/dev/fedora/tmp', fmt=raw size=1073741824
  filename ssh://localhost/dev/fedora/tmp: has_zero_init = 0
Cc Kevin Wolf <[email protected]>
(cherry picked from commit 0b3f21e6a99c025c829d342ee417f317fe2e03b2)
---
 block/ssh.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
block/ssh.c +16 -0
index 246a70d..d7e7bf8 100644
@@ -716,6 +716,21 @@ static void ssh_close(BlockDriverState *bs)
     ssh_state_free(s);
 }
 
+static int ssh_has_zero_init(BlockDriverState *bs)
+{
+    BDRVSSHState *s = bs->opaque;
+    /* Assume false, unless we can positively prove it's true. */
+    int has_zero_init = 0;
+
+    if (s->attrs.flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) {
+        if (s->attrs.permissions & LIBSSH2_SFTP_S_IFREG) {
+            has_zero_init = 1;
+        }
+    }
+
+    return has_zero_init;
+}
+
 static void restart_coroutine(void *opaque)
 {
     Coroutine *co = opaque;
@@ -1037,6 +1052,7 @@ static BlockDriver bdrv_ssh = {
     .bdrv_file_open               = ssh_file_open,
     .bdrv_create                  = ssh_create,
     .bdrv_close                   = ssh_close,
+    .bdrv_has_zero_init           = ssh_has_zero_init,
     .bdrv_co_readv                = ssh_co_readv,
     .bdrv_co_writev               = ssh_co_writev,
     .bdrv_getlength               = ssh_getlength,
Signature · 1 line
1.7.9.5
#11 lore raw

PATCH 11/56 gluster: Return bdrv_has_zero_init = 0

In reply to Michael Roth

From: Kevin Wolf <[email protected]>

GlusterFS volumes can be backed by block devices, in which case bdrv_create() doesn't make sure that the image is zeroed out. It is currently not possibly to detect whether a given image is backed by a file or a block device, and incorrectly assuming that it is zeroed corrupts images during qemu-img convert, so let's err on the side of caution and always return 0.

(cherry picked from commit 8ab6feec2c7500faafd9a4571fb40d03dd360a64)
---
 block/gluster.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
block/gluster.c +10 -0
index 91acde2..61424bc 100644
@@ -574,6 +574,12 @@ static void qemu_gluster_close(BlockDriverState *bs)
     glfs_fini(s->glfs);
 }
 
+static int qemu_gluster_has_zero_init(BlockDriverState *bs)
+{
+    /* GlusterFS volume could be backed by a block device */
+    return 0;
+}
+
 static QEMUOptionParameter qemu_gluster_create_options[] = {
     {
         .name = BLOCK_OPT_SIZE,
@@ -595,6 +601,7 @@ static BlockDriver bdrv_gluster = {
     .bdrv_aio_readv               = qemu_gluster_aio_readv,
     .bdrv_aio_writev              = qemu_gluster_aio_writev,
     .bdrv_aio_flush               = qemu_gluster_aio_flush,
+    .bdrv_has_zero_init           = qemu_gluster_has_zero_init,
     .create_options               = qemu_gluster_create_options,
 };
 
@@ -610,6 +617,7 @@ static BlockDriver bdrv_gluster_tcp = {
     .bdrv_aio_readv               = qemu_gluster_aio_readv,
     .bdrv_aio_writev              = qemu_gluster_aio_writev,
     .bdrv_aio_flush               = qemu_gluster_aio_flush,
+    .bdrv_has_zero_init           = qemu_gluster_has_zero_init,
     .create_options               = qemu_gluster_create_options,
 };
 
@@ -625,6 +633,7 @@ static BlockDriver bdrv_gluster_unix = {
     .bdrv_aio_readv               = qemu_gluster_aio_readv,
     .bdrv_aio_writev              = qemu_gluster_aio_writev,
     .bdrv_aio_flush               = qemu_gluster_aio_flush,
+    .bdrv_has_zero_init           = qemu_gluster_has_zero_init,
     .create_options               = qemu_gluster_create_options,
 };
 
@@ -640,6 +649,7 @@ static BlockDriver bdrv_gluster_rdma = {
     .bdrv_aio_readv               = qemu_gluster_aio_readv,
     .bdrv_aio_writev              = qemu_gluster_aio_writev,
     .bdrv_aio_flush               = qemu_gluster_aio_flush,
+    .bdrv_has_zero_init           = qemu_gluster_has_zero_init,
     .create_options               = qemu_gluster_create_options,
 };
 
Signature · 1 line
1.7.9.5
#12 lore raw

PATCH 12/56 vmdk: remove wrong calculation of relative path

In reply to Michael Roth

From: Fam Zheng <[email protected]>

When creating image with backing file, the driver tries to calculate the relative path from created image file to backing file, but the path computation is incorrect. e.g.:

    $ qemu-img create -f vmdk -b vmdk-data-disk.vmdk vmdk-data-snapshot1
    Formatting 'vmdk-data-snapshot1', fmt=vmdk size=10737418240
    backing_file='vmdk-data-disk.vmdk' compat6=off zeroed_grain=off
    $ qemu-img info vmdk-data-snapshot1
    image: vmdk-data-snapshot1
    file format: vmdk
    virtual size: 10G (10737418240 bytes)
    disk size: 12K
->  backing file: disk.vmdk

The common part in file names, "vmdk-data-", is incorrectly forgotten by relative_path(). As the VMDK specification has no restriction on parentNameHint to be relative path, we simply remove this by using the backing_file option.

(cherry picked from commit 8ed610a1c983dd2ed1eed8841036af55751d115f)
---
 block/vmdk.c |   44 +-------------------------------------------
 1 file changed, 1 insertion(+), 43 deletions(-)
block/vmdk.c +1 -43
index ee50a73..8c8f1fd 100644
@@ -1465,45 +1465,6 @@ static int filename_decompose(const char *filename, char *path, char *prefix,
     return VMDK_OK;
 }
 
-static int relative_path(char *dest, int dest_size,
-        const char *base, const char *target)
-{
-    int i = 0;
-    int n = 0;
-    const char *p, *q;
-#ifdef _WIN32
-    const char *sep = "\\";
-#else
-    const char *sep = "/";
-#endif
-
-    if (!(dest && base && target)) {
-        return VMDK_ERROR;
-    }
-    if (path_is_absolute(target)) {
-        pstrcpy(dest, dest_size, target);
-        return VMDK_OK;
-    }
-    while (base[i] == target[i]) {
-        i++;
-    }
-    p = &base[i];
-    q = &target[i];
-    while (*p) {
-        if (*p == *sep) {
-            n++;
-        }
-        p++;
-    }
-    dest[0] = '\0';
-    for (; n; n--) {
-        pstrcat(dest, dest_size, "..");
-        pstrcat(dest, dest_size, sep);
-    }
-    pstrcat(dest, dest_size, q);
-    return VMDK_OK;
-}
-
 static int vmdk_create(const char *filename, QEMUOptionParameter *options)
 {
     int fd, idx = 0;
@@ -1603,7 +1564,6 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
         return -ENOTSUP;
     }
     if (backing_file) {
-        char parent_filename[PATH_MAX];
         BlockDriverState *bs = bdrv_new("");
         ret = bdrv_open(bs, backing_file, NULL, 0, NULL);
         if (ret != 0) {
@@ -1616,10 +1576,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
         }
         parent_cid = vmdk_read_cid(bs, 0);
         bdrv_delete(bs);
-        relative_path(parent_filename, sizeof(parent_filename),
-                      filename, backing_file);
         snprintf(parent_desc_line, sizeof(parent_desc_line),
-                "parentFileNameHint=\"%s\"", parent_filename);
+                "parentFileNameHint=\"%s\"", backing_file);
     }
 
     /* Create extents */
Signature · 1 line
1.7.9.5
#13 lore raw

PATCH 13/56 Revert "migration: do not sent zero pages in bulk stage"

In reply to Michael Roth

From: Peter Lieven <[email protected]>

Not sending zero pages breaks migration if a page is zero at the source but not at the destination. This can e.g. happen if different BIOS versions are used at source and destination. It has also been reported that migration on pseries is completely broken with this patch.

This effectively reverts commit f1c72795af573b24a7da5eb52375c9aba8a37972.

Conflicts:

arch_init.c

(cherry picked from commit 9ef051e5536b6368a1076046ec6c4ec4ac12b5c6)
---
 arch_init.c |   13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
arch_init.c +4 -9
index 522caeb..6afc57e 100644
@@ -457,15 +457,10 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
             bytes_sent = -1;
             if (is_zero_page(p)) {
                 acct_info.dup_pages++;
-                if (!ram_bulk_stage) {
-                    bytes_sent = save_block_hdr(f, block, offset, cont,
-                                                RAM_SAVE_FLAG_COMPRESS);
-                    qemu_put_byte(f, 0);
-                    bytes_sent++;
-                } else {
-                    acct_info.skipped_pages++;
-                    bytes_sent = 0;
-                }
+                bytes_sent = save_block_hdr(f, block, offset, cont,
+                                            RAM_SAVE_FLAG_COMPRESS);
+                qemu_put_byte(f, 0);
+                bytes_sent++;
             } else if (!ram_bulk_stage && migrate_use_xbzrle()) {
                 current_addr = block->offset + offset;
                 bytes_sent = save_xbzrle_page(f, p, current_addr, block,
Signature · 1 line
1.7.9.5
#14 lore raw

PATCH 14/56 migration: do not overwrite zero pages

In reply to Michael Roth

From: Peter Lieven <[email protected]>

on incoming migration do not memset pages to zero if they already read as zero. this will allocate a new zero page and consume memory unnecessarily. even if we madvise a MADV_DONTNEED later this will only deallocate the memory asynchronously.

(cherry picked from commit 211ea74022f51164a7729030b28eec90b6c99a08)
---
 arch_init.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
arch_init.c +8 -6
index 6afc57e..b526dd0 100644
@@ -832,14 +832,16 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             }
 
             ch = qemu_get_byte(f);
-            memset(host, ch, TARGET_PAGE_SIZE);
+            if (ch != 0 || !is_zero_page(host)) {
+                memset(host, ch, TARGET_PAGE_SIZE);
 #ifndef _WIN32
-            if (ch == 0 &&
-                (!kvm_enabled() || kvm_has_sync_mmu()) &&
-                getpagesize() <= TARGET_PAGE_SIZE) {
-                qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED);
-            }
+                if (ch == 0 &&
+                    (!kvm_enabled() || kvm_has_sync_mmu()) &&
+                    getpagesize() <= TARGET_PAGE_SIZE) {
+                    qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED);
+                }
 #endif
+            }
         } else if (flags & RAM_SAVE_FLAG_PAGE) {
             void *host;
 
Signature · 1 line
1.7.9.5
#15 lore raw

PATCH 15/56 raw-posix: Fix /dev/cdrom magic on OS X

In reply to Michael Roth

From: Kevin Wolf <[email protected]>

The raw-posix driver has code to provide a /dev/cdrom on OS X even though it doesn't really exist. However, since commit c66a6157 the real filename is dismissed after finding it, so opening /dev/cdrom fails. Put the filename back into the options QDict to make this work again.

(cherry picked from commit a5c5ea3f60c000bf18c99435439533728a5f34a2)
---
 block/raw-posix.c |    1 +
 1 file changed, 1 insertion(+)
block/raw-posix.c +1 -0
index c0ccf27..90ce9f8 100644
@@ -1350,6 +1350,7 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags)
                 qemu_close(fd);
             }
             filename = bsdPath;
+            qdict_put(options, "filename", qstring_from_str(filename));
         }
 
         if ( mediaIterator )
Signature · 1 line
1.7.9.5
#16 lore raw

PATCH 16/56 kvmclock: clock should count only if vm is running

In reply to Michael Roth

From: Marcelo Tosatti <[email protected]>

kvmclock should not count while vm is paused, because:

1) if the vm is paused for long periods, timekeeping math can overflow while converting the (large) clocksource delta to nanoseconds.

2) Users rely on CLOCK_MONOTONIC to count run time, that is, time which OS has been in a runnable state (see CLOCK_BOOTTIME).

Change kvmclock driver so as to save clock value when vm transitions from runnable to stopped state, and to restore clock value from stopped to runnable transition.

(cherry picked from commit 00f4d64ee76e873be881a82d893a591487aa7950)
---
 hw/i386/kvm/clock.c |   64 ++++++++++++++++++++++++---------------------------
 1 file changed, 30 insertions(+), 34 deletions(-)
hw/i386/kvm/clock.c +30 -34
index 87d4d0f..98e5ca5 100644
@@ -28,38 +28,6 @@ typedef struct KVMClockState {
     bool clock_valid;
 } KVMClockState;
 
-static void kvmclock_pre_save(void *opaque)
-{
-    KVMClockState *s = opaque;
-    struct kvm_clock_data data;
-    int ret;
-
-    if (s->clock_valid) {
-        return;
-    }
-    ret = kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, &data);
-    if (ret < 0) {
-        fprintf(stderr, "KVM_GET_CLOCK failed: %s\n", strerror(ret));
-        data.clock = 0;
-    }
-    s->clock = data.clock;
-    /*
-     * If the VM is stopped, declare the clock state valid to avoid re-reading
-     * it on next vmsave (which would return a different value). Will be reset
-     * when the VM is continued.
-     */
-    s->clock_valid = !runstate_is_running();
-}
-
-static int kvmclock_post_load(void *opaque, int version_id)
-{
-    KVMClockState *s = opaque;
-    struct kvm_clock_data data;
-
-    data.clock = s->clock;
-    data.flags = 0;
-    return kvm_vm_ioctl(kvm_state, KVM_SET_CLOCK, &data);
-}
 
 static void kvmclock_vm_state_change(void *opaque, int running,
                                      RunState state)
@@ -70,8 +38,18 @@ static void kvmclock_vm_state_change(void *opaque, int running,
     int ret;
 
     if (running) {
+        struct kvm_clock_data data;
+
         s->clock_valid = false;
 
+        data.clock = s->clock;
+        data.flags = 0;
+        ret = kvm_vm_ioctl(kvm_state, KVM_SET_CLOCK, &data);
+        if (ret < 0) {
+            fprintf(stderr, "KVM_SET_CLOCK failed: %s\n", strerror(ret));
+            abort();
+        }
+
         if (!cap_clock_ctrl) {
             return;
         }
@@ -84,6 +62,26 @@ static void kvmclock_vm_state_change(void *opaque, int running,
                 return;
             }
         }
+    } else {
+        struct kvm_clock_data data;
+        int ret;
+
+        if (s->clock_valid) {
+            return;
+        }
+        ret = kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, &data);
+        if (ret < 0) {
+            fprintf(stderr, "KVM_GET_CLOCK failed: %s\n", strerror(ret));
+            abort();
+        }
+        s->clock = data.clock;
+
+        /*
+         * If the VM is stopped, declare the clock state valid to
+         * avoid re-reading it on next vmsave (which would return
+         * a different value). Will be reset when the VM is continued.
+         */
+        s->clock_valid = true;
     }
 }
 
@@ -100,8 +98,6 @@ static const VMStateDescription kvmclock_vmsd = {
     .version_id = 1,
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
-    .pre_save = kvmclock_pre_save,
-    .post_load = kvmclock_post_load,
     .fields = (VMStateField[]) {
         VMSTATE_UINT64(clock, KVMClockState),
         VMSTATE_END_OF_LIST()
Signature · 1 line
1.7.9.5
#17 lore raw

PATCH 17/56 qemu-char: Fix ID reuse after chardev-remove for qapi-based init

In reply to Michael Roth

From: Markus Armbruster <[email protected]>

Commit 2c5f488 introduced qapi-based character device initialization as a new code path in qemu_chr_new_from_opts(). Unfortunately, it failed to store parameter opts in the new chardev. Therefore, qemu_chr_delete() doesn't delete it. Even though the device is gone, its options linger, and any attempt to create another one with the same ID fails.

Message-id: [email protected]

(cherry picked from commit 2ea3e2c1e85097c45a882dbc1fbba4a7fdb3ff1c)
---
 qemu-char.c |    1 +
 1 file changed, 1 insertion(+)
qemu-char.c +1 -0
index efe706d..b8ffcba 100644
@@ -3228,6 +3228,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
         }
 
         chr = qemu_chr_find(id);
+        chr->opts = opts;
 
     qapi_out:
         qapi_free_ChardevBackend(backend);
Signature · 1 line
1.7.9.5
#19 lore raw

PATCH 19/56 target-lm32: gen_intermediate_code_internal() should be inlined

In reply to Michael Roth

From: Andreas Färber <[email protected]>

(cherry picked from commit 28014bcab244e968cb03f20384943494bd069ee0)
---
 target-lm32/translate.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
target-lm32/translate.c +3 -2
index af9ce8c..3e44e5c 100644
@@ -1011,8 +1011,9 @@ static void check_breakpoint(CPULM32State *env, DisasContext *dc)
 }
 
 /* generate intermediate code for basic block 'tb'.  */
-static void gen_intermediate_code_internal(CPULM32State *env,
-        TranslationBlock *tb, int search_pc)
+static inline
+void gen_intermediate_code_internal(CPULM32State *env,
+                                    TranslationBlock *tb, int search_pc)
 {
     struct DisasContext ctx, *dc = &ctx;
     uint16_t *gen_opc_end;
Signature · 1 line
1.7.9.5
#18 lore raw

PATCH 18/56 target-cris: gen_intermediate_code_internal() should be inlined

In reply to Michael Roth

From: Andreas Färber <[email protected]>

(cherry picked from commit 6f47ec50db92b4bc77de06661a9e7a3eb538b660)
---
 target-cris/translate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-cris/translate.c +1 -1
index dbcb811..ad61071 100644
@@ -3161,7 +3161,7 @@ static void check_breakpoint(CPUCRISState *env, DisasContext *dc)
  */
 
 /* generate intermediate code for basic block 'tb'.  */
-static void
+static inline void
 gen_intermediate_code_internal(CPUCRISState *env, TranslationBlock *tb,
                                int search_pc)
 {
Signature · 1 line
1.7.9.5
#20 lore raw

PATCH 20/56 target-microblaze: gen_intermediate_code_internal() should be inlined

In reply to Michael Roth

From: Andreas Färber <[email protected]>

(cherry picked from commit fd327f48f7e5892318b6dca2c9c6030618f65728)
---
 target-microblaze/translate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-microblaze/translate.c +1 -1
index 06d2346..85b5488 100644
@@ -1737,7 +1737,7 @@ static void check_breakpoint(CPUMBState *env, DisasContext *dc)
 }
 
 /* generate intermediate code for basic block 'tb'.  */
-static void
+static inline void
 gen_intermediate_code_internal(CPUMBState *env, TranslationBlock *tb,
                                int search_pc)
 {
Signature · 1 line
1.7.9.5
#21 lore raw

PATCH 21/56 target-moxie: gen_intermediate_code_internal() should be inlined

In reply to Michael Roth

From: Andreas Färber <[email protected]>

(cherry picked from commit 13cccc692818a570d1fb1326c84d3edae68987aa)
---
 target-moxie/translate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-moxie/translate.c +1 -1
index cc02bd3..28a5462 100644
@@ -818,7 +818,7 @@ static int decode_opc(MoxieCPU *cpu, DisasContext *ctx)
 }
 
 /* generate intermediate code for basic block 'tb'.  */
-static void
+static inline void
 gen_intermediate_code_internal(MoxieCPU *cpu, TranslationBlock *tb,
                                bool search_pc)
 {
Signature · 1 line
1.7.9.5
#22 lore raw

PATCH 22/56 target-xtensa: gen_intermediate_code_internal() should be inlined

In reply to Michael Roth

From: Andreas Färber <[email protected]>

(cherry picked from commit ae06d4988d6799f0bd16f27c2bcf80fa1cd2cfd7)
---
 target-xtensa/translate.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
target-xtensa/translate.c +3 -2
index 06d68db..9e05a66 100644
@@ -2875,8 +2875,9 @@ static void gen_ibreak_check(CPUXtensaState *env, DisasContext *dc)
     }
 }
 
-static void gen_intermediate_code_internal(
-        CPUXtensaState *env, TranslationBlock *tb, int search_pc)
+static inline
+void gen_intermediate_code_internal(CPUXtensaState *env,
+                                    TranslationBlock *tb, int search_pc)
 {
     DisasContext dc;
     int insn_count = 0;
Signature · 1 line
1.7.9.5
#23 lore raw

PATCH 23/56 block: fix bdrv_flush() ordering in bdrv_close()

In reply to Michael Roth

From: Stefan Hajnoczi <[email protected]>

Since 80ccf93b we flush the block device during close. The bdrv_drain_all() call should come before bdrv_flush() to ensure guest write requests have completed. Otherwise we may miss pending writes when flushing.

Call bdrv_drain_all() again for safety as the final step after bdrv_flush(). This should not be necessary but we can be paranoid here in case bdrv_flush() left I/O pending.

(cherry picked from commit 58fda173e1156d24e5ff62361774715152188a07)
---
 block.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
block.c +3 -2
index 3f87489..c7c3e06 100644
@@ -1349,11 +1349,12 @@ void bdrv_reopen_abort(BDRVReopenState *reopen_state)
 
 void bdrv_close(BlockDriverState *bs)
 {
-    bdrv_flush(bs);
     if (bs->job) {
         block_job_cancel_sync(bs->job);
     }
-    bdrv_drain_all();
+    bdrv_drain_all(); /* complete I/O */
+    bdrv_flush(bs);
+    bdrv_drain_all(); /* in case flush left pending I/O */
     notifier_list_notify(&bs->close_notifiers, bs);
 
     if (bs->drv) {
Signature · 1 line
1.7.9.5
#24 lore raw

PATCH 24/56 target-openrisc: Fix typename in openrisc_cpu_class_by_name()

In reply to Michael Roth

From: Dongxue Zhang <[email protected]>

Commit 478032a93d908e59085c1ac56f10979942e7dc4f (target-openrisc:
Rename CPU subtypes) suffixed CPU sub-types with "-or32-cpu" but forgot to update openrisc_cpu_class_by_name(), so that it was still looking for the types without suffix.

Make target-openrisc running OK by adding the suffix to the model name.

This means it is no longer possible to use -cpu or1200-or32-cpu or -cpu any-or32-cpu though.

(cherry picked from commit 071b3364e7995036816aa4ebf80ecfa04b1a31de)
---
 target-openrisc/cpu.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
target-openrisc/cpu.c +3 -1
index ffe14f3..4e9a3e8 100644
@@ -97,12 +97,14 @@ static void openrisc_cpu_initfn(Object *obj)
 static ObjectClass *openrisc_cpu_class_by_name(const char *cpu_model)
 {
     ObjectClass *oc;
+    char *typename;
 
     if (cpu_model == NULL) {
         return NULL;
     }
 
-    oc = object_class_by_name(cpu_model);
+    typename = g_strdup_printf("%s-" TYPE_OPENRISC_CPU, cpu_model);
+    oc = object_class_by_name(typename);
     if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_OPENRISC_CPU) ||
                        object_class_is_abstract(oc))) {
         return NULL;
Signature · 1 line
1.7.9.5
#25 lore raw

PATCH 25/56 qom: Fix class cast of NULL classes

In reply to Michael Roth

From: Peter Crosthwaite <[email protected]>

Its clear from the implementation that class casting is supposed to work with a NULL class argument. Guard all dereferences of the class argument against NULL accordingly.

Message-id: 94cd5ba46b74eea289a7e582635820c1c54e66fa.1371546907.git.peter.crosthwaite@xilinx.com

(cherry picked from commit 9d6a3d58e4d1431ab3809ff621cfd1f9ec75eef5)
---
 qom/object.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
qom/object.c +3 -3
index 803b94b..b7ecb9f 100644
@@ -531,14 +531,14 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class,
 #ifdef CONFIG_QOM_CAST_DEBUG
     int i;
 
-    for (i = 0; i < OBJECT_CLASS_CAST_CACHE; i++) {
+    for (i = 0; class && i < OBJECT_CLASS_CAST_CACHE; i++) {
         if (class->cast_cache[i] == typename) {
             ret = class;
             goto out;
         }
     }
 #else
-    if (!class->interfaces) {
+    if (!class || !class->interfaces) {
         return class;
     }
 #endif
@@ -551,7 +551,7 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class,
     }
 
 #ifdef CONFIG_QOM_CAST_DEBUG
-    if (ret == class) {
+    if (class && ret == class) {
         for (i = 1; i < OBJECT_CLASS_CAST_CACHE; i++) {
             class->cast_cache[i - 1] = class->cast_cache[i];
         }
Signature · 1 line
1.7.9.5
#26 lore raw

PATCH 26/56 seccomp: add the asynchronous I/O syscalls to the whitelist

In reply to Michael Roth

From: Paul Moore <[email protected]>

In order to enable the asynchronous I/O functionality when using the seccomp sandbox we need to add the associated syscalls to the whitelist.

Message-id: 20130529203001.20939.83322.stgit@localhost

(cherry picked from commit fd21faadb12669e24eaf0a277de61c24fcde4cac)
---
 qemu-seccomp.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
qemu-seccomp.c +4 -1
index 031da1d..ca123bf 100644
@@ -87,6 +87,7 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(stat), 245 },
     { SCMP_SYS(uname), 245 },
     { SCMP_SYS(eventfd2), 245 },
+    { SCMP_SYS(io_getevents), 245 },
     { SCMP_SYS(dup), 245 },
     { SCMP_SYS(dup2), 245 },
     { SCMP_SYS(dup3), 245 },
@@ -229,7 +230,9 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(sendmmsg), 241 },
     { SCMP_SYS(recvmmsg), 241 },
     { SCMP_SYS(prlimit64), 241 },
-    { SCMP_SYS(waitid), 241 }
+    { SCMP_SYS(waitid), 241 },
+    { SCMP_SYS(io_setup), 241 },
+    { SCMP_SYS(io_destroy), 241 }
 };
 
 int seccomp_start(void)
Signature · 1 line
1.7.9.5
#27 lore raw

PATCH 27/56 qapi: qapi-commands: fix possible leaks on visitor dealloc

In reply to Michael Roth

From: Luiz Capitulino <[email protected]>

In qmp-marshal.c the dealloc visitor calls use the same errp pointer of the input visitor calls. This means that if any of the input visitor calls fails, then the dealloc visitor will return early, before freeing the object's memory.

Here's an example, consider this code:

int qmp_marshal_input_block_passwd(Monitor *mon, const QDict *qdict, QObject **ret)

{
	[...]

    char * device = NULL;
    char * password = NULL;

    mi = qmp_input_visitor_new_strict(QOBJECT(args));
    v = qmp_input_get_visitor(mi);
    visit_type_str(v, &device, "device", errp);
    visit_type_str(v, &password, "password", errp);
    qmp_input_visitor_cleanup(mi);

    if (error_is_set(errp)) {
        goto out;
    }
    qmp_block_passwd(device, password, errp);

out:

    md = qapi_dealloc_visitor_new();
    v = qapi_dealloc_get_visitor(md);
    visit_type_str(v, &device, "device", errp);
    visit_type_str(v, &password, "password", errp);
    qapi_dealloc_visitor_cleanup(md);

	[...]

    return 0;
}

Consider errp != NULL when the out label is reached, we're going to leak device and password.

This patch fixes this by always passing errp=NULL for dealloc visitors, meaning that we always try to free them regardless of any previous failure. The above example would then be:

out:

    md = qapi_dealloc_visitor_new();
    v = qapi_dealloc_get_visitor(md);
    visit_type_str(v, &device, "device", NULL);
    visit_type_str(v, &password, "password", NULL);
    qapi_dealloc_visitor_cleanup(md);
(cherry picked from commit 8f91ad8a1b4702966d91ea58cd90bbde1faea1b3)
---
 scripts/qapi-commands.py |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
scripts/qapi-commands.py +10 -7
index e06332b..b12b696 100644
@@ -128,12 +128,15 @@ bool has_%(argname)s = false;
 
 def gen_visitor_input_block(args, obj, dealloc=False):
     ret = ""
+    errparg = 'errp'
+
     if len(args) == 0:
         return ret
 
     push_indent()
 
     if dealloc:
+        errparg = 'NULL'
         ret += mcgen('''
 md = qapi_dealloc_visitor_new();
 v = qapi_dealloc_get_visitor(md);
@@ -148,22 +151,22 @@ v = qmp_input_get_visitor(mi);
     for argname, argtype, optional, structured in parse_args(args):
         if optional:
             ret += mcgen('''
-visit_start_optional(v, &has_%(c_name)s, "%(name)s", errp);
+visit_start_optional(v, &has_%(c_name)s, "%(name)s", %(errp)s);
 if (has_%(c_name)s) {
 ''',
-                         c_name=c_var(argname), name=argname)
+                         c_name=c_var(argname), name=argname, errp=errparg)
             push_indent()
         ret += mcgen('''
-%(visitor)s(v, &%(c_name)s, "%(name)s", errp);
+%(visitor)s(v, &%(c_name)s, "%(name)s", %(errp)s);
 ''',
                      c_name=c_var(argname), name=argname, argtype=argtype,
-                     visitor=type_visitor(argtype))
+                     visitor=type_visitor(argtype), errp=errparg)
         if optional:
             pop_indent()
             ret += mcgen('''
 }
-visit_end_optional(v, errp);
-''')
+visit_end_optional(v, %(errp)s);
+''', errp=errparg)
 
     if dealloc:
         ret += mcgen('''
@@ -194,7 +197,7 @@ static void qmp_marshal_output_%(c_name)s(%(c_ret_type)s ret_in, QObject **ret_o
     }
     qmp_output_visitor_cleanup(mo);
     v = qapi_dealloc_get_visitor(md);
-    %(visitor)s(v, &ret_in, "unused", errp);
+    %(visitor)s(v, &ret_in, "unused", NULL);
     qapi_dealloc_visitor_cleanup(md);
 }
 ''',
Signature · 1 line
1.7.9.5
#29 lore raw

PATCH 29/56 iscsi: fix -ENOSPC in iscsi_create()

In reply to Michael Roth

From: Peter Lieven <[email protected]>

the -ENOPSC case did not work due to the missing goto.

(cherry picked from commit d3bda7bc166f40326ba646ee145630bb1b59da96)
---
 block/iscsi.c |    1 +
 1 file changed, 1 insertion(+)
block/iscsi.c +1 -0
index fa5252c..91b602c 100644
@@ -1272,6 +1272,7 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options)
     }
     if (bs.total_sectors < total_size) {
         ret = -ENOSPC;
+        goto out;
     }
 
     ret = 0;
Signature · 1 line
1.7.9.5
#28 lore raw

PATCH 28/56 ahci: Fix FLUSH command

In reply to Michael Roth

From: Kevin Wolf <[email protected]>

AHCI couldn't cope with asynchronous commands that aren't doing DMA, it simply wouldn't complete them. Due to the bug fixed in commit f68ec837, FLUSH commands would seem to have completed immediately even if they were still running on the host. After the commit, they would simply hang and never unset the BSY bit, rendering AHCI unusable on any OS sending flushes.

This patch adds another callback for the completion of asynchronous commands. This is what AHCI really wants to use for its command completion logic rather than an DMA completion callback.

(cherry picked from commit a62eaa26c1d6d48fbdc3ac1d32bd1314f5fdc8c9)
---
 hw/ide/ahci.c     |    8 +++++++-
 hw/ide/core.c     |    9 +++++++++
 hw/ide/internal.h |    1 +
 3 files changed, 17 insertions(+), 1 deletion(-)
hw/ide/ahci.c +7 -1
index eab6096..ade9f64 100644
@@ -1104,9 +1104,14 @@ static int ahci_dma_add_status(IDEDMA *dma, int status)
 
 static int ahci_dma_set_inactive(IDEDMA *dma)
 {
+    return 0;
+}
+
+static int ahci_async_cmd_done(IDEDMA *dma)
+{
     AHCIDevice *ad = DO_UPCAST(AHCIDevice, dma, dma);
 
-    DPRINTF(ad->port_no, "dma done\n");
+    DPRINTF(ad->port_no, "async cmd done\n");
 
     /* update d2h status */
     ahci_write_fis_d2h(ad, NULL);
@@ -1141,6 +1146,7 @@ static const IDEDMAOps ahci_dma_ops = {
     .set_unit = ahci_dma_set_unit,
     .add_status = ahci_dma_add_status,
     .set_inactive = ahci_dma_set_inactive,
+    .async_cmd_done = ahci_async_cmd_done,
     .restart_cb = ahci_dma_restart_cb,
     .reset = ahci_dma_reset,
 };
hw/ide/core.c +9 -0
index 9926d92..8b3dde6 100644
@@ -568,10 +568,18 @@ static void dma_buf_commit(IDEState *s)
     qemu_sglist_destroy(&s->sg);
 }
 
+static void ide_async_cmd_done(IDEState *s)
+{
+    if (s->bus->dma->ops->async_cmd_done) {
+        s->bus->dma->ops->async_cmd_done(s->bus->dma);
+    }
+}
+
 void ide_set_inactive(IDEState *s)
 {
     s->bus->dma->aiocb = NULL;
     s->bus->dma->ops->set_inactive(s->bus->dma);
+    ide_async_cmd_done(s);
 }
 
 void ide_dma_error(IDEState *s)
@@ -804,6 +812,7 @@ static void ide_flush_cb(void *opaque, int ret)
 
     bdrv_acct_done(s->bs, &s->acct);
     s->status = READY_STAT | SEEK_STAT;
+    ide_async_cmd_done(s);
     ide_set_irq(s->bus);
 }
 
hw/ide/internal.h +1 -0
index 03f1489..048a052 100644
@@ -433,6 +433,7 @@ struct IDEDMAOps {
     DMAIntFunc *set_unit;
     DMAIntFunc *add_status;
     DMAFunc *set_inactive;
+    DMAFunc *async_cmd_done;
     DMARestartFunc *restart_cb;
     DMAFunc *reset;
 };
Signature · 1 line
1.7.9.5
#30 lore raw

PATCH 30/56 iscsi: remove support for misaligned nb_sectors in aio_readv

In reply to Michael Roth

From: Peter Lieven <[email protected]>

this hask is not working (anymore). support for misaligned offsets should be handled at the block layer.

(cherry picked from commit 7e4d5a9f94a0d8485bf63e1f8256e0a0014495ab)
---
 block/iscsi.c |   22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)
block/iscsi.c +4 -18
index 91b602c..df283ed 100644
@@ -62,8 +62,6 @@ typedef struct IscsiAIOCB {
     int status;
     int canceled;
     int retries;
-    size_t read_size;
-    size_t read_offset;
     int64_t sector_num;
     int nb_sectors;
 #ifdef __linux__
@@ -380,6 +378,7 @@ static int
 iscsi_aio_readv_acb(IscsiAIOCB *acb)
 {
     struct iscsi_context *iscsi = acb->iscsilun->iscsi;
+    size_t size;
     uint64_t lba;
     uint32_t num_sectors;
     int ret;
@@ -392,20 +391,7 @@ iscsi_aio_readv_acb(IscsiAIOCB *acb)
     acb->status      = -EINPROGRESS;
     acb->buf         = NULL;
 
-    /* If LUN blocksize is bigger than BDRV_BLOCK_SIZE a read from QEMU
-     * may be misaligned to the LUN, so we may need to read some extra
-     * data.
-     */
-    acb->read_offset = 0;
-    if (acb->iscsilun->block_size > BDRV_SECTOR_SIZE) {
-        uint64_t bdrv_offset = BDRV_SECTOR_SIZE * acb->sector_num;
-
-        acb->read_offset  = bdrv_offset % acb->iscsilun->block_size;
-    }
-
-    num_sectors  = (acb->read_size + acb->iscsilun->block_size
-                    + acb->read_offset - 1)
-                    / acb->iscsilun->block_size;
+    size = acb->nb_sectors * BDRV_SECTOR_SIZE;
 
     acb->task = malloc(sizeof(struct scsi_task));
     if (acb->task == NULL) {
@@ -416,8 +402,9 @@ iscsi_aio_readv_acb(IscsiAIOCB *acb)
     memset(acb->task, 0, sizeof(struct scsi_task));
 
     acb->task->xfer_dir = SCSI_XFER_READ;
+    acb->task->expxferlen = size;
     lba = sector_qemu2lun(acb->sector_num, acb->iscsilun);
-    acb->task->expxferlen = acb->read_size;
+    num_sectors = sector_qemu2lun(acb->nb_sectors, acb->iscsilun);
 
     switch (acb->iscsilun->type) {
     case TYPE_DISK:
@@ -472,7 +459,6 @@ iscsi_aio_readv(BlockDriverState *bs, int64_t sector_num,
     acb->sector_num  = sector_num;
     acb->iscsilun    = iscsilun;
     acb->qiov        = qiov;
-    acb->read_size   = BDRV_SECTOR_SIZE * (size_t)acb->nb_sectors;
     acb->retries     = ISCSI_CMD_RETRIES;
 
     if (iscsi_aio_readv_acb(acb) != 0) {
Signature · 1 line
1.7.9.5
#31 lore raw

PATCH 31/56 iscsi: assert that sectors are aligned to LUN blocksize

In reply to Michael Roth

From: Peter Lieven <[email protected]>

if the blocksize of an iSCSI LUN is bigger than the BDRV_SECTOR_SIZE it is possible that sector_num or nb_sectors are not correctly aligned.

to avoid corruption we fail requests which are misaligned.

(cherry picked from commit 91bea4e2bb1a5f7954a3b3a4f2e28e96bd25c458)
---
 block/iscsi.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
block/iscsi.c +20 -0
index df283ed..1294fdf 100644
@@ -237,6 +237,18 @@ static int64_t sector_qemu2lun(int64_t sector, IscsiLun *iscsilun)
     return sector * BDRV_SECTOR_SIZE / iscsilun->block_size;
 }
 
+static bool is_request_lun_aligned(int64_t sector_num, int nb_sectors,
+                                      IscsiLun *iscsilun)
+{
+    if ((sector_num * BDRV_SECTOR_SIZE) % iscsilun->block_size ||
+        (nb_sectors * BDRV_SECTOR_SIZE) % iscsilun->block_size) {
+            error_report("iSCSI misaligned request: iscsilun->block_size %u, sector_num %ld, nb_sectors %d",
+                         iscsilun->block_size, sector_num, nb_sectors);
+            return 0;
+    }
+    return 1;
+}
+
 static int
 iscsi_aio_writev_acb(IscsiAIOCB *acb)
 {
@@ -321,6 +333,10 @@ iscsi_aio_writev(BlockDriverState *bs, int64_t sector_num,
     IscsiLun *iscsilun = bs->opaque;
     IscsiAIOCB *acb;
 
+    if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
+        return NULL;
+    }
+
     acb = qemu_aio_get(&iscsi_aiocb_info, bs, cb, opaque);
     trace_iscsi_aio_writev(iscsilun->iscsi, sector_num, nb_sectors, opaque, acb);
 
@@ -452,6 +468,10 @@ iscsi_aio_readv(BlockDriverState *bs, int64_t sector_num,
     IscsiLun *iscsilun = bs->opaque;
     IscsiAIOCB *acb;
 
+    if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
+        return NULL;
+    }
+
     acb = qemu_aio_get(&iscsi_aiocb_info, bs, cb, opaque);
     trace_iscsi_aio_readv(iscsilun->iscsi, sector_num, nb_sectors, opaque, acb);
 
Signature · 1 line
1.7.9.5
#35 lore raw

PATCH 35/56 megasas: Legacy command line handling fix

In reply to Michael Roth

From: Andreas Färber <[email protected]>

Only apply legacy command line handling when the device has not been hot-plugged. Propagate failure of legacy command line handling.

(cherry picked from commit 22d6aa03fd87ba5f219d26bc1810646d0f95842a)

Conflicts:

hw/scsi/megasas.c

* modified to avoid dependency on fancy new upcast macros

---
 hw/scsi/megasas.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/scsi/megasas.c +4 -1
index 4934a81..27288b9 100644
@@ -2088,6 +2088,7 @@ static const struct SCSIBusInfo megasas_scsi_info = {
 
 static int megasas_scsi_init(PCIDevice *dev)
 {
+    DeviceState *d = DEVICE(dev);
     MegasasState *s = DO_UPCAST(MegasasState, dev, dev);
     uint8_t *pci_conf;
     int i, bar_type;
@@ -2160,7 +2161,9 @@ static int megasas_scsi_init(PCIDevice *dev)
     }
 
     scsi_bus_new(&s->bus, &dev->qdev, &megasas_scsi_info, NULL);
-    scsi_bus_legacy_handle_cmdline(&s->bus);
+    if (!d->hotplugged) {
+        return scsi_bus_legacy_handle_cmdline(&s->bus);
+    }
     return 0;
 }
 
Signature · 1 line
1.7.9.5
#36 lore raw

PATCH 36/56 gtk: don't use g_object_unref on GdkCursor

In reply to Michael Roth

From: Anthony Liguori <[email protected]>

It's not a GObject.

---
v1 -> v2
- Fix summary to agree with code (Peter)
(cherry picked from commit 171392406d8e230d62e5ebf4805f71460854b8ec)

---
 ui/gtk.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ui/gtk.c +1 -1
index a788cc0..41942cb 100644
@@ -377,7 +377,7 @@ static void gd_cursor_define(DisplayChangeListener *dcl,
                                         pixbuf, c->hot_x, c->hot_y);
     gdk_window_set_cursor(gtk_widget_get_window(s->drawing_area), cursor);
     g_object_unref(pixbuf);
-    g_object_unref(cursor);
+    gdk_cursor_unref(cursor);
 }
 
 static void gd_switch(DisplayChangeListener *dcl,
Signature · 1 line
1.7.9.5
#32 lore raw

PATCH 32/56 block: Add return value for bdrv_flush_all()

In reply to Michael Roth

From: Kevin Wolf <[email protected]>

bdrv_flush() can fail, and bdrv_flush_all() should return an error as well if this happens for a block device. It returns the first error return now, but still at least tries to flush the remaining devices even in error cases.

(cherry picked from commit f0f0fdfeec6c67ad374114ecc4b3e3ccde5e94d2)
---
 block.c               |   10 ++++++++--
 include/block/block.h |    2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)
block.c +8 -2
index c7c3e06..d338a20 100644
@@ -2907,13 +2907,19 @@ int bdrv_get_flags(BlockDriverState *bs)
     return bs->open_flags;
 }
 
-void bdrv_flush_all(void)
+int bdrv_flush_all(void)
 {
     BlockDriverState *bs;
+    int result = 0;
 
     QTAILQ_FOREACH(bs, &bdrv_states, list) {
-        bdrv_flush(bs);
+        int ret = bdrv_flush(bs);
+        if (ret < 0 && !result) {
+            result = ret;
+        }
     }
+
+    return result;
 }
 
 int bdrv_has_zero_init(BlockDriverState *bs)
include/block/block.h +1 -1
index 1251c5c..4bc51d5 100644
@@ -276,7 +276,7 @@ void bdrv_clear_incoming_migration_all(void);
 /* Ensure contents are flushed to disk.  */
 int bdrv_flush(BlockDriverState *bs);
 int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
-void bdrv_flush_all(void);
+int bdrv_flush_all(void);
 void bdrv_close_all(void);
 void bdrv_drain_all(void);
 
Signature · 1 line
1.7.9.5
#33 lore raw

PATCH 33/56 cpus: Add return value for vm_stop()

In reply to Michael Roth

From: Kevin Wolf <[email protected]>

If flushing the block devices fails, return an error. The VM is stopped anyway.

(cherry picked from commit 5698346391b306c2c84358c68ee897c095d714cc)
---
 cpus.c                  |   20 +++++++++++++-------
 include/sysemu/sysemu.h |    4 ++--
 stubs/vm-stop.c         |    2 +-
 3 files changed, 16 insertions(+), 10 deletions(-)
cpus.c +13 -7
index c232265..2a2f633 100644
@@ -437,17 +437,21 @@ bool cpu_is_stopped(CPUState *cpu)
     return !runstate_is_running() || cpu->stopped;
 }
 
-static void do_vm_stop(RunState state)
+static int do_vm_stop(RunState state)
 {
+    int ret = 0;
+
     if (runstate_is_running()) {
         cpu_disable_ticks();
         pause_all_vcpus();
         runstate_set(state);
         vm_state_notify(0, state);
         bdrv_drain_all();
-        bdrv_flush_all();
+        ret = bdrv_flush_all();
         monitor_protocol_event(QEVENT_STOP, NULL);
     }
+
+    return ret;
 }
 
 static bool cpu_can_run(CPUState *cpu)
@@ -1093,7 +1097,7 @@ void cpu_stop_current(void)
     }
 }
 
-void vm_stop(RunState state)
+int vm_stop(RunState state)
 {
     if (qemu_in_vcpu_thread()) {
         qemu_system_vmstop_request(state);
@@ -1102,19 +1106,21 @@ void vm_stop(RunState state)
          * vm_stop() has been requested.
          */
         cpu_stop_current();
-        return;
+        return 0;
     }
-    do_vm_stop(state);
+
+    return do_vm_stop(state);
 }
 
 /* does a state transition even if the VM is already stopped,
    current state is forgotten forever */
-void vm_stop_force_state(RunState state)
+int vm_stop_force_state(RunState state)
 {
     if (runstate_is_running()) {
-        vm_stop(state);
+        return vm_stop(state);
     } else {
         runstate_set(state);
+        return 0;
     }
 }
 
include/sysemu/sysemu.h +2 -2
index 2fb71af..b5e1add 100644
@@ -35,8 +35,8 @@ void vm_state_notify(int running, RunState state);
 #define VMRESET_REPORT   true
 
 void vm_start(void);
-void vm_stop(RunState state);
-void vm_stop_force_state(RunState state);
+int vm_stop(RunState state);
+int vm_stop_force_state(RunState state);
 
 typedef enum WakeupReason {
     QEMU_WAKEUP_REASON_OTHER = 0,
stubs/vm-stop.c +1 -1
index 4568935..f82c897 100644
@@ -1,7 +1,7 @@
 #include "qemu-common.h"
 #include "sysemu/sysemu.h"
 
-void vm_stop(RunState state)
+int vm_stop(RunState state)
 {
     abort();
 }
Signature · 1 line
1.7.9.5
#37 lore raw

PATCH 37/56 gtk: Fix compiler warning (GTK 3 deprecated function)

In reply to Michael Roth

From: Stefan Weil <[email protected]>

With GTK 3, the function gdk_cursor_unref is deprecated:

qemu/ui/gtk.c: In function ‘gd_cursor_define’:
qemu/ui/gtk.c:380:5: error:
‘gdk_cursor_unref’ is deprecated (declared at /usr/include/gtk-3.0/gdk/gdkcursor.h:233): Use 'g_object_unref' instead [-Werror=deprecated-declarations]

Fix the gcc compiler warning by using conditional compilation.

Message-id: [email protected]

(cherry picked from commit 030b4b7debf659dcd6fc66826564285fdce5057d)
---
 ui/gtk.c |    4 ++++
 1 file changed, 4 insertions(+)
ui/gtk.c +4 -0
index 41942cb..abd0c4c 100644
@@ -377,7 +377,11 @@ static void gd_cursor_define(DisplayChangeListener *dcl,
                                         pixbuf, c->hot_x, c->hot_y);
     gdk_window_set_cursor(gtk_widget_get_window(s->drawing_area), cursor);
     g_object_unref(pixbuf);
+#if !GTK_CHECK_VERSION(3, 0, 0)
     gdk_cursor_unref(cursor);
+#else
+    g_object_unref(cursor);
+#endif
 }
 
 static void gd_switch(DisplayChangeListener *dcl,
Signature · 1 line
1.7.9.5
#38 lore raw

PATCH 38/56 dataplane: refuse to start if device is already in use

In reply to Michael Roth

From: Stefan Hajnoczi <[email protected]>

Dataplane must check whether a block device is in use before launching the dataplane thread. This is necessary since the thread does not synchronize with the main loop and I/O requests could cause corruption.

One example is when a drive is added and a block job is started before hotplugging the virtio-blk-pci adapter. In this case we must not use dataplane mode.

(cherry picked from commit b0f2027cde31c645524256763672e09eeb204a9a)
---
 hw/block/dataplane/virtio-blk.c |    8 ++++++++
 1 file changed, 8 insertions(+)
hw/block/dataplane/virtio-blk.c +8 -0
index 0356665..a58cc53 100644
@@ -418,6 +418,14 @@ bool virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
         return false;
     }
 
+    /* If dataplane is (re-)enabled while the guest is running there could be
+     * block jobs that can conflict.
+     */
+    if (bdrv_in_use(blk->conf.bs)) {
+        error_report("cannot start dataplane thread while device is in use");
+        return false;
+    }
+
     fd = raw_get_aio_fd(blk->conf.bs);
     if (fd < 0) {
         error_report("drive is incompatible with x-data-plane, "
Signature · 1 line
1.7.9.5
#39 lore raw

PATCH 39/56 xhci: handle USB_RET_IOERROR

In reply to Michael Roth

From: Gerd Hoffmann <[email protected]>

https://bugzilla.redhat.com/show_bug.cgi?id=980377

(cherry picked from commit ed60ff024fdb0e7ca9c002af166e10683cf49805)
---
 hw/usb/hcd-xhci.c |    1 +
 1 file changed, 1 insertion(+)
hw/usb/hcd-xhci.c +1 -0
index 8813bdf..632ede8 100644
@@ -1707,6 +1707,7 @@ static int xhci_complete_packet(XHCITransfer *xfer)
     trace_usb_xhci_xfer_error(xfer, xfer->packet.status);
     switch (xfer->packet.status) {
     case USB_RET_NODEV:
+    case USB_RET_IOERROR:
         xfer->status = CC_USB_TRANSACTION_ERROR;
         xhci_xfer_report(xfer);
         xhci_stall_ep(xfer);
Signature · 1 line
1.7.9.5
#34 lore raw

PATCH 34/56 cpus: Let vm_stop[_force_state]() always flush block devices

In reply to Michael Roth

From: Kevin Wolf <[email protected]>

Even if the VM is already stopped, we cannot assume that all data has already been successfully flushed to disk. The flush during the previous vm_stop() could have failed.

Run bdrv_flush_all() unconditionally so that we get an error each time if the block device isn't really flushed.

(cherry picked from commit 594a45ce64dbef1829996403506a1154eb2fd1cc)
---
 cpus.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
cpus.c +6 -3
index 2a2f633..65b0b0e 100644
@@ -446,11 +446,12 @@ static int do_vm_stop(RunState state)
         pause_all_vcpus();
         runstate_set(state);
         vm_state_notify(0, state);
-        bdrv_drain_all();
-        ret = bdrv_flush_all();
         monitor_protocol_event(QEVENT_STOP, NULL);
     }
 
+    bdrv_drain_all();
+    ret = bdrv_flush_all();
+
     return ret;
 }
 
@@ -1120,7 +1121,9 @@ int vm_stop_force_state(RunState state)
         return vm_stop(state);
     } else {
         runstate_set(state);
-        return 0;
+        /* Make sure to return an error if the flush in a previous vm_stop()
+         * failed. */
+        return bdrv_flush_all();
     }
 }
 
Signature · 1 line
1.7.9.5
#40 lore raw

PATCH 40/56 qemu-char: Register ring buffer driver with correct name "ringbuf"

In reply to Michael Roth

From: Markus Armbruster <[email protected]>

The driver is new in 1.4, with the documented name "ringbuf". However, it's actual name is the completely undocumented "memory". Screwed up in commit 3949e59. Fix code to match documentation.

Keep the undocumented name working as an alias for compatibility.

Message-id: [email protected]

(cherry picked from commit c11ed9666d69abaf217c8800f299c519b487b7d3)

Conflicts:

qemu-char.c

* removed dependency on command-line specifiable mux (bb6fb7c0)

---
 qemu-char.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
qemu-char.c +4 -1
index b8ffcba..c6c4c6b 100644
@@ -3764,7 +3764,7 @@ static void register_types(void)
     register_char_driver_qapi("null", CHARDEV_BACKEND_KIND_NULL, NULL);
     register_char_driver("socket", qemu_chr_open_socket);
     register_char_driver("udp", qemu_chr_open_udp);
-    register_char_driver_qapi("memory", CHARDEV_BACKEND_KIND_MEMORY,
+    register_char_driver_qapi("ringbuf", CHARDEV_BACKEND_KIND_MEMORY,
                               qemu_chr_parse_ringbuf);
     register_char_driver_qapi("file", CHARDEV_BACKEND_KIND_FILE,
                               qemu_chr_parse_file_out);
@@ -3782,6 +3782,9 @@ static void register_types(void)
     register_char_driver_qapi("console", CHARDEV_BACKEND_KIND_CONSOLE, NULL);
     register_char_driver_qapi("pipe", CHARDEV_BACKEND_KIND_PIPE,
                               qemu_chr_parse_pipe);
+    /* Bug-compatibility: */
+    register_char_driver_qapi("memory", CHARDEV_BACKEND_KIND_MEMORY,
+                              qemu_chr_parse_ringbuf);
 }
 
 type_init(register_types);
Signature · 1 line
1.7.9.5
#42 lore raw

PATCH 42/56 virtio-console: Use exitfn for virtserialport, too

In reply to Michael Roth

From: Andreas Färber <[email protected]>

virtconsole and virtserialport are identical in every other aspect except for the distinguishing VirtIOSerialPortClass::is_console field.

Message-id: [email protected]

(cherry picked from commit 203439ce0a832e36b276f10892846bd91ee836eb)
---
 hw/char/virtio-console.c |    1 +
 1 file changed, 1 insertion(+)
hw/char/virtio-console.c +1 -0
index 6759e51..2e00ad2 100644
@@ -185,6 +185,7 @@ static void virtserialport_class_init(ObjectClass *klass, void *data)
     VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(klass);
 
     k->init = virtconsole_initfn;
+    k->exit = virtconsole_exitfn;
     k->have_data = flush_buf;
     k->set_guest_connected = set_guest_connected;
     dc->props = virtserialport_properties;
Signature · 1 line
1.7.9.5
#41 lore raw

PATCH 41/56 qapi: Rename ChardevBackend member "memory" to "ringbuf"

In reply to Michael Roth

From: Markus Armbruster <[email protected]>

Commit 1da48c6 called the new member "memory" after commit 3949e59 standardized "ringbuf". Rename for consistency.

However, member name "memory" is visible in QMP since 1.5. It's undocumented just like the driver name. Keep it working anyway.

Message-id: [email protected]

(cherry picked from commit 3a1da42eb35a67d0dbc899dd571ea386fa11c4dd)
---
 qapi-schema.json |    6 ++++--
 qemu-char.c      |   11 ++++++-----
 2 files changed, 10 insertions(+), 7 deletions(-)
qapi-schema.json +4 -2
index 9302e7d..1c8503a 100644
@@ -3288,9 +3288,9 @@
 ##
 # @ChardevRingbuf:
 #
-# Configuration info for memory chardevs
+# Configuration info for ring buffer chardevs.
 #
-# @size: #optional Ringbuffer size, must be power of two, default is 65536
+# @size: #optional ring buffer size, must be power of two, default is 65536
 #
 # Since: 1.5
 ##
@@ -3321,6 +3321,8 @@
                                        'spicevmc' : 'ChardevSpiceChannel',
                                        'spiceport' : 'ChardevSpicePort',
                                        'vc'     : 'ChardevVC',
+                                       'ringbuf': 'ChardevRingbuf',
+                                       # next one is just for compatibility
                                        'memory' : 'ChardevRingbuf' } }
 
 ##
qemu-char.c +6 -5
index c6c4c6b..c16aea1 100644
@@ -3115,12 +3115,12 @@ static void qemu_chr_parse_ringbuf(QemuOpts *opts, ChardevBackend *backend,
 {
     int val;
 
-    backend->memory = g_new0(ChardevRingbuf, 1);
+    backend->ringbuf = g_new0(ChardevRingbuf, 1);
 
     val = qemu_opt_get_number(opts, "size", 0);
     if (val != 0) {
-        backend->memory->has_size = true;
-        backend->memory->size = val;
+        backend->ringbuf->has_size = true;
+        backend->ringbuf->size = val;
     }
 }
 
@@ -3713,8 +3713,9 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
     case CHARDEV_BACKEND_KIND_VC:
         chr = vc_init(backend->vc);
         break;
+    case CHARDEV_BACKEND_KIND_RINGBUF:
     case CHARDEV_BACKEND_KIND_MEMORY:
-        chr = qemu_chr_open_ringbuf(backend->memory, errp);
+        chr = qemu_chr_open_ringbuf(backend->ringbuf, errp);
         break;
     default:
         error_setg(errp, "unknown chardev backend (%d)", backend->kind);
@@ -3764,7 +3765,7 @@ static void register_types(void)
     register_char_driver_qapi("null", CHARDEV_BACKEND_KIND_NULL, NULL);
     register_char_driver("socket", qemu_chr_open_socket);
     register_char_driver("udp", qemu_chr_open_udp);
-    register_char_driver_qapi("ringbuf", CHARDEV_BACKEND_KIND_MEMORY,
+    register_char_driver_qapi("ringbuf", CHARDEV_BACKEND_KIND_RINGBUF,
                               qemu_chr_parse_ringbuf);
     register_char_driver_qapi("file", CHARDEV_BACKEND_KIND_FILE,
                               qemu_chr_parse_file_out);
Signature · 1 line
1.7.9.5
#43 lore raw

PATCH 43/56 pci-bridge: update mappings for migration/restore

In reply to Michael Roth

From: Don Koch <[email protected]>

Fix for LP#1187529: Devices on PCI bridge stop working when live-migrated. Update bridge mappings for all PCI bridge devices in get_pci_config_device().

(cherry picked from commit e78e9ae4a933504d383703870d491615b0261801)
---
 hw/pci/pci.c                |    5 +++++
 hw/pci/pci_bridge.c         |    2 +-
 include/hw/pci/pci_bridge.h |    1 +
 3 files changed, 7 insertions(+), 1 deletion(-)
hw/pci/pci.c +5 -0
index d5257ed..26995d7 100644
@@ -373,6 +373,7 @@ int pci_bus_num(PCIBus *s)
 static int get_pci_config_device(QEMUFile *f, void *pv, size_t size)
 {
     PCIDevice *s = container_of(pv, PCIDevice, config);
+    PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(s);
     uint8_t *config;
     int i;
 
@@ -390,6 +391,10 @@ static int get_pci_config_device(QEMUFile *f, void *pv, size_t size)
     memcpy(s->config, config, size);
 
     pci_update_mappings(s);
+    if (pc->is_bridge) {
+        PCIBridge *b = container_of(s, PCIBridge, dev);
+        pci_bridge_update_mappings(b);
+    }
 
     memory_region_set_enabled(&s->bus_master_enable_region,
                               pci_get_word(s->config + PCI_COMMAND)
hw/pci/pci_bridge.c +1 -1
index 24be6c5..3897bd8 100644
@@ -224,7 +224,7 @@ static void pci_bridge_region_cleanup(PCIBridge *br, PCIBridgeWindows *w)
     g_free(w);
 }
 
-static void pci_bridge_update_mappings(PCIBridge *br)
+void pci_bridge_update_mappings(PCIBridge *br)
 {
     PCIBridgeWindows *w = br->windows;
 
include/hw/pci/pci_bridge.h +1 -0
index 1868f7a..1d8f997 100644
@@ -37,6 +37,7 @@ PCIBus *pci_bridge_get_sec_bus(PCIBridge *br);
 pcibus_t pci_bridge_get_base(const PCIDevice *bridge, uint8_t type);
 pcibus_t pci_bridge_get_limit(const PCIDevice *bridge, uint8_t type);
 
+void pci_bridge_update_mappings(PCIBridge *br);
 void pci_bridge_write_config(PCIDevice *d,
                              uint32_t address, uint32_t val, int len);
 void pci_bridge_disable_base_limit(PCIDevice *dev);
Signature · 1 line
1.7.9.5
#45 lore raw

PATCH 45/56 chardev: fix CHR_EVENT_OPENED events for mux chardevs

In reply to Michael Roth

As of bd5c51ee6c4f1c79cae5ad2516d711a27b4ea8ec, chardevs no longer use bottom-halves to issue CHR_EVENT_OPENED events. To maintain past semantics, we instead defer the CHR_EVENT_OPENED events toward the end of chardev initialization.

For muxes, this isn't good enough, since a range of FEs must be able to attach to the mux prior to any CHR_EVENT_OPENED being issued, else each FE will immediately print it's initial output (prompts, banners, etc.) just prior to us switching to the next FE as part of initialization.

The is new and confusing behavior for users, as they'll see output for things like the HMP monitor, even though their the current mux focus may be a guest serial port with potentially no output.

We fix this by further deferring CHR_EVENT_OPENED events for FEs associated with muxes until after machine init by flagging mux chardevs with 'explicit_be_open', which suppresses emission of CHR_EVENT_OPENED events until we explicitly set the mux as opened later.

Currently, we must defer till after machine init since we potentially associate FEs with muxes as part of realize (for instance, serial_isa_realizefn).

Message-id: [email protected]

(cherry picked from commit 7b7ab18d0b9769b5f39e663fa55caed461b1202e)
---
 include/sysemu/char.h |    1 +
 qemu-char.c           |   50 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
include/sysemu/char.h +1 -0
index 066c216..ac2aaaf 100644
@@ -77,6 +77,7 @@ struct CharDriverState {
     int explicit_fe_open;
     int explicit_be_open;
     int avail_connections;
+    int is_mux;
     QemuOpts *opts;
     QTAILQ_ENTRY(CharDriverState) next;
 };
qemu-char.c +50 -0

68 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#44 lore raw

PATCH 44/56 xhci: fix segfault

In reply to Michael Roth

From: Gerd Hoffmann <[email protected]>

Guest trying to reset a endpoint of a disconnected device resulted in xhci trying to dereference uport while being NULL, thereby crashing qemu. Fix that by adding a check. Drop unused dev variable while touching that code bit.

(cherry picked from commit 75cc1c1fcba1987bdf3979c4289ab756c2b15742)
---
 hw/usb/hcd-xhci.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
hw/usb/hcd-xhci.c +2 -3
index 632ede8..d88c1ae 100644
@@ -1395,7 +1395,6 @@ static TRBCCode xhci_reset_ep(XHCIState *xhci, unsigned int slotid,
 {
     XHCISlot *slot;
     XHCIEPContext *epctx;
-    USBDevice *dev;
 
     trace_usb_xhci_ep_reset(slotid, epid);
     assert(slotid >= 1 && slotid <= xhci->numslots);
@@ -1431,8 +1430,8 @@ static TRBCCode xhci_reset_ep(XHCIState *xhci, unsigned int slotid,
         ep |= 0x80;
     }
 
-    dev = xhci->slots[slotid-1].uport->dev;
-    if (!dev) {
+    if (!xhci->slots[slotid-1].uport ||
+        !xhci->slots[slotid-1].uport->dev) {
         return CC_USB_TRANSACTION_ERROR;
     }
 
Signature · 1 line
1.7.9.5
#48 lore raw

PATCH 48/56 iov: handle EOF in iov_send_recv

In reply to Michael Roth

From: MORITA Kazutaka <[email protected]>

Without this patch, iov_send_recv() never returns when do_send_recv() returns zero.

(cherry picked from commit 840042901710c2dc1a3ac3e5af9bed449c339701)
---
 util/iov.c |    6 ++++++
 1 file changed, 6 insertions(+)
util/iov.c +6 -0
index cc6e837..f705586 100644
@@ -202,6 +202,12 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,
             return -1;
         }
 
+        if (ret == 0 && !do_send) {
+            /* recv returns 0 when the peer has performed an orderly
+             * shutdown. */
+            break;
+        }
+
         /* Prepare for the next iteration */
         offset += ret;
         total += ret;
Signature · 1 line
1.7.9.5
#49 lore raw

PATCH 49/56 target-i386: Fix X86CPU error handling

In reply to Michael Roth

From: Andreas Färber <[email protected]>

Error **errp argument is not for emitting warnings, it means an error has occurred and the caller should not make any assumptions about the state of other return values (unless otherwise documented).

Therefore cpu_x86_create() must unref the new X86CPU itself, and pc_new_cpu() must check for an Error rather than NULL return value.

While at it, clean up a superfluous NULL check.

Cc Igor Mammedov <[email protected]>
(cherry picked from commit cd7b87ffe9b6b7b0089ec8c71555f3b942bc6daf)
---
 hw/i386/pc.c      |   13 ++++++-------
 target-i386/cpu.c |    6 +++++-
 2 files changed, 11 insertions(+), 8 deletions(-)
hw/i386/pc.c +6 -7
index e2c44f8..a7ecfb0 100644
@@ -902,20 +902,19 @@ static X86CPU *pc_new_cpu(const char *cpu_model, int64_t apic_id,
     X86CPU *cpu;
     Error *local_err = NULL;
 
-    cpu = cpu_x86_create(cpu_model, icc_bridge, errp);
-    if (!cpu) {
-        return cpu;
+    cpu = cpu_x86_create(cpu_model, icc_bridge, &local_err);
+    if (local_err != NULL) {
+        error_propagate(errp, local_err);
+        return NULL;
     }
 
     object_property_set_int(OBJECT(cpu), apic_id, "apic-id", &local_err);
     object_property_set_bool(OBJECT(cpu), true, "realized", &local_err);
 
     if (local_err) {
-        if (cpu != NULL) {
-            object_unref(OBJECT(cpu));
-            cpu = NULL;
-        }
         error_propagate(errp, local_err);
+        object_unref(OBJECT(cpu));
+        cpu = NULL;
     }
     return cpu;
 }
target-i386/cpu.c +5 -1
index ae8e682..cdae1ce 100644
@@ -1820,7 +1820,11 @@ X86CPU *cpu_x86_create(const char *cpu_model, DeviceState *icc_bridge,
     }
 
 out:
-    error_propagate(errp, error);
+    if (error != NULL) {
+        error_propagate(errp, error);
+        object_unref(OBJECT(cpu));
+        cpu = NULL;
+    }
     g_strfreev(model_pieces);
     return cpu;
 }
Signature · 1 line
1.7.9.5
#46 lore raw

PATCH 46/56 seccomp: add arch_prctl() to the syscall whitelist

In reply to Michael Roth

From: Paul Moore <[email protected]>

It appears that even a very simple /etc/qemu-ifup configuration can require the arch_prctl() syscall, see the example below:

	#!/bin/sh
	/sbin/ifconfig $1 0.0.0.0 up
	/usr/sbin/brctl addif <switch> $1

Message-id: 20130718135703.8247.19213.stgit@localhost

(cherry picked from commit d2509b667caf482b6f827ff2645cbeb9b39ce29e)
---
 qemu-seccomp.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
qemu-seccomp.c +2 -1
index ca123bf..a7fb139 100644
@@ -232,7 +232,8 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(prlimit64), 241 },
     { SCMP_SYS(waitid), 241 },
     { SCMP_SYS(io_setup), 241 },
-    { SCMP_SYS(io_destroy), 241 }
+    { SCMP_SYS(io_destroy), 241 },
+    { SCMP_SYS(arch_prctl), 240 }
 };
 
 int seccomp_start(void)
Signature · 1 line
1.7.9.5
#47 lore raw

PATCH 47/56 seccomp: add additional asynchronous I/O syscalls

In reply to Michael Roth

From: Paul Moore <[email protected]>

A previous commit, "seccomp: add the asynchronous I/O syscalls to the whitelist", added several asynchronous I/O syscalls but left out the io_submit() and io_cancel() syscalls. This patch corrects this by adding the two missing asynchronous I/O syscalls.

Message-id: 20130715193201.943.4913.stgit@localhost

(cherry picked from commit 94113bd8a1d9acd05a879bc309cc659ace09e287)
---
 qemu-seccomp.c |    2 ++
 1 file changed, 2 insertions(+)
qemu-seccomp.c +2 -0
index a7fb139..9e91c73 100644
@@ -33,6 +33,7 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(socketcall), 250 },
 #endif
     { SCMP_SYS(read), 249 },
+    { SCMP_SYS(io_submit), 249 },
     { SCMP_SYS(brk), 248 },
     { SCMP_SYS(clone), 247 },
     { SCMP_SYS(mmap), 247 },
@@ -231,6 +232,7 @@ static const struct QemuSeccompSyscall seccomp_whitelist[] = {
     { SCMP_SYS(recvmmsg), 241 },
     { SCMP_SYS(prlimit64), 241 },
     { SCMP_SYS(waitid), 241 },
+    { SCMP_SYS(io_cancel), 241 },
     { SCMP_SYS(io_setup), 241 },
     { SCMP_SYS(io_destroy), 241 },
     { SCMP_SYS(arch_prctl), 240 }
Signature · 1 line
1.7.9.5
#50 lore raw

PATCH 50/56 ignore SIGPIPE in qemu-img and qemu-io

In reply to Michael Roth

From: MORITA Kazutaka <[email protected]>

This prevents the tools from being stopped when they write data to a closed connection in the other side.

(cherry picked from commit 526eda14a68d5b3596be715505289b541288ef2a)
---
 qemu-img.c |    4 ++++
 qemu-io.c  |    4 ++++
 2 files changed, 8 insertions(+)
qemu-img.c +4 -0
index cd096a1..2189fc9 100644
@@ -2460,6 +2460,10 @@ int main(int argc, char **argv)
     const img_cmd_t *cmd;
     const char *cmdname;
 
+#ifdef CONFIG_POSIX
+    signal(SIGPIPE, SIG_IGN);
+#endif
+
     error_set_progname(argv[0]);
 
     qemu_init_main_loop();
qemu-io.c +4 -0
index 475a8bd..5045ff8 100644
@@ -1920,6 +1920,10 @@ int main(int argc, char **argv)
     int opt_index = 0;
     int flags = BDRV_O_UNMAP;
 
+#ifdef CONFIG_POSIX
+    signal(SIGPIPE, SIG_IGN);
+#endif
+
     progname = basename(argv[0]);
 
     while ((c = getopt_long(argc, argv, sopt, lopt, &opt_index)) != -1) {
Signature · 1 line
1.7.9.5
#51 lore raw

PATCH 51/56 semaphore: fix a hangup problem under load on NetBSD hosts.

In reply to Michael Roth

From: Izumi Tsutsui <[email protected]>

Fix following bugs in "fallback implementation of counting semaphores with mutex+condvar" added in c166cb72f1676855816340666c3b618beef4b976:
- waiting threads are not restarted properly if more than one threads are waiting unblock signals in qemu_sem_timedwait()
- possible missing pthread_cond_signal(3) calls when waiting threads are returned by ETIMEDOUT
- fix an uninitialized variable
The problem is analyzed by and fix is provided by Noriyuki Soda.

Also put additional cleanup suggested by Laszlo Ersek:
- make QemuSemaphore.count unsigned (it won't be negative)
- check a return value of in pthread_cond_wait() in qemu_sem_wait()

Message-id: [email protected]

(cherry picked from commit 79761c6681f0d1cc1c027116fcb4382d41ed3ece)
---
 include/qemu/thread-posix.h |    2 +-
 util/qemu-thread-posix.c    |   28 ++++++++++++++++------------
 2 files changed, 17 insertions(+), 13 deletions(-)
include/qemu/thread-posix.h +1 -1
index 0f30dcc..361566a 100644
@@ -15,7 +15,7 @@ struct QemuSemaphore {
 #if defined(__APPLE__) || defined(__NetBSD__)
     pthread_mutex_t lock;
     pthread_cond_t cond;
-    int count;
+    unsigned int count;
 #else
     sem_t sem;
 #endif
util/qemu-thread-posix.c +16 -12
index 4489abf..4de133e 100644
@@ -170,12 +170,11 @@ void qemu_sem_post(QemuSemaphore *sem)
 
 #if defined(__APPLE__) || defined(__NetBSD__)
     pthread_mutex_lock(&sem->lock);
-    if (sem->count == INT_MAX) {
+    if (sem->count == UINT_MAX) {
         rc = EINVAL;
-    } else if (sem->count++ < 0) {
-        rc = pthread_cond_signal(&sem->cond);
     } else {
-        rc = 0;
+        sem->count++;
+        rc = pthread_cond_signal(&sem->cond);
     }
     pthread_mutex_unlock(&sem->lock);
     if (rc != 0) {
@@ -207,19 +206,21 @@ int qemu_sem_timedwait(QemuSemaphore *sem, int ms)
     struct timespec ts;
 
 #if defined(__APPLE__) || defined(__NetBSD__)
+    rc = 0;
     compute_abs_deadline(&ts, ms);
     pthread_mutex_lock(&sem->lock);
-    --sem->count;
-    while (sem->count < 0) {
+    while (sem->count == 0) {
         rc = pthread_cond_timedwait(&sem->cond, &sem->lock, &ts);
         if (rc == ETIMEDOUT) {
-            ++sem->count;
             break;
         }
         if (rc != 0) {
             error_exit(rc, __func__);
         }
     }
+    if (rc != ETIMEDOUT) {
+        --sem->count;
+    }
     pthread_mutex_unlock(&sem->lock);
     return (rc == ETIMEDOUT ? -1 : 0);
 #else
@@ -249,16 +250,19 @@ int qemu_sem_timedwait(QemuSemaphore *sem, int ms)
 
 void qemu_sem_wait(QemuSemaphore *sem)
 {
+    int rc;
+
 #if defined(__APPLE__) || defined(__NetBSD__)
     pthread_mutex_lock(&sem->lock);
-    --sem->count;
-    while (sem->count < 0) {
-        pthread_cond_wait(&sem->cond, &sem->lock);
+    while (sem->count == 0) {
+        rc = pthread_cond_wait(&sem->cond, &sem->lock);
+        if (rc != 0) {
+            error_exit(rc, __func__);
+        }
     }
+    --sem->count;
     pthread_mutex_unlock(&sem->lock);
 #else
-    int rc;
-
     do {
         rc = sem_wait(&sem->sem);
     } while (rc == -1 && errno == EINTR);
Signature · 1 line
1.7.9.5
#52 lore raw

PATCH 52/56 Bugfix for loading multiboot kernels

In reply to Michael Roth

From: Martijn van den Broek <[email protected]>

This patch fixes a bug in rom_copy introduced by
commit d60fa42e8bae39440f997ebfe8fe328269a57d16.

rom_copy failed to load roms with a "datasize" of 0. As a result, multiboot kernels were not loaded correctly when they contain a segment with a "file size" of 0.

https://bugs.launchpad.net/qemu/+bug/1208944

Message-id: CAG1x_oET1u3TMPu3r_zzd3ZXsTWQLiaM0zAc+RkHFCwvJjGOvg@mail.gmail.com

(cherry picked from commit 0dd5ce38fbeb2fb97b01cc8c1c97292211e48ee6)
---
 hw/core/loader.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
hw/core/loader.c +3 -4
index 7507914..8514eaf 100644
@@ -779,9 +779,6 @@ int rom_copy(uint8_t *dest, hwaddr addr, size_t size)
         if (rom->addr > end) {
             break;
         }
-        if (!rom->data) {
-            continue;
-        }
 
         d = dest + (rom->addr - addr);
         s = rom->data;
@@ -791,7 +788,9 @@ int rom_copy(uint8_t *dest, hwaddr addr, size_t size)
             l = dest - d;
         }
 
-        memcpy(d, s, l);
+        if (l > 0) {
+            memcpy(d, s, l);
+        }
 
         if (rom->romsize > rom->datasize) {
             /* If datasize is less than romsize, it means that we didn't
Signature · 1 line
1.7.9.5
#53 lore raw

PATCH 53/56 i82801b11: Fix i82801b11 PCI host bridge config space

In reply to Michael Roth

From: Gerd Hoffmann <[email protected]>

pci_bridge_write_config() was not being used.

(cherry picked from commit 4965b7f056177ddfb816319e9ff5e766898d0bc5)

Conflicts:

	hw/pci-bridge/i82801b11.c

* modified to avoid dependency on 125ee0ed

---
 hw/pci-bridge/i82801b11.c |    1 +
 1 file changed, 1 insertion(+)
hw/pci-bridge/i82801b11.c +1 -0
index 5807a92..0841531 100644
@@ -87,6 +87,7 @@ static void i82801b11_bridge_class_init(ObjectClass *klass, void *data)
     k->device_id = PCI_DEVICE_ID_INTEL_82801BA_11;
     k->revision = ICH9_D2P_A2_REVISION;
     k->init = i82801b11_bridge_initfn;
+    k->config_write = pci_bridge_write_config;
 }
 
 static const TypeInfo i82801b11_bridge_info = {
Signature · 1 line
1.7.9.5
#56 lore raw

PATCH 56/56 vhost: clear signalled_used_valid on vhost stop

In reply to Michael Roth

From: "Michael S. Tsirkin" <[email protected]>

When vhost device stops, its implementation synchronizes kernel state back to virtio.c so we can continue emulating the device in userspace.

This patch ensures that virtio.c's signalled_used_valid flag is reset so that userspace does not suppress guest notifications due to stale signalled_used values.

(cherry picked from commit 3561ba14188b3c1e54246ed6db97896bbc082d2f)
---
 hw/virtio/vhost.c |    1 +
 1 file changed, 1 insertion(+)
hw/virtio/vhost.c +1 -0
index fbabf99..0dabf26 100644
@@ -761,6 +761,7 @@ static void vhost_virtqueue_stop(struct vhost_dev *dev,
         fflush(stderr);
     }
     virtio_queue_set_last_avail_idx(vdev, idx, state.num);
+    virtio_queue_invalidate_signalled_used(vdev, idx);
     assert (r >= 0);
     cpu_physical_memory_unmap(vq->ring, virtio_queue_get_ring_size(vdev, idx),
                               0, virtio_queue_get_ring_size(vdev, idx));
Signature · 1 line
1.7.9.5
#54 lore raw

PATCH 54/56 dataplane: sync virtio.c and vring.c virtqueue state

In reply to Michael Roth

From: Stefan Hajnoczi <[email protected]>

Load the virtio.c state into vring.c when we start dataplane mode and vice versa when stopping dataplane mode. This patch makes it possible to start and stop dataplane any time while the guest is running.

This will eventually allow us to go back to QEMU main loop for bdrv_drain_all() and live migration. In the meantime, this patch makes the dataplane lifecycle more robust but should make no visible difference. It may be useful in the virtio-net dataplane effort.

(cherry picked from commit 9154b02c53bb6685797c973fcdbec51c4714777d)
---
 hw/block/dataplane/virtio-blk.c     |    2 +-
 hw/virtio/dataplane/vring.c         |    8 +++++---
 include/hw/virtio/dataplane/vring.h |    2 +-
 3 files changed, 7 insertions(+), 5 deletions(-)
hw/block/dataplane/virtio-blk.c +1 -1
index a58cc53..fb70645 100644
@@ -545,7 +545,7 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)
     /* Clean up guest notifier (irq) */
     k->set_guest_notifiers(qbus->parent, 1, false);
 
-    vring_teardown(&s->vring);
+    vring_teardown(&s->vring, s->vdev, 0);
     s->started = false;
     s->stopping = false;
 }
hw/virtio/dataplane/vring.c +5 -3
index e0d6e83..82cc151 100644
@@ -39,8 +39,8 @@ bool vring_setup(Vring *vring, VirtIODevice *vdev, int n)
 
     vring_init(&vring->vr, virtio_queue_get_num(vdev, n), vring_ptr, 4096);
 
-    vring->last_avail_idx = 0;
-    vring->last_used_idx = 0;
+    vring->last_avail_idx = virtio_queue_get_last_avail_idx(vdev, n);
+    vring->last_used_idx = vring->vr.used->idx;
     vring->signalled_used = 0;
     vring->signalled_used_valid = false;
 
@@ -49,8 +49,10 @@ bool vring_setup(Vring *vring, VirtIODevice *vdev, int n)
     return true;
 }
 
-void vring_teardown(Vring *vring)
+void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)
 {
+    virtio_queue_set_last_avail_idx(vdev, n, vring->last_avail_idx);
+
     hostmem_finalize(&vring->hostmem);
 }
 
include/hw/virtio/dataplane/vring.h +1 -1
index 9380cb5..c0b69ff 100644
@@ -50,7 +50,7 @@ static inline void vring_set_broken(Vring *vring)
 }
 
 bool vring_setup(Vring *vring, VirtIODevice *vdev, int n);
-void vring_teardown(Vring *vring);
+void vring_teardown(Vring *vring, VirtIODevice *vdev, int n);
 void vring_disable_notification(VirtIODevice *vdev, Vring *vring);
 bool vring_enable_notification(VirtIODevice *vdev, Vring *vring);
 bool vring_should_notify(VirtIODevice *vdev, Vring *vring);
Signature · 1 line
1.7.9.5
#55 lore raw

PATCH 55/56 virtio: clear signalled_used_valid when switching from dataplane

In reply to Michael Roth

From: Stefan Hajnoczi <[email protected]>

When the dataplane thread stops, its vring.c implementation synchronizes vring state back to virtio.c so we can continue emulating the virtio device.

This patch ensures that virtio.c's signalled_used_valid flag is reset so that we do not suppress guest notifications due to stale signalled_used values.

(cherry picked from commit 6793dfd1b6a99a79b9f2e3c4d6625ccd6513f240)
---
 hw/virtio/dataplane/vring.c |    1 +
 hw/virtio/virtio.c          |    5 +++++
 include/hw/virtio/virtio.h  |    1 +
 3 files changed, 7 insertions(+)
hw/virtio/dataplane/vring.c +1 -0
index 82cc151..351a343 100644
@@ -52,6 +52,7 @@ bool vring_setup(Vring *vring, VirtIODevice *vdev, int n)
 void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)
 {
     virtio_queue_set_last_avail_idx(vdev, n, vring->last_avail_idx);
+    virtio_queue_invalidate_signalled_used(vdev, n);
 
     hostmem_finalize(&vring->hostmem);
 }
hw/virtio/virtio.c +5 -0
index 8176c14..a5251cb 100644
@@ -1025,6 +1025,11 @@ void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx)
     vdev->vq[n].last_avail_idx = idx;
 }
 
+void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n)
+{
+    vdev->vq[n].signalled_used_valid = false;
+}
+
 VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n)
 {
     return vdev->vq + n;
include/hw/virtio/virtio.h +1 -0
index a6c5c53..f2aa6a3 100644
@@ -233,6 +233,7 @@ hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n);
 hwaddr virtio_queue_get_ring_size(VirtIODevice *vdev, int n);
 uint16_t virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n);
 void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx);
+void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n);
 VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n);
 uint16_t virtio_get_queue_index(VirtQueue *vq);
 int virtio_queue_get_id(VirtQueue *vq);
Signature · 1 line
1.7.9.5
Reviewed-by Eric Blake
#57 lore raw
In reply to Michael Roth
Quoted 6 lines · Michael Roth

Hi everyone,

The following new patches are queued for QEMU stable v1.5.3:

https://github.com/mdroth/qemu/commits/stable-1.5-staging

Quoted 7 lines

The release is planned for 2013-08-21:

http://wiki.qemu.org/Planning/1.5

Please respond here or CC [email protected] on any patches you think should be included in the release. The cut-off date is 2013-08-16 for new patches.

Potentially:

commit 0f953051178f2e3df36efa5158a71f33d35fa812

Author: Markus Armbruster <[email protected]>
Date:   Thu Jun 27 16:22:07 2013 +0200

qemu-char: Fix ringbuf option size

Any attempt to use it trips an "opt->desc->type == QEMU_OPT_NUMBER" assertion. Broken in commit 1da48c65.

Signature · 1 line
Doug Goldstein
#58 lore raw

Quoting Doug Goldstein (2013-08-13 23:05:31)

Quoted 10 lines
Quoted 8 lines · Michael Roth

Hi everyone,

The following new patches are queued for QEMU stable v1.5.3:

https://github.com/mdroth/qemu/commits/stable-1.5-staging

The release is planned for 2013-08-21:

Quoted 7 lines
Quoted 5 lines

http://wiki.qemu.org/Planning/1.5

Please respond here or CC [email protected] on any patches you think should be included in the release. The cut-off date is 2013-08-16 for new patches.

Potentially:

Definitely :) Slipped by me, applied now.

Quoted 17 lines

commit 0f953051178f2e3df36efa5158a71f33d35fa812

Author: Markus Armbruster <[email protected]>
Date:   Thu Jun 27 16:22:07 2013 +0200

qemu-char: Fix ringbuf option size

Any attempt to use it trips an "opt->desc->type == QEMU_OPT_NUMBER" assertion. Broken in commit 1da48c65.

Signature · 1 line
Doug Goldstein