Re: [Qemu-devel] [QGA] Bug of qga?

2017-08-28 Thread Sam
I could repeat this several times, I think it's mis-order of qmp in qga
socket.

2017-08-25 11:09 GMT+08:00 Sam :

> Also I found:
>
> when I use `socat` to take a qga socket, then I use `socat` to communicate
> it will got error.
> But also SOMETIMES, I will not got error and will communicate OK.
>
> If one user take qga socket, another user should got error, is it? But why
> sometimes, the communicate is OK?
>
> 2017-08-25 10:11 GMT+08:00 Sam :
>
>> Hi all,
>>
>> I'm using qga to send `route -n` and `ping` command to guest. But I found
>> SOMETIMES, the second `ping` command's result is the same as `route -n`
>> command.
>>
>> So I guess is there some cache mechanism of qga command result? So when I
>> send the second command, and receive from qga socket, I receive the result
>> of first command.
>>
>> Or is this bug happened because of I use async mechanism of python code
>> to operate qga socket?
>>
>> This is the python code I use to operate on this qga socket:
>>
>> try:
>>> sock=socket(AF_UNIX, SOCK_STREAM)
>>> sock.settimeout(20)
>>> sock.connect(vm_qga_sockpath)
>>> sock.send(cmd)
>>> while True:
>>> res = sock.recv(1024)
>>> if len(res):
>>> break
>>> except Exception as e:
>>> res = -1
>>> finally:
>>> sock.settimeout(None)
>>> sock.close()
>>
>>
>


[Qemu-devel] [PATCH v4] vl: exit if maxcpus is negative

2017-08-28 Thread Seeteena Thoufeek
---Steps to Reproduce---

When passed a negative number to 'maxcpus' parameter, Qemu aborts
with a core dump.

Run the following command with maxcpus argument as negative number

ppc64-softmmu/qemu-system-ppc64 --nographic -vga none -machine
pseries,accel=kvm,kvm-type=HV -m size=200g -device virtio-blk-pci,
drive=rootdisk -drive file=/home/images/pegas-1.0-ppc64le.qcow2,
if=none,cache=none,id=rootdisk,format=qcow2 -monitor telnet
:127.0.0.1:1234,server,nowait -net nic,model=virtio -net
user -redir tcp:2000::22 -device nec-usb-xhci -smp 8,cores=1,
threads=1,maxcpus=-12

(process:12149): GLib-ERROR **: gmem.c:130: failed to allocate
 18446744073709550568 bytes

Trace/breakpoint trap

Reported-by: R.Nageswara Sastry 
Signed-off-by: Seeteena Thoufeek 
---
v1 -> v2:
  - Fix the error check in vl.c to make it generic.
v2 -> v3:
  - Fix coding style pointed out by patchew.
  - Fix check for "<= 0" instead of just "< 0".
v3 -> v4:
  - Fix subject line.
  - Removed space before ":" from vl.c:1248
  - Removed Reviewed-by: flag.
---
 vl.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/vl.c b/vl.c
index 8e247cc..2d9e73d 100644
--- a/vl.c
+++ b/vl.c
@@ -1244,7 +1244,10 @@ static void smp_parse(QemuOpts *opts)
 }
 
 max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
-
+if (max_cpus <= 0) {
+error_report("Invalid max_cpus: %d", max_cpus);
+exit(1);
+}
 if (max_cpus < cpus) {
 error_report("maxcpus must be equal to or greater than smp");
 exit(1);
-- 
1.8.3.1




Re: [Qemu-devel] [RFC v2 04/32] qemu_ram_block_host_offset

2017-08-28 Thread Peter Xu
On Thu, Aug 24, 2017 at 08:27:02PM +0100, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" 
> 
> Utility to give the offset of a host pointer within a RAMBlock
> (assuming we already know it's in that RAMBlock)
> 
> Signed-off-by: Dr. David Alan Gilbert 

Reviewed-by: Peter Xu 

-- 
Peter Xu



Re: [Qemu-devel] [Qemu devel v7 PATCH 1/5] msf2: Add Smartfusion2 System timer

2017-08-28 Thread sundeep subbaraya
Hi Alistair,

On Tue, Aug 29, 2017 at 3:23 AM, Alistair Francis 
wrote:

> On Mon, Aug 28, 2017 at 9:37 AM, Subbaraya Sundeep
>  wrote:
> > Modelled System Timer in Microsemi's Smartfusion2 Soc.
> > Timer has two 32bit down counters and two interrupts.
> >
> > Signed-off-by: Subbaraya Sundeep 
>
> I had already reviewed this patch in v6. As long as you have made all
> of the changes mentioned their you can add my reviewed-by to the next
> version (as long as there are no other significant changes).
>
> Can you please ensure you do add and keep reviewed-by tags, it's a
> pain to have to do it multiple times.
>

Sorry I was not aware that I can add reviewed by tag myself and send.
I will add your reviewed by since I fixed all your comments.
Do I need to send another version v8 with your Reviewed-by ?

Thanks,
Sundeep


>
> Thanks,
> Alistair
>
> > ---
> >  hw/timer/Makefile.objs   |   1 +
> >  hw/timer/mss-timer.c | 289 ++
> +
> >  include/hw/timer/mss-timer.h |  64 ++
> >  3 files changed, 354 insertions(+)
> >  create mode 100644 hw/timer/mss-timer.c
> >  create mode 100644 include/hw/timer/mss-timer.h
> >
> > diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs
> > index 15cce1c..8c19eac 100644
> > --- a/hw/timer/Makefile.objs
> > +++ b/hw/timer/Makefile.objs
> > @@ -42,3 +42,4 @@ common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o
> >
> >  common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o
> >  common-obj-$(CONFIG_CMSDK_APB_TIMER) += cmsdk-apb-timer.o
> > +common-obj-$(CONFIG_MSF2) += mss-timer.o
> > diff --git a/hw/timer/mss-timer.c b/hw/timer/mss-timer.c
> > new file mode 100644
> > index 000..60f1213
> > --- /dev/null
> > +++ b/hw/timer/mss-timer.c
> > @@ -0,0 +1,289 @@
> > +/*
> > + * Block model of System timer present in
> > + * Microsemi's SmartFusion2 and SmartFusion SoCs.
> > + *
> > + * Copyright (c) 2017 Subbaraya Sundeep .
> > + *
> > + * Permission is hereby granted, free of charge, to any person
> obtaining a copy
> > + * of this software and associated documentation files (the
> "Software"), to deal
> > + * in the Software without restriction, including without limitation
> the rights
> > + * to use, copy, modify, merge, publish, distribute, sublicense, and/or
> sell
> > + * copies of the Software, and to permit persons to whom the Software is
> > + * furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be
> included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
> SHALL
> > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
> OTHER
> > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> ARISING FROM,
> > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> DEALINGS IN
> > + * THE SOFTWARE.
> > + */
> > +
> > +#include "qemu/osdep.h"
> > +#include "qemu/main-loop.h"
> > +#include "qemu/log.h"
> > +#include "hw/timer/mss-timer.h"
> > +
> > +#ifndef MSS_TIMER_ERR_DEBUG
> > +#define MSS_TIMER_ERR_DEBUG  0
> > +#endif
> > +
> > +#define DB_PRINT_L(lvl, fmt, args...) do { \
> > +if (MSS_TIMER_ERR_DEBUG >= lvl) { \
> > +qemu_log("%s: " fmt "\n", __func__, ## args); \
> > +} \
> > +} while (0);
> > +
> > +#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
> > +
> > +#define R_TIM_VAL 0
> > +#define R_TIM_LOADVAL 1
> > +#define R_TIM_BGLOADVAL   2
> > +#define R_TIM_CTRL3
> > +#define R_TIM_RIS 4
> > +#define R_TIM_MIS 5
> > +
> > +#define TIMER_CTRL_ENBL (1 << 0)
> > +#define TIMER_CTRL_ONESHOT  (1 << 1)
> > +#define TIMER_CTRL_INTR (1 << 2)
> > +#define TIMER_RIS_ACK   (1 << 0)
> > +#define TIMER_RST_CLR   (1 << 6)
> > +#define TIMER_MODE  (1 << 0)
> > +
> > +static void timer_update_irq(struct Msf2Timer *st)
> > +{
> > +bool isr, ier;
> > +
> > +isr = !!(st->regs[R_TIM_RIS] & TIMER_RIS_ACK);
> > +ier = !!(st->regs[R_TIM_CTRL] & TIMER_CTRL_INTR);
> > +qemu_set_irq(st->irq, (ier && isr));
> > +}
> > +
> > +static void timer_update(struct Msf2Timer *st)
> > +{
> > +uint64_t count;
> > +
> > +if (!(st->regs[R_TIM_CTRL] & TIMER_CTRL_ENBL)) {
> > +ptimer_stop(st->ptimer);
> > +return;
> > +}
> > +
> > +count = st->regs[R_TIM_LOADVAL];
> > +ptimer_set_limit(st->ptimer, count, 1);
> > +ptimer_run(st->ptimer, 1);
> > +}
> > +
> > +static uint64_t
> > +timer_read(void *opaque, hwaddr offset, unsigned int size)
> > +{
> > +MSSTimerState *t = opaque;
> > +hwaddr addr;
> > +struct Msf2Timer *st;
> > +

Re: [Qemu-devel] [PATCH V4 0/3] Optimize COLO-compare performance

2017-08-28 Thread Zhang Chen

Hi~ Jason.

Have any comments for this series?

Thanks

Zhang Chen


On 08/21/2017 04:55 PM, Zhang Chen wrote:

In this serise, we do a lot of job to optimize COLO net performance.
Mainly focus on TCP protocol.

V4:
  - Remove the old patch1.

V3:
  - Rebase on upstream.
  - Remove origin p2.
  - Move the "checkpoint_time_ms" to CompareState,
in order to aviod multi colo-compare instance conflict.
  - Add "TODO comments" for reset s->checkpoint_time_ms.
  - Add a new patch fix comments and scheme.

V2:
  - Rename p2's subject.


Zhang Chen (3):
   net/colo-compare.c: Optimize unpredictable tcp options comparison
   net/colo-compare.c: Adjust net queue pop order for performance
   net/colo-compare.c: Fix comments and scheme

  net/colo-compare.c | 62 +++---
  1 file changed, 40 insertions(+), 22 deletions(-)



--
Thanks
Zhang Chen






Re: [Qemu-devel] [RFC v2 03/32] migrate: Update ram_block_discard_range for shared

2017-08-28 Thread Peter Xu
On Thu, Aug 24, 2017 at 08:27:01PM +0100, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" 
> 
> The choice of call to discard a block is getting more complicated
> for other cases.   We use fallocate PUNCH_HOLE in any file cases;
> it works for both hugepage and for tmpfs.
> We use the DONTNEED for non-hugepage cases either where they're
> anonymous or where they're private.
> 
> Care should be taken when trying other backing files.
> 
> Signed-off-by: Dr. David Alan Gilbert 
> ---
>  exec.c   | 35 ---
>  trace-events |  3 +++
>  2 files changed, 27 insertions(+), 11 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index d20c34ca83..67df2909ce 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -3573,6 +3573,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t 
> start, size_t length)
>  }
>  
>  if ((start + length) <= rb->used_length) {
> +bool need_madvise, need_fallocate;
>  uint8_t *host_endaddr = host_startaddr + length;
>  if ((uintptr_t)host_endaddr & (rb->page_size - 1)) {
>  error_report("ram_block_discard_range: Unaligned end address: 
> %p",
> @@ -3582,23 +3583,35 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t 
> start, size_t length)
>  
>  errno = ENOTSUP; /* If we are missing MADVISE etc */
>  
> -if (rb->page_size == qemu_host_page_size) {
> -#if defined(CONFIG_MADVISE)
> -/* Note: We need the madvise MADV_DONTNEED behaviour of 
> definitely
> - * freeing the page.
> - */
> -ret = madvise(host_startaddr, length, MADV_DONTNEED);
> -#endif
> -} else {
> -/* Huge page case  - unfortunately it can't do DONTNEED, but
> - * it can do the equivalent by FALLOC_FL_PUNCH_HOLE in the
> - * huge page file.
> +/* The logic here is messy;
> + *madvise DONTNEED fails for hugepages
> + *fallocate works on hugepages and shmem
> + */
> +need_madvise = (rb->page_size == qemu_host_page_size);
> +need_fallocate = rb->fd != -1;
> +if (need_fallocate) {
> +/* For a file, this causes the area of the file to be zero'd
> + * if read, and for hugetlbfs also causes it to be unmapped
> + * so a userfault will trigger.
>   */
>  #ifdef CONFIG_FALLOCATE_PUNCH_HOLE
>  ret = fallocate(rb->fd, FALLOC_FL_PUNCH_HOLE | 
> FALLOC_FL_KEEP_SIZE,
>  start, length);
>  #endif
>  }
> +/* i.e. need madvise but skip it if the fallocate failed */
> +if (need_madvise && (!need_fallocate || (ret == 0))) {

I'll slightly prefer:

  trace_ram_block_discard_range();

  if (need_fallocate) {
ret = fallocate();
if (ret) {
  error_report();
  goto err;
}
  }

  if (need_madvise) {
ret = madvise();
if (ret) {
  error_report();
  goto err;
}
  }

But it is personal preference.  For either way:

Reviewed-by: Peter Xu 

> +/* For normal RAM this causes it to be unmapped,
> + * for shared memory it causes the local mapping to disappear
> + * and to fall back on the file contents (which we just
> + * fallocate'd away).
> + */
> +#if defined(CONFIG_MADVISE)
> +ret =  madvise(host_startaddr, length, MADV_DONTNEED);
> +#endif
> +}
> +trace_ram_block_discard_range(rb->idstr, host_startaddr,
> +  need_madvise, need_fallocate, ret);
>  if (ret) {
>  ret = -errno;
>  error_report("ram_block_discard_range: Failed to discard range "
> diff --git a/trace-events b/trace-events
> index 1f50f56d9d..213ee34f89 100644
> --- a/trace-events
> +++ b/trace-events
> @@ -55,6 +55,9 @@ dma_complete(void *dbs, int ret, void *cb) "dbs=%p ret=%d 
> cb=%p"
>  dma_blk_cb(void *dbs, int ret) "dbs=%p ret=%d"
>  dma_map_wait(void *dbs) "dbs=%p"
>  
> +# exec.c
> +ram_block_discard_range(const char *rbname, void *hva, bool need_madvise, 
> bool need_fallocate, int ret) "%s@%p: madvise: %d fallocate: %d ret: %d"
> +
>  # memory.c
>  memory_region_ops_read(int cpu_index, void *mr, uint64_t addr, uint64_t 
> value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size 
> %u"
>  memory_region_ops_write(int cpu_index, void *mr, uint64_t addr, uint64_t 
> value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size 
> %u"
> -- 
> 2.13.5
> 

-- 
Peter Xu



Re: [Qemu-devel] [PATCH] MAINTAINERS: Update mail address for COLO Proxy

2017-08-28 Thread Zhang Chen

Hi~

No news for long time.

Ping...


Thanks

Zhang Chen


On 08/23/2017 04:51 PM, Zhang Chen wrote:

My Fujitsu mail account will be disabled soon, update the mail info
to my private mail.

Signed-off-by: Zhang Chen 
---
  MAINTAINERS | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index ccee28b..3b530a7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1561,7 +1561,7 @@ F: include/migration/failover.h
  F: docs/COLO-FT.txt
  
  COLO Proxy

-M: Zhang Chen 
+M: Zhang Chen 
  M: Li Zhijian 
  S: Supported
  F: docs/colo-proxy.txt


--
Thanks
Zhang Chen






Re: [Qemu-devel] [PATCH 4/4] s390x/pci: add iommu replay callback

2017-08-28 Thread Yi Min Zhao



在 2017/8/28 下午11:57, Cornelia Huck 写道:

On Mon, 28 Aug 2017 10:04:47 +0200
Yi Min Zhao  wrote:


Let's introduce iommu replay callback for s390 pci iommu memory region.
Currently we don't need any dma mapping replay. So let it return
directly. This implementation will avoid meaningless loops calling
translation callback.

Reviewed-by: Pierre Morel 
Reviewed-by: Halil Pasic 
Signed-off-by: Yi Min Zhao 
---
  hw/s390x/s390-pci-bus.c | 8 
  1 file changed, 8 insertions(+)

diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 9e1f7ff5c5..359509ccea 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -407,6 +407,13 @@ static IOMMUTLBEntry 
s390_translate_iommu(IOMMUMemoryRegion *mr, hwaddr addr,
  return ret;
  }
  
+static void s390_pci_iommu_replay(IOMMUMemoryRegion *iommu,

+  IOMMUNotifier *notifier)
+{
+/* we don't need iommu replay currently */

This really needs to be heavier on the _why_. My guess is that anything
which would require replay goes through the rpcit instruction?

My understanding is:
Our arch is different from others. Each pci device has its own iommu, not
like other archs' implementation. So currently there must be no existing
mappings belonging to any newly plugged pci device whose iommu doesn't
have any mapping at the time.
In addition, it's also due to vfio blocking migration. If vfio-pci supports
migration in future, we could implement iommu replay by that time.



+return;
+}
+
  static S390PCIIOMMU *s390_pci_get_iommu(S390pciState *s, PCIBus *bus,
  int devfn)
  {
@@ -1055,6 +1062,7 @@ static void 
s390_iommu_memory_region_class_init(ObjectClass *klass, void *data)
  IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_CLASS(klass);
  
  imrc->translate = s390_translate_iommu;

+imrc->replay = s390_pci_iommu_replay;
  }
  
  static const TypeInfo s390_iommu_memory_region_info = {








[Qemu-devel] [Bug 1713434] Re: prom-env-test test aborted and core dumped

2017-08-28 Thread Thomas Huth
Weird. I managed to run the test on a POWER9 box today, too, and it
works for me:

TEST: tests/prom-env-test... (pid=18912)
  /ppc64/prom-env/mac99:   OK
  /ppc64/prom-env/g3beige: OK
  /ppc64/prom-env/pseries: OK
PASS: tests/prom-env-test

Which OS and C compiler are you using?

Also, could you please try to add this patch (to add "-serial
/dev/stderr") and then post the console output of the prom-env-test:

diff --git a/tests/prom-env-test.c b/tests/prom-env-test.c
--- a/tests/prom-env-test.c
+++ b/tests/prom-env-test.c
@@ -51,7 +51,7 @@ static void test_machine(const void *machine)
 extra_args = strcmp(machine, "pseries") == 0 ? "-nodefaults" : "";
 
 args = g_strdup_printf("-M %s,accel=tcg %s -prom-env 'use-nvramrc?=true' "
-   "-prom-env 'nvramrc=%x %x l!' ",
+   "-prom-env 'nvramrc=%x %x l!' -serial /dev/stderr",
(const char *)machine, extra_args, MAGIC, ADDRESS);
 
 qtest_start(args);

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1713434

Title:
  prom-env-test test aborted and core dumped

Status in QEMU:
  In Progress

Bug description:
  On ppc64le architecture machine the following test case Aborted and
  Core dumped.

  # tests/prom-env-test --quiet --keep-going -m=quick --GTestLogFD=6
  **
  ERROR:tests/libqtest.c:628:qtest_get_arch: assertion failed: (qemu != NULL)
  Aborted (core dumped)

  Steps to re-produce:
  clone from the git
  configure & compile 
  run the unit tests by 'make check'

  (gdb) bt
  #0  0x3fff9d60eff0 in raise () from /lib64/libc.so.6
  #1  0x3fff9d61136c in abort () from /lib64/libc.so.6
  #2  0x3fff9de1aa04 in g_assertion_message () from /lib64/libglib-2.0.so.0
  #3  0x3fff9de1ab0c in g_assertion_message_expr () from 
/lib64/libglib-2.0.so.0
  #4  0x1000cc30 in qtest_get_arch () at tests/libqtest.c:628
  #5  0x100048f0 in main (argc=5, argv=0x32145538) at 
tests/prom-env-test.c:82
  (gdb) i r
  r0 0xfa   250
  r1 0x32144d30 70368510627120
  r2 0x3fff9d7b9900 7036709176
  r3 0x00
  r4 0x12a7 4775
  r5 0x66
  r6 0x88
  r7 0x11
  r8 0x00
  r9 0x00
  r100x00
  r110x00
  r120x00
  r130x3fff9dfa1950 70367099623760
  r140x00
  r150x00
  r160x00
  r170x00
  r180x00
  r190x00
  r200x00
  r210x00
  r220x00
  r230x00
  r240x00
  r250x00
  r260x00
  r270x100287f8 268601336
  r280x16841b40 377756480
  r290x4c   76
  r300x32144de8 70368510627304
  r310x66
  pc 0x3fff9d60eff0 0x3fff9d60eff0 
  msr0x9280f033 10376293541503627315
  cr 0x42000842 1107298370
  lr 0x3fff9d61136c 0x3fff9d61136c 
  ctr0x00
  xer0x00
  orig_r30x12a7 4775
  trap   0xc00  3072

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1713434/+subscriptions



Re: [Qemu-devel] [PATCH 3/4] s390x/pci: fixup ind_offset of msix routing entry

2017-08-28 Thread Yi Min Zhao



在 2017/8/28 下午11:33, Cornelia Huck 写道:

On Mon, 28 Aug 2017 10:04:46 +0200
Yi Min Zhao  wrote:


The aibvo of zpci device should be constant after issued mpcifc
registering irqs instruction. Each msix vector should offset from the
aibvo. But for flic adapter interrupt, we should use the absolute
offset within the aibv. So let's use the aibvo+vector to fixup msix
routing entry.

This makes sense, but I would tweak the description a bit.

"The guest uses the mpcifc instruction to register the aibvo of a zpci
device, which is the starting offset of indicators in the indicator
area and thus remains constant. Each msix vector is an offset from the
aibvo. When we map a msix route to an adapter route, we should not
modify the starting offset, but instead add the vector to the starting
offset to get the absolute offset in the specific route."

Much better. Thanks!


I'm wondering how this was ever supposed to work?

I investigated this. Linux kernel always uses 0 as starting offset for
aibvo. And each msix entry is only registered one time. So we didn't
encounter any problem. But the logic here is not right obviously. It
is just a coincidence.




Signed-off-by: Yi Min Zhao 
---
  target/s390x/kvm.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
index e348bfb7cc..c08b7757e7 100644
--- a/target/s390x/kvm.c
+++ b/target/s390x/kvm.c
@@ -2515,14 +2515,12 @@ int kvm_arch_fixup_msi_route(struct 
kvm_irq_routing_entry *route,
  return -ENODEV;
  }
  
-pbdev->routes.adapter.ind_offset = vec;

-
  route->type = KVM_IRQ_ROUTING_S390_ADAPTER;
  route->flags = 0;
  route->u.adapter.summary_addr = pbdev->routes.adapter.summary_addr;
  route->u.adapter.ind_addr = pbdev->routes.adapter.ind_addr;
  route->u.adapter.summary_offset = pbdev->routes.adapter.summary_offset;
-route->u.adapter.ind_offset = pbdev->routes.adapter.ind_offset;
+route->u.adapter.ind_offset = pbdev->routes.adapter.ind_offset + vec;
  route->u.adapter.adapter_id = pbdev->routes.adapter.adapter_id;
  return 0;
  }







Re: [Qemu-devel] [PATCH 2/4] s390x/pci: remove idx from msix msg data

2017-08-28 Thread Yi Min Zhao



在 2017/8/28 下午11:04, Cornelia Huck 写道:

On Mon, 28 Aug 2017 10:04:45 +0200
Yi Min Zhao  wrote:


PCIDevcie pointer has been a parameter of kvm_arch_fixup_msi_route().

s/PCIDevcie/PCIDevice

Thanks!



So we don't need to store zpci idx in msix message data to find out the
specific zpci device. Instead, we could use pci device id to find its
corresponding zpci device.

Signed-off-by: Yi Min Zhao 
---
  hw/s390x/s390-pci-bus.c  | 16 +---
  hw/s390x/s390-pci-bus.h  |  2 ++
  hw/s390x/s390-pci-inst.c | 24 
  target/s390x/kvm.c   |  7 +--
  4 files changed, 12 insertions(+), 37 deletions(-)
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
index 1c68c36663..e348bfb7cc 100644
--- a/target/s390x/kvm.c
+++ b/target/s390x/kvm.c
@@ -2503,10 +2503,13 @@ int kvm_arch_fixup_msi_route(struct 
kvm_irq_routing_entry *route,
   uint64_t address, uint32_t data, PCIDevice *dev)
  {
  S390PCIBusDevice *pbdev;
-uint32_t idx = data >> ZPCI_MSI_VEC_BITS;
  uint32_t vec = data & ZPCI_MSI_VEC_MASK;
  
-pbdev = s390_pci_find_dev_by_idx(s390_get_phb(), idx);

+if (!dev) {
+return -ENODEV;
+}
+
+pbdev = s390_pci_find_dev_by_target(s390_get_phb(), DEVICE(dev)->id);

You need to replace the stub for s390_pci_find_dev_by_idx() with a stub
for s390_pci_find_dev_by_target() in s390-pci-stubs.c (on my s390-next
branch), so that it compiles without CONFIG_PCI.

OK. Got it.



  if (!pbdev) {
  DPRINTF("add_msi_route no dev\n");
  return -ENODEV;








Re: [Qemu-devel] [PATCH 1/4] s390x/pci: fixup trap_msix()

2017-08-28 Thread Yi Min Zhao



在 2017/8/28 下午10:51, Cornelia Huck 写道:

On Mon, 28 Aug 2017 10:04:44 +0200
Yi Min Zhao  wrote:


The function trap_msix() is to check if pcistg instruction would access
msix table entries. The correct boundary condition should be
[table_offset, table_offset+entries*entry_size). But the current
condition calculated misses the last entry. So let's fixup it.

Acked-by: Dong Jia Shi 
Reviewed-by: Pierre Morel 
Signed-off-by: Yi Min Zhao 
---
  hw/s390x/s390-pci-inst.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/s390x/s390-pci-inst.c b/hw/s390x/s390-pci-inst.c
index b7beb8c36a..eba9ffb5f2 100644
--- a/hw/s390x/s390-pci-inst.c
+++ b/hw/s390x/s390-pci-inst.c
@@ -440,8 +440,8 @@ static int trap_msix(S390PCIBusDevice *pbdev, uint64_t 
offset, uint8_t pcias)
  {
  if (pbdev->msix.available && pbdev->msix.table_bar == pcias &&
  offset >= pbdev->msix.table_offset &&
-offset <= pbdev->msix.table_offset +
-  (pbdev->msix.entries - 1) * PCI_MSIX_ENTRY_SIZE) {
+offset < (pbdev->msix.table_offset +
+  pbdev->msix.entries * PCI_MSIX_ENTRY_SIZE)) {
  return 1;
  } else {
  return 0;

What happened before due to the miscalculation? Write to wrong memory
region?



We tried to plug virtio-net pci device but failed. After inspected, we
found that the device uses two msix entries but the last one was
missed. Then we cannot register interrupt successfully because we
should call trap_msixi() in order to save some useful and arch
information into msix message. But what about wrong memory region
didn't happen.




[Qemu-devel] [Bug 1713434] Re: prom-env-test test aborted and core dumped

2017-08-28 Thread R.Nageswara Sastry
TEST: tests/prom-env-test... (pid=9915)
  /ppc64/prom-env/mac99:   OK
  /ppc64/prom-env/g3beige: OK
  /ppc64/prom-env/pseries: **
ERROR:tests/prom-env-test.c:42:check_guest_memory: assertion failed (signature 
== MAGIC): (0x7c7f1b78 == 0xcafec0de)
FAIL
GTester: last random seed: R02S765f0e192be9c96e793728ecc28d6395
(pid=10152)
FAIL: tests/prom-env-test

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1713434

Title:
  prom-env-test test aborted and core dumped

Status in QEMU:
  In Progress

Bug description:
  On ppc64le architecture machine the following test case Aborted and
  Core dumped.

  # tests/prom-env-test --quiet --keep-going -m=quick --GTestLogFD=6
  **
  ERROR:tests/libqtest.c:628:qtest_get_arch: assertion failed: (qemu != NULL)
  Aborted (core dumped)

  Steps to re-produce:
  clone from the git
  configure & compile 
  run the unit tests by 'make check'

  (gdb) bt
  #0  0x3fff9d60eff0 in raise () from /lib64/libc.so.6
  #1  0x3fff9d61136c in abort () from /lib64/libc.so.6
  #2  0x3fff9de1aa04 in g_assertion_message () from /lib64/libglib-2.0.so.0
  #3  0x3fff9de1ab0c in g_assertion_message_expr () from 
/lib64/libglib-2.0.so.0
  #4  0x1000cc30 in qtest_get_arch () at tests/libqtest.c:628
  #5  0x100048f0 in main (argc=5, argv=0x32145538) at 
tests/prom-env-test.c:82
  (gdb) i r
  r0 0xfa   250
  r1 0x32144d30 70368510627120
  r2 0x3fff9d7b9900 7036709176
  r3 0x00
  r4 0x12a7 4775
  r5 0x66
  r6 0x88
  r7 0x11
  r8 0x00
  r9 0x00
  r100x00
  r110x00
  r120x00
  r130x3fff9dfa1950 70367099623760
  r140x00
  r150x00
  r160x00
  r170x00
  r180x00
  r190x00
  r200x00
  r210x00
  r220x00
  r230x00
  r240x00
  r250x00
  r260x00
  r270x100287f8 268601336
  r280x16841b40 377756480
  r290x4c   76
  r300x32144de8 70368510627304
  r310x66
  pc 0x3fff9d60eff0 0x3fff9d60eff0 
  msr0x9280f033 10376293541503627315
  cr 0x42000842 1107298370
  lr 0x3fff9d61136c 0x3fff9d61136c 
  ctr0x00
  xer0x00
  orig_r30x12a7 4775
  trap   0xc00  3072

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1713434/+subscriptions



Re: [Qemu-devel] [PATCH 4/5] pci: Add INTERFACE_LEGACY_PCI_DEVICE to legacy PCI devices

2017-08-28 Thread Eduardo Habkost
On Mon, Aug 28, 2017 at 06:58:37PM -0400, John Snow wrote:
> 
> 
> On 08/25/2017 03:39 PM, Eduardo Habkost wrote:
> > CCing maintainers of affected devices (sorry for not CCing you
> > before).
> > 
> > On Wed, Aug 23, 2017 at 07:14:44PM -0300, Eduardo Habkost wrote:
> >> Add INTERFACE_LEGACY_PCI_DEVICE to all direct subtypes of
> >> TYPE_PCI_DEVICE, except:
> >>
> >> 1) The ones that already have INTERFACE_PCIE_DEVICE set:
> >>
> >> * base-xhci
> >> * e1000e
> >> * nvme
> >> * pvscsi
> >> * vfio-pci
> >> * virtio-pci
> >> * vmxnet3
> >>
> >> 2) base-pci-bridge
> >>
> >> Not all PCI bridges are legacy PCI devices, so
> >> INTERFACE_LEGACY_PCI_DEVICE is added only to the subtypes that
> >> are actually legacy PCI devices:
> >>
> >> * dec-21154-p2p-bridge
> >> * i82801b11-bridge
> >> * pbm-bridge
> >> * pci-bridge
> >>
> >> The direct subtypes of base-pci-bridge not touched by this patch
> >> are:
> >>
> >> * xilinx-pcie-root: Already marked as PCIe-only device.
> >> * pcie-port: all non-abstract subtypes of pcie-port are already
> >>   marked as PCIe-only devices.
> >>
> >> 3) megasas-base
> >>
> >> Not all megasas devices are legacy PCI devices, so the interface
> >> names are added to the subclasses registered by
> >> megasas_register_types(), according to information in the
> >> megasas_devices[] array.
> >>
> >> "megasas-gen2" already implements INTERFACE_PCIE_DEVICE, so add
> >> INTERFACE_LEGACY_PCI_DEVICE only to "megasas".
> >>
> >> Signed-off-by: Eduardo Habkost 
> >> ---
> 
> [...]
> 
> >>  hw/ide/ich.c|  4 
> >>  hw/ide/pci.c|  4 
> 
> Acked-by: John Snow 
> 
> 
> (Random fly-by comment without looking at the other patches: I assume
> there are reasons it's not appropriate or good to add a legacy PCI
> device parent that we inherit from, and it's instead better to manually
> add the property to all children?)

Yes, the reason I'm using interfaces instead of regular
inheritance is the existence of hybrid devices (see patch 2/5).

-- 
Eduardo



Re: [Qemu-devel] [PATCH] spapr: Add ibm, processor-storage-keys property to CPU DT node

2017-08-28 Thread David Gibson
On Mon, Aug 28, 2017 at 10:50:11AM -0700, Ram Pai wrote:
> On Fri, Aug 25, 2017 at 02:23:13PM +1000, David Gibson wrote:
> > On Thu, Aug 24, 2017 at 11:11:22AM -0700, Ram Pai wrote:
> > > On Thu, Aug 24, 2017 at 12:54:48PM +1000, Paul Mackerras wrote:
> > > > On Mon, Aug 21, 2017 at 05:00:36PM -0300, Thiago Jung Bauermann wrote:
> > > > > LoPAPR says:
> > > > > 
> > > > > “ibm,processor-storage-keys”
> > > > > 
> > > > > property name indicating the number of virtual storage keys 
> > > > > supported
> > > > > by the processor described by this node.
> > > > > 
> > > > > prop-encoded-array: Consists of two cells encoded as with 
> > > > > encode-int.
> > > > > The first cell represents the number of virtual storage keys 
> > > > > supported
> > > > > for data accesses while the second cell represents the number of
> > > > > virtual storage keys supported for instruction accesses. The cell 
> > > > > value
> > > > > of zero indicates that no storage keys are supported for the 
> > > > > access
> > > > > type.
> > > > > 
> > > > > pHyp provides the property above but there's a bug in P8 firmware 
> > > > > where the
> > > > > second cell is zero even though POWER8 supports instruction access 
> > > > > keys.
> > > > > This bug will be fixed for P9.
> > > > > 
> > > > > Tested with KVM on POWER8 Firenze machine and with TCG on x86_64 
> > > > > machine.
> > > > > 
> > > > > Signed-off-by: Thiago Jung Bauermann 
> > > > > ---
> > > > > 
> > > > > The sysfs files are provided by this patch for Linux:
> > > > 
> > > > Those sysfs files relate to the kernel's support for userspace
> > > > processes using storage keys.  That is quite distinct from KVM's
> > > > support for guests using storage keys, so I think that using those
> > > > sysfs files to indicate what the guest can do is wrong.
> > > > 
> > > > In fact KVM allows guests to specify storage keys in the HPTE values
> > > > that they set, except that there is a bug (for which Ram Pai has
> > > > posted a patch) that means that KVM loses the top two bits of the key
> > > > number.
> > > > 
> > > > What I would suggest is that we use the 'pad' field in the struct
> > > > kvm_ppc_smmu_info to report the number of keys supported by KVM for
> > > > guest use.  That will be 0 in all current kernels, indicating that
> > > > keys are not supported, which is reasonable because of the bug.  I
> > > > will make sure the patch fixing the bug goes in first.
> > > 
> > > with the current kernels, even with the bug, KVM can still support 8
> > > keys. Should we say 8 instead of 0?  It will help enable keys on KVM
> > > earlier and give a jump start to its adaption by applications.
> > 
> > But the point isn't really what we *can* say, it's with what is
> > implicitly said by kernels that don't advertise anything
> > specifically.  Which is 0.
> > 
> 
> Right. I was pointing to the case where nothing is said implicitly by
> the kernel (no advertised values), to default to 8 instead of defaulting
> to 0.

The point is that the kernel advertising nothing is indistinguishable
from it advertising 0.  We don't get to chose that default value.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH v15 4/5] mm: support reporting free page blocks

2017-08-28 Thread Wei Wang

On 08/28/2017 09:33 PM, Michal Hocko wrote:

On Mon 28-08-17 18:08:32, Wei Wang wrote:

This patch adds support to walk through the free page blocks in the
system and report them via a callback function. Some page blocks may
leave the free list after zone->lock is released, so it is the caller's
responsibility to either detect or prevent the use of such pages.

One use example of this patch is to accelerate live migration by skipping
the transfer of free pages reported from the guest. A popular method used
by the hypervisor to track which part of memory is written during live
migration is to write-protect all the guest memory. So, those pages that
are reported as free pages but are written after the report function
returns will be captured by the hypervisor, and they will be added to the
next round of memory transfer.

OK, looks much better. I still have few nits.


+extern void walk_free_mem_block(void *opaque,
+   int min_order,
+   bool (*report_page_block)(void *, unsigned long,
+ unsigned long));
+

please add names to arguments of the prototype


  /*
   * Free reserved pages within range [PAGE_ALIGN(start), end & PAGE_MASK)
   * into the buddy system. The freed pages will be poisoned with pattern
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 6d00f74..81eedc7 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4762,6 +4762,71 @@ void show_free_areas(unsigned int filter, nodemask_t 
*nodemask)
show_swap_cache_info();
  }
  
+/**

+ * walk_free_mem_block - Walk through the free page blocks in the system
+ * @opaque: the context passed from the caller
+ * @min_order: the minimum order of free lists to check
+ * @report_page_block: the callback function to report free page blocks

page_block has meaning in the core MM which doesn't strictly match its
usage here. Moreover we are reporting pfn ranges rather than struct page
range. So report_pfn_range would suit better.

[...]

+   for_each_populated_zone(zone) {
+   for (order = MAX_ORDER - 1; order >= min_order; order--) {
+   for (mt = 0; !stop && mt < MIGRATE_TYPES; mt++) {
+   spin_lock_irqsave(>lock, flags);
+   list = >free_area[order].free_list[mt];
+   list_for_each_entry(page, list, lru) {
+   pfn = page_to_pfn(page);
+   stop = report_page_block(opaque, pfn,
+1 << order);
+   if (stop)
+   break;

if (stop) {

spin_unlock_irqrestore(>lock, flags);
return;
}

would be both easier and less error prone. E.g. You wouldn't pointlessly
iterate over remaining orders just to realize there is nothing to be
done for those...



Yes, that's better, thanks. I will take other suggestions as well.

Best,
Wei






Re: [Qemu-devel] [PATCH v15 3/5] virtio-balloon: VIRTIO_BALLOON_F_SG

2017-08-28 Thread Wei Wang

On 08/29/2017 02:03 AM, Michael S. Tsirkin wrote:

On Mon, Aug 28, 2017 at 06:08:31PM +0800, Wei Wang wrote:

Add a new feature, VIRTIO_BALLOON_F_SG, which enables the transfer
of balloon (i.e. inflated/deflated) pages using scatter-gather lists
to the host.

The implementation of the previous virtio-balloon is not very
efficient, because the balloon pages are transferred to the
host one by one. Here is the breakdown of the time in percentage
spent on each step of the balloon inflating process (inflating
7GB of an 8GB idle guest).

1) allocating pages (6.5%)
2) sending PFNs to host (68.3%)
3) address translation (6.1%)
4) madvise (19%)

It takes about 4126ms for the inflating process to complete.
The above profiling shows that the bottlenecks are stage 2)
and stage 4).

This patch optimizes step 2) by transferring pages to the host in
sgs. An sg describes a chunk of guest physically continuous pages.
With this mechanism, step 4) can also be optimized by doing address
translation and madvise() in chunks rather than page by page.

With this new feature, the above ballooning process takes ~597ms
resulting in an improvement of ~86%.

TODO: optimize stage 1) by allocating/freeing a chunk of pages
instead of a single page each time.

Signed-off-by: Wei Wang 
Signed-off-by: Liang Li 
Suggested-by: Michael S. Tsirkin 
---
  drivers/virtio/virtio_balloon.c | 171 
  include/uapi/linux/virtio_balloon.h |   1 +
  2 files changed, 155 insertions(+), 17 deletions(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index f0b3a0b..8ecc1d4 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -32,6 +32,8 @@
  #include 
  #include 
  #include 
+#include 
+#include 
  
  /*

   * Balloon device works in 4K page units.  So each page is pointed to by
@@ -79,6 +81,9 @@ struct virtio_balloon {
/* Synchronize access/update to this struct virtio_balloon elements */
struct mutex balloon_lock;
  
+	/* The xbitmap used to record balloon pages */

+   struct xb page_xb;
+
/* The array of pfns we tell the Host about. */
unsigned int num_pfns;
__virtio32 pfns[VIRTIO_BALLOON_ARRAY_PFNS_MAX];
@@ -141,13 +146,111 @@ static void set_page_pfns(struct virtio_balloon *vb,
  page_to_balloon_pfn(page) + i);
  }
  
+static int add_one_sg(struct virtqueue *vq, void *addr, uint32_t size)

+{
+   struct scatterlist sg;
+
+   sg_init_one(, addr, size);
+   return virtqueue_add_inbuf(vq, , 1, vq, GFP_KERNEL);
+}
+
+static void send_balloon_page_sg(struct virtio_balloon *vb,
+struct virtqueue *vq,
+void *addr,
+uint32_t size,
+bool batch)
+{
+   unsigned int len;
+   int err;
+
+   err = add_one_sg(vq, addr, size);
+   /* Sanity check: this can't really happen */
+   WARN_ON(err);

It might be cleaner to detect that add failed due to
ring full and kick then. Just an idea, up to you
whether to do it.


+
+   /* If batching is in use, we batch the sgs till the vq is full. */
+   if (!batch || !vq->num_free) {
+   virtqueue_kick(vq);
+   wait_event(vb->acked, virtqueue_get_buf(vq, ));
+   /* Release all the entries if there are */

Meaning
Account for all used entries if any
?


+   while (virtqueue_get_buf(vq, ))
+   ;


Above code is reused below. Add a function?


+   }
+}
+
+/*
+ * Send balloon pages in sgs to host. The balloon pages are recorded in the
+ * page xbitmap. Each bit in the bitmap corresponds to a page of PAGE_SIZE.
+ * The page xbitmap is searched for continuous "1" bits, which correspond
+ * to continuous pages, to chunk into sgs.
+ *
+ * @page_xb_start and @page_xb_end form the range of bits in the xbitmap that
+ * need to be searched.
+ */
+static void tell_host_sgs(struct virtio_balloon *vb,
+ struct virtqueue *vq,
+ unsigned long page_xb_start,
+ unsigned long page_xb_end)
+{
+   unsigned long sg_pfn_start, sg_pfn_end;
+   void *sg_addr;
+   uint32_t sg_len, sg_max_len = round_down(UINT_MAX, PAGE_SIZE);
+
+   sg_pfn_start = page_xb_start;
+   while (sg_pfn_start < page_xb_end) {
+   sg_pfn_start = xb_find_next_bit(>page_xb, sg_pfn_start,
+   page_xb_end, 1);
+   if (sg_pfn_start == page_xb_end + 1)
+   break;
+   sg_pfn_end = xb_find_next_bit(>page_xb, sg_pfn_start + 1,
+ page_xb_end, 0);
+   sg_addr = (void *)pfn_to_kaddr(sg_pfn_start);
+   sg_len = (sg_pfn_end - sg_pfn_start) << 

Re: [Qemu-devel] reduce write bandwidth of qcow2 driver while allocating new cluster

2017-08-28 Thread Liu Qing
On Mon, Aug 28, 2017 at 05:40:48PM -0400, John Snow wrote:
> 
> 
> On 08/28/2017 01:56 AM, Liu Qing wrote:
> > Dear list,
> > Recently I used fio to test qcow2 driver in the guest os, and found out
> > that when a new cluster is allocated the 4K IO will occupy 64K(default 
> > cluster
> > size) bandwith.
> > From the code qcow2 driver will fill the unused part of new allocated
> > cluster with 0 in perform_cow. These 0s are set in qcow2_co_readv when the 
> > read
> > destination is not allocated and it has no backing file. Could I forbidden 
> > any
> > further write in copy_sectors if the copy source is not allocated and it has
> > no backing file? So only the requested data is written to the cluster. 
> > Function
> > copy_sectors is only used by perform_cow in the master branch.
> > Do you think this change is reasonable? Thanks.
> > 
> > 
> 
> CCing qemu-block.
> 
> If I am understanding you correctly, you're noticing an adverse
> performance impact from initial writes to unallocated clusters through
> the qcow2 driver, when qcow2 performs zero-fill of uninitiated clusters.
Yes, that's it.
> 
> First, can you look at sources for current master branch? it hasn't been
> named "copy_sectors" since June 2016, and the function looks a bit
> differently than it did in the version you're looking at, I think.
I checkout the latest master branch and the code path has some changes, but the
zero-fill process still exists. Eric has replied a patch from Anton
which could improve the write performance. Thanks all.
> 
> John
> 




Re: [Qemu-devel] reduce write bandwidth of qcow2 driver while allocating new cluster

2017-08-28 Thread Liu Qing
On Mon, Aug 28, 2017 at 10:46:34AM -0500, Eric Blake wrote:
> [adding qemu-block]
> 
> On 08/28/2017 12:56 AM, Liu Qing wrote:
> > Dear list,
> > Recently I used fio to test qcow2 driver in the guest os, and found out
> > that when a new cluster is allocated the 4K IO will occupy 64K(default 
> > cluster
> > size) bandwith.
> > From the code qcow2 driver will fill the unused part of new allocated
> > cluster with 0 in perform_cow. These 0s are set in qcow2_co_readv when the 
> > read
> > destination is not allocated and it has no backing file. Could I forbidden 
> > any
> > further write in copy_sectors if the copy source is not allocated and it has
> > no backing file? So only the requested data is written to the cluster. 
> > Function
> > copy_sectors is only used by perform_cow in the master branch.
> 
> There have already been discussions on optimizing COW writes in a manner
> similar to what you are describing; for example,
> 
> https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg00109.html
Thanks Eric, this is what I am looking for.
The only concern I have is in patch '[Qemu-devel] [PATCH v4 12/15] qcow2: skip
writing zero buffers to empty' it says:

It can be detected that
  1. COW alignment of a write request is zeroes
  2. Respective areas on the underlying BDS already read as zeroes
 after being preallocated previously
  If both of these true, COW may be skipped

Will writing zero be skipped if the disk is not preallocated? @Anton

BTW: why the code in the patch is a little different than the latest
master branch? For example I don't have the is_zero function but only
get is_zero_sectors. Is there something wrong with my settings?

My repo:
# git remote -v
origin  git://git.qemu-project.org/qemu.git (fetch)
origin  git://git.qemu-project.org/qemu.git (push)

Thanks.
> 
> -- 
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.   +1-919-301-3266
> Virtualization:  qemu.org | libvirt.org
> 






Re: [Qemu-devel] [PATCH 00/79] Patch Round-up for stable 2.9.1, freeze on 2017-09-04

2017-08-28 Thread Thomas Huth
On 29.08.2017 02:13, Michael Roth wrote:
> Hi everyone,
> 
> The following new patches are queued for QEMU stable v2.9.1:
> 
>   https://github.com/mdroth/qemu/commits/stable-2.9-staging
> 
> The release is planned for 2017-09-07:
> 
>   http://wiki.qemu.org/Planning/2.9
> 
> Please respond here or CC qemu-sta...@nongnu.org on any patches you
> think should be included in the release.

I'd like to suggest the following patches:

601b9a9008c5a612d76073bb - target-s390x: Mask the SIGP order_code ...
b7da97eef74bf834be244de0 - monitor: Check whether TCG is enabled ...
17eb587aeb492fe68f8130b0 - slirp: tftp, copy sockaddr_size
99efaa2696caaf6182958e27 - hw/s390x/ipl: Fix crash with ...
36bed541ca886da735bef1e8 - fix qemu-system-unicore32 crashing ...
b190f477e29c7cd03a8fee49 - qemu-system-tricore: segfault when ...
8ff9dd7ba24c7a788611 - hw/ppc/spapr_rtc: Mark the RTC device ...
1f98e55385d11da1dc0de644 - hw/ppc/spapr_iommu: Fix crash when ...

Not sure, but maybe the following patch should be included, too, since
there were some bogus files in the old version of the U-Boot sources:

73663d71ef2bab201475d58e - PPC: E500: Update u-boot to v2017.07

 Thomas



Re: [Qemu-devel] [PATCH] spapr: Add ibm, processor-storage-keys property to CPU DT node

2017-08-28 Thread David Gibson
On Mon, Aug 28, 2017 at 10:53:56AM -0700, Ram Pai wrote:
> On Thu, Aug 24, 2017 at 12:54:48PM +1000, Paul Mackerras wrote:
> > 
> > We could either have two u16 fields for the number of keys for data
> > and instruction, or we could have a u32 field for the number of keys
> > and a separate bit in the flags field to indicate that instruction
> > keys are supported.  Which would be preferable?
> 
> the second choice is more confusion-proof; to me atleast.
> 
> The first choice gives a illusion that there are 'x' number of data keys
> and 'y' number of instruction keys; which is not exactly true.

Ah.. can you elaborate?

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH 00/79] Patch Round-up for stable 2.9.1, freeze on 2017-09-04

2017-08-28 Thread Michael Roth
Quoting Michael Roth (2017-08-28 19:13:35)
> Hi everyone,
> 
> The following new patches are queued for QEMU stable v2.9.1:
> 
>   
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_mdroth_qemu_commits_stable-2D2.9-2Dstaging=DwIFaQ=jf_iaSHvJObTbx-siA1ZOg=sThPI1c0u5x-3sg5Nw8wNqjg_5Z5xLzfPGC18E94zn8=Mw1bU8iEiV5THnZe_RluoHefJMDFgKus3DOUY40AbVA=wB11-59-V11-yisUGoowZ4UvmSBfZNqhjDdEk9QwqAk=
>  
> 
> The release is planned for 2017-09-07:
> 
>   
> https://urldefense.proofpoint.com/v2/url?u=http-3A__wiki.qemu.org_Planning_2.9=DwIFaQ=jf_iaSHvJObTbx-siA1ZOg=sThPI1c0u5x-3sg5Nw8wNqjg_5Z5xLzfPGC18E94zn8=Mw1bU8iEiV5THnZe_RluoHefJMDFgKus3DOUY40AbVA=aKWE0XkaM9D2OJvn5Etwst9lR3FUDED9C_m5ue7HB6w=
>  

Sorry for this. I've sent some other emails to see if this behavior
continued from my SMTP relay, and it seems to have been some sort of
temporary issue. The original URLs were (assuming I don't get bit by
this again):

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

and

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

> 
> Please respond here or CC qemu-sta...@nongnu.org on any patches you
> think should be included in the release.
> 
> Testing/feedback is greatly appreciated.
> 
> Thanks!
> 
> 
> Alberto Garcia (1):
>   stream: fix crash in stream_start() when block_job_create() fails
> 
> Aleksandr Bezzubikov (1):
>   hw/i386: allow SHPC for Q35 machine
> 
> Alexander Graf (2):
>   hid: Reset kbd modifiers on reset
>   input: Decrement queue count on kbd delay
> 
> Anton Nefedov (1):
>   qemu-img: wait for convert coroutines to complete
> 
> Bruce Rogers (2):
>   ACPI: don't call acpi_pcihp_device_plug_cb on xen
>   9pfs: local: remove: use correct path component
> 
> Daniel P. Berrange (1):
>   migration: setup bi-directional I/O channel for exec: protocol
> 
> Eduardo Habkost (1):
>   pc: Use "min-[x]level" on compat_props
> 
> Eric Blake (16):
>   dirty-bitmap: Report BlockDirtyInfo.count in bytes, as documented
>   coccinelle: Add script to remove useless QObject casts
>   qobject: Drop useless QObject casts
>   qobject: Add helper macros for common scalar insertions
>   s390x: Drop useless casts
>   qobject: Use simpler QDict/QList scalar insertion macros
>   blkdebug: Sanity check block layer guarantees
>   blkdebug: Refactor error injection
>   blkdebug: Add pass-through write_zero and discard support
>   blkdebug: Simplify override logic
>   blkdebug: Add ability to override unmap geometries
>   tests: Add coverage for recent block geometry fixes
>   block: Simplify BDRV_BLOCK_RAW recursion
>   block: Guarantee that *file is set on bdrv_get_block_status()
>   nbd: Fully initialize client in case of failed negotiation
>   nbd: Fix regression on resiliency to port scan
> 
> Fam Zheng (2):
>   block: Reuse bs as backing hd for drive-backup sync=none
>   virtio-scsi: Unset hotplug handler when unrealize
> 
> Gerd Hoffmann (1):
>   input: limit kbd queue depth
> 
> Greg Kurz (7):
>   9pfs: local: fix unlink of alien files in mapped-file mode
>   virtio: allow broken device to notify guest
>   target/ppc: pass const string to kvmppc_is_mem_backend_page_size_ok()
>   target/ppc: fix memory leak in kvmppc_is_mem_backend_page_size_ok()
>   spapr: fix memory leak in spapr_memory_pre_plug()
>   spapr: fix memory leak in spapr_core_pre_plug()
>   9pfs: local: fix fchmodat_nofollow() limitations
> 
> Halil Pasic (1):
>   s390x/css: catch section mismatch on load
> 
> Herongguang (Stephen) (1):
>   pci: deassert intx when pci device unrealize
> 
> Hervé Poussineau (1):
>   vvfat: fix qemu-img map and qemu-img convert
> 
> Jason Wang (2):
>   virtio-scsi: finalize IOMMU support
>   virtio-net: fix offload ctrl endian
> 
> Jeff Cody (1):
>   block/nfs: fix mutex assertion in nfs_file_close()
> 
> John Snow (1):
>   blockdev: use drained_begin/end for qmp_block_resize
> 
> Kevin Wolf (6):
>   mirror: Drop permissions on s->target on completion
>   commit: Fix use after free in completion
>   commit: Fix completion with extra reference
>   commit: Add NULL check for overlay_bs
>   qemu-iotests: Test automatic commit job cancel on hot unplug
>   block: Skip implicit nodes in query-block/blockstats
> 
> Ladi Prosek (1):
>   virtio-serial-bus: Unset hotplug handler when unrealize
> 
> Laurent Vivier (3):
>   spapr: add pre_plug function for memory
>   spapr: fix migration to pseries machine < 2.8
>   cpu: don't allow negative core id
> 
> Markus Armbruster (1):
>   replication: Make --disable-replication compile again
> 
> Max Filippov (3):
>   target/xtensa: fix mapping direction in read/write simcalls
>   target/xtensa: fix return value of read/write simcalls
>   target/xtensa: handle unknown registers in gdbstub
> 
> Max Reitz (11):

Re: [Qemu-devel] [PATCH 7/9] AHCI: Rework IRQ constants

2017-08-28 Thread John Snow


On 08/25/2017 10:00 AM, Philippe Mathieu-Daudé wrote:
> Hi John,
> 
> On 08/08/2017 03:33 PM, John Snow wrote:
>> Create a new enum so that we can name the IRQ bits, which will make
>> debugging
>> them a little nicer if we can print them out. Not handled in this
>> patch, but
>> this will make it possible to get a nice debug printf detailing
>> exactly which
>> status bits are set, as it can be multiple at any given time.
>>
>> As a consequence of this patch, it is no longer possible to set
>> multiple IRQ
>> codes at once, but nothing was utilizing this ability anyway.
>>
>> Signed-off-by: John Snow 
>> ---
>>   hw/ide/ahci.c  | 49
>> ++---
>>   hw/ide/ahci_internal.h | 44
>> +++-
>>   hw/ide/trace-events|  2 +-
>>   3 files changed, 74 insertions(+), 21 deletions(-)
>>
>> diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
>> index d5acceb..c5a9b69 100644
>> --- a/hw/ide/ahci.c
>> +++ b/hw/ide/ahci.c
>> @@ -56,6 +56,27 @@ static bool ahci_map_fis_address(AHCIDevice *ad);
>>   static void ahci_unmap_clb_address(AHCIDevice *ad);
>>   static void ahci_unmap_fis_address(AHCIDevice *ad);
>>   +static const char *AHCIPortIRQ_lookup[AHCI_PORT_IRQ__END] = {
>> +[AHCI_PORT_IRQ_BIT_DHRS] = "DHRS",
>> +[AHCI_PORT_IRQ_BIT_PSS]  = "PSS",
>> +[AHCI_PORT_IRQ_BIT_DSS]  = "DSS",
>> +[AHCI_PORT_IRQ_BIT_SDBS] = "SDBS",
>> +[AHCI_PORT_IRQ_BIT_UFS]  = "UFS",
>> +[AHCI_PORT_IRQ_BIT_DPS]  = "DPS",
>> +[AHCI_PORT_IRQ_BIT_PCS]  = "PCS",
>> +[AHCI_PORT_IRQ_BIT_DMPS] = "DMPS",
>> +[8 ... 21]   = "RESERVED",
>> +[AHCI_PORT_IRQ_BIT_PRCS] = "PRCS",
>> +[AHCI_PORT_IRQ_BIT_IPMS] = "IPMS",
>> +[AHCI_PORT_IRQ_BIT_OFS]  = "OFS",
>> +[25] = "RESERVED",
>> +[AHCI_PORT_IRQ_BIT_INFS] = "INFS",
>> +[AHCI_PORT_IRQ_BIT_IFS]  = "IFS",
>> +[AHCI_PORT_IRQ_BIT_HBDS] = "HBDS",
>> +[AHCI_PORT_IRQ_BIT_HBFS] = "HBFS",
>> +[AHCI_PORT_IRQ_BIT_TFES] = "TFES",
>> +[AHCI_PORT_IRQ_BIT_CPDS] = "CPDS"
>> +};
>> static uint32_t  ahci_port_read(AHCIState *s, int port, int offset)
>>   {
>> @@ -170,12 +191,18 @@ static void ahci_check_irq(AHCIState *s)
>>   }
>> static void ahci_trigger_irq(AHCIState *s, AHCIDevice *d,
>> - int irq_type)
>> + enum AHCIPortIRQ irqbit)
>>   {
>> -DPRINTF(d->port_no, "trigger irq %#x -> %x\n",
>> -irq_type, d->port_regs.irq_mask & irq_type);
>> +g_assert(irqbit >= 0 && irqbit < 32);
> 
> Since you now use an enum this check is no more necessary.
> 

You can actually still pass in a wrong value if you wanted to. This is
to prevent old-style IRQ masks from getting passed in by accident.

> However ...
> 
>> +uint32_t irq = 1U << irqbit;
>> +uint32_t irqstat = d->port_regs.irq_stat | irq;
>>   -d->port_regs.irq_stat |= irq_type;
>> +trace_ahci_trigger_irq(s, d->port_no,
>> +   AHCIPortIRQ_lookup[irqbit], irq,
>> +   d->port_regs.irq_stat, irqstat,
>> +   irqstat & d->port_regs.irq_mask);
>> +
> 
> Why not keep using masked irqs, and iterate over AHCI_PORT_IRQ__END
> bits? Something like:
> 
> if (TRACE_AHCI_IRQ_ENABLED) {
> int irqbit;
> for (irqbit = 0; irqbit < AHCI_PORT_IRQ__END; irqbit++) {
> if (irqmask & BIT(irqbit)) {
> trace_ahci_trigger_irq(s, d->port_no, ...
> 

Would rather not iterate like that for the IRQ path. Generally no place
in the codebase needs to raise more than one IRQ type at a time, so why
bother allowing it?



Re: [Qemu-devel] [PATCH] tests: fix incorrect size_t format in benchmark-crypto

2017-08-28 Thread Longpeng (Mike)


On 2017/8/28 19:37, Philippe Mathieu-Daudé wrote:

>   $ make check-speed
>   tests/benchmark-crypto-hash.c: In function 'test_hash_speed':
>   tests/benchmark-crypto-hash.c:44:5: error: format '%ld' expects argument of 
> type 'long int', but argument 2 has type 'size_t' [-Werror=format=]
>g_print("Testing chunk_size %ld bytes ", chunk_size);
>^
>   tests/benchmark-crypto-hash.c: In function 'main':
>   tests/benchmark-crypto-hash.c:62:9: error: format '%lu' expects argument of 
> type 'long unsigned int', but argument 4 has type 'size_t' [-Werror=format=]
>snprintf(name, sizeof(name), "/crypto/hash/speed-%lu", i);
>^
>   cc1: all warnings being treated as errors
>   rules.mak:66: recipe for target 'tests/benchmark-crypto-hash.o' failed
>   make: *** [tests/benchmark-crypto-hash.o] Error 1
> 
> Signed-off-by: Philippe Mathieu-Daudé 


Reviewed-by: Longpeng(Mike) 

> ---
> testing v2.10.0-rc4
> 
>  tests/benchmark-crypto-cipher.c | 4 ++--
>  tests/benchmark-crypto-hash.c   | 4 ++--
>  tests/benchmark-crypto-hmac.c   | 4 ++--
>  3 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/tests/benchmark-crypto-cipher.c b/tests/benchmark-crypto-cipher.c
> index c6a40929e4..cf98443468 100644
> --- a/tests/benchmark-crypto-cipher.c
> +++ b/tests/benchmark-crypto-cipher.c
> @@ -59,7 +59,7 @@ static void test_cipher_speed(const void *opaque)
>  total /= 1024 * 1024; /* to MB */
>  
>  g_print("cbc(aes128): ");
> -g_print("Testing chunk_size %ld bytes ", chunk_size);
> +g_print("Testing chunk_size %zu bytes ", chunk_size);
>  g_print("done: %.2f MB in %.2f secs: ", total, g_test_timer_last());
>  g_print("%.2f MB/sec\n", total / g_test_timer_last());
>  
> @@ -80,7 +80,7 @@ int main(int argc, char **argv)
>  
>  for (i = 512; i <= (64 * 1204); i *= 2) {
>  memset(name, 0 , sizeof(name));
> -snprintf(name, sizeof(name), "/crypto/cipher/speed-%lu", i);
> +snprintf(name, sizeof(name), "/crypto/cipher/speed-%zu", i);
>  g_test_add_data_func(name, (void *)i, test_cipher_speed);
>  }
>  
> diff --git a/tests/benchmark-crypto-hash.c b/tests/benchmark-crypto-hash.c
> index 6769d2a11b..122bfb6b85 100644
> --- a/tests/benchmark-crypto-hash.c
> +++ b/tests/benchmark-crypto-hash.c
> @@ -41,7 +41,7 @@ static void test_hash_speed(const void *opaque)
>  
>  total /= 1024 * 1024; /* to MB */
>  g_print("sha256: ");
> -g_print("Testing chunk_size %ld bytes ", chunk_size);
> +g_print("Testing chunk_size %zu bytes ", chunk_size);
>  g_print("done: %.2f MB in %.2f secs: ", total, g_test_timer_last());
>  g_print("%.2f MB/sec\n", total / g_test_timer_last());
>  
> @@ -59,7 +59,7 @@ int main(int argc, char **argv)
>  
>  for (i = 512; i <= (64 * 1204); i *= 2) {
>  memset(name, 0 , sizeof(name));
> -snprintf(name, sizeof(name), "/crypto/hash/speed-%lu", i);
> +snprintf(name, sizeof(name), "/crypto/hash/speed-%zu", i);
>  g_test_add_data_func(name, (void *)i, test_hash_speed);
>  }
>  
> diff --git a/tests/benchmark-crypto-hmac.c b/tests/benchmark-crypto-hmac.c
> index 72408be987..c30250df3e 100644
> --- a/tests/benchmark-crypto-hmac.c
> +++ b/tests/benchmark-crypto-hmac.c
> @@ -56,7 +56,7 @@ static void test_hmac_speed(const void *opaque)
>  total /= 1024 * 1024; /* to MB */
>  
>  g_print("hmac(sha256): ");
> -g_print("Testing chunk_size %ld bytes ", chunk_size);
> +g_print("Testing chunk_size %zu bytes ", chunk_size);
>  g_print("done: %.2f MB in %.2f secs: ", total, g_test_timer_last());
>  g_print("%.2f MB/sec\n", total / g_test_timer_last());
>  
> @@ -74,7 +74,7 @@ int main(int argc, char **argv)
>  
>  for (i = 512; i <= (64 * 1204); i *= 2) {
>  memset(name, 0 , sizeof(name));
> -snprintf(name, sizeof(name), "/crypto/hmac/speed-%lu", i);
> +snprintf(name, sizeof(name), "/crypto/hmac/speed-%zu", i);
>  g_test_add_data_func(name, (void *)i, test_hmac_speed);
>  }
>  


-- 
Regards,
Longpeng(Mike)




Re: [Qemu-devel] [PATCH 5/9] IDE: replace DEBUG_AIO with trace events

2017-08-28 Thread John Snow


On 08/25/2017 09:46 AM, Philippe Mathieu-Daudé wrote:
> Hi John,
> 
> On 08/08/2017 03:33 PM, John Snow wrote:
>> Signed-off-by: John Snow 
>> ---
>>   hw/ide/atapi.c|  5 +
>>   hw/ide/core.c | 17 ++---
>>   hw/ide/trace-events   |  3 +++
>>   include/hw/ide/internal.h |  7 +--
>>   4 files changed, 19 insertions(+), 13 deletions(-)
>>
>> diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
>> index 37fa699..b8fc51e 100644
>> --- a/hw/ide/atapi.c
>> +++ b/hw/ide/atapi.c
>> @@ -416,10 +416,7 @@ static void ide_atapi_cmd_read_dma_cb(void
>> *opaque, int ret)
>>   s->io_buffer_size = n * 2048;
>>   data_offset = 0;
>>   }
>> -#ifdef DEBUG_AIO
>> -printf("aio_read_cd: lba=%u n=%d\n", s->lba, n);
>> -#endif
>> -
>> +trace_ide_atapi_cmd_read_dma_cb_aio(s, s->lba, n);
>>   s->bus->dma->iov.iov_base = (void *)(s->io_buffer + data_offset);
>>   s->bus->dma->iov.iov_len = n * ATAPI_SECTOR_SIZE;
>>   qemu_iovec_init_external(>bus->dma->qiov, >bus->dma->iov, 1);
>> diff --git a/hw/ide/core.c b/hw/ide/core.c
>> index 29848ff..1358029 100644
>> --- a/hw/ide/core.c
>> +++ b/hw/ide/core.c
>> @@ -58,6 +58,13 @@ static const int smart_attributes[][12] = {
>>   { 190,  0x03, 0x00, 0x45, 0x45, 0x1f, 0x00, 0x1f, 0x1f, 0x00,
>> 0x00, 0x32},
>>   };
>>   +const char *IDE_DMA_CMD_lookup[IDE_DMA__END] = {
>> +[IDE_DMA_READ] = "DMA_READ",
>> +[IDE_DMA_WRITE] = "DMA_WRITE",
>> +[IDE_DMA_TRIM] = "DMA TRIM",
>> +[IDE_DMA_ATAPI] = "DMA ATAPI"
>> +};
>> +
>>   static void ide_dummy_transfer_stop(IDEState *s);
>> static void padstr(char *str, const char *src, int len)
>> @@ -860,10 +867,8 @@ static void ide_dma_cb(void *opaque, int ret)
>>   goto eot;
>>   }
>>   -#ifdef DEBUG_AIO
>> -printf("ide_dma_cb: sector_num=%" PRId64 " n=%d, cmd_cmd=%d\n",
>> -   sector_num, n, s->dma_cmd);
>> -#endif
>> +trace_ide_dma_cb(s, sector_num, n,
>> + IDE_DMA_CMD_lookup[s->dma_cmd]);
>> if ((s->dma_cmd == IDE_DMA_READ || s->dma_cmd ==
>> IDE_DMA_WRITE) &&
>>   !ide_sect_range_ok(s, sector_num, n)) {
>> @@ -2383,9 +2388,7 @@ void ide_bus_reset(IDEBus *bus)
>> /* pending async DMA */
>>   if (bus->dma->aiocb) {
>> -#ifdef DEBUG_AIO
>> -printf("aio_cancel\n");
>> -#endif
>> +trace_ide_bus_reset_aio();
>>   blk_aio_cancel(bus->dma->aiocb);
>>   bus->dma->aiocb = NULL;
>>   }
>> diff --git a/hw/ide/trace-events b/hw/ide/trace-events
>> index ade1e76..6e33cb3 100644
>> --- a/hw/ide/trace-events
>> +++ b/hw/ide/trace-events
>> @@ -17,6 +17,8 @@ ide_cancel_dma_sync_remaining(void) "draining all
>> remaining requests"
>>   ide_sector_read(int64_t sector_num, int nsectors) "sector=%"PRId64"
>> nsectors=%d"
>>   ide_sector_write(int64_t sector_num, int nsectors) "sector=%"PRId64"
>> nsectors=%d"
>>   ide_reset(void *s) "IDEstate %p"
>> +ide_bus_reset_aio(void) "aio_cancel"
>> +ide_dma_cb(void *s, int64_t sector_num, int n, const char *dma)
>> "IDEState %p; sector_num=%"PRId64" n=%d cmd=%s"
>> # hw/ide/pci.c
>>   bmdma_reset(void) ""
>> @@ -48,5 +50,6 @@ ide_atapi_cmd_reply_end_new(void *s, int status)
>> "IDEState: %p; new transfer sta
>>   ide_atapi_cmd_check_status(void *s) "IDEState: %p"
>>   ide_atapi_cmd_read(void *s, const char *method, int lba, int
>> nb_sectors) "IDEState: %p; read %s: LBA=%d nb_sectors=%d"
>>   ide_atapi_cmd(void *s, uint8_t cmd) "IDEState: %p; cmd: 0x%02x"
>> +ide_atapi_cmd_read_dma_cb_aio(void *s, int lba, int n) "IDEState: %p;
>> aio read: lba=%d n=%d"
>>   # Warning: Verbose
>>   ide_atapi_cmd_packet(void *s, uint16_t limit, const char *packet)
>> "IDEState: %p; limit=0x%x packet: %s"
>> \ No newline at end of file
>> diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h
>> index 74efe8a..97e97a2 100644
>> --- a/include/hw/ide/internal.h
>> +++ b/include/hw/ide/internal.h
>> @@ -14,7 +14,6 @@
>>   #include "block/scsi.h"
>> /* debug IDE devices */
>> -//#define DEBUG_AIO
>>   #define USE_DMA_CDROM
>> typedef struct IDEBus IDEBus;
>> @@ -333,12 +332,16 @@ struct unreported_events {
>>   };
>> enum ide_dma_cmd {
>> -IDE_DMA_READ,
>> +IDE_DMA__BEGIN = 0,
>> +IDE_DMA_READ = IDE_DMA__BEGIN,
> 
> not that useful, you can use directly:
> 
> IDE_DMA_READ = 0,
> 

I could do lots of things; one of the things I like to do out of habit
is to name an enumerator after the beginning so that if I were to ever
loop over the items contained within, I can write a loop that looks like
this:

for (i = IDE_DMA__BEGIN; i < IDE_DMA__END; i++) {
...foo...;
}

instead of having to name a specific constant in the beginning.

Why?

Because, heaven help us, someone reorders the enum for whatever reason,
the program is still going to compile and nobody will notice this change
halfway across the globe.

Having a distinct __START __END (or even COUNT as you suggest) clues us
in to 

[Qemu-devel] [PATCH 07/79] iotests/051: Add test for empty filename

2017-08-28 Thread Michael Roth
From: Max Reitz 

Signed-off-by: Max Reitz 
Reviewed-by: Eric Blake 
Reviewed-by: Fam Zheng 
Signed-off-by: Kevin Wolf 
(cherry picked from commit 42dc10f17a7f1754d419e715114c37f5c5fde12f)
Signed-off-by: Michael Roth 
---
 tests/qemu-iotests/051| 1 +
 tests/qemu-iotests/051.out| 3 +++
 tests/qemu-iotests/051.pc.out | 3 +++
 3 files changed, 7 insertions(+)

diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051
index 630cb7a..4fe6760 100755
--- a/tests/qemu-iotests/051
+++ b/tests/qemu-iotests/051
@@ -231,6 +231,7 @@ echo === Leaving out required options ===
 echo
 
 run_qemu -drive driver=file
+run_qemu -drive driver=file,filename=
 run_qemu -drive driver=nbd
 run_qemu -drive driver=raw
 run_qemu -drive file.driver=file
diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out
index 7524c62..57bee08 100644
--- a/tests/qemu-iotests/051.out
+++ b/tests/qemu-iotests/051.out
@@ -221,6 +221,9 @@ QEMU X.Y.Z monitor - type 'help' for more information
 Testing: -drive driver=file
 QEMU_PROG: -drive driver=file: The 'file' block driver requires a file name
 
+Testing: -drive driver=file,filename=
+QEMU_PROG: -drive driver=file,filename=: The 'file' block driver requires a 
file name
+
 Testing: -drive driver=nbd
 QEMU_PROG: -drive driver=nbd: NBD server address missing
 
diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out
index c6f4eef..19426e5 100644
--- a/tests/qemu-iotests/051.pc.out
+++ b/tests/qemu-iotests/051.pc.out
@@ -319,6 +319,9 @@ QEMU X.Y.Z monitor - type 'help' for more information
 Testing: -drive driver=file
 QEMU_PROG: -drive driver=file: The 'file' block driver requires a file name
 
+Testing: -drive driver=file,filename=
+QEMU_PROG: -drive driver=file,filename=: The 'file' block driver requires a 
file name
+
 Testing: -drive driver=nbd
 QEMU_PROG: -drive driver=nbd: NBD server address missing
 
-- 
2.7.4




Re: [Qemu-devel] [PATCH] tests: fix incorrect size_t format in benchmark-crypto

2017-08-28 Thread Longpeng (Mike)


On 2017/8/29 8:21, Longpeng (Mike) wrote:

> 
> 
> On 2017/8/28 19:37, Philippe Mathieu-Daudé wrote:
> 
>>   $ make check-speed
>>   tests/benchmark-crypto-hash.c: In function 'test_hash_speed':
>>   tests/benchmark-crypto-hash.c:44:5: error: format '%ld' expects argument 
>> of type 'long int', but argument 2 has type 'size_t' [-Werror=format=]
>>g_print("Testing chunk_size %ld bytes ", chunk_size);
>>^
>>   tests/benchmark-crypto-hash.c: In function 'main':
>>   tests/benchmark-crypto-hash.c:62:9: error: format '%lu' expects argument 
>> of type 'long unsigned int', but argument 4 has type 'size_t' 
>> [-Werror=format=]
>>snprintf(name, sizeof(name), "/crypto/hash/speed-%lu", i);
>>^
>>   cc1: all warnings being treated as errors
>>   rules.mak:66: recipe for target 'tests/benchmark-crypto-hash.o' failed
>>   make: *** [tests/benchmark-crypto-hash.o] Error 1
>>
>> Signed-off-by: Philippe Mathieu-Daudé 
> 
> 
> Reviewed-by: Longpeng(Mike) 
> 


Sorry, s/@/2/

Reviewed-by: Longpeng(Mike) 

>> ---
>> testing v2.10.0-rc4
>>
>>  tests/benchmark-crypto-cipher.c | 4 ++--
>>  tests/benchmark-crypto-hash.c   | 4 ++--
>>  tests/benchmark-crypto-hmac.c   | 4 ++--
>>  3 files changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/tests/benchmark-crypto-cipher.c 
>> b/tests/benchmark-crypto-cipher.c
>> index c6a40929e4..cf98443468 100644
>> --- a/tests/benchmark-crypto-cipher.c
>> +++ b/tests/benchmark-crypto-cipher.c
>> @@ -59,7 +59,7 @@ static void test_cipher_speed(const void *opaque)
>>  total /= 1024 * 1024; /* to MB */
>>  
>>  g_print("cbc(aes128): ");
>> -g_print("Testing chunk_size %ld bytes ", chunk_size);
>> +g_print("Testing chunk_size %zu bytes ", chunk_size);
>>  g_print("done: %.2f MB in %.2f secs: ", total, g_test_timer_last());
>>  g_print("%.2f MB/sec\n", total / g_test_timer_last());
>>  
>> @@ -80,7 +80,7 @@ int main(int argc, char **argv)
>>  
>>  for (i = 512; i <= (64 * 1204); i *= 2) {
>>  memset(name, 0 , sizeof(name));
>> -snprintf(name, sizeof(name), "/crypto/cipher/speed-%lu", i);
>> +snprintf(name, sizeof(name), "/crypto/cipher/speed-%zu", i);
>>  g_test_add_data_func(name, (void *)i, test_cipher_speed);
>>  }
>>  
>> diff --git a/tests/benchmark-crypto-hash.c b/tests/benchmark-crypto-hash.c
>> index 6769d2a11b..122bfb6b85 100644
>> --- a/tests/benchmark-crypto-hash.c
>> +++ b/tests/benchmark-crypto-hash.c
>> @@ -41,7 +41,7 @@ static void test_hash_speed(const void *opaque)
>>  
>>  total /= 1024 * 1024; /* to MB */
>>  g_print("sha256: ");
>> -g_print("Testing chunk_size %ld bytes ", chunk_size);
>> +g_print("Testing chunk_size %zu bytes ", chunk_size);
>>  g_print("done: %.2f MB in %.2f secs: ", total, g_test_timer_last());
>>  g_print("%.2f MB/sec\n", total / g_test_timer_last());
>>  
>> @@ -59,7 +59,7 @@ int main(int argc, char **argv)
>>  
>>  for (i = 512; i <= (64 * 1204); i *= 2) {
>>  memset(name, 0 , sizeof(name));
>> -snprintf(name, sizeof(name), "/crypto/hash/speed-%lu", i);
>> +snprintf(name, sizeof(name), "/crypto/hash/speed-%zu", i);
>>  g_test_add_data_func(name, (void *)i, test_hash_speed);
>>  }
>>  
>> diff --git a/tests/benchmark-crypto-hmac.c b/tests/benchmark-crypto-hmac.c
>> index 72408be987..c30250df3e 100644
>> --- a/tests/benchmark-crypto-hmac.c
>> +++ b/tests/benchmark-crypto-hmac.c
>> @@ -56,7 +56,7 @@ static void test_hmac_speed(const void *opaque)
>>  total /= 1024 * 1024; /* to MB */
>>  
>>  g_print("hmac(sha256): ");
>> -g_print("Testing chunk_size %ld bytes ", chunk_size);
>> +g_print("Testing chunk_size %zu bytes ", chunk_size);
>>  g_print("done: %.2f MB in %.2f secs: ", total, g_test_timer_last());
>>  g_print("%.2f MB/sec\n", total / g_test_timer_last());
>>  
>> @@ -74,7 +74,7 @@ int main(int argc, char **argv)
>>  
>>  for (i = 512; i <= (64 * 1204); i *= 2) {
>>  memset(name, 0 , sizeof(name));
>> -snprintf(name, sizeof(name), "/crypto/hmac/speed-%lu", i);
>> +snprintf(name, sizeof(name), "/crypto/hmac/speed-%zu", i);
>>  g_test_add_data_func(name, (void *)i, test_hmac_speed);
>>  }
>>  
> 
> 


-- 
Regards,
Longpeng(Mike)




Re: [Qemu-devel] Persistent bitmaps for non-qcow2 formats

2017-08-28 Thread John Snow


On 08/25/2017 09:44 AM, Max Reitz wrote:
> On 2017-08-25 02:55, John Snow wrote:
>> Sorry in advance for :words: ...
>>
>> On 08/23/2017 02:04 PM, Vladimir Sementsov-Ogievskiy wrote:
>>> 23.08.2017 11:59, Vladimir Sementsov-Ogievskiy wrote:
 22.08.2017 22:07, John Snow wrote:

[snip]


 Should there be some problems with internal snapshots and other things?
> 
> I'd suspect you get exactly the same problems when using internal
> snapshots together with backing files.  Imagine a newly created overlay
> file and taking a snapshot.  This should give you exactly the same
> issue, doesn't it?
> 



>>> Hm. looks like that this backing file should not only receive all reads
>>> and writes, but almost everything ->bdrv_ handlers, except bitmap
>>> related of course.
> 
> How so?  Shouldn't it just work like a backing file, except it also
> receives writes instead of just reads?
> 
>>>This doesn't seems simple to implement. Especially if
>>> imaging some not-raw feature-full format under this thin qcow2 layer..
>>> Or we can restrict this RW backing file to be raw-only?
>>>
>>>
>>
>> The idea would really be to support any arbitrary data store, so I
>> wouldn't want to restrict it to just raw.
>>
>> You're right though, this might be a kind of messy approach.
>>
>> [From your other mail:]
>>
>>>
>>> So, anyway, I see only two differences (from the outside) between this 
>>> approach and just a separate bitmap-only qcow2 without a data:
>>>
>>
>> It's very delicately similar, yes.
>>
>>> 1. in RW-backing approach qcow2-bitmap file has a link to data file (as a 
>>> backing). It looks good.
> 
> And this is rather important to me.
> 

Good to know. Some good solid opinions to work around. ;)

>> Right. The information necessary to establish a link between the bitmap
>> data and the data being described is fully contained within a file fully
>> specified by the QCOW2 spec.
>>
>>> 2. in RW-backing approach qcow2-bitmap file is a top of the virtual disk, 
>>> in separate-file approach it is an option of the real data drive. In my 
>>> opinion the second is more clean for users ("to add this feature you should 
>>> use other file as your disk" vs "to add this feature you should add an 
>>> option to your disk description")
> 
> I'd argue it's rather: "You cannot use this feature unless your format
> supports it.  The only format supporting persistent bitmaps currently is
> qcow2.  To use persistent bitmaps with other formats you can attach them
> as R/W backing files to an empty qcow2 file, though."
> 
> So the difference is that you are saying it's a feature that is added to
> a non-qcow2 image whereas I'm saying it's a feature that only a qcow2
> image can provide (currently).
> 
>> This puts us a little closer to the original idea that was rejected by
>> Kevin at the time. To recap:
>>
>> "1": Use qcow2 as a container. This was rejected because we didn't want
>> qcow2 containing data with no semantic relationship to the qcow2
>> container or to each other. The way it sounds like you're proposing it,
>> though, it would be one-qcow2-with-bitmaps-per-drive, so the data would
>> at least stay strictly related, but it would be meaningless outside of
>> QEMU itself. I think this is something that Kevin wanted to avoid, but I
>> can't speak for him.
>>
>> It's certainly not beyond the realm of management software to remember
>> to correlate a qcow2 metadata file alongside its actual data stores
>> whenever it needed to do so, but it does mean the introduction of a
>> feature that essentially requires the use of management software, which
>> sees resistance in the community at times.
>>
>> In this model, you'd probably have the raw drive at the top, with the
>> qcow2-with-bitmaps as a child node with some kind of new named child
>> relationship. All IO stays at the root node, but the bitmap method
>> handlers would know to look for this special bitmap-child. It shouldn't
>> be too hard to implement.
> 
> I'd still like to throw in how much I dislike this approach, and I can't
> really think of a way to make it palatable to me.  Not even "just write
> the file name of the image the bitmaps cover into the qcow2 file" sounds
> good to me, because then it still is basically unrelated data.
> 

Understood. It's something I'd like to avoid too, but I have some real
concerns about implementation of that semantic link.

> The only approach that I might see myself liking is to indeed add a flag
> or whatever to say a qcow2 backing image is supposed to be R/W; and then
> (after somehow verifying that the qcow2 image itself is empty) just make
> qemu interpret this as "load the backing file as the real disk and
> attach the qcow2 image as a 'metadata' child" or whatever.  But I fear
> this gets uglier and uglier because how qemu loads the files will then
> depend on whether the overlay is empty or not, and this may be very
> confusing.
> 

Right, it makes opening a little more convoluted 

[Qemu-devel] [PATCH 77/79] hw/i386: allow SHPC for Q35 machine

2017-08-28 Thread Michael Roth
From: Aleksandr Bezzubikov 

Unmask previously masked SHPC feature in _OSC method.

Signed-off-by: Aleksandr Bezzubikov 
Reviewed-by: Marcel Apfelbaum 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
(cherry picked from commit a41c78c135eb1850826e96b2154690323ff66719)
Signed-off-by: Michael Roth 
---
 hw/i386/acpi-build.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 2073108..76fa455 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1818,9 +1818,9 @@ static Aml *build_q35_osc_method(void)
 
 /*
  * Always allow native PME, AER (no dependencies)
- * Never allow SHPC (no SHPC controller in this system)
+ * Allow SHPC (PCI bridges can have SHPC controller)
  */
-aml_append(if_ctx, aml_and(a_ctrl, aml_int(0x1D), a_ctrl));
+aml_append(if_ctx, aml_and(a_ctrl, aml_int(0x1F), a_ctrl));
 
 if_ctx2 = aml_if(aml_lnot(aml_equal(aml_arg(1), aml_int(1;
 /* Unknown revision */
-- 
2.7.4




[Qemu-devel] [PATCH 78/79] block/nfs: fix mutex assertion in nfs_file_close()

2017-08-28 Thread Michael Roth
From: Jeff Cody 

Commit c096358e747e88fc7364e40e3c354ee0bb683960 introduced assertion
checks for when qemu_mutex() functions are called without the
corresponding qemu_mutex_init() having initialized the mutex.

This uncovered a latent bug in qemu's nfs driver - in
nfs_client_close(), the NFSClient structure is overwritten with zeros,
prior to the mutex being destroyed.

Go ahead and destroy the mutex in nfs_client_close(), and change where
we call qemu_mutex_init() so that it is correctly balanced.

There are also a couple of memory leaks obscured by the memset, so this
fixes those as well.

Finally, we should be able to get rid of the memset(), as it isn't
necessary.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Jeff Cody 
Reviewed-by: Peter Lieven 
Reviewed-by: Stefan Hajnoczi 
Reviewed-by: John Snow 
Signed-off-by: Kevin Wolf 
(cherry picked from commit 113fe792fd4931dd0538f03859278b8719ee4fa2)
Signed-off-by: Michael Roth 
---
 block/nfs.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/block/nfs.c b/block/nfs.c
index 344186f..7e1bea1 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -434,19 +434,23 @@ static void nfs_client_close(NFSClient *client)
 if (client->context) {
 if (client->fh) {
 nfs_close(client->context, client->fh);
+client->fh = NULL;
 }
 aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context),
false, NULL, NULL, NULL, NULL);
 nfs_destroy_context(client->context);
+client->context = NULL;
 }
-memset(client, 0, sizeof(NFSClient));
+g_free(client->path);
+qemu_mutex_destroy(>mutex);
+qapi_free_NFSServer(client->server);
+client->server = NULL;
 }
 
 static void nfs_file_close(BlockDriverState *bs)
 {
 NFSClient *client = bs->opaque;
 nfs_client_close(client);
-qemu_mutex_destroy(>mutex);
 }
 
 static NFSServer *nfs_config(QDict *options, Error **errp)
@@ -499,6 +503,7 @@ static int64_t nfs_client_open(NFSClient *client, QDict 
*options,
 struct stat st;
 char *file = NULL, *strp = NULL;
 
+qemu_mutex_init(>mutex);
 opts = qemu_opts_create(_opts, NULL, 0, _abort);
 qemu_opts_absorb_qdict(opts, options, _err);
 if (local_err) {
@@ -661,7 +666,7 @@ static int nfs_file_open(BlockDriverState *bs, QDict 
*options, int flags,
 if (ret < 0) {
 return ret;
 }
-qemu_mutex_init(>mutex);
+
 bs->total_sectors = ret;
 ret = 0;
 return ret;
-- 
2.7.4




[Qemu-devel] [PATCH 08/79] migration: setup bi-directional I/O channel for exec: protocol

2017-08-28 Thread Michael Roth
From: "Daniel P. Berrange" 

Historically the migration data channel has only needed to be
unidirectional. Thus the 'exec:' protocol was requesting an
I/O channel with O_RDONLY on incoming side, and O_WRONLY on
the outgoing side.

This is fine for classic migration, but if you then try to run
TLS over it, this fails because the TLS handshake requires a
bi-directional channel.

Signed-off-by: Daniel P. Berrange 
Reviewed-by: Juan Quintela 
Signed-off-by: Juan Quintela 
(cherry picked from commit 062d81f0e968fe1597474735f3ea038065027372)
Signed-off-by: Michael Roth 
---
 migration/exec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/migration/exec.c b/migration/exec.c
index 9157721..aba9089 100644
--- a/migration/exec.c
+++ b/migration/exec.c
@@ -32,7 +32,7 @@ void exec_start_outgoing_migration(MigrationState *s, const 
char *command, Error
 
 trace_migration_exec_outgoing(command);
 ioc = QIO_CHANNEL(qio_channel_command_new_spawn(argv,
-O_WRONLY,
+O_RDWR,
 errp));
 if (!ioc) {
 return;
@@ -59,7 +59,7 @@ void exec_start_incoming_migration(const char *command, Error 
**errp)
 
 trace_migration_exec_incoming(command);
 ioc = QIO_CHANNEL(qio_channel_command_new_spawn(argv,
-O_RDONLY,
+O_RDWR,
 errp));
 if (!ioc) {
 return;
-- 
2.7.4




[Qemu-devel] [PATCH 75/79] block: Skip implicit nodes in query-block/blockstats

2017-08-28 Thread Michael Roth
From: Kevin Wolf 

Commits 0db832f and 6cdbceb introduced the automatic insertion of filter
nodes above the top layer of mirror and commit block jobs. The
assumption made there was that since libvirt doesn't do node-level
management of the block layer yet, it shouldn't be affected by added
nodes.

This is true as far as commands issued by libvirt are concerned. It only
uses BlockBackend names to address nodes, so any operations it performs
still operate on the root of the tree as intended.

However, the assumption breaks down when you consider query commands,
which return data for the wrong node now. These commands also return
information on some child nodes (bs->file and/or bs->backing), which
libvirt does make use of, and which refer to the wrong nodes, too.

One of the consequences is that oVirt gets wrong information about the
image size and stops the VM in response as long as a mirror or commit
job is running:

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

This patch fixes the problem by hiding the implicit nodes created
automatically by the mirror and commit block jobs in the output of
query-block and BlockBackend-based query-blockstats as long as the user
doesn't indicate that they are aware of those nodes by providing a node
name for them in the QMP command to start the block job.

The node-based commands query-named-block-nodes and query-blockstats
with query-nodes=true still show all nodes, including implicit ones.
This ensures that users that are capable of node-level management can
still access the full information; users that only know BlockBackends
won't use these commands.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Kevin Wolf 
Reviewed-by: Peter Krempa 
Reviewed-by: Max Reitz 
Tested-by: Eric Blake 
(cherry picked from commit d3c8c67469ee70fcae116d5abc277a7ebc8a19fd)
 Conflicts:
block/qapi.c
include/block/block_int.h
* fix context deps on 46eade7b and 5a9347c6
Signed-off-by: Michael Roth 
---
 block.c| 13 -
 block/commit.c |  3 +++
 block/mirror.c |  3 +++
 block/qapi.c   | 34 --
 include/block/block.h  |  1 -
 include/block/block_int.h  |  1 +
 qapi/block-core.json   |  6 --
 tests/qemu-iotests/040 | 30 +-
 tests/qemu-iotests/040.out |  4 ++--
 tests/qemu-iotests/041 | 38 +-
 tests/qemu-iotests/041.out |  4 ++--
 11 files changed, 109 insertions(+), 28 deletions(-)

diff --git a/block.c b/block.c
index 21cb65e..46ea4a3 100644
--- a/block.c
+++ b/block.c
@@ -3863,19 +3863,6 @@ BlockDriverState 
*bdrv_find_backing_image(BlockDriverState *bs,
 return retval;
 }
 
-int bdrv_get_backing_file_depth(BlockDriverState *bs)
-{
-if (!bs->drv) {
-return 0;
-}
-
-if (!bs->backing) {
-return 0;
-}
-
-return 1 + bdrv_get_backing_file_depth(bs->backing->bs);
-}
-
 void bdrv_init(void)
 {
 module_call_init(MODULE_INIT_BLOCK);
diff --git a/block/commit.c b/block/commit.c
index 66e3418..b4c1be7 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -351,6 +351,9 @@ void commit_start(const char *job_id, BlockDriverState *bs,
 if (commit_top_bs == NULL) {
 goto fail;
 }
+if (!filter_node_name) {
+commit_top_bs->implicit = true;
+}
 commit_top_bs->total_sectors = top->total_sectors;
 bdrv_set_aio_context(commit_top_bs, bdrv_get_aio_context(top));
 
diff --git a/block/mirror.c b/block/mirror.c
index 4e8f124..9bf5f89 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -1152,6 +1152,9 @@ static void mirror_start_job(const char *job_id, 
BlockDriverState *bs,
 if (mirror_top_bs == NULL) {
 return;
 }
+if (!filter_node_name) {
+mirror_top_bs->implicit = true;
+}
 mirror_top_bs->total_sectors = bs->total_sectors;
 bdrv_set_aio_context(mirror_top_bs, bdrv_get_aio_context(bs));
 
diff --git a/block/qapi.c b/block/qapi.c
index a40922e..803205b 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -64,7 +64,6 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
 info->backing_file = g_strdup(bs->backing_file);
 }
 
-info->backing_file_depth = bdrv_get_backing_file_depth(bs);
 info->detect_zeroes = bs->detect_zeroes;
 
 if (blk && blk_get_public(blk)->throttle_state) {
@@ -125,6 +124,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
 
 bs0 = bs;
 p_image_info = >image;
+info->backing_file_depth = 0;
 while (1) {
 Error *local_err = NULL;
 bdrv_query_image_info(bs0, p_image_info, _err);
@@ -133,13 +133,21 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
 qapi_free_BlockDeviceInfo(info);
 return NULL;
 }
+
 if (bs0->drv && bs0->backing) {
+

Re: [Qemu-devel] [PATCH 9/9] AHCI: remove DPRINTF macro

2017-08-28 Thread John Snow


On 08/25/2017 09:48 AM, Philippe Mathieu-Daudé wrote:
> On 08/08/2017 03:33 PM, John Snow wrote:
>> Signed-off-by: John Snow 
> 
> Reviewed-by: Philippe Mathieu-Daudé 
> 

:)

I'll wait on V2 to hear back. Thank you for your feedback so far.



[Qemu-devel] [PATCH 76/79] cpu: don't allow negative core id

2017-08-28 Thread Michael Roth
From: Laurent Vivier 

With pseries machine type a negative core-id is not managed properly:
-1 gives an inaccurate error message ("core -1 already populated"),
-2 crashes QEMU (core dump)

As it seems a negative value is invalid for any architecture,
instead of checking this in spapr_core_pre_plug() I think it's better
to check this in the generic part, core_prop_set_core_id()

Signed-off-by: Laurent Vivier 
Message-Id: <20170802103259.25940-1-lviv...@redhat.com>
Reviewed-by: Greg Kurz 
Reviewed-by: David Gibson 
Reviewed-by: Eduardo Habkost 
Signed-off-by: Eduardo Habkost 
(cherry picked from commit be2960baae07e5257cde8c814cbd91647e235147)
Signed-off-by: Michael Roth 
---
 hw/cpu/core.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/hw/cpu/core.c b/hw/cpu/core.c
index 2bf960d..bd578ab 100644
--- a/hw/cpu/core.c
+++ b/hw/cpu/core.c
@@ -33,6 +33,11 @@ static void core_prop_set_core_id(Object *obj, Visitor *v, 
const char *name,
 return;
 }
 
+if (value < 0) {
+error_setg(errp, "Invalid core id %"PRId64, value);
+return;
+}
+
 core->core_id = value;
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH 74/79] qemu-iotests: Test automatic commit job cancel on hot unplug

2017-08-28 Thread Michael Roth
From: Kevin Wolf 

Signed-off-by: Kevin Wolf 
Reviewed-by: John Snow 
(cherry picked from commit c3971b883a596abc6af45f53d2f43fb2f59ccd3b)
*prereq for d3c8c674
Signed-off-by: Michael Roth 
---
 tests/qemu-iotests/040 | 35 +--
 tests/qemu-iotests/040.out |  4 ++--
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040
index 5bdaf3d..9d381d9 100755
--- a/tests/qemu-iotests/040
+++ b/tests/qemu-iotests/040
@@ -70,7 +70,9 @@ class ImageCommitTestCase(iotests.QMPTestCase):
 self.wait_for_complete()
 
 class TestSingleDrive(ImageCommitTestCase):
-image_len = 1 * 1024 * 1024
+# Need some space after the copied data so that throttling is effective in
+# tests that use it rather than just completing the job immediately
+image_len = 2 * 1024 * 1024
 test_len = 1 * 1024 * 256
 
 def setUp(self):
@@ -79,7 +81,9 @@ class TestSingleDrive(ImageCommitTestCase):
 qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % 
mid_img, test_img)
 qemu_io('-f', 'raw', '-c', 'write -P 0xab 0 524288', backing_img)
 qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', 
mid_img)
-self.vm = iotests.VM().add_drive(test_img)
+self.vm = iotests.VM().add_drive(test_img, interface="none")
+self.vm.add_device("virtio-scsi-pci")
+self.vm.add_device("scsi-hd,id=scsi0,drive=drive0")
 self.vm.launch()
 
 def tearDown(self):
@@ -131,6 +135,33 @@ class TestSingleDrive(ImageCommitTestCase):
 self.assert_qmp(result, 'error/class', 'GenericError')
 self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % 
mid_img)
 
+# When the job is running on a BB that is automatically deleted on hot
+# unplug, the job is cancelled when the device disappears
+def test_hot_unplug(self):
+if self.image_len == 0:
+return
+
+self.assert_no_active_block_jobs()
+result = self.vm.qmp('block-commit', device='drive0', top=mid_img,
+ base=backing_img, speed=(self.image_len / 4))
+self.assert_qmp(result, 'return', {})
+result = self.vm.qmp('device_del', id='scsi0')
+self.assert_qmp(result, 'return', {})
+
+cancelled = False
+deleted = False
+while not cancelled or not deleted:
+for event in self.vm.get_qmp_events(wait=True):
+if event['event'] == 'DEVICE_DELETED':
+self.assert_qmp(event, 'data/device', 'scsi0')
+deleted = True
+elif event['event'] == 'BLOCK_JOB_CANCELLED':
+self.assert_qmp(event, 'data/device', 'drive0')
+cancelled = True
+else:
+self.fail("Unexpected event %s" % (event['event']))
+
+self.assert_no_active_block_jobs()
 
 class TestRelativePaths(ImageCommitTestCase):
 image_len = 1 * 1024 * 1024
diff --git a/tests/qemu-iotests/040.out b/tests/qemu-iotests/040.out
index 4fd1c2d..6d9bee1 100644
--- a/tests/qemu-iotests/040.out
+++ b/tests/qemu-iotests/040.out
@@ -1,5 +1,5 @@
-.
+...
 --
-Ran 25 tests
+Ran 27 tests
 
 OK
-- 
2.7.4




[Qemu-devel] [PATCH 06/79] block: An empty filename counts as no filename

2017-08-28 Thread Michael Roth
From: Max Reitz 

Reproducer:
$ ./qemu-img info ''
qemu-img: ./block.c:1008: bdrv_open_driver: Assertion
`!drv->bdrv_needs_filename || bs->filename[0]' failed.
[1]26105 abort (core dumped)  ./qemu-img info ''

This patch fixes this to be:
$ ./qemu-img info ''
qemu-img: Could not open '': The 'file' block driver requires a file
name

Cc: qemu-stable 
Signed-off-by: Max Reitz 
Reviewed-by: Eric Blake 
Reviewed-by: Fam Zheng 
Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Kevin Wolf 
(cherry picked from commit 4a0082401a770261b85625a41eef4a4e89ad7a74)
Signed-off-by: Michael Roth 
---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block.c b/block.c
index 1fbbb8d..46da908 100644
--- a/block.c
+++ b/block.c
@@ -1167,7 +1167,7 @@ static int bdrv_open_common(BlockDriverState *bs, 
BlockBackend *file,
 filename = qdict_get_try_str(options, "filename");
 }
 
-if (drv->bdrv_needs_filename && !filename) {
+if (drv->bdrv_needs_filename && (!filename || !filename[0])) {
 error_setg(errp, "The '%s' block driver requires a file name",
drv->format_name);
 ret = -EINVAL;
-- 
2.7.4




[Qemu-devel] [PATCH 79/79] 9pfs: local: fix fchmodat_nofollow() limitations

2017-08-28 Thread Michael Roth
From: Greg Kurz 

This function has to ensure it doesn't follow a symlink that could be used
to escape the virtfs directory. This could be easily achieved if fchmodat()
on linux honored the AT_SYMLINK_NOFOLLOW flag as described in POSIX, but
it doesn't. There was a tentative to implement a new fchmodat2() syscall
with the correct semantics:

https://patchwork.kernel.org/patch/9596301/

but it didn't gain much momentum. Also it was suggested to look at an O_PATH
based solution in the first place.

The current implementation covers most use-cases, but it notably fails if:
- the target path has access rights equal to  (openat() returns EPERM),
  => once you've done chmod() on a file, you can never chmod() again
- the target path is UNIX domain socket (openat() returns ENXIO)
  => bind() of UNIX domain sockets fails if the file is on 9pfs

The solution is to use O_PATH: openat() now succeeds in both cases, and we
can ensure the path isn't a symlink with fstat(). The associated entry in
"/proc/self/fd" can hence be safely passed to the regular chmod() syscall.

The previous behavior is kept for older systems that don't have O_PATH.

Signed-off-by: Greg Kurz 
Reviewed-by: Eric Blake 
Tested-by: Zhi Yong Wu 
Acked-by: Philippe Mathieu-Daudé 
(cherry picked from commit 4751fd5328dfcd4fe2f9055728a72a0e3ae56512)
Signed-off-by: Michael Roth 
---
 hw/9pfs/9p-local.c | 42 +++---
 hw/9pfs/9p-util.h  | 24 +++-
 2 files changed, 50 insertions(+), 16 deletions(-)

diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index b13ff21..a83dbfb 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -278,17 +278,27 @@ update_map_file:
 
 static int fchmodat_nofollow(int dirfd, const char *name, mode_t mode)
 {
+struct stat stbuf;
 int fd, ret;
 
 /* FIXME: this should be handled with fchmodat(AT_SYMLINK_NOFOLLOW).
- * Unfortunately, the linux kernel doesn't implement it yet. As an
- * alternative, let's open the file and use fchmod() instead. This
- * may fail depending on the permissions of the file, but it is the
- * best we can do to avoid TOCTTOU. We first try to open read-only
- * in case name points to a directory. If that fails, we try write-only
- * in case name doesn't point to a directory.
+ * Unfortunately, the linux kernel doesn't implement it yet.
  */
-fd = openat_file(dirfd, name, O_RDONLY, 0);
+
+ /* First, we clear non-racing symlinks out of the way. */
+if (fstatat(dirfd, name, , AT_SYMLINK_NOFOLLOW)) {
+return -1;
+}
+if (S_ISLNK(stbuf.st_mode)) {
+errno = ELOOP;
+return -1;
+}
+
+/* Access modes are ignored when O_PATH is supported. We try O_RDONLY and
+ * O_WRONLY for old-systems that don't support O_PATH.
+ */
+fd = openat_file(dirfd, name, O_RDONLY | O_PATH_9P_UTIL, 0);
+#if O_PATH_9P_UTIL == 0
 if (fd == -1) {
 /* In case the file is writable-only and isn't a directory. */
 if (errno == EACCES) {
@@ -302,6 +312,24 @@ static int fchmodat_nofollow(int dirfd, const char *name, 
mode_t mode)
 return -1;
 }
 ret = fchmod(fd, mode);
+#else
+if (fd == -1) {
+return -1;
+}
+
+/* Now we handle racing symlinks. */
+ret = fstat(fd, );
+if (!ret) {
+if (S_ISLNK(stbuf.st_mode)) {
+errno = ELOOP;
+ret = -1;
+} else {
+char *proc_path = g_strdup_printf("/proc/self/fd/%d", fd);
+ret = chmod(proc_path, mode);
+g_free(proc_path);
+}
+}
+#endif
 close_preserve_errno(fd);
 return ret;
 }
diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
index 517027c..033e7e6 100644
--- a/hw/9pfs/9p-util.h
+++ b/hw/9pfs/9p-util.h
@@ -13,6 +13,12 @@
 #ifndef QEMU_9P_UTIL_H
 #define QEMU_9P_UTIL_H
 
+#ifdef O_PATH
+#define O_PATH_9P_UTIL O_PATH
+#else
+#define O_PATH_9P_UTIL 0
+#endif
+
 static inline void close_preserve_errno(int fd)
 {
 int serrno = errno;
@@ -22,13 +28,8 @@ static inline void close_preserve_errno(int fd)
 
 static inline int openat_dir(int dirfd, const char *name)
 {
-#ifdef O_PATH
-#define OPENAT_DIR_O_PATH O_PATH
-#else
-#define OPENAT_DIR_O_PATH 0
-#endif
 return openat(dirfd, name,
-  O_DIRECTORY | O_RDONLY | O_NOFOLLOW | OPENAT_DIR_O_PATH);
+  O_DIRECTORY | O_RDONLY | O_NOFOLLOW | O_PATH_9P_UTIL);
 }
 
 static inline int openat_file(int dirfd, const char *name, int flags,
@@ -43,9 +44,14 @@ static inline int openat_file(int dirfd, const char *name, 
int flags,
 }
 
 serrno = errno;
-/* O_NONBLOCK was only needed to open the file. Let's drop it. */
-ret = fcntl(fd, F_SETFL, flags);
-assert(!ret);
+/* O_NONBLOCK was only needed to open the file. Let's drop it. We don't
+ * do that with O_PATH since 

[Qemu-devel] [PATCH 71/79] virtio-net: fix offload ctrl endian

2017-08-28 Thread Michael Roth
From: Jason Wang 

Spec said offloads should be le64, so use virtio_ldq_p() to guarantee
valid endian.

Fixes: 644c98587d4c ("virtio-net: dynamic network offloads configuration")
Cc: qemu-sta...@nongnu.org
Cc: Dmitry Fleytman 
Signed-off-by: Jason Wang 
(cherry picked from commit 189ae6bb5ce1f5a322f8691d00fe942ba43dd601)
Signed-off-by: Michael Roth 
---
 hw/net/virtio-net.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 98bd683..7695f75 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -723,6 +723,8 @@ static int virtio_net_handle_offloads(VirtIONet *n, uint8_t 
cmd,
 if (cmd == VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET) {
 uint64_t supported_offloads;
 
+offloads = virtio_ldq_p(vdev, );
+
 if (!n->has_vnet_hdr) {
 return VIRTIO_NET_ERR;
 }
-- 
2.7.4




[Qemu-devel] [PATCH 72/79] input: limit kbd queue depth

2017-08-28 Thread Michael Roth
From: Gerd Hoffmann 

Apply a limit to the number of items we accept into the keyboard queue.

Impact: Without this limit vnc clients can exhaust host memory by
sending keyboard events faster than qemu feeds them to the guest.

Fixes: CVE-2017-8379
Cc: P J P 
Cc: Huawei PSIRT 
Reported-by: jiangx...@huawei.com
Signed-off-by: Gerd Hoffmann 
Message-id: 20170428084237.23960-1-kra...@redhat.com
(cherry picked from commit fa18f36a461984eae50ab957e47ec78dae3c14fc)
Signed-off-by: Michael Roth 
---
 ui/input.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/ui/input.c b/ui/input.c
index ed88cda..fb1f404 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -41,6 +41,8 @@ static QTAILQ_HEAD(QemuInputEventQueueHead, 
QemuInputEventQueue) kbd_queue =
 QTAILQ_HEAD_INITIALIZER(kbd_queue);
 static QEMUTimer *kbd_timer;
 static uint32_t kbd_default_delay_ms = 10;
+static uint32_t queue_count;
+static uint32_t queue_limit = 1024;
 
 QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,
QemuInputHandler *handler)
@@ -268,6 +270,7 @@ static void qemu_input_queue_process(void *opaque)
 break;
 }
 QTAILQ_REMOVE(queue, item, node);
+queue_count--;
 g_free(item);
 }
 }
@@ -282,6 +285,7 @@ static void qemu_input_queue_delay(struct 
QemuInputEventQueueHead *queue,
 item->delay_ms = delay_ms;
 item->timer = timer;
 QTAILQ_INSERT_TAIL(queue, item, node);
+queue_count++;
 
 if (start_timer) {
 timer_mod(item->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL)
@@ -298,6 +302,7 @@ static void qemu_input_queue_event(struct 
QemuInputEventQueueHead *queue,
 item->src = src;
 item->evt = evt;
 QTAILQ_INSERT_TAIL(queue, item, node);
+queue_count++;
 }
 
 static void qemu_input_queue_sync(struct QemuInputEventQueueHead *queue)
@@ -306,6 +311,7 @@ static void qemu_input_queue_sync(struct 
QemuInputEventQueueHead *queue)
 
 item->type = QEMU_INPUT_QUEUE_SYNC;
 QTAILQ_INSERT_TAIL(queue, item, node);
+queue_count++;
 }
 
 void qemu_input_event_send_impl(QemuConsole *src, InputEvent *evt)
@@ -381,7 +387,7 @@ void qemu_input_event_send_key(QemuConsole *src, KeyValue 
*key, bool down)
 qemu_input_event_send(src, evt);
 qemu_input_event_sync();
 qapi_free_InputEvent(evt);
-} else {
+} else if (queue_count < queue_limit) {
 qemu_input_queue_event(_queue, src, evt);
 qemu_input_queue_sync(_queue);
 }
@@ -409,8 +415,10 @@ void qemu_input_event_send_key_delay(uint32_t delay_ms)
 kbd_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, qemu_input_queue_process,
  _queue);
 }
-qemu_input_queue_delay(_queue, kbd_timer,
-   delay_ms ? delay_ms : kbd_default_delay_ms);
+if (queue_count < queue_limit) {
+qemu_input_queue_delay(_queue, kbd_timer,
+   delay_ms ? delay_ms : kbd_default_delay_ms);
+}
 }
 
 InputEvent *qemu_input_event_new_btn(InputButton btn, bool down)
-- 
2.7.4




[Qemu-devel] [PATCH 62/79] blkverify: Catch bs->exact_filename overflow

2017-08-28 Thread Michael Roth
From: Max Reitz 

The bs->exact_filename field may not be sufficient to store the full
blkverify node filename. In this case, we should not generate a filename
at all instead of an unusable one.

Cc: qemu-sta...@nongnu.org
Reported-by: Qu Wenruo 
Signed-off-by: Max Reitz 
Message-id: 20170613172006.19685-3-mre...@redhat.com
Reviewed-by: Alberto Garcia 
Reviewed-by: Stefan Hajnoczi 
Signed-off-by: Max Reitz 
(cherry picked from commit 05cc758a3dfc79488d0a8eb7f5830a41871e78d0)
Signed-off-by: Michael Roth 
---
 block/blkverify.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/block/blkverify.c b/block/blkverify.c
index 6b0a603..06369f9 100644
--- a/block/blkverify.c
+++ b/block/blkverify.c
@@ -301,10 +301,14 @@ static void blkverify_refresh_filename(BlockDriverState 
*bs, QDict *options)
 if (bs->file->bs->exact_filename[0]
 && s->test_file->bs->exact_filename[0])
 {
-snprintf(bs->exact_filename, sizeof(bs->exact_filename),
- "blkverify:%s:%s",
- bs->file->bs->exact_filename,
- s->test_file->bs->exact_filename);
+int ret = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
+   "blkverify:%s:%s",
+   bs->file->bs->exact_filename,
+   s->test_file->bs->exact_filename);
+if (ret >= sizeof(bs->exact_filename)) {
+/* An overflow makes the filename unusable, so do not report any */
+bs->exact_filename[0] = 0;
+}
 }
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH 73/79] input: Decrement queue count on kbd delay

2017-08-28 Thread Michael Roth
From: Alexander Graf 

Delays in the input layer are special cased input events. Every input
event is accounted for in a global intput queue count. The special cased
delays however did not get removed from the queue, leading to queue overruns
and thus silent key drops after typing quite a few characters.

Signed-off-by: Alexander Graf 
Message-id: 1498117318-162102-1-git-send-email-ag...@suse.de
Fixes: be1a7176 ("input: add support for kbd delays")
Cc: qemu-sta...@nongnu.org
Signed-off-by: Gerd Hoffmann 
(cherry picked from commit 77b0359bf414ad666d1714dc9888f1017c08e283)
Signed-off-by: Michael Roth 
---
 ui/input.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ui/input.c b/ui/input.c
index fb1f404..94ba3d5 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -252,6 +252,7 @@ static void qemu_input_queue_process(void *opaque)
 item = QTAILQ_FIRST(queue);
 g_assert(item->type == QEMU_INPUT_QUEUE_DELAY);
 QTAILQ_REMOVE(queue, item, node);
+queue_count--;
 g_free(item);
 
 while (!QTAILQ_EMPTY(queue)) {
-- 
2.7.4




[Qemu-devel] [PATCH 70/79] spapr: fix memory leak in spapr_core_pre_plug()

2017-08-28 Thread Michael Roth
From: Greg Kurz 

In case of error, we must ensure the dynamically allocated base_core_type
is freed, like it is done everywhere else in this function.

This is a regression introduced in QEMU 2.9 by commit 8149e2992f78.

Signed-off-by: Greg Kurz 
Signed-off-by: David Gibson 
(cherry picked from commit df8658de43db242ea82183d75cc957c2b0fa013a)
 Conflicts:
hw/ppc/spapr.c
* fix context dep on 459264ef2
Signed-off-by: Michael Roth 
---
 hw/ppc/spapr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 58c15ef..bda3854 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2805,7 +2805,7 @@ static void spapr_core_pre_plug(HotplugHandler 
*hotplug_dev, DeviceState *dev,
 if (cc->nr_threads != smp_threads) {
 error_setg(errp, "invalid nr-threads %d, must be %d",
cc->nr_threads, smp_threads);
-return;
+goto out;
 }
 
 core_slot = spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, );
-- 
2.7.4




[Qemu-devel] [PATCH 68/79] virtio-scsi: finalize IOMMU support

2017-08-28 Thread Michael Roth
From: Jason Wang 

After converting to use DMA api for virtio devices, we should use
dma_as instead of address_space_memory. Otherwise it won't work if
IOMMU is enabled.

Fixes: commit 8607f5c3072c ("virtio: convert to use DMA api")
Cc: qemu-sta...@nongnu.org
Signed-off-by: Jason Wang 
Message-Id: <1499170866-9068-1-git-send-email-jasow...@redhat.com>
Signed-off-by: Paolo Bonzini 
(cherry picked from commit 025bdeab3c163aee9604a60b2332a5fcbcc00f8d)
Signed-off-by: Michael Roth 
---
 hw/scsi/virtio-scsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index cb1c123..3915c2e 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -43,12 +43,13 @@ static inline SCSIDevice 
*virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun)
 
 void virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq, VirtIOSCSIReq *req)
 {
+VirtIODevice *vdev = VIRTIO_DEVICE(s);
 const size_t zero_skip =
 offsetof(VirtIOSCSIReq, resp_iov) + sizeof(req->resp_iov);
 
 req->vq = vq;
 req->dev = s;
-qemu_sglist_init(>qsgl, DEVICE(s), 8, _space_memory);
+qemu_sglist_init(>qsgl, DEVICE(s), 8, vdev->dma_as);
 qemu_iovec_init(>resp_iov, 1);
 memset((uint8_t *)req + zero_skip, 0, sizeof(*req) - zero_skip);
 }
-- 
2.7.4




[Qemu-devel] [PATCH 69/79] commit: Add NULL check for overlay_bs

2017-08-28 Thread Michael Roth
From: Kevin Wolf 

I can't see how overlay_bs could become NULL with the current code, but
other code in this function already checks it and we can make Coverity
happy with this check, so let's add it.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Kevin Wolf 
Reviewed-by: Stefan Hajnoczi 
(cherry picked from commit b1e1fa0c3afc7f671fbc24645bdf67949a5657e5)
Signed-off-by: Michael Roth 
---
 block/commit.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/block/commit.c b/block/commit.c
index fba25e2..66e3418 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -91,7 +91,9 @@ static void commit_complete(BlockJob *job, void *opaque)
 
 /* Make sure overlay_bs and top stay around until bdrv_set_backing_hd() */
 bdrv_ref(top);
-bdrv_ref(overlay_bs);
+if (overlay_bs) {
+bdrv_ref(overlay_bs);
+}
 
 /* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before
  * the normal backing chain can be restored. */
-- 
2.7.4




[Qemu-devel] [PATCH 65/79] 9pfs: local: remove: use correct path component

2017-08-28 Thread Michael Roth
From: Bruce Rogers 

Commit a0e640a8 introduced a path processing error.
Pass fstatat the dirpath based path component instead
of the entire path.

Signed-off-by: Bruce Rogers 
Signed-off-by: Greg Kurz 
(cherry picked from commit 790db7efdbe1536acf1c4f4f95a0316dbda59433)
Signed-off-by: Michael Roth 
---
 hw/9pfs/9p-local.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 7a0c383..b13ff21 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -1009,7 +1009,7 @@ static int local_remove(FsContext *ctx, const char *path)
 goto out;
 }
 
-if (fstatat(dirfd, path, , AT_SYMLINK_NOFOLLOW) < 0) {
+if (fstatat(dirfd, name, , AT_SYMLINK_NOFOLLOW) < 0) {
 goto err_out;
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH 60/79] commit: Fix completion with extra reference

2017-08-28 Thread Michael Roth
From: Kevin Wolf 

commit_complete() can't assume that after its block_job_completed() the
job is actually immediately freed; someone else may still be holding
references. In this case, the op blockers on the intermediate nodes make
the graph reconfiguration in the completion code fail.

Call block_job_remove_all_bdrv() manually so that we know for sure that
any blockers on intermediate nodes are given up.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Kevin Wolf 
Reviewed-by: Eric Blake 
Reviewed-by: Max Reitz 
(cherry picked from commit 4f78a16fee462471416dc49b409d57b2071cf3d9)
Signed-off-by: Michael Roth 
---
 block/commit.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/block/commit.c b/block/commit.c
index 3bae46e..fba25e2 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -119,6 +119,13 @@ static void commit_complete(BlockJob *job, void *opaque)
 }
 g_free(s->backing_file_str);
 blk_unref(s->top);
+
+/* If there is more than one reference to the job (e.g. if called from
+ * block_job_finish_sync()), block_job_completed() won't free it and
+ * therefore the blockers on the intermediate nodes remain. This would
+ * cause bdrv_set_backing_hd() to fail. */
+block_job_remove_all_bdrv(job);
+
 block_job_completed(>common, ret);
 g_free(data);
 
-- 
2.7.4




[Qemu-devel] [PATCH 61/79] blkdebug: Catch bs->exact_filename overflow

2017-08-28 Thread Michael Roth
From: Max Reitz 

The bs->exact_filename field may not be sufficient to store the full
blkdebug node filename. In this case, we should not generate a filename
at all instead of an unusable one.

Cc: qemu-sta...@nongnu.org
Reported-by: Qu Wenruo 
Signed-off-by: Max Reitz 
Message-id: 20170613172006.19685-2-mre...@redhat.com
Reviewed-by: Alberto Garcia 
Reviewed-by: Stefan Hajnoczi 
Signed-off-by: Max Reitz 
(cherry picked from commit de81d72d3d13a19edf4d461be3b0f5a877be0234)
Signed-off-by: Michael Roth 
---
 block/blkdebug.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/block/blkdebug.c b/block/blkdebug.c
index 5ccb9ce..63bc5d4 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -840,9 +840,13 @@ static void blkdebug_refresh_filename(BlockDriverState 
*bs, QDict *options)
 }
 
 if (!force_json && bs->file->bs->exact_filename[0]) {
-snprintf(bs->exact_filename, sizeof(bs->exact_filename),
- "blkdebug:%s:%s", s->config_file ?: "",
- bs->file->bs->exact_filename);
+int ret = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
+   "blkdebug:%s:%s", s->config_file ?: "",
+   bs->file->bs->exact_filename);
+if (ret >= sizeof(bs->exact_filename)) {
+/* An overflow makes the filename unusable, so do not report any */
+bs->exact_filename[0] = 0;
+}
 }
 
 opts = qdict_new();
-- 
2.7.4




[Qemu-devel] [PATCH 64/79] block: Do not strcmp() with NULL uri->scheme

2017-08-28 Thread Michael Roth
From: Max Reitz 

uri_parse(...)->scheme may be NULL. In fact, probably every field may be
NULL, and the callers do test this for all of the other fields but not
for scheme (except for block/gluster.c; block/vxhs.c does not access
that field at all).

We can easily fix this by using g_strcmp0() instead of strcmp().

Cc: qemu-sta...@nongnu.org
Signed-off-by: Max Reitz 
Message-id: 20170613205726.13544-1-mre...@redhat.com
Reviewed-by: Stefan Hajnoczi 
Signed-off-by: Max Reitz 
(cherry picked from commit f69165a8feca055cf4a37d13ab0fc5beec3cb372)
Signed-off-by: Michael Roth 
---
 block/nbd.c  | 6 +++---
 block/nfs.c  | 2 +-
 block/sheepdog.c | 6 +++---
 block/ssh.c  | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/block/nbd.c b/block/nbd.c
index b3545f5..9a54edf 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -65,11 +65,11 @@ static int nbd_parse_uri(const char *filename, QDict 
*options)
 }
 
 /* transport */
-if (!strcmp(uri->scheme, "nbd")) {
+if (!g_strcmp0(uri->scheme, "nbd")) {
 is_unix = false;
-} else if (!strcmp(uri->scheme, "nbd+tcp")) {
+} else if (!g_strcmp0(uri->scheme, "nbd+tcp")) {
 is_unix = false;
-} else if (!strcmp(uri->scheme, "nbd+unix")) {
+} else if (!g_strcmp0(uri->scheme, "nbd+unix")) {
 is_unix = true;
 } else {
 ret = -EINVAL;
diff --git a/block/nfs.c b/block/nfs.c
index bfeebc1..344186f 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -83,7 +83,7 @@ static int nfs_parse_uri(const char *filename, QDict 
*options, Error **errp)
 error_setg(errp, "Invalid URI specified");
 goto out;
 }
-if (strcmp(uri->scheme, "nfs") != 0) {
+if (g_strcmp0(uri->scheme, "nfs") != 0) {
 error_setg(errp, "URI scheme must be 'nfs'");
 goto out;
 }
diff --git a/block/sheepdog.c b/block/sheepdog.c
index fb9203e..2d8d8c8 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1052,11 +1052,11 @@ static void sd_parse_uri(SheepdogConfig *cfg, const 
char *filename,
 }
 
 /* transport */
-if (!strcmp(uri->scheme, "sheepdog")) {
+if (!g_strcmp0(uri->scheme, "sheepdog")) {
 is_unix = false;
-} else if (!strcmp(uri->scheme, "sheepdog+tcp")) {
+} else if (!g_strcmp0(uri->scheme, "sheepdog+tcp")) {
 is_unix = false;
-} else if (!strcmp(uri->scheme, "sheepdog+unix")) {
+} else if (!g_strcmp0(uri->scheme, "sheepdog+unix")) {
 is_unix = true;
 } else {
 error_setg(, "URI scheme must be 'sheepdog', 'sheepdog+tcp',"
diff --git a/block/ssh.c b/block/ssh.c
index 34a2f79..139b05d 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -205,7 +205,7 @@ static int parse_uri(const char *filename, QDict *options, 
Error **errp)
 return -EINVAL;
 }
 
-if (strcmp(uri->scheme, "ssh") != 0) {
+if (g_strcmp0(uri->scheme, "ssh") != 0) {
 error_setg(errp, "URI scheme must be 'ssh'");
 goto err;
 }
-- 
2.7.4




[Qemu-devel] [PATCH 66/79] hid: Reset kbd modifiers on reset

2017-08-28 Thread Michael Roth
From: Alexander Graf 

When resetting the keyboard, we need to reset not just the pending keystrokes,
but also any pending modifiers. Otherwise there's a race when we're getting
reset while running an escape sequence (modifier 0x100).

Cc: qemu-sta...@nongnu.org
Signed-off-by: Alexander Graf 
Message-id: 1498117295-162030-1-git-send-email-ag...@suse.de
Signed-off-by: Gerd Hoffmann 
(cherry picked from commit 51dbea77a29ea46173373a6dad4ebd95d4661f42)
Signed-off-by: Michael Roth 
---
 hw/input/hid.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/input/hid.c b/hw/input/hid.c
index fa9cc4c..a0892e8 100644
--- a/hw/input/hid.c
+++ b/hw/input/hid.c
@@ -483,6 +483,7 @@ void hid_reset(HIDState *hs)
 memset(hs->kbd.keycodes, 0, sizeof(hs->kbd.keycodes));
 memset(hs->kbd.key, 0, sizeof(hs->kbd.key));
 hs->kbd.keys = 0;
+hs->kbd.modifiers = 0;
 break;
 case HID_MOUSE:
 case HID_TABLET:
-- 
2.7.4




[Qemu-devel] [PATCH 45/79] block: Guarantee that *file is set on bdrv_get_block_status()

2017-08-28 Thread Michael Roth
From: Eric Blake 

We document that *file is valid if the return is not an error and
includes BDRV_BLOCK_OFFSET_VALID, but forgot to obey this contract
when a driver (such as blkdebug) lacks a callback.  Messed up in
commit 67a0fd2 (v2.6), when we added the file parameter.

Enhance qemu-iotest 177 to cover this, using a sequence that would
print garbage or even SEGV, because it was dererefencing through
uninitialized memory.  [The resulting test output shows that we
have less-than-ideal block status from the blkdebug driver, but
that's a separate fix coming up soon.]

Setting *file on all paths that return BDRV_BLOCK_OFFSET_VALID is
enough to fix the crash, but we can go one step further: always
setting *file, even on error, means that a broken caller that
blindly dereferences file without checking for error is now more
likely to get a reliable SEGV instead of randomly acting on garbage,
making it easier to diagnose such buggy callers.  Adding an
assertion that file is set where expected doesn't hurt either.

CC: qemu-sta...@nongnu.org
Signed-off-by: Eric Blake 
Reviewed-by: Fam Zheng 
Reviewed-by: Max Reitz 
Reviewed-by: John Snow 
Signed-off-by: Kevin Wolf 
(cherry picked from commit 81c219ac6ce0d6182e35f3976f2caa4cefcaf9f0)
Signed-off-by: Michael Roth 
---
 block/io.c | 5 +++--
 tests/qemu-iotests/177 | 3 +++
 tests/qemu-iotests/177.out | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/block/io.c b/block/io.c
index fe0c867..a8589ee 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1757,6 +1757,7 @@ static int64_t coroutine_fn 
bdrv_co_get_block_status(BlockDriverState *bs,
 int64_t n;
 int64_t ret, ret2;
 
+*file = NULL;
 total_sectors = bdrv_nb_sectors(bs);
 if (total_sectors < 0) {
 return total_sectors;
@@ -1777,11 +1778,11 @@ static int64_t coroutine_fn 
bdrv_co_get_block_status(BlockDriverState *bs,
 ret = BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED;
 if (bs->drv->protocol_name) {
 ret |= BDRV_BLOCK_OFFSET_VALID | (sector_num * BDRV_SECTOR_SIZE);
+*file = bs;
 }
 return ret;
 }
 
-*file = NULL;
 bdrv_inc_in_flight(bs);
 ret = bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, pnum,
 file);
@@ -1791,7 +1792,7 @@ static int64_t coroutine_fn 
bdrv_co_get_block_status(BlockDriverState *bs,
 }
 
 if (ret & BDRV_BLOCK_RAW) {
-assert(ret & BDRV_BLOCK_OFFSET_VALID);
+assert(ret & BDRV_BLOCK_OFFSET_VALID && *file);
 ret = bdrv_co_get_block_status(*file, ret >> BDRV_SECTOR_BITS,
*pnum, pnum, file);
 goto out;
diff --git a/tests/qemu-iotests/177 b/tests/qemu-iotests/177
index 2005c17..f8ed8fb 100755
--- a/tests/qemu-iotests/177
+++ b/tests/qemu-iotests/177
@@ -43,6 +43,7 @@ _supported_proto file
 CLUSTER_SIZE=1M
 size=128M
 options=driver=blkdebug,image.driver=qcow2
+nested_opts=image.file.driver=file,image.file.filename=$TEST_IMG
 
 echo
 echo "== setting up files =="
@@ -106,6 +107,8 @@ function verify_io()
 }
 
 verify_io | $QEMU_IO -r "$TEST_IMG" | _filter_qemu_io
+$QEMU_IMG map --image-opts "$options,$nested_opts,align=4k" \
+| _filter_qemu_img_map
 
 _check_test_img
 
diff --git a/tests/qemu-iotests/177.out b/tests/qemu-iotests/177.out
index e887542..fcfbfa3 100644
--- a/tests/qemu-iotests/177.out
+++ b/tests/qemu-iotests/177.out
@@ -45,5 +45,7 @@ read 30408704/30408704 bytes at offset 80740352
 29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 read 23068672/23068672 bytes at offset 49056
 22 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+Offset  Length  File
+0   0x800   json:{"image": {"driver": "IMGFMT", "file": 
{"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}}, "driver": "blkdebug", 
"align": "4k"}
 No errors were found on the image.
 *** done
-- 
2.7.4




[Qemu-devel] [PATCH 58/79] nbd: Fully initialize client in case of failed negotiation

2017-08-28 Thread Michael Roth
From: Eric Blake 

If a non-NBD client connects to qemu-nbd, we would end up with
a SIGSEGV in nbd_client_put() because we were trying to
unregister the client's association to the export, even though
we skipped inserting the client into that list.  Easy trigger
in two terminals:

$ qemu-nbd -p 30001 --format=raw file
$ nmap 127.0.0.1 -p 30001

nmap claims that it thinks it connected to a pago-services1
server (which probably means nmap could be updated to learn the
NBD protocol and give a more accurate diagnosis of the open
port - but that's not our problem), then terminates immediately,
so our call to nbd_negotiate() fails.  The fix is to reorder
nbd_co_client_start() to ensure that all initialization occurs
before we ever try talking to a client in nbd_negotiate(), so
that the teardown sequence on negotiation failure doesn't fault
while dereferencing a half-initialized object.

While debugging this, I also noticed that nbd_update_server_watch()
called by nbd_client_closed() was still adding a channel to accept
the next client, even when the state was no longer RUNNING.  That
is fixed by making nbd_can_accept() pay attention to the current
state.

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

Signed-off-by: Eric Blake 
Message-Id: <20170527030421.28366-1-ebl...@redhat.com>
Signed-off-by: Paolo Bonzini 
(cherry picked from commit df8ad9f128c15aa0a0ebc7b24e9a22c9775b67af)
Signed-off-by: Michael Roth 
---
 nbd/server.c | 8 +++-
 qemu-nbd.c   | 2 +-
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/nbd/server.c b/nbd/server.c
index 924a1fe..edfda84 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -1376,16 +1376,14 @@ static coroutine_fn void nbd_co_client_start(void 
*opaque)
 
 if (exp) {
 nbd_export_get(exp);
+QTAILQ_INSERT_TAIL(>clients, client, next);
 }
+qemu_co_mutex_init(>send_lock);
+
 if (nbd_negotiate(data)) {
 client_close(client);
 goto out;
 }
-qemu_co_mutex_init(>send_lock);
-
-if (exp) {
-QTAILQ_INSERT_TAIL(>clients, client, next);
-}
 
 nbd_client_receive_next_request(client);
 
diff --git a/qemu-nbd.c b/qemu-nbd.c
index e4f00e2..14e7947 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -324,7 +324,7 @@ out:
 
 static int nbd_can_accept(void)
 {
-return nb_fds < shared;
+return state == RUNNING && nb_fds < shared;
 }
 
 static void nbd_export_closed(NBDExport *exp)
-- 
2.7.4




[Qemu-devel] [PATCH 67/79] spapr: fix migration to pseries machine < 2.8

2017-08-28 Thread Michael Roth
From: Laurent Vivier 

since commit 5c4537bd ("spapr: Fix 2.7<->2.8 migration of PCI host bridge"),
some migration fields are forged from the new ones in spapr_pci_pre_save().

It works well, except when the number of MSI devices is 0,
because in this case the function exits immediately.

This fix moves the migration code before the exit code.

The problem can be reproduced with these commands:

source qemu-2.9:

qemu-system-ppc64 -monitor stdio -M pseries-2.6 -nodefaults -S

destination qemu-2.6:

qemu-system-ppc64 -monitor stdio -M pseries-2.6 -nodefaults \
  -incoming tcp:0:

on the source:

migrate tcp:localhost:

Destination fails with the following error:

qemu-system-ppc64: error while loading state for
   instance 0x0 of device 'spapr_pci'
qemu-system-ppc64: load of migration failed: Invalid argument

Signed-off-by: Laurent Vivier 
Reviewed-by: Greg Kurz 
Signed-off-by: David Gibson 
(cherry picked from commit e806b4db1477a1c6bfda7bba28c7f26c47f18e1e)
Signed-off-by: Michael Roth 
---
 hw/ppc/spapr_pci.c | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 98c52e4..ecfbf01 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -1893,20 +1893,6 @@ static void spapr_pci_pre_save(void *opaque)
 gpointer key, value;
 int i;
 
-g_free(sphb->msi_devs);
-sphb->msi_devs = NULL;
-sphb->msi_devs_num = g_hash_table_size(sphb->msi);
-if (!sphb->msi_devs_num) {
-return;
-}
-sphb->msi_devs = g_malloc(sphb->msi_devs_num * sizeof(spapr_pci_msi_mig));
-
-g_hash_table_iter_init(, sphb->msi);
-for (i = 0; g_hash_table_iter_next(, , ); ++i) {
-sphb->msi_devs[i].key = *(uint32_t *) key;
-sphb->msi_devs[i].value = *(spapr_pci_msi *) value;
-}
-
 if (sphb->pre_2_8_migration) {
 sphb->mig_liobn = sphb->dma_liobn[0];
 sphb->mig_mem_win_addr = sphb->mem_win_addr;
@@ -1920,6 +1906,20 @@ static void spapr_pci_pre_save(void *opaque)
 sphb->mig_mem_win_size += sphb->mem64_win_size;
 }
 }
+
+g_free(sphb->msi_devs);
+sphb->msi_devs = NULL;
+sphb->msi_devs_num = g_hash_table_size(sphb->msi);
+if (!sphb->msi_devs_num) {
+return;
+}
+sphb->msi_devs = g_malloc(sphb->msi_devs_num * sizeof(spapr_pci_msi_mig));
+
+g_hash_table_iter_init(, sphb->msi);
+for (i = 0; g_hash_table_iter_next(, , ); ++i) {
+sphb->msi_devs[i].key = *(uint32_t *) key;
+sphb->msi_devs[i].value = *(spapr_pci_msi *) value;
+}
 }
 
 static int spapr_pci_post_load(void *opaque, int version_id)
-- 
2.7.4




[Qemu-devel] [PATCH 05/79] qemu-img/convert: Move bs_n > 1 && -B check down

2017-08-28 Thread Michael Roth
From: Max Reitz 

It does not make much sense to use a backing image for the target when
you concatenate multiple images (because then there is no correspondence
between the source images' backing files and the target's); but it was
still possible to give one by using -o backing_file=X instead of -B X.

Fix this by moving the check.

(Also, change the error message because -B is not the only way to
 specify the backing file, evidently.)

Cc: qemu-stable 
Signed-off-by: Max Reitz 
Reviewed-by: Eric Blake 
* applied patch from v1 of series as suggested by author
Signed-off-by: Michael Roth 
---
 qemu-img.c | 14 +++---
 tests/qemu-iotests/122.out |  4 ++--
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index cfc3bc3..4b2d59a 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2113,13 +2113,6 @@ static int img_convert(int argc, char **argv)
 }
 
 
-if (bs_n > 1 && out_baseimg) {
-error_report("-B makes no sense when concatenating multiple input "
- "images");
-ret = -1;
-goto out;
-}
-
 src_flags = 0;
 ret = bdrv_parse_cache_mode(src_cache, _flags, _writethrough);
 if (ret < 0) {
@@ -2229,6 +,13 @@ static int img_convert(int argc, char **argv)
 out_baseimg = out_baseimg_param;
 }
 
+if (bs_n > 1 && out_baseimg) {
+error_report("Having a backing file for the target makes no sense when 
"
+ "concatenating multiple input images");
+ret = -1;
+goto out;
+}
+
 /* Check if compression is supported */
 if (compress) {
 bool encryption =
diff --git a/tests/qemu-iotests/122.out b/tests/qemu-iotests/122.out
index 98814de..9317d80 100644
--- a/tests/qemu-iotests/122.out
+++ b/tests/qemu-iotests/122.out
@@ -61,8 +61,8 @@ read 65536/65536 bytes at offset 4194304
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 read 65536/65536 bytes at offset 8388608
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-qemu-img: -B makes no sense when concatenating multiple input images
-qemu-img: -B makes no sense when concatenating multiple input images
+qemu-img: Having a backing file for the target makes no sense when 
concatenating multiple input images
+qemu-img: Having a backing file for the target makes no sense when 
concatenating multiple input images
 
 === Compression with misaligned allocations and image sizes ===
 
-- 
2.7.4




[Qemu-devel] [PATCH 40/79] blkdebug: Add pass-through write_zero and discard support

2017-08-28 Thread Michael Roth
From: Eric Blake 

In order to test the effects of artificial geometry constraints
on operations like write zero or discard, we first need blkdebug
to manage these actions.  It also allows us to inject errors on
those operations, just like we can for read/write/flush.

We can also test the contract promised by the block layer; namely,
if a device has specified limits on alignment or maximum size,
then those limits must be obeyed (for now, the blkdebug driver
merely inherits limits from whatever it is wrapping, but the next
patch will further enhance it to allow specific limit overrides).

This patch intentionally refuses to service requests smaller than
the requested alignments; this is because an upcoming patch adds
a qemu-iotest to prove that the block layer is correctly handling
fragmentation, but the test only works if there is a way to tell
the difference at artificial alignment boundaries when blkdebug is
using a larger-than-default alignment.  If we let the blkdebug
layer always defer to the underlying layer, which potentially has
a smaller granularity, the iotest will be thwarted.

Tested by setting up an NBD server with export 'foo', then invoking:
$ ./qemu-io
qemu-io> open -o driver=blkdebug blkdebug::nbd://localhost:10809/foo
qemu-io> d 0 15M
qemu-io> w -z 0 15M

Pre-patch, the server never sees the discard (it was silently
eaten by the block layer); post-patch it is passed across the
wire.  Likewise, pre-patch the write is always passed with
NBD_WRITE (with 15M of zeroes on the wire), while post-patch
it can utilize NBD_WRITE_ZEROES (for less traffic).

Signed-off-by: Eric Blake 
Reviewed-by: Max Reitz 
Message-id: 20170429191419.30051-7-ebl...@redhat.com
Signed-off-by: Max Reitz 
(cherry picked from commit 63188c245013dbe383e8b031e665f813e2452ea5)
* prereq for 81c219a
Signed-off-by: Michael Roth 
---
 block/blkdebug.c | 74 
 1 file changed, 74 insertions(+)

diff --git a/block/blkdebug.c b/block/blkdebug.c
index c5d2edb..a3dc5f6 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -1,6 +1,7 @@
 /*
  * Block protocol for I/O error injection
  *
+ * Copyright (C) 2016-2017 Red Hat, Inc.
  * Copyright (c) 2010 Kevin Wolf 
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -382,6 +383,11 @@ static int blkdebug_open(BlockDriverState *bs, QDict 
*options, int flags,
 goto out;
 }
 
+bs->supported_write_flags = BDRV_REQ_FUA &
+bs->file->bs->supported_write_flags;
+bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
+bs->file->bs->supported_zero_flags;
+
 /* Set request alignment */
 align = qemu_opt_get_size(opts, "align", 0);
 if (align < INT_MAX && is_power_of_2(align)) {
@@ -494,6 +500,72 @@ static int blkdebug_co_flush(BlockDriverState *bs)
 return bdrv_co_flush(bs->file->bs);
 }
 
+static int coroutine_fn blkdebug_co_pwrite_zeroes(BlockDriverState *bs,
+  int64_t offset, int count,
+  BdrvRequestFlags flags)
+{
+uint32_t align = MAX(bs->bl.request_alignment,
+ bs->bl.pwrite_zeroes_alignment);
+int err;
+
+/* Only pass through requests that are larger than requested
+ * preferred alignment (so that we test the fallback to writes on
+ * unaligned portions), and check that the block layer never hands
+ * us anything unaligned that crosses an alignment boundary.  */
+if (count < align) {
+assert(QEMU_IS_ALIGNED(offset, align) ||
+   QEMU_IS_ALIGNED(offset + count, align) ||
+   DIV_ROUND_UP(offset, align) ==
+   DIV_ROUND_UP(offset + count, align));
+return -ENOTSUP;
+}
+assert(QEMU_IS_ALIGNED(offset, align));
+assert(QEMU_IS_ALIGNED(count, align));
+if (bs->bl.max_pwrite_zeroes) {
+assert(count <= bs->bl.max_pwrite_zeroes);
+}
+
+err = rule_check(bs, offset, count);
+if (err) {
+return err;
+}
+
+return bdrv_co_pwrite_zeroes(bs->file, offset, count, flags);
+}
+
+static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs,
+ int64_t offset, int count)
+{
+uint32_t align = bs->bl.pdiscard_alignment;
+int err;
+
+/* Only pass through requests that are larger than requested
+ * minimum alignment, and ensure that unaligned requests do not
+ * cross optimum discard boundaries. */
+if (count < bs->bl.request_alignment) {
+assert(QEMU_IS_ALIGNED(offset, align) ||
+   QEMU_IS_ALIGNED(offset + count, align) ||
+   DIV_ROUND_UP(offset, align) ==
+   DIV_ROUND_UP(offset + count, align));
+return -ENOTSUP;
+}
+assert(QEMU_IS_ALIGNED(offset, 

[Qemu-devel] [PATCH 54/79] spapr: add pre_plug function for memory

2017-08-28 Thread Michael Roth
From: Laurent Vivier 

This allows to manage errors before the memory
has started to be hotplugged. We already have
the function for the CPU cores.

Signed-off-by: Laurent Vivier 
Reviewed-by: Greg Kurz 
[dwg: Fixed a couple of style nits]
Signed-off-by: David Gibson 

(cherry picked from commit c871bc70bb22d1d70451bc813ecb008fe98cc92b)
Signed-off-by: Michael Roth 
---
 hw/ppc/spapr.c | 41 ++---
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 35db949..5564f78 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2508,20 +2508,6 @@ static void spapr_memory_plug(HotplugHandler 
*hotplug_dev, DeviceState *dev,
 uint64_t align = memory_region_get_alignment(mr);
 uint64_t size = memory_region_size(mr);
 uint64_t addr;
-char *mem_dev;
-
-if (size % SPAPR_MEMORY_BLOCK_SIZE) {
-error_setg(_err, "Hotplugged memory size must be a multiple of "
-  "%lld MB", SPAPR_MEMORY_BLOCK_SIZE/M_BYTE);
-goto out;
-}
-
-mem_dev = object_property_get_str(OBJECT(dimm), PC_DIMM_MEMDEV_PROP, NULL);
-if (mem_dev && !kvmppc_is_mem_backend_page_size_ok(mem_dev)) {
-error_setg(_err, "Memory backend has bad page size. "
-   "Use 'memory-backend-file' with correct mem-path.");
-goto out;
-}
 
 pc_dimm_memory_plug(dev, >hotplug_memory, mr, align, _err);
 if (local_err) {
@@ -2542,6 +2528,29 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void spapr_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState 
*dev,
+  Error **errp)
+{
+PCDIMMDevice *dimm = PC_DIMM(dev);
+PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
+MemoryRegion *mr = ddc->get_memory_region(dimm);
+uint64_t size = memory_region_size(mr);
+char *mem_dev;
+
+if (size % SPAPR_MEMORY_BLOCK_SIZE) {
+error_setg(errp, "Hotplugged memory size must be a multiple of "
+  "%lld MB", SPAPR_MEMORY_BLOCK_SIZE / M_BYTE);
+return;
+}
+
+mem_dev = object_property_get_str(OBJECT(dimm), PC_DIMM_MEMDEV_PROP, NULL);
+if (mem_dev && !kvmppc_is_mem_backend_page_size_ok(mem_dev)) {
+error_setg(errp, "Memory backend has bad page size. "
+   "Use 'memory-backend-file' with correct mem-path.");
+return;
+}
+}
+
 typedef struct sPAPRDIMMState {
 uint32_t nr_lmbs;
 } sPAPRDIMMState;
@@ -2912,7 +2921,9 @@ static void 
spapr_machine_device_unplug_request(HotplugHandler *hotplug_dev,
 static void spapr_machine_device_pre_plug(HotplugHandler *hotplug_dev,
   DeviceState *dev, Error **errp)
 {
-if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) {
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+spapr_memory_pre_plug(hotplug_dev, dev, errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) {
 spapr_core_pre_plug(hotplug_dev, dev, errp);
 }
 }
-- 
2.7.4




[Qemu-devel] [PATCH 63/79] nbd: fix NBD over TLS

2017-08-28 Thread Michael Roth
From: Paolo Bonzini 

When attaching the NBD QIOChannel to an AioContext, the TLS channel should
be used, not the underlying socket channel.  This is because, trivially,
the TLS channel will be the one that we read/write to and thus the one
that will get the qio_channel_yield() call.

Fixes: ff82911cd3f69f028f2537825c9720ff78bc3f19
Cc: qemu-sta...@nongnu.org
Reviewed-by: Stefan Hajnoczi 
Reviewed-by: Daniel P. Berrange 
Tested-by: Daniel P. Berrange 
Signed-off-by: Paolo Bonzini 
(cherry picked from commit 96d06835dc40007673cdfab6322e9042c4077113)
Signed-off-by: Michael Roth 
---
 block/nbd-client.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/nbd-client.c b/block/nbd-client.c
index 1e2952f..56eb0e2 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -352,14 +352,14 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t 
offset, int count)
 void nbd_client_detach_aio_context(BlockDriverState *bs)
 {
 NBDClientSession *client = nbd_get_client_session(bs);
-qio_channel_detach_aio_context(QIO_CHANNEL(client->sioc));
+qio_channel_detach_aio_context(QIO_CHANNEL(client->ioc));
 }
 
 void nbd_client_attach_aio_context(BlockDriverState *bs,
AioContext *new_context)
 {
 NBDClientSession *client = nbd_get_client_session(bs);
-qio_channel_attach_aio_context(QIO_CHANNEL(client->sioc), new_context);
+qio_channel_attach_aio_context(QIO_CHANNEL(client->ioc), new_context);
 aio_co_schedule(new_context, client->read_reply_co);
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH 56/79] target/xtensa: handle unknown registers in gdbstub

2017-08-28 Thread Michael Roth
From: Max Filippov 

Xtensa cores may have registers of types/sizes not supported by the
gdbstub accessors. Ignore writes to such registers and return zero on
read, but always return correct register size, so that gdb on the other
side is able to access all registers in the packet holding unsupported
registers in the middle. This fixes gdb interaction with cores that have
vector/custom TIE registers.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Max Filippov 
(cherry picked from commit dd7b952b793e341c905355581a21cdbaa8b13c31)
Signed-off-by: Michael Roth 
---
 target/xtensa/gdbstub.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/target/xtensa/gdbstub.c b/target/xtensa/gdbstub.c
index fa5469a..da131ae 100644
--- a/target/xtensa/gdbstub.c
+++ b/target/xtensa/gdbstub.c
@@ -58,7 +58,10 @@ int xtensa_cpu_gdb_read_register(CPUState *cs, uint8_t 
*mem_buf, int n)
 case 8:
 return gdb_get_reg64(mem_buf, float64_val(env->fregs[i].f64));
 default:
-return 0;
+qemu_log_mask(LOG_UNIMP, "%s from reg %d of unsupported size %d\n",
+  __func__, n, reg->size);
+memset(mem_buf, 0, reg->size);
+return reg->size;
 }
 
 case 8: /*a*/
@@ -67,6 +70,8 @@ int xtensa_cpu_gdb_read_register(CPUState *cs, uint8_t 
*mem_buf, int n)
 default:
 qemu_log_mask(LOG_UNIMP, "%s from reg %d of unsupported type %d\n",
   __func__, n, reg->type);
+memset(mem_buf, 0, reg->size);
+return reg->size;
 return 0;
 }
 }
@@ -111,7 +116,9 @@ int xtensa_cpu_gdb_write_register(CPUState *cs, uint8_t 
*mem_buf, int n)
 env->fregs[reg->targno & 0x0f].f64 = make_float64(tmp);
 return 8;
 default:
-return 0;
+qemu_log_mask(LOG_UNIMP, "%s to reg %d of unsupported size %d\n",
+  __func__, n, reg->size);
+return reg->size;
 }
 
 case 8: /*a*/
@@ -121,7 +128,7 @@ int xtensa_cpu_gdb_write_register(CPUState *cs, uint8_t 
*mem_buf, int n)
 default:
 qemu_log_mask(LOG_UNIMP, "%s to reg %d of unsupported type %d\n",
   __func__, n, reg->type);
-return 0;
+return reg->size;
 }
 
 return 4;
-- 
2.7.4




[Qemu-devel] [PATCH 38/79] blkdebug: Sanity check block layer guarantees

2017-08-28 Thread Michael Roth
From: Eric Blake 

Commits 04ed95f4 and 1a62d0ac updated the block layer to auto-fragment
any I/O to fit within device boundaries. Additionally, when using a
minimum alignment of 4k, we want to ensure the block layer does proper
read-modify-write rather than requesting I/O on a slice of a sector.
Let's enforce that the contract is obeyed when using blkdebug.  For
now, blkdebug only allows alignment overrides, and just inherits other
limits from whatever device it is wrapping, but a future patch will
further enhance things.

Signed-off-by: Eric Blake 
Reviewed-by: Kevin Wolf 
Reviewed-by: Max Reitz 
Message-id: 20170429191419.30051-5-ebl...@redhat.com
Signed-off-by: Max Reitz 
(cherry picked from commit e0ef439588ce1ede747f82b77d893190c1cc9f4d)
* prereq for 81c219a
Signed-off-by: Michael Roth 
---
 block/blkdebug.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/block/blkdebug.c b/block/blkdebug.c
index 46bd08a..b2cee0c 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -429,6 +429,13 @@ blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, 
uint64_t bytes,
 BDRVBlkdebugState *s = bs->opaque;
 BlkdebugRule *rule = NULL;
 
+/* Sanity check block layer guarantees */
+assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
+assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment));
+if (bs->bl.max_transfer) {
+assert(bytes <= bs->bl.max_transfer);
+}
+
 QSIMPLEQ_FOREACH(rule, >active_rules, active_next) {
 uint64_t inject_offset = rule->options.inject.offset;
 
@@ -453,6 +460,13 @@ blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, 
uint64_t bytes,
 BDRVBlkdebugState *s = bs->opaque;
 BlkdebugRule *rule = NULL;
 
+/* Sanity check block layer guarantees */
+assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
+assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment));
+if (bs->bl.max_transfer) {
+assert(bytes <= bs->bl.max_transfer);
+}
+
 QSIMPLEQ_FOREACH(rule, >active_rules, active_next) {
 uint64_t inject_offset = rule->options.inject.offset;
 
-- 
2.7.4




[Qemu-devel] [PATCH 51/79] pc: Use "min-[x]level" on compat_props

2017-08-28 Thread Michael Roth
From: Eduardo Habkost 

Since the automatic cpuid-level code was introduced in commit
c39c0edf9bb3b968ba95484465a50c7b19f4aa3a ("target-i386: Automatically
set level/xlevel/xlevel2 when needed"), the CPU model tables just define
the default CPUID level code (set using "min-level").  Setting
"[x]level" forces CPUID level to a specific value and disable the
automatic-level logic.

But the PC compat code was not updated and the existing "[x]level"
compat properties broke compatibility for people using features that
triggered the auto-level code.  To keep previous behavior, we should set
"min-[x]level" instead of "[x]level" on compat_props.

This was not a problem for most cases, because old machine-types don't
have full-cpuid-auto-level enabled.  The only common use case it broke
was the CPUID[7] auto-level code, that was already enabled since the
first CPUID[7] feature was introduced (in QEMU 1.4.0).

This causes the regression reported at:
https://bugzilla.redhat.com/show_bug.cgi?id=1454641

Change the PC compat code to use "min-[x]level" instead of "[x]level" on
compat_props, and add new test cases to ensure we don't break this
again.

Reported-by: "Guo, Zhiyi" 
Fixes: c39c0edf9bb ("target-i386: Automatically set level/xlevel/xlevel2 when 
needed")
Cc: qemu-sta...@nongnu.org
Acked-by: Michael S. Tsirkin 
Signed-off-by: Eduardo Habkost 
(cherry picked from commit 1f43571604da85c62f25f3ba6d275b1b5ea76ca2)
Signed-off-by: Michael Roth 
---
 include/hw/i386/pc.h  | 42 +-
 tests/test-x86-cpuid-compat.c | 38 ++
 2 files changed, 59 insertions(+), 21 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index f278b3a..564486f 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -558,75 +558,75 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t 
*);
 .value= "off",\
 },{\
 .driver   = "qemu64" "-" TYPE_X86_CPU,\
-.property = "level",\
+.property = "min-level",\
 .value= stringify(4),\
 },{\
 .driver   = "kvm64" "-" TYPE_X86_CPU,\
-.property = "level",\
+.property = "min-level",\
 .value= stringify(5),\
 },{\
 .driver   = "pentium3" "-" TYPE_X86_CPU,\
-.property = "level",\
+.property = "min-level",\
 .value= stringify(2),\
 },{\
 .driver   = "n270" "-" TYPE_X86_CPU,\
-.property = "level",\
+.property = "min-level",\
 .value= stringify(5),\
 },{\
 .driver   = "Conroe" "-" TYPE_X86_CPU,\
-.property = "level",\
+.property = "min-level",\
 .value= stringify(4),\
 },{\
 .driver   = "Penryn" "-" TYPE_X86_CPU,\
-.property = "level",\
+.property = "min-level",\
 .value= stringify(4),\
 },{\
 .driver   = "Nehalem" "-" TYPE_X86_CPU,\
-.property = "level",\
+.property = "min-level",\
 .value= stringify(4),\
 },{\
 .driver   = "n270" "-" TYPE_X86_CPU,\
-.property = "xlevel",\
+.property = "min-xlevel",\
 .value= stringify(0x800a),\
 },{\
 .driver   = "Penryn" "-" TYPE_X86_CPU,\
-.property = "xlevel",\
+.property = "min-xlevel",\
 .value= stringify(0x800a),\
 },{\
 .driver   = "Conroe" "-" TYPE_X86_CPU,\
-.property = "xlevel",\
+.property = "min-xlevel",\
 .value= stringify(0x800a),\
 },{\
 .driver   = "Nehalem" "-" TYPE_X86_CPU,\
-.property = "xlevel",\
+.property = "min-xlevel",\
 .value= stringify(0x800a),\
 },{\
 .driver   = "Westmere" "-" TYPE_X86_CPU,\
-.property = "xlevel",\
+.property = "min-xlevel",\
 .value= stringify(0x800a),\
 },{\
 .driver   = "SandyBridge" "-" TYPE_X86_CPU,\
-.property = "xlevel",\
+.property = "min-xlevel",\
 .value= stringify(0x800a),\
 },{\
 .driver   = "IvyBridge" "-" TYPE_X86_CPU,\
-.property = "xlevel",\
+.property = "min-xlevel",\
 .value= stringify(0x800a),\
 },{\
 .driver   = "Haswell" "-" TYPE_X86_CPU,\
-.property = "xlevel",\
+.property = "min-xlevel",\
 .value= stringify(0x800a),\
 },{\
 .driver   = "Haswell-noTSX" "-" TYPE_X86_CPU,\
-.property = "xlevel",\
+.property = "min-xlevel",\
 .value= stringify(0x800a),\
 },{\
 .driver   = "Broadwell" "-" TYPE_X86_CPU,\
-.property = "xlevel",\
+.property = "min-xlevel",\
 .value= stringify(0x800a),\
 },{\
 .driver   = "Broadwell-noTSX" "-" TYPE_X86_CPU,\
-.property = "xlevel",\
+   

[Qemu-devel] [PATCH 59/79] nbd: Fix regression on resiliency to port scan

2017-08-28 Thread Michael Roth
From: Eric Blake 

Back in qemu 2.5, qemu-nbd was immune to port probes (a transient
server would not quit, regardless of how many probe connections
came and went, until a connection actually negotiated).  But we
broke that in commit ee7d7aa when removing the return value to
nbd_client_new(), although that patch also introduced a bug causing
an assertion failure on a client that fails negotiation.  We then
made it worse during refactoring in commit 1a6245a (a segfault
before we could even assert); the (masked) assertion was cleaned
up in d3780c2 (still in 2.6), and just recently we finally fixed
the segfault ("nbd: Fully intialize client in case of failed
negotiation").  But that still means that ever since we added
TLS support to qemu-nbd, we have been vulnerable to an ill-timed
port-scan being able to cause a denial of service by taking down
qemu-nbd before a real client has a chance to connect.

Since negotiation is now handled asynchronously via coroutines,
we no longer have a synchronous point of return by re-adding a
return value to nbd_client_new().  So this patch instead wires
things up to pass the negotiation status through the close_fn
callback function.

Simple test across two terminals:
$ qemu-nbd -f raw -p 30001 file
$ nmap 127.0.0.1 -p 30001 && \
  qemu-io -c 'r 0 512' -f raw nbd://localhost:30001

Note that this patch does not change what constitutes successful
negotiation (thus, a client must enter transmission phase before
that client can be considered as a reason to terminate the server
when the connection ends).  Perhaps we may want to tweak things
in a later patch to also treat a client that uses NBD_OPT_ABORT
as being a 'successful' negotiation (the client correctly talked
the NBD protocol, and informed us it was not going to use our
export after all), but that's a discussion for another day.

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

Signed-off-by: Eric Blake 
Message-Id: <20170608222617.20376-1-ebl...@redhat.com>
Signed-off-by: Paolo Bonzini 
(cherry picked from commit 0c9390d978cbf61e8f16c9f580fa96b305c43568)
Signed-off-by: Michael Roth 
---
 blockdev-nbd.c  |  6 +-
 include/block/nbd.h |  2 +-
 nbd/server.c| 24 +++-
 qemu-nbd.c  |  4 ++--
 4 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index 8a11807..8d7284a 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -27,6 +27,10 @@ typedef struct NBDServerData {
 
 static NBDServerData *nbd_server;
 
+static void nbd_blockdev_client_closed(NBDClient *client, bool ignored)
+{
+nbd_client_put(client);
+}
 
 static gboolean nbd_accept(QIOChannel *ioc, GIOCondition condition,
gpointer opaque)
@@ -46,7 +50,7 @@ static gboolean nbd_accept(QIOChannel *ioc, GIOCondition 
condition,
 qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server");
 nbd_client_new(NULL, cioc,
nbd_server->tlscreds, NULL,
-   nbd_client_put);
+   nbd_blockdev_client_closed);
 object_unref(OBJECT(cioc));
 return TRUE;
 }
diff --git a/include/block/nbd.h b/include/block/nbd.h
index 3e373f0..b69c30d 100644
--- a/include/block/nbd.h
+++ b/include/block/nbd.h
@@ -160,7 +160,7 @@ void nbd_client_new(NBDExport *exp,
 QIOChannelSocket *sioc,
 QCryptoTLSCreds *tlscreds,
 const char *tlsaclname,
-void (*close)(NBDClient *));
+void (*close_fn)(NBDClient *, bool));
 void nbd_client_get(NBDClient *client);
 void nbd_client_put(NBDClient *client);
 
diff --git a/nbd/server.c b/nbd/server.c
index edfda84..a98bb21 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -81,7 +81,7 @@ static QTAILQ_HEAD(, NBDExport) exports = 
QTAILQ_HEAD_INITIALIZER(exports);
 
 struct NBDClient {
 int refcount;
-void (*close)(NBDClient *client);
+void (*close_fn)(NBDClient *client, bool negotiated);
 
 bool no_zeroes;
 NBDExport *exp;
@@ -796,7 +796,7 @@ void nbd_client_put(NBDClient *client)
 }
 }
 
-static void client_close(NBDClient *client)
+static void client_close(NBDClient *client, bool negotiated)
 {
 if (client->closing) {
 return;
@@ -811,8 +811,8 @@ static void client_close(NBDClient *client)
  NULL);
 
 /* Also tell the client, so that they release their reference.  */
-if (client->close) {
-client->close(client);
+if (client->close_fn) {
+client->close_fn(client, negotiated);
 }
 }
 
@@ -993,7 +993,7 @@ void nbd_export_close(NBDExport *exp)
 
 nbd_export_get(exp);
 QTAILQ_FOREACH_SAFE(client, >clients, next, next) {
-client_close(client);
+client_close(client, true);
 }
 nbd_export_set_name(exp, NULL);
 nbd_export_set_description(exp, NULL);
@@ -1355,7 +1355,7 @@ done:
 
 out:
 

[Qemu-devel] [PATCH 55/79] spapr: fix memory leak in spapr_memory_pre_plug()

2017-08-28 Thread Michael Roth
From: Greg Kurz 

The string returned by object_property_get_str() is dynamically allocated.

(Spotted by Coverity, CID 1375942)

Signed-off-by: Greg Kurz 
Signed-off-by: David Gibson 
(cherry picked from commit 8a9e0e7b890b2598da94646bf6a7272f3d3924de)
Signed-off-by: Michael Roth 
---
 hw/ppc/spapr.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 5564f78..58c15ef 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2547,8 +2547,11 @@ static void spapr_memory_pre_plug(HotplugHandler 
*hotplug_dev, DeviceState *dev,
 if (mem_dev && !kvmppc_is_mem_backend_page_size_ok(mem_dev)) {
 error_setg(errp, "Memory backend has bad page size. "
"Use 'memory-backend-file' with correct mem-path.");
-return;
+goto out;
 }
+
+out:
+g_free(mem_dev);
 }
 
 typedef struct sPAPRDIMMState {
-- 
2.7.4




[Qemu-devel] [PATCH 57/79] commit: Fix use after free in completion

2017-08-28 Thread Michael Roth
From: Kevin Wolf 

The final bdrv_set_backing_hd() could be working on already freed nodes
because the commit job drops its references (through BlockBackends) to
both overlay_bs and top already a bit earlier.

One way to trigger the bug is hot unplugging a disk for which
blockdev_mark_auto_del() cancels the block job.

Fix this by taking BDS-level references while we're still using the
nodes.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Kevin Wolf 
Reviewed-by: John Snow 
(cherry picked from commit 19ebd13ed45ad5d5f277f5914d55b83f13eb09eb)
Signed-off-by: Michael Roth 
---
 block/commit.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/block/commit.c b/block/commit.c
index 76a0d98..3bae46e 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -89,6 +89,10 @@ static void commit_complete(BlockJob *job, void *opaque)
 int ret = data->ret;
 bool remove_commit_top_bs = false;
 
+/* Make sure overlay_bs and top stay around until bdrv_set_backing_hd() */
+bdrv_ref(top);
+bdrv_ref(overlay_bs);
+
 /* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before
  * the normal backing chain can be restored. */
 blk_unref(s->base);
@@ -124,6 +128,9 @@ static void commit_complete(BlockJob *job, void *opaque)
 if (remove_commit_top_bs) {
 bdrv_set_backing_hd(overlay_bs, top, _abort);
 }
+
+bdrv_unref(overlay_bs);
+bdrv_unref(top);
 }
 
 static void coroutine_fn commit_run(void *opaque)
-- 
2.7.4




[Qemu-devel] [PATCH 36/79] s390x/css: catch section mismatch on load

2017-08-28 Thread Michael Roth
From: Halil Pasic 

Prior to the virtio-ccw-2.7 machine (and commit 2a79eb1a), our virtio
devices residing under the virtual-css bus do not have qdev_path based
migration stream identifiers (because their qdev_path is NULL). The ids
are instead generated when the device is registered as a composition of
the so called idstr, which takes the vmsd name as its value, and an
instance_id, which is which is calculated as a maximal instance_id
registered with the same idstr plus one, or zero (if none was registered
previously).

That means, under certain circumstances, one device might try, and even
succeed, to load the state of a different device. This can lead to
trouble.

Let us fail the migration if the above problem is detected during load.

How to reproduce the problem:
1) start qemu-system-s390x making sure you have the following devices
   defined on your command line:
 -device virtio-rng-ccw,id=rng1,devno=fe.0.0001
 -device virtio-rng-ccw,id=rng2,devno=fe.0.0002
2) detach the devices and reattach in reverse order using the monitor:
 (qemu) device_del rng1
 (qemu) device_del rng2
 (qemu) device_add virtio-rng-ccw,id=rng2,devno=fe.0.0002
 (qemu) device_add virtio-rng-ccw,id=rng1,devno=fe.0.0001
3) save the state of the vm into a temporary file and quit QEMU:
 (qemu) migrate "exec:gzip -c > /tmp/tmp_vmstate.gz"
 (qemu) q
4) use your command line from step 1 with
 -incoming "exec:gzip -c -d /tmp/tmp_vmstate.gz"
   appended to reproduce the problem (while trying to to load the saved vm)

CC: qemu-sta...@nongnu.org
Signed-off-by: Halil Pasic 
Reviewed-by: Dong Jia Shi 
Reviewed-by: Cornelia Huck 
Message-Id: <20170518111405.56947-1-pa...@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger 
(cherry picked from commit 8ed179c937830143dc0e03daac30a55272ed89e3)
* removed context dep on d8d98db5
Signed-off-by: Michael Roth 
---
 hw/s390x/css.c| 14 ++
 hw/s390x/virtio-ccw.c |  6 +-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index 37caa98..b24e8b7 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -14,6 +14,7 @@
 #include "qapi/visitor.h"
 #include "hw/qdev.h"
 #include "qemu/bitops.h"
+#include "qemu/error-report.h"
 #include "exec/address-spaces.h"
 #include "cpu.h"
 #include "hw/s390x/ioinst.h"
@@ -1676,13 +1677,26 @@ void subch_device_save(SubchDev *s, QEMUFile *f)
 int subch_device_load(SubchDev *s, QEMUFile *f)
 {
 SubchDev *old_s;
+Error *err = NULL;
 uint16_t old_schid = s->schid;
+uint16_t old_devno = s->devno;
 int i;
 
 s->cssid = qemu_get_byte(f);
 s->ssid = qemu_get_byte(f);
 s->schid = qemu_get_be16(f);
 s->devno = qemu_get_be16(f);
+if (s->devno != old_devno) {
+/* Only possible if machine < 2.7 (no css_dev_path) */
+
+error_setg(, "%x != %x", old_devno,  s->devno);
+error_append_hint(, "Devno mismatch, tried to load wrong section!"
+  " Likely reason: some sequences of plug and unplug"
+  " can break migration for machine versions prior to"
+  " 2.7 (known design flaw).\n");
+error_report_err(err);
+return -EINVAL;
+}
 /* Re-assign subch. */
 if (old_schid != s->schid) {
 old_s = channel_subsys.css[s->cssid]->sch_set[s->ssid]->sch[old_schid];
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 00b3bde..c0c1db8 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -1264,9 +1264,13 @@ static int virtio_ccw_load_config(DeviceState *d, 
QEMUFile *f)
 SubchDev *s = ccw_dev->sch;
 VirtIODevice *vdev = virtio_ccw_get_vdev(s);
 int len;
+int ret;
 
 s->driver_data = dev;
-subch_device_load(s, f);
+ret = subch_device_load(s, f);
+if (ret) {
+return ret;
+}
 len = qemu_get_be32(f);
 if (len != 0) {
 dev->indicators = get_indicator(qemu_get_be64(f), len);
-- 
2.7.4




[Qemu-devel] [PATCH 43/79] tests: Add coverage for recent block geometry fixes

2017-08-28 Thread Michael Roth
From: Eric Blake 

Use blkdebug's new geometry constraints to emulate setups that
have needed past regression fixes: write zeroes asserting
when running through a loopback block device with max-transfer
smaller than cluster size, and discard rounding away portions
of requests not aligned to preferred boundaries.  Also, add
coverage that the block layer is honoring max transfer limits.

For now, a single iotest performs all actions, with the idea
that we can add future blkdebug constraint test cases in the
same file; but it can be split into multiple iotests if we find
reason to run one portion of the test in more setups than what
are possible in the other.

For reference, the final portion of the test (checking whether
discard passes as much as possible to the lowest layers of the
stack) works as follows:

qemu-io: discard 30M at 8001, passed to blkdebug
  blkdebug: discard 511 bytes at 8001, -ENOTSUP (smaller than
blkdebug's 512 align)
  blkdebug: discard 14371328 bytes at 8512, passed to qcow2
qcow2: discard 739840 bytes at 8512, -ENOTSUP (smaller than
qcow2's 1M align)
qcow2: discard 13M bytes at 77M, succeeds
  blkdebug: discard 15M bytes at 90M, passed to qcow2
qcow2: discard 15M bytes at 90M, succeeds
  blkdebug: discard 1356800 bytes at 105M, passed to qcow2
qcow2: discard 1M at 105M, succeeds
qcow2: discard 308224 bytes at 106M, -ENOTSUP (smaller than qcow2's
1M align)
  blkdebug: discard 1 byte at 111457280, -ENOTSUP (smaller than
blkdebug's 512 align)

Signed-off-by: Eric Blake 
Reviewed-by: Max Reitz 
Message-id: 20170429191419.30051-10-ebl...@redhat.com
[mreitz: For cooperation with image locking, add -r to the qemu-io
 invocation which verifies the image content]
Signed-off-by: Max Reitz 

(cherry picked from commit 40812d937392fddc11f72a668aef251039cc15ce)
 Conflicts:
tests/qemu-iotests/group
* dropped context dependency on other test groups
* prereq for 81c219a
Signed-off-by: Michael Roth 
---
 tests/qemu-iotests/177 | 114 +
 tests/qemu-iotests/177.out |  49 +++
 tests/qemu-iotests/group   |   1 +
 3 files changed, 164 insertions(+)
 create mode 100755 tests/qemu-iotests/177
 create mode 100644 tests/qemu-iotests/177.out

diff --git a/tests/qemu-iotests/177 b/tests/qemu-iotests/177
new file mode 100755
index 000..2005c17
--- /dev/null
+++ b/tests/qemu-iotests/177
@@ -0,0 +1,114 @@
+#!/bin/bash
+#
+# Test corner cases with unusual block geometries
+#
+# Copyright (C) 2016-2017 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+#
+
+# creator
+owner=ebl...@redhat.com
+
+seq=`basename $0`
+echo "QA output created by $seq"
+
+here=`pwd`
+status=1   # failure is the default!
+
+_cleanup()
+{
+   _cleanup_test_img
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+_supported_fmt qcow2
+_supported_proto file
+
+CLUSTER_SIZE=1M
+size=128M
+options=driver=blkdebug,image.driver=qcow2
+
+echo
+echo "== setting up files =="
+
+TEST_IMG="$TEST_IMG.base" _make_test_img $size
+$QEMU_IO -c "write -P 11 0 $size" "$TEST_IMG.base" | _filter_qemu_io
+_make_test_img -b "$TEST_IMG.base"
+$QEMU_IO -c "write -P 22 0 $size" "$TEST_IMG" | _filter_qemu_io
+
+# Limited to 64k max-transfer
+echo
+echo "== constrained alignment and max-transfer =="
+limits=align=4k,max-transfer=64k
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
+ -c "write -P 33 1000 128k" -c "read -P 33 1000 128k" | _filter_qemu_io
+
+echo
+echo "== write zero with constrained max-transfer =="
+limits=align=512,max-transfer=64k,opt-write-zero=$CLUSTER_SIZE
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
+ -c "write -z 8003584 2093056" | _filter_qemu_io
+
+# non-power-of-2 write-zero/discard alignments
+echo
+echo "== non-power-of-2 write zeroes limits =="
+
+limits=align=512,opt-write-zero=15M,max-write-zero=15M,opt-discard=15M,max-discard=15M
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
+ -c "write -z 32M 32M" | _filter_qemu_io
+
+echo
+echo "== non-power-of-2 discard limits =="
+
+limits=align=512,opt-write-zero=15M,max-write-zero=15M,opt-discard=15M,max-discard=15M

[Qemu-devel] [PATCH 53/79] target/ppc: fix memory leak in kvmppc_is_mem_backend_page_size_ok()

2017-08-28 Thread Michael Roth
From: Greg Kurz 

The string returned by object_property_get_str() is dynamically allocated.

Signed-off-by: Greg Kurz 
Reviewed-by: Thomas Huth 
Signed-off-by: David Gibson 
(cherry picked from commit 2d3e302ec2246d703ffa8d8f8769a3fa448d8145)
Signed-off-by: Michael Roth 
---
 target/ppc/kvm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 89f3586..b1dd41c 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -423,6 +423,7 @@ bool kvmppc_is_mem_backend_page_size_ok(const char 
*obj_path)
 
 if (mempath) {
 pagesize = qemu_mempath_getpagesize(mempath);
+g_free(mempath);
 } else {
 pagesize = getpagesize();
 }
-- 
2.7.4




[Qemu-devel] [PATCH 52/79] target/ppc: pass const string to kvmppc_is_mem_backend_page_size_ok()

2017-08-28 Thread Michael Roth
From: Greg Kurz 

This function has three implementations. Two are stubs that do nothing
and the third one only passes the obj_path argument to:

Object *object_resolve_path(const char *path, bool *ambiguous);

Signed-off-by: Greg Kurz 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
Signed-off-by: David Gibson 
(cherry picked from commit ec69355beffe138c0f97306e65410e5dbc605554)
Signed-off-by: Michael Roth 
---
 target/ppc/kvm.c | 4 ++--
 target/ppc/kvm_ppc.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 9f1f132..89f3586 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -415,7 +415,7 @@ static void kvm_fixup_page_sizes(PowerPCCPU *cpu)
 }
 }
 
-bool kvmppc_is_mem_backend_page_size_ok(char *obj_path)
+bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path)
 {
 Object *mem_obj = object_resolve_path(obj_path, NULL);
 char *mempath = object_property_get_str(mem_obj, "mem-path", NULL);
@@ -436,7 +436,7 @@ static inline void kvm_fixup_page_sizes(PowerPCCPU *cpu)
 {
 }
 
-bool kvmppc_is_mem_backend_page_size_ok(char *obj_path)
+bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path)
 {
 return true;
 }
diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h
index 8e9f42d..eec5cca 100644
--- a/target/ppc/kvm_ppc.h
+++ b/target/ppc/kvm_ppc.h
@@ -57,7 +57,7 @@ int kvmppc_enable_hwrng(void);
 int kvmppc_put_books_sregs(PowerPCCPU *cpu);
 PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void);
 
-bool kvmppc_is_mem_backend_page_size_ok(char *obj_path);
+bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path);
 
 #else
 
@@ -191,7 +191,7 @@ static inline uint64_t kvmppc_rma_size(uint64_t 
current_size,
 return ram_size;
 }
 
-static inline bool kvmppc_is_mem_backend_page_size_ok(char *obj_path)
+static inline bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path)
 {
 return true;
 }
-- 
2.7.4





[Qemu-devel] [PATCH 34/79] virtio-scsi: Unset hotplug handler when unrealize

2017-08-28 Thread Michael Roth
From: Fam Zheng 

This matches the qbus_set_hotplug_handler in realize, and it releases
the final reference to the embedded VirtIODevice so that it is
properly finalized.

A use-after-free is fixed with this patch, indirectly:
virtio_device_instance_finalize wasn't called at hot-unplug, and the
vdev->listener would be a dangling pointer in the global and the per
address space listener list. See also RHBZ 1449031.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Fam Zheng 
Message-Id: <20170518102808.30046-1-f...@redhat.com>
Signed-off-by: Paolo Bonzini 
(cherry picked from commit 2cbe2de5454cf9af44b620b2b40d56361a12a45f)
Signed-off-by: Michael Roth 
---
 hw/scsi/virtio-scsi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index bd62d08..cb1c123 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -915,6 +915,9 @@ void virtio_scsi_common_unrealize(DeviceState *dev, Error 
**errp)
 
 static void virtio_scsi_device_unrealize(DeviceState *dev, Error **errp)
 {
+VirtIOSCSI *s = VIRTIO_SCSI(dev);
+
+qbus_set_hotplug_handler(BUS(>bus), NULL, _abort);
 virtio_scsi_common_unrealize(dev, errp);
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH 03/79] qemu-img/convert: Always set ret < 0 on error

2017-08-28 Thread Michael Roth
From: Max Reitz 

Otherwise the qemu-img process will exit with EXIT_SUCCESS instead of
EXIT_FAILURE.

Cc: qemu-stable 
Signed-off-by: Max Reitz 
Reviewed-by: Eric Blake 
Reviewed-by: Philippe Mathieu-Daudé 
* applied directly to stable, upstream code has issue fixed via a
  refactoring introduced by 9fd77f9, which isn't targetted for stable
Signed-off-by: Michael Roth 
---
 qemu-img.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/qemu-img.c b/qemu-img.c
index b220cf7..9aa7823 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2069,6 +2069,7 @@ static int img_convert(int argc, char **argv)
 opts = qemu_opts_parse_noisily(_object_opts,
optarg, true);
 if (!opts) {
+ret = -1;
 goto fail_getopt;
 }
 break;
@@ -2081,6 +2082,7 @@ static int img_convert(int argc, char **argv)
 if (qemu_opts_foreach(_object_opts,
   user_creatable_add_opts_foreach,
   NULL, NULL)) {
+ret = -1;
 goto fail_getopt;
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH 04/79] qemu-img/convert: Use @opts for one thing only

2017-08-28 Thread Michael Roth
From: Max Reitz 

After storing the creation options for the new image into @opts, we
fetch some things for our own information, like the backing file name,
or whether to use encryption or preallocation.

With the -n parameter, there will not be any creation options; this is
not too bad because this just means that querying a NULL @opts will
always return the default value.

However, we also use @opts for the --object options. Therefore, @opts is
not necessarily NULL if -n was specified; instead, it may contain those
options. In practice, this probably does not cause any problems because
there most likely is no object that supports any of the parameters we
query here, but this is neither something we should rely on nor does
this variable reuse make the code very nice to read.

Therefore, just use an own variable for the --object options.

Cc: qemu-stable 
Signed-off-by: Max Reitz 
Reviewed-by: Eric Blake 
* applied patch from v1 of series as suggested by author
Signed-off-by: Michael Roth 
---
 qemu-img.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 9aa7823..cfc3bc3 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2065,14 +2065,16 @@ static int img_convert(int argc, char **argv)
 case 'W':
 wr_in_order = false;
 break;
-case OPTION_OBJECT:
-opts = qemu_opts_parse_noisily(_object_opts,
-   optarg, true);
-if (!opts) {
+case OPTION_OBJECT: {
+QemuOpts *object_opts;
+object_opts = qemu_opts_parse_noisily(_object_opts,
+  optarg, true);
+if (!object_opts) {
 ret = -1;
 goto fail_getopt;
 }
 break;
+}
 case OPTION_IMAGE_OPTS:
 image_opts = true;
 break;
-- 
2.7.4




[Qemu-devel] [PATCH 50/79] monitor: fix object_del for command-line-created objects

2017-08-28 Thread Michael Roth
Currently objects specified on the command-line are only partially
cleaned up when 'object_del' is issued in either HMP or QMP: the
object itself is fully finalized, but the QemuOpts are not removed.
This results in the following behavior:

  x86_64-softmmu/qemu-system-x86_64 -monitor stdio \
-object memory-backend-ram,id=ram1,size=256M

  QEMU 2.7.91 monitor - type 'help' for more information
  (qemu) object_del ram1
  (qemu) object_del ram1
  object 'ram1' not found
  (qemu) object_add memory-backend-ram,id=ram1,size=256M
  Duplicate ID 'ram1' for object
  Try "help object_add" for more information

which can be an issue for use-cases like memory hotplug.

This happens on the HMP side because hmp_object_add() attempts to
create a temporary QemuOpts entry with ID 'ram1', which ends up
conflicting with the command-line-created entry, since it was never
cleaned up during the previous hmp_object_del() call.

We address this by adding a check in user_creatable_del(), which
is called by both qmp_object_del() and hmp_object_del() to handle
the actual object cleanup, to determine whether an option group entry
matching the object's ID is present and removing it if it is.

Note that qmp_object_add() never attempts to create a temporary
QemuOpts entry, so it does not encounter the duplicate ID error,
which is why this isn't generally visible in libvirt.

Cc: "Dr. David Alan Gilbert" 
Cc: Markus Armbruster 
Cc: Eric Blake 
Cc: Daniel Berrange 
Cc: qemu-sta...@nongnu.org
Signed-off-by: Michael Roth 
Reviewed-by: Daniel P. Berrange 
Reviewed-by: Markus Armbruster 
Message-Id: <1496531612-22166-3-git-send-email-mdr...@linux.vnet.ibm.com>
Signed-off-by: Markus Armbruster 
(cherry picked from commit c645d5acee0ae022534cb609184277ec2b4a8577)
Signed-off-by: Michael Roth 
---
 qom/object_interfaces.c| 9 +
 tests/check-qom-proplist.c | 4 ++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index d4253a8..ff27e06 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -4,6 +4,7 @@
 #include "qemu/module.h"
 #include "qapi-visit.h"
 #include "qapi/opts-visitor.h"
+#include "qemu/config-file.h"
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
@@ -181,6 +182,14 @@ void user_creatable_del(const char *id, Error **errp)
 error_setg(errp, "object '%s' is in use, can not be deleted", id);
 return;
 }
+
+/*
+ * if object was defined on the command-line, remove its corresponding
+ * option group entry
+ */
+qemu_opts_del(qemu_opts_find(qemu_find_opts_err("object", _abort),
+ id));
+
 object_unparent(obj);
 }
 
diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
index e3b3ae4..8e432e9 100644
--- a/tests/check-qom-proplist.c
+++ b/tests/check-qom-proplist.c
@@ -438,9 +438,9 @@ static void test_dummy_createcmdl(void)
  * check for this in user_creatable_del() and remove the QemuOpts if
  * it is present.
  *
- * FIXME: add an assert to verify that the QemuOpts is cleaned up
- * once the corresponding cleanup code is added.
+ * The below check ensures this works as expected.
  */
+g_assert_null(qemu_opts_find(_object_opts, "dev0"));
 }
 
 static void test_dummy_badenum(void)
-- 
2.7.4




[Qemu-devel] [PATCH 32/79] vvfat: fix qemu-img map and qemu-img convert

2017-08-28 Thread Michael Roth
From: Hervé Poussineau 

- bs->total_sectors is the number of sectors of the whole disk
- s->sector_count is the number of sectors of the FAT partition

This fixes the following assert in qemu-img map:
qemu-img.c:2641: get_block_status: Assertion `nb_sectors' failed.

This also fixes an infinite loop in qemu-img convert.

Fixes: 4480e0f924a42e1db8b8cfcac4d0634dd1bb27a0
Fixes: https://bugs.launchpad.net/qemu/+bug/1599539
Cc: qemu-sta...@nongnu.org
Signed-off-by: Hervé Poussineau 
Reviewed-by: Eric Blake 
Signed-off-by: Kevin Wolf 
(cherry picked from commit 139921aaa77c435104308ad53b631a00c3b65ae8)
Signed-off-by: Michael Roth 
---
 block/vvfat.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index 8b4e4eb..7d08f65 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2958,8 +2958,7 @@ vvfat_co_pwritev(BlockDriverState *bs, uint64_t offset, 
uint64_t bytes,
 static int64_t coroutine_fn vvfat_co_get_block_status(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, int *n, BlockDriverState **file)
 {
-BDRVVVFATState* s = bs->opaque;
-*n = s->sector_count - sector_num;
+*n = bs->total_sectors - sector_num;
 if (*n > nb_sectors) {
 *n = nb_sectors;
 } else if (*n < 0) {
-- 
2.7.4




[Qemu-devel] [PATCH 35/79] e1000e: Fix ICR "Other" causes clear logic

2017-08-28 Thread Michael Roth
From: Sameeh Jubran 

This commit fixes a bug which causes the guest to hang. The bug was
observed upon a "receive overrun" (bit #6 of the ICR register)
interrupt which could be triggered post migration in a heavy traffic
environment. Even though the "receive overrun" bit (#6) is masked out
by the IMS register (refer to the log below) the driver still receives
an interrupt as the "receive overrun" bit (#6) causes the "Other" -
bit #24 of the ICR register - bit to be set as documented below. The
driver handles the interrupt and clears the "Other" bit (#24) but
doesn't clear the "receive overrun" bit (#6) which leads to an
infinite loop. Apparently the Windows driver expects that the "receive
overrun" bit and other ones - documented below - to be cleared when
the "Other" bit (#24) is cleared.

So to sum that up:
1. Bit #6 of the ICR register is set by heavy traffic
2. As a results of setting bit #6, bit #24 is set
3. The driver receives an interrupt for bit 24 (it doesn't receieve an
   interrupt for bit #6 as it is masked out by IMS)
4. The driver handles and clears the interrupt of bit #24
5. Bit #6 is still set.
6. 2 happens all over again

The Interrupt Cause Read - ICR register:

The ICR has the "Other" bit - bit #24 - that is set when one or more
of the following ICR register's bits are set:

LSC - bit #2, RXO - bit #6, MDAC - bit #9, SRPD - bit #16, ACK - bit
#17, MNG - bit #18

This bug can occur with any of these bits depending on the driver's
behaviour and the way it configures the device. However, trying to
reproduce it with any bit other than RX0 is challenging and came to
failure as the drivers don't implement most of these bits, trying to
reproduce it with LSC (Link Status Change - bit #2) bit didn't succeed
too as it seems that Windows handles this bit differently.

Log sample of the storm:

27563@1494850819.411877:e1000e_irq_pending_interrupts ICR PENDING: 0x100 
(ICR: 0x815000c2, IMS: 0x1a4)
27563@1494850819.411900:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.411915:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412380:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412395:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412436:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412441:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412998:e1000e_irq_pending_interrupts ICR PENDING: 0x100 
(ICR: 0x815000c2, IMS: 0x1a4)

* This bug behaviour wasn't observed with the Linux driver.

This commit solves:
https://bugzilla.redhat.com/show_bug.cgi?id=1447935
https://bugzilla.redhat.com/show_bug.cgi?id=1449490

Cc: qemu-sta...@nongnu.org
Signed-off-by: Sameeh Jubran 
Signed-off-by: Jason Wang 
(cherry picked from commit 82342e91b60a4a078811df4e1a545e57abffa11d)
Signed-off-by: Michael Roth 
---
 hw/net/e1000e_core.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
index 28c5be1..8140564 100644
--- a/hw/net/e1000e_core.c
+++ b/hw/net/e1000e_core.c
@@ -2454,14 +2454,20 @@ e1000e_set_ics(E1000ECore *core, int index, uint32_t 
val)
 static void
 e1000e_set_icr(E1000ECore *core, int index, uint32_t val)
 {
+uint32_t icr = 0;
 if ((core->mac[ICR] & E1000_ICR_ASSERTED) &&
 (core->mac[CTRL_EXT] & E1000_CTRL_EXT_IAME)) {
 trace_e1000e_irq_icr_process_iame();
 e1000e_clear_ims_bits(core, core->mac[IAM]);
 }
 
-trace_e1000e_irq_icr_write(val, core->mac[ICR], core->mac[ICR] & ~val);
-core->mac[ICR] &= ~val;
+icr = core->mac[ICR] & ~val;
+/* Windows driver expects that the "receive overrun" bit and other
+ * ones to be cleared when the "Other" bit (#24) is cleared.
+ */
+icr = (val & E1000_ICR_OTHER) ? (icr & ~E1000_ICR_OTHER_CAUSES) : icr;
+trace_e1000e_irq_icr_write(val, core->mac[ICR], icr);
+core->mac[ICR] = icr;
 e1000e_update_interrupt_state(core);
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH 49/79] tests: check-qom-proplist: add checks for cmdline-created objects

2017-08-28 Thread Michael Roth
check-qom-proplist originally added tests for verifying that
object-creation helpers object_new_with_{props,propv} behaved in
similar fashion to the "traditional" method involving setting each
individual property separately after object creation rather than
via a single call.

Another similar "helper" for creating Objects exists in the form of
objects specified via -object command-line parameters. By that
rationale, we extend check-qom-proplist to include similar checks
for command-line-created objects by employing the same
qemu_opts_parse()-based parsing the vl.c employs.

This parser has a side-effect of parsing the object's options into
a QemuOpt structure and registering this in the global QemuOptsList
using the Object's ID. This can conflict with future Object instances
that attempt to use the same ID if we don't ensure this is cleaned
up as part of Object finalization, so we include a FIXME stub to test
for this case, which will then be resolved in a subsequent patch.

Suggested-by: Daniel Berrange 
Cc: "Dr. David Alan Gilbert" 
Cc: Markus Armbruster 
Cc: Eric Blake 
Cc: Daniel Berrange 
Cc: qemu-sta...@nongnu.org
Signed-off-by: Michael Roth 
Reviewed-by: Markus Armbruster 
Message-Id: <1496531612-22166-2-git-send-email-mdr...@linux.vnet.ibm.com>
[Comment formatting tidied up]
Signed-off-by: Markus Armbruster 

(cherry picked from commit a1af255f065ccf3f47a7bfe88f1dbc9eeca36935)
Signed-off-by: Michael Roth 
---
 tests/check-qom-proplist.c | 56 ++
 1 file changed, 56 insertions(+)

diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
index a16cefc..e3b3ae4 100644
--- a/tests/check-qom-proplist.c
+++ b/tests/check-qom-proplist.c
@@ -23,6 +23,9 @@
 #include "qapi/error.h"
 #include "qom/object.h"
 #include "qemu/module.h"
+#include "qemu/option.h"
+#include "qemu/config-file.h"
+#include "qom/object_interfaces.h"
 
 
 #define TYPE_DUMMY "qemu-dummy"
@@ -162,6 +165,10 @@ static const TypeInfo dummy_info = {
 .instance_finalize = dummy_finalize,
 .class_size = sizeof(DummyObjectClass),
 .class_init = dummy_class_init,
+.interfaces = (InterfaceInfo[]) {
+{ TYPE_USER_CREATABLE },
+{ }
+}
 };
 
 
@@ -320,6 +327,14 @@ static const TypeInfo dummy_backend_info = {
 .class_size = sizeof(DummyBackendClass),
 };
 
+static QemuOptsList qemu_object_opts = {
+.name = "object",
+.implied_opt_name = "qom-type",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
+.desc = {
+{ }
+},
+};
 
 
 static void test_dummy_createv(void)
@@ -388,6 +403,46 @@ static void test_dummy_createlist(void)
 object_unparent(OBJECT(dobj));
 }
 
+static void test_dummy_createcmdl(void)
+{
+QemuOpts *opts;
+DummyObject *dobj;
+Error *err = NULL;
+const char *params = TYPE_DUMMY \
+ ",id=dev0," \
+ "bv=yes,sv=Hiss hiss hiss,av=platypus";
+
+qemu_add_opts(_object_opts);
+opts = qemu_opts_parse(_object_opts, params, true, );
+g_assert(err == NULL);
+g_assert(opts);
+
+dobj = DUMMY_OBJECT(user_creatable_add_opts(opts, ));
+g_assert(err == NULL);
+g_assert(dobj);
+g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss");
+g_assert(dobj->bv == true);
+g_assert(dobj->av == DUMMY_PLATYPUS);
+
+user_creatable_del("dev0", );
+g_assert(err == NULL);
+error_free(err);
+
+/*
+ * cmdline-parsing via qemu_opts_parse() results in a QemuOpts entry
+ * corresponding to the Object's ID to be added to the QemuOptsList
+ * for objects. To avoid having this entry conflict with future
+ * Objects using the same ID (which can happen in cases where
+ * qemu_opts_parse() is used to parse the object params, such as
+ * with hmp_object_add() at the time of this comment), we need to
+ * check for this in user_creatable_del() and remove the QemuOpts if
+ * it is present.
+ *
+ * FIXME: add an assert to verify that the QemuOpts is cleaned up
+ * once the corresponding cleanup code is added.
+ */
+}
+
 static void test_dummy_badenum(void)
 {
 Error *err = NULL;
@@ -525,6 +580,7 @@ int main(int argc, char **argv)
 
 g_test_add_func("/qom/proplist/createlist", test_dummy_createlist);
 g_test_add_func("/qom/proplist/createv", test_dummy_createv);
+g_test_add_func("/qom/proplist/createcmdline", test_dummy_createcmdl);
 g_test_add_func("/qom/proplist/badenum", test_dummy_badenum);
 g_test_add_func("/qom/proplist/getenum", test_dummy_getenum);
 g_test_add_func("/qom/proplist/iterator", test_dummy_iterator);
-- 
2.7.4




[Qemu-devel] [PATCH 30/79] curl: avoid recursive locking of BDRVCURLState mutex

2017-08-28 Thread Michael Roth
From: Paolo Bonzini 

The curl driver has a ugly hack where, if it cannot find an empty CURLState,
it just uses aio_poll to wait for one to be empty.  This is probably
buggy when used together with dataplane, and the simplest way to fix it
is to use coroutines instead.

A more immediate effect of the bug however is that it can cause a
recursive call to curl_readv_bh_cb and recursively taking the
BDRVCURLState mutex.  This causes a deadlock.

The fix is to unlock the mutex around aio_poll, but for cleanliness we
should also take the mutex around all calls to curl_init_state, even if
reaching the unlock/lock pair is impossible.  The same is true for
curl_clean_state.

Reported-by: Kun Wei 
Tested-by: Richard W.M. Jones 
Reviewed-by: Max Reitz 
Reviewed-by: Jeff Cody 
Signed-off-by: Paolo Bonzini 
Message-id: 20170515100059.15795-4-pbonz...@redhat.com
Cc: qemu-sta...@nongnu.org
Cc: Jeff Cody 
Signed-off-by: Paolo Bonzini 
Signed-off-by: Jeff Cody 
(cherry picked from commit 456af346297ebef86aa097b3609534d34f3d2f75)
Signed-off-by: Michael Roth 
---
 block/curl.c | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/block/curl.c b/block/curl.c
index 59e69c6..dddf5ef 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -281,6 +281,7 @@ read_end:
 return size * nmemb;
 }
 
+/* Called with s->mutex held.  */
 static int curl_find_buf(BDRVCURLState *s, size_t start, size_t len,
  CURLAIOCB *acb)
 {
@@ -453,6 +454,7 @@ static void curl_multi_timeout_do(void *arg)
 #endif
 }
 
+/* Called with s->mutex held.  */
 static CURLState *curl_init_state(BlockDriverState *bs, BDRVCURLState *s)
 {
 CURLState *state = NULL;
@@ -471,7 +473,9 @@ static CURLState *curl_init_state(BlockDriverState *bs, 
BDRVCURLState *s)
 break;
 }
 if (!state) {
+qemu_mutex_unlock(>mutex);
 aio_poll(bdrv_get_aio_context(bs), true);
+qemu_mutex_lock(>mutex);
 }
 } while(!state);
 
@@ -534,6 +538,7 @@ static CURLState *curl_init_state(BlockDriverState *bs, 
BDRVCURLState *s)
 return state;
 }
 
+/* Called with s->mutex held.  */
 static void curl_clean_state(CURLState *s)
 {
 int j;
@@ -565,6 +570,7 @@ static void curl_detach_aio_context(BlockDriverState *bs)
 BDRVCURLState *s = bs->opaque;
 int i;
 
+qemu_mutex_lock(>mutex);
 for (i = 0; i < CURL_NUM_STATES; i++) {
 if (s->states[i].in_use) {
 curl_clean_state(>states[i]);
@@ -580,6 +586,7 @@ static void curl_detach_aio_context(BlockDriverState *bs)
 curl_multi_cleanup(s->multi);
 s->multi = NULL;
 }
+qemu_mutex_unlock(>mutex);
 
 timer_del(>timer);
 }
@@ -677,6 +684,7 @@ static int curl_open(BlockDriverState *bs, QDict *options, 
int flags,
 return -EROFS;
 }
 
+qemu_mutex_init(>mutex);
 opts = qemu_opts_create(_opts, NULL, 0, _abort);
 qemu_opts_absorb_qdict(opts, options, _err);
 if (local_err) {
@@ -747,7 +755,9 @@ static int curl_open(BlockDriverState *bs, QDict *options, 
int flags,
 DPRINTF("CURL: Opening %s\n", file);
 s->aio_context = bdrv_get_aio_context(bs);
 s->url = g_strdup(file);
+qemu_mutex_lock(>mutex);
 state = curl_init_state(bs, s);
+qemu_mutex_unlock(>mutex);
 if (!state)
 goto out_noclean;
 
@@ -791,11 +801,12 @@ static int curl_open(BlockDriverState *bs, QDict 
*options, int flags,
 }
 DPRINTF("CURL: Size = %zd\n", s->len);
 
+qemu_mutex_lock(>mutex);
 curl_clean_state(state);
+qemu_mutex_unlock(>mutex);
 curl_easy_cleanup(state->curl);
 state->curl = NULL;
 
-qemu_mutex_init(>mutex);
 curl_attach_aio_context(bs, bdrv_get_aio_context(bs));
 
 qemu_opts_del(opts);
@@ -806,6 +817,7 @@ out:
 curl_easy_cleanup(state->curl);
 state->curl = NULL;
 out_noclean:
+qemu_mutex_destroy(>mutex);
 g_free(s->cookie);
 g_free(s->url);
 qemu_opts_del(opts);
-- 
2.7.4




[Qemu-devel] [PATCH 46/79] mirror: Drop permissions on s->target on completion

2017-08-28 Thread Michael Roth
From: Kevin Wolf 

This fixes an assertion failure that was triggered by qemu-iotests 129
on some CI host, while the same test case didn't seem to fail on other
hosts.

Essentially the problem is that the blk_unref(s->target) in
mirror_exit() doesn't necessarily mean that the BlockBackend goes away
immediately. It is possible that the job completion was triggered nested
in mirror_drain(), which looks like this:

BlockBackend *target = s->target;
blk_ref(target);
blk_drain(target);
blk_unref(target);

In this case, the write permissions for s->target are retained until
after blk_drain(), which makes removing mirror_top_bs fail for the
active commit case (can't have a writable backing file in the chain
without the filter driver).

Explicitly dropping the permissions first means that the additional
reference doesn't hurt and the job can complete successfully even if
called from the nested blk_drain().

Cc: qemu-sta...@nongnu.org
Signed-off-by: Kevin Wolf 
Acked-by: Paolo Bonzini 
Reviewed-by: Max Reitz 
(cherry picked from commit 63c8ef289087a225d445319d047501d4fe593687)
Signed-off-by: Michael Roth 
---
 block/mirror.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/block/mirror.c b/block/mirror.c
index 2173a2f..4e8f124 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -514,7 +514,12 @@ static void mirror_exit(BlockJob *job, void *opaque)
 
 /* Remove target parent that still uses BLK_PERM_WRITE/RESIZE before
  * inserting target_bs at s->to_replace, where we might not be able to get
- * these permissions. */
+ * these permissions.
+ *
+ * Note that blk_unref() alone doesn't necessarily drop permissions because
+ * we might be running nested inside mirror_drain(), which takes an extra
+ * reference, so use an explicit blk_set_perm() first. */
+blk_set_perm(s->target, 0, BLK_PERM_ALL, _abort);
 blk_unref(s->target);
 s->target = NULL;
 
-- 
2.7.4




[Qemu-devel] [PATCH 48/79] linuxboot_dma: compile for i486

2017-08-28 Thread Michael Roth
From: Paolo Bonzini 

The ROM uses the cmovne instruction, which is new in Pentium Pro and does not
work when running QEMU with "-cpu 486".  Avoid producing that instruction.

Suggested-by: Richard W.M. Jones 
Suggested-by: Thomas Huth 
Reported-by: Rob Landley 
Cc: qemu-sta...@nongnu.org
Signed-off-by: Paolo Bonzini 
(cherry picked from commit 7e018385103cd7a571b9ea0d6f994af6b1129fe7)
Signed-off-by: Michael Roth 
---
 pc-bios/linuxboot_dma.bin  | Bin 1536 -> 1536 bytes
 pc-bios/optionrom/Makefile |   1 +
 2 files changed, 1 insertion(+)

diff --git a/pc-bios/linuxboot_dma.bin b/pc-bios/linuxboot_dma.bin
index 
218d3ab4a29bfb5ab7125ec7a4d29dad1860c673..d176f62797813e4b926dca9dfce7ce554dc1a4d6
 100644
GIT binary patch
literal 1536
zcmeHFL2J`s82-{_T52KL%w~}udiW-YBE*9t=s~ClrIm^s9^6H6Pf%onr07*+kWd=L
zpW)d<4G1ZESU1FyUDSCf^YYaxioy<}t?!rmu^#*f?mHxJo;-Qp_kHp#Je^o$|2##;
zYs)n)qh6k7XI07O)9TW>>H@3WSgzkI-MW44`qG_Jxhgq7fAt@+rpuZy7{g_FpG^eo
zuoD<7Fjn!zK~Uydy3X@Fj1CnQuA}{tXz$^z=7>a?#S!%6CsARNbiO)h=v+Q~y@5O1
ze8y7!akTy&-YXMV@p3Es`0q*km+)Mtxe(3DE2)a5;c%$H0|Yu~mbnR0C7dKHR7Zsr
zmrccq5lm%U=wXc39gV6@%Jl!9^%vQ9V0A-7aUkNnpxu8npp2ruY0}SsKn=BiGN9Y;
L*>*abWuoMsO(*

literal 1536
zcmeHF#RCxYN|nUh%gpJFME=L9)#^}1F5!ps0f07iy|#(O1W^nf~VP8b!3b3v@l;?V$SuIwL6uYt5>dGyH?(K>6@S?eidI1hgSZ^wky
zNA%Hz@f^krJcQTH!Ptb+b>Z7QOZy_v)9!Gc_A*CUnxyOgP~7<9qN#In@`mGjfw=z$
z*1p4gW?~r|cz_FdqLT)y8y*s0Z-)z#_;!*cE?PD>cN4CX-n(2NP%(`OENoGw|EGqnf#7ASHq-k?KrExJ~
z^CHnSr*VvZO%mMQmY+taei4m+{T$|c^(w4)XlpT*^|#=^eK`aF_0%gE_5j9w)aV=c
zk7$UtO_Fkt>S!)b5N*mx5@orPY(na#Hj4MfwIDj65ohT<|dXkK7E?qHJ9XdoKqMjysh
NXm9N~@Si)N{RVuA8xQ~h

diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
index fa53d9e..a9a9e5e 100644
--- a/pc-bios/optionrom/Makefile
+++ b/pc-bios/optionrom/Makefile
@@ -13,6 +13,7 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
 ifeq ($(lastword $(filter -O%, -O0 $(CFLAGS))),-O0)
 override CFLAGS += -O2
 endif
+override CFLAGS += -march=i486
 
 # Drop -fstack-protector and the like
 QEMU_CFLAGS := $(filter -W%, $(QEMU_CFLAGS)) $(CFLAGS_NOPIE) -ffreestanding
-- 
2.7.4




[Qemu-devel] [PATCH 31/79] stream: fix crash in stream_start() when block_job_create() fails

2017-08-28 Thread Michael Roth
From: Alberto Garcia 

The code that tries to reopen a BlockDriverState in stream_start()
when the creation of a new block job fails crashes because it attempts
to dereference a pointer that is known to be NULL.

This is a regression introduced in a170a91fd3eab6155da39e740381867e,
likely because the code was copied from stream_complete().

Cc: qemu-sta...@nongnu.org
Reported-by: Kashyap Chamarthy 
Signed-off-by: Alberto Garcia 
Tested-by: Kashyap Chamarthy 
Signed-off-by: Kevin Wolf 
(cherry picked from commit 525989a50a70ea0ffa2b1cdf56279765bb2b7de0)
Signed-off-by: Michael Roth 
---
 block/stream.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/stream.c b/block/stream.c
index 0113710..52d329f 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -280,6 +280,6 @@ void stream_start(const char *job_id, BlockDriverState *bs,
 
 fail:
 if (orig_bs_flags != bdrv_get_flags(bs)) {
-bdrv_reopen(bs, s->bs_flags, NULL);
+bdrv_reopen(bs, orig_bs_flags, NULL);
 }
 }
-- 
2.7.4




[Qemu-devel] [PATCH 41/79] blkdebug: Simplify override logic

2017-08-28 Thread Michael Roth
From: Eric Blake 

Rather than store into a local variable, then copy to the struct
if the value is valid, then reporting errors otherwise, it is
simpler to just store into the struct and report errors if the
value is invalid.  This however requires that the struct store
a 64-bit number, rather than a narrower type.  Likewise, setting
a sane errno value in ret prior to the sequence of parsing and
jumping to out: on error makes it easier for the next patch to
add a chain of similar checks.

Signed-off-by: Eric Blake 
Message-id: 20170429191419.30051-8-ebl...@redhat.com
Reviewed-by: Max Reitz 
Signed-off-by: Max Reitz 
(cherry picked from commit 3dc834f8795a46f919d90b1e5369308628858601)
* prereq for 81c219a
Signed-off-by: Michael Roth 
---
 block/blkdebug.c | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/block/blkdebug.c b/block/blkdebug.c
index a3dc5f6..2b934ef 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -38,7 +38,7 @@
 typedef struct BDRVBlkdebugState {
 int state;
 int new_state;
-int align;
+uint64_t align;
 
 /* For blkdebug_refresh_filename() */
 char *config_file;
@@ -353,7 +353,6 @@ static int blkdebug_open(BlockDriverState *bs, QDict 
*options, int flags,
 BDRVBlkdebugState *s = bs->opaque;
 QemuOpts *opts;
 Error *local_err = NULL;
-uint64_t align;
 int ret;
 
 opts = qemu_opts_create(_opts, NULL, 0, _abort);
@@ -387,20 +386,17 @@ static int blkdebug_open(BlockDriverState *bs, QDict 
*options, int flags,
 bs->file->bs->supported_write_flags;
 bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
 bs->file->bs->supported_zero_flags;
+ret = -EINVAL;
 
 /* Set request alignment */
-align = qemu_opt_get_size(opts, "align", 0);
-if (align < INT_MAX && is_power_of_2(align)) {
-s->align = align;
-} else if (align) {
-error_setg(errp, "Invalid alignment");
-ret = -EINVAL;
+s->align = qemu_opt_get_size(opts, "align", 0);
+if (s->align && (s->align >= INT_MAX || !is_power_of_2(s->align))) {
+error_setg(errp, "Cannot meet constraints with align %" PRIu64,
+   s->align);
 goto out;
 }
 
 ret = 0;
-goto out;
-
 out:
 if (ret < 0) {
 g_free(s->config_file);
-- 
2.7.4




[Qemu-devel] [PATCH 28/79] curl: strengthen assertion in curl_clean_state

2017-08-28 Thread Michael Roth
From: Paolo Bonzini 

curl_clean_state should only be called after all AIOCBs have been
completed.  This is not so obvious for the call from curl_detach_aio_context,
so assert that.

Cc: qemu-sta...@nongnu.org
Reviewed-by: Jeff Cody 
Signed-off-by: Paolo Bonzini 
Reviewed-by: Max Reitz 
Message-id: 20170515100059.15795-2-pbonz...@redhat.com
Signed-off-by: Jeff Cody 
(cherry picked from commit 675a775633e68bf8b426a896fea5b93a4f4ff1cc)
Signed-off-by: Michael Roth 
---
 block/curl.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/block/curl.c b/block/curl.c
index aa6e8cc..c6dc4c0 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -532,6 +532,11 @@ static CURLState *curl_init_state(BlockDriverState *bs, 
BDRVCURLState *s)
 
 static void curl_clean_state(CURLState *s)
 {
+int j;
+for (j = 0; j < CURL_NUM_ACB; j++) {
+assert(!s->acb[j]);
+}
+
 if (s->s->multi)
 curl_multi_remove_handle(s->s->multi, s->curl);
 
-- 
2.7.4




[Qemu-devel] [PATCH 47/79] virtio-serial-bus: Unset hotplug handler when unrealize

2017-08-28 Thread Michael Roth
From: Ladi Prosek 

Virtio serial device controls the lifetime of virtio-serial-bus and
virtio-serial-bus links back to the device via its hotplug-handler
property. This extra ref-count prevents the device from getting
finalized, leaving the VirtIODevice memory listener registered and
leading to use-after-free later on.

This patch addresses the same issue as Fam Zheng's
"virtio-scsi: Unset hotplug handler when unrealize"
only for a different virtio device.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Ladi Prosek 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Paolo Bonzini 
Reviewed-by: Fam Zheng 
(cherry picked from commit f811f97040a48358b456b46ecbc9167f0131034f)
Signed-off-by: Michael Roth 
---
 hw/char/virtio-serial-bus.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index d797a67..aa9c11a 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -1121,6 +1121,9 @@ static void virtio_serial_device_unrealize(DeviceState 
*dev, Error **errp)
 timer_free(vser->post_load->timer);
 g_free(vser->post_load);
 }
+
+qbus_set_hotplug_handler(BUS(>bus), NULL, errp);
+
 virtio_cleanup(vdev);
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH 29/79] curl: never invoke callbacks with s->mutex held

2017-08-28 Thread Michael Roth
From: Paolo Bonzini 

All curl callbacks go through curl_multi_do, and hence are called with
s->mutex held.  Note that with comments, and make curl_read_cb drop the
lock before invoking the callback.

Likewise for curl_find_buf, where the callback can be invoked by the
caller.

Cc: qemu-sta...@nongnu.org
Reviewed-by: Jeff Cody 
Signed-off-by: Paolo Bonzini 
Reviewed-by: Max Reitz 
Message-id: 20170515100059.15795-3-pbonz...@redhat.com
Signed-off-by: Jeff Cody 
(cherry picked from commit 34db05e7ffe8d61ca7288b9532ad6e8300853318)
Signed-off-by: Michael Roth 
---
 block/curl.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/block/curl.c b/block/curl.c
index c6dc4c0..59e69c6 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -147,6 +147,7 @@ static void curl_multi_do(void *arg);
 static void curl_multi_read(void *arg);
 
 #ifdef NEED_CURL_TIMER_CALLBACK
+/* Called from curl_multi_do_locked, with s->mutex held.  */
 static int curl_timer_cb(CURLM *multi, long timeout_ms, void *opaque)
 {
 BDRVCURLState *s = opaque;
@@ -163,6 +164,7 @@ static int curl_timer_cb(CURLM *multi, long timeout_ms, 
void *opaque)
 }
 #endif
 
+/* Called from curl_multi_do_locked, with s->mutex held.  */
 static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
 void *userp, void *sp)
 {
@@ -212,6 +214,7 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int 
action,
 return 0;
 }
 
+/* Called from curl_multi_do_locked, with s->mutex held.  */
 static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void 
*opaque)
 {
 BDRVCURLState *s = opaque;
@@ -226,6 +229,7 @@ static size_t curl_header_cb(void *ptr, size_t size, size_t 
nmemb, void *opaque)
 return realsize;
 }
 
+/* Called from curl_multi_do_locked, with s->mutex held.  */
 static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
 {
 CURLState *s = ((CURLState*)opaque);
@@ -264,7 +268,9 @@ static size_t curl_read_cb(void *ptr, size_t size, size_t 
nmemb, void *opaque)
   request_length - offset);
 }
 
+qemu_mutex_unlock(>s->mutex);
 acb->common.cb(acb->common.opaque, 0);
+qemu_mutex_lock(>s->mutex);
 qemu_aio_unref(acb);
 s->acb[i] = NULL;
 }
@@ -305,8 +311,6 @@ static int curl_find_buf(BDRVCURLState *s, size_t start, 
size_t len,
 if (clamped_len < len) {
 qemu_iovec_memset(acb->qiov, clamped_len, 0, len - 
clamped_len);
 }
-acb->common.cb(acb->common.opaque, 0);
-
 return FIND_RET_OK;
 }
 
@@ -832,8 +836,8 @@ static void curl_readv_bh_cb(void *p)
 // we can just call the callback and be done.
 switch (curl_find_buf(s, start, acb->nb_sectors * BDRV_SECTOR_SIZE, acb)) {
 case FIND_RET_OK:
-qemu_aio_unref(acb);
-// fall through
+ret = 0;
+goto out;
 case FIND_RET_WAIT:
 goto out;
 default:
-- 
2.7.4




[Qemu-devel] [PATCH 27/79] target/xtensa: fix return value of read/write simcalls

2017-08-28 Thread Michael Roth
From: Max Filippov 

Return value of read/write simcalls is not calculated correctly in case
of operations crossing page boundary and in case of short reads/writes.
Read and write simcalls should return the size of data actually
read/written or -1 in case of error.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Max Filippov 
(cherry picked from commit 347ec03093f9668a379ef6b7fa1feb332fff039c)
Signed-off-by: Michael Roth 
---
 target/xtensa/xtensa-semi.c | 25 -
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c
index 98ae28c..ffcaf8d 100644
--- a/target/xtensa/xtensa-semi.c
+++ b/target/xtensa/xtensa-semi.c
@@ -166,6 +166,7 @@ void HELPER(simcall)(CPUXtensaState *env)
 uint32_t fd = regs[3];
 uint32_t vaddr = regs[4];
 uint32_t len = regs[5];
+uint32_t len_done = 0;
 
 while (len > 0) {
 hwaddr paddr = cpu_get_phys_page_debug(cs, vaddr);
@@ -174,24 +175,38 @@ void HELPER(simcall)(CPUXtensaState *env)
 uint32_t io_sz = page_left < len ? page_left : len;
 hwaddr sz = io_sz;
 void *buf = cpu_physical_memory_map(paddr, , !is_write);
+uint32_t io_done;
+bool error = false;
 
 if (buf) {
 vaddr += io_sz;
 len -= io_sz;
-regs[2] = is_write ?
+io_done = is_write ?
 write(fd, buf, io_sz) :
 read(fd, buf, io_sz);
 regs[3] = errno_h2g(errno);
-cpu_physical_memory_unmap(buf, sz, !is_write, sz);
-if (regs[2] == -1) {
-break;
+if (io_done == -1) {
+error = true;
+io_done = 0;
 }
+cpu_physical_memory_unmap(buf, sz, !is_write, io_done);
 } else {
-regs[2] = -1;
+error = true;
 regs[3] = TARGET_EINVAL;
 break;
 }
+if (error) {
+if (!len_done) {
+len_done = -1;
+}
+break;
+}
+len_done += io_done;
+if (io_done < io_sz) {
+break;
+}
 }
+regs[2] = len_done;
 }
 break;
 
-- 
2.7.4




[Qemu-devel] [PATCH 42/79] blkdebug: Add ability to override unmap geometries

2017-08-28 Thread Michael Roth
From: Eric Blake 

Make it easier to simulate various unusual hardware setups (for
example, recent commits 3482b9b and b8d0a98 affect the Dell
Equallogic iSCSI with its 15M preferred and maximum unmap and
write zero sizing, or b2f95fe deals with the Linux loopback
block device having a max_transfer of 64k), by allowing blkdebug
to wrap any other device with further restrictions on various
alignments.

Signed-off-by: Eric Blake 
Reviewed-by: Max Reitz 
Message-id: 20170429191419.30051-9-ebl...@redhat.com
Signed-off-by: Max Reitz 
(cherry picked from commit 430b26a82da61876c4eaf559ae02332582968043)
* prereq for 81c219a
Signed-off-by: Michael Roth 
---
 block/blkdebug.c | 96 +++-
 qapi/block-core.json | 33 --
 2 files changed, 125 insertions(+), 4 deletions(-)

diff --git a/block/blkdebug.c b/block/blkdebug.c
index 2b934ef..5ccb9ce 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -39,6 +39,11 @@ typedef struct BDRVBlkdebugState {
 int state;
 int new_state;
 uint64_t align;
+uint64_t max_transfer;
+uint64_t opt_write_zero;
+uint64_t max_write_zero;
+uint64_t opt_discard;
+uint64_t max_discard;
 
 /* For blkdebug_refresh_filename() */
 char *config_file;
@@ -343,6 +348,31 @@ static QemuOptsList runtime_opts = {
 .type = QEMU_OPT_SIZE,
 .help = "Required alignment in bytes",
 },
+{
+.name = "max-transfer",
+.type = QEMU_OPT_SIZE,
+.help = "Maximum transfer size in bytes",
+},
+{
+.name = "opt-write-zero",
+.type = QEMU_OPT_SIZE,
+.help = "Optimum write zero alignment in bytes",
+},
+{
+.name = "max-write-zero",
+.type = QEMU_OPT_SIZE,
+.help = "Maximum write zero size in bytes",
+},
+{
+.name = "opt-discard",
+.type = QEMU_OPT_SIZE,
+.help = "Optimum discard alignment in bytes",
+},
+{
+.name = "max-discard",
+.type = QEMU_OPT_SIZE,
+.help = "Maximum discard size in bytes",
+},
 { /* end of list */ }
 },
 };
@@ -354,6 +384,7 @@ static int blkdebug_open(BlockDriverState *bs, QDict 
*options, int flags,
 QemuOpts *opts;
 Error *local_err = NULL;
 int ret;
+uint64_t align;
 
 opts = qemu_opts_create(_opts, NULL, 0, _abort);
 qemu_opts_absorb_qdict(opts, options, _err);
@@ -388,13 +419,61 @@ static int blkdebug_open(BlockDriverState *bs, QDict 
*options, int flags,
 bs->file->bs->supported_zero_flags;
 ret = -EINVAL;
 
-/* Set request alignment */
+/* Set alignment overrides */
 s->align = qemu_opt_get_size(opts, "align", 0);
 if (s->align && (s->align >= INT_MAX || !is_power_of_2(s->align))) {
 error_setg(errp, "Cannot meet constraints with align %" PRIu64,
s->align);
 goto out;
 }
+align = MAX(s->align, bs->file->bs->bl.request_alignment);
+
+s->max_transfer = qemu_opt_get_size(opts, "max-transfer", 0);
+if (s->max_transfer &&
+(s->max_transfer >= INT_MAX ||
+ !QEMU_IS_ALIGNED(s->max_transfer, align))) {
+error_setg(errp, "Cannot meet constraints with max-transfer %" PRIu64,
+   s->max_transfer);
+goto out;
+}
+
+s->opt_write_zero = qemu_opt_get_size(opts, "opt-write-zero", 0);
+if (s->opt_write_zero &&
+(s->opt_write_zero >= INT_MAX ||
+ !QEMU_IS_ALIGNED(s->opt_write_zero, align))) {
+error_setg(errp, "Cannot meet constraints with opt-write-zero %" 
PRIu64,
+   s->opt_write_zero);
+goto out;
+}
+
+s->max_write_zero = qemu_opt_get_size(opts, "max-write-zero", 0);
+if (s->max_write_zero &&
+(s->max_write_zero >= INT_MAX ||
+ !QEMU_IS_ALIGNED(s->max_write_zero,
+  MAX(s->opt_write_zero, align {
+error_setg(errp, "Cannot meet constraints with max-write-zero %" 
PRIu64,
+   s->max_write_zero);
+goto out;
+}
+
+s->opt_discard = qemu_opt_get_size(opts, "opt-discard", 0);
+if (s->opt_discard &&
+(s->opt_discard >= INT_MAX ||
+ !QEMU_IS_ALIGNED(s->opt_discard, align))) {
+error_setg(errp, "Cannot meet constraints with opt-discard %" PRIu64,
+   s->opt_discard);
+goto out;
+}
+
+s->max_discard = qemu_opt_get_size(opts, "max-discard", 0);
+if (s->max_discard &&
+(s->max_discard >= INT_MAX ||
+ !QEMU_IS_ALIGNED(s->max_discard,
+  MAX(s->opt_discard, align {
+error_setg(errp, "Cannot meet constraints with max-discard %" PRIu64,
+   s->max_discard);
+goto out;
+}
 
 

[Qemu-devel] [PATCH 44/79] block: Simplify BDRV_BLOCK_RAW recursion

2017-08-28 Thread Michael Roth
From: Eric Blake 

Since we are already in coroutine context during the body of
bdrv_co_get_block_status(), we can shave off a few layers of
wrappers when recursing to query the protocol when a format driver
returned BDRV_BLOCK_RAW.

Note that we are already using the correct recursion later on in
the same function, when probing whether the protocol layer is sparse
in order to find out if we can add BDRV_BLOCK_ZERO to an existing
BDRV_BLOCK_DATA|BDRV_BLOCK_OFFSET_VALID.

Signed-off-by: Eric Blake 
Reviewed-by: Max Reitz 
Reviewed-by: Fam Zheng 
Message-id: 20170504173745.27414-1-ebl...@redhat.com
Signed-off-by: Stefan Hajnoczi 
(cherry picked from commit ee29d6adefcca7e76abb124183814ed3acc74fac)
* prereq for 81c219a
Signed-off-by: Michael Roth 
---
 block/io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/io.c b/block/io.c
index a7142e0..fe0c867 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1792,8 +1792,8 @@ static int64_t coroutine_fn 
bdrv_co_get_block_status(BlockDriverState *bs,
 
 if (ret & BDRV_BLOCK_RAW) {
 assert(ret & BDRV_BLOCK_OFFSET_VALID);
-ret = bdrv_get_block_status(*file, ret >> BDRV_SECTOR_BITS,
-*pnum, pnum, file);
+ret = bdrv_co_get_block_status(*file, ret >> BDRV_SECTOR_BITS,
+   *pnum, pnum, file);
 goto out;
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH 25/79] blockdev: use drained_begin/end for qmp_block_resize

2017-08-28 Thread Michael Roth
From: John Snow 

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

If one tries to issue a block_resize while a guest is busy
accessing the disk, it is possible that qemu may deadlock
when invoking aio_poll from both the main loop and the iothread.

Replace another instance of bdrv_drain_all that doesn't
quite belong.

Cc: qemu-sta...@nongnu.org
Suggested-by: Paolo Bonzini 
Signed-off-by: John Snow 
Reviewed-by: Eric Blake 
Reviewed-by: Paolo Bonzini 
Signed-off-by: Kevin Wolf 
(cherry picked from commit 698bdfa07d66b5ec218a60229e58eae1dcde00e5)
Signed-off-by: Michael Roth 
---
 blockdev.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 78e1204..e8a9a65 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2923,10 +2923,9 @@ void qmp_block_resize(bool has_device, const char 
*device,
 goto out;
 }
 
-/* complete all in-flight operations before resizing the device */
-bdrv_drain_all();
-
+bdrv_drained_begin(bs);
 ret = blk_truncate(blk, size, errp);
+bdrv_drained_end(bs);
 
 out:
 blk_unref(blk);
-- 
2.7.4




[Qemu-devel] [PATCH 24/79] block: Add errp to b{lk, drv}_truncate()

2017-08-28 Thread Michael Roth
From: Max Reitz 

For one thing, this allows us to drop the error message generation from
qemu-img.c and blockdev.c and instead have it unified in
bdrv_truncate().

Signed-off-by: Max Reitz 
Message-id: 20170328205129.15138-3-mre...@redhat.com
Reviewed-by: Stefan Hajnoczi 
Signed-off-by: Max Reitz 
(cherry picked from commit ed3d2ec98a33fbdeabc471b11ff807075f07e996)
* prereq for 698bdfa
Signed-off-by: Michael Roth 
---
 block.c| 16 
 block/blkdebug.c   |  2 +-
 block/block-backend.c  |  5 +++--
 block/commit.c |  5 +++--
 block/crypto.c |  2 +-
 block/mirror.c |  2 +-
 block/parallels.c  | 13 -
 block/qcow.c   |  6 +++---
 block/qcow2-refcount.c |  5 -
 block/qcow2.c  | 14 +-
 block/qed.c|  2 +-
 block/raw-format.c |  2 +-
 block/vdi.c|  4 ++--
 block/vhdx-log.c   |  2 +-
 block/vhdx.c   |  6 +++---
 block/vmdk.c   | 13 +++--
 block/vpc.c| 13 +++--
 blockdev.c | 21 +
 include/block/block.h  |  2 +-
 include/sysemu/block-backend.h |  2 +-
 qemu-img.c | 17 -
 qemu-io-cmds.c |  5 +++--
 22 files changed, 73 insertions(+), 86 deletions(-)

diff --git a/block.c b/block.c
index 513e6e5..21cb65e 100644
--- a/block.c
+++ b/block.c
@@ -3262,7 +3262,7 @@ exit:
 /**
  * Truncate file to 'offset' bytes (needed only for file protocols)
  */
-int bdrv_truncate(BdrvChild *child, int64_t offset)
+int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp)
 {
 BlockDriverState *bs = child->bs;
 BlockDriver *drv = bs->drv;
@@ -3274,12 +3274,18 @@ int bdrv_truncate(BdrvChild *child, int64_t offset)
  *cannot assert this permission in that case. */
 // assert(child->perm & BLK_PERM_RESIZE);
 
-if (!drv)
+if (!drv) {
+error_setg(errp, "No medium inserted");
 return -ENOMEDIUM;
-if (!drv->bdrv_truncate)
+}
+if (!drv->bdrv_truncate) {
+error_setg(errp, "Image format driver does not support resize");
 return -ENOTSUP;
-if (bs->read_only)
+}
+if (bs->read_only) {
+error_setg(errp, "Image is read-only");
 return -EACCES;
+}
 
 ret = drv->bdrv_truncate(bs, offset);
 if (ret == 0) {
@@ -3287,6 +3293,8 @@ int bdrv_truncate(BdrvChild *child, int64_t offset)
 bdrv_dirty_bitmap_truncate(bs);
 bdrv_parent_cb_resize(bs);
 ++bs->write_gen;
+} else {
+error_setg_errno(errp, -ret, "Failed to resize image");
 }
 return ret;
 }
diff --git a/block/blkdebug.c b/block/blkdebug.c
index ffc6f1d..46bd08a 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -661,7 +661,7 @@ static int64_t blkdebug_getlength(BlockDriverState *bs)
 
 static int blkdebug_truncate(BlockDriverState *bs, int64_t offset)
 {
-return bdrv_truncate(bs->file, offset);
+return bdrv_truncate(bs->file, offset, NULL);
 }
 
 static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options)
diff --git a/block/block-backend.c b/block/block-backend.c
index 7405024..1e70c4d 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1746,13 +1746,14 @@ int blk_pwrite_compressed(BlockBackend *blk, int64_t 
offset, const void *buf,
BDRV_REQ_WRITE_COMPRESSED);
 }
 
-int blk_truncate(BlockBackend *blk, int64_t offset)
+int blk_truncate(BlockBackend *blk, int64_t offset, Error **errp)
 {
 if (!blk_is_available(blk)) {
+error_setg(errp, "No medium inserted");
 return -ENOMEDIUM;
 }
 
-return bdrv_truncate(blk->root, offset);
+return bdrv_truncate(blk->root, offset, errp);
 }
 
 static void blk_pdiscard_entry(void *opaque)
diff --git a/block/commit.c b/block/commit.c
index 91d2c34..76a0d98 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -151,7 +151,7 @@ static void coroutine_fn commit_run(void *opaque)
 }
 
 if (base_len < s->common.len) {
-ret = blk_truncate(s->base, s->common.len);
+ret = blk_truncate(s->base, s->common.len, NULL);
 if (ret) {
 goto out;
 }
@@ -511,8 +511,9 @@ int bdrv_commit(BlockDriverState *bs)
  * grow the backing file image if possible.  If not possible,
  * we must return an error */
 if (length > backing_length) {
-ret = blk_truncate(backing, length);
+ret = blk_truncate(backing, length, _err);
 if (ret < 0) {
+error_report_err(local_err);
 goto ro_cleanup;
 }
 }
diff --git a/block/crypto.c b/block/crypto.c
index 4a20388..52e4f2b 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ 

[Qemu-devel] [PATCH 37/79] virtio-net: fix wild pointer when remove virtio-net queues

2017-08-28 Thread Michael Roth
From: Yunjian Wang 

The tx_bh or tx_timer will free in virtio_net_del_queue() function, when
removing virtio-net queues if the guest doesn't support multiqueue. But
it might be still referenced by virtio_net_set_status(), which needs to
be set NULL. And also the tx_waiting needs to be set zero to prevent
virtio_net_set_status() accessing tx_bh or tx_timer.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Yunjian Wang 
Signed-off-by: Jason Wang 
(cherry picked from commit f989c30cf834ba8625e98b808eac30e4e7ec5008)
Signed-off-by: Michael Roth 
---
 hw/net/virtio-net.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 7d091c9..98bd683 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1522,9 +1522,12 @@ static void virtio_net_del_queue(VirtIONet *n, int index)
 if (q->tx_timer) {
 timer_del(q->tx_timer);
 timer_free(q->tx_timer);
+q->tx_timer = NULL;
 } else {
 qemu_bh_delete(q->tx_bh);
+q->tx_bh = NULL;
 }
+q->tx_waiting = 0;
 virtio_del_queue(vdev, index * 2 + 1);
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH 21/79] aio: add missing aio_notify() to aio_enable_external()

2017-08-28 Thread Michael Roth
From: Stefan Hajnoczi 

The main loop uses aio_disable_external()/aio_enable_external() to
temporarily disable processing of external AioContext clients like
device emulation.

This allows monitor commands to quiesce I/O and prevent the guest from
submitting new requests while a monitor command is in progress.

The aio_enable_external() API is currently broken when an IOThread is in
aio_poll() waiting for fd activity when the main loop re-enables
external clients.  Incrementing ctx->external_disable_cnt does not wake
the IOThread from ppoll(2) so fd processing remains suspended and leads
to unresponsive emulated devices.

This patch adds an aio_notify() call to aio_enable_external() so the
IOThread is kicked out of ppoll(2) and will re-arm the file descriptors.

The bug can be reproduced as follows:

  $ qemu -M accel=kvm -m 1024 \
 -object iothread,id=iothread0 \
 -device virtio-scsi-pci,iothread=iothread0,id=virtio-scsi-pci0 \
 -drive 
if=none,id=drive0,aio=native,cache=none,format=raw,file=test.img \
 -device scsi-hd,id=scsi-hd0,drive=drive0 \
 -qmp tcp::,server,nowait

  $ scripts/qmp/qmp-shell localhost:
  (qemu) blockdev-snapshot-sync device=drive0 snapshot-file=sn1.qcow2
 mode=absolute-paths format=qcow2

After blockdev-snapshot-sync completes the SCSI disk will be
unresponsive.  This leads to request timeouts inside the guest.

Reported-by: Qianqian Zhu 
Reviewed-by: Fam Zheng 
Signed-off-by: Stefan Hajnoczi 
Message-id: 20170508180705.20609-1-stefa...@redhat.com
Suggested-by: Fam Zheng 
Signed-off-by: Stefan Hajnoczi 
(cherry picked from commit 321d1dba8bef9676a77e9399484e3cd8bf2cf16a)
Signed-off-by: Michael Roth 
---
 include/block/aio.h | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/block/aio.h b/include/block/aio.h
index 406e323..e9aeeae 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -454,8 +454,14 @@ static inline void aio_disable_external(AioContext *ctx)
  */
 static inline void aio_enable_external(AioContext *ctx)
 {
-assert(ctx->external_disable_cnt > 0);
-atomic_dec(>external_disable_cnt);
+int old;
+
+old = atomic_fetch_dec(>external_disable_cnt);
+assert(old > 0);
+if (old == 1) {
+/* Kick event loop so it re-arms file descriptors */
+aio_notify(ctx);
+}
 }
 
 /**
-- 
2.7.4




[Qemu-devel] [PATCH 18/79] qobject: Use simpler QDict/QList scalar insertion macros

2017-08-28 Thread Michael Roth
From: Eric Blake 

We now have macros in place to make it less verbose to add a scalar
to QDict and QList, so use them.

Patch created mechanically via:
  spatch --sp-file scripts/coccinelle/qobject.cocci \
--macro-file scripts/cocci-macro-file.h --dir . --in-place
then touched up manually to fix a couple of '?:' back to original
spacing, as well as avoiding a long line in monitor.c.

Signed-off-by: Eric Blake 
Reviewed-by: Markus Armbruster 
Message-Id: <20170427215821.19397-7-ebl...@redhat.com>
Reviewed-by: Stefan Hajnoczi 
Reviewed-by: Alberto Garcia 
Signed-off-by: Markus Armbruster 
(cherry picked from commit 46f5ac205a9dc5e2c24274c7df371509a286281f)
* prereq for fc0932f
Signed-off-by: Michael Roth 
---
 block.c |  45 +---
 block/blkdebug.c|   6 +-
 block/blkverify.c   |   6 +-
 block/curl.c|   2 +-
 block/file-posix.c  |   8 +--
 block/file-win32.c  |   4 +-
 block/nbd.c |  41 ++-
 block/nfs.c |  43 +---
 block/null.c|   2 +-
 block/qcow2.c   |   4 +-
 block/quorum.c  |   8 +--
 block/rbd.c |  16 ++---
 block/snapshot.c|   2 +-
 block/ssh.c |  16 ++---
 block/vvfat.c   |  10 +--
 blockdev.c  |  30 
 hw/block/xen_disk.c |   2 +-
 hw/usb/xen-usb.c|  12 ++--
 monitor.c   |  23 +++
 qapi/qmp-event.c|   2 +-
 qemu-img.c  |   6 +-
 qemu-io.c   |   2 +-
 qemu-nbd.c  |   2 +-
 qobject/qdict.c |   2 +-
 target/s390x/cpu_models.c   |   4 +-
 tests/check-qdict.c | 134 ++--
 tests/check-qlist.c |   4 +-
 tests/device-introspect-test.c  |   4 +-
 tests/test-qemu-opts.c  |   4 +-
 tests/test-qmp-commands.c   |  24 +++
 tests/test-qmp-event.c  |  30 
 tests/test-qobject-output-visitor.c |   6 +-
 util/qemu-option.c  |   2 +-
 33 files changed, 241 insertions(+), 265 deletions(-)

diff --git a/block.c b/block.c
index f156348..513e6e5 100644
--- a/block.c
+++ b/block.c
@@ -937,16 +937,14 @@ static void update_flags_from_options(int *flags, 
QemuOpts *opts)
 static void update_options_from_flags(QDict *options, int flags)
 {
 if (!qdict_haskey(options, BDRV_OPT_CACHE_DIRECT)) {
-qdict_put(options, BDRV_OPT_CACHE_DIRECT,
-  qbool_from_bool(flags & BDRV_O_NOCACHE));
+qdict_put_bool(options, BDRV_OPT_CACHE_DIRECT, flags & BDRV_O_NOCACHE);
 }
 if (!qdict_haskey(options, BDRV_OPT_CACHE_NO_FLUSH)) {
-qdict_put(options, BDRV_OPT_CACHE_NO_FLUSH,
-  qbool_from_bool(flags & BDRV_O_NO_FLUSH));
+qdict_put_bool(options, BDRV_OPT_CACHE_NO_FLUSH,
+   flags & BDRV_O_NO_FLUSH);
 }
 if (!qdict_haskey(options, BDRV_OPT_READ_ONLY)) {
-qdict_put(options, BDRV_OPT_READ_ONLY,
-  qbool_from_bool(!(flags & BDRV_O_RDWR)));
+qdict_put_bool(options, BDRV_OPT_READ_ONLY, !(flags & BDRV_O_RDWR));
 }
 }
 
@@ -1362,7 +1360,7 @@ static int bdrv_fill_options(QDict **options, const char 
*filename,
 /* Fetch the file name from the options QDict if necessary */
 if (protocol && filename) {
 if (!qdict_haskey(*options, "filename")) {
-qdict_put(*options, "filename", qstring_from_str(filename));
+qdict_put_str(*options, "filename", filename);
 parse_filename = true;
 } else {
 error_setg(errp, "Can't specify 'file' and 'filename' options at "
@@ -1383,7 +1381,7 @@ static int bdrv_fill_options(QDict **options, const char 
*filename,
 }
 
 drvname = drv->format_name;
-qdict_put(*options, "driver", qstring_from_str(drvname));
+qdict_put_str(*options, "driver", drvname);
 } else {
 error_setg(errp, "Must specify either driver or file");
 return -EINVAL;
@@ -2038,7 +2036,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*parent_options,
 }
 
 if (bs->backing_format[0] != '\0' && !qdict_haskey(options, "driver")) {
-qdict_put(options, "driver", qstring_from_str(bs->backing_format));
+qdict_put_str(options, "driver", bs->backing_format);
 }
 
 backing_hd = bdrv_open_inherit(*backing_filename ? backing_filename : NULL,
@@ -2193,12 +2191,9 @@ static BlockDriverState 
*bdrv_append_temp_snapshot(BlockDriverState *bs,
   

[Qemu-devel] [PATCH 26/79] target/xtensa: fix mapping direction in read/write simcalls

2017-08-28 Thread Michael Roth
From: Max Filippov 

Read and write simcalls map physical memory to access I/O buffers, but
'read' simcall need to map it for writing and 'write' simcall need to
map it for reading, i.e. the opposite of what they do now. Fix that.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Max Filippov 
(cherry picked from commit 30c2afd151cbc38c012f7b441088980807183da6)
Signed-off-by: Michael Roth 
---
 target/xtensa/xtensa-semi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c
index a888a9d..98ae28c 100644
--- a/target/xtensa/xtensa-semi.c
+++ b/target/xtensa/xtensa-semi.c
@@ -173,7 +173,7 @@ void HELPER(simcall)(CPUXtensaState *env)
 TARGET_PAGE_SIZE - (vaddr & (TARGET_PAGE_SIZE - 1));
 uint32_t io_sz = page_left < len ? page_left : len;
 hwaddr sz = io_sz;
-void *buf = cpu_physical_memory_map(paddr, , is_write);
+void *buf = cpu_physical_memory_map(paddr, , !is_write);
 
 if (buf) {
 vaddr += io_sz;
@@ -182,7 +182,7 @@ void HELPER(simcall)(CPUXtensaState *env)
 write(fd, buf, io_sz) :
 read(fd, buf, io_sz);
 regs[3] = errno_h2g(errno);
-cpu_physical_memory_unmap(buf, sz, is_write, sz);
+cpu_physical_memory_unmap(buf, sz, !is_write, sz);
 if (regs[2] == -1) {
 break;
 }
-- 
2.7.4




[Qemu-devel] [PATCH 39/79] blkdebug: Refactor error injection

2017-08-28 Thread Michael Roth
From: Eric Blake 

Rather than repeat the logic at each caller of checking if a Rule
exists that warrants an error injection, fold that logic into
inject_error(); and rename it to rule_check() for legibility.
This will help the next patch, which adds two more callers that
need to check rules for the potential of injecting errors.

Signed-off-by: Eric Blake 
Reviewed-by: Max Reitz 
Message-id: 20170429191419.30051-6-ebl...@redhat.com
Signed-off-by: Max Reitz 
(cherry picked from commit d157ed5f7235f3d2d5596a514ad7507b18e24b88)
* prereq for 81c219a
Signed-off-by: Michael Roth 
---
 block/blkdebug.c | 74 +---
 1 file changed, 33 insertions(+), 41 deletions(-)

diff --git a/block/blkdebug.c b/block/blkdebug.c
index b2cee0c..c5d2edb 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -403,11 +403,30 @@ out:
 return ret;
 }
 
-static int inject_error(BlockDriverState *bs, BlkdebugRule *rule)
+static int rule_check(BlockDriverState *bs, uint64_t offset, uint64_t bytes)
 {
 BDRVBlkdebugState *s = bs->opaque;
-int error = rule->options.inject.error;
-bool immediately = rule->options.inject.immediately;
+BlkdebugRule *rule = NULL;
+int error;
+bool immediately;
+
+QSIMPLEQ_FOREACH(rule, >active_rules, active_next) {
+uint64_t inject_offset = rule->options.inject.offset;
+
+if (inject_offset == -1 ||
+(bytes && inject_offset >= offset &&
+ inject_offset < offset + bytes))
+{
+break;
+}
+}
+
+if (!rule || !rule->options.inject.error) {
+return 0;
+}
+
+immediately = rule->options.inject.immediately;
+error = rule->options.inject.error;
 
 if (rule->options.inject.once) {
 QSIMPLEQ_REMOVE(>active_rules, rule, BlkdebugRule, active_next);
@@ -426,8 +445,7 @@ static int coroutine_fn
 blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
QEMUIOVector *qiov, int flags)
 {
-BDRVBlkdebugState *s = bs->opaque;
-BlkdebugRule *rule = NULL;
+int err;
 
 /* Sanity check block layer guarantees */
 assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
@@ -436,18 +454,9 @@ blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, 
uint64_t bytes,
 assert(bytes <= bs->bl.max_transfer);
 }
 
-QSIMPLEQ_FOREACH(rule, >active_rules, active_next) {
-uint64_t inject_offset = rule->options.inject.offset;
-
-if (inject_offset == -1 ||
-(inject_offset >= offset && inject_offset < offset + bytes))
-{
-break;
-}
-}
-
-if (rule && rule->options.inject.error) {
-return inject_error(bs, rule);
+err = rule_check(bs, offset, bytes);
+if (err) {
+return err;
 }
 
 return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);
@@ -457,8 +466,7 @@ static int coroutine_fn
 blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
 QEMUIOVector *qiov, int flags)
 {
-BDRVBlkdebugState *s = bs->opaque;
-BlkdebugRule *rule = NULL;
+int err;
 
 /* Sanity check block layer guarantees */
 assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
@@ -467,18 +475,9 @@ blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, 
uint64_t bytes,
 assert(bytes <= bs->bl.max_transfer);
 }
 
-QSIMPLEQ_FOREACH(rule, >active_rules, active_next) {
-uint64_t inject_offset = rule->options.inject.offset;
-
-if (inject_offset == -1 ||
-(inject_offset >= offset && inject_offset < offset + bytes))
-{
-break;
-}
-}
-
-if (rule && rule->options.inject.error) {
-return inject_error(bs, rule);
+err = rule_check(bs, offset, bytes);
+if (err) {
+return err;
 }
 
 return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags);
@@ -486,17 +485,10 @@ blkdebug_co_pwritev(BlockDriverState *bs, uint64_t 
offset, uint64_t bytes,
 
 static int blkdebug_co_flush(BlockDriverState *bs)
 {
-BDRVBlkdebugState *s = bs->opaque;
-BlkdebugRule *rule = NULL;
-
-QSIMPLEQ_FOREACH(rule, >active_rules, active_next) {
-if (rule->options.inject.offset == -1) {
-break;
-}
-}
+int err = rule_check(bs, 0, 0);
 
-if (rule && rule->options.inject.error) {
-return inject_error(bs, rule);
+if (err) {
+return err;
 }
 
 return bdrv_co_flush(bs->file->bs);
-- 
2.7.4




[Qemu-devel] [PATCH 01/79] qga-win: Enable 'can-offline' field in 'guest-get-vcpus' reply

2017-08-28 Thread Michael Roth
From: Sameeh Jubran 

The QGA schema states:

@can-offline: Whether offlining the VCPU is possible. This member
   is always filled in by the guest agent when the structure
   is returned, and always ignored on input (hence it can be
   omitted then).

Currently 'can-offline' is missing entirely from the reply. This causes
errors in libvirt which is expecting the reply to be compliant with the
schema docs.

BZ#1438735: https://bugzilla.redhat.com/show_bug.cgi?id=1438735

Signed-off-by: Sameeh Jubran 
Reviewed-by: Eric Blake 
Cc: qemu-sta...@nongnu.org
Signed-off-by: Michael Roth 
(cherry picked from commit 54858553def1879a3b0781529fb12a028ba36713)
Signed-off-by: Michael Roth 
---
 qga/commands-win32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 19d72b2..f0d72a0 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -1344,7 +1344,7 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error 
**errp)
 vcpu = g_malloc0(sizeof *vcpu);
 vcpu->logical_id = current++;
 vcpu->online = true;
-vcpu->has_can_offline = false;
+vcpu->has_can_offline = true;
 
 entry = g_malloc0(sizeof *entry);
 entry->value = vcpu;
-- 
2.7.4




[Qemu-devel] [PATCH 22/79] qemu-img: wait for convert coroutines to complete

2017-08-28 Thread Michael Roth
From: Anton Nefedov 

On error path (like i/o error in one of the coroutines), it's required to
  - wait for coroutines completion before cleaning the common structures
  - reenter dependent coroutines so they ever finish

Introduced in 2d9187bc65.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Anton Nefedov 
Reviewed-by: Peter Lieven 
Signed-off-by: Kevin Wolf 
(cherry picked from commit b91127edd0ff96f27f1e58e47f4e9f9d6a0fed02)
Signed-off-by: Michael Roth 
---
 qemu-img.c | 26 +++---
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 2e61561..26ded22 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1761,13 +1761,13 @@ static void coroutine_fn convert_co_do_copy(void 
*opaque)
 qemu_co_mutex_lock(>lock);
 if (s->ret != -EINPROGRESS || s->sector_num >= s->total_sectors) {
 qemu_co_mutex_unlock(>lock);
-goto out;
+break;
 }
 n = convert_iteration_sectors(s, s->sector_num);
 if (n < 0) {
 qemu_co_mutex_unlock(>lock);
 s->ret = n;
-goto out;
+break;
 }
 /* save current sector and allocation status to local variables */
 sector_num = s->sector_num;
@@ -1792,7 +1792,6 @@ static void coroutine_fn convert_co_do_copy(void *opaque)
 error_report("error while reading sector %" PRId64
  ": %s", sector_num, strerror(-ret));
 s->ret = ret;
-goto out;
 }
 } else if (!s->min_sparse && status == BLK_ZERO) {
 status = BLK_DATA;
@@ -1801,22 +1800,20 @@ static void coroutine_fn convert_co_do_copy(void 
*opaque)
 
 if (s->wr_in_order) {
 /* keep writes in order */
-while (s->wr_offs != sector_num) {
-if (s->ret != -EINPROGRESS) {
-goto out;
-}
+while (s->wr_offs != sector_num && s->ret == -EINPROGRESS) {
 s->wait_sector_num[index] = sector_num;
 qemu_coroutine_yield();
 }
 s->wait_sector_num[index] = -1;
 }
 
-ret = convert_co_write(s, sector_num, n, buf, status);
-if (ret < 0) {
-error_report("error while writing sector %" PRId64
- ": %s", sector_num, strerror(-ret));
-s->ret = ret;
-goto out;
+if (s->ret == -EINPROGRESS) {
+ret = convert_co_write(s, sector_num, n, buf, status);
+if (ret < 0) {
+error_report("error while writing sector %" PRId64
+ ": %s", sector_num, strerror(-ret));
+s->ret = ret;
+}
 }
 
 if (s->wr_in_order) {
@@ -1837,7 +1834,6 @@ static void coroutine_fn convert_co_do_copy(void *opaque)
 }
 }
 
-out:
 qemu_vfree(buf);
 s->co[index] = NULL;
 s->running_coroutines--;
@@ -1899,7 +1895,7 @@ static int convert_do_copy(ImgConvertState *s)
 qemu_coroutine_enter(s->co[i]);
 }
 
-while (s->ret == -EINPROGRESS) {
+while (s->running_coroutines) {
 main_loop_wait(false);
 }
 
-- 
2.7.4




[Qemu-devel] [PATCH 20/79] hw/virtio: fix vhost user fails to startup when MQ

2017-08-28 Thread Michael Roth
From: Zhiyong Yang 

 Qemu2.7~2.9 and vhost user for dpdk 17.02 release work together
to cause failures of new connection when negotiating to set MQ.
(one queue pair works well).
   Because there exist some bugs in qemu code when introducing
VHOST_USER_PROTOCOL_F_REPLY_ACK to qemu. When vhost_user_set_mem_table
is invoked to deal with the vhost message VHOST_USER_SET_MEM_TABLE
for the second time, qemu indeed doesn't send the messge (The message
needs to be sent only once)but still will be waiting for dpdk's reply
ack, then, qemu is always freezing, while DPDK is always waiting for
next vhost message from qemu.
  The patch aims to fix the bug, MQ can work well.
  The same bug is found in function vhost_user_net_set_mtu, it is fixed
at the same time.
  DPDK related patch is as following:
  http://www.dpdk.org/dev/patchwork/patch/23955/

Signed-off-by: Zhiyong Yang 
Cc: qemu-sta...@nongnu.org
Fixes: ca525ce5618b ("vhost-user: Introduce a new protocol feature REPLY_ACK.")
Reviewed-by: Maxime Coquelin 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
Tested-by: Jens Freimann 
Reviewed-by: Marc-André Lureau 
(cherry picked from commit 60cd11024f41cc73175e651a2dfe09a3cade56bb)
Signed-off-by: Michael Roth 
---
 hw/virtio/vhost-user.c | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 9334a8a..32a95a8c 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -163,22 +163,26 @@ fail:
 }
 
 static int process_message_reply(struct vhost_dev *dev,
- VhostUserRequest request)
+ VhostUserMsg msg)
 {
-VhostUserMsg msg;
+VhostUserMsg msg_reply;
 
-if (vhost_user_read(dev, ) < 0) {
+if ((msg.flags & VHOST_USER_NEED_REPLY_MASK) == 0) {
+return 0;
+}
+
+if (vhost_user_read(dev, _reply) < 0) {
 return -1;
 }
 
-if (msg.request != request) {
+if (msg_reply.request != msg.request) {
 error_report("Received unexpected msg type."
  "Expected %d received %d",
- request, msg.request);
+ msg.request, msg_reply.request);
 return -1;
 }
 
-return msg.payload.u64 ? -1 : 0;
+return msg_reply.payload.u64 ? -1 : 0;
 }
 
 static bool vhost_user_one_time_request(VhostUserRequest request)
@@ -208,6 +212,7 @@ static int vhost_user_write(struct vhost_dev *dev, 
VhostUserMsg *msg,
  * request, we just ignore it.
  */
 if (vhost_user_one_time_request(msg->request) && dev->vq_index != 0) {
+msg->flags &= ~VHOST_USER_NEED_REPLY_MASK;
 return 0;
 }
 
@@ -320,7 +325,7 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
 }
 
 if (reply_supported) {
-return process_message_reply(dev, msg.request);
+return process_message_reply(dev, msg);
 }
 
 return 0;
@@ -712,7 +717,7 @@ static int vhost_user_net_set_mtu(struct vhost_dev *dev, 
uint16_t mtu)
 
 /* If reply_ack supported, slave has to ack specified MTU is valid */
 if (reply_supported) {
-return process_message_reply(dev, msg.request);
+return process_message_reply(dev, msg);
 }
 
 return 0;
-- 
2.7.4




[Qemu-devel] [PATCH 02/79] dirty-bitmap: Report BlockDirtyInfo.count in bytes, as documented

2017-08-28 Thread Michael Roth
From: Eric Blake 

We've been documenting the value in bytes since its introduction
in commit b9a9b3a4 (v1.3), where it was actually reported in bytes.

Commit e4654d2 (v2.0) then removed things from block/qapi.c, in
preparation for a rewrite to a list of dirty sectors in the next
commit 21b5683 in block.c, but the new code mistakenly started
reporting in sectors.

Fixes: https://bugzilla.redhat.com/1441460

CC: qemu-sta...@nongnu.org
Signed-off-by: Eric Blake 
Reviewed-by: John Snow 
Reviewed-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
(cherry picked from commit 6c98c57af3f4fab85bdf5f01616c91322bd4312a)
Signed-off-by: Michael Roth 
---
 block/dirty-bitmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index 519737c..6d8ce5f 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -345,7 +345,7 @@ BlockDirtyInfoList 
*bdrv_query_dirty_bitmaps(BlockDriverState *bs)
 QLIST_FOREACH(bm, >dirty_bitmaps, list) {
 BlockDirtyInfo *info = g_new0(BlockDirtyInfo, 1);
 BlockDirtyInfoList *entry = g_new0(BlockDirtyInfoList, 1);
-info->count = bdrv_get_dirty_count(bm);
+info->count = bdrv_get_dirty_count(bm) << BDRV_SECTOR_BITS;
 info->granularity = bdrv_dirty_bitmap_granularity(bm);
 info->has_name = !!bm->name;
 info->name = g_strdup(bm->name);
-- 
2.7.4




[Qemu-devel] [PATCH 15/79] qobject: Drop useless QObject casts

2017-08-28 Thread Michael Roth
From: Eric Blake 

We have macros in place to make it less verbose to add a subtype
of QObject to both QDict and QList. While we have made cleanups
like this in the past (see commit fcfcd8ffc, for example), having
it be automated by Coccinelle makes it easier to maintain.

Patch created mechanically via:
  spatch --sp-file scripts/coccinelle/qobject.cocci \
--macro-file scripts/cocci-macro-file.h --dir . --in-place
then I verified that no manual touchups were required.

Signed-off-by: Eric Blake 
Reviewed-by: Stefan Hajnoczi 
Reviewed-by: Alberto Garcia 
Reviewed-by: Markus Armbruster 
Message-Id: <20170427215821.19397-5-ebl...@redhat.com>
Signed-off-by: Markus Armbruster 
(cherry picked from commit de6e7951fe66053dfeaac1a237f7aceb9e079619)
Signed-off-by: Michael Roth 
---
 block.c   | 12 
 block/blkdebug.c  |  4 ++--
 block/blkverify.c |  7 +++
 block/file-posix.c|  6 +++---
 block/file-win32.c|  4 ++--
 block/quorum.c| 16 ++--
 tests/check-qdict.c   | 20 ++--
 tests/test-qmp-commands.c | 24 
 8 files changed, 42 insertions(+), 51 deletions(-)

diff --git a/block.c b/block.c
index 46da908..f156348 100644
--- a/block.c
+++ b/block.c
@@ -4674,11 +4674,9 @@ void bdrv_refresh_filename(BlockDriverState *bs)
  * contain a representation of the filename, therefore the following
  * suffices without querying the (exact_)filename of this BDS. */
 if (bs->file->bs->full_open_options) {
-qdict_put_obj(opts, "driver",
-  QOBJECT(qstring_from_str(drv->format_name)));
+qdict_put(opts, "driver", qstring_from_str(drv->format_name));
 QINCREF(bs->file->bs->full_open_options);
-qdict_put_obj(opts, "file",
-  QOBJECT(bs->file->bs->full_open_options));
+qdict_put(opts, "file", bs->file->bs->full_open_options);
 
 bs->full_open_options = opts;
 } else {
@@ -4694,8 +4692,7 @@ void bdrv_refresh_filename(BlockDriverState *bs)
 
 opts = qdict_new();
 append_open_options(opts, bs);
-qdict_put_obj(opts, "driver",
-  QOBJECT(qstring_from_str(drv->format_name)));
+qdict_put(opts, "driver", qstring_from_str(drv->format_name));
 
 if (bs->exact_filename[0]) {
 /* This may not work for all block protocol drivers (some may
@@ -4705,8 +4702,7 @@ void bdrv_refresh_filename(BlockDriverState *bs)
  * needs some special format of the options QDict, it needs to
  * implement the driver-specific bdrv_refresh_filename() function.
  */
-qdict_put_obj(opts, "filename",
-  QOBJECT(qstring_from_str(bs->exact_filename)));
+qdict_put(opts, "filename", qstring_from_str(bs->exact_filename));
 }
 
 bs->full_open_options = opts;
diff --git a/block/blkdebug.c b/block/blkdebug.c
index cc4a146..42b8d80 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -693,10 +693,10 @@ static void blkdebug_refresh_filename(BlockDriverState 
*bs, QDict *options)
 }
 
 opts = qdict_new();
-qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("blkdebug")));
+qdict_put(opts, "driver", qstring_from_str("blkdebug"));
 
 QINCREF(bs->file->bs->full_open_options);
-qdict_put_obj(opts, "image", QOBJECT(bs->file->bs->full_open_options));
+qdict_put(opts, "image", bs->file->bs->full_open_options);
 
 for (e = qdict_first(options); e; e = qdict_next(options, e)) {
 if (strcmp(qdict_entry_key(e), "x-image")) {
diff --git a/block/blkverify.c b/block/blkverify.c
index af23281..cc29cd2 100644
--- a/block/blkverify.c
+++ b/block/blkverify.c
@@ -288,13 +288,12 @@ static void blkverify_refresh_filename(BlockDriverState 
*bs, QDict *options)
 && s->test_file->bs->full_open_options)
 {
 QDict *opts = qdict_new();
-qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("blkverify")));
+qdict_put(opts, "driver", qstring_from_str("blkverify"));
 
 QINCREF(bs->file->bs->full_open_options);
-qdict_put_obj(opts, "raw", QOBJECT(bs->file->bs->full_open_options));
+qdict_put(opts, "raw", bs->file->bs->full_open_options);
 QINCREF(s->test_file->bs->full_open_options);
-qdict_put_obj(opts, "test",
-  QOBJECT(s->test_file->bs->full_open_options));
+qdict_put(opts, "test", s->test_file->bs->full_open_options);
 
 bs->full_open_options = opts;
 }
diff --git a/block/file-posix.c b/block/file-posix.c
index 0c48968..5370ba0 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -377,7 +377,7 @@ static void raw_parse_filename(const char *filename, QDict 

[Qemu-devel] [PATCH 33/79] virtio: allow broken device to notify guest

2017-08-28 Thread Michael Roth
From: Greg Kurz 

According to section 2.1.2 of the virtio-1 specification:

"The device SHOULD set DEVICE_NEEDS_RESET when it enters an error state that
a reset is needed. If DRIVER_OK is set, after it sets DEVICE_NEEDS_RESET,
the device MUST send a device configuration change notification to the
driver."

Commit "f5ed36635d8f virtio: stop virtqueue processing if device is broken"
introduced a virtio_error() call that just does that:

- internally mark the device as broken
- set the DEVICE_NEEDS_RESET bit in the status
- send a configuration change notification

Unfortunately, virtio_notify_vector(), called by virtio_notify_config(),
returns right away when the device is marked as broken and the notification
isn't sent in this case.

The spec doesn't say whether a broken device can send notifications
in other situations or not. But since the driver isn't supposed to do
anything but to reset the device, it makes sense to keep the check in
virtio_notify_config().

Marking the device as broken AFTER the configuration change notification was
sent is enough to fix the issue.

Signed-off-by: Greg Kurz 
Reviewed-by: Cornelia Huck 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Stefan Hajnoczi 
(cherry picked from commit 66453cff9e5e75344c601cd7674c8ef5fefee8a6)
Signed-off-by: Michael Roth 
---
 hw/virtio/virtio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 03592c5..890b4d7 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2451,12 +2451,12 @@ void GCC_FMT_ATTR(2, 3) virtio_error(VirtIODevice 
*vdev, const char *fmt, ...)
 error_vreport(fmt, ap);
 va_end(ap);
 
-vdev->broken = true;
-
 if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) {
 virtio_set_status(vdev, vdev->status | VIRTIO_CONFIG_S_NEEDS_RESET);
 virtio_notify_config(vdev);
 }
+
+vdev->broken = true;
 }
 
 static void virtio_memory_listener_commit(MemoryListener *listener)
-- 
2.7.4




[Qemu-devel] [PATCH 13/79] 9pfs: local: fix unlink of alien files in mapped-file mode

2017-08-28 Thread Michael Roth
From: Greg Kurz 

When trying to remove a file from a directory, both created in non-mapped
mode, the file remains and EBADF is returned to the guest.

This is a regression introduced by commit "df4938a6651b 9pfs: local:
unlinkat: don't follow symlinks" when fixing CVE-2016-9602. It changed the
way we unlink the metadata file from

ret = remove("$dir/.virtfs_metadata/$name");
if (ret < 0 && errno != ENOENT) {
 /* Error out */
}
/* Ignore absence of metadata */

to

fd = openat("$dir/.virtfs_metadata")
unlinkat(fd, "$name")
if (ret < 0 && errno != ENOENT) {
 /* Error out */
}
/* Ignore absence of metadata */

If $dir was created in non-mapped mode, openat() fails with ENOENT and
we pass -1 to unlinkat(), which fails in turn with EBADF.

We just need to check the return of openat() and ignore ENOENT, in order
to restore the behaviour we had with remove().

Signed-off-by: Greg Kurz 
Reviewed-by: Eric Blake 
[groug: rewrote the comments as suggested by Eric]

(cherry picked from commit 6a87e7929f97b86c5823d4616fa1aa7636b2f116)
Signed-off-by: Michael Roth 
---
 hw/9pfs/9p-local.c | 34 +++---
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index f3ebca4..7a0c383 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -957,6 +957,14 @@ static int local_unlinkat_common(FsContext *ctx, int 
dirfd, const char *name,
 if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
 int map_dirfd;
 
+/* We need to remove the metadata as well:
+ * - the metadata directory if we're removing a directory
+ * - the metadata file in the parent's metadata directory
+ *
+ * If any of these are missing (ie, ENOENT) then we're probably
+ * trying to remove something that wasn't created in mapped-file
+ * mode. We just ignore the error.
+ */
 if (flags == AT_REMOVEDIR) {
 int fd;
 
@@ -964,32 +972,20 @@ static int local_unlinkat_common(FsContext *ctx, int 
dirfd, const char *name,
 if (fd == -1) {
 goto err_out;
 }
-/*
- * If directory remove .virtfs_metadata contained in the
- * directory
- */
 ret = unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR);
 close_preserve_errno(fd);
 if (ret < 0 && errno != ENOENT) {
-/*
- * We didn't had the .virtfs_metadata file. May be file created
- * in non-mapped mode ?. Ignore ENOENT.
- */
 goto err_out;
 }
 }
-/*
- * Now remove the name from parent directory
- * .virtfs_metadata directory.
- */
 map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
-ret = unlinkat(map_dirfd, name, 0);
-close_preserve_errno(map_dirfd);
-if (ret < 0 && errno != ENOENT) {
-/*
- * We didn't had the .virtfs_metadata file. May be file created
- * in non-mapped mode ?. Ignore ENOENT.
- */
+if (map_dirfd != -1) {
+ret = unlinkat(map_dirfd, name, 0);
+close_preserve_errno(map_dirfd);
+if (ret < 0 && errno != ENOENT) {
+goto err_out;
+}
+} else if (errno != ENOENT) {
 goto err_out;
 }
 }
-- 
2.7.4




[Qemu-devel] [PATCH 19/79] block: Reuse bs as backing hd for drive-backup sync=none

2017-08-28 Thread Michael Roth
From: Fam Zheng 

Opening the backing image for the second time is bad, especially here
when it is also in use as the active image as the source. The
drive-backup job itself doesn't read from target->backing for COW,
instead it gets data from the write notifier, so it's not a big problem.
However, exporting the target to NBD etc. won't work, because of the
likely stale metadata cache.

Use BDRV_O_NO_BACKING in this case and manually set up the backing
BdrvChild.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Fam Zheng 
Signed-off-by: Kevin Wolf 
(cherry picked from commit fc0932fdcfc3e5cafa3641e361b681c07f639812)
Signed-off-by: Michael Roth 
---
 blockdev.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/blockdev.c b/blockdev.c
index e2f9c1e..841200e 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3170,6 +3170,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup, 
BlockJobTxn *txn,
 Error *local_err = NULL;
 int flags;
 int64_t size;
+bool set_backing_hd = false;
 
 if (!backup->has_speed) {
 backup->speed = 0;
@@ -3220,6 +3221,8 @@ static BlockJob *do_drive_backup(DriveBackup *backup, 
BlockJobTxn *txn,
 }
 if (backup->sync == MIRROR_SYNC_MODE_NONE) {
 source = bs;
+flags |= BDRV_O_NO_BACKING;
+set_backing_hd = true;
 }
 
 size = bdrv_getlength(bs);
@@ -3246,7 +3249,9 @@ static BlockJob *do_drive_backup(DriveBackup *backup, 
BlockJobTxn *txn,
 }
 
 if (backup->format) {
-options = qdict_new();
+if (!options) {
+options = qdict_new();
+}
 qdict_put_str(options, "driver", backup->format);
 }
 
@@ -3257,6 +3262,14 @@ static BlockJob *do_drive_backup(DriveBackup *backup, 
BlockJobTxn *txn,
 
 bdrv_set_aio_context(target_bs, aio_context);
 
+if (set_backing_hd) {
+bdrv_set_backing_hd(target_bs, source, _err);
+if (local_err) {
+bdrv_unref(target_bs);
+goto out;
+}
+}
+
 if (backup->has_bitmap) {
 bmap = bdrv_find_dirty_bitmap(bs, backup->bitmap);
 if (!bmap) {
-- 
2.7.4




[Qemu-devel] [PATCH 16/79] qobject: Add helper macros for common scalar insertions

2017-08-28 Thread Michael Roth
From: Eric Blake 

Rather than making lots of callers wrap a scalar in a QInt, QString,
or QBool, provide helper macros that do the wrapping automatically.

Update the Coccinelle script to make mass conversions easy, although
the conversion itself will be done as a separate patches to ease
review and backport efforts.

Signed-off-by: Eric Blake 
Reviewed-by: Markus Armbruster 
Message-Id: <20170427215821.19397-6-ebl...@redhat.com>
Signed-off-by: Markus Armbruster 
(cherry picked from commit a92c21591b5bb9543996538f14854ca6b528318b)
Signed-off-by: Michael Roth 
---
 include/qapi/qmp/qdict.h |  8 
 include/qapi/qmp/qlist.h |  8 
 scripts/coccinelle/qobject.cocci | 22 ++
 3 files changed, 38 insertions(+)

diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h
index fe9a4c5..188440a 100644
--- a/include/qapi/qmp/qdict.h
+++ b/include/qapi/qmp/qdict.h
@@ -52,6 +52,14 @@ void qdict_destroy_obj(QObject *obj);
 #define qdict_put(qdict, key, obj) \
 qdict_put_obj(qdict, key, QOBJECT(obj))
 
+/* Helpers for int, bool, and string */
+#define qdict_put_int(qdict, key, value) \
+qdict_put(qdict, key, qint_from_int(value))
+#define qdict_put_bool(qdict, key, value) \
+qdict_put(qdict, key, qbool_from_bool(value))
+#define qdict_put_str(qdict, key, value) \
+qdict_put(qdict, key, qstring_from_str(value))
+
 /* High level helpers */
 double qdict_get_double(const QDict *qdict, const char *key);
 int64_t qdict_get_int(const QDict *qdict, const char *key);
diff --git a/include/qapi/qmp/qlist.h b/include/qapi/qmp/qlist.h
index a84117e..5dc4ed9 100644
--- a/include/qapi/qmp/qlist.h
+++ b/include/qapi/qmp/qlist.h
@@ -29,6 +29,14 @@ typedef struct QList {
 #define qlist_append(qlist, obj) \
 qlist_append_obj(qlist, QOBJECT(obj))
 
+/* Helpers for int, bool, and string */
+#define qlist_append_int(qlist, value) \
+qlist_append(qlist, qint_from_int(value))
+#define qlist_append_bool(qlist, value) \
+qlist_append(qlist, qbool_from_bool(value))
+#define qlist_append_str(qlist, value) \
+qlist_append(qlist, qstring_from_str(value))
+
 #define QLIST_FOREACH_ENTRY(qlist, var) \
 for ((var) = ((qlist)->head.tqh_first); \
 (var);  \
diff --git a/scripts/coccinelle/qobject.cocci b/scripts/coccinelle/qobject.cocci
index aa899e2..97703a4 100644
--- a/scripts/coccinelle/qobject.cocci
+++ b/scripts/coccinelle/qobject.cocci
@@ -2,12 +2,34 @@
 @@
 expression Obj, Key, E;
 @@
+(
 - qdict_put_obj(Obj, Key, QOBJECT(E));
 + qdict_put(Obj, Key, E);
+|
+- qdict_put(Obj, Key, qint_from_int(E));
++ qdict_put_int(Obj, Key, E);
+|
+- qdict_put(Obj, Key, qbool_from_bool(E));
++ qdict_put_bool(Obj, Key, E);
+|
+- qdict_put(Obj, Key, qstring_from_str(E));
++ qdict_put_str(Obj, Key, E);
+)
 
 // Use QList macros where they make sense
 @@
 expression Obj, E;
 @@
+(
 - qlist_append_obj(Obj, QOBJECT(E));
 + qlist_append(Obj, E);
+|
+- qlist_append(Obj, qint_from_int(E));
++ qlist_append_int(Obj, E);
+|
+- qlist_append(Obj, qbool_from_bool(E));
++ qlist_append_bool(Obj, E);
+|
+- qlist_append(Obj, qstring_from_str(E));
++ qlist_append_str(Obj, E);
+)
-- 
2.7.4




  1   2   3   >