RE: [PATCH] contrib/elf2dmp: prevent uninitialized warning

2020-03-06 Thread Chenqun (kuhn)

>-Original Message-
>From: Viktor Prutyanov [mailto:viktor.prutya...@phystech.edu]
>Sent: Friday, March 6, 2020 7:48 PM
>To: Chenqun (kuhn) 
>Cc: qemu-triv...@nongnu.org; pbonz...@redhat.com; qemu-
>de...@nongnu.org; Zhanghailiang 
>Subject: Re: [PATCH] contrib/elf2dmp: prevent uninitialized warning
>
>On Fri, 6 Mar 2020 02:18:07 +
>"Chenqun (kuhn)"  wrote:
>
>> >-Original Message-
>> >From: Viktor Prutyanov [mailto:viktor.prutya...@phystech.edu]
>> >Sent: Friday, March 6, 2020 2:59 AM
>> >To: Chenqun (kuhn) 
>> >Cc: qemu-devel@nongnu.org; pbonz...@redhat.com; Zhanghailiang
>> >; qemu-triv...@nongnu.org
>> >Subject: Re: [PATCH] contrib/elf2dmp: prevent uninitialized warning
>> >
>> >On Fri, 7 Feb 2020 12:16:01 +0800
>> > wrote:
>> >
>> >> From: Chen Qun 
>> >>
>> >> Fix compilation warnings:
>> >> contrib/elf2dmp/main.c:66:17: warning: ‘KdpDataBlockEncoded’ may be
>> >> used uninitialized in this function [-Wmaybe-uninitialized]
>> >>  block = __builtin_bswap64(block ^ kdbe) ^ kwa;
>> >>  ^~~
>> >> contrib/elf2dmp/main.c:78:24: note: ‘KdpDataBlockEncoded’ was
>> >> declared here uint64_t kwn, kwa, KdpDataBlockEncoded;
>> >> ^~~
>> >>
>> >> Reported-by: Euler Robot 
>> >> Signed-off-by: Chen Qun 
>> >> ---
>> >>  contrib/elf2dmp/main.c | 25 -
>> >>  1 file changed, 12 insertions(+), 13 deletions(-)
>> >>
>> >> diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index
>> >> 9a2dbc2902..203b9e6d04 100644
>> >> --- a/contrib/elf2dmp/main.c
>> >> +++ b/contrib/elf2dmp/main.c
>> >> @@ -76,6 +76,7 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t
>> >> KernBase, struct pdb_reader *pdb, DBGKD_DEBUG_DATA_HEADER64
>> >kdbg_hdr;
>> >>  bool decode = false;
>> >>  uint64_t kwn, kwa, KdpDataBlockEncoded;
>> >> +uint64_t KiWaitNever, KiWaitAlways;
>> >>
>> >>  if (va_space_rw(vs,
>> >>  KdDebuggerDataBlock + offsetof(KDDEBUGGER_DATA64,
>> >> Header), @@ -84,21 +85,19 @@ static KDDEBUGGER_DATA64
>> >> *get_kdbg(uint64_t KernBase, struct pdb_reader *pdb, return NULL;
>> >>  }
>> >>
>> >> -if (memcmp(&kdbg_hdr.OwnerTag, OwnerTag, sizeof(OwnerTag))) {
>> >> -uint64_t KiWaitNever, KiWaitAlways;
>> >> -
>> >> -decode = true;
>> >> +if (!SYM_RESOLVE(KernBase, pdb, KiWaitNever) ||
>> >> +!SYM_RESOLVE(KernBase, pdb, KiWaitAlways) ||
>> >> +!SYM_RESOLVE(KernBase, pdb, KdpDataBlockEncoded)) {
>> >> +return NULL;
>> >> +}
>> >>
>> >> -if (!SYM_RESOLVE(KernBase, pdb, KiWaitNever) ||
>> >> -!SYM_RESOLVE(KernBase, pdb, KiWaitAlways) ||
>> >> -!SYM_RESOLVE(KernBase, pdb, KdpDataBlockEncoded))
>> >> {
>> >> -return NULL;
>> >> -}
>> >> +if (va_space_rw(vs, KiWaitNever, &kwn, sizeof(kwn), 0) ||
>> >> +va_space_rw(vs, KiWaitAlways, &kwa, sizeof(kwa), 0)) {
>> >> +return NULL;
>> >> +}
>> >>
>> >> -if (va_space_rw(vs, KiWaitNever, &kwn, sizeof(kwn), 0) ||
>> >> -va_space_rw(vs, KiWaitAlways, &kwa, sizeof(kwa),
>> >> 0)) {
>> >> -return NULL;
>> >> -}
>> >> +if (memcmp(&kdbg_hdr.OwnerTag, OwnerTag, sizeof(OwnerTag))) {
>> >> +decode = true;
>> >>
>> >>  printf("[KiWaitNever] = 0x%016"PRIx64"\n", kwn);
>> >>  printf("[KiWaitAlways] = 0x%016"PRIx64"\n", kwa);
>> >
>> >Hi!
>> >
>> >I suppose the problem is in your compiler, because kdbg_decode() is
>> >only used when KdpDataBlockEncoded is already initialized by
>> >SYM_RESOLVE().
>> >
>> Hi  Viktor,
>>
>>I know it's actually initialized when  'decode = true;',
>> otherwise ' return kdbg;'  no need to initialize.
>>  But usually the compiler cannot understand it, because it seems
>> that the initialization is only in the if() statement.
>
>As for me, my GCC 9.2.1 doesn't show any warning while building elf2dmp.
>
Maybe you are right, my GCC version lower( 7.3.0).

>
>> If we put the initialization outside the if() statement, it might
>> looks better without affecting the functionality ?
>
>For now, your original patch affects the functionality. The utility tries to
>resolve symbols as little as possible during conversion, because we don't
>know exactly how Windows kernel works. This is the reason why KDBG
>header should be checked before resolving 3 symbols.
>
OK ,  let's drop this patch.

Thanks.
>>
>> Thanks.
>> >--
>> >Viktor Prutyanov
>
>
>
>--
>Viktor Prutyanov


Re: [PATCH v7 06/10] iotests: limit line length to 79 chars

2020-03-06 Thread Markus Armbruster
Kevin Wolf  writes:

> Am 05.03.2020 um 19:25 hat John Snow geschrieben:
[...]
>> So in summary:
>> 
>> - Avoid nested hanging indents from format operators
>> - Use a line break before the % format operator.
>> - OPTIONALLY(?), use a hanging indent for the entire format string to
>> reduce nesting depth.
>
> Yes, though I don't think of it as a special case for format strings. So
> I would phrase it like this:
>
> - Don't use hanging indent for any nested parentheses unless the outer
>   parentheses use hanging indents, too.
> - Use a line break before binary operators.
> - OPTIONALLY, use a hanging indent for the top level(s) to reduce
>   nesting depth.
>
> The first one is the only rule that involves some interpretation of
> PEP-8, the rest seems to be its unambiguous recommendation.
>
> Anyway, so I would apply the exact same rules to the following (imagine
> even longer expressions, especially the last example doesn't make sense
> with the short numbers):
>
> * bad:
> really_long_function_name(-1234567890 + 987654321 * (
> 1337 / 42))

Definitely bad.

> * ok:
> really_long_function_name(-1234567890 + 987654321
>   * (1337 / 42))
>
> * ok:
> really_long_function_name(
> -1234567890 + 987654321
> * (1337 / 42))

Yup.

> * ok:
> really_long_function_name(
> -1234567890 + 987654321 * (
> 1337 / 42))

Okay, although when you need this, chances are there's just too much
going on in that argument list.

>> e.g., either this form:
>> (using a line break before the binary operator and nesting to the
>> argument level)
>> 
>> write('hello %s'
>>   % (world,))
>> 
>> 
>> or optionally this form if it buys you a little more room:
>> (using a hanging indent of 4 spaces and nesting arguments at that level)
>> 
>> write(
>> 'hello %s'
>> % ('world',))
>> 
>> 
>> but not ever this form:
>> (Using a hanging indent of 4 spaces from the opening paren of the format
>> operand)
>> 
>> write('hello %s' % (
>> 'world',))
>> 
>> 
>> 
>> yea/nea?
>> 
>> (Kevin, Philippe, Markus, Max)
>
> Looks good to me.

Me too.




Re: [PATCH v4 1/5] target/riscv: add vector unit stride load and store instructions

2020-03-06 Thread LIU Zhiwei




On 2020/2/28 3:17, Richard Henderson wrote:

On 2/25/20 2:35 AM, LIU Zhiwei wrote:

+static bool vext_check_reg(DisasContext *s, uint32_t reg, bool widen)
+{
+int legal = widen ? 2 << s->lmul : 1 << s->lmul;
+
+return !((s->lmul == 0x3 && widen) || (reg % legal));
+}
+
+static bool vext_check_overlap_mask(DisasContext *s, uint32_t vd, bool vm)
+{
+return !(s->lmul > 1 && vm == 0 && vd == 0);
+}
+
+static bool vext_check_nf(DisasContext *s, uint32_t nf)
+{
+return s->lmul * (nf + 1) <= 8;
+}

Some commentary would be good here, quoting the rule being applied.  E.g. "The
destination vector register group for a masked vector instruction can only
overlap the source mask regis-
ter (v0) when LMUL=1. (Section 5.3)"


+static bool ld_us_op(DisasContext *s, arg_r2nfvm *a, uint8_t seq)
+{
+uint8_t nf = a->nf + 1;

Perhaps NF should have the +1 done during decode, so that it cannot be
forgotten here or elsewhere.  E.g.

%nf  31:3  !function=ex_plus_1
@r2_nfvm ... ... vm:1 . . ... . ... \
  &r2nfvm %nf %rs1 %rd

Where ex_plus_1 is the obvious modification of ex_shift_1().


+static inline uint32_t vext_nf(uint32_t desc)
+{
+return (simd_data(desc) >> 11) & 0xf;
+}
+
+static inline uint32_t vext_mlen(uint32_t desc)
+{
+return simd_data(desc) & 0xff;
+}
+
+static inline uint32_t vext_vm(uint32_t desc)
+{
+return (simd_data(desc) >> 8) & 0x1;
+}
+
+static inline uint32_t vext_lmul(uint32_t desc)
+{
+return (simd_data(desc) >> 9) & 0x3;
+}

You should use FIELD() to define the fields, and then use FIELD_EX32 and
FIELD_DP32 to reference them.

I define fields shared between vector helpers and decode code.
FIELD(VDATA, MLEN, 0, 8)
FIELD(VDATA, VM, 8, 1)
FIELD(VDATA, LMUL, 9, 2)
FIELD(VDATA, NF, 11, 4)

But I can't find a  good place to place the fields. There is not a 
"translate.h" in target/riscv.

 Is cpu.h OK?

Zhiwei

+/*
+ * This function checks watchpoint before real load operation.
+ *
+ * In softmmu mode, the TLB API probe_access is enough for watchpoint check.
+ * In user mode, there is no watchpoint support now.
+ *
+ * It will triggle an exception if there is no mapping in TLB

trigger.


+ * and page table walk can't fill the TLB entry. Then the guest
+ * software can return here after process the exception or never return.
+ */
+static void probe_read_access(CPURISCVState *env, target_ulong addr,
+target_ulong len, uintptr_t ra)
+{
+while (len) {
+const target_ulong pagelen = -(addr | TARGET_PAGE_MASK);
+const target_ulong curlen = MIN(pagelen, len);
+
+probe_read(env, addr, curlen, cpu_mmu_index(env, false), ra);
+addr += curlen;
+len -= curlen;
+}
+}
+
+static void probe_write_access(CPURISCVState *env, target_ulong addr,
+target_ulong len, uintptr_t ra)
+{
+while (len) {
+const target_ulong pagelen = -(addr | TARGET_PAGE_MASK);
+const target_ulong curlen = MIN(pagelen, len);
+
+probe_write(env, addr, curlen, cpu_mmu_index(env, false), ra);
+addr += curlen;
+len -= curlen;
+}
+}

A loop is overkill -- the access cannot span to 3 pages.  These two functions
can be merged using probe_access and MMU_DATA_{LOAD,STORE}.


+
+#ifdef HOST_WORDS_BIGENDIAN
+static void vext_clear(void *tail, uint32_t cnt, uint32_t tot)
+{
+/*
+ * Split the remaining range to two parts.
+ * The first part is in the last uint64_t unit.
+ * The second part start from the next uint64_t unit.
+ */
+int part1 = 0, part2 = tot - cnt;
+if (cnt % 64) {
+part1 = 64 - (cnt % 64);
+part2 = tot - cnt - part1;
+memset(tail & ~(63ULL), 0, part1);
+memset((tail + 64) & ~(63ULL), 0, part2);

You're confusing bit and byte offsets -- cnt and tot are both byte offsets.


+static inline int vext_elem_mask(void *v0, int mlen, int index)
+{
+
+int idx = (index * mlen) / 8;
+int pos = (index * mlen) % 8;
+
+switch (mlen) {
+case 8:
+return *((uint8_t *)v0 + H1(index)) & 0x1;
+case 16:
+return *((uint16_t *)v0 + H2(index)) & 0x1;
+case 32:
+return *((uint32_t *)v0 + H4(index)) & 0x1;
+case 64:
+return *((uint64_t *)v0 + index) & 0x1;
+default:
+return (*((uint8_t *)v0 + H1(idx)) >> pos) & 0x1;
+}

This is not what I had in mind, and looks wrong as well.

 int idx = (index * mlen) / 64;
 int pos = (index * mlen) % 64;
 return (((uint64_t *)v0)[idx] >> pos) & 1;

You also might consider passing log2(mlen), so the multiplication could be
strength-reduced to a shift.


+#define GEN_VEXT_LD_ELEM(NAME, MTYPE, ETYPE, H, LDSUF)  \
+static void vext_##NAME##_ld_elem(CPURISCVState *env, abi_ptr addr, \
+uint32_t idx, void *vd, uintptr_t retaddr)  \
+{   \
+int mmu_idx = cpu_mmu_index(env, false);\
+MTYPE data;  

Re: [PATCH v4 2/5] target/riscv: add vector stride load and store instructions

2020-03-06 Thread LIU Zhiwei




On 2020/2/28 3:36, Richard Henderson wrote:

On 2/25/20 2:35 AM, LIU Zhiwei wrote:

+GEN_VEXT_LD_ELEM(vlsb_v_b, int8_t,  int8_t,  H1, ldsb)
+GEN_VEXT_LD_ELEM(vlsb_v_h, int8_t,  int16_t, H2, ldsb)
+GEN_VEXT_LD_ELEM(vlsb_v_w, int8_t,  int32_t, H4, ldsb)
+GEN_VEXT_LD_ELEM(vlsb_v_d, int8_t,  int64_t, H8, ldsb)
+GEN_VEXT_LD_ELEM(vlsh_v_h, int16_t, int16_t, H2, ldsw)
+GEN_VEXT_LD_ELEM(vlsh_v_w, int16_t, int32_t, H4, ldsw)
+GEN_VEXT_LD_ELEM(vlsh_v_d, int16_t, int64_t, H8, ldsw)
+GEN_VEXT_LD_ELEM(vlsw_v_w, int32_t, int32_t, H4, ldl)
+GEN_VEXT_LD_ELEM(vlsw_v_d, int32_t, int64_t, H8, ldl)
+GEN_VEXT_LD_ELEM(vlse_v_b, int8_t,  int8_t,  H1, ldsb)
+GEN_VEXT_LD_ELEM(vlse_v_h, int16_t, int16_t, H2, ldsw)
+GEN_VEXT_LD_ELEM(vlse_v_w, int32_t, int32_t, H4, ldl)
+GEN_VEXT_LD_ELEM(vlse_v_d, int64_t, int64_t, H8, ldq)
+GEN_VEXT_LD_ELEM(vlsbu_v_b, uint8_t,  uint8_t,  H1, ldub)
+GEN_VEXT_LD_ELEM(vlsbu_v_h, uint8_t,  uint16_t, H2, ldub)
+GEN_VEXT_LD_ELEM(vlsbu_v_w, uint8_t,  uint32_t, H4, ldub)
+GEN_VEXT_LD_ELEM(vlsbu_v_d, uint8_t,  uint64_t, H8, ldub)
+GEN_VEXT_LD_ELEM(vlshu_v_h, uint16_t, uint16_t, H2, lduw)
+GEN_VEXT_LD_ELEM(vlshu_v_w, uint16_t, uint32_t, H4, lduw)
+GEN_VEXT_LD_ELEM(vlshu_v_d, uint16_t, uint64_t, H8, lduw)
+GEN_VEXT_LD_ELEM(vlswu_v_w, uint32_t, uint32_t, H4, ldl)
+GEN_VEXT_LD_ELEM(vlswu_v_d, uint32_t, uint64_t, H8, ldl)

Why do you need to define new functions identical to the old ones?  Are you
doing this just to make the names match up?



+GEN_VEXT_ST_ELEM(vssb_v_b, int8_t,  H1, stb)
+GEN_VEXT_ST_ELEM(vssb_v_h, int16_t, H2, stb)
+GEN_VEXT_ST_ELEM(vssb_v_w, int32_t, H4, stb)
+GEN_VEXT_ST_ELEM(vssb_v_d, int64_t, H8, stb)
+GEN_VEXT_ST_ELEM(vssh_v_h, int16_t, H2, stw)
+GEN_VEXT_ST_ELEM(vssh_v_w, int32_t, H4, stw)
+GEN_VEXT_ST_ELEM(vssh_v_d, int64_t, H8, stw)
+GEN_VEXT_ST_ELEM(vssw_v_w, int32_t, H4, stl)
+GEN_VEXT_ST_ELEM(vssw_v_d, int64_t, H8, stl)
+GEN_VEXT_ST_ELEM(vsse_v_b, int8_t,  H1, stb)
+GEN_VEXT_ST_ELEM(vsse_v_h, int16_t, H2, stw)
+GEN_VEXT_ST_ELEM(vsse_v_w, int32_t, H4, stl)
+GEN_VEXT_ST_ELEM(vsse_v_d, int64_t, H8, stq)

Likewise.


+static void vext_st_stride(void *vd, void *v0, target_ulong base,
+target_ulong stride, CPURISCVState *env, uint32_t desc,
+vext_st_elem_fn st_elem, uint32_t esz, uint32_t msz, uintptr_t ra)
+{
+uint32_t i, k;
+uint32_t nf = vext_nf(desc);
+uint32_t vm = vext_vm(desc);
+uint32_t mlen = vext_mlen(desc);
+uint32_t vlmax = vext_maxsz(desc) / esz;
+
+/* probe every access*/
+for (i = 0; i < env->vl; i++) {
+if (!vm && !vext_elem_mask(v0, mlen, i)) {
+continue;
+}
+probe_write_access(env, base + stride * i, nf * msz, ra);
+}
+/* store bytes to guest memory */
+for (i = 0; i < env->vl; i++) {
+k = 0;
+if (!vm && !vext_elem_mask(v0, mlen, i)) {
+continue;
+}
+while (k < nf) {
+target_ulong addr = base + stride * i + k * msz;
+st_elem(env, addr, i + k * vlmax, vd, ra);
+k++;
+}
+}
+}

Similar comments wrt unifying the load and store helpers.

I'll also note that vext_st_stride and vext_st_us_mask could be unified by
passing sizeof(ETYPE) as stride, and vm = true as a parameter.

Maybe it is msz * nf as stride.

For element index  i,  the base load memory address for stride load is 
"i * stride".

For unit stride load ,  the base load memory address is "i * nf * msz".

Zhiwei


r~





Re: [PATCH] core/qdev: fix memleak in qdev_get_gpio_out_connector()

2020-03-06 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20200307030756.5913-1-pannengy...@huawei.com/



Hi,

This series failed the docker-clang@ubuntu build test. Please find the testing 
commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-ubuntu V=1 NETWORK=1
time make docker-test-clang@ubuntu SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===

  GEN hppa-softmmu/hmp-commands.h
  GEN alpha-softmmu/hmp-commands.h
  GEN microblazeel-softmmu/hmp-commands-info.h
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  GEN microblazeel-softmmu/config-devices.h
  GEN lm32-softmmu/hmp-commands-info.h
  GEN microblazeel-softmmu/config-target.h
---
  GEN i386-softmmu/config-devices.h
  GEN i386-softmmu/config-target.h
  CC  i386-softmmu/exec.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  GEN arm-softmmu/hmp-commands-info.h
  GEN arm-softmmu/config-devices.h
  GEN arm-softmmu/config-target.h
---
  CC  mips-softmmu/qapi/qapi-introspect.o
  CC  mips-softmmu/qapi/qapi-types-machine-target.o
  CC  mips-softmmu/qapi/qapi-types-misc-target.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  i386-softmmu/hw/i386/multiboot.o
  CC  mips64el-softmmu/hw/mips/gt64xxx_pci.o
  CC  hppa-softmmu/qapi/qapi-types-machine-target.o
---
  CC  moxie-softmmu/trace/control-target.o
  CC  or1k-softmmu/qapi/qapi-introspect.o
  CC  aarch64-softmmu/target/arm/monitor.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  ppc64-softmmu/memory_mapping.o
  CC  arm-softmmu/target/arm/arm-powerctl.o
  CC  nios2-softmmu/target/nios2/translate.o
---
  GEN aarch64-softmmu/target/arm/decode-vfp-uncond.inc.c
  GEN aarch64-softmmu/target/arm/decode-a32.inc.c
  GEN aarch64-softmmu/target/arm/decode-a32-uncond.inc.c
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  GEN aarch64-softmmu/target/arm/decode-t32.inc.c
  CC  ppc-softmmu/accel/stubs/kvm-stub.o
  CC  nios2-softmmu/target/nios2/cpu.o
---
  GEN aarch64-softmmu/target/arm/decode-sve.inc.c
  CC  ppc-softmmu/hw/block/virtio-blk.o
  CC  ppc64-softmmu/hw/block/dataplane/virtio-blk.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  GEN or1k-softmmu/target/openrisc/decode.inc.c
  CC  arm-softmmu/softmmu/main.o
  CC  or1k-softmmu/target/openrisc/exception_helper.o
---
  GEN trace/generated-helpers.c
  CC  ppc64-softmmu/hw/display/virtio-gpu-3d.o
 

[PATCH] core/qdev: fix memleak in qdev_get_gpio_out_connector()

2020-03-06 Thread Pan Nengyuan
Fix a memory leak in qdev_get_gpio_out_connector().

Reported-by: Euler Robot 
Signed-off-by: Pan Nengyuan 
---
 hw/core/qdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 3937d1eb1a..85f062def7 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -557,7 +557,7 @@ void qdev_connect_gpio_out_named(DeviceState *dev, const 
char *name, int n,
 
 qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n)
 {
-char *propname = g_strdup_printf("%s[%d]",
+g_autofree char *propname = g_strdup_printf("%s[%d]",
  name ? name : "unnamed-gpio-out", n);
 
 qemu_irq ret = (qemu_irq)object_property_get_link(OBJECT(dev), propname,
-- 
2.18.2




Re: [PATCH] hw/arm/stm32f405: Add preliminary RCC emulation support

2020-03-06 Thread Alistair Francis
On Thu, Mar 5, 2020 at 5:06 PM Stephanos Ioannidis  wrote:
>
> > These should at least be numbers (if not macros) instead of binary.
>
> Just wanted to follow the convention that the reference manual uses (it lists 
> the field values in binary).

The one I read was both, in this case I think the binary form is more
complex then just the decimal values.

>
> > Can't you just do (rcc_pllcfgr.pllp + 1) * 2 instead of a switch case?
> > I don't think we need a switch statement here
> > if (rcc_cfgr.hpre) <= 8) {
> >   ahb_div = 1;
> > } else {
> >   ahb_div = (rcc_cfgr.hpre - 7) * 2
> > }
>
> I wanted to be as verbose as possible and leave any optimisation up to the 
> compiler. After all, when reading code, the switch implementation is a direct 
> representation of the value mapping on and is therefore much easier to 
> understand- given that it is not excessively long.

Fair, this one isn't too bad.

>
> > Where does this come from? I can't seem to find it in the RM.
>
> This is an equation representation of the clock tree diagram (refer to the  
> "Figure 21. Clock tree" from RM0900).
>
> > Shouldn't this be 0x0477 7F33?
>
> No, that is for STM32F42xxx and STM32F43xxx. See "7.3.19 RCC APB2 peripheral 
> clock enabled in low power mode register (RCC_APB2LPENR)" from RM0900.

Ah, I opened the wrong one then.

>
> > Shouldn't this be PLLSAIRDYF?
> > Aren't you missing a PLLSAIRDYIE
>
> No, PLLSAIRDYF and PLLSAIRDYIE are for STM32F42xxx and STM32F43xxx. STM32F405 
> does not have these fields.

Same as above.

Alistair

>
> Stephanos
>
> -Original Message-
> From: Alistair Francis 
> Sent: Friday, March 6, 2020 4:40 AM
> To: Stephanos Ioannidis 
> Cc: Peter Maydell ; Alistair Francis 
> ; open list:All patches CC here 
> ; open list:ARM TCG CPUs 
> Subject: Re: [PATCH] hw/arm/stm32f405: Add preliminary RCC emulation support
>
>  =  heOn Sat, Feb 29, 2020 at 6:12 AM Stephanos Ioannidis  
> wrote:
> >
> > The RCC (reset and clock control) is a hardware peripheral reset and
> > clock configuration controller available on the STM32F4xx series
> > devices.
> >
> > This commit adds preliminary support for the RCC peripheral emulation,
> > in order to support proper emulation of the firmware images that use
> > the STM32Cube driver, which configures and validates the RCC registers
> > during system initialisation.
> >
> > In addition, the current STM32F405 SoC implementation does not specify
> > the Cortex-M SysTick clock scaling factor and this causes the QEMU to
> > become unresponsive as soon as the SysTick timer is enabled by the
> > guest. This problem is addressed by configuring the SysTick clock
> > scaling factor from the AHB clock frequency computed using the RCC
> > clock configurations.
> >
> > Signed-off-by: Stephanos Ioannidis 
> > ---
> >  hw/arm/Kconfig  |   1 +
> >  hw/arm/netduinoplus2.c  |   1 +
> >  hw/arm/stm32f405_soc.c  |  17 +-
> >  hw/misc/Kconfig |   3 +
> >  hw/misc/Makefile.objs   |   1 +
> >  hw/misc/stm32f4xx_rcc.c | 472 
> >  hw/misc/trace-events|   4 +
> >  include/hw/arm/stm32f405_soc.h  |   3 +
> >  include/hw/misc/stm32f4xx_rcc.h | 316 +
> >  9 files changed, 817 insertions(+), 1 deletion(-)  create mode 100644
> > hw/misc/stm32f4xx_rcc.c  create mode 100644
> > include/hw/misc/stm32f4xx_rcc.h
> >
> > diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index
> > 3d86691ae0..16442b3c4b 100644
> > --- a/hw/arm/Kconfig
> > +++ b/hw/arm/Kconfig
> > @@ -314,6 +314,7 @@ config STM32F205_SOC  config STM32F405_SOC
> >  bool
> >  select ARM_V7M
> > +select STM32F4XX_RCC
> >  select STM32F4XX_SYSCFG
> >  select STM32F4XX_EXTI
> >
> > diff --git a/hw/arm/netduinoplus2.c b/hw/arm/netduinoplus2.c index
> > e5e247edbe..37d57dafe4 100644
> > --- a/hw/arm/netduinoplus2.c
> > +++ b/hw/arm/netduinoplus2.c
> > @@ -36,6 +36,7 @@ static void netduinoplus2_init(MachineState
> > *machine)
> >
> >  dev = qdev_create(NULL, TYPE_STM32F405_SOC);
> >  qdev_prop_set_string(dev, "cpu-type",
> > ARM_CPU_TYPE_NAME("cortex-m4"));
> > +qdev_prop_set_uint32(dev, "hse-frequency", 2500);
> >  object_property_set_bool(OBJECT(dev), true, "realized",
> > &error_fatal);
> >
> >  armv7m_load_kernel(ARM_CPU(first_cpu),
> > diff --git a/hw/arm/stm32f405_soc.c b/hw/arm/stm32f405_soc.c index
> > 9bcad97853..5abbbc96c0 100644
> > --- a/hw/arm/stm32f405_soc.c
> > +++ b/hw/arm/stm32f405_soc.c
> > @@ -30,6 +30,7 @@
> >  #include "hw/arm/stm32f405_soc.h"
> >  #include "hw/misc/unimp.h"
> >
> > +#define RCC_ADDR   0x40023800
> >  #define SYSCFG_ADD 0x40013800
> >  static const uint32_t usart_addr[] = { 0x40011000, 0x40004400, 0x40004800,
> > 0x40004C00, 0x40005000,
> > 0x40011400, @@ -59,6 +60,9 @@ static void stm32f405_soc_initfn(Object *obj)
> >  sysbus_init_child_obj(obj, "armv7m

Re: [PATCH] hw/arm/stm32f405: Add preliminary RCC emulation support

2020-03-06 Thread Alistair Francis
On Thu, Mar 5, 2020 at 4:48 PM Stephanos Ioannidis  wrote:
>
> > Is it portable, though? I thought C bitfield order and packing was 
> > implementation-defined, which would mean that you can't guarantee that this 
> > union will give you the required thing in the uint32_t half.
>
> They are indeed implementation defined. As for packing, it is often 
> controllable; as for order, I do not recall seeing a compiler that dares to 
> change the order by which the fields are specified; though
> I understand the concern if QEMU policy is to be as portable as possible.
>
> Does QEMU have any form of bit field manipulation macros (e.g. 
> GET_BIT_RANGE(a, b), SET_BIT_RANGE(a, b), ...)?

The register fields that I pointed out earlier should do what you want.

You can look at other devices and see what they do.

Alistair

>
> -Original Message-
> From: Peter Maydell 
> Sent: Friday, March 6, 2020 4:30 AM
> To: Alistair Francis 
> Cc: Stephanos Ioannidis ; Alistair Francis 
> ; open list:All patches CC here 
> ; open list:ARM TCG CPUs 
> Subject: Re: [PATCH] hw/arm/stm32f405: Add preliminary RCC emulation support
>
> On Thu, 5 Mar 2020 at 19:24, Alistair Francis  wrote:
> >
> > On Sat, Feb 29, 2020 at 6:12 AM Stephanos Ioannidis  
> > wrote:
>
> > > +typedef union {
> > > +struct {
> > > +uint32_t hsion : 1;
> > > +uint32_t hsirdy : 1;
> > > +uint32_t reserved0 : 1;
> > > +uint32_t hsitrim : 5;
> > > +uint32_t hsical : 8;
> > > +uint32_t hseon : 1;
> > > +uint32_t hserdy : 1;
> > > +uint32_t hsebyp : 1;
> > > +uint32_t csson : 1;
> > > +uint32_t reserved1 : 4;
> > > +uint32_t pllon : 1;
> > > +uint32_t pllrdy : 1;
> > > +uint32_t plli2son : 1;
> > > +uint32_t plli2srdy : 1;
> > > +uint32_t reserved2 : 4;
> > > +};
> > > +uint32_t reg;
> > > +} RccCrType;
> >
> > This is a pretty interesting way to represent the registers
>
> Is it portable, though? I thought C bitfield order and packing was 
> implementation-defined, which would mean that you can't guarantee that this 
> union will give you the required thing in the uint32_t half.
>
> I think it would be better to do this the way that other device models do it, 
> and avoid bitfields.
>
> thanks
> -- PMM



Re: [PATCH] gdbstub: add support to Xfer:auxv:read: packet

2020-03-06 Thread no-reply
Patchew URL: https://patchew.org/QEMU/20200307010051.97022-1-yua...@google.com/



Hi,

This series failed the docker-clang@ubuntu build test. Please find the testing 
commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-ubuntu V=1 NETWORK=1
time make docker-test-clang@ubuntu SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===

  LINKqemu-bridge-helper
  LINKvirtiofsd
  LINKvhost-user-input
/usr/bin/ld/usr/bin/ld: : 
/lib/x86_64-linux-gnu/libtirpc.so.3/lib/x86_64-linux-gnu/libtirpc.so.3: 
warning: common of `: warning: common of 
`rpc_createerr@@GLIBC_2.2.5rpc_createerr@@GLIBC_2.2.5' overridden by definition 
from ' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6/lib/x86_64-linux-gnu/libc.so.6

/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  LINKqemu-img
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  GEN m68k-softmmu/hmp-commands.h
  GEN microblazeel-softmmu/hmp-commands.h
  GEN microblaze-softmmu/hmp-commands.h
---
  CC  i386-softmmu/hw/display/virtio-gpu-3d.o
  CC  m68k-softmmu/target/m68k/softfloat.o
  CC  hppa-softmmu/hw/net/virtio-net.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  aarch64-softmmu/hw/intc/exynos4210_gic.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  i386-softmmu/hw/display/vhost-user-gpu.o
  CC  m68k-softmmu/target/m68k/gdbstub.o
  CC  aarch64-softmmu/hw/intc/exynos4210_combiner.o
---
  CC  arm-softmmu/hw/scsi/virtio-scsi.o
  CC  i386-softmmu/hw/display/vhost-user-vga.o
  CC  aarch64-softmmu/hw/scsi/virtio-scsi.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  aarch64-softmmu/hw/scsi/virtio-scsi-dataplane.o
  CC  mips-softmmu/hw/net/rocker/qmp-norocker.o
  CC  i386-softmmu/hw/hyperv/hyperv.o
---
  CC  mips-softmmu/hw/mips/mips_int.o
  CC  mips-softmmu/hw/mips/mips_r4k.o
  CC  ppc-softmmu/accel/tcg/tcg-all.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  mips64el-softmmu/hw/mips/cps.o
  CC  nios2-softmmu/monitor/misc.o
  CC  moxie-softmmu/qapi/qapi-visit-machine-target.o
---
  CC  mips-softmmu/qapi/qapi-events-machine-target.o
  CC  arm-softmmu/hw/arm/musicpal.o
  CC  ppc-softmmu/hw/core/machine-qmp-cmds.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  or1k-softmmu/qapi/qapi-types-machine-target.o
  CC  aarch64-softmmu/hw/arm/microbit.o
  CC  or1k-softmmu/qapi/qapi-types-misc-target.o
---
  CC  or1k-softmmu/qapi/qapi-commands-machine-target.o
  CC  or1k-softmmu/qapi/qapi-commands-misc-target.o
  CC  i386-softmmu/hw/i386/microvm.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  ppc-softmmu/hw/display/virtio-gpu-base.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  or1k-softmmu/qapi/qapi-commands.o
  CC  mips64-softmmu/target/mips/translate.o
  CC  ppc-softmmu/hw/display/virtio-gpu.o
---
  CC  mips-softmmu/target/mips/translate.o
  CC  ppc64-softmmu/accel/stubs/whpx-stub.o
  CC  i386-softmmu/hw/i386/x86-iommu.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  mips64-softmmu/target/mips/op_helper.o
  CC  riscv32-softmmu/exec-vary.o
  CC  riscv32-softmmu/tcg/tcg.o
---
  LINKhppa-softmmu/qemu-system-hppa
  CC  i386-softmmu/hw/i386/vmport.o
  CC  or1k-softmmu/target/openrisc/mmu.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by 

Re: [PATCH v3 1/3] riscv/sifive_u: Fix up file ordering

2020-03-06 Thread Bin Meng
On Sat, Mar 7, 2020 at 5:44 AM Alistair Francis
 wrote:
>
> Split the file into clear machine and SoC sections.
>
> Signed-off-by: Alistair Francis 
> ---
>  hw/riscv/sifive_u.c | 109 ++--
>  1 file changed, 55 insertions(+), 54 deletions(-)
>

Reviewed-by: Bin Meng 



[PATCH] gdbstub: add support to Xfer:auxv:read: packet

2020-03-06 Thread Lirong Yuan
This allows gdb to access the target’s auxiliary vector,
which can be helpful for telling system libraries important details
about the hardware, operating system, and process.

Signed-off-by: Lirong Yuan 
---
 gdbstub.c | 55 +++
 1 file changed, 55 insertions(+)

diff --git a/gdbstub.c b/gdbstub.c
index 22a2d630cd..a946af7007 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2105,6 +2105,12 @@ static void handle_query_supported(GdbCmdContext 
*gdb_ctx, void *user_ctx)
 pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf),
 ";qXfer:features:read+");
 }
+#ifdef CONFIG_USER_ONLY
+if (gdb_ctx->s->c_cpu->opaque) {
+pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf),
+";qXfer:auxv:read+");
+}
+#endif
 
 if (gdb_ctx->num_params &&
 strstr(gdb_ctx->params[0].data, "multiprocess+")) {
@@ -2166,6 +2172,47 @@ static void handle_query_xfer_features(GdbCmdContext 
*gdb_ctx, void *user_ctx)
 put_packet_binary(gdb_ctx->s, gdb_ctx->str_buf, len + 1, true);
 }
 
+#ifdef CONFIG_USER_ONLY
+static void handle_query_xfer_auxv(GdbCmdContext *gdb_ctx, void *user_ctx)
+{
+TaskState *ts;
+unsigned long offset, len, saved_auxv, auxv_len;
+const char *mem;
+
+if (gdb_ctx->num_params < 2) {
+put_packet(gdb_ctx->s, "E22");
+return;
+}
+
+offset = gdb_ctx->params[0].val_ul;
+len = gdb_ctx->params[1].val_ul;
+
+ts = gdb_ctx->s->c_cpu->opaque;
+saved_auxv = ts->info->saved_auxv;
+auxv_len = ts->info->auxv_len;
+mem = (const char *)(saved_auxv + offset);
+
+if (offset >= auxv_len) {
+put_packet(gdb_ctx->s, "E22");
+return;
+}
+
+if (len > (MAX_PACKET_LENGTH - 5) / 2) {
+len = (MAX_PACKET_LENGTH - 5) / 2;
+}
+
+if (len < auxv_len - offset) {
+gdb_ctx->str_buf[0] = 'm';
+len = memtox(gdb_ctx->str_buf + 1, mem, len);
+} else {
+gdb_ctx->str_buf[0] = 'l';
+len = memtox(gdb_ctx->str_buf + 1, mem, auxv_len - offset);
+}
+
+put_packet_binary(gdb_ctx->s, gdb_ctx->str_buf, len + 1, true);
+}
+#endif
+
 static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx)
 {
 put_packet(gdb_ctx->s, GDB_ATTACHED);
@@ -2271,6 +2318,14 @@ static GdbCmdParseEntry gdb_gen_query_table[] = {
 .cmd_startswith = 1,
 .schema = "s:l,l0"
 },
+#ifdef CONFIG_USER_ONLY
+{
+.handler = handle_query_xfer_auxv,
+.cmd = "Xfer:auxv:read:",
+.cmd_startswith = 1,
+.schema = "l,l0"
+},
+#endif
 {
 .handler = handle_query_attached,
 .cmd = "Attached:",
-- 
2.25.1.481.gfbce0eb801-goog




Any interest in dwc-otg (aka dwc2) device emulation? For Raspi 3 and below.

2020-03-06 Thread Paul Zimmerman
Hi Folks,

I have been working on an emulation of the dwc-otg USB controller
(host mode only for now), as implemented on the Raspberry Pi 3 and
below, and on numerous other embedded platforms. I have it to a point
where it works pretty well with the dwc2 driver in the mainline Linux
kernel, and with the dwc-otg driver in the Raspbian kernel. Mouse and
keyboard work fine, and I *think* the usb-net device is working too,
although I have been unsuccessful in connecting to the outside world
with it.

I haven't done anything with gadget-mode yet, but that could certainly
be added in the future.

Would there be any interest in me submitting this for inclusion in
Qemu? I ask because I see there was a previous effort at this at
github.com/0xabu/qemu/hw/usb/bcm2835_usb.c, but it seems it never went
anywhere.

Thanks,
Paul



Re: [PATCH] gdbstub: add support to Xfer:auxv:read: packet

2020-03-06 Thread Philippe Mathieu-Daudé

On 3/7/20 1:04 AM, Lirong Yuan wrote:

This allows gdb to access the target’s auxiliary vector,
which can be helpful for telling system libraries important details
about the hardware, operating system, and process.

Signed-off-by: Lirong Yuan 
---
  gdbstub.c | 50 ++
  1 file changed, 50 insertions(+)

diff --git a/gdbstub.c b/gdbstub.c
index 22a2d630cd..c2865ea873 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2105,6 +2105,12 @@ static void handle_query_supported(GdbCmdContext 
*gdb_ctx, void *user_ctx)
  pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf),
  ";qXfer:features:read+");
  }
+#ifdef CONFIG_USER_ONLY
+if (gdb_ctx->s->c_cpu->opaque) {
+pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf),
+";qXfer:auxv:read+");
+}
+#endif
  
  if (gdb_ctx->num_params &&

  strstr(gdb_ctx->params[0].data, "multiprocess+")) {
@@ -2166,6 +2172,42 @@ static void handle_query_xfer_features(GdbCmdContext 
*gdb_ctx, void *user_ctx)
  put_packet_binary(gdb_ctx->s, gdb_ctx->str_buf, len + 1, true);
  }
  
+#ifdef CONFIG_USER_ONLY

+static void handle_query_xfer_auxv(GdbCmdContext *gdb_ctx, void *user_ctx)
+{
+TaskState *ts;
+unsigned long offset, len, saved_auxv, auxv_len;
+const char *mem;
+
+if (gdb_ctx->num_params < 2) {
+put_packet(gdb_ctx->s, "E22");
+return;
+}
+
+offset = gdb_ctx->params[0].val_ul;
+len = gdb_ctx->params[1].val_ul;
+
+ts = gdb_ctx->s->c_cpu->opaque;
+saved_auxv = ts->info->saved_auxv;
+auxv_len = ts->info->auxv_len;


Maybe check we are in range first?

   if (offset + len > auxv_len) {
   put_packet(gdb_ctx->s, "E22");
   return;
   }


+mem = (const char *)(saved_auxv + offset);
+
+if (len > (MAX_PACKET_LENGTH - 5) / 2) {
+len = (MAX_PACKET_LENGTH - 5) / 2;
+}
+
+if (len < auxv_len - offset) {
+gdb_ctx->str_buf[0] = 'm';
+len = memtox(gdb_ctx->str_buf + 1, mem, len);
+} else {
+gdb_ctx->str_buf[0] = 'l';
+len = memtox(gdb_ctx->str_buf + 1, mem, auxv_len - offset);
+}
+
+put_packet_binary(gdb_ctx->s, gdb_ctx->str_buf, len + 1, true);
+}
+#endif
+
  static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx)
  {
  put_packet(gdb_ctx->s, GDB_ATTACHED);
@@ -2271,6 +2313,14 @@ static GdbCmdParseEntry gdb_gen_query_table[] = {
  .cmd_startswith = 1,
  .schema = "s:l,l0"
  },
+#ifdef CONFIG_USER_ONLY
+{
+.handler = handle_query_xfer_auxv,
+.cmd = "Xfer:auxv:read:",
+.cmd_startswith = 1,
+.schema = "l,l0"
+},
+#endif
  {
  .handler = handle_query_attached,
  .cmd = "Attached:",






[PATCH] gdbstub: add support to Xfer:auxv:read: packet

2020-03-06 Thread Lirong Yuan
This allows gdb to access the target’s auxiliary vector,
which can be helpful for telling system libraries important details
about the hardware, operating system, and process.

Signed-off-by: Lirong Yuan 
---
 gdbstub.c | 50 ++
 1 file changed, 50 insertions(+)

diff --git a/gdbstub.c b/gdbstub.c
index 22a2d630cd..c2865ea873 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2105,6 +2105,12 @@ static void handle_query_supported(GdbCmdContext 
*gdb_ctx, void *user_ctx)
 pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf),
 ";qXfer:features:read+");
 }
+#ifdef CONFIG_USER_ONLY
+if (gdb_ctx->s->c_cpu->opaque) {
+pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf),
+";qXfer:auxv:read+");
+}
+#endif
 
 if (gdb_ctx->num_params &&
 strstr(gdb_ctx->params[0].data, "multiprocess+")) {
@@ -2166,6 +2172,42 @@ static void handle_query_xfer_features(GdbCmdContext 
*gdb_ctx, void *user_ctx)
 put_packet_binary(gdb_ctx->s, gdb_ctx->str_buf, len + 1, true);
 }
 
+#ifdef CONFIG_USER_ONLY
+static void handle_query_xfer_auxv(GdbCmdContext *gdb_ctx, void *user_ctx)
+{
+TaskState *ts;
+unsigned long offset, len, saved_auxv, auxv_len;
+const char *mem;
+
+if (gdb_ctx->num_params < 2) {
+put_packet(gdb_ctx->s, "E22");
+return;
+}
+
+offset = gdb_ctx->params[0].val_ul;
+len = gdb_ctx->params[1].val_ul;
+
+ts = gdb_ctx->s->c_cpu->opaque;
+saved_auxv = ts->info->saved_auxv;
+auxv_len = ts->info->auxv_len;
+mem = (const char *)(saved_auxv + offset);
+
+if (len > (MAX_PACKET_LENGTH - 5) / 2) {
+len = (MAX_PACKET_LENGTH - 5) / 2;
+}
+
+if (len < auxv_len - offset) {
+gdb_ctx->str_buf[0] = 'm';
+len = memtox(gdb_ctx->str_buf + 1, mem, len);
+} else {
+gdb_ctx->str_buf[0] = 'l';
+len = memtox(gdb_ctx->str_buf + 1, mem, auxv_len - offset);
+}
+
+put_packet_binary(gdb_ctx->s, gdb_ctx->str_buf, len + 1, true);
+}
+#endif
+
 static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx)
 {
 put_packet(gdb_ctx->s, GDB_ATTACHED);
@@ -2271,6 +2313,14 @@ static GdbCmdParseEntry gdb_gen_query_table[] = {
 .cmd_startswith = 1,
 .schema = "s:l,l0"
 },
+#ifdef CONFIG_USER_ONLY
+{
+.handler = handle_query_xfer_auxv,
+.cmd = "Xfer:auxv:read:",
+.cmd_startswith = 1,
+.schema = "l,l0"
+},
+#endif
 {
 .handler = handle_query_attached,
 .cmd = "Attached:",
-- 
2.25.1.481.gfbce0eb801-goog




Re: [PATCH 2/2] via-ide: Also emulate non 100% native mode

2020-03-06 Thread BALATON Zoltan

On Fri, 6 Mar 2020, Mark Cave-Ayland wrote:

On 06/03/2020 19:38, BALATON Zoltan wrote:

On Fri, 6 Mar 2020, Mark Cave-Ayland wrote:

On 06/03/2020 12:06, BALATON Zoltan wrote:

On Fri, 6 Mar 2020, Mark Cave-Ayland wrote:

On 05/03/2020 23:35, BALATON Zoltan wrote:

On real hardware this may be true but in QEMU how would it otherwise raise the
correct interrupt line the guest expects? This probably does not matter for
pegasos2
but I think is needed for 100% native mode used with the fulong2e so it gets the
IRQ
it expects.


That's easy - remember that both the PCI and IRQ interrupts are separate pins 
on the
chip, so all that needs to be done is expose the legacy IRQ via qdev and use 
that to
wire it up to your interrupt controller.


This "chip" is part of an integrated southbridge/superio/everything chip the 
also
includes the two PICs and how they are internally connected is not known so we 
would
be guessing here anyway. I don't see a need to make it more complicated than it 
is
now by modeling internal pins but how would I wire up gpio to the i8259 model 
and
where should I connect the PCI irq?


For now I would say not to worry about the PCI IRQ: the reason for discussing 
this
before was because we believed that if the controller was in native mode it 
must be
using the IRQ in PCI_INTERRUPT_LINE. But from yesterday's read of the 
specification
we know that PCI_INTERRUPT_LINE is never used by the device itself, and so 
given that
the existing via-ide device doesn't currently attempt to use the PCI IRQ in
via_ide_set_irq() then we should be good.

If someone had a machine somewhere that did use the PCI IRQ then it would need
investigation, but since there isn't then I don't see any need to do this now.


Okay so this is interesting: I've been switching between the VT8231 and the
VT82C686B
datasheets, and there is a difference here. You are correct in what you say 
above in
that the 8231 docs specify that this is set to 1, but on the 686B this is 
clearly
not
the case.


The 82C686B says this reg can be 0 or 1, where 0 is legacy interrupt routing 
and 1 is
native mode. Given that we only model native mode of the chip it does not make 
sense
to set it to anything else than 1 and setting it to 0 confuses MorphOS and 
Linux on
pegasos2 while setting it to 1 works with everything I've tried both on 
pegasos2 and
fulong2e even if that may not completely match how it's implemented in hardware.


What is rather unusual here is that both the 8231 and 686B have exactly the same
device and vendor ids, so I'm not sure how you'd distinguish between them?


Guests distinguish by looking at the parent device (function 0) which is the 
chip
this IDE device is part of (on function 1).


Okay thanks, that's useful to know.

I've done a quick grep of the source tree and AFAICT the only IDE controller 
that
tries to use the PCI_INTERRUPT_LINE register is via-ide, which means this 
should be
fairly easy. In short:

1) Add qemu_irq legacy_irqs[2] into PCIIDEState

(You could argue that it should belong in a separate VIAIDEState, however quite 
a few
of the BMDMA controllers in QEMU don't have their own device state and just use
PCIIDEState. And whilst via-ide is the only one that currently needs support for
legacy IRQs, I think it's good to put it there in case other controllers need 
it in
future)

2) Add via_ide_initfn() to hw/ide/via.c and add qdev_init_gpio_out_named() with 
a
name of "legacy-irq" to it


I don't like this. This adds two via-ide specific data to to common PCI IDE code
where it does not belong and subclassing it just for this also seems to be more
changes than really needed. Reusing the existing CMD646 field and generalising 
it to
allow implementation specific feature flags seems much less intrusive and not 
less
clean than your proposal.


It's not VIA-specific though: the ISA legacy and PCI buses have different 
electrical
characteristics and so by definition their signals must be driven by separate
physical pins. Have a look at the CMD646 datasheet for example, and you will 
see that
separate pins exist for legacy and PCI native IRQs.


For CMD646 we only use PCI interrupt which is in PCIDevice. Its legacy 
mode and thus those pins are not modelled so not needed now. For via-ide 
we only use ISA interrupts because even if we don't model legacy mode, 
boards expect ISA interrupts also in native mode maybe because this 
controller is not a separate PCI device only found embedded in 
southbridge/superio chips where they connect to the also embedded ISA PICs 
so even in native mode it should raise one of the ISA IRQs. My patch 
accesses ISA irqs with isa_get_irq() so no gpios and legacy irqs in 
PCIIDEState is neeeded and I don't see the need to introduce this 
complexity here. Also newer PCI ATA and SATA controllers such as sii3112 
do not have a legacy mode so I'd keep things related to that out of common 
PCI IDE code and model it instead in the controllers that have this as 
this does not seem to b

[PATCH v3 1/4] block: Add trivial backing_fmt support to qcow, sheepdog, vmdk

2020-03-06 Thread Eric Blake
For qcow2 and qed, we want to encourage the use of -F always, as these
formats can suffer from data corruption or security holes if backing
format is probed.  But for other formats, the backing format cannot be
recorded.  Making the user decide on a per-format basis whether to
supply a backing format string is awkward, better is to just blindly
accept a backing format argument even if it is ignored by the
contraints of the format at hand.

Signed-off-by: Eric Blake 
---
 block/qcow.c | 6 ++
 block/sheepdog.c | 6 ++
 block/vmdk.c | 5 +
 3 files changed, 17 insertions(+)

diff --git a/block/qcow.c b/block/qcow.c
index fce89898681f..d05c3d526170 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -947,6 +947,7 @@ static int coroutine_fn qcow_co_create_opts(const char 
*filename,

 static const QDictRenames opt_renames[] = {
 { BLOCK_OPT_BACKING_FILE,   "backing-file" },
+{ BLOCK_OPT_BACKING_FMT,"backing-fmt" },
 { BLOCK_OPT_ENCRYPT,BLOCK_OPT_ENCRYPT_FORMAT },
 { NULL, NULL },
 };
@@ -1151,6 +1152,11 @@ static QemuOptsList qcow_create_opts = {
 .type = QEMU_OPT_STRING,
 .help = "File name of a base image"
 },
+{
+.name = BLOCK_OPT_BACKING_FMT,
+.type = QEMU_OPT_STRING,
+.help = "Ignored (use raw backing files with caution)",
+},
 {
 .name = BLOCK_OPT_ENCRYPT,
 .type = QEMU_OPT_BOOL,
diff --git a/block/sheepdog.c b/block/sheepdog.c
index cfa84338a2d6..248dcf4dfa01 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -2187,6 +2187,7 @@ static int coroutine_fn sd_co_create_opts(const char 
*filename, QemuOpts *opts,
 /* Change legacy command line options into QMP ones */
 static const QDictRenames opt_renames[] = {
 { BLOCK_OPT_BACKING_FILE,   "backing-file" },
+{ BLOCK_OPT_BACKING_FMT,"backing-fmt" },
 { BLOCK_OPT_OBJECT_SIZE,"object-size" },
 { NULL, NULL },
 };
@@ -3189,6 +3190,11 @@ static QemuOptsList sd_create_opts = {
 .type = QEMU_OPT_STRING,
 .help = "File name of a base image"
 },
+{
+.name = BLOCK_OPT_BACKING_FMT,
+.type = QEMU_OPT_STRING,
+.help = "Ignored (use raw backing files with caution)",
+},
 {
 .name = BLOCK_OPT_PREALLOC,
 .type = QEMU_OPT_STRING,
diff --git a/block/vmdk.c b/block/vmdk.c
index 20e909d99794..53f3d864f3fe 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -3005,6 +3005,11 @@ static QemuOptsList vmdk_create_opts = {
 .type = QEMU_OPT_STRING,
 .help = "File name of a base image"
 },
+{
+.name = BLOCK_OPT_BACKING_FMT,
+.type = QEMU_OPT_STRING,
+.help = "Ignored (base image must be vmdk format)",
+},
 {
 .name = BLOCK_OPT_COMPAT6,
 .type = QEMU_OPT_BOOL,
-- 
2.25.1




[PATCH v3 4/4] qemu-img: Deprecate use of -b without -F

2020-03-06 Thread Eric Blake
Creating an image that requires format probing of the backing image is
inherently unsafe (we've had several CVEs over the years based on
probes leaking information to the guest on a subsequent boot, although
these days tools like libvirt are aware of the issue enough to prevent
the worst effects).  However, if our probing algorithm ever changes,
or if other tools like libvirt determine a different probe result than
we do, then subsequent use of that backing file under a different
format will present corrupted data to the guest.  Start a deprecation
clock so that future qemu-img can refuse to create unsafe backing
chains that would rely on probing.  The warnings are intentionally
emitted from the block layer rather than qemu-img (thus, all paths
into image creation or rewriting perform the check).

However, there is one time where probing is safe: if we probe raw,
then it is safe to record that implicitly in the image (but we still
warn, as it's better to teach the user to supply -F always than to
make them guess when it is safe).

iotest 114 specifically wants to create an unsafe image for later
amendment rather than defaulting to our new default of recording a
probed format, so it needs an update.  While touching it, expand it to
cover all of the various warnings enabled by this patch.

Signed-off-by: Eric Blake 
---
 docs/system/deprecated.rst | 19 +++
 block.c| 21 -
 qemu-img.c |  2 +-
 tests/qemu-iotests/114 | 11 +++
 tests/qemu-iotests/114.out |  8 
 5 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 6c1d9034d9e3..a8ffacf54a52 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -376,6 +376,25 @@ The above, converted to the current supported format::
 Related binaries
 

+qemu-img backing file without format (since 5.0.0)
+''
+
+The use of ``qemu-img create``, ``qemu-img rebase``, ``qemu-img
+convert``, or ``qemu-img amend`` to create or modify an image that
+depends on a backing file now recommends that an explicit backing
+format be provided.  This is for safety: if qemu probes a different
+format than what you thought, the data presented to the guest will be
+corrupt; similarly, presenting a raw image to a guest allows a
+potential security exploit if a future probe sees a non-raw image
+based on guest writes.  To avoid the warning message, or even future
+refusal to create an unsafe image, you must pass ``-o backing_fmt=``
+(or the shorthand ``-F`` during create) to specify the intended
+backing format.  You may use ``qemu-img rebase -u`` to retroactively
+add a backing format to an existing image.  However, be aware that
+there are already potential security risks to blindly using ``qemu-img
+info`` to probe the format of an untrusted backing image, when
+deciding what format to add into an existing image.
+
 ``qemu-img convert -n -o`` (since 4.2.0)
 

diff --git a/block.c b/block.c
index 43452976acdc..ad49d515809c 100644
--- a/block.c
+++ b/block.c
@@ -6039,6 +6039,20 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
   "Could not open backing image to determine 
size.\n");
 goto out;
 } else {
+if (!backing_fmt) {
+warn_report("Deprecated use of backing file without explicit "
+"backing format (detected format of %s)",
+bs->drv->format_name);
+if (bs->drv == &bdrv_raw) {
+/*
+ * A probe of raw is always correct, so in this one
+ * case, we can write that into the image.
+ */
+backing_fmt = bs->drv->format_name;
+qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, backing_fmt,
+ NULL);
+}
+}
 if (size == -1) {
 /* Opened BS, have no size */
 size = bdrv_getlength(bs);
@@ -6052,7 +6066,12 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
 }
 bdrv_unref(bs);
 }
-} /* (backing_file && !(flags & BDRV_O_NO_BACKING)) */
+/* (backing_file && !(flags & BDRV_O_NO_BACKING)) */
+} else if (backing_file && !backing_fmt) {
+warn_report("Deprecated use of unopened backing file without "
+"explicit backing format, use of this image requires "
+"potentially unsafe format probing");
+}

 if (size == -1) {
 error_setg(errp, "Image creation needs a size parameter");
diff --git a/qemu-img.c b/qemu-img.c
index b9375427404d..48424f8dbcd4 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3637,7 +3637,7 @@ static int img_rebase(int argc, char 

[PATCH v3 3/4] block: Add support to warn on backing file change without format

2020-03-06 Thread Eric Blake
For now, this is a mechanical addition; all callers pass false. But
the next patch will use it to improve 'qemu-img rebase -u' when
selecting a backing file with no format.

Signed-off-by: Eric Blake 
Reviewed-by: Peter Krempa 
Reviewed-by: Ján Tomko 
---
 include/block/block.h |  4 ++--
 block.c   | 13 ++---
 block/qcow2.c |  2 +-
 block/stream.c|  2 +-
 blockdev.c|  3 ++-
 qemu-img.c|  4 ++--
 6 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/include/block/block.h b/include/block/block.h
index cd6b5b95aad2..8b1dd94f7629 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -350,8 +350,8 @@ BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts 
*opts,
 void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
 void bdrv_refresh_limits(BlockDriverState *bs, Error **errp);
 int bdrv_commit(BlockDriverState *bs);
-int bdrv_change_backing_file(BlockDriverState *bs,
-const char *backing_file, const char *backing_fmt);
+int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_file,
+ const char *backing_fmt, bool warn);
 void bdrv_register(BlockDriver *bdrv);
 int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base,
const char *backing_file_str);
diff --git a/block.c b/block.c
index 957630b1c5d5..43452976acdc 100644
--- a/block.c
+++ b/block.c
@@ -1291,7 +1291,8 @@ static int bdrv_backing_update_filename(BdrvChild *c, 
BlockDriverState *base,
 }

 ret = bdrv_change_backing_file(parent, filename,
-   base->drv ? base->drv->format_name : "");
+   base->drv ? base->drv->format_name : "",
+   false);
 if (ret < 0) {
 error_setg_errno(errp, -ret, "Could not update backing file link");
 }
@@ -4535,8 +4536,8 @@ int bdrv_check(BlockDriverState *bs,
  *image file header
  * -ENOTSUP - format driver doesn't support changing the backing file
  */
-int bdrv_change_backing_file(BlockDriverState *bs,
-const char *backing_file, const char *backing_fmt)
+int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_file,
+ const char *backing_fmt, bool warn)
 {
 BlockDriver *drv = bs->drv;
 int ret;
@@ -4550,6 +4551,12 @@ int bdrv_change_backing_file(BlockDriverState *bs,
 return -EINVAL;
 }

+if (warn && backing_file && !backing_fmt) {
+warn_report("Deprecated use of backing file without explicit "
+"backing format, use of this image requires "
+"potentially unsafe format probing");
+}
+
 if (drv->bdrv_change_backing_file != NULL) {
 ret = drv->bdrv_change_backing_file(bs, backing_file, backing_fmt);
 } else {
diff --git a/block/qcow2.c b/block/qcow2.c
index 3640e8c07d0a..0abd6073fc34 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3506,7 +3506,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, 
Error **errp)
 }

 ret = bdrv_change_backing_file(blk_bs(blk), qcow2_opts->backing_file,
-   backing_format);
+   backing_format, false);
 if (ret < 0) {
 error_setg_errno(errp, -ret, "Could not assign backing file '%s' "
  "with format '%s'", qcow2_opts->backing_file,
diff --git a/block/stream.c b/block/stream.c
index 5562ccbf577a..7c4d8ee0bcf1 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -78,7 +78,7 @@ static int stream_prepare(Job *job)
 }
 }
 bdrv_set_backing_hd(bs, base, &local_err);
-ret = bdrv_change_backing_file(bs, base_id, base_fmt);
+ret = bdrv_change_backing_file(bs, base_id, base_fmt, false);
 if (local_err) {
 error_report_err(local_err);
 return -EPERM;
diff --git a/blockdev.c b/blockdev.c
index 3e44fa766b8f..c961df4c76b9 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3796,7 +3796,8 @@ void qmp_change_backing_file(const char *device,
 }

 ret = bdrv_change_backing_file(image_bs, backing_file,
-   image_bs->drv ? image_bs->drv->format_name : 
"");
+   image_bs->drv ? image_bs->drv->format_name 
: "",
+   false);

 if (ret < 0) {
 error_setg_errno(errp, -ret, "Could not change backing file to '%s'",
diff --git a/qemu-img.c b/qemu-img.c
index 804630a368d6..b9375427404d 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3637,9 +3637,9 @@ static int img_rebase(int argc, char **argv)
  * doesn't change when we switch the backing file.
  */
 if (out_baseimg && *out_baseimg) {
-ret = bdrv_change_backing_file(bs, out_baseimg, out_basefmt);
+ret = bdrv_change_backing_file(bs, out_baseimg, out_basefmt, false);
 } else 

[PATCH v3 0/4] Tighten qemu-img rules on missing backing format

2020-03-06 Thread Eric Blake
In v3:
- patch 1 is new [Jan]
- patch 2:
  - add test 225 for vmdk [Jan]
  - add a few more tests where raw backing files are used [Peter]
- patch 3 add R-b
- patch 4:
  - more tweaks on which messages are emitted [Peter]
  - more test coverage in 114 of new messages
  - rebase to .rst conversion

Eric Blake (4):
  block: Add trivial backing_fmt support to qcow, sheepdog, vmdk
  iotests: Specify explicit backing format where sensible
  block: Add support to warn on backing file change without format
  qemu-img: Deprecate use of -b without -F

 docs/system/deprecated.rst| 19 ++
 include/block/block.h |  4 +--
 block.c   | 34 ++---
 block/qcow.c  |  6 +
 block/qcow2.c |  2 +-
 block/sheepdog.c  |  6 +
 block/stream.c|  2 +-
 block/vmdk.c  |  5 
 blockdev.c|  3 ++-
 qemu-img.c|  4 +--
 tests/qemu-iotests/017|  2 +-
 tests/qemu-iotests/017.out|  2 +-
 tests/qemu-iotests/018|  2 +-
 tests/qemu-iotests/018.out|  2 +-
 tests/qemu-iotests/019|  5 ++--
 tests/qemu-iotests/019.out|  2 +-
 tests/qemu-iotests/020|  4 +--
 tests/qemu-iotests/020.out|  4 +--
 tests/qemu-iotests/024|  8 +++---
 tests/qemu-iotests/024.out|  5 ++--
 tests/qemu-iotests/028|  4 +--
 tests/qemu-iotests/028.out|  2 +-
 tests/qemu-iotests/030| 26 +--
 tests/qemu-iotests/034|  2 +-
 tests/qemu-iotests/034.out|  2 +-
 tests/qemu-iotests/037|  2 +-
 tests/qemu-iotests/037.out|  2 +-
 tests/qemu-iotests/038|  2 +-
 tests/qemu-iotests/038.out|  2 +-
 tests/qemu-iotests/039|  3 ++-
 tests/qemu-iotests/039.out|  2 +-
 tests/qemu-iotests/040| 47 +--
 tests/qemu-iotests/041| 37 ++-
 tests/qemu-iotests/042|  4 +--
 tests/qemu-iotests/043| 18 +++---
 tests/qemu-iotests/043.out| 16 +++-
 tests/qemu-iotests/046|  2 +-
 tests/qemu-iotests/046.out|  2 +-
 tests/qemu-iotests/050|  4 +--
 tests/qemu-iotests/050.out|  2 +-
 tests/qemu-iotests/051|  2 +-
 tests/qemu-iotests/051.out|  2 +-
 tests/qemu-iotests/051.pc.out |  2 +-
 tests/qemu-iotests/056|  3 ++-
 tests/qemu-iotests/060|  2 +-
 tests/qemu-iotests/060.out|  2 +-
 tests/qemu-iotests/061| 10 
 tests/qemu-iotests/061.out| 10 
 tests/qemu-iotests/069|  2 +-
 tests/qemu-iotests/069.out|  2 +-
 tests/qemu-iotests/073|  2 +-
 tests/qemu-iotests/073.out|  2 +-
 tests/qemu-iotests/082| 16 +++-
 tests/qemu-iotests/082.out| 16 ++--
 tests/qemu-iotests/085|  4 +--
 tests/qemu-iotests/085.out|  6 ++---
 tests/qemu-iotests/089|  2 +-
 tests/qemu-iotests/089.out|  2 +-
 tests/qemu-iotests/095|  4 +--
 tests/qemu-iotests/095.out|  4 +--
 tests/qemu-iotests/097|  4 +--
 tests/qemu-iotests/097.out| 16 ++--
 tests/qemu-iotests/098|  2 +-
 tests/qemu-iotests/098.out|  8 +++---
 tests/qemu-iotests/110|  4 +--
 tests/qemu-iotests/110.out|  4 +--
 tests/qemu-iotests/114| 11 
 tests/qemu-iotests/114.out|  8 ++
 tests/qemu-iotests/122| 27 
 tests/qemu-iotests/122.out|  8 +++---
 tests/qemu-iotests/126|  4 +--
 tests/qemu-iotests/126.out|  4 +--
 tests/qemu-iotests/127|  4 +--
 tests/qemu-iotests/127.out|  4 +--
 tests/qemu-iotests/129|  3 ++-
 tests/qemu-iotests/133|  2 +-
 tests/qemu-iotests/133.out|  2 +-
 tests/qemu-iotests/139|  2 +-
 tests/qemu-iotests/141|  4 +--
 tests/qemu-iotests/141.out|  4 +--
 tests/qemu-iotests/142|  2 +-
 tests/qemu-iotests/142.out|  2 +-
 tests/qemu-iotests/153| 14 +--
 tests/qemu-iotests/153.out| 35 ++
 tests/qemu-iotests/154| 42 +++
 tests/qemu-iotests/154.out| 42 +++
 tests/qemu-iotests/155| 12 ++---
 tests/qemu-iotests/156|  9 ---
 tests/qemu-iotests/156.out|  6 ++---
 tests/qemu-iotests/158|  2 +-
 tests/qemu-iotests/158.out|  2 +-
 tests/qemu-iotests/161|  8 +++---
 tests/qemu-iotests/161.out|  8 +++---
 tests/qemu-iotests/176|  4 +--
 tests/qemu-iotests/176.out| 32 
 tests/qemu-iotests/177|  2 +-
 tests/qemu-iotests/177.out|  2 +-
 tests/qemu-iotests/179|  2 +-
 tests/qemu-iotests/179.out|  2 +-
 tests/qemu-iotests/189|  2 +-
 tests/qemu-iotests/189.out|  2 +-
 tests/qemu-iotests/191| 12 -
 tests/qemu-iotests/191.out| 12 -
 tests/qemu-iotests/195   

[PATCH RESEND v2] block/nvme: introduce PMR support from NVMe 1.4 spec

2020-03-06 Thread Andrzej Jakowski
This patch introduces support for PMR that has been defined as part of NVMe 1.4
spec. User can now specify a pmr_file which will be mmap'ed into qemu address
space and subsequently in PCI BAR 2. Guest OS can perform mmio read and writes
to the PMR region that will stay persistent accross system reboot.

Signed-off-by: Andrzej Jakowski 
---
Changes since v1:
 - provided support for Bit 1 from PMRWBM register instead of Bit 0 to ensure
   improved performance in virtualized environment [1] (Stefan)

 - added check if pmr size is power of two in size (David)

 - addressed cross compilation build problems reported by CI environment

[1]: 
https://nvmexpress.org/wp-content/uploads/NVM-Express-1_4-2019.06.10-Ratified.pdf
[2]: 
https://lore.kernel.org/qemu-devel/20200218224811.30050-1-andrzej.jakow...@linux.intel.com/
 
---

Persistent Memory Region (PMR) is a new optional feature provided in NVMe 1.4
specification. This patch implements initial support for it in NVMe driver.

 hw/block/nvme.c   | 165 +++-
 hw/block/nvme.h   |   5 ++
 hw/block/trace-events |   5 ++
 include/block/nvme.h  | 172 ++
 4 files changed, 346 insertions(+), 1 deletion(-)

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index d28335cbf3..ff7e74d765 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -19,10 +19,14 @@
  *  -drive file=,if=none,id=
  *  -device nvme,drive=,serial=,id=, \
  *  cmb_size_mb=, \
+ *  [pmr_file=,] \
  *  num_queues=
  *
  * Note cmb_size_mb denotes size of CMB in MB. CMB is assumed to be at
  * offset 0 in BAR2 and supports only WDS, RDS and SQS for now.
+ *
+ * Either cmb or pmr - due to limitation in avaialbe BAR indexes.
+ * pmr_file file needs to be preallocated and power of two in size.
  */
 
 #include "qemu/osdep.h"
@@ -1141,6 +1145,28 @@ static void nvme_write_bar(NvmeCtrl *n, hwaddr offset, 
uint64_t data,
 NVME_GUEST_ERR(nvme_ub_mmiowr_cmbsz_readonly,
"invalid write to read only CMBSZ, ignored");
 return;
+#ifndef _WIN32
+case 0xE00: /* PMRCAP */
+NVME_GUEST_ERR(nvme_ub_mmiowr_pmrcap_readonly,
+   "invalid write to PMRCAP register, ignored");
+return;
+case 0xE04: /* TODO PMRCTL */
+break;
+case 0xE08: /* PMRSTS */
+NVME_GUEST_ERR(nvme_ub_mmiowr_pmrsts_readonly,
+   "invalid write to PMRSTS register, ignored");
+return;
+case 0xE0C: /* PMREBS */
+NVME_GUEST_ERR(nvme_ub_mmiowr_pmrebs_readonly,
+   "invalid write to PMREBS register, ignored");
+return;
+case 0xE10: /* PMRSWTP */
+NVME_GUEST_ERR(nvme_ub_mmiowr_pmrswtp_readonly,
+   "invalid write to PMRSWTP register, ignored");
+return;
+case 0xE14: /* TODO PMRMSC */
+ break;
+#endif /* !_WIN32 */
 default:
 NVME_GUEST_ERR(nvme_ub_mmiowr_invalid,
"invalid MMIO write,"
@@ -1169,6 +1195,22 @@ static uint64_t nvme_mmio_read(void *opaque, hwaddr 
addr, unsigned size)
 }
 
 if (addr < sizeof(n->bar)) {
+#ifndef _WIN32
+/*
+ * When PMRWBM bit 1 is set then read from
+ * from PMRSTS should ensure prior writes
+ * made it to persistent media
+ */
+if (addr == 0xE08 &&
+(NVME_PMRCAP_PMRWBM(n->bar.pmrcap) & 0x02) >> 1) {
+int ret;
+ret = msync(n->pmrbuf, n->f_pmr_size, MS_SYNC);
+if (!ret) {
+NVME_GUEST_ERR(nvme_ub_mmiord_pmrread_barrier,
+   "error while persisting data");
+}
+}
+#endif /* !_WIN32 */
 memcpy(&val, ptr + addr, size);
 } else {
 NVME_GUEST_ERR(nvme_ub_mmiord_invalid_ofs,
@@ -1303,6 +1345,31 @@ static const MemoryRegionOps nvme_cmb_ops = {
 },
 };
 
+#ifndef _WIN32
+static void nvme_pmr_write(void *opaque, hwaddr addr, uint64_t data,
+unsigned size)
+{
+NvmeCtrl *n = (NvmeCtrl *)opaque;
+stn_le_p(&n->pmrbuf[addr], size, data);
+}
+
+static uint64_t nvme_pmr_read(void *opaque, hwaddr addr, unsigned size)
+{
+NvmeCtrl *n = (NvmeCtrl *)opaque;
+return ldn_le_p(&n->pmrbuf[addr], size);
+}
+
+static const MemoryRegionOps nvme_pmr_ops = {
+.read = nvme_pmr_read,
+.write = nvme_pmr_write,
+.endianness = DEVICE_LITTLE_ENDIAN,
+.impl = {
+.min_access_size = 1,
+.max_access_size = 8,
+},
+};
+#endif /* !_WIN32 */
+
 static void nvme_realize(PCIDevice *pci_dev, Error **errp)
 {
 NvmeCtrl *n = NVME(pci_dev);
@@ -1332,6 +1399,39 @@ static void nvme_realize(PCIDevice *pci_dev, Error 
**errp)
 error_setg(errp, "serial property not set");
 return;
 }
+
+#ifndef _WIN32
+if (!n->cmb_size_mb && n->pmr_file) {
+int fd;
+
+n->f_pmr = fopen(n->pmr_file, "r+b");
+if (!n->f_pmr) {
+error_setg(er

Re: [PATCH] build-sys: Move the print-variable rule to rules.mak

2020-03-06 Thread Marc-André Lureau
On Fri, Mar 6, 2020 at 6:05 PM Philippe Mathieu-Daudé  wrote:
>
> Currently the print-variable rule can only be used in the
> root directory:
>
>   $ make print-vhost-user-json-y
>   vhost-user-json-y= contrib/vhost-user-gpu/50-qemu-gpu.json 
> tools/virtiofsd/50-qemu-virtiofsd.json
>
>   $ make -C i386-softmmu print-obj-y
>   make: Entering directory 'build/i386-softmmu'
>   make: *** No rule to make target 'print-obj-y'.  Stop.
>   make: Leaving directory 'build/i386-softmmu'
>
> Move it to rules.mak so we can use it from other directories:
>
>   $ make -C i386-softmmu print-obj-y
>   make: Entering directory 'build/i386-softmmu'
>   obj-y=qapi-introspect.o qapi-types-machine-target.o 
> qapi-types-misc-target.o qapi-types.o qapi-visit-machine-target.o 
> qapi-visit-misc-target.o qapi-visit.o qapi-events-machine-target.o 
> qapi-events-misc-target.o qapi-events.o qapi-commands-machine-target.o 
> qapi-commands-misc-target.o qapi-commands.o qapi-init-commands.o
>   make: Leaving directory 'build/i386-softmmu'
>
> Signed-off-by: Philippe Mathieu-Daudé 

Reviewed-by: Marc-André Lureau 

> ---
>  Makefile  | 3 ---
>  rules.mak | 3 +++
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 9d4b224126..fdc5d29bb9 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -15,9 +15,6 @@ UNCHECKED_GOALS := %clean TAGS cscope ctags dist \
>  help check-help print-% \
>  docker docker-% vm-help vm-test vm-build-%
>
> -print-%:
> -   @echo '$*=$($*)'
> -
>  # All following code might depend on configuration variables
>  ifneq ($(wildcard config-host.mak),)
>  # Put the all: rule here so that config-host.mak can contain dependencies.
> diff --git a/rules.mak b/rules.mak
> index e39b073d46..694865b63e 100644
> --- a/rules.mak
> +++ b/rules.mak
> @@ -435,3 +435,6 @@ sentinel = .$(subst $(SPACE),_,$(subst /,_,$1)).sentinel.
>  atomic = $(eval $1: $(call sentinel,$1) ; @:) \
>   $(call sentinel,$1) : $2 ; @touch $$@ \
>   $(foreach t,$1,$(if $(wildcard $t),,$(shell rm -f $(call 
> sentinel,$1
> +
> +print-%:
> +   @echo '$*=$($*)'
> --
> 2.21.1
>
>


-- 
Marc-André Lureau



[PATCH v3 2/3] riscv/sifive_u: Add a serial property to the sifive_u SoC

2020-03-06 Thread Alistair Francis
At present the board serial number is hard-coded to 1, and passed
to OTP model during initialization. Firmware (FSBL, U-Boot) uses
the serial number to generate a unique MAC address for the on-chip
ethernet controller. When multiple QEMU 'sifive_u' instances are
created and connected to the same subnet, they all have the same
MAC address hence it creates a unusable network.

A new "serial" property is introduced to the sifive_u SoC to specify
the board serial number. When not given, the default serial number
1 is used.

Suggested-by: Bin Meng 
Signed-off-by: Alistair Francis 
Reviewed-by: Bin Meng 
Tested-by: Bin Meng 
---
 hw/riscv/sifive_u.c | 8 +++-
 include/hw/riscv/sifive_u.h | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index 4688837216..dc572c761a 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -488,7 +488,6 @@ static void riscv_sifive_u_soc_init(Object *obj)
   TYPE_SIFIVE_U_PRCI);
 sysbus_init_child_obj(obj, "otp", &s->otp, sizeof(s->otp),
   TYPE_SIFIVE_U_OTP);
-qdev_prop_set_uint32(DEVICE(&s->otp), "serial", OTP_SERIAL);
 sysbus_init_child_obj(obj, "gem", &s->gem, sizeof(s->gem),
   TYPE_CADENCE_GEM);
 }
@@ -581,6 +580,7 @@ static void riscv_sifive_u_soc_realize(DeviceState *dev, 
Error **errp)
 object_property_set_bool(OBJECT(&s->prci), true, "realized", &err);
 sysbus_mmio_map(SYS_BUS_DEVICE(&s->prci), 0, memmap[SIFIVE_U_PRCI].base);
 
+qdev_prop_set_uint32(DEVICE(&s->otp), "serial", s->serial);
 object_property_set_bool(OBJECT(&s->otp), true, "realized", &err);
 sysbus_mmio_map(SYS_BUS_DEVICE(&s->otp), 0, memmap[SIFIVE_U_OTP].base);
 
@@ -607,10 +607,16 @@ static void riscv_sifive_u_soc_realize(DeviceState *dev, 
Error **errp)
 memmap[SIFIVE_U_GEM_MGMT].base, memmap[SIFIVE_U_GEM_MGMT].size);
 }
 
+static Property riscv_sifive_u_soc_props[] = {
+DEFINE_PROP_UINT32("serial", SiFiveUSoCState, serial, OTP_SERIAL),
+DEFINE_PROP_END_OF_LIST()
+};
+
 static void riscv_sifive_u_soc_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
 
+device_class_set_props(dc, riscv_sifive_u_soc_props);
 dc->realize = riscv_sifive_u_soc_realize;
 /* Reason: Uses serial_hds in realize function, thus can't be used twice */
 dc->user_creatable = false;
diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h
index 82667b5746..a2baa1de5f 100644
--- a/include/hw/riscv/sifive_u.h
+++ b/include/hw/riscv/sifive_u.h
@@ -42,6 +42,8 @@ typedef struct SiFiveUSoCState {
 SiFiveUPRCIState prci;
 SiFiveUOTPState otp;
 CadenceGEMState gem;
+
+uint32_t serial;
 } SiFiveUSoCState;
 
 #define TYPE_RISCV_U_MACHINE MACHINE_TYPE_NAME("sifive_u")
-- 
2.25.1




[PATCH v3 3/3] riscv/sifive_u: Add a serial property to the sifive_u machine

2020-03-06 Thread Alistair Francis
From: Bin Meng 

At present the board serial number is hard-coded to 1, and passed
to OTP model during initialization. Firmware (FSBL, U-Boot) uses
the serial number to generate a unique MAC address for the on-chip
ethernet controller. When multiple QEMU 'sifive_u' instances are
created and connected to the same subnet, they all have the same
MAC address hence it creates a unusable network.

A new "serial" property is introduced to specify the board serial
number. When not given, the default serial number 1 is used.

Signed-off-by: Bin Meng 
Reviewed-by: Palmer Dabbelt 
Reviewed-by: Alistair Francis 
Message-Id: <1573916930-19068-1-git-send-email-bmeng...@gmail.com>
[ Changed by AF:
 - Use the SoC's serial property to pass the info to the SoC
 - Fixup commit title
 - Rebase on file restructuring
]
Signed-off-by: Alistair Francis 
---
 hw/riscv/sifive_u.c | 20 
 include/hw/riscv/sifive_u.h |  1 +
 2 files changed, 21 insertions(+)

diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index dc572c761a..44cb72f09e 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -34,6 +34,7 @@
 #include "qemu/log.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
+#include "qapi/visitor.h"
 #include "hw/boards.h"
 #include "hw/loader.h"
 #include "hw/sysbus.h"
@@ -322,6 +323,8 @@ static void sifive_u_machine_init(MachineState *machine)
 object_initialize_child(OBJECT(machine), "soc", &s->soc,
 sizeof(s->soc), TYPE_RISCV_U_SOC,
 &error_abort, NULL);
+object_property_set_uint(OBJECT(&s->soc), s->serial, "serial",
+&error_abort);
 object_property_set_bool(OBJECT(&s->soc), true, "realized",
 &error_abort);
 
@@ -413,6 +416,18 @@ static void sifive_u_machine_set_start_in_flash(Object 
*obj, bool value, Error *
 s->start_in_flash = value;
 }
 
+static void sifive_u_machine_get_serial(Object *obj, Visitor *v, const char 
*name,
+void *opaque, Error **errp)
+{
+visit_type_uint32(v, name, (uint32_t *)opaque, errp);
+}
+
+static void sifive_u_machine_set_serial(Object *obj, Visitor *v, const char 
*name,
+void *opaque, Error **errp)
+{
+visit_type_uint32(v, name, (uint32_t *)opaque, errp);
+}
+
 static void sifive_u_machine_instance_init(Object *obj)
 {
 SiFiveUState *s = RISCV_U_MACHINE(obj);
@@ -424,6 +439,11 @@ static void sifive_u_machine_instance_init(Object *obj)
 "Set on to tell QEMU's ROM to jump to " \
 "flash. Otherwise QEMU will jump to DRAM",
 NULL);
+
+s->serial = OTP_SERIAL;
+object_property_add(obj, "serial", "uint32", sifive_u_machine_get_serial,
+sifive_u_machine_set_serial, NULL, &s->serial, NULL);
+object_property_set_description(obj, "serial", "Board serial number", 
NULL);
 }
 
 
diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h
index a2baa1de5f..16c297ec5f 100644
--- a/include/hw/riscv/sifive_u.h
+++ b/include/hw/riscv/sifive_u.h
@@ -61,6 +61,7 @@ typedef struct SiFiveUState {
 int fdt_size;
 
 bool start_in_flash;
+uint32_t serial;
 } SiFiveUState;
 
 enum {
-- 
2.25.1




[PATCH v3 0/3] hw/riscv: Add a serial property to sifive_u

2020-03-06 Thread Alistair Francis
At present the board serial number is hard-coded to 1, and passed
to OTP model during initialization. Firmware (FSBL, U-Boot) uses
the serial number to generate a unique MAC address for the on-chip
ethernet controller. When multiple QEMU 'sifive_u' instances are
created and connected to the same subnet, they all have the same
MAC address hence it creates a unusable network.

A new "serial" property is introduced to specify the board serial
number. When not given, the default serial number 1 is used.

v3:
 - Improve machine function names
v2:
 - Fix the serial setting so it correctly sets

Alistair Francis (2):
  riscv/sifive_u: Fix up file ordering
  riscv/sifive_u: Add a serial property to the sifive_u SoC

Bin Meng (1):
  riscv/sifive_u: Add a serial property to the sifive_u machine

 hw/riscv/sifive_u.c | 137 +---
 include/hw/riscv/sifive_u.h |   3 +
 2 files changed, 85 insertions(+), 55 deletions(-)

-- 
2.25.1




[PATCH v3 1/3] riscv/sifive_u: Fix up file ordering

2020-03-06 Thread Alistair Francis
Split the file into clear machine and SoC sections.

Signed-off-by: Alistair Francis 
---
 hw/riscv/sifive_u.c | 109 ++--
 1 file changed, 55 insertions(+), 54 deletions(-)

diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index 156a003642..4688837216 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -308,7 +308,7 @@ static void create_fdt(SiFiveUState *s, const struct 
MemmapEntry *memmap,
 g_free(nodename);
 }
 
-static void riscv_sifive_u_init(MachineState *machine)
+static void sifive_u_machine_init(MachineState *machine)
 {
 const struct MemmapEntry *memmap = sifive_u_memmap;
 SiFiveUState *s = RISCV_U_MACHINE(machine);
@@ -399,6 +399,60 @@ static void riscv_sifive_u_init(MachineState *machine)
   &address_space_memory);
 }
 
+static bool sifive_u_machine_get_start_in_flash(Object *obj, Error **errp)
+{
+SiFiveUState *s = RISCV_U_MACHINE(obj);
+
+return s->start_in_flash;
+}
+
+static void sifive_u_machine_set_start_in_flash(Object *obj, bool value, Error 
**errp)
+{
+SiFiveUState *s = RISCV_U_MACHINE(obj);
+
+s->start_in_flash = value;
+}
+
+static void sifive_u_machine_instance_init(Object *obj)
+{
+SiFiveUState *s = RISCV_U_MACHINE(obj);
+
+s->start_in_flash = false;
+object_property_add_bool(obj, "start-in-flash", 
sifive_u_machine_get_start_in_flash,
+ sifive_u_machine_set_start_in_flash, NULL);
+object_property_set_description(obj, "start-in-flash",
+"Set on to tell QEMU's ROM to jump to " \
+"flash. Otherwise QEMU will jump to DRAM",
+NULL);
+}
+
+
+static void sifive_u_machine_class_init(ObjectClass *oc, void *data)
+{
+MachineClass *mc = MACHINE_CLASS(oc);
+
+mc->desc = "RISC-V Board compatible with SiFive U SDK";
+mc->init = sifive_u_machine_init;
+mc->max_cpus = SIFIVE_U_MANAGEMENT_CPU_COUNT + SIFIVE_U_COMPUTE_CPU_COUNT;
+mc->min_cpus = SIFIVE_U_MANAGEMENT_CPU_COUNT + 1;
+mc->default_cpus = mc->min_cpus;
+}
+
+static const TypeInfo sifive_u_machine_typeinfo = {
+.name   = MACHINE_TYPE_NAME("sifive_u"),
+.parent = TYPE_MACHINE,
+.class_init = sifive_u_machine_class_init,
+.instance_init = sifive_u_machine_instance_init,
+.instance_size = sizeof(SiFiveUState),
+};
+
+static void sifive_u_machine_init_register_types(void)
+{
+type_register_static(&sifive_u_machine_typeinfo);
+}
+
+type_init(sifive_u_machine_init_register_types)
+
 static void riscv_sifive_u_soc_init(Object *obj)
 {
 MachineState *ms = MACHINE(qdev_get_machine());
@@ -439,33 +493,6 @@ static void riscv_sifive_u_soc_init(Object *obj)
   TYPE_CADENCE_GEM);
 }
 
-static bool sifive_u_get_start_in_flash(Object *obj, Error **errp)
-{
-SiFiveUState *s = RISCV_U_MACHINE(obj);
-
-return s->start_in_flash;
-}
-
-static void sifive_u_set_start_in_flash(Object *obj, bool value, Error **errp)
-{
-SiFiveUState *s = RISCV_U_MACHINE(obj);
-
-s->start_in_flash = value;
-}
-
-static void riscv_sifive_u_machine_instance_init(Object *obj)
-{
-SiFiveUState *s = RISCV_U_MACHINE(obj);
-
-s->start_in_flash = false;
-object_property_add_bool(obj, "start-in-flash", 
sifive_u_get_start_in_flash,
- sifive_u_set_start_in_flash, NULL);
-object_property_set_description(obj, "start-in-flash",
-"Set on to tell QEMU's ROM to jump to " \
-"flash. Otherwise QEMU will jump to DRAM",
-NULL);
-}
-
 static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp)
 {
 MachineState *ms = MACHINE(qdev_get_machine());
@@ -603,29 +630,3 @@ static void riscv_sifive_u_soc_register_types(void)
 }
 
 type_init(riscv_sifive_u_soc_register_types)
-
-static void riscv_sifive_u_machine_class_init(ObjectClass *oc, void *data)
-{
-MachineClass *mc = MACHINE_CLASS(oc);
-
-mc->desc = "RISC-V Board compatible with SiFive U SDK";
-mc->init = riscv_sifive_u_init;
-mc->max_cpus = SIFIVE_U_MANAGEMENT_CPU_COUNT + SIFIVE_U_COMPUTE_CPU_COUNT;
-mc->min_cpus = SIFIVE_U_MANAGEMENT_CPU_COUNT + 1;
-mc->default_cpus = mc->min_cpus;
-}
-
-static const TypeInfo riscv_sifive_u_machine_typeinfo = {
-.name   = MACHINE_TYPE_NAME("sifive_u"),
-.parent = TYPE_MACHINE,
-.class_init = riscv_sifive_u_machine_class_init,
-.instance_init = riscv_sifive_u_machine_instance_init,
-.instance_size = sizeof(SiFiveUState),
-};
-
-static void riscv_sifive_u_machine_init_register_types(void)
-{
-type_register_static(&riscv_sifive_u_machine_typeinfo);
-}
-
-type_init(riscv_sifive_u_machine_init_register_types)
-- 
2.25.1




Re: [PATCH v6 0/4] linux-user: generate syscall_nr.sh for RISC-V

2020-03-06 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/cover.1583518447.git.alistair.fran...@wdc.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Subject: [PATCH v6 0/4]  linux-user: generate syscall_nr.sh for RISC-V
Message-id: cover.1583518447.git.alistair.fran...@wdc.com
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

From https://github.com/patchew-project/qemu
 - [tag update]  patchew/cover.1583518447.git.alistair.fran...@wdc.com -> 
patchew/cover.1583518447.git.alistair.fran...@wdc.com
Switched to a new branch 'test'
6c8b2a5 linux-user/riscv: Update the syscall_nr's to the 5.5 kernel
a8c3505 linux-user: Support futex_time64
5020c23 linux-user/syscall: Add support for clock_gettime64/clock_settime64
2229302 linux-user: Protect more syscalls

=== OUTPUT BEGIN ===
1/4 Checking commit 22293021a06b (linux-user: Protect more syscalls)
2/4 Checking commit 5020c2382b9e (linux-user/syscall: Add support for 
clock_gettime64/clock_settime64)
3/4 Checking commit a8c3505c6ff4 (linux-user: Support futex_time64)
WARNING: architecture specific defines should be avoided
#23: FILE: linux-user/syscall.c:248:
+#if defined(__NR_futex)

WARNING: architecture specific defines should be avoided
#26: FILE: linux-user/syscall.c:251:
+#if defined(__NR_futex_time64)

WARNING: architecture specific defines should be avoided
#42: FILE: linux-user/syscall.c:308:
+#if defined(TARGET_NR_futex_time64) && defined(__NR_futex_time64)

ERROR: space required after that ',' (ctx:VxV)
#43: FILE: linux-user/syscall.c:309:
+_syscall6(int,sys_futex_time64,int *,uaddr,int,op,int,val,
  ^

ERROR: space required after that ',' (ctx:VxV)
#43: FILE: linux-user/syscall.c:309:
+_syscall6(int,sys_futex_time64,int *,uaddr,int,op,int,val,
   ^

ERROR: space required after that ',' (ctx:OxV)
#43: FILE: linux-user/syscall.c:309:
+_syscall6(int,sys_futex_time64,int *,uaddr,int,op,int,val,
 ^

ERROR: space required after that ',' (ctx:VxV)
#43: FILE: linux-user/syscall.c:309:
+_syscall6(int,sys_futex_time64,int *,uaddr,int,op,int,val,
   ^

ERROR: space required after that ',' (ctx:VxV)
#43: FILE: linux-user/syscall.c:309:
+_syscall6(int,sys_futex_time64,int *,uaddr,int,op,int,val,
   ^

ERROR: space required after that ',' (ctx:VxV)
#43: FILE: linux-user/syscall.c:309:
+_syscall6(int,sys_futex_time64,int *,uaddr,int,op,int,val,
  ^

ERROR: space required after that ',' (ctx:VxV)
#43: FILE: linux-user/syscall.c:309:
+_syscall6(int,sys_futex_time64,int *,uaddr,int,op,int,val,
  ^

ERROR: space required after that ',' (ctx:OxV)
#44: FILE: linux-user/syscall.c:310:
+  const struct timespec *,timeout,int *,uaddr2,int,val3)
  ^

ERROR: space required after that ',' (ctx:VxV)
#44: FILE: linux-user/syscall.c:310:
+  const struct timespec *,timeout,int *,uaddr2,int,val3)
  ^

ERROR: space required after that ',' (ctx:OxV)
#44: FILE: linux-user/syscall.c:310:
+  const struct timespec *,timeout,int *,uaddr2,int,val3)
^

ERROR: space required after that ',' (ctx:VxV)
#44: FILE: linux-user/syscall.c:310:
+  const struct timespec *,timeout,int *,uaddr2,int,val3)
   ^

ERROR: space required after that ',' (ctx:VxV)
#44: FILE: linux-user/syscall.c:310:
+  const struct timespec *,timeout,int *,uaddr2,int,val3)
   ^

WARNING: architecture specific defines should be avoided
#54: FILE: linux-user/syscall.c:775:
+#if defined(__NR_futex)

WARNING: architecture specific defines should be avoided
#58: FILE: linux-user/syscall.c:779:
+#if defined(__NR_futex_time64)

ERROR: space required after that ',' (ctx:VxV)
#59: FILE: linux-user/syscall.c:780:
+safe_syscall6(int,futex_time64,int *,uaddr,int,op,int,val, \
  ^

ERROR: space required after that ',' (ctx:VxV)
#59: FILE: linux-user/syscall.c:780:
+safe_syscall6(int,futex_time64,int *,uaddr,int,op,int,val, \
   ^

ERROR: space required after that ',' (ctx:OxV)
#59: FILE: linux-user/syscall.c:780:
+safe_syscall6(int,futex_time64,int *,uaddr,int,op,int,val, \
 ^

ERROR: space required after that ',' (ctx:VxV)
#59: FILE: linux-user/syscall.c:780:
+safe_syscall6(int,futex_time64,int *,uaddr,int,op,int,val, \
   ^

ERROR: space r

Re: [PATCH v6 1/4] linux-user: Protect more syscalls

2020-03-06 Thread Laurent Vivier
Le 06/03/2020 à 19:24, Alistair Francis a écrit :
> New y2038 safe 32-bit architectures (like RISC-V) don't support old
> syscalls with a 32-bit time_t. The kernel defines new *_time64 versions
> of these syscalls. Add some more #ifdefs to syscall.c in linux-user to
> allow us to compile without these old syscalls.
> 
> Signed-off-by: Alistair Francis 
> ---
>  linux-user/strace.c  |  2 ++
>  linux-user/syscall.c | 68 +++-
>  2 files changed, 69 insertions(+), 1 deletion(-)
> 
...
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 8d27d10807..1a7df23440 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
...
>  #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)

You can remove this line ^^ as you check individually for each syscall
below.

With that fixed:

Reviewed-by: Laurent Vivier 



Re: [PATCH 2/2] via-ide: Also emulate non 100% native mode

2020-03-06 Thread Mark Cave-Ayland
On 06/03/2020 19:38, BALATON Zoltan wrote:

> On Fri, 6 Mar 2020, Mark Cave-Ayland wrote:
>> On 06/03/2020 12:06, BALATON Zoltan wrote:
>>> On Fri, 6 Mar 2020, Mark Cave-Ayland wrote:
 On 05/03/2020 23:35, BALATON Zoltan wrote:
> On real hardware this may be true but in QEMU how would it otherwise 
> raise the
> correct interrupt line the guest expects? This probably does not matter 
> for
> pegasos2
> but I think is needed for 100% native mode used with the fulong2e so it 
> gets the
> IRQ
> it expects.

 That's easy - remember that both the PCI and IRQ interrupts are separate 
 pins on the
 chip, so all that needs to be done is expose the legacy IRQ via qdev and 
 use that to
 wire it up to your interrupt controller.
>>>
>>> This "chip" is part of an integrated southbridge/superio/everything chip 
>>> the also
>>> includes the two PICs and how they are internally connected is not known so 
>>> we would
>>> be guessing here anyway. I don't see a need to make it more complicated 
>>> than it is
>>> now by modeling internal pins but how would I wire up gpio to the i8259 
>>> model and
>>> where should I connect the PCI irq?
>>
>> For now I would say not to worry about the PCI IRQ: the reason for 
>> discussing this
>> before was because we believed that if the controller was in native mode it 
>> must be
>> using the IRQ in PCI_INTERRUPT_LINE. But from yesterday's read of the 
>> specification
>> we know that PCI_INTERRUPT_LINE is never used by the device itself, and so 
>> given that
>> the existing via-ide device doesn't currently attempt to use the PCI IRQ in
>> via_ide_set_irq() then we should be good.
>>
>> If someone had a machine somewhere that did use the PCI IRQ then it would 
>> need
>> investigation, but since there isn't then I don't see any need to do this 
>> now.
>>
 Okay so this is interesting: I've been switching between the VT8231 and the
 VT82C686B
 datasheets, and there is a difference here. You are correct in what you 
 say above in
 that the 8231 docs specify that this is set to 1, but on the 686B this is 
 clearly
 not
 the case.
>>>
>>> The 82C686B says this reg can be 0 or 1, where 0 is legacy interrupt 
>>> routing and 1 is
>>> native mode. Given that we only model native mode of the chip it does not 
>>> make sense
>>> to set it to anything else than 1 and setting it to 0 confuses MorphOS and 
>>> Linux on
>>> pegasos2 while setting it to 1 works with everything I've tried both on 
>>> pegasos2 and
>>> fulong2e even if that may not completely match how it's implemented in 
>>> hardware.
>>>
 What is rather unusual here is that both the 8231 and 686B have exactly 
 the same
 device and vendor ids, so I'm not sure how you'd distinguish between them?
>>>
>>> Guests distinguish by looking at the parent device (function 0) which is 
>>> the chip
>>> this IDE device is part of (on function 1).
>>
>> Okay thanks, that's useful to know.
>>
>> I've done a quick grep of the source tree and AFAICT the only IDE controller 
>> that
>> tries to use the PCI_INTERRUPT_LINE register is via-ide, which means this 
>> should be
>> fairly easy. In short:
>>
>> 1) Add qemu_irq legacy_irqs[2] into PCIIDEState
>>
>> (You could argue that it should belong in a separate VIAIDEState, however 
>> quite a few
>> of the BMDMA controllers in QEMU don't have their own device state and just 
>> use
>> PCIIDEState. And whilst via-ide is the only one that currently needs support 
>> for
>> legacy IRQs, I think it's good to put it there in case other controllers 
>> need it in
>> future)
>>
>> 2) Add via_ide_initfn() to hw/ide/via.c and add qdev_init_gpio_out_named() 
>> with a
>> name of "legacy-irq" to it
> 
> I don't like this. This adds two via-ide specific data to to common PCI IDE 
> code
> where it does not belong and subclassing it just for this also seems to be 
> more
> changes than really needed. Reusing the existing CMD646 field and 
> generalising it to
> allow implementation specific feature flags seems much less intrusive and not 
> less
> clean than your proposal.

It's not VIA-specific though: the ISA legacy and PCI buses have different 
electrical
characteristics and so by definition their signals must be driven by separate
physical pins. Have a look at the CMD646 datasheet for example, and you will 
see that
separate pins exist for legacy and PCI native IRQs.

>> 3) Inline via_ide_init() into hw/mips/mips_fulong2e.c, changing 
>> pci_create_simple()
>> to pci_create() because the device shouldn't be realised immediately
>>
>> 4) In vt82c686b_southbridge_init use qdev_connect_gpio_out_named() to connect
>> legacy_irq[0] to 8259 IRQ 14 and legacy_irq[1] to 8259 IRQ 15, and then 
>> realise the
>> device
> 
> How do I connect gpios to 8259 interrupts? That seems to be internal state of 
> 8259
> that I'm not sure how to access cleanly from code instantiating it. Is this 
> better
> than my patc

Re: [PATCH v1 2/3] riscv/sifive_u: Add a serial property to the sifive_u SoC

2020-03-06 Thread Alistair Francis
On Thu, Mar 5, 2020 at 4:09 PM Bin Meng  wrote:
>
> Hi Alistair,
>
> On Fri, Mar 6, 2020 at 12:53 AM Alistair Francis  wrote:
> >
> > On Thu, Mar 5, 2020 at 1:31 AM Bin Meng  wrote:
> > >
> > > Hi Alistair,
> > >
> > > On Thu, Mar 5, 2020 at 7:13 AM Alistair Francis  
> > > wrote:
> > > >
> > > > On Wed, Mar 4, 2020 at 6:47 AM Bin Meng  wrote:
> > > > >
> > > > > Hi Alistair,
> > > > >
> > > > > On Wed, Mar 4, 2020 at 9:37 AM Alistair Francis
> > > > >  wrote:
> > > > > >
> > > > > > At present the board serial number is hard-coded to 1, and passed
> > > > > > to OTP model during initialization. Firmware (FSBL, U-Boot) uses
> > > > > > the serial number to generate a unique MAC address for the on-chip
> > > > > > ethernet controller. When multiple QEMU 'sifive_u' instances are
> > > > > > created and connected to the same subnet, they all have the same
> > > > > > MAC address hence it creates a unusable network.
> > > > > >
> > > > > > A new "serial" property is introduced to the sifive_u SoC to specify
> > > > > > the board serial number. When not given, the default serial number
> > > > > > 1 is used.
> > > > > >
> > > > > > Suggested-by: Bin Meng 
> > > > > > Signed-off-by: Alistair Francis 
> > > > > > ---
> > > > > >  hw/riscv/sifive_u.c | 8 +++-
> > > > > >  include/hw/riscv/sifive_u.h | 2 ++
> > > > > >  2 files changed, 9 insertions(+), 1 deletion(-)
> > > > > >
> > > > > > diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
> > > > > > index 9a0145b5b4..e52f9d0bd4 100644
> > > > > > --- a/hw/riscv/sifive_u.c
> > > > > > +++ b/hw/riscv/sifive_u.c
> > > > > > @@ -488,7 +488,7 @@ static void riscv_sifive_u_soc_init(Object *obj)
> > > > > >TYPE_SIFIVE_U_PRCI);
> > > > > >  sysbus_init_child_obj(obj, "otp", &s->otp, sizeof(s->otp),
> > > > > >TYPE_SIFIVE_U_OTP);
> > > > > > -qdev_prop_set_uint32(DEVICE(&s->otp), "serial", OTP_SERIAL);
> > > > > > +qdev_prop_set_uint32(DEVICE(&s->otp), "serial", s->serial);
> > > > > >  sysbus_init_child_obj(obj, "gem", &s->gem, sizeof(s->gem),
> > > > > >TYPE_CADENCE_GEM);
> > > > > >  }
> > > > > > @@ -607,10 +607,16 @@ static void 
> > > > > > riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp)
> > > > > >  memmap[SIFIVE_U_GEM_MGMT].base, 
> > > > > > memmap[SIFIVE_U_GEM_MGMT].size);
> > > > > >  }
> > > > > >
> > > > > > +static Property riscv_sifive_u_soc_props[] = {
> > > > > > +DEFINE_PROP_UINT32("serial", SiFiveUSoCState, serial, 
> > > > > > OTP_SERIAL),
> > > > > > +DEFINE_PROP_END_OF_LIST()
> > > > >
> > > > > I am not sure how adding another level of property in the SoC could
> > > > > solve the 'make check' error.
> > > >
> > > > The problem is that you were adding a machine property and then you
> > > > had the SoC reach up to the machine object to get the serial value.
> > > > This isn't correct and is why the tests fail.
> > > >
> > >
> > > So looks the failure was due to a check in the test codes only? As I
> > > did not see QEMU crashed during my normal usage.
> >
> > No, the bug was in the actual implementation. You were just lucky that
> > you didn't see any issues as in your case you could access the machine
> > state. The make check probably added the SoC individually and hence
> > caught the bug.
>
> That sounds like the difference that caused the crash in the test.
> Thanks for helping this!

No worries!

Alistair

>
> Regards,
> Bin



Re: [PATCH 0/7] post-rst-conversion cleanups

2020-03-06 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20200306171749.10756-1-peter.mayd...@linaro.org/



Hi,

This series failed the docker-clang@ubuntu build test. Please find the testing 
commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-ubuntu V=1 NETWORK=1
time make docker-test-clang@ubuntu SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===

  LINKfsdev/virtfs-proxy-helper
  LINKscsi/qemu-pr-helper
  LINKqemu-bridge-helper
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  LINKvirtiofsd
  LINKvhost-user-input
  GEN cris-softmmu/hmp-commands.h
---
  CC  mips64el-softmmu/qapi/qapi-commands-misc-target.o
  CC  hppa-softmmu/target/hppa/translate.o
  CC  mips64-softmmu/target/mips/cp0_helper.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  mips64el-softmmu/qapi/qapi-commands.o
  CC  mipsel-softmmu/qapi/qapi-visit-machine-target.o
  GEN trace/generated-helpers.c
---
  CC  or1k-softmmu/tcg/tcg-op-gvec.o
  CC  nios2-softmmu/tcg/optimize.o
  CC  moxie-softmmu/memory_mapping.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  i386-softmmu/trace/control-target.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  moxie-softmmu/migration/ram.o
  CC  arm-softmmu/hw/arm/fsl-imx7.o
  CC  or1k-softmmu/tcg/tcg-common.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  aarch64-softmmu/hw/arm/armsse.o
  CC  nios2-softmmu/fpu/softfloat.o
  CC  or1k-softmmu/tcg/optimize.o
---
  GEN or1k-softmmu/target/openrisc/decode.inc.c
  CC  nios2-softmmu/trace/control-target.o
  CC  ppc64-softmmu/hw/intc/pnv_xive.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  nios2-softmmu/softmmu/main.o
  GEN trace/generated-helpers.c
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  aarch64-softmmu/trace/control-target.o
  CC  ppc-softmmu/hw/vfio/pci-quirks.o
  CC  or1k-softmmu/target/openrisc/exception_helper.o
---
  CC  ppc64-softmmu/hw/rtc/mc146818rtc.o
  CC  riscv32-softmmu/tcg/tcg-common.o
  LINKor1k-softmmu/qemu-system-or1k
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  sh4-softmmu/fpu/softfloat.o
  CC  riscv64-softmmu/fpu/softfloat.o
  CC  riscv64-softmmu/disas.o
---
  CC  s390x-softmmu/gdbstub.o
  CC  sh4-softmmu/memory.o
  CC  ppc64-softmmu/hw/vfio/pci.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  ppc-softmmu/h

Re: [PATCH 2/2] via-ide: Also emulate non 100% native mode

2020-03-06 Thread BALATON Zoltan

On Fri, 6 Mar 2020, Mark Cave-Ayland wrote:

On 06/03/2020 12:06, BALATON Zoltan wrote:

On Fri, 6 Mar 2020, Mark Cave-Ayland wrote:

On 05/03/2020 23:35, BALATON Zoltan wrote:

On real hardware this may be true but in QEMU how would it otherwise raise the
correct interrupt line the guest expects? This probably does not matter for 
pegasos2
but I think is needed for 100% native mode used with the fulong2e so it gets 
the IRQ
it expects.


That's easy - remember that both the PCI and IRQ interrupts are separate pins 
on the
chip, so all that needs to be done is expose the legacy IRQ via qdev and use 
that to
wire it up to your interrupt controller.


This "chip" is part of an integrated southbridge/superio/everything chip the 
also
includes the two PICs and how they are internally connected is not known so we 
would
be guessing here anyway. I don't see a need to make it more complicated than it 
is
now by modeling internal pins but how would I wire up gpio to the i8259 model 
and
where should I connect the PCI irq?


For now I would say not to worry about the PCI IRQ: the reason for discussing 
this
before was because we believed that if the controller was in native mode it 
must be
using the IRQ in PCI_INTERRUPT_LINE. But from yesterday's read of the 
specification
we know that PCI_INTERRUPT_LINE is never used by the device itself, and so 
given that
the existing via-ide device doesn't currently attempt to use the PCI IRQ in
via_ide_set_irq() then we should be good.

If someone had a machine somewhere that did use the PCI IRQ then it would need
investigation, but since there isn't then I don't see any need to do this now.


Okay so this is interesting: I've been switching between the VT8231 and the 
VT82C686B
datasheets, and there is a difference here. You are correct in what you say 
above in
that the 8231 docs specify that this is set to 1, but on the 686B this is 
clearly not
the case.


The 82C686B says this reg can be 0 or 1, where 0 is legacy interrupt routing 
and 1 is
native mode. Given that we only model native mode of the chip it does not make 
sense
to set it to anything else than 1 and setting it to 0 confuses MorphOS and 
Linux on
pegasos2 while setting it to 1 works with everything I've tried both on 
pegasos2 and
fulong2e even if that may not completely match how it's implemented in hardware.


What is rather unusual here is that both the 8231 and 686B have exactly the same
device and vendor ids, so I'm not sure how you'd distinguish between them?


Guests distinguish by looking at the parent device (function 0) which is the 
chip
this IDE device is part of (on function 1).


Okay thanks, that's useful to know.

I've done a quick grep of the source tree and AFAICT the only IDE controller 
that
tries to use the PCI_INTERRUPT_LINE register is via-ide, which means this 
should be
fairly easy. In short:

1) Add qemu_irq legacy_irqs[2] into PCIIDEState

(You could argue that it should belong in a separate VIAIDEState, however quite 
a few
of the BMDMA controllers in QEMU don't have their own device state and just use
PCIIDEState. And whilst via-ide is the only one that currently needs support for
legacy IRQs, I think it's good to put it there in case other controllers need 
it in
future)

2) Add via_ide_initfn() to hw/ide/via.c and add qdev_init_gpio_out_named() with 
a
name of "legacy-irq" to it


I don't like this. This adds two via-ide specific data to to common PCI 
IDE code where it does not belong and subclassing it just for this also 
seems to be more changes than really needed. Reusing the existing CMD646 
field and generalising it to allow implementation specific feature flags 
seems much less intrusive and not less clean than your proposal.



3) Inline via_ide_init() into hw/mips/mips_fulong2e.c, changing 
pci_create_simple()
to pci_create() because the device shouldn't be realised immediately

4) In vt82c686b_southbridge_init use qdev_connect_gpio_out_named() to connect
legacy_irq[0] to 8259 IRQ 14 and legacy_irq[1] to 8259 IRQ 15, and then realise 
the
device


How do I connect gpios to 8259 interrupts? That seems to be internal 
state of 8259 that I'm not sure how to access cleanly from code 
instantiating it. Is this better than my patch? It seems it achieves the 
same via-ide specific behaviour just in a more complicated way and would 
still need the feature bit to know when to use legacy_irq[1].



5) Remove the PCI_INTERRUPT_LINE logic from via_ide_set_irq() and instead just 
do
qemu_set_irq() on legacy_irq[0] (in theory I guess it should be legacy_irq[n] 
but it
seems that both drives on MIPS and Pegasos both use IRQ 14).


According to the 8231 datasheet in legacy mode (and on pegasos2's 
half-native mode) the interrupts should be 14 and 15 so legacy_irq[n] with 
your way but in 100% native mode (used on the fulong2e) it should be the 
one set in PCI_INTERRUPT_LINE. The 686B datasheet does not detail this but 
I believe it works the same. Since we currently fixed the native m

Re: [PULL 00/29] Block layer patches

2020-03-06 Thread Peter Maydell
On Fri, 6 Mar 2020 at 17:15, Kevin Wolf  wrote:
>
> The following changes since commit f4c4357fbfca0fb14e477bf661ae7384b4b9b283:
>
>   Merge remote-tracking branch 'remotes/pmaydell/tags/pull-docs-20200306' 
> into staging (2020-03-06 11:11:54 +)
>
> are available in the Git repository at:
>
>   git://repo.or.cz/qemu/kevin.git tags/for-upstream
>
> for you to fetch changes up to 1de6b45fb5c1489b450df7d1a4c692bba9678ce6:
>
>   block: bdrv_reopen() with backing file in different AioContext (2020-03-06 
> 17:34:09 +0100)
>
> 
> Block layer patches:
>
> - Add qemu-storage-daemon (still experimental)
> - rbd: Add support for ceph namespaces
> - Fix bdrv_reopen() with backing file in different AioContext
> - qcow2: Fix read-write reopen with persistent dirty bitmaps
> - qcow2: Fix alloc_cluster_abort() for pre-existing clusters
>


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.0
for any user-visible changes.

-- PMM



Re: [PULL 00/29] Block layer patches

2020-03-06 Thread no-reply
Patchew URL: https://patchew.org/QEMU/20200306171458.1848-1-kw...@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Subject: [PULL 00/29] Block layer patches
Message-id: 20200306171458.1848-1-kw...@redhat.com
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 - [tag update]  patchew/20200226155304.60219-1-da...@redhat.com -> 
patchew/20200226155304.60219-1-da...@redhat.com
Switched to a new branch 'test'
32121e1 block: bdrv_reopen() with backing file in different AioContext
b4fc54d iotests: Refactor blockdev-reopen test for iothreads
2d8f428 block/rbd: Add support for ceph namespaces
b316a0b qemu-storage-daemon: Add --monitor option
caf92c2 monitor: Add allow_hmp parameter to monitor_init()
73480ad hmp: Fail gracefully if chardev is already in use
1a7c874 qmp: Fail gracefully if chardev is already in use
f7fbb53 monitor: Create QAPIfied monitor_init()
85141e5 qapi: Create 'pragma' module
5012797 stubs: Update monitor stubs for qemu-storage-daemon
a32e4ac qemu-storage-daemon: Add --chardev option
2a264c4 qemu-storage-daemon: Add main loop
0f2bb9d qemu-storage-daemon: Add --export option
95f79fa blockdev-nbd: Boxed argument type for nbd-server-add
c3e93ca qemu-storage-daemon: Add --nbd-server option
2a54241 qemu-storage-daemon: Add --object option
b3767de qapi: Flatten object-add
40c88aa qemu-storage-daemon: Add --blockdev option
f52856a block: Move sysemu QMP commands to QAPI block module
280af2e block: Move common QMP commands to block-core QAPI module
223169a block: Move system emulator QMP commands to block/qapi-sysemu.c
c687d45 stubs: Add arch_type
1ca4df6 qemu-storage-daemon: Add barebone tool
e148d2c block/qcow2: Move bitmap reopen into bdrv_reopen_commit_post
90ceeb8 block: Introduce 'bdrv_reopen_commit_post' step
f82447c block: Fix leak in bdrv_create_file_fallback()
6c79b95 iotests/026: Test EIO on allocation in a data-file
ce45c2f iotests/026: Test EIO on preallocated zero cluster
6fe3d12 qcow2: Fix alloc_cluster_abort() for pre-existing clusters

=== OUTPUT BEGIN ===
1/29 Checking commit 6fe3d1204d78 (qcow2: Fix alloc_cluster_abort() for 
pre-existing clusters)
2/29 Checking commit ce45c2f906d8 (iotests/026: Test EIO on preallocated zero 
cluster)
3/29 Checking commit 6c79b9543536 (iotests/026: Test EIO on allocation in a 
data-file)
4/29 Checking commit f82447c66adc (block: Fix leak in 
bdrv_create_file_fallback())
5/29 Checking commit 90ceeb8bb6dc (block: Introduce 'bdrv_reopen_commit_post' 
step)
6/29 Checking commit e148d2cd2ef4 (block/qcow2: Move bitmap reopen into 
bdrv_reopen_commit_post)
7/29 Checking commit 1ca4df6e0c59 (qemu-storage-daemon: Add barebone tool)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#49: 
new file mode 100644

total: 0 errors, 1 warnings, 142 lines checked

Patch 7/29 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
8/29 Checking commit c687d45eee38 (stubs: Add arch_type)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#40: 
new file mode 100644

total: 0 errors, 1 warnings, 16 lines checked

Patch 8/29 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
9/29 Checking commit 223169a6a829 (block: Move system emulator QMP commands to 
block/qapi-sysemu.c)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#32: 
new file mode 100644

WARNING: Block comments use a leading /* on a separate line
#258: FILE: block/qapi-sysemu.c:222:
+/* For tray-less devices, blockdev-open-tray is a no-op (or may not be

WARNING: Block comments use a trailing */ on a separate line
#261: FILE: block/qapi-sysemu.c:225:
+ * value passed here (i.e. false). */

WARNING: Block comments use a leading /* on a separate line
#305: FILE: block/qapi-sysemu.c:269:
+/* For tray-less devices, blockdev-close-tray is a no-op (or may not be

WARNING: Block comments use a trailing */ on a separate line
#309: FILE: block/qapi-sysemu.c:273:
+ * value passed here (i.e. true). */

WARNING: Block comments use a leading /* on a separate line
#442: FILE: block/qapi-sysemu.c:406:
+/* If the medium has been inserted, the device has its own reference, so

WARNING: Block comments use a trailing */ on a separate line
#444: FILE: block/qapi-sysemu.c:408:
+ * the reference must be relinquished anyway */

WARNING: Block comments use a leading /* on a separate line
#551: FILE: block/qapi-sysemu.c:515:
+/* Enable I/O limits if they're not 

Re: [PATCH v3 09/13] migration/ram: Consolidate variable reset after placement in ram_load_postcopy()

2020-03-06 Thread Dr. David Alan Gilbert
* David Hildenbrand (da...@redhat.com) wrote:
> On 06.03.20 17:30, Dr. David Alan Gilbert wrote:
> > * David Hildenbrand (da...@redhat.com) wrote:
> >> Let's consolidate resetting the variables.
> >>
> >> Cc: "Dr. David Alan Gilbert" 
> >> Cc: Juan Quintela 
> >> Cc: Peter Xu 
> >> Signed-off-by: David Hildenbrand 
> > 
> > Thanks, I think that's actually fixing a case where huge zero pages
> > weren't placed as zero pages?
> 
> I don't see it :) Can you point out in which receive sequence it would
> go wrong?
> 
> We used to set "all_zero = true" when processing the first sub-page.
> Now, we set "all_zero = true" before we start to process the first sub-page.

No, you're right - no change.

Dave

> Thanks!
> 
> -- 
> Thanks,
> 
> David / dhildenb
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK




Re: [PATCH v3 09/13] migration/ram: Consolidate variable reset after placement in ram_load_postcopy()

2020-03-06 Thread David Hildenbrand
On 06.03.20 17:30, Dr. David Alan Gilbert wrote:
> * David Hildenbrand (da...@redhat.com) wrote:
>> Let's consolidate resetting the variables.
>>
>> Cc: "Dr. David Alan Gilbert" 
>> Cc: Juan Quintela 
>> Cc: Peter Xu 
>> Signed-off-by: David Hildenbrand 
> 
> Thanks, I think that's actually fixing a case where huge zero pages
> weren't placed as zero pages?

I don't see it :) Can you point out in which receive sequence it would
go wrong?

We used to set "all_zero = true" when processing the first sub-page.
Now, we set "all_zero = true" before we start to process the first sub-page.

Thanks!

-- 
Thanks,

David / dhildenb




Re: [PATCH v3 10/13] migration/ram: Handle RAM block resizes during postcopy

2020-03-06 Thread Dr. David Alan Gilbert
* David Hildenbrand (da...@redhat.com) wrote:
> On 06.03.20 17:56, Dr. David Alan Gilbert wrote:
> > * David Hildenbrand (da...@redhat.com) wrote:
> >> Resizing while migrating is dangerous and does not work as expected.
> >> The whole migration code works on the usable_length of ram blocks and does
> >> not expect this to change at random points in time.
> >>
> >> In the case of postcopy, relying on used_length is racy as soon as the
> >> guest is running. Also, when used_length changes we might leave the
> >> uffd handler registered for some memory regions, reject valid pages
> >> when migrating and fail when sending the recv bitmap to the source.
> >>
> >> Resizing can be trigger *after* (but not during) a reset in
> >> ACPI code by the guest
> >> - hw/arm/virt-acpi-build.c:acpi_ram_update()
> >> - hw/i386/acpi-build.c:acpi_ram_update()
> >>
> >> Let's remember the original used_length in a separate variable and
> >> use it in relevant postcopy code. Make sure to update it when we resize
> >> during precopy, when synchronizing the RAM block sizes with the source.
> >>
> >> Reviewed-by: Peter Xu 
> >> Cc: "Dr. David Alan Gilbert" 
> >> Cc: Juan Quintela 
> >> Cc: Eduardo Habkost 
> >> Cc: Paolo Bonzini 
> >> Cc: Igor Mammedov 
> >> Cc: "Michael S. Tsirkin" 
> >> Cc: Richard Henderson 
> >> Cc: Shannon Zhao 
> >> Cc: Alex Bennée 
> >> Cc: Peter Xu 
> >> Signed-off-by: David Hildenbrand 
> >> ---
> >>  include/exec/ramblock.h  | 10 ++
> >>  migration/postcopy-ram.c | 15 ---
> >>  migration/ram.c  | 11 +--
> >>  3 files changed, 31 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h
> >> index 07d50864d8..664701b759 100644
> >> --- a/include/exec/ramblock.h
> >> +++ b/include/exec/ramblock.h
> >> @@ -59,6 +59,16 @@ struct RAMBlock {
> >>   */
> >>  unsigned long *clear_bmap;
> >>  uint8_t clear_bmap_shift;
> >> +
> >> +/*
> >> + * RAM block length that corresponds to the used_length on the 
> >> migration
> >> + * source (after RAM block sizes were synchronized). Especially, after
> >> + * starting to run the guest, used_length and postcopy_length can 
> >> differ.
> >> + * Used to register/unregister uffd handlers and as the size of the 
> >> received
> >> + * bitmap. Receiving any page beyond this length will bail out, as it
> >> + * could not have been valid on the source.
> >> + */
> >> +ram_addr_t postcopy_length;
> >>  };
> >>  #endif
> >>  #endif
> >> diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
> >> index a36402722b..c68caf4e42 100644
> >> --- a/migration/postcopy-ram.c
> >> +++ b/migration/postcopy-ram.c
> >> @@ -17,6 +17,7 @@
> >>   */
> >>  
> >>  #include "qemu/osdep.h"
> >> +#include "qemu/rcu.h"
> >>  #include "exec/target_page.h"
> >>  #include "migration.h"
> >>  #include "qemu-file.h"
> >> @@ -31,6 +32,7 @@
> >>  #include "qemu/error-report.h"
> >>  #include "trace.h"
> >>  #include "hw/boards.h"
> >> +#include "exec/ramblock.h"
> >>  
> >>  /* Arbitrary limit on size of each discard command,
> >>   * keeps them around ~200 bytes
> >> @@ -456,6 +458,13 @@ static int init_range(RAMBlock *rb, void *opaque)
> >>  ram_addr_t length = qemu_ram_get_used_length(rb);
> >>  trace_postcopy_init_range(block_name, host_addr, offset, length);
> >>  
> >> +/*
> >> + * Save the used_length before running the guest. In case we have to
> >> + * resize RAM blocks when syncing RAM block sizes from the source 
> >> during
> >> + * precopy, we'll update it manually via the ram block notifier.
> >> + */
> >> +rb->postcopy_length = length;
> >> +
> >>  /*
> >>   * We need the whole of RAM to be truly empty for postcopy, so things
> >>   * like ROMs and any data tables built during init must be zero'd
> >> @@ -478,7 +487,7 @@ static int cleanup_range(RAMBlock *rb, void *opaque)
> >>  const char *block_name = qemu_ram_get_idstr(rb);
> >>  void *host_addr = qemu_ram_get_host_addr(rb);
> >>  ram_addr_t offset = qemu_ram_get_offset(rb);
> >> -ram_addr_t length = qemu_ram_get_used_length(rb);
> >> +ram_addr_t length = rb->postcopy_length;
> >>  MigrationIncomingState *mis = opaque;
> >>  struct uffdio_range range_struct;
> >>  trace_postcopy_cleanup_range(block_name, host_addr, offset, length);
> >> @@ -600,7 +609,7 @@ static int nhp_range(RAMBlock *rb, void *opaque)
> >>  const char *block_name = qemu_ram_get_idstr(rb);
> >>  void *host_addr = qemu_ram_get_host_addr(rb);
> >>  ram_addr_t offset = qemu_ram_get_offset(rb);
> >> -ram_addr_t length = qemu_ram_get_used_length(rb);
> >> +ram_addr_t length = rb->postcopy_length;
> >>  trace_postcopy_nhp_range(block_name, host_addr, offset, length);
> >>  
> >>  /*
> >> @@ -644,7 +653,7 @@ static int ram_block_enable_notify(RAMBlock *rb, void 
> >> *opaque)
> >>  struct uffdio_register reg_struct;
> >>  
> >>  reg

Re: [PATCH v3 08/13] migration/ram: Simplify host page handling in ram_load_postcopy()

2020-03-06 Thread Dr. David Alan Gilbert
* David Hildenbrand (da...@redhat.com) wrote:
> On 06.03.20 17:20, David Hildenbrand wrote:
> > On 06.03.20 17:05, Dr. David Alan Gilbert wrote:
> >> * David Hildenbrand (da...@redhat.com) wrote:
> >>> Add two new helper functions. This will in come handy once we want to
> >>> handle ram block resizes while postcopy is active.
> >>>
> >>> Cc: "Dr. David Alan Gilbert" 
> >>> Cc: Juan Quintela 
> >>> Cc: Peter Xu 
> >>> Signed-off-by: David Hildenbrand 
> >>> ---
> >>>  migration/ram.c | 54 -
> >>>  1 file changed, 31 insertions(+), 23 deletions(-)
> >>>
> >>> diff --git a/migration/ram.c b/migration/ram.c
> >>> index d5a4d69e1c..f815f4e532 100644
> >>> --- a/migration/ram.c
> >>> +++ b/migration/ram.c
> >>> @@ -2734,6 +2734,20 @@ static inline void 
> >>> *host_from_ram_block_offset(RAMBlock *block,
> >>>  return block->host + offset;
> >>>  }
> >>>  
> >>> +static void *host_page_from_ram_block_offset(RAMBlock *block,
> >>> + ram_addr_t offset)
> >>> +{
> >>> +/* Note: Explicitly no check against offset_in_ramblock(). */
> >>> +return (void *)QEMU_ALIGN_DOWN((uintptr_t)block->host + offset,
> >>> +   block->page_size);
> >>> +}
> >>> +
> >>> +static ram_addr_t host_page_offset_from_ram_block_offset(RAMBlock *block,
> >>> + ram_addr_t 
> >>> offset)
> >>> +{
> >>> +return ((uintptr_t)block->host + offset) & (block->page_size - 1);
> >>> +}
> >>> +
> >>>  static inline void *colo_cache_from_block_offset(RAMBlock *block,
> >>>   ram_addr_t offset)
> >>>  {
> >>> @@ -3111,13 +3125,12 @@ static int ram_load_postcopy(QEMUFile *f)
> >>>  MigrationIncomingState *mis = migration_incoming_get_current();
> >>>  /* Temporary page that is later 'placed' */
> >>>  void *postcopy_host_page = mis->postcopy_tmp_page;
> >>> -void *this_host = NULL;
> >>> +void *host_page = NULL;
> >>>  bool all_zero = false;
> >>>  int target_pages = 0;
> >>>  
> >>>  while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) {
> >>>  ram_addr_t addr;
> >>> -void *host = NULL;
> >>>  void *page_buffer = NULL;
> >>>  void *place_source = NULL;
> >>>  RAMBlock *block = NULL;
> >>> @@ -3143,9 +3156,12 @@ static int ram_load_postcopy(QEMUFile *f)
> >>>  if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE |
> >>>   RAM_SAVE_FLAG_COMPRESS_PAGE)) {
> >>>  block = ram_block_from_stream(f, flags);
> >>> +if (!block) {
> >>> +ret = -EINVAL;
> >>
> >> Could we have an error_report there, at the moment it would trigger
> >> the one below.
> > 
> > Makes sense, I'll add one!
> 
> My memory kicks in: This was dropped on purpose. ram_block_from_stream()
> will print proper errors already.

OK!

Dave

> Cheers!
> 
> 
> -- 
> Thanks,
> 
> David / dhildenb
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK




Re: [PATCH v3 08/13] migration/ram: Simplify host page handling in ram_load_postcopy()

2020-03-06 Thread David Hildenbrand
On 06.03.20 17:20, David Hildenbrand wrote:
> On 06.03.20 17:05, Dr. David Alan Gilbert wrote:
>> * David Hildenbrand (da...@redhat.com) wrote:
>>> Add two new helper functions. This will in come handy once we want to
>>> handle ram block resizes while postcopy is active.
>>>
>>> Cc: "Dr. David Alan Gilbert" 
>>> Cc: Juan Quintela 
>>> Cc: Peter Xu 
>>> Signed-off-by: David Hildenbrand 
>>> ---
>>>  migration/ram.c | 54 -
>>>  1 file changed, 31 insertions(+), 23 deletions(-)
>>>
>>> diff --git a/migration/ram.c b/migration/ram.c
>>> index d5a4d69e1c..f815f4e532 100644
>>> --- a/migration/ram.c
>>> +++ b/migration/ram.c
>>> @@ -2734,6 +2734,20 @@ static inline void 
>>> *host_from_ram_block_offset(RAMBlock *block,
>>>  return block->host + offset;
>>>  }
>>>  
>>> +static void *host_page_from_ram_block_offset(RAMBlock *block,
>>> + ram_addr_t offset)
>>> +{
>>> +/* Note: Explicitly no check against offset_in_ramblock(). */
>>> +return (void *)QEMU_ALIGN_DOWN((uintptr_t)block->host + offset,
>>> +   block->page_size);
>>> +}
>>> +
>>> +static ram_addr_t host_page_offset_from_ram_block_offset(RAMBlock *block,
>>> + ram_addr_t offset)
>>> +{
>>> +return ((uintptr_t)block->host + offset) & (block->page_size - 1);
>>> +}
>>> +
>>>  static inline void *colo_cache_from_block_offset(RAMBlock *block,
>>>   ram_addr_t offset)
>>>  {
>>> @@ -3111,13 +3125,12 @@ static int ram_load_postcopy(QEMUFile *f)
>>>  MigrationIncomingState *mis = migration_incoming_get_current();
>>>  /* Temporary page that is later 'placed' */
>>>  void *postcopy_host_page = mis->postcopy_tmp_page;
>>> -void *this_host = NULL;
>>> +void *host_page = NULL;
>>>  bool all_zero = false;
>>>  int target_pages = 0;
>>>  
>>>  while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) {
>>>  ram_addr_t addr;
>>> -void *host = NULL;
>>>  void *page_buffer = NULL;
>>>  void *place_source = NULL;
>>>  RAMBlock *block = NULL;
>>> @@ -3143,9 +3156,12 @@ static int ram_load_postcopy(QEMUFile *f)
>>>  if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE |
>>>   RAM_SAVE_FLAG_COMPRESS_PAGE)) {
>>>  block = ram_block_from_stream(f, flags);
>>> +if (!block) {
>>> +ret = -EINVAL;
>>
>> Could we have an error_report there, at the moment it would trigger
>> the one below.
> 
> Makes sense, I'll add one!

My memory kicks in: This was dropped on purpose. ram_block_from_stream()
will print proper errors already.

Cheers!


-- 
Thanks,

David / dhildenb




Re: [PATCH v3 10/13] migration/ram: Handle RAM block resizes during postcopy

2020-03-06 Thread David Hildenbrand
On 06.03.20 17:56, Dr. David Alan Gilbert wrote:
> * David Hildenbrand (da...@redhat.com) wrote:
>> Resizing while migrating is dangerous and does not work as expected.
>> The whole migration code works on the usable_length of ram blocks and does
>> not expect this to change at random points in time.
>>
>> In the case of postcopy, relying on used_length is racy as soon as the
>> guest is running. Also, when used_length changes we might leave the
>> uffd handler registered for some memory regions, reject valid pages
>> when migrating and fail when sending the recv bitmap to the source.
>>
>> Resizing can be trigger *after* (but not during) a reset in
>> ACPI code by the guest
>> - hw/arm/virt-acpi-build.c:acpi_ram_update()
>> - hw/i386/acpi-build.c:acpi_ram_update()
>>
>> Let's remember the original used_length in a separate variable and
>> use it in relevant postcopy code. Make sure to update it when we resize
>> during precopy, when synchronizing the RAM block sizes with the source.
>>
>> Reviewed-by: Peter Xu 
>> Cc: "Dr. David Alan Gilbert" 
>> Cc: Juan Quintela 
>> Cc: Eduardo Habkost 
>> Cc: Paolo Bonzini 
>> Cc: Igor Mammedov 
>> Cc: "Michael S. Tsirkin" 
>> Cc: Richard Henderson 
>> Cc: Shannon Zhao 
>> Cc: Alex Bennée 
>> Cc: Peter Xu 
>> Signed-off-by: David Hildenbrand 
>> ---
>>  include/exec/ramblock.h  | 10 ++
>>  migration/postcopy-ram.c | 15 ---
>>  migration/ram.c  | 11 +--
>>  3 files changed, 31 insertions(+), 5 deletions(-)
>>
>> diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h
>> index 07d50864d8..664701b759 100644
>> --- a/include/exec/ramblock.h
>> +++ b/include/exec/ramblock.h
>> @@ -59,6 +59,16 @@ struct RAMBlock {
>>   */
>>  unsigned long *clear_bmap;
>>  uint8_t clear_bmap_shift;
>> +
>> +/*
>> + * RAM block length that corresponds to the used_length on the migration
>> + * source (after RAM block sizes were synchronized). Especially, after
>> + * starting to run the guest, used_length and postcopy_length can 
>> differ.
>> + * Used to register/unregister uffd handlers and as the size of the 
>> received
>> + * bitmap. Receiving any page beyond this length will bail out, as it
>> + * could not have been valid on the source.
>> + */
>> +ram_addr_t postcopy_length;
>>  };
>>  #endif
>>  #endif
>> diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
>> index a36402722b..c68caf4e42 100644
>> --- a/migration/postcopy-ram.c
>> +++ b/migration/postcopy-ram.c
>> @@ -17,6 +17,7 @@
>>   */
>>  
>>  #include "qemu/osdep.h"
>> +#include "qemu/rcu.h"
>>  #include "exec/target_page.h"
>>  #include "migration.h"
>>  #include "qemu-file.h"
>> @@ -31,6 +32,7 @@
>>  #include "qemu/error-report.h"
>>  #include "trace.h"
>>  #include "hw/boards.h"
>> +#include "exec/ramblock.h"
>>  
>>  /* Arbitrary limit on size of each discard command,
>>   * keeps them around ~200 bytes
>> @@ -456,6 +458,13 @@ static int init_range(RAMBlock *rb, void *opaque)
>>  ram_addr_t length = qemu_ram_get_used_length(rb);
>>  trace_postcopy_init_range(block_name, host_addr, offset, length);
>>  
>> +/*
>> + * Save the used_length before running the guest. In case we have to
>> + * resize RAM blocks when syncing RAM block sizes from the source during
>> + * precopy, we'll update it manually via the ram block notifier.
>> + */
>> +rb->postcopy_length = length;
>> +
>>  /*
>>   * We need the whole of RAM to be truly empty for postcopy, so things
>>   * like ROMs and any data tables built during init must be zero'd
>> @@ -478,7 +487,7 @@ static int cleanup_range(RAMBlock *rb, void *opaque)
>>  const char *block_name = qemu_ram_get_idstr(rb);
>>  void *host_addr = qemu_ram_get_host_addr(rb);
>>  ram_addr_t offset = qemu_ram_get_offset(rb);
>> -ram_addr_t length = qemu_ram_get_used_length(rb);
>> +ram_addr_t length = rb->postcopy_length;
>>  MigrationIncomingState *mis = opaque;
>>  struct uffdio_range range_struct;
>>  trace_postcopy_cleanup_range(block_name, host_addr, offset, length);
>> @@ -600,7 +609,7 @@ static int nhp_range(RAMBlock *rb, void *opaque)
>>  const char *block_name = qemu_ram_get_idstr(rb);
>>  void *host_addr = qemu_ram_get_host_addr(rb);
>>  ram_addr_t offset = qemu_ram_get_offset(rb);
>> -ram_addr_t length = qemu_ram_get_used_length(rb);
>> +ram_addr_t length = rb->postcopy_length;
>>  trace_postcopy_nhp_range(block_name, host_addr, offset, length);
>>  
>>  /*
>> @@ -644,7 +653,7 @@ static int ram_block_enable_notify(RAMBlock *rb, void 
>> *opaque)
>>  struct uffdio_register reg_struct;
>>  
>>  reg_struct.range.start = (uintptr_t)qemu_ram_get_host_addr(rb);
>> -reg_struct.range.len = qemu_ram_get_used_length(rb);
>> +reg_struct.range.len = rb->postcopy_length;
>>  reg_struct.mode = UFFDIO_REGISTER_MODE_MISSING;
>>  
>>  /* Now tell our userfault_fd that it's responsible 

Re: [PATCH 2/2] via-ide: Also emulate non 100% native mode

2020-03-06 Thread Mark Cave-Ayland
On 06/03/2020 12:40, BALATON Zoltan wrote:

> On Fri, 6 Mar 2020, Mark Cave-Ayland wrote:
>> On 06/03/2020 00:21, BALATON Zoltan wrote:
>>> On Fri, 6 Mar 2020, BALATON Zoltan wrote:
 On Thu, 5 Mar 2020, Mark Cave-Ayland wrote:
> On 04/03/2020 22:33, BALATON Zoltan wrote:
> another possibility: PCI configuration space register 0x3d (Interrupt 
> pin) is
> documented as having value 0 == Legacy IRQ routing which should be the 
> initial
> value
> on reset, but QEMU incorrectly sets it to 1 which indicates PCI IRQ 
> routing.

 The VT8231 docs say this should always read 1 but may be this is somehow 
 set to 0
 on the Pegasos2. What does that mean? Should we use this value instead of 
 the
 feature bit to force using legacy interrupts? We'd still need a property 
 in via-ide
 to set this reg or is it possible to set it from board code overriding the 
 default
 after device is created? That would allow to drop patch 1. I can try this.
>>>
>>> This seemed like it could simplify patches a bit but it does not work. 
>>> Setting this
>>> reg to 0 breaks Linux and MorphOS which then think the device does not have 
>>> an
>>> interrupt at all and fail as before waiting for the irq. So we still need 
>>> the feature
>>> bit, cant use this reg to force legacy interrupts. I've spent considerable 
>>> time
>>> testing different OSes before I've ended up with this patch series I've 
>>> submitted and
>>> I could not find a simpler way that works with everything.
>>
>> I appreciate that testing these things can take a lot of time, but what is 
>> important
>> thing to ask here is whether these hacks are attempting to work around 
>> something in
>> QEMU that doesn't match the hardware specification, and to me it feels that 
>> this is
>> what is happening here.
> 
> It may be we need to work around some incomplete modelling of devices in 
> QEMU, e.g.
> we only model the native mode of these IDE interfaces so anything involving 
> legacy
> mode is out of scope. To also emulate legacy mode we'd need changing common 
> ISA code
> and maybe PIC code as well. As those parts are also used by other more 
> commonly used
> machine models I'd avoid breaking those and rather implement it confined to 
> these
> machines that are not yet finished or complete anyway than try to change all
> dependent devices that would need even more testing. These "hacks" could be 
> cleaned
> up later and this would not be the only hack in QEMU, I don't have time to fix
> everything and it's unreasonable to demand it I think. I'd suggest to take 
> this patch
> as it is now and if you don't like it you can submit patches that clean it up 
> the way
> you think is correct or submit an alternative patch now that shows how do you 
> think
> it can be done in a cleaner way because I don't see it and don't have more 
> time for
> it now.
> 
>> Obviously this thread has become quite long (and even I'm struggling to find 
>> previous
>> discussions) but here is my summary below:
>>
>> - I don't think the patch in its current form is the right way to do this. 
>> Instead of
>> adding a feature bit to fudge the existing IRQ routing when the existing IRQ 
>> routing
>> is wrong, let's fix the existing IRQ routing instead.
> 
> I think that would involve changing parts which could break other machines so 
> I'd
> rather go with a featute bit only affecting pegasos2 and fulonge2 than touch 
> i8259 or
> ISA emulation basing that on some guess how the real chip may be implemented. 
> Is it
> possible to implement what you propose without changing common IDE, ISA and 
> PIC
> emulation only in via-ide and fulong2e code?
> 
>> - There is no mention of "non-100%" native mode in the 8231 or 686B 
>> datasheet: this
>> is simply a term used within the Linux patches. The controller is either in 
>> native
>> mode, or legacy mode. It may be that guests are making use of some undefined
>> behaviour here.
> 
> Yes, this is a Linux term and Linux also uses a feature bit to enable this
> workaround. If that's good enough for Linux why isn't it good enough for you?
> 
>> - The code that uses the value of PCI_INTERRUPT_LINE in via-ide is incorrect 
>> (as your
>> patch comment points out, some guests ignore it anyway).
> 
> You're misunderstanding the comment. The via_ide_config_read function is 
> needed to
> restore value in interrupt line that common PCI reset code deletes. Linux 
> depends on
> this value to be the same as on real hardware so this is needed to work 
> around QEMU
> and Linux pecularities.
> 
> I've tried using PCI_INTERRUPT_PIN in place of the feature bit but setting 
> that to 0
> breaks Linux and MorphOS on pegasos2 because these apparently expect this to 
> be set
> to 1 corresponding to native mode. (Firmware only sets native mode enable 
> bits in
> prog-if but datasheet says this reg should be 1 by default and other PCI docs 
> say 0
> here means no interrupt used so maybe

Re: [PATCH] build-sys: Move the print-variable rule to rules.mak

2020-03-06 Thread no-reply
Patchew URL: https://patchew.org/QEMU/20200306170456.21977-1-phi...@redhat.com/



Hi,

This series failed the docker-clang@ubuntu build test. Please find the testing 
commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-ubuntu V=1 NETWORK=1
time make docker-test-clang@ubuntu SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===

  LINKqemu-bridge-helper
  LINKvirtiofsd
  LINKvhost-user-input
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`/usr/bin/ldrpc_createerr@@GLIBC_2.2.5' overridden by definition from : 
/lib/x86_64-linux-gnu/libc.so.6/lib/x86_64-linux-gnu/libtirpc.so.3
: warning: common of `rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  GEN cris-softmmu/hmp-commands.h
  GEN m68k-softmmu/hmp-commands.h
  GEN microblazeel-softmmu/hmp-commands.h
---
  CC  mips64-softmmu/target/mips/translate.o
  CC  mips-softmmu/softmmu/vl.o
  CC  mips64el-softmmu/qapi/qapi-commands.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3rpc_createerr@@GLIBC_2.2.5: 
warning: common of `' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  alpha-softmmu/target/alpha/helper.o
  CC  aarch64-softmmu/hw/arm/exynos4_boards.o
  CC  arm-softmmu/hw/arm/exynos4_boards.o
---
  CC  arm-softmmu/qapi/qapi-types.o
  CC  ppc-softmmu/memory.o
  CC  moxie-softmmu/accel/tcg/cpu-exec.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  i386-softmmu/trace/generated-helpers.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  moxie-softmmu/accel/tcg/cpu-exec-common.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  nios2-softmmu/accel/tcg/translate-all.o
  CC  mipsel-softmmu/dump/dump.o
  CC  arm-softmmu/qapi/qapi-visit-machine-target.o
---
  CC  nios2-softmmu/target/nios2/mmu.o
  CC  arm-softmmu/target/arm/iwmmxt_helper.o
  CC  mipsel-softmmu/hw/virtio/vhost-backend.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  ppc-softmmu/hw/scsi/vhost-scsi-common.o
  CC  aarch64-softmmu/target/arm/debug_helper.o
  CC  nios2-softmmu/target/nios2/nios2-semi.o
---
  CC  mipsel-softmmu/hw/virtio/vhost-vsock.o
  CC  ppc64-softmmu/arch_init.o
  CC  ppc-softmmu/hw/vfio/display.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  ppc64-softmmu/cpus.o
  CC  mipsel-softmmu/hw/virtio/vhost-vsock-pci.o
  GEN riscv32-softmmu/hmp-commands.h
---
  CC  ppc-softmmu/hw/vfio/calxeda-xgmac.o
  CC  ppc-softmmu/hw/vfio/amd-xgbe.o
  CC  ppc-softmmu/hw/virtio/virtio.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  aarch64-softmmu/target/arm/translate-a64.o
  CC  mipsel-softmmu/hw/virtio/vhost-user-scsi-pci.o
  CC  mipsel-softmmu/hw/virtio/vhost-scsi-pci.o
---
  CC  s390x-softmmu/gdbstub.o
  CC  sh4-softmmu/accel/tcg/tcg-runtime-gvec.o
  CC  sh4eb-softmmu/accel/tcg/tc

Re: [PATCH 2/2] via-ide: Also emulate non 100% native mode

2020-03-06 Thread Mark Cave-Ayland
On 06/03/2020 12:06, BALATON Zoltan wrote:

> On Fri, 6 Mar 2020, Mark Cave-Ayland wrote:
>> On 05/03/2020 23:35, BALATON Zoltan wrote:
>>> On real hardware this may be true but in QEMU how would it otherwise raise 
>>> the
>>> correct interrupt line the guest expects? This probably does not matter for 
>>> pegasos2
>>> but I think is needed for 100% native mode used with the fulong2e so it 
>>> gets the IRQ
>>> it expects.
>>
>> That's easy - remember that both the PCI and IRQ interrupts are separate 
>> pins on the
>> chip, so all that needs to be done is expose the legacy IRQ via qdev and use 
>> that to
>> wire it up to your interrupt controller.
> 
> This "chip" is part of an integrated southbridge/superio/everything chip the 
> also
> includes the two PICs and how they are internally connected is not known so 
> we would
> be guessing here anyway. I don't see a need to make it more complicated than 
> it is
> now by modeling internal pins but how would I wire up gpio to the i8259 model 
> and
> where should I connect the PCI irq?

For now I would say not to worry about the PCI IRQ: the reason for discussing 
this
before was because we believed that if the controller was in native mode it 
must be
using the IRQ in PCI_INTERRUPT_LINE. But from yesterday's read of the 
specification
we know that PCI_INTERRUPT_LINE is never used by the device itself, and so 
given that
the existing via-ide device doesn't currently attempt to use the PCI IRQ in
via_ide_set_irq() then we should be good.

If someone had a machine somewhere that did use the PCI IRQ then it would need
investigation, but since there isn't then I don't see any need to do this now.

>> Okay so this is interesting: I've been switching between the VT8231 and the 
>> VT82C686B
>> datasheets, and there is a difference here. You are correct in what you say 
>> above in
>> that the 8231 docs specify that this is set to 1, but on the 686B this is 
>> clearly not
>> the case.
> 
> The 82C686B says this reg can be 0 or 1, where 0 is legacy interrupt routing 
> and 1 is
> native mode. Given that we only model native mode of the chip it does not 
> make sense
> to set it to anything else than 1 and setting it to 0 confuses MorphOS and 
> Linux on
> pegasos2 while setting it to 1 works with everything I've tried both on 
> pegasos2 and
> fulong2e even if that may not completely match how it's implemented in 
> hardware.
> 
>> What is rather unusual here is that both the 8231 and 686B have exactly the 
>> same
>> device and vendor ids, so I'm not sure how you'd distinguish between them?
> 
> Guests distinguish by looking at the parent device (function 0) which is the 
> chip
> this IDE device is part of (on function 1).

Okay thanks, that's useful to know.

I've done a quick grep of the source tree and AFAICT the only IDE controller 
that
tries to use the PCI_INTERRUPT_LINE register is via-ide, which means this 
should be
fairly easy. In short:

1) Add qemu_irq legacy_irqs[2] into PCIIDEState

(You could argue that it should belong in a separate VIAIDEState, however quite 
a few
of the BMDMA controllers in QEMU don't have their own device state and just use
PCIIDEState. And whilst via-ide is the only one that currently needs support for
legacy IRQs, I think it's good to put it there in case other controllers need 
it in
future)

2) Add via_ide_initfn() to hw/ide/via.c and add qdev_init_gpio_out_named() with 
a
name of "legacy-irq" to it

3) Inline via_ide_init() into hw/mips/mips_fulong2e.c, changing 
pci_create_simple()
to pci_create() because the device shouldn't be realised immediately

4) In vt82c686b_southbridge_init use qdev_connect_gpio_out_named() to connect
legacy_irq[0] to 8259 IRQ 14 and legacy_irq[1] to 8259 IRQ 15, and then realise 
the
device

5) Remove the PCI_INTERRUPT_LINE logic from via_ide_set_irq() and instead just 
do
qemu_set_irq() on legacy_irq[0] (in theory I guess it should be legacy_irq[n] 
but it
seems that both drives on MIPS and Pegasos both use IRQ 14).


ATB,

Mark.



[PATCH v6 4/4] linux-user/riscv: Update the syscall_nr's to the 5.5 kernel

2020-03-06 Thread Alistair Francis
Signed-off-by: Alistair Francis 
Reviewed-by: Laurent Vivier 
---
 linux-user/riscv/syscall32_nr.h | 295 +++
 linux-user/riscv/syscall64_nr.h | 301 
 linux-user/riscv/syscall_nr.h   | 294 +--
 3 files changed, 598 insertions(+), 292 deletions(-)
 create mode 100644 linux-user/riscv/syscall32_nr.h
 create mode 100644 linux-user/riscv/syscall64_nr.h

diff --git a/linux-user/riscv/syscall32_nr.h b/linux-user/riscv/syscall32_nr.h
new file mode 100644
index 00..4fef73e954
--- /dev/null
+++ b/linux-user/riscv/syscall32_nr.h
@@ -0,0 +1,295 @@
+/*
+ * This file contains the system call numbers.
+ */
+#ifndef LINUX_USER_RISCV_SYSCALL32_NR_H
+#define LINUX_USER_RISCV_SYSCALL32_NR_H
+
+#define TARGET_NR_io_setup 0
+#define TARGET_NR_io_destroy 1
+#define TARGET_NR_io_submit 2
+#define TARGET_NR_io_cancel 3
+#define TARGET_NR_setxattr 5
+#define TARGET_NR_lsetxattr 6
+#define TARGET_NR_fsetxattr 7
+#define TARGET_NR_getxattr 8
+#define TARGET_NR_lgetxattr 9
+#define TARGET_NR_fgetxattr 10
+#define TARGET_NR_listxattr 11
+#define TARGET_NR_llistxattr 12
+#define TARGET_NR_flistxattr 13
+#define TARGET_NR_removexattr 14
+#define TARGET_NR_lremovexattr 15
+#define TARGET_NR_fremovexattr 16
+#define TARGET_NR_getcwd 17
+#define TARGET_NR_lookup_dcookie 18
+#define TARGET_NR_eventfd2 19
+#define TARGET_NR_epoll_create1 20
+#define TARGET_NR_epoll_ctl 21
+#define TARGET_NR_epoll_pwait 22
+#define TARGET_NR_dup 23
+#define TARGET_NR_dup3 24
+#define TARGET_NR_fcntl64 25
+#define TARGET_NR_inotify_init1 26
+#define TARGET_NR_inotify_add_watch 27
+#define TARGET_NR_inotify_rm_watch 28
+#define TARGET_NR_ioctl 29
+#define TARGET_NR_ioprio_set 30
+#define TARGET_NR_ioprio_get 31
+#define TARGET_NR_flock 32
+#define TARGET_NR_mknodat 33
+#define TARGET_NR_mkdirat 34
+#define TARGET_NR_unlinkat 35
+#define TARGET_NR_symlinkat 36
+#define TARGET_NR_linkat 37
+#define TARGET_NR_umount2 39
+#define TARGET_NR_mount 40
+#define TARGET_NR_pivot_root 41
+#define TARGET_NR_nfsservctl 42
+#define TARGET_NR_statfs64 43
+#define TARGET_NR_fstatfs64 44
+#define TARGET_NR_truncate64 45
+#define TARGET_NR_ftruncate64 46
+#define TARGET_NR_fallocate 47
+#define TARGET_NR_faccessat 48
+#define TARGET_NR_chdir 49
+#define TARGET_NR_fchdir 50
+#define TARGET_NR_chroot 51
+#define TARGET_NR_fchmod 52
+#define TARGET_NR_fchmodat 53
+#define TARGET_NR_fchownat 54
+#define TARGET_NR_fchown 55
+#define TARGET_NR_openat 56
+#define TARGET_NR_close 57
+#define TARGET_NR_vhangup 58
+#define TARGET_NR_pipe2 59
+#define TARGET_NR_quotactl 60
+#define TARGET_NR_getdents64 61
+#define TARGET_NR_llseek 62
+#define TARGET_NR_read 63
+#define TARGET_NR_write 64
+#define TARGET_NR_readv 65
+#define TARGET_NR_writev 66
+#define TARGET_NR_pread64 67
+#define TARGET_NR_pwrite64 68
+#define TARGET_NR_preadv 69
+#define TARGET_NR_pwritev 70
+#define TARGET_NR_sendfile64 71
+#define TARGET_NR_signalfd4 74
+#define TARGET_NR_vmsplice 75
+#define TARGET_NR_splice 76
+#define TARGET_NR_tee 77
+#define TARGET_NR_readlinkat 78
+#define TARGET_NR_fstatat64 79
+#define TARGET_NR_fstat64 80
+#define TARGET_NR_sync 81
+#define TARGET_NR_fsync 82
+#define TARGET_NR_fdatasync 83
+#define TARGET_NR_sync_file_range 84
+#define TARGET_NR_timerfd_create 85
+#define TARGET_NR_acct 89
+#define TARGET_NR_capget 90
+#define TARGET_NR_capset 91
+#define TARGET_NR_personality 92
+#define TARGET_NR_exit 93
+#define TARGET_NR_exit_group 94
+#define TARGET_NR_waitid 95
+#define TARGET_NR_set_tid_address 96
+#define TARGET_NR_unshare 97
+#define TARGET_NR_set_robust_list 99
+#define TARGET_NR_get_robust_list 100
+#define TARGET_NR_getitimer 102
+#define TARGET_NR_setitimer 103
+#define TARGET_NR_kexec_load 104
+#define TARGET_NR_init_module 105
+#define TARGET_NR_delete_module 106
+#define TARGET_NR_timer_create 107
+#define TARGET_NR_timer_getoverrun 109
+#define TARGET_NR_timer_delete 111
+#define TARGET_NR_syslog 116
+#define TARGET_NR_ptrace 117
+#define TARGET_NR_sched_setparam 118
+#define TARGET_NR_sched_setscheduler 119
+#define TARGET_NR_sched_getscheduler 120
+#define TARGET_NR_sched_getparam 121
+#define TARGET_NR_sched_setaffinity 122
+#define TARGET_NR_sched_getaffinity 123
+#define TARGET_NR_sched_yield 124
+#define TARGET_NR_sched_get_priority_max 125
+#define TARGET_NR_sched_get_priority_min 126
+#define TARGET_NR_restart_syscall 128
+#define TARGET_NR_kill 129
+#define TARGET_NR_tkill 130
+#define TARGET_NR_tgkill 131
+#define TARGET_NR_sigaltstack 132
+#define TARGET_NR_rt_sigsuspend 133
+#define TARGET_NR_rt_sigaction 134
+#define TARGET_NR_rt_sigprocmask 135
+#define TARGET_NR_rt_sigpending 136
+#define TARGET_NR_rt_sigqueueinfo 138
+#define TARGET_NR_rt_sigreturn 139
+#define TARGET_NR_setpriority 140
+#define TARGET_NR_getpriority 141
+#define TARGET_NR_reboot 142
+#define TARGET_NR_setregid 143
+#define TARGET_NR_setgid 144
+#define TARGET_NR_setreuid 145
+#define TARGET_NR_set

Re: [PATCH v7 06/10] iotests: limit line length to 79 chars

2020-03-06 Thread John Snow



On 3/6/20 5:14 AM, Kevin Wolf wrote:
> Am 05.03.2020 um 19:25 hat John Snow geschrieben:
>> On 3/5/20 6:55 AM, Kevin Wolf wrote:
>>> Am 05.03.2020 um 00:14 hat John Snow geschrieben:


 On 3/4/20 4:58 PM, Philippe Mathieu-Daudé wrote:
>>>
>>> Adding back the context:
>>>
 -sys.stderr.write('qemu-img received signal %i: %s\n' % 
 (-exitcode, ' '.join(qemu_img_args + list(args
 +sys.stderr.write('qemu-img received signal %i: %s\n' % (
 +-exitcode, ' '.join(qemu_img_args + list(args
>>>
> Do we want to indent Python like C and align argument below opening
> parenthesis? Except when using sys.stderr.write() you seem to do it.

 This isn't an argument to write, it's an argument to the format string,
 so I will say "no."
>>>
>>> The argument to write() is an expression. This expression contains the %
>>> operator with both of its operands. It's still fully within the
>>> parentheses of write(), so I think Philippe's question is valid.
>>>
 For *where* I've placed the line break, this is the correct indentation.
 emacs's python mode will settle on this indent, too.

 https://python.org/dev/peps/pep-0008/#indentation
>>>
>>> The PEP-8 examples are not nested, so it's not completely clear. I
>>> wonder if hanging indents wouldn't actually mean the following because
>>> if you line wrap an argument list (which contains the whole %
>>> expression), you're supposed to have nothing else on the line of the
>>> opening parenthesis:
>>>
>>> sys.stderr.write(
>>> 'qemu-img received signal %i: %s\n'
>>> % (-exitcode, ' '.join(qemu_img_args + list(args
>>>
>>
>> This is fine too.
>>
>>> But anyway, I think the question is more whether we want to use hanging
>>> indents at all (or at least if we want to use it even in cases where the
>>> opening parenthesis isn't already at like 70 characters) when we're
>>> avoiding it in our C coding style.
>>>
>>> There's no technical answer to this, it's a question of our preferences.
>>>
>>
>> Maybe it is ambiguous. Long lines are just ugly everywhere.
>>
 (If anyone quotes Guido's belittling comment in this email, I will
 become cross.)


 But there are other places to put the line break. This is also
 technically valid:

 sys.stderr.write('qemu-img received signal %i: %s\n'
  % (-exitcode, ' '.join(qemu_img_args + list(args

 And so is this:

 sys.stderr.write('qemu-img received signal %i: %s\n' %
  (-exitcode, ' '.join(qemu_img_args + list(args
>>>
>>> PEP-8 suggests the former, but allows both styles:
>>>
>>> https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
>>>
>>
>> So in summary:
>>
>> - Avoid nested hanging indents from format operators
>> - Use a line break before the % format operator.
>> - OPTIONALLY(?), use a hanging indent for the entire format string to
>> reduce nesting depth.
> 
> Yes, though I don't think of it as a special case for format strings. So
> I would phrase it like this:
> 
> - Don't use hanging indent for any nested parentheses unless the outer
>   parentheses use hanging indents, too.
> - Use a line break before binary operators.
> - OPTIONALLY, use a hanging indent for the top level(s) to reduce
>   nesting depth.
> 
> The first one is the only rule that involves some interpretation of
> PEP-8, the rest seems to be its unambiguous recommendation.
> 
> Anyway, so I would apply the exact same rules to the following (imagine
> even longer expressions, especially the last example doesn't make sense
> with the short numbers):
> 
> * bad:
> really_long_function_name(-1234567890 + 987654321 * (
> 1337 / 42))
> 
> * ok:
> really_long_function_name(-1234567890 + 987654321
>   * (1337 / 42))
> 
> * ok:
> really_long_function_name(
> -1234567890 + 987654321
> * (1337 / 42))
> 
> * ok:
> really_long_function_name(
> -1234567890 + 987654321 * (
> 1337 / 42))
> 
>> e.g., either this form:
>> (using a line break before the binary operator and nesting to the
>> argument level)
>>
>> write('hello %s'
>>   % (world,))
>>
>>
>> or optionally this form if it buys you a little more room:
>> (using a hanging indent of 4 spaces and nesting arguments at that level)
>>
>> write(
>> 'hello %s'
>> % ('world',))
>>
>>
>> but not ever this form:
>> (Using a hanging indent of 4 spaces from the opening paren of the format
>> operand)
>>
>> write('hello %s' % (
>> 'world',))
>>
>>
>>
>> yea/nea?
>>
>> (Kevin, Philippe, Markus, Max)
> 
> Looks good to me.
> 
> Kevin
> 

Great, thanks!

I am sorry for having been so tetchy. I appreciate the reviews.

--js




[PATCH v6 3/4] linux-user: Support futex_time64

2020-03-06 Thread Alistair Francis
Add support for host and target futex_time64. If futex_time64 exists on
the host we try that first before falling back to the standard futux
syscall.

Signed-off-by: Alistair Francis 
---
 linux-user/syscall.c | 98 
 1 file changed, 80 insertions(+), 18 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 0f219b26c1..8a50e2d3dc 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -245,7 +245,12 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 
arg4,type5 arg5,  \
 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
 #define __NR_sys_rt_tgsigqueueinfo __NR_rt_tgsigqueueinfo
 #define __NR_sys_syslog __NR_syslog
-#define __NR_sys_futex __NR_futex
+#if defined(__NR_futex)
+# define __NR_sys_futex __NR_futex
+#endif
+#if defined(__NR_futex_time64)
+# define __NR_sys_futex_time64 __NR_futex_time64
+#endif
 #define __NR_sys_inotify_init __NR_inotify_init
 #define __NR_sys_inotify_add_watch __NR_inotify_add_watch
 #define __NR_sys_inotify_rm_watch __NR_inotify_rm_watch
@@ -295,10 +300,15 @@ _syscall1(int,exit_group,int,error_code)
 #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
 _syscall1(int,set_tid_address,int *,tidptr)
 #endif
-#if defined(TARGET_NR_futex) && defined(__NR_futex)
+#if (defined(TARGET_NR_futex) || defined(TARGET_NR_futex_time64)) && \
+defined(__NR_futex)
 _syscall6(int,sys_futex,int *,uaddr,int,op,int,val,
   const struct timespec *,timeout,int *,uaddr2,int,val3)
 #endif
+#if defined(TARGET_NR_futex_time64) && defined(__NR_futex_time64)
+_syscall6(int,sys_futex_time64,int *,uaddr,int,op,int,val,
+  const struct timespec *,timeout,int *,uaddr2,int,val3)
+#endif
 #define __NR_sys_sched_getaffinity __NR_sched_getaffinity
 _syscall3(int, sys_sched_getaffinity, pid_t, pid, unsigned int, len,
   unsigned long *, user_mask_ptr);
@@ -762,10 +772,14 @@ safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned 
int, nfds,
 safe_syscall6(int, epoll_pwait, int, epfd, struct epoll_event *, events,
   int, maxevents, int, timeout, const sigset_t *, sigmask,
   size_t, sigsetsize)
-#ifdef TARGET_NR_futex
+#if defined(__NR_futex)
 safe_syscall6(int,futex,int *,uaddr,int,op,int,val, \
   const struct timespec *,timeout,int *,uaddr2,int,val3)
 #endif
+#if defined(__NR_futex_time64)
+safe_syscall6(int,futex_time64,int *,uaddr,int,op,int,val, \
+  const struct timespec *,timeout,int *,uaddr2,int,val3)
+#endif
 safe_syscall2(int, rt_sigsuspend, sigset_t *, newset, size_t, sigsetsize)
 safe_syscall2(int, kill, pid_t, pid, int, sig)
 safe_syscall2(int, tkill, int, tid, int, sig)
@@ -1210,7 +1224,7 @@ static inline abi_long copy_to_user_timeval64(abi_ulong 
target_tv_addr,
 return 0;
 }
 
-#if defined(TARGET_NR_futex) || \
+#if defined(TARGET_NR_futex) || defined(TARGET_NR_futex_time64) || \
 defined(TARGET_NR_rt_sigtimedwait) || \
 defined(TARGET_NR_pselect6) || defined(TARGET_NR_pselect6) || \
 defined(TARGET_NR_nanosleep) || defined(TARGET_NR_clock_settime) || \
@@ -6898,12 +6912,12 @@ static inline abi_long host_to_target_statx(struct 
target_statx *host_stx,
futexes locally would make futexes shared between multiple processes
tricky.  However they're probably useless because guest atomic
operations won't work either.  */
-#if defined(TARGET_NR_futex)
+#if defined(TARGET_NR_futex) || defined(TARGET_NR_futex_time64)
 static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout,
 target_ulong uaddr2, int val3)
 {
 struct timespec ts, *pts;
-int base_op;
+int base_op, err = -ENOSYS;
 
 /* ??? We assume FUTEX_* constants are the same on both host
and target.  */
@@ -6915,18 +6929,49 @@ static int do_futex(target_ulong uaddr, int op, int 
val, target_ulong timeout,
 switch (base_op) {
 case FUTEX_WAIT:
 case FUTEX_WAIT_BITSET:
+#ifdef __NR_futex_time64
+struct __kernel_timespec ts64, *pts64;
+
 if (timeout) {
-pts = &ts;
-target_to_host_timespec(pts, timeout);
+pts64 = &ts64;
+target_to_host_timespec64(pts64, timeout);
 } else {
-pts = NULL;
+pts64 = NULL;
+}
+
+err = get_errno(safe_futex_time64(g2h(uaddr), op, tswap32(val),
+ pts64, NULL, val3));
+#endif
+#ifdef __NR_futex
+if (err == -ENOSYS) {
+if (timeout) {
+pts = &ts;
+target_to_host_timespec(pts, timeout);
+} else {
+pts = NULL;
+}
+return get_errno(safe_futex(g2h(uaddr), op, tswap32(val),
+ pts, NULL, val3));
 }
-return get_errno(safe_futex(g2h(uaddr), op, tswap32(val),
- pts, NULL, val3));
+#endif
 case FUTEX_WAKE:
-return get_errno(safe_futex(g2h(uaddr), op,

[PATCH v6 1/4] linux-user: Protect more syscalls

2020-03-06 Thread Alistair Francis
New y2038 safe 32-bit architectures (like RISC-V) don't support old
syscalls with a 32-bit time_t. The kernel defines new *_time64 versions
of these syscalls. Add some more #ifdefs to syscall.c in linux-user to
allow us to compile without these old syscalls.

Signed-off-by: Alistair Francis 
---
 linux-user/strace.c  |  2 ++
 linux-user/syscall.c | 68 +++-
 2 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 4f7130b2ff..6420ccd97b 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -775,6 +775,7 @@ print_syscall_ret_newselect(const struct syscallname *name, 
abi_long ret)
 #define TARGET_TIME_OOP  3   /* leap second in progress */
 #define TARGET_TIME_WAIT 4   /* leap second has occurred */
 #define TARGET_TIME_ERROR5   /* clock not synchronized */
+#ifdef TARGET_NR_adjtimex
 static void
 print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret)
 {
@@ -813,6 +814,7 @@ print_syscall_ret_adjtimex(const struct syscallname *name, 
abi_long ret)
 
 qemu_log("\n");
 }
+#endif
 
 UNUSED static struct flags access_flags[] = {
 FLAG_GENERIC(F_OK),
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8d27d10807..1a7df23440 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -742,21 +742,30 @@ safe_syscall3(ssize_t, read, int, fd, void *, buff, 
size_t, count)
 safe_syscall3(ssize_t, write, int, fd, const void *, buff, size_t, count)
 safe_syscall4(int, openat, int, dirfd, const char *, pathname, \
   int, flags, mode_t, mode)
+#if defined(TARGET_NR_wait4) || defined(TARGET_NR_waitpid)
 safe_syscall4(pid_t, wait4, pid_t, pid, int *, status, int, options, \
   struct rusage *, rusage)
+#endif
 safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, siginfo_t *, infop, \
   int, options, struct rusage *, rusage)
 safe_syscall3(int, execve, const char *, filename, char **, argv, char **, 
envp)
+#if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) || \
+defined(TARGET_NR_pselect6)
 safe_syscall6(int, pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, 
\
   fd_set *, exceptfds, struct timespec *, timeout, void *, sig)
+#endif
+#if defined(TARGET_NR_ppoll) || defined(TARGET_NR_poll)
 safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds,
   struct timespec *, tsp, const sigset_t *, sigmask,
   size_t, sigsetsize)
+#endif
 safe_syscall6(int, epoll_pwait, int, epfd, struct epoll_event *, events,
   int, maxevents, int, timeout, const sigset_t *, sigmask,
   size_t, sigsetsize)
+#ifdef TARGET_NR_futex
 safe_syscall6(int,futex,int *,uaddr,int,op,int,val, \
   const struct timespec *,timeout,int *,uaddr2,int,val3)
+#endif
 safe_syscall2(int, rt_sigsuspend, sigset_t *, newset, size_t, sigsetsize)
 safe_syscall2(int, kill, pid_t, pid, int, sig)
 safe_syscall2(int, tkill, int, tid, int, sig)
@@ -776,12 +785,16 @@ safe_syscall6(ssize_t, recvfrom, int, fd, void *, buf, 
size_t, len,
 safe_syscall3(ssize_t, sendmsg, int, fd, const struct msghdr *, msg, int, 
flags)
 safe_syscall3(ssize_t, recvmsg, int, fd, struct msghdr *, msg, int, flags)
 safe_syscall2(int, flock, int, fd, int, operation)
+#ifdef TARGET_NR_rt_sigtimedwait
 safe_syscall4(int, rt_sigtimedwait, const sigset_t *, these, siginfo_t *, 
uinfo,
   const struct timespec *, uts, size_t, sigsetsize)
+#endif
 safe_syscall4(int, accept4, int, fd, struct sockaddr *, addr, socklen_t *, len,
   int, flags)
+#if defined(TARGET_NR_nanosleep)
 safe_syscall2(int, nanosleep, const struct timespec *, req,
   struct timespec *, rem)
+#endif
 #ifdef TARGET_NR_clock_nanosleep
 safe_syscall4(int, clock_nanosleep, const clockid_t, clock, int, flags,
   const struct timespec *, req, struct timespec *, rem)
@@ -803,10 +816,14 @@ safe_syscall4(int, semtimedop, int, semid, struct sembuf 
*, tsops,
   unsigned, nsops, const struct timespec *, timeout)
 #endif
 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
+# ifdef TARGET_NR_mq_timedsend
 safe_syscall5(int, mq_timedsend, int, mqdes, const char *, msg_ptr,
   size_t, len, unsigned, prio, const struct timespec *, timeout)
+# endif
+# ifdef TARGET_NR_mq_timedreceive
 safe_syscall5(int, mq_timedreceive, int, mqdes, char *, msg_ptr,
   size_t, len, unsigned *, prio, const struct timespec *, timeout)
+# endif
 #endif
 /* We do ioctl like this rather than via safe_syscall3 to preserve the
  * "third argument might be integer or pointer or not present" behaviour of
@@ -946,6 +963,8 @@ abi_long do_brk(abi_ulong new_brk)
 return target_brk;
 }
 
+#if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) || \
+defined(TARGET_NR_pselect6)
 static inline abi_long copy_from_user_fdset(fd_set *fds,
 abi_ulong

[PATCH v6 2/4] linux-user/syscall: Add support for clock_gettime64/clock_settime64

2020-03-06 Thread Alistair Francis
Add support for the clock_gettime64/clock_settime64 syscalls.

If your host is 64-bit or is 32-bit with the *_time64 syscall then the
timespec will correctly be a 64-bit time_t. Otherwise the host will
return a 32-bit time_t which will be rounded to 64-bits. This will be
incorrect after y2038.

Signed-off-by: Alistair Francis 
Reviewed-by: Laurent Vivier 
---
 linux-user/syscall.c | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 1a7df23440..0f219b26c1 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1231,6 +1231,22 @@ static inline abi_long target_to_host_timespec(struct 
timespec *host_ts,
 }
 #endif
 
+#if defined(TARGET_NR_clock_settime64)
+static inline abi_long target_to_host_timespec64(struct timespec *host_ts,
+ abi_ulong target_addr)
+{
+struct target__kernel_timespec *target_ts;
+
+if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1)) {
+return -TARGET_EFAULT;
+}
+__get_user(host_ts->tv_sec, &target_ts->tv_sec);
+__get_user(host_ts->tv_nsec, &target_ts->tv_nsec);
+unlock_user_struct(target_ts, target_addr, 0);
+return 0;
+}
+#endif
+
 static inline abi_long host_to_target_timespec(abi_ulong target_addr,
struct timespec *host_ts)
 {
@@ -11460,6 +11476,18 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 return ret;
 }
 #endif
+#ifdef TARGET_NR_clock_settime64
+case TARGET_NR_clock_settime64:
+{
+struct timespec ts;
+
+ret = target_to_host_timespec64(&ts, arg2);
+if (!is_error(ret)) {
+ret = get_errno(clock_settime(arg1, &ts));
+}
+return ret;
+}
+#endif
 #ifdef TARGET_NR_clock_gettime
 case TARGET_NR_clock_gettime:
 {
@@ -11471,6 +11499,17 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 return ret;
 }
 #endif
+#ifdef TARGET_NR_clock_gettime64
+case TARGET_NR_clock_gettime64:
+{
+struct timespec ts;
+ret = get_errno(clock_gettime(arg1, &ts));
+if (!is_error(ret)) {
+ret = host_to_target_timespec64(arg2, &ts);
+}
+return ret;
+}
+#endif
 #ifdef TARGET_NR_clock_getres
 case TARGET_NR_clock_getres:
 {
-- 
2.25.1




[PATCH v6 0/4] linux-user: generate syscall_nr.sh for RISC-V

2020-03-06 Thread Alistair Francis
This series updates the RISC-V syscall_nr.sh based on the 5.5 kernel.

There are two parts to this. One is just adding the new syscalls, the
other part is updating the RV32 syscalls to match the fact that RV32 is
a 64-bit time_t architectures (y2038) safe.

We need to make some changes to syscall.c to avoid warnings/errors
during compliling with the new syscall.

I did some RV32 user space testing after applying these patches. I ran the
glibc testsuite in userspace and I don't see any regressions.

v6:
 - Split out futex patch and make it more robust
v5:
 - Addres comments raised on v4
   - Don't require 64-bit host for * _time64 functions

Alistair Francis (4):
  linux-user: Protect more syscalls
  linux-user/syscall: Add support for clock_gettime64/clock_settime64
  linux-user: Support futex_time64
  linux-user/riscv: Update the syscall_nr's to the 5.5 kernel

 linux-user/riscv/syscall32_nr.h | 295 +++
 linux-user/riscv/syscall64_nr.h | 301 
 linux-user/riscv/syscall_nr.h   | 294 +--
 linux-user/strace.c |   2 +
 linux-user/syscall.c| 199 +++--
 5 files changed, 783 insertions(+), 308 deletions(-)
 create mode 100644 linux-user/riscv/syscall32_nr.h
 create mode 100644 linux-user/riscv/syscall64_nr.h

-- 
2.25.1




Re: [PATCH 1/1] target/riscv: Fix VS mode interrupts forwarding.

2020-03-06 Thread Palmer Dabbelt

On Wed, 26 Feb 2020 09:55:34 PST (-0800), alistai...@gmail.com wrote:

On Wed, Feb 26, 2020 at 12:54 AM Rajnesh Kanwal
 wrote:


Here is the link to the patch
https://lists.nongnu.org/archive/html/qemu-riscv/2020-01/msg00191.html


Ah, it doesn't look like it made it to the QEMU-devel list. Can you
re-send it to QEMU-devel?


I can't find the older patch in my inbox, so I'm just taking this one.



Alistair



-Rajnesh

On Tue, Feb 25, 2020 at 12:06 AM Alistair Francis  wrote:


On Sun, Feb 23, 2020 at 11:23 AM Jose Martins  wrote:
>
> Hello rajnesh,
>
> I had already submitted almost this exact patch a few weeks ago.

To QEMU? I don't see the patch.

Alistair

>
> Jose
>
> On Sun, 23 Feb 2020 at 13:51,  wrote:
> >
> > From: Rajnesh Kanwal 
> >
> > Currently riscv_cpu_local_irq_pending is used to find out pending
> > interrupt and VS mode interrupts are being shifted to represent
> > S mode interrupts in this function. So when the cause returned by
> > this function is passed to riscv_cpu_do_interrupt to actually
> > forward the interrupt, the VS mode forwarding check does not work
> > as intended and interrupt is actually forwarded to hypervisor. This
> > patch fixes this issue.
> >
> > Signed-off-by: Rajnesh Kanwal 
> > ---
> >  target/riscv/cpu_helper.c | 9 -
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
> > index b9e90dfd9a..59535ecba6 100644
> > --- a/target/riscv/cpu_helper.c
> > +++ b/target/riscv/cpu_helper.c
> > @@ -46,7 +46,7 @@ static int riscv_cpu_local_irq_pending(CPURISCVState *env)
> >  target_ulong pending = env->mip & env->mie &
> > ~(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP);
> >  target_ulong vspending = (env->mip & env->mie &
> > -  (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP)) >> 1;
> > +  (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP));
> >
> >  target_ulong mie= env->priv < PRV_M ||
> >(env->priv == PRV_M && mstatus_mie);
> > @@ -900,6 +900,13 @@ void riscv_cpu_do_interrupt(CPUState *cs)
> >
> >  if (riscv_cpu_virt_enabled(env) && ((hdeleg >> cause) & 1) &&
> >  !force_hs_execp) {
> > +/*
> > + * See if we need to adjust cause. Yes if its VS mode 
interrupt
> > + * no if hypervisor has delegated one of hs mode's 
interrupt
> > + */
> > +if (cause == IRQ_VS_TIMER || cause == IRQ_VS_SOFT ||
> > +cause == IRQ_VS_EXT)
> > +cause = cause - 1;
> >  /* Trap to VS mode */
> >  } else if (riscv_cpu_virt_enabled(env)) {
> >  /* Trap into HS mode, from virt */
> > --
> > 2.17.1
> >
> >
>




[PATCH 5/7] Makefile: Make all Sphinx documentation depend on the extensions

2020-03-06 Thread Peter Maydell
Add the Python source files of our Sphinx extensions to the
dependencies of the Sphinx manuals, so that if we edit the
extension source code the manuals get rebuilt.

Adding this dependency unconditionally means that we'll rebuild
a manual even if it happens to not use the extension whose
source file was changed, but this is simpler and less error
prone, and it's unlikely that we'll be making frequent changes
to the extensions.

Signed-off-by: Peter Maydell 
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 2ccd80065b6..5847f8d41d9 100644
--- a/Makefile
+++ b/Makefile
@@ -1046,7 +1046,8 @@ build-manual = $(call 
quiet-command,CONFDIR="$(qemu_confdir)" $(SPHINX_BUILD) $(
 # We assume all RST files in the manual's directory are used in it
 manual-deps = $(wildcard $(SRC_PATH)/docs/$1/*.rst) \
   $(SRC_PATH)/docs/defs.rst.inc \
-  $(SRC_PATH)/docs/$1/conf.py $(SRC_PATH)/docs/conf.py
+  $(SRC_PATH)/docs/$1/conf.py $(SRC_PATH)/docs/conf.py \
+  $(SRC_PATH)/docs/sphinx/*.py
 # Macro to write out the rule and dependencies for building manpages
 # Usage: $(call define-manpage-rule,manualname,manpage1 
manpage2...[,extradeps])
 # 'extradeps' is optional, and specifies extra files (eg .hx files) that
-- 
2.20.1




Re: [PATCH v3 00/12] Convert QAPI doc comments to generate rST instead of texinfo

2020-03-06 Thread Peter Maydell
On Tue, 25 Feb 2020 at 14:04, Peter Maydell  wrote:
>
> This series switches all our QAPI doc comments over from
> texinfo format to rST.

> Git branch of this series also available at
> https://git.linaro.org/people/peter.maydell/qemu-arm.git sphinx-conversions

I've just updated this git branch with a rebase on top of:
 * current master, which has the qemu-doc conversion
 * the minor-cleanups patchset I just posted

No serious changes to the meat of the series:
 * some new text in migration.json needed indenting to
   match this series' stricter requirements
 * fixups of (textual) makefile conflicts
 * five new patches at the end which delete all the
   texinfo machinery since once the qapi generation
   is converted we don't need texinfo at all

I'll probably send a new set of patches to the list next
week; this set should still be fine for review though.

thanks
-- PMM



[PATCH 6/7] docs/index.rst, docs/index.html.in: Reorder manuals

2020-03-06 Thread Peter Maydell
Now that qemu-doc.html is no longer present, the ordering of manuals
within the top-level index page looks a bit odd. Reshuffle so that
the manuals the user is most likely to be interested in are at the
top of the list, and the reference material is at the bottom.

Similarly, we reorder the index.rst file used as the base of
the "all manuals in one" documentation for readthedocs.

The new order is:
 * system
 * user
 * tools
 * interop
 * specs
 * QMP reference (if present)
 * Guest agent protocol reference (if present)
 * devel (if present)

Signed-off-by: Peter Maydell 
---
 docs/index.html.in | 10 +-
 docs/index.rst |  8 
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/docs/index.html.in b/docs/index.html.in
index cc19aad2ec5..e9a160384cf 100644
--- a/docs/index.html.in
+++ b/docs/index.html.in
@@ -7,13 +7,13 @@
 
 QEMU @@VERSION@@ Documentation
 
-QMP Reference Manual
-Guest Agent Protocol 
Reference
+System Emulation User's 
Guide
+User Mode Emulation User's 
Guide
+Tools Guide
 System Emulation Management and 
Interoperability Guide
 System Emulation Guest Hardware 
Specifications
-System Emulation User's 
Guide
-Tools Guide
-User Mode Emulation User's 
Guide
+QMP Reference Manual
+Guest Agent Protocol 
Reference
 
 
 
diff --git a/docs/index.rst b/docs/index.rst
index 376dab28850..763e3d0426e 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -10,9 +10,9 @@ Welcome to QEMU's documentation!
:maxdepth: 2
:caption: Contents:
 
-   interop/index
-   devel/index
-   specs/index
system/index
-   tools/index
user/index
+   tools/index
+   interop/index
+   specs/index
+   devel/index
-- 
2.20.1




[PATCH 4/7] docs/sphinx/hxtool.py: Remove STEXI/ETEXI support

2020-03-06 Thread Peter Maydell
Now that none of our input .hx files have STEXI/ETEXI blocks,
we can remove the code in the Sphinx hxtool extension that
supported parsing them.

Signed-off-by: Peter Maydell 
---
 docs/sphinx/hxtool.py | 28 
 1 file changed, 4 insertions(+), 24 deletions(-)

diff --git a/docs/sphinx/hxtool.py b/docs/sphinx/hxtool.py
index 7dd223fe362..fb0649a3d5b 100644
--- a/docs/sphinx/hxtool.py
+++ b/docs/sphinx/hxtool.py
@@ -37,13 +37,11 @@ else:
 
 __version__ = '1.0'
 
-# We parse hx files with a state machine which may be in one of three
-# states: reading the C code fragment, inside a texi fragment,
-# or inside a rST fragment.
+# We parse hx files with a state machine which may be in one of two
+# states: reading the C code fragment, or inside a rST fragment.
 class HxState(Enum):
 CTEXT = 1
-TEXI = 2
-RST = 3
+RST = 2
 
 def serror(file, lnum, errtext):
 """Raise an exception giving a user-friendly syntax error message"""
@@ -110,31 +108,13 @@ class HxtoolDocDirective(Directive):
 
 if directive == 'HXCOMM':
 pass
-elif directive == 'STEXI':
-if state == HxState.RST:
-serror(hxfile, lnum, 'expected ERST, found STEXI')
-elif state == HxState.TEXI:
-serror(hxfile, lnum, 'expected ETEXI, found STEXI')
-else:
-state = HxState.TEXI
-elif directive == 'ETEXI':
-if state == HxState.RST:
-serror(hxfile, lnum, 'expected ERST, found ETEXI')
-elif state == HxState.CTEXT:
-serror(hxfile, lnum, 'expected STEXI, found ETEXI')
-else:
-state = HxState.CTEXT
 elif directive == 'SRST':
 if state == HxState.RST:
 serror(hxfile, lnum, 'expected ERST, found SRST')
-elif state == HxState.TEXI:
-serror(hxfile, lnum, 'expected ETEXI, found SRST')
 else:
 state = HxState.RST
 elif directive == 'ERST':
-if state == HxState.TEXI:
-serror(hxfile, lnum, 'expected ETEXI, found ERST')
-elif state == HxState.CTEXT:
+if state == HxState.CTEXT:
 serror(hxfile, lnum, 'expected SRST, found ERST')
 else:
 state = HxState.CTEXT
-- 
2.20.1




[PATCH 7/7] docs/qemu-option-trace.rst.inc: Remove redundant comment

2020-03-06 Thread Peter Maydell
The Texinfo version of the tracing options documentation has now
been deleted, so we can remove the now-redundant comment at the top
of the rST version that was reminding us that the two should be
kept in sync.

Signed-off-by: Peter Maydell 
---
 docs/qemu-option-trace.rst.inc | 4 
 1 file changed, 4 deletions(-)

diff --git a/docs/qemu-option-trace.rst.inc b/docs/qemu-option-trace.rst.inc
index 23cfcb48537..7e09773a9c5 100644
--- a/docs/qemu-option-trace.rst.inc
+++ b/docs/qemu-option-trace.rst.inc
@@ -1,7 +1,3 @@
-..
-  The contents of this file must be kept in sync with qemu-option-trace.texi
-  until all the users of the texi file have been converted to rst and
-  the texi file can be removed.
 
 Specify tracing options.
 
-- 
2.20.1




[PATCH 0/7] post-rst-conversion cleanups

2020-03-06 Thread Peter Maydell
This series has some small cleanups now that the conversion
of qemu-doc to rST has gone into master:
 * reorder the index.html.in/index.rst as it looks a bit odd
   now that qemu-doc.html has gone from the top of the list
 * remove various bits of redundant code, makefile runes, etc
 * update some comments still talking about texi
 * add a missing dependency so that editing the Sphinx
   extension source code triggers a rebuild of the docs

thanks
-- PMM

Peter Maydell (7):
  Makefile: Remove redundant Texinfo related code
  Update comments in .hx files that mention Texinfo
  hxtool: Remove Texinfo generation support
  docs/sphinx/hxtool.py: Remove STEXI/ETEXI support
  Makefile: Make all Sphinx documentation depend on the extensions
  docs/index.rst, docs/index.html.in: Reorder manuals
  docs/qemu-option-trace.rst.inc: Remove redundant comment

 Makefile   | 14 ++
 docs/index.html.in | 10 ++---
 docs/index.rst |  8 ++--
 docs/qemu-option-trace.rst.inc |  4 --
 docs/sphinx/hxtool.py  | 28 ++--
 hmp-commands-info.hx   |  8 ++--
 hmp-commands.hx|  8 ++--
 qemu-options.hx|  8 ++--
 scripts/hxtool | 78 +-
 9 files changed, 29 insertions(+), 137 deletions(-)

-- 
2.20.1




[PATCH 2/7] Update comments in .hx files that mention Texinfo

2020-03-06 Thread Peter Maydell
Update the header comments in .hx files that mention STEXI/ETEXI
markup; this is now SRST/ERST as all these files have been
converted to rST.

Signed-off-by: Peter Maydell 
---
 hmp-commands-info.hx | 8 
 hmp-commands.hx  | 8 
 qemu-options.hx  | 8 
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 499d6d54b01..ca5198438de 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -1,9 +1,9 @@
-HXCOMM Use DEFHEADING() to define headings in both help text and texi
-HXCOMM Text between STEXI and ETEXI are copied to texi version and
-HXCOMM discarded from C version
+HXCOMM Use DEFHEADING() to define headings in both help text and rST.
+HXCOMM Text between SRST and ERST is copied to the rST version and
+HXCOMM discarded from C version.
 HXCOMM DEF(command, args, callback, arg_string, help) is used to construct
 HXCOMM monitor info commands
-HXCOMM HXCOMM can be used for comments, discarded from both texi and C
+HXCOMM HXCOMM can be used for comments, discarded from both rST and C.
 HXCOMM
 HXCOMM In this file, generally SRST fragments should have two extra
 HXCOMM spaces of indent, so that the documentation list item for "info foo"
diff --git a/hmp-commands.hx b/hmp-commands.hx
index eb3d1605fd6..d33ff367da3 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1,9 +1,9 @@
-HXCOMM Use DEFHEADING() to define headings in both help text and texi
-HXCOMM Text between STEXI and ETEXI are copied to texi version and
-HXCOMM discarded from C version
+HXCOMM Use DEFHEADING() to define headings in both help text and rST.
+HXCOMM Text between SRST and ERST is copied to the rST version and
+HXCOMM discarded from C version.
 HXCOMM DEF(command, args, callback, arg_string, help) is used to construct
 HXCOMM monitor commands
-HXCOMM HXCOMM can be used for comments, discarded from both texi and C
+HXCOMM HXCOMM can be used for comments, discarded from both rST and C.
 
 
 {
diff --git a/qemu-options.hx b/qemu-options.hx
index f9fefd43be9..1d8f852d896 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1,10 +1,10 @@
-HXCOMM Use DEFHEADING() to define headings in both help text and texi
-HXCOMM Text between STEXI and ETEXI are copied to texi version and
-HXCOMM discarded from C version
+HXCOMM Use DEFHEADING() to define headings in both help text and rST.
+HXCOMM Text between SRST and ERST is copied to the rST version and
+HXCOMM discarded from C version.
 HXCOMM DEF(option, HAS_ARG/0, opt_enum, opt_help, arch_mask) is used to
 HXCOMM construct option structures, enums and help message for specified
 HXCOMM architectures.
-HXCOMM HXCOMM can be used for comments, discarded from both texi and C
+HXCOMM HXCOMM can be used for comments, discarded from both rST and C.
 
 DEFHEADING(Standard options:)
 
-- 
2.20.1




Re: [PATCH] usb-serial: wakeup device on input

2020-03-06 Thread Jason Andryuk
On Fri, Mar 6, 2020 at 11:13 AM  wrote:
>
> Patchew URL: 
> https://patchew.org/QEMU/20200306140917.26726-1-jandr...@gmail.com/
>
>
>
> Hi,
>
> This series failed the docker-clang@ubuntu build test. Please find the 
> testing commands and
> their output below. If you have Docker installed, you can probably reproduce 
> it
> locally.
>
> === TEST SCRIPT BEGIN ===
> #!/bin/bash
> make docker-image-ubuntu V=1 NETWORK=1
> time make docker-test-clang@ubuntu SHOW_ENV=1 J=14 NETWORK=1
> === TEST SCRIPT END ===

I ran these two commands locally and they completed successfully.

>   LINKfp-test
> ---
> dbus-daemon[5453]: Could not get password database information for UID of 
> current process: User "???" unknown or no memory to allocate password entry

Was there a problem with this container's password db and/or
out-of-memory like this message states?

Regards,
Jason

> **
> ERROR:/tmp/qemu-test/src/tests/qtest/dbus-vmstate-test.c:114:get_connection: 
> assertion failed (err == NULL): The connection is closed (g-io-error-quark, 
> 18)
> ERROR - Bail out! 
> ERROR:/tmp/qemu-test/src/tests/qtest/dbus-vmstate-test.c:114:get_connection: 
> assertion failed (err == NULL): The connection is closed (g-io-error-quark, 
> 18)
> Aborted (core dumped)
> cleaning up pid 5453
> make: *** [/tmp/qemu-test/src/tests/Makefile.include:632: check-qtest-i386] 
> Error 1
> make: *** Waiting for unfinished jobs
>
> Looking for expected file 'tests/data/acpi/pc/FACP.bridge'
> ---
> dbus-daemon[6892]: Could not get password database information for UID of 
> current process: User "???" unknown or no memory to allocate password entry
>
> **
> ERROR:/tmp/qemu-test/src/tests/qtest/dbus-vmstate-test.c:114:get_connection: 
> assertion failed (err == NULL): The connection is closed (g-io-error-quark, 
> 18)
> Aborted (core dumped)
> cleaning up pid 6892
> ERROR - Bail out! 
> ERROR:/tmp/qemu-test/src/tests/qtest/dbus-vmstate-test.c:114:get_connection: 
> assertion failed (err == NULL): The connection is closed (g-io-error-quark, 
> 18)
> make: *** [/tmp/qemu-test/src/tests/Makefile.include:632: check-qtest-x86_64] 
> Error 1
>   TESTcheck-qtest-arm: tests/qtest/test-hmp
>   TESTcheck-qtest-arm: tests/qtest/qos-test
>   TESTcheck-qtest-aarch64: tests/qtest/test-hmp
> ---
> raise CalledProcessError(retcode, cmd)
> subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', 
> '--label', 'com.qemu.instance.uuid=2e42e92cfb504ed5b5cb56b2c8b512df', '-u', 
> '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', 
> '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', 
> '-e', 'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', 
> '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', 
> '/var/tmp/patchew-tester-tmp-dwbsabkq/src/docker-src.2020-03-06-10.32.46.2194:/var/tmp/qemu:z,ro',
>  'qemu:ubuntu', '/var/tmp/qemu/run', 'test-clang']' returned non-zero exit 
> status 2.
> filter=--filter=label=com.qemu.instance.uuid=2e42e92cfb504ed5b5cb56b2c8b512df
> make[1]: *** [docker-run] Error 1
> make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-dwbsabkq/src'
> make: *** [docker-run-test-clang@ubuntu] Error 2
>
> real40m29.624s
> user0m9.675s
>
>
> The full log is available at
> http://patchew.org/logs/20200306140917.26726-1-jandr...@gmail.com/testing.docker-clang@ubuntu/?type=message.
> ---
> Email generated automatically by Patchew [https://patchew.org/].
> Please send your feedback to patchew-de...@redhat.com



[PATCH 3/7] hxtool: Remove Texinfo generation support

2020-03-06 Thread Peter Maydell
All the STEXI/ETEXI blocks and the Makfile rules that use them have now
been removed from the codebase. We can remove the code from the hxtool
script which handles the STEXI/ETEXI directives and the '-t' option.

Signed-off-by: Peter Maydell 
---
 scripts/hxtool | 78 +-
 1 file changed, 1 insertion(+), 77 deletions(-)

diff --git a/scripts/hxtool b/scripts/hxtool
index 0003e7b673d..7b1452f3cf1 100644
--- a/scripts/hxtool
+++ b/scripts/hxtool
@@ -7,7 +7,7 @@ hxtoh()
 case $str in
 HXCOMM*)
 ;;
-STEXI*|ETEXI*|SRST*|ERST*) flag=$(($flag^1))
+SRST*|ERST*) flag=$(($flag^1))
 ;;
 *)
 test $flag -eq 1 && printf "%s\n" "$str"
@@ -16,84 +16,8 @@ hxtoh()
 done
 }
 
-print_texi_heading()
-{
-if test "$*" != ""; then
-title="$*"
-printf "@subsection %s\n" "${title%:}"
-fi
-}
-
-hxtotexi()
-{
-flag=0
-rstflag=0
-line=1
-while read -r str; do
-case "$str" in
-HXCOMM*)
-;;
-STEXI*)
-if test $rstflag -eq 1 ; then
-printf "line %d: syntax error: expected ERST, found '%s'\n" 
"$line" "$str" >&2
-exit 1
-fi
-if test $flag -eq 1 ; then
-printf "line %d: syntax error: expected ETEXI, found '%s'\n" 
"$line" "$str" >&2
-exit 1
-fi
-flag=1
-;;
-ETEXI*)
-if test $rstflag -eq 1 ; then
-printf "line %d: syntax error: expected ERST, found '%s'\n" 
"$line" "$str" >&2
-exit 1
-fi
-if test $flag -ne 1 ; then
-printf "line %d: syntax error: expected STEXI, found '%s'\n" 
"$line" "$str" >&2
-exit 1
-fi
-flag=0
-;;
-SRST*)
-if test $rstflag -eq 1 ; then
-printf "line %d: syntax error: expected ERST, found '%s'\n" 
"$line" "$str" >&2
-exit 1
-fi
-if test $flag -eq 1 ; then
-printf "line %d: syntax error: expected ETEXI, found '%s'\n" 
"$line" "$str" >&2
-exit 1
-fi
-rstflag=1
-;;
-ERST*)
-if test $flag -eq 1 ; then
-printf "line %d: syntax error: expected ETEXI, found '%s'\n" 
"$line" "$str" >&2
-exit 1
-fi
-if test $rstflag -ne 1 ; then
-printf "line %d: syntax error: expected SRST, found '%s'\n" 
"$line" "$str" >&2
-exit 1
-fi
-rstflag=0
-;;
-DEFHEADING*)
-print_texi_heading "$(expr "$str" : "DEFHEADING(\(.*\))")"
-;;
-ARCHHEADING*)
-print_texi_heading "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
-;;
-*)
-test $flag -eq 1 && printf '%s\n' "$str"
-;;
-esac
-line=$((line+1))
-done
-}
-
 case "$1" in
 "-h") hxtoh ;;
-"-t") hxtotexi ;;
 *) exit 1 ;;
 esac
 
-- 
2.20.1




[PULL 09/29] block: Move system emulator QMP commands to block/qapi-sysemu.c

2020-03-06 Thread Kevin Wolf
These commands make only sense for system emulators and their
implementations call functions that don't exist in tools (e.g. to
resolve qdev IDs). Move them out so that blockdev.c can be linked to
qemu-storage-daemon.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-4-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 block/qapi-sysemu.c | 590 
 blockdev.c  | 559 -
 block/Makefile.objs |   2 +
 3 files changed, 592 insertions(+), 559 deletions(-)
 create mode 100644 block/qapi-sysemu.c

diff --git a/block/qapi-sysemu.c b/block/qapi-sysemu.c
new file mode 100644
index 00..8498402ad4
--- /dev/null
+++ b/block/qapi-sysemu.c
@@ -0,0 +1,590 @@
+/*
+ * QMP command handlers specific to the system emulators
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ *
+ * This file incorporates work covered by the following copyright and
+ * permission notice:
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * 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 "qapi/error.h"
+#include "qapi/qapi-commands-block.h"
+#include "qapi/qmp/qdict.h"
+#include "sysemu/block-backend.h"
+#include "sysemu/blockdev.h"
+
+static BlockBackend *qmp_get_blk(const char *blk_name, const char *qdev_id,
+ Error **errp)
+{
+BlockBackend *blk;
+
+if (!blk_name == !qdev_id) {
+error_setg(errp, "Need exactly one of 'device' and 'id'");
+return NULL;
+}
+
+if (qdev_id) {
+blk = blk_by_qdev_id(qdev_id, errp);
+} else {
+blk = blk_by_name(blk_name);
+if (blk == NULL) {
+error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+  "Device '%s' not found", blk_name);
+}
+}
+
+return blk;
+}
+
+/*
+ * Attempt to open the tray of @device.
+ * If @force, ignore its tray lock.
+ * Else, if the tray is locked, don't open it, but ask the guest to open it.
+ * On error, store an error through @errp and return -errno.
+ * If @device does not exist, return -ENODEV.
+ * If it has no removable media, return -ENOTSUP.
+ * If it has no tray, return -ENOSYS.
+ * If the guest was asked to open the tray, return -EINPROGRESS.
+ * Else, return 0.
+ */
+static int do_open_tray(const char *blk_name, const char *qdev_id,
+bool force, Error **errp)
+{
+BlockBackend *blk;
+const char *device = qdev_id ?: blk_name;
+bool locked;
+
+blk = qmp_get_blk(blk_name, qdev_id, errp);
+if (!blk) {
+return -ENODEV;
+}
+
+if (!blk_dev_has_removable_media(blk)) {
+error_setg(errp, "Device '%s' is not removable", device);
+return -ENOTSUP;
+}
+
+if (!blk_dev_has_tray(blk)) {
+error_setg(errp, "Device '%s' does not have a tray", device);
+return -ENOSYS;
+}
+
+if (blk_dev_is_tray_open(blk)) {
+return 0;
+}
+
+locked = blk_dev_is_medium_locked(blk);
+if (locked) {
+blk_dev_eject_request(blk, force);
+}
+
+if (!locked || force) {
+blk_dev_change_media_cb(blk, false, &error_abort);
+}
+
+if (locked && !force) {
+error_setg(errp, "Device '%s' is locked and force was not specified, "
+   "wait for tray to open and try again", device);
+return -EINPROGRESS;
+}
+
+return 0;
+}
+
+void qmp_blockdev_open_tray(bool has_device, const char *device,
+bool has_id, const char *id,
+bool has_force, bool force,
+Error **errp)
+{
+Error *local_err = NULL;
+int rc;
+
+if (!has_force) {
+force = false;
+}
+rc = do_open_tray(has_device ? device : 

Re: [PATCH] tests/qemu-iotests: Fix socket_scm_helper build path

2020-03-06 Thread no-reply
Patchew URL: https://patchew.org/QEMU/20200306165751.18986-1-phi...@redhat.com/



Hi,

This series failed the docker-clang@ubuntu build test. Please find the testing 
commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-ubuntu V=1 NETWORK=1
time make docker-test-clang@ubuntu SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===

  GEN i386-softmmu/config-devices.h
  GEN i386-softmmu/config-target.h
  CC  i386-softmmu/exec.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6/usr/bin/ld
: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  aarch64-softmmu/exec-vary.o
  CC  aarch64-softmmu/tcg/tcg.o
  CC  alpha-softmmu/exec-vary.o
---
  CC  mips64-softmmu/hw/9pfs/virtio-9p-device.o
  CC  aarch64-softmmu/hw/arm/netduinoplus2.o
  CC  mipsel-softmmu/migration/ram.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  aarch64-softmmu/hw/arm/nseries.o
  CC  mips64el-softmmu/accel/tcg/translator.o
  CC  mips64-softmmu/hw/block/virtio-blk.o
---
  CC  mips64-softmmu/hw/net/rocker/qmp-norocker.o
  CC  aarch64-softmmu/hw/arm/sabrelite.o
  CC  mips64el-softmmu/hw/misc/mips_itu.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  mips64-softmmu/hw/rtc/mc146818rtc.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  mipsel-softmmu/hw/block/vhost-user-blk.o
  GEN trace/generated-helpers.c
  CC  i386-softmmu/hw/i386/kvmvapic.o
---
  CC  nios2-softmmu/exec-vary.o
  CC  mipsel-softmmu/hw/net/virtio-net.o
  CC  mips64el-softmmu/hw/semihosting/console.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  mipsel-softmmu/hw/net/rocker/qmp-norocker.o
  CC  nios2-softmmu/tcg/tcg.o
  CC  mips64-softmmu/hw/vfio/display.o
---
  CC  ppc-softmmu/gdbstub.o
  CC  ppc-softmmu/balloon.o
  GEN trace/generated-helpers.c
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  nios2-softmmu/trace/control-target.o
  CC  aarch64-softmmu/target/arm/arm-semi.o
  GEN trace/generated-helpers.c
---
  CC  or1k-softmmu/qapi/qapi-types-machine-target.o
  CC  mips64el-softmmu/target/mips/op_helper.o
  CC  mips64el-softmmu/target/mips/cp0_helper.o
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  LINKi386-softmmu/qemu-system-i386
  CC  aarch64-softmmu/target/arm/gdbstub64.o
  CC  arm-softmmu/target/arm/gdbstub.o
---
  CC  mips64el-softmmu/target/mips/fpu_helper.o
  CC  or1k-softmmu/qapi/qapi-types.o
  GEN trace/generated-helpers.c
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  mipsel-softmmu/trace/control-target.o
  CC  or1k-softmmu/qapi/qapi-visit-machine-target.o
  CC  ppc64-softmmu/accel/stubs/kvm-stub.o
---
  CC  mips64el-softmmu/trace/generated-helpers.o
  CC  ppc64-softmmu/hw/9pfs/virtio-9p-device.o
  GEN arm-softmmu/target/arm/decode-a32-uncond.inc.c
/usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of 
`rpc_createerr@@GLIBC_2.2.5' overridden by definition from 
/lib/x86_64-linux-gnu/libc.so.6
  CC  ppc-softmmu/hw/block/virtio-blk.o
  CC  ppc-s

[PULL 11/29] block: Move sysemu QMP commands to QAPI block module

2020-03-06 Thread Kevin Wolf
QMP commands that are related to the system emulator and don't make
sense in the context of tools such as qemu-storage-daemon should live in
qapi/block.json rather than qapi/block-core.json. Move them there.

The associated data types are actually also used in code shared with the
tools, so they stay in block-core.json.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-6-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qapi/block-core.json | 386 ---
 qapi/block.json  | 386 +++
 monitor/qmp-cmds.c   |   2 +-
 3 files changed, 387 insertions(+), 387 deletions(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index 60860ead68..b65b6a9f49 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -563,78 +563,6 @@
 { 'struct': 'BlockLatencyHistogramInfo',
   'data': {'boundaries': ['uint64'], 'bins': ['uint64'] } }
 
-##
-# @block-latency-histogram-set:
-#
-# Manage read, write and flush latency histograms for the device.
-#
-# If only @id parameter is specified, remove all present latency histograms
-# for the device. Otherwise, add/reset some of (or all) latency histograms.
-#
-# @id: The name or QOM path of the guest device.
-#
-# @boundaries: list of interval boundary values (see description in
-#  BlockLatencyHistogramInfo definition). If specified, all
-#  latency histograms are removed, and empty ones created for all
-#  io types with intervals corresponding to @boundaries (except for
-#  io types, for which specific boundaries are set through the
-#  following parameters).
-#
-# @boundaries-read: list of interval boundary values for read latency
-#   histogram. If specified, old read latency histogram is
-#   removed, and empty one created with intervals
-#   corresponding to @boundaries-read. The parameter has higher
-#   priority then @boundaries.
-#
-# @boundaries-write: list of interval boundary values for write latency
-#histogram.
-#
-# @boundaries-flush: list of interval boundary values for flush latency
-#histogram.
-#
-# Returns: error if device is not found or any boundary arrays are invalid.
-#
-# Since: 4.0
-#
-# Example: set new histograms for all io types with intervals
-# [0, 10), [10, 50), [50, 100), [100, +inf):
-#
-# -> { "execute": "block-latency-histogram-set",
-#  "arguments": { "id": "drive0",
-# "boundaries": [10, 50, 100] } }
-# <- { "return": {} }
-#
-# Example: set new histogram only for write, other histograms will remain
-# not changed (or not created):
-#
-# -> { "execute": "block-latency-histogram-set",
-#  "arguments": { "id": "drive0",
-# "boundaries-write": [10, 50, 100] } }
-# <- { "return": {} }
-#
-# Example: set new histograms with the following intervals:
-#   read, flush: [0, 10), [10, 50), [50, 100), [100, +inf)
-#   write: [0, 1000), [1000, 5000), [5000, +inf)
-#
-# -> { "execute": "block-latency-histogram-set",
-#  "arguments": { "id": "drive0",
-# "boundaries": [10, 50, 100],
-# "boundaries-write": [1000, 5000] } }
-# <- { "return": {} }
-#
-# Example: remove all latency histograms:
-#
-# -> { "execute": "block-latency-histogram-set",
-#  "arguments": { "id": "drive0" } }
-# <- { "return": {} }
-##
-{ 'command': 'block-latency-histogram-set',
-  'data': {'id': 'str',
-   '*boundaries': ['uint64'],
-   '*boundaries-read': ['uint64'],
-   '*boundaries-write': ['uint64'],
-   '*boundaries-flush': ['uint64'] } }
-
 ##
 # @BlockInfo:
 #
@@ -2356,78 +2284,6 @@
 '*copy-mode': 'MirrorCopyMode',
 '*auto-finalize': 'bool', '*auto-dismiss': 'bool' } }
 
-##
-# @block_set_io_throttle:
-#
-# Change I/O throttle limits for a block drive.
-#
-# Since QEMU 2.4, each device with I/O limits is member of a throttle
-# group.
-#
-# If two or more devices are members of the same group, the limits
-# will apply to the combined I/O of the whole group in a round-robin
-# fashion. Therefore, setting new I/O limits to a device will affect
-# the whole group.
-#
-# The name of the group can be specified using the 'group' parameter.
-# If the parameter is unset, it is assumed to be the current group of
-# that device. If it's not in any group yet, the name of the device
-# will be used as the name for its group.
-#
-# The 'group' parameter can also be used to move a device to a
-# different group. In this case the limits specified in the parameters
-# will be applied to the new group only.
-#
-# I/O limits can be disabled by setting all of them to 0. In this case
-# the device will be removed from its group and the rest of its
-# members will not be affected. The 'group' parameter is ignored.
-#
-# Returns: - Nothing on success
-#  

[PULL 26/29] qemu-storage-daemon: Add --monitor option

2020-03-06 Thread Kevin Wolf
This adds and parses the --monitor option, so that a QMP monitor can be
used in the storage daemon. The monitor offers commands defined in the
QAPI schema at storage-daemon/qapi/qapi-schema.json.

The --monitor options currently allows to create multiple monitors with
the same ID. This part of the interface is considered unstable. We will
reject such configurations as soon as we have a design for the monitor
subsystem to perform these checks. (In the system emulator, we depend on
QemuOpts rejecting duplicate IDs.)

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-21-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qapi/transaction.json|  2 +-
 qemu-storage-daemon.c| 47 ++--
 scripts/qapi/gen.py  |  5 +++
 Makefile | 33 +++
 Makefile.objs|  4 +--
 monitor/Makefile.objs|  2 ++
 qapi/Makefile.objs   |  5 +++
 storage-daemon/Makefile.objs |  1 +
 storage-daemon/qapi/Makefile.objs|  1 +
 storage-daemon/qapi/qapi-schema.json | 26 +++
 10 files changed, 121 insertions(+), 5 deletions(-)
 create mode 100644 storage-daemon/Makefile.objs
 create mode 100644 storage-daemon/qapi/Makefile.objs
 create mode 100644 storage-daemon/qapi/qapi-schema.json

diff --git a/qapi/transaction.json b/qapi/transaction.json
index 04301f1be7..b6c11158f0 100644
--- a/qapi/transaction.json
+++ b/qapi/transaction.json
@@ -5,7 +5,7 @@
 # = Transactions
 ##
 
-{ 'include': 'block.json' }
+{ 'include': 'block-core.json' }
 
 ##
 # @Abort:
diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
index 82fe6cd5f2..dd128978cc 100644
--- a/qemu-storage-daemon.c
+++ b/qemu-storage-daemon.c
@@ -31,13 +31,15 @@
 #include "block/nbd.h"
 #include "chardev/char.h"
 #include "crypto/init.h"
+#include "monitor/monitor.h"
+#include "monitor/monitor-internal.h"
 
 #include "qapi/error.h"
-#include "qapi/qapi-commands-block.h"
-#include "qapi/qapi-commands-block-core.h"
 #include "qapi/qapi-visit-block.h"
 #include "qapi/qapi-visit-block-core.h"
+#include "qapi/qapi-visit-control.h"
 #include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qstring.h"
 #include "qapi/qobject-input-visitor.h"
 
 #include "qemu-common.h"
@@ -51,6 +53,9 @@
 #include "qemu/option.h"
 #include "qom/object_interfaces.h"
 
+#include "storage-daemon/qapi/qapi-commands.h"
+#include "storage-daemon/qapi/qapi-init-commands.h"
+
 #include "sysemu/runstate.h"
 #include "trace/control.h"
 
@@ -61,6 +66,11 @@ void qemu_system_killed(int signal, pid_t pid)
 exit_requested = true;
 }
 
+void qmp_quit(Error **errp)
+{
+exit_requested = true;
+}
+
 static void help(void)
 {
 printf(
@@ -87,6 +97,9 @@ static void help(void)
 " export the specified block node over NBD\n"
 " (requires --nbd-server)\n"
 "\n"
+"  --monitor [chardev=]name[,mode=control][,pretty[=on|off]]\n"
+" configure a QMP monitor\n"
+"\n"
 "  --nbd-server addr.type=inet,addr.host=,addr.port=\n"
 "   [,tls-creds=][,tls-authz=]\n"
 "  --nbd-server addr.type=unix,addr.path=\n"
@@ -110,6 +123,7 @@ enum {
 OPTION_BLOCKDEV = 256,
 OPTION_CHARDEV,
 OPTION_EXPORT,
+OPTION_MONITOR,
 OPTION_NBD_SERVER,
 OPTION_OBJECT,
 };
@@ -125,6 +139,17 @@ static QemuOptsList qemu_object_opts = {
 },
 };
 
+static void init_qmp_commands(void)
+{
+qmp_init_marshal(&qmp_commands);
+qmp_register_command(&qmp_commands, "query-qmp-schema",
+ qmp_query_qmp_schema, QCO_ALLOW_PRECONFIG);
+
+QTAILQ_INIT(&qmp_cap_negotiation_commands);
+qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",
+ qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG);
+}
+
 static void init_export(BlockExport *export, Error **errp)
 {
 switch (export->type) {
@@ -145,6 +170,7 @@ static void process_options(int argc, char *argv[])
 {"chardev", required_argument, NULL, OPTION_CHARDEV},
 {"export", required_argument, NULL, OPTION_EXPORT},
 {"help", no_argument, NULL, 'h'},
+{"monitor", required_argument, NULL, OPTION_MONITOR},
 {"nbd-server", required_argument, NULL, OPTION_NBD_SERVER},
 {"object", required_argument, NULL, OPTION_OBJECT},
 {"trace", required_argument, NULL, 'T'},
@@ -219,6 +245,21 @@ static void process_options(int argc, char *argv[])
 qapi_free_BlockExport(export);
 break;
 }
+case OPTION_MONITOR:
+{
+Visitor *v;
+MonitorOptions *monitor;
+
+v = qobject_input_visitor_new_str(optarg, "chardev",
+  &error_fatal);
+visit_type_MonitorOptions(v, NULL, &monitor, &error_fatal);
+visit_free(v);
+
+

[PULL 24/29] hmp: Fail gracefully if chardev is already in use

2020-03-06 Thread Kevin Wolf
Trying to attach a HMP monitor to a chardev that is already in use
results in a crash because monitor_init_hmp() passes &error_abort to
qemu_chr_fe_init():

$ ./x86_64-softmmu/qemu-system-x86_64 --chardev stdio,id=foo --mon foo --mon foo
QEMU 4.2.50 monitor - type 'help' for more information
(qemu) Unexpected error in qemu_chr_fe_init() at chardev/char-fe.c:220:
qemu-system-x86_64: --mon foo: Device 'foo' is in use
Abgebrochen (Speicherabzug geschrieben)

Fix this by allowing monitor_init_hmp() to return an error and passing
any error in qemu_chr_fe_init() to its caller instead of aborting.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-19-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 include/monitor/monitor.h | 2 +-
 chardev/char.c| 8 +++-
 gdbstub.c | 2 +-
 monitor/hmp.c | 8 ++--
 monitor/monitor.c | 2 +-
 stubs/monitor.c   | 2 +-
 tests/test-util-sockets.c | 2 +-
 7 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index e55a3b57e0..ad823b9edb 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -18,7 +18,7 @@ bool monitor_cur_is_qmp(void);
 void monitor_init_globals(void);
 void monitor_init_globals_core(void);
 void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp);
-void monitor_init_hmp(Chardev *chr, bool use_readline);
+void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp);
 int monitor_init(MonitorOptions *opts, Error **errp);
 int monitor_init_opts(QemuOpts *opts, Error **errp);
 void monitor_cleanup(void);
diff --git a/chardev/char.c b/chardev/char.c
index 87237568df..e77564060d 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -737,7 +737,13 @@ Chardev *qemu_chr_new_noreplay(const char *label, const 
char *filename,
 
 if (qemu_opt_get_bool(opts, "mux", 0)) {
 assert(permit_mux_mon);
-monitor_init_hmp(chr, true);
+monitor_init_hmp(chr, true, &err);
+if (err) {
+error_report_err(err);
+object_unparent(OBJECT(chr));
+chr = NULL;
+goto out;
+}
 }
 
 out:
diff --git a/gdbstub.c b/gdbstub.c
index ce304ff482..22a2d630cd 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -3367,7 +3367,7 @@ int gdbserver_start(const char *device)
 /* Initialize a monitor terminal for gdb */
 mon_chr = qemu_chardev_new(NULL, TYPE_CHARDEV_GDB,
NULL, NULL, &error_abort);
-monitor_init_hmp(mon_chr, false);
+monitor_init_hmp(mon_chr, false, &error_abort);
 } else {
 qemu_chr_fe_deinit(&s->chr, true);
 mon_chr = s->mon_chr;
diff --git a/monitor/hmp.c b/monitor/hmp.c
index 944fa9651e..d598dd02bb 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1399,12 +1399,16 @@ static void monitor_readline_flush(void *opaque)
 monitor_flush(&mon->common);
 }
 
-void monitor_init_hmp(Chardev *chr, bool use_readline)
+void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp)
 {
 MonitorHMP *mon = g_new0(MonitorHMP, 1);
 
+if (!qemu_chr_fe_init(&mon->common.chr, chr, errp)) {
+g_free(mon);
+return;
+}
+
 monitor_data_init(&mon->common, false, false, false);
-qemu_chr_fe_init(&mon->common.chr, chr, &error_abort);
 
 mon->use_readline = use_readline;
 if (mon->use_readline) {
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 00d287655e..2282bf6780 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -631,7 +631,7 @@ int monitor_init(MonitorOptions *opts, Error **errp)
 warn_report("'pretty' is deprecated for HMP monitors, it has no "
 "effect and will be removed in future versions");
 }
-monitor_init_hmp(chr, true);
+monitor_init_hmp(chr, true, &local_err);
 break;
 default:
 g_assert_not_reached();
diff --git a/stubs/monitor.c b/stubs/monitor.c
index 9403f8e72c..20786ac4ff 100644
--- a/stubs/monitor.c
+++ b/stubs/monitor.c
@@ -9,7 +9,7 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **errp)
 return -1;
 }
 
-void monitor_init_hmp(Chardev *chr, bool use_readline)
+void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp)
 {
 }
 
diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c
index 2edb4c539d..5fd947c7bf 100644
--- a/tests/test-util-sockets.c
+++ b/tests/test-util-sockets.c
@@ -72,7 +72,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error 
**errp)
 __thread Monitor *cur_mon;
 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); }
 void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) {}
-void monitor_init_hmp(Chardev *chr, bool use_readline) {}
+void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp) {}
 
 
 static void test_socket_fd_pass_name_good(void)
-- 
2.20.1




[PULL 22/29] monitor: Create QAPIfied monitor_init()

2020-03-06 Thread Kevin Wolf
This adds a new QAPI-based monitor_init() function. The existing
monitor_init_opts() is rewritten to simply put its QemuOpts parameter
into a visitor and pass the resulting QAPI object to monitor_init().

This will cause some change in those error messages for the monitor
options in the system emulator that are now generated by the visitor
rather than explicitly checked in monitor_init_opts().

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-17-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qapi/control.json | 36 ++
 include/monitor/monitor.h |  2 +
 monitor/monitor.c | 77 +--
 3 files changed, 80 insertions(+), 35 deletions(-)

diff --git a/qapi/control.json b/qapi/control.json
index 759c20e76f..3ee086aec7 100644
--- a/qapi/control.json
+++ b/qapi/control.json
@@ -216,3 +216,39 @@
 # <- { "return": {} }
 ##
 { 'command': 'quit' }
+
+##
+# @MonitorMode:
+#
+# An enumeration of monitor modes.
+#
+# @readline: HMP monitor (human-oriented command line interface)
+#
+# @control: QMP monitor (JSON-based machine interface)
+#
+# Since: 5.0
+##
+{ 'enum': 'MonitorMode', 'data': [ 'readline', 'control' ] }
+
+##
+# @MonitorOptions:
+#
+# Options to be used for adding a new monitor.
+#
+# @id:  Name of the monitor
+#
+# @mode:Selects the monitor mode (default: readline)
+#
+# @pretty:  Enables pretty printing (QMP only)
+#
+# @chardev: Name of a character device to expose the monitor on
+#
+# Since: 5.0
+##
+{ 'struct': 'MonitorOptions',
+  'data': {
+  '*id': 'str',
+  '*mode': 'MonitorMode',
+  '*pretty': 'bool',
+  'chardev': 'str'
+  } }
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index b7bdd2bb2a..db1112552c 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -7,6 +7,7 @@
 
 extern __thread Monitor *cur_mon;
 typedef struct MonitorHMP MonitorHMP;
+typedef struct MonitorOptions MonitorOptions;
 
 #define QMP_REQ_QUEUE_LEN_MAX 8
 
@@ -18,6 +19,7 @@ void monitor_init_globals(void);
 void monitor_init_globals_core(void);
 void monitor_init_qmp(Chardev *chr, bool pretty);
 void monitor_init_hmp(Chardev *chr, bool use_readline);
+int monitor_init(MonitorOptions *opts, Error **errp);
 int monitor_init_opts(QemuOpts *opts, Error **errp);
 void monitor_cleanup(void);
 
diff --git a/monitor/monitor.c b/monitor/monitor.c
index c1a6c4460f..f8a6ef795b 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -25,7 +25,9 @@
 #include "qemu/osdep.h"
 #include "monitor-internal.h"
 #include "qapi/error.h"
+#include "qapi/opts-visitor.h"
 #include "qapi/qapi-emit-events.h"
+#include "qapi/qapi-visit-control.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
 #include "qemu/error-report.h"
@@ -609,50 +611,55 @@ void monitor_init_globals_core(void)
NULL);
 }
 
-int monitor_init_opts(QemuOpts *opts, Error **errp)
+int monitor_init(MonitorOptions *opts, Error **errp)
 {
 Chardev *chr;
-bool qmp;
-bool pretty = false;
-const char *chardev;
-const char *mode;
-
-mode = qemu_opt_get(opts, "mode");
-if (mode == NULL) {
-mode = "readline";
-}
-if (strcmp(mode, "readline") == 0) {
-qmp = false;
-} else if (strcmp(mode, "control") == 0) {
-qmp = true;
-} else {
-error_setg(errp, "unknown monitor mode \"%s\"", mode);
+
+chr = qemu_chr_find(opts->chardev);
+if (chr == NULL) {
+error_setg(errp, "chardev \"%s\" not found", opts->chardev);
 return -1;
 }
 
-if (!qmp && qemu_opt_get(opts, "pretty")) {
-warn_report("'pretty' is deprecated for HMP monitors, it has no effect 
"
-"and will be removed in future versions");
-}
-if (qemu_opt_get_bool(opts, "pretty", 0)) {
-pretty = true;
+switch (opts->mode) {
+case MONITOR_MODE_CONTROL:
+monitor_init_qmp(chr, opts->pretty);
+break;
+case MONITOR_MODE_READLINE:
+if (opts->pretty) {
+warn_report("'pretty' is deprecated for HMP monitors, it has no "
+"effect and will be removed in future versions");
+}
+monitor_init_hmp(chr, true);
+break;
+default:
+g_assert_not_reached();
 }
 
-chardev = qemu_opt_get(opts, "chardev");
-if (!chardev) {
-error_report("chardev is required");
-exit(1);
-}
-chr = qemu_chr_find(chardev);
-if (chr == NULL) {
-error_setg(errp, "chardev \"%s\" not found", chardev);
-return -1;
+return 0;
+}
+
+int monitor_init_opts(QemuOpts *opts, Error **errp)
+{
+Visitor *v;
+MonitorOptions *options;
+Error *local_err = NULL;
+
+v = opts_visitor_new(opts);
+visit_type_MonitorOptions(v, NULL, &options, &local_err);
+visit_free(v);
+
+if (local_err) {
+goto out;
 }
 
-if (qmp) {
-monitor_

[PULL 27/29] block/rbd: Add support for ceph namespaces

2020-03-06 Thread Kevin Wolf
From: Florian Florensa 

Starting from ceph Nautilus, RBD has support for namespaces, allowing
for finer grain ACLs on images inside a pool, and tenant isolation.

In the rbd cli tool documentation, the new image-spec and snap-spec are :
 - [pool-name/[namespace-name/]]image-name
 - [pool-name/[namespace-name/]]image-name@snap-name

When using an non namespace's enabled qemu, it complains about not
finding the image called namespace-name/image-name, thus we only need to
parse the image once again to find if there is a '/' in its name, and if
there is, use what is before it as the name of the namespace to later
pass it to rados_ioctx_set_namespace.
rados_ioctx_set_namespace if called with en empty string or a null
pointer as the namespace parameters pretty much does nothing, as it then
defaults to the default namespace.

The namespace is extracted inside qemu_rbd_parse_filename, stored in the
qdict, and used in qemu_rbd_connect to make it work with both qemu-img,
and qemu itself.

Signed-off-by: Florian Florensa 
Message-Id: <20200110111513.321728-2-fflore...@online.net>
Reviewed-by: Jason Dillaman 
Reviewed-by: Stefano Garzarella 
Signed-off-by: Kevin Wolf 
---
 qapi/block-core.json |  3 +++
 block/rbd.c  | 44 +++-
 2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index 48631218fa..9758fc48d2 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -3544,6 +3544,8 @@
 #
 # @pool: Ceph pool name.
 #
+# @namespace: Rados namespace name in the Ceph pool. (Since 5.0)
+#
 # @image: Image name in the Ceph pool.
 #
 # @conf: path to Ceph configuration file.  Values
@@ -3570,6 +3572,7 @@
 ##
 { 'struct': 'BlockdevOptionsRbd',
   'data': { 'pool': 'str',
+'*namespace': 'str',
 'image': 'str',
 '*conf': 'str',
 '*snapshot': 'str',
diff --git a/block/rbd.c b/block/rbd.c
index 027cbcc695..84115d34b4 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -104,6 +104,7 @@ typedef struct BDRVRBDState {
 rbd_image_t image;
 char *image_name;
 char *snap;
+char *namespace;
 uint64_t image_size;
 } BDRVRBDState;
 
@@ -152,7 +153,7 @@ static void qemu_rbd_parse_filename(const char *filename, 
QDict *options,
 const char *start;
 char *p, *buf;
 QList *keypairs = NULL;
-char *found_str;
+char *found_str, *image_name;
 
 if (!strstart(filename, "rbd:", &start)) {
 error_setg(errp, "File name must start with 'rbd:'");
@@ -171,18 +172,24 @@ static void qemu_rbd_parse_filename(const char *filename, 
QDict *options,
 qdict_put_str(options, "pool", found_str);
 
 if (strchr(p, '@')) {
-found_str = qemu_rbd_next_tok(p, '@', &p);
-qemu_rbd_unescape(found_str);
-qdict_put_str(options, "image", found_str);
+image_name = qemu_rbd_next_tok(p, '@', &p);
 
 found_str = qemu_rbd_next_tok(p, ':', &p);
 qemu_rbd_unescape(found_str);
 qdict_put_str(options, "snapshot", found_str);
 } else {
-found_str = qemu_rbd_next_tok(p, ':', &p);
+image_name = qemu_rbd_next_tok(p, ':', &p);
+}
+/* Check for namespace in the image_name */
+if (strchr(image_name, '/')) {
+found_str = qemu_rbd_next_tok(image_name, '/', &image_name);
 qemu_rbd_unescape(found_str);
-qdict_put_str(options, "image", found_str);
+qdict_put_str(options, "namespace", found_str);
+} else {
+qdict_put_str(options, "namespace", "");
 }
+qemu_rbd_unescape(image_name);
+qdict_put_str(options, "image", image_name);
 if (!p) {
 goto done;
 }
@@ -343,6 +350,11 @@ static QemuOptsList runtime_opts = {
 .type = QEMU_OPT_STRING,
 .help = "Rados pool name",
 },
+{
+.name = "namespace",
+.type = QEMU_OPT_STRING,
+.help = "Rados namespace name in the pool",
+},
 {
 .name = "image",
 .type = QEMU_OPT_STRING,
@@ -467,13 +479,14 @@ static int coroutine_fn qemu_rbd_co_create_opts(const 
char *filename,
  * schema, but when they come from -drive, they're all QString.
  */
 loc = rbd_opts->location;
-loc->pool = g_strdup(qdict_get_try_str(options, "pool"));
-loc->conf = g_strdup(qdict_get_try_str(options, "conf"));
-loc->has_conf = !!loc->conf;
-loc->user = g_strdup(qdict_get_try_str(options, "user"));
-loc->has_user = !!loc->user;
-loc->image= g_strdup(qdict_get_try_str(options, "image"));
-keypairs  = qdict_get_try_str(options, "=keyvalue-pairs");
+loc->pool= g_strdup(qdict_get_try_str(options, "pool"));
+loc->conf= g_strdup(qdict_get_try_str(options, "conf"));
+loc->has_conf= !!loc->conf;
+loc->user= g_strdup(qdict_get_try_str(options, "user"));
+loc->has_user= !!loc->user;
+loc->q_namespace = g_strdup(qdi

[PULL 25/29] monitor: Add allow_hmp parameter to monitor_init()

2020-03-06 Thread Kevin Wolf
Add a new parameter allow_hmp to monitor_init() so that the storage
daemon can disable HMP.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-20-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qapi/control.json |  3 ++-
 include/monitor/monitor.h |  2 +-
 monitor/monitor.c | 12 ++--
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/qapi/control.json b/qapi/control.json
index 3ee086aec7..85b12fe0fb 100644
--- a/qapi/control.json
+++ b/qapi/control.json
@@ -237,7 +237,8 @@
 #
 # @id:  Name of the monitor
 #
-# @mode:Selects the monitor mode (default: readline)
+# @mode:Selects the monitor mode (default: readline in the system
+#   emulator, control in qemu-storage-daemon)
 #
 # @pretty:  Enables pretty printing (QMP only)
 #
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index ad823b9edb..1018d754a6 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -19,7 +19,7 @@ void monitor_init_globals(void);
 void monitor_init_globals_core(void);
 void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp);
 void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp);
-int monitor_init(MonitorOptions *opts, Error **errp);
+int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp);
 int monitor_init_opts(QemuOpts *opts, Error **errp);
 void monitor_cleanup(void);
 
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 2282bf6780..125494410a 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -611,7 +611,7 @@ void monitor_init_globals_core(void)
NULL);
 }
 
-int monitor_init(MonitorOptions *opts, Error **errp)
+int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp)
 {
 Chardev *chr;
 Error *local_err = NULL;
@@ -622,11 +622,19 @@ int monitor_init(MonitorOptions *opts, Error **errp)
 return -1;
 }
 
+if (!opts->has_mode) {
+opts->mode = allow_hmp ? MONITOR_MODE_READLINE : MONITOR_MODE_CONTROL;
+}
+
 switch (opts->mode) {
 case MONITOR_MODE_CONTROL:
 monitor_init_qmp(chr, opts->pretty, &local_err);
 break;
 case MONITOR_MODE_READLINE:
+if (!allow_hmp) {
+error_setg(errp, "Only QMP is supported");
+return -1;
+}
 if (opts->pretty) {
 warn_report("'pretty' is deprecated for HMP monitors, it has no "
 "effect and will be removed in future versions");
@@ -658,7 +666,7 @@ int monitor_init_opts(QemuOpts *opts, Error **errp)
 goto out;
 }
 
-monitor_init(options, &local_err);
+monitor_init(options, true, &local_err);
 qapi_free_MonitorOptions(options);
 
 out:
-- 
2.20.1




[PATCH 1/7] Makefile: Remove redundant Texinfo related code

2020-03-06 Thread Peter Maydell
The recent conversion of qemu-doc.texi to rST forgot a few stray bits
of makefile code that are now redundant. Remove them.

Signed-off-by: Peter Maydell 
---
 Makefile | 11 +--
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index 9d4b2241265..2ccd80065b6 100644
--- a/Makefile
+++ b/Makefile
@@ -761,7 +761,7 @@ rm -f $(MANUAL_BUILDDIR)/$1/objects.inv 
$(MANUAL_BUILDDIR)/$1/searchindex.js $(M
 endef
 
 distclean: clean
-   rm -f config-host.mak config-host.h* config-host.ld $(DOCS) 
qemu-options.texi qemu-monitor.texi qemu-monitor-info.texi
+   rm -f config-host.mak config-host.h* config-host.ld $(DOCS)
rm -f tests/tcg/config-*.mak
rm -f config-all-devices.mak config-all-disas.mak config.status
rm -f $(SUBDIR_DEVICES_MAK)
@@ -1088,15 +1088,6 @@ $(MANUAL_BUILDDIR)/index.html: 
$(SRC_PATH)/docs/index.html.in qemu-version.h
$(call quiet-command, sed "s|@@VERSION@@|${VERSION}|g" $< >$@, \
  "GEN","$@")
 
-qemu-options.texi: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool
-   $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > 
$@,"GEN","$@")
-
-qemu-monitor.texi: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
-   $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > 
$@,"GEN","$@")
-
-qemu-monitor-info.texi: $(SRC_PATH)/hmp-commands-info.hx 
$(SRC_PATH)/scripts/hxtool
-   $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > 
$@,"GEN","$@")
-
 docs/interop/qemu-qmp-qapi.texi: qapi/qapi-doc.texi
@cp -p $< $@
 
-- 
2.20.1




[PULL 23/29] qmp: Fail gracefully if chardev is already in use

2020-03-06 Thread Kevin Wolf
Trying to attach a QMP monitor to a chardev that is already in use
results in a crash because monitor_init_qmp() passes &error_abort to
qemu_chr_fe_init():

$ ./x86_64-softmmu/qemu-system-x86_64 --chardev stdio,id=foo --mon 
foo,mode=control --mon foo,mode=control
Unexpected error in qemu_chr_fe_init() at chardev/char-fe.c:220:
qemu-system-x86_64: --mon foo,mode=control: Device 'foo' is in use
Abgebrochen (Speicherabzug geschrieben)

Fix this by allowing monitor_init_qmp() to return an error and passing
any error in qemu_chr_fe_init() to its caller instead of aborting.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-18-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 include/monitor/monitor.h |  2 +-
 monitor/monitor.c |  7 ++-
 monitor/qmp.c | 11 +++
 stubs/monitor-core.c  |  2 +-
 tests/test-util-sockets.c |  2 +-
 5 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index db1112552c..e55a3b57e0 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -17,7 +17,7 @@ bool monitor_cur_is_qmp(void);
 
 void monitor_init_globals(void);
 void monitor_init_globals_core(void);
-void monitor_init_qmp(Chardev *chr, bool pretty);
+void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp);
 void monitor_init_hmp(Chardev *chr, bool use_readline);
 int monitor_init(MonitorOptions *opts, Error **errp);
 int monitor_init_opts(QemuOpts *opts, Error **errp);
diff --git a/monitor/monitor.c b/monitor/monitor.c
index f8a6ef795b..00d287655e 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -614,6 +614,7 @@ void monitor_init_globals_core(void)
 int monitor_init(MonitorOptions *opts, Error **errp)
 {
 Chardev *chr;
+Error *local_err = NULL;
 
 chr = qemu_chr_find(opts->chardev);
 if (chr == NULL) {
@@ -623,7 +624,7 @@ int monitor_init(MonitorOptions *opts, Error **errp)
 
 switch (opts->mode) {
 case MONITOR_MODE_CONTROL:
-monitor_init_qmp(chr, opts->pretty);
+monitor_init_qmp(chr, opts->pretty, &local_err);
 break;
 case MONITOR_MODE_READLINE:
 if (opts->pretty) {
@@ -636,6 +637,10 @@ int monitor_init(MonitorOptions *opts, Error **errp)
 g_assert_not_reached();
 }
 
+if (local_err) {
+error_propagate(errp, local_err);
+return -1;
+}
 return 0;
 }
 
diff --git a/monitor/qmp.c b/monitor/qmp.c
index 8379c8f96e..f89e7daf27 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -395,10 +395,16 @@ static void monitor_qmp_setup_handlers_bh(void *opaque)
 monitor_list_append(&mon->common);
 }
 
-void monitor_init_qmp(Chardev *chr, bool pretty)
+void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp)
 {
 MonitorQMP *mon = g_new0(MonitorQMP, 1);
 
+if (!qemu_chr_fe_init(&mon->common.chr, chr, errp)) {
+g_free(mon);
+return;
+}
+qemu_chr_fe_set_echo(&mon->common.chr, true);
+
 /* Note: we run QMP monitor in I/O thread when @chr supports that */
 monitor_data_init(&mon->common, true, false,
   qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT));
@@ -408,9 +414,6 @@ void monitor_init_qmp(Chardev *chr, bool pretty)
 qemu_mutex_init(&mon->qmp_queue_lock);
 mon->qmp_requests = g_queue_new();
 
-qemu_chr_fe_init(&mon->common.chr, chr, &error_abort);
-qemu_chr_fe_set_echo(&mon->common.chr, true);
-
 json_message_parser_init(&mon->parser, handle_qmp_command, mon, NULL);
 if (mon->common.use_io_thread) {
 /*
diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c
index 403c00a6d0..6cff1c4e1d 100644
--- a/stubs/monitor-core.c
+++ b/stubs/monitor-core.c
@@ -5,7 +5,7 @@
 
 __thread Monitor *cur_mon;
 
-void monitor_init_qmp(Chardev *chr, bool pretty)
+void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp)
 {
 }
 
diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c
index 8ce55efe70..2edb4c539d 100644
--- a/tests/test-util-sockets.c
+++ b/tests/test-util-sockets.c
@@ -71,7 +71,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error 
**errp)
  */
 __thread Monitor *cur_mon;
 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); }
-void monitor_init_qmp(Chardev *chr, bool pretty) {}
+void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) {}
 void monitor_init_hmp(Chardev *chr, bool use_readline) {}
 
 
-- 
2.20.1




[PULL 29/29] block: bdrv_reopen() with backing file in different AioContext

2020-03-06 Thread Kevin Wolf
This patch allows bdrv_reopen() (and therefore the x-blockdev-reopen QMP
command) to attach a node as the new backing file even if the node is in
a different AioContext than the parent if one of both nodes can be moved
to the AioContext of the other node.

Signed-off-by: Kevin Wolf 
Tested-by: Peter Krempa 
Message-Id: <20200306141413.30705-3-kw...@redhat.com>
Reviewed-by: Alberto Garcia 
Signed-off-by: Kevin Wolf 
---
 block.c| 32 ++--
 tests/qemu-iotests/245 |  8 +++-
 2 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/block.c b/block.c
index aaa387504e..957630b1c5 100644
--- a/block.c
+++ b/block.c
@@ -3787,6 +3787,29 @@ static void bdrv_reopen_perm(BlockReopenQueue *q, 
BlockDriverState *bs,
 *shared = cumulative_shared_perms;
 }
 
+static bool bdrv_reopen_can_attach(BlockDriverState *parent,
+   BdrvChild *child,
+   BlockDriverState *new_child,
+   Error **errp)
+{
+AioContext *parent_ctx = bdrv_get_aio_context(parent);
+AioContext *child_ctx = bdrv_get_aio_context(new_child);
+GSList *ignore;
+bool ret;
+
+ignore = g_slist_prepend(NULL, child);
+ret = bdrv_can_set_aio_context(new_child, parent_ctx, &ignore, NULL);
+g_slist_free(ignore);
+if (ret) {
+return ret;
+}
+
+ignore = g_slist_prepend(NULL, child);
+ret = bdrv_can_set_aio_context(parent, child_ctx, &ignore, errp);
+g_slist_free(ignore);
+return ret;
+}
+
 /*
  * Take a BDRVReopenState and check if the value of 'backing' in the
  * reopen_state->options QDict is valid or not.
@@ -3838,14 +3861,11 @@ static int bdrv_reopen_parse_backing(BDRVReopenState 
*reopen_state,
 }
 
 /*
- * TODO: before removing the x- prefix from x-blockdev-reopen we
- * should move the new backing file into the right AioContext
- * instead of returning an error.
+ * Check AioContext compatibility so that the bdrv_set_backing_hd() call in
+ * bdrv_reopen_commit() won't fail.
  */
 if (new_backing_bs) {
-if (bdrv_get_aio_context(new_backing_bs) != bdrv_get_aio_context(bs)) {
-error_setg(errp, "Cannot use a new backing file "
-   "with a different AioContext");
+if (!bdrv_reopen_can_attach(bs, bs->backing, new_backing_bs, errp)) {
 return -EINVAL;
 }
 }
diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245
index 7d9eb6285c..1001275a44 100755
--- a/tests/qemu-iotests/245
+++ b/tests/qemu-iotests/245
@@ -1015,18 +1015,16 @@ class TestBlockdevReopen(iotests.QMPTestCase):
 # neither of them can switch to the other AioContext
 def test_iothreads_error(self):
 self.run_test_iothreads('iothread0', 'iothread1',
-"Cannot use a new backing file with a 
different AioContext")
+"Cannot change iothread of active block 
backend")
 
 def test_iothreads_compatible_users(self):
 self.run_test_iothreads('iothread0', 'iothread0')
 
 def test_iothreads_switch_backing(self):
-self.run_test_iothreads('iothread0', None,
-"Cannot use a new backing file with a 
different AioContext")
+self.run_test_iothreads('iothread0', None)
 
 def test_iothreads_switch_overlay(self):
-self.run_test_iothreads(None, 'iothread0',
-"Cannot use a new backing file with a 
different AioContext")
+self.run_test_iothreads(None, 'iothread0')
 
 if __name__ == '__main__':
 iotests.main(supported_fmts=["qcow2"],
-- 
2.20.1




[PULL 20/29] stubs: Update monitor stubs for qemu-storage-daemon

2020-03-06 Thread Kevin Wolf
Before we can add the monitor to qemu-storage-daemon, we need to add a
stubs for monitor_fdsets_cleanup().

We also need to make sure that stubs that are actually implemented in
the monitor core aren't linked to qemu-storage-daemon so that we don't
get linker errors because of duplicate symbols. This is achieved by
moving the stubs in question to a new file stubs/monitor-core.c.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-15-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 stubs/monitor-core.c | 21 +
 stubs/monitor.c  | 15 ++-
 stubs/Makefile.objs  |  1 +
 3 files changed, 24 insertions(+), 13 deletions(-)
 create mode 100644 stubs/monitor-core.c

diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c
new file mode 100644
index 00..403c00a6d0
--- /dev/null
+++ b/stubs/monitor-core.c
@@ -0,0 +1,21 @@
+#include "qemu/osdep.h"
+#include "monitor/monitor.h"
+#include "qemu-common.h"
+#include "qapi/qapi-emit-events.h"
+
+__thread Monitor *cur_mon;
+
+void monitor_init_qmp(Chardev *chr, bool pretty)
+{
+}
+
+void qapi_event_emit(QAPIEvent event, QDict *qdict)
+{
+}
+
+int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
+{
+abort();
+}
+
+
diff --git a/stubs/monitor.c b/stubs/monitor.c
index c3e9a2e4dc..9403f8e72c 100644
--- a/stubs/monitor.c
+++ b/stubs/monitor.c
@@ -1,14 +1,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "qapi/qapi-emit-events.h"
 #include "monitor/monitor.h"
-
-__thread Monitor *cur_mon;
-
-int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
-{
-abort();
-}
+#include "../monitor/monitor-internal.h"
 
 int monitor_get_fd(Monitor *mon, const char *name, Error **errp)
 {
@@ -16,14 +9,10 @@ int monitor_get_fd(Monitor *mon, const char *name, Error 
**errp)
 return -1;
 }
 
-void monitor_init_qmp(Chardev *chr, bool pretty)
-{
-}
-
 void monitor_init_hmp(Chardev *chr, bool use_readline)
 {
 }
 
-void qapi_event_emit(QAPIEvent event, QDict *qdict)
+void monitor_fdsets_cleanup(void)
 {
 }
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 24062ce7d9..45be5dc0ed 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -19,6 +19,7 @@ stub-obj-y += machine-init-done.o
 stub-obj-y += migr-blocker.o
 stub-obj-y += change-state-handler.o
 stub-obj-y += monitor.o
+stub-obj-y += monitor-core.o
 stub-obj-y += notify-event.o
 stub-obj-y += qtest.o
 stub-obj-y += replay.o
-- 
2.20.1




[PULL 18/29] qemu-storage-daemon: Add main loop

2020-03-06 Thread Kevin Wolf
Instead of exiting after processing all command line options, start a
main loop and keep processing events until exit is requested with a
signal (e.g. SIGINT).

Now qemu-storage-daemon can be used as an alternative for qemu-nbd that
provides a few features that were previously only available from QMP,
such as access to options only available with -blockdev and the socket
types 'vsock' and 'fd'.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-13-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qemu-storage-daemon.c | 13 +
 Makefile.objs |  2 ++
 2 files changed, 15 insertions(+)

diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
index 5904d3c5b4..14093ac3a0 100644
--- a/qemu-storage-daemon.c
+++ b/qemu-storage-daemon.c
@@ -50,8 +50,16 @@
 #include "qemu/option.h"
 #include "qom/object_interfaces.h"
 
+#include "sysemu/runstate.h"
 #include "trace/control.h"
 
+static volatile bool exit_requested = false;
+
+void qemu_system_killed(int signal, pid_t pid)
+{
+exit_requested = true;
+}
+
 static void help(void)
 {
 printf(
@@ -241,6 +249,7 @@ int main(int argc, char *argv[])
 
 error_init(argv[0]);
 qemu_init_exec_dir(argv[0]);
+os_setup_signal_handling();
 
 module_call_init(MODULE_INIT_QOM);
 module_call_init(MODULE_INIT_TRACE);
@@ -256,5 +265,9 @@ int main(int argc, char *argv[])
 qemu_init_main_loop(&error_fatal);
 process_options(argc, argv);
 
+while (!exit_requested) {
+main_loop_wait(false);
+}
+
 return EXIT_SUCCESS;
 }
diff --git a/Makefile.objs b/Makefile.objs
index bacbdb55bc..2554e331d5 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -33,6 +33,8 @@ endif # CONFIG_SOFTMMU or CONFIG_TOOLS
 
 storage-daemon-obj-y = block/ qom/
 storage-daemon-obj-y += blockdev.o blockdev-nbd.o iothread.o
+storage-daemon-obj-$(CONFIG_WIN32) += os-win32.o
+storage-daemon-obj-$(CONFIG_POSIX) += os-posix.o
 
 ##
 # Target independent part of system emulation. The long term path is to
-- 
2.20.1




[PULL 19/29] qemu-storage-daemon: Add --chardev option

2020-03-06 Thread Kevin Wolf
This adds a --chardev option to the storage daemon that works the same
as the -chardev option of the system emulator.

The syntax of the --chardev option is still considered unstable. We want
to QAPIfy it and will potentially make changes to its syntax while
converting it. However, we haven't decided yet on a design for the
QAPIfication, so QemuOpts will have to do for now.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-14-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qemu-storage-daemon.c | 24 
 Makefile  |  2 +-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
index 14093ac3a0..82fe6cd5f2 100644
--- a/qemu-storage-daemon.c
+++ b/qemu-storage-daemon.c
@@ -29,6 +29,7 @@
 
 #include "block/block.h"
 #include "block/nbd.h"
+#include "chardev/char.h"
 #include "crypto/init.h"
 
 #include "qapi/error.h"
@@ -78,6 +79,9 @@ static void help(void)
 " [,driver specific parameters...]\n"
 " configure a block backend\n"
 "\n"
+"  --chardev configure a character device backend\n"
+" (see the qemu(1) man page for possible options)\n"
+"\n"
 "  --export [type=]nbd,device=[,name=]\n"
 "   [,writable=on|off][,bitmap=]\n"
 " export the specified block node over NBD\n"
@@ -104,11 +108,14 @@ QEMU_HELP_BOTTOM "\n",
 
 enum {
 OPTION_BLOCKDEV = 256,
+OPTION_CHARDEV,
 OPTION_EXPORT,
 OPTION_NBD_SERVER,
 OPTION_OBJECT,
 };
 
+extern QemuOptsList qemu_chardev_opts;
+
 static QemuOptsList qemu_object_opts = {
 .name = "object",
 .implied_opt_name = "qom-type",
@@ -135,6 +142,7 @@ static void process_options(int argc, char *argv[])
 
 static const struct option long_options[] = {
 {"blockdev", required_argument, NULL, OPTION_BLOCKDEV},
+{"chardev", required_argument, NULL, OPTION_CHARDEV},
 {"export", required_argument, NULL, OPTION_EXPORT},
 {"help", no_argument, NULL, 'h'},
 {"nbd-server", required_argument, NULL, OPTION_NBD_SERVER},
@@ -182,6 +190,22 @@ static void process_options(int argc, char *argv[])
 qapi_free_BlockdevOptions(options);
 break;
 }
+case OPTION_CHARDEV:
+{
+/* TODO This interface is not stable until we QAPIfy it */
+QemuOpts *opts = qemu_opts_parse_noisily(&qemu_chardev_opts,
+ optarg, true);
+if (opts == NULL) {
+exit(EXIT_FAILURE);
+}
+
+if (!qemu_chr_new_from_opts(opts, NULL, &error_fatal)) {
+/* No error, but NULL returned means help was printed */
+exit(EXIT_SUCCESS);
+}
+qemu_opts_del(opts);
+break;
+}
 case OPTION_EXPORT:
 {
 Visitor *v;
diff --git a/Makefile b/Makefile
index 7c75440182..05a74c77b2 100644
--- a/Makefile
+++ b/Makefile
@@ -589,7 +589,7 @@ qemu-img.o: qemu-img-cmds.h
 qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) 
$(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
 qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) 
$(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
 qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) 
$(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
-qemu-storage-daemon$(EXESUF): qemu-storage-daemon.o $(authz-obj-y) 
$(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(storage-daemon-obj-y) 
$(COMMON_LDADDS)
+qemu-storage-daemon$(EXESUF): qemu-storage-daemon.o $(authz-obj-y) 
$(block-obj-y) $(crypto-obj-y) $(chardev-obj-y) $(io-obj-y) $(qom-obj-y) 
$(storage-daemon-obj-y) $(COMMON_LDADDS)
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS)
 
-- 
2.20.1




[PULL 12/29] qemu-storage-daemon: Add --blockdev option

2020-03-06 Thread Kevin Wolf
This adds a --blockdev option to the storage daemon that works the same
as the -blockdev option of the system emulator.

In order to be able to link with blockdev.o, we also need to change
stream.o from common-obj to block-obj, which is where all other block
jobs already are.

In contrast to the system emulator, qemu-storage-daemon options will be
processed in the order they are given. The user needs to take care to
refer to other objects only after defining them.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-7-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qemu-storage-daemon.c | 31 +++
 Makefile  |  5 -
 Makefile.objs |  7 +++
 block/Makefile.objs   |  2 +-
 4 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
index fc4aef572b..c30caaf59e 100644
--- a/qemu-storage-daemon.c
+++ b/qemu-storage-daemon.c
@@ -31,6 +31,10 @@
 #include "crypto/init.h"
 
 #include "qapi/error.h"
+#include "qapi/qapi-visit-block-core.h"
+#include "qapi/qapi-commands-block-core.h"
+#include "qapi/qobject-input-visitor.h"
+
 #include "qemu-common.h"
 #include "qemu-version.h"
 #include "qemu/config-file.h"
@@ -52,15 +56,27 @@ static void help(void)
 " specify tracing options\n"
 "  -V, --version  output version information and exit\n"
 "\n"
+"  --blockdev [driver=][,node-name=][,discard=ignore|unmap]\n"
+" [,cache.direct=on|off][,cache.no-flush=on|off]\n"
+" [,read-only=on|off][,auto-read-only=on|off]\n"
+" [,force-share=on|off][,detect-zeroes=on|off|unmap]\n"
+" [,driver specific parameters...]\n"
+" configure a block backend\n"
+"\n"
 QEMU_HELP_BOTTOM "\n",
 error_get_progname());
 }
 
+enum {
+OPTION_BLOCKDEV = 256,
+};
+
 static void process_options(int argc, char *argv[])
 {
 int c;
 
 static const struct option long_options[] = {
+{"blockdev", required_argument, NULL, OPTION_BLOCKDEV},
 {"help", no_argument, NULL, 'h'},
 {"trace", required_argument, NULL, 'T'},
 {"version", no_argument, NULL, 'V'},
@@ -90,6 +106,21 @@ static void process_options(int argc, char *argv[])
 printf("qemu-storage-daemon version "
QEMU_FULL_VERSION "\n" QEMU_COPYRIGHT "\n");
 exit(EXIT_SUCCESS);
+case OPTION_BLOCKDEV:
+{
+Visitor *v;
+BlockdevOptions *options;
+
+v = qobject_input_visitor_new_str(optarg, "driver",
+  &error_fatal);
+
+visit_type_BlockdevOptions(v, NULL, &options, &error_fatal);
+visit_free(v);
+
+qmp_blockdev_add(options, &error_fatal);
+qapi_free_BlockdevOptions(options);
+break;
+}
 default:
 g_assert_not_reached();
 }
diff --git a/Makefile b/Makefile
index 2bf59d4f42..7c75440182 100644
--- a/Makefile
+++ b/Makefile
@@ -450,6 +450,8 @@ dummy := $(call unnest-vars,, \
 qga-vss-dll-obj-y \
 block-obj-y \
 block-obj-m \
+storage-daemon-obj-y \
+storage-daemon-obj-m \
 crypto-obj-y \
 qom-obj-y \
 io-obj-y \
@@ -482,6 +484,7 @@ TARGET_DIRS_RULES := $(foreach t, all fuzz clean install, 
$(addsuffix /$(t), $(T
 SOFTMMU_ALL_RULES=$(filter %-softmmu/all, $(TARGET_DIRS_RULES))
 $(SOFTMMU_ALL_RULES): $(authz-obj-y)
 $(SOFTMMU_ALL_RULES): $(block-obj-y)
+$(SOFTMMU_ALL_RULES): $(storage-daemon-obj-y)
 $(SOFTMMU_ALL_RULES): $(chardev-obj-y)
 $(SOFTMMU_ALL_RULES): $(crypto-obj-y)
 $(SOFTMMU_ALL_RULES): $(io-obj-y)
@@ -586,7 +589,7 @@ qemu-img.o: qemu-img-cmds.h
 qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) 
$(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
 qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) 
$(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
 qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) 
$(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
-qemu-storage-daemon$(EXESUF): qemu-storage-daemon.o $(authz-obj-y) 
$(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
+qemu-storage-daemon$(EXESUF): qemu-storage-daemon.o $(authz-obj-y) 
$(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(storage-daemon-obj-y) 
$(COMMON_LDADDS)
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS)
 
diff --git a/Makefile.objs b/Makefile.objs
index 8a1cbe8000..3db3a7db6e 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -27,6 +27,13 @@ io-obj-y = io/
 
 endif # CONFIG_SOFTMMU or CONFIG_TOOLS
 
+###
+# storage-daemon-obj-y is code used by qemu-storage-daemon (these objects are
+# used for

[PULL 28/29] iotests: Refactor blockdev-reopen test for iothreads

2020-03-06 Thread Kevin Wolf
We'll want to test more than one successful case in the future, so
prepare the test for that by a refactoring that runs each scenario in a
separate VM.

test_iothreads_switch_{backing,overlay} currently produce errors, but
these are cases that should actually work, by switching either the
backing file node or the overlay node to the AioContext of the other
node.

Signed-off-by: Kevin Wolf 
Tested-by: Peter Krempa 
Message-Id: <20200306141413.30705-2-kw...@redhat.com>
Signed-off-by: Kevin Wolf 
---
 tests/qemu-iotests/245 | 47 ++
 tests/qemu-iotests/245.out |  4 ++--
 2 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245
index 489bf78bd0..7d9eb6285c 100755
--- a/tests/qemu-iotests/245
+++ b/tests/qemu-iotests/245
@@ -970,8 +970,7 @@ class TestBlockdevReopen(iotests.QMPTestCase):
 self.assertEqual(self.get_node('hd1'), None)
 self.assert_qmp(self.get_node('hd2'), 'ro', True)
 
-# We don't allow setting a backing file that uses a different AioContext
-def test_iothreads(self):
+def run_test_iothreads(self, iothread_a, iothread_b, errmsg = None):
 opts = hd_opts(0)
 result = self.vm.qmp('blockdev-add', conv_keys = False, **opts)
 self.assert_qmp(result, 'return', {})
@@ -986,20 +985,48 @@ class TestBlockdevReopen(iotests.QMPTestCase):
 result = self.vm.qmp('object-add', qom_type='iothread', id='iothread1')
 self.assert_qmp(result, 'return', {})
 
-result = self.vm.qmp('x-blockdev-set-iothread', node_name='hd0', 
iothread='iothread0')
+result = self.vm.qmp('device_add', driver='virtio-scsi', id='scsi0',
+ iothread=iothread_a)
 self.assert_qmp(result, 'return', {})
 
-self.reopen(opts, {'backing': 'hd2'}, "Cannot use a new backing file 
with a different AioContext")
-
-result = self.vm.qmp('x-blockdev-set-iothread', node_name='hd2', 
iothread='iothread1')
+result = self.vm.qmp('device_add', driver='virtio-scsi', id='scsi1',
+ iothread=iothread_b)
 self.assert_qmp(result, 'return', {})
 
-self.reopen(opts, {'backing': 'hd2'}, "Cannot use a new backing file 
with a different AioContext")
+if iothread_a:
+result = self.vm.qmp('device_add', driver='scsi-hd', drive='hd0',
+ share_rw=True, bus="scsi0.0")
+self.assert_qmp(result, 'return', {})
 
-result = self.vm.qmp('x-blockdev-set-iothread', node_name='hd2', 
iothread='iothread0')
-self.assert_qmp(result, 'return', {})
+if iothread_b:
+result = self.vm.qmp('device_add', driver='scsi-hd', drive='hd2',
+ share_rw=True, bus="scsi1.0")
+self.assert_qmp(result, 'return', {})
 
-self.reopen(opts, {'backing': 'hd2'})
+# Attaching the backing file may or may not work
+self.reopen(opts, {'backing': 'hd2'}, errmsg)
+
+# But removing the backing file should always work
+self.reopen(opts, {'backing': None})
+
+self.vm.shutdown()
+
+# We don't allow setting a backing file that uses a different AioContext if
+# neither of them can switch to the other AioContext
+def test_iothreads_error(self):
+self.run_test_iothreads('iothread0', 'iothread1',
+"Cannot use a new backing file with a 
different AioContext")
+
+def test_iothreads_compatible_users(self):
+self.run_test_iothreads('iothread0', 'iothread0')
+
+def test_iothreads_switch_backing(self):
+self.run_test_iothreads('iothread0', None,
+"Cannot use a new backing file with a 
different AioContext")
+
+def test_iothreads_switch_overlay(self):
+self.run_test_iothreads(None, 'iothread0',
+"Cannot use a new backing file with a 
different AioContext")
 
 if __name__ == '__main__':
 iotests.main(supported_fmts=["qcow2"],
diff --git a/tests/qemu-iotests/245.out b/tests/qemu-iotests/245.out
index a19de5214d..682b93394d 100644
--- a/tests/qemu-iotests/245.out
+++ b/tests/qemu-iotests/245.out
@@ -1,6 +1,6 @@
-..
+.
 --
-Ran 18 tests
+Ran 21 tests
 
 OK
 {"execute": "job-finalize", "arguments": {"id": "commit0"}}
-- 
2.20.1




[PULL 06/29] block/qcow2: Move bitmap reopen into bdrv_reopen_commit_post

2020-03-06 Thread Kevin Wolf
From: Peter Krempa 

The bitmap code requires writing the 'file' child when the qcow2 driver
is reopened in read-write mode.

If the 'file' child is being reopened due to a permissions change, the
modification is commited yet when qcow2_reopen_commit is called. This
means that any attempt to write the 'file' child will end with EBADFD
as the original fd was already closed.

Moving bitmap reopening to the new callback which is called after
permission modifications are commited fixes this as the file descriptor
will be replaced with the correct one.

The above problem manifests itself when reopening 'qcow2' format layer
which uses a 'file-posix' file child which was opened with the
'auto-read-only' property set.

Signed-off-by: Peter Krempa 
Message-Id: 

Signed-off-by: Kevin Wolf 
---
 block/qcow2.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index 3c754f616b..3640e8c07d 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1884,6 +1884,11 @@ fail:
 static void qcow2_reopen_commit(BDRVReopenState *state)
 {
 qcow2_update_options_commit(state->bs, state->opaque);
+g_free(state->opaque);
+}
+
+static void qcow2_reopen_commit_post(BDRVReopenState *state)
+{
 if (state->flags & BDRV_O_RDWR) {
 Error *local_err = NULL;
 
@@ -1898,7 +1903,6 @@ static void qcow2_reopen_commit(BDRVReopenState *state)
   bdrv_get_node_name(state->bs));
 }
 }
-g_free(state->opaque);
 }
 
 static void qcow2_reopen_abort(BDRVReopenState *state)
@@ -5534,6 +5538,7 @@ BlockDriver bdrv_qcow2 = {
 .bdrv_close = qcow2_close,
 .bdrv_reopen_prepare  = qcow2_reopen_prepare,
 .bdrv_reopen_commit   = qcow2_reopen_commit,
+.bdrv_reopen_commit_post = qcow2_reopen_commit_post,
 .bdrv_reopen_abort= qcow2_reopen_abort,
 .bdrv_join_options= qcow2_join_options,
 .bdrv_child_perm  = bdrv_format_default_perms,
-- 
2.20.1




[PULL 13/29] qapi: Flatten object-add

2020-03-06 Thread Kevin Wolf
Mapping object-add to the command line as is doesn't result in nice
syntax because of the nesting introduced with 'props'. This becomes
nicer and more consistent with device_add and netdev_add when we accept
properties for the object on the top level instead.

'props' is still accepted after this patch, but marked as deprecated.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-8-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qapi/qom.json   | 12 +++---
 docs/system/deprecated.rst  |  5 
 include/qom/object_interfaces.h |  7 ++
 hw/block/xen-block.c| 11 -
 monitor/misc.c  |  2 ++
 qom/qom-qmp-cmds.c  | 42 +++--
 6 files changed, 68 insertions(+), 11 deletions(-)

diff --git a/qapi/qom.json b/qapi/qom.json
index ecc60c4401..8abe998962 100644
--- a/qapi/qom.json
+++ b/qapi/qom.json
@@ -210,7 +210,12 @@
 #
 # @id: the name of the new object
 #
-# @props: a dictionary of properties to be passed to the backend
+# @props: a dictionary of properties to be passed to the backend. Deprecated
+# since 5.0, specify the properties on the top level instead. It is an
+# error to specify the same option both on the top level and in @props.
+#
+# Additional arguments depend on qom-type and are passed to the backend
+# unchanged.
 #
 # Returns: Nothing on success
 #  Error if @qom-type is not a valid class name
@@ -221,12 +226,13 @@
 #
 # -> { "execute": "object-add",
 #  "arguments": { "qom-type": "rng-random", "id": "rng1",
-# "props": { "filename": "/dev/hwrng" } } }
+# "filename": "/dev/hwrng" } }
 # <- { "return": {} }
 #
 ##
 { 'command': 'object-add',
-  'data': {'qom-type': 'str', 'id': 'str', '*props': 'any'} }
+  'data': {'qom-type': 'str', 'id': 'str', '*props': 'any'},
+  'gen': false } # so we can get the additional arguments
 
 ##
 # @object-del:
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 1eaa559079..6c1d9034d9 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -190,6 +190,11 @@ Use ``migrate-set-parameters`` instead.
 
 Use ``migrate-set-parameters`` and ``query-migrate-parameters`` instead.
 
+``object-add`` option ``props`` (since 5.0)
+'''
+
+Specify the properties for the object as top-level arguments instead.
+
 ``query-block`` result field ``dirty-bitmaps[i].status`` (since 4.0)
 
 
diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
index 3e4e1d928b..6f92f3cebb 100644
--- a/include/qom/object_interfaces.h
+++ b/include/qom/object_interfaces.h
@@ -162,4 +162,11 @@ void user_creatable_del(const char *id, Error **errp);
  */
 void user_creatable_cleanup(void);
 
+/**
+ * qmp_object_add:
+ *
+ * QMP command handler for object-add. See the QAPI schema for documentation.
+ */
+void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp);
+
 #endif
diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
index 686bbc3f0d..3885464513 100644
--- a/hw/block/xen-block.c
+++ b/hw/block/xen-block.c
@@ -18,6 +18,7 @@
 #include "qapi/visitor.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
+#include "qom/object_interfaces.h"
 #include "hw/xen/xen_common.h"
 #include "hw/block/xen_blkif.h"
 #include "hw/qdev-properties.h"
@@ -858,10 +859,18 @@ static XenBlockIOThread *xen_block_iothread_create(const 
char *id,
 {
 XenBlockIOThread *iothread = g_new(XenBlockIOThread, 1);
 Error *local_err = NULL;
+QDict *opts;
+QObject *ret_data;
 
 iothread->id = g_strdup(id);
 
-qmp_object_add(TYPE_IOTHREAD, id, false, NULL, &local_err);
+opts = qdict_new();
+qdict_put_str(opts, "qom-type", TYPE_IOTHREAD);
+qdict_put_str(opts, "id", id);
+qmp_object_add(opts, &ret_data, &local_err);
+qobject_unref(opts);
+qobject_unref(ret_data);
+
 if (local_err) {
 error_propagate(errp, local_err);
 
diff --git a/monitor/misc.c b/monitor/misc.c
index 6c41293102..1748ab3911 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -248,6 +248,8 @@ static void monitor_init_qmp_commands(void)
  QCO_NO_OPTIONS);
 qmp_register_command(&qmp_commands, "netdev_add", qmp_netdev_add,
  QCO_NO_OPTIONS);
+qmp_register_command(&qmp_commands, "object-add", qmp_object_add,
+ QCO_NO_OPTIONS);
 
 QTAILQ_INIT(&qmp_cap_negotiation_commands);
 qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",
diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c
index 6136efec16..49db926fcc 100644
--- a/qom/qom-qmp-cmds.c
+++ b/qom/qom-qmp-cmds.c
@@ -14,6 +14,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "block/qdict.h"
 #include "hw/qdev-core.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-

[PULL 21/29] qapi: Create 'pragma' module

2020-03-06 Thread Kevin Wolf
We want to share the whitelists between the system emulator schema and
the storage daemon schema, so move all the pragmas from the main schema
file into a separate file that can be included from both.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-16-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qapi/pragma.json  | 24 
 qapi/qapi-schema.json | 25 +
 qapi/Makefile.objs|  2 +-
 3 files changed, 26 insertions(+), 25 deletions(-)
 create mode 100644 qapi/pragma.json

diff --git a/qapi/pragma.json b/qapi/pragma.json
new file mode 100644
index 00..cffae27666
--- /dev/null
+++ b/qapi/pragma.json
@@ -0,0 +1,24 @@
+{ 'pragma': { 'doc-required': true } }
+
+# Whitelists to permit QAPI rule violations; think twice before you
+# add to them!
+{ 'pragma': {
+# Commands allowed to return a non-dictionary:
+'returns-whitelist': [
+'human-monitor-command',
+'qom-get',
+'query-migrate-cache-size',
+'query-tpm-models',
+'query-tpm-types',
+'ringbuf-read' ],
+'name-case-whitelist': [
+'ACPISlotType', # DIMM, visible through 
query-acpi-ospm-status
+'CpuInfoMIPS',  # PC, visible through query-cpu
+'CpuInfoTricore',   # PC, visible through query-cpu
+'BlockdevVmdkSubformat',# all members, to match VMDK spec spellings
+'BlockdevVmdkAdapterType',  # legacyESX, to match VMDK spec spellings
+'QapiErrorClass',   # all members, visible through errors
+'UuidInfo', # UUID, visible through query-uuid
+'X86CPURegister32', # all members, visible indirectly through 
qom-get
+'CpuInfo'   # CPU, visible through query-cpu
+] } }
diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json
index fe980ce437..43b0ba0dea 100644
--- a/qapi/qapi-schema.json
+++ b/qapi/qapi-schema.json
@@ -49,30 +49,7 @@
 #
 ##
 
-{ 'pragma': { 'doc-required': true } }
-
-# Whitelists to permit QAPI rule violations; think twice before you
-# add to them!
-{ 'pragma': {
-# Commands allowed to return a non-dictionary:
-'returns-whitelist': [
-'human-monitor-command',
-'qom-get',
-'query-migrate-cache-size',
-'query-tpm-models',
-'query-tpm-types',
-'ringbuf-read' ],
-'name-case-whitelist': [
-'ACPISlotType', # DIMM, visible through 
query-acpi-ospm-status
-'CpuInfoMIPS',  # PC, visible through query-cpu
-'CpuInfoTricore',   # PC, visible through query-cpu
-'BlockdevVmdkSubformat',# all members, to match VMDK spec spellings
-'BlockdevVmdkAdapterType',  # legacyESX, to match VMDK spec spellings
-'QapiErrorClass',   # all members, visible through errors
-'UuidInfo', # UUID, visible through query-uuid
-'X86CPURegister32', # all members, visible indirectly through 
qom-get
-'CpuInfo'   # CPU, visible through query-cpu
-] } }
+{ 'include': 'pragma.json' }
 
 # Documentation generated with qapi-gen.py is in source order, with
 # included sub-schemas inserted at the first include directive
diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs
index 20fcc37c2c..cf33fd9cc0 100644
--- a/qapi/Makefile.objs
+++ b/qapi/Makefile.objs
@@ -7,7 +7,7 @@ util-obj-y += qapi-util.o
 
 QAPI_COMMON_MODULES = audio authz block-core block char common control crypto
 QAPI_COMMON_MODULES += dump error introspect job machine migration misc
-QAPI_COMMON_MODULES += net qdev qom rdma rocker run-state sockets tpm
+QAPI_COMMON_MODULES += net pragma qdev qom rdma rocker run-state sockets tpm
 QAPI_COMMON_MODULES += trace transaction ui
 QAPI_TARGET_MODULES = machine-target misc-target
 QAPI_MODULES = $(QAPI_COMMON_MODULES) $(QAPI_TARGET_MODULES)
-- 
2.20.1




[PULL 10/29] block: Move common QMP commands to block-core QAPI module

2020-03-06 Thread Kevin Wolf
block-core is for everything that isn't related to the system emulator.
Internal snapshots, the NBD server and quorum events make sense in the
tools, too, so move them to block-core.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-5-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qapi/block-core.json | 283 ++
 qapi/block.json  | 284 ---
 2 files changed, 283 insertions(+), 284 deletions(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index 85e27bb61f..60860ead68 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -5447,3 +5447,286 @@
   'data' : { 'node-name': 'str',
  'iothread': 'StrOrNull',
  '*force': 'bool' } }
+
+##
+# @nbd-server-start:
+#
+# Start an NBD server listening on the given host and port.  Block
+# devices can then be exported using @nbd-server-add.  The NBD
+# server will present them as named exports; for example, another
+# QEMU instance could refer to them as "nbd:HOST:PORT:exportname=NAME".
+#
+# @addr: Address on which to listen.
+# @tls-creds: ID of the TLS credentials object (since 2.6).
+# @tls-authz: ID of the QAuthZ authorization object used to validate
+# the client's x509 distinguished name. This object is
+# is only resolved at time of use, so can be deleted and
+# recreated on the fly while the NBD server is active.
+# If missing, it will default to denying access (since 4.0).
+#
+# Returns: error if the server is already running.
+#
+# Since: 1.3.0
+##
+{ 'command': 'nbd-server-start',
+  'data': { 'addr': 'SocketAddressLegacy',
+'*tls-creds': 'str',
+'*tls-authz': 'str'} }
+
+##
+# @nbd-server-add:
+#
+# Export a block node to QEMU's embedded NBD server.
+#
+# @device: The device name or node name of the node to be exported
+#
+# @name: Export name. If unspecified, the @device parameter is used as the
+#export name. (Since 2.12)
+#
+# @description: Free-form description of the export, up to 4096 bytes.
+#   (Since 5.0)
+#
+# @writable: Whether clients should be able to write to the device via the
+#NBD connection (default false).
+#
+# @bitmap: Also export the dirty bitmap reachable from @device, so the
+#  NBD client can use NBD_OPT_SET_META_CONTEXT with
+#  "qemu:dirty-bitmap:NAME" to inspect the bitmap. (since 4.0)
+#
+# Returns: error if the server is not running, or export with the same name
+#  already exists.
+#
+# Since: 1.3.0
+##
+{ 'command': 'nbd-server-add',
+  'data': {'device': 'str', '*name': 'str', '*description': 'str',
+   '*writable': 'bool', '*bitmap': 'str' } }
+
+##
+# @NbdServerRemoveMode:
+#
+# Mode for removing an NBD export.
+#
+# @safe: Remove export if there are no existing connections, fail otherwise.
+#
+# @hard: Drop all connections immediately and remove export.
+#
+# Potential additional modes to be added in the future:
+#
+# hide: Just hide export from new clients, leave existing connections as is.
+# Remove export after all clients are disconnected.
+#
+# soft: Hide export from new clients, answer with ESHUTDOWN for all further
+# requests from existing clients.
+#
+# Since: 2.12
+##
+{'enum': 'NbdServerRemoveMode', 'data': ['safe', 'hard']}
+
+##
+# @nbd-server-remove:
+#
+# Remove NBD export by name.
+#
+# @name: Export name.
+#
+# @mode: Mode of command operation. See @NbdServerRemoveMode description.
+#Default is 'safe'.
+#
+# Returns: error if
+#- the server is not running
+#- export is not found
+#- mode is 'safe' and there are existing connections
+#
+# Since: 2.12
+##
+{ 'command': 'nbd-server-remove',
+  'data': {'name': 'str', '*mode': 'NbdServerRemoveMode'} }
+
+##
+# @nbd-server-stop:
+#
+# Stop QEMU's embedded NBD server, and unregister all devices previously
+# added via @nbd-server-add.
+#
+# Since: 1.3.0
+##
+{ 'command': 'nbd-server-stop' }
+
+##
+# @QuorumOpType:
+#
+# An enumeration of the quorum operation types
+#
+# @read: read operation
+#
+# @write: write operation
+#
+# @flush: flush operation
+#
+# Since: 2.6
+##
+{ 'enum': 'QuorumOpType',
+  'data': [ 'read', 'write', 'flush' ] }
+
+##
+# @QUORUM_FAILURE:
+#
+# Emitted by the Quorum block driver if it fails to establish a quorum
+#
+# @reference: device name if defined else node name
+#
+# @sector-num: number of the first sector of the failed read operation
+#
+# @sectors-count: failed read operation sector count
+#
+# Note: This event is rate-limited.
+#
+# Since: 2.0
+#
+# Example:
+#
+# <- { "event": "QUORUM_FAILURE",
+#  "data": { "reference": "usr1", "sector-num": 345435, "sectors-count": 5 
},
+#  "timestamp": { "seconds": 1344522075, "microseconds": 745528 } }
+#
+##
+{ 'event': 'QUORUM_FAILURE',
+  'data': { 'reference': 'str', 'sector-num': 'int', 'sectors-count': 'int' } }
+
+##
+# @QUORUM_REPOR

[PULL 15/29] qemu-storage-daemon: Add --nbd-server option

2020-03-06 Thread Kevin Wolf
Add a --nbd-server option to qemu-storage-daemon to start the built-in
NBD server right away. It maps the arguments for nbd-server-start to the
command line, with the exception that it uses SocketAddress instead of
SocketAddressLegacy: New interfaces shouldn't use legacy types, and the
additional nesting would be nasty on the command line.

Example (only with required options):

--nbd-server addr.type=inet,addr.host=localhost,addr.port=10809

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-10-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qapi/block-core.json  | 24 
 include/block/nbd.h   |  1 +
 blockdev-nbd.c|  5 +
 qemu-storage-daemon.c | 26 +-
 Makefile.objs |  2 +-
 5 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index b65b6a9f49..ff06c8 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -5062,6 +5062,27 @@
  'iothread': 'StrOrNull',
  '*force': 'bool' } }
 
+##
+# @NbdServerOptions:
+#
+# @addr: Address on which to listen.
+# @tls-creds: ID of the TLS credentials object (since 2.6).
+# @tls-authz: ID of the QAuthZ authorization object used to validate
+# the client's x509 distinguished name. This object is
+# is only resolved at time of use, so can be deleted and
+# recreated on the fly while the NBD server is active.
+# If missing, it will default to denying access (since 4.0).
+#
+# Keep this type consistent with the nbd-server-start arguments. The only
+# intended difference is using SocketAddress instead of SocketAddressLegacy.
+#
+# Since: 4.2
+##
+{ 'struct': 'NbdServerOptions',
+  'data': { 'addr': 'SocketAddress',
+'*tls-creds': 'str',
+'*tls-authz': 'str'} }
+
 ##
 # @nbd-server-start:
 #
@@ -5080,6 +5101,9 @@
 #
 # Returns: error if the server is already running.
 #
+# Keep this type consistent with the NbdServerOptions type. The only intended
+# difference is using SocketAddressLegacy instead of SocketAddress.
+#
 # Since: 1.3.0
 ##
 { 'command': 'nbd-server-start',
diff --git a/include/block/nbd.h b/include/block/nbd.h
index 7f46932d80..20363280ae 100644
--- a/include/block/nbd.h
+++ b/include/block/nbd.h
@@ -353,6 +353,7 @@ void nbd_client_put(NBDClient *client);
 
 void nbd_server_start(SocketAddress *addr, const char *tls_creds,
   const char *tls_authz, Error **errp);
+void nbd_server_start_options(NbdServerOptions *arg, Error **errp);
 
 /* nbd_read
  * Reads @size bytes from @ioc. Returns 0 on success.
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index de2f2ff713..d8c892f7da 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -132,6 +132,11 @@ void nbd_server_start(SocketAddress *addr, const char 
*tls_creds,
 nbd_server = NULL;
 }
 
+void nbd_server_start_options(NbdServerOptions *arg, Error **errp)
+{
+nbd_server_start(arg->addr, arg->tls_creds, arg->tls_authz, errp);
+}
+
 void qmp_nbd_server_start(SocketAddressLegacy *addr,
   bool has_tls_creds, const char *tls_creds,
   bool has_tls_authz, const char *tls_authz,
diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
index 0cd8144c81..276a412915 100644
--- a/qemu-storage-daemon.c
+++ b/qemu-storage-daemon.c
@@ -28,11 +28,14 @@
 #include 
 
 #include "block/block.h"
+#include "block/nbd.h"
 #include "crypto/init.h"
 
 #include "qapi/error.h"
-#include "qapi/qapi-visit-block-core.h"
+#include "qapi/qapi-commands-block.h"
 #include "qapi/qapi-commands-block-core.h"
+#include "qapi/qapi-visit-block.h"
+#include "qapi/qapi-visit-block-core.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qobject-input-visitor.h"
 
@@ -67,6 +70,12 @@ static void help(void)
 " [,driver specific parameters...]\n"
 " configure a block backend\n"
 "\n"
+"  --nbd-server addr.type=inet,addr.host=,addr.port=\n"
+"   [,tls-creds=][,tls-authz=]\n"
+"  --nbd-server addr.type=unix,addr.path=\n"
+"   [,tls-creds=][,tls-authz=]\n"
+" start an NBD server for exporting block nodes\n"
+"\n"
 "  --object help  list object types that can be added\n"
 "  --object ,help   list properties for the given object type\n"
 "  --object [,=...]\n"
@@ -82,6 +91,7 @@ QEMU_HELP_BOTTOM "\n",
 
 enum {
 OPTION_BLOCKDEV = 256,
+OPTION_NBD_SERVER,
 OPTION_OBJECT,
 };
 
@@ -101,6 +111,7 @@ static void process_options(int argc, char *argv[])
 static const struct option long_options[] = {
 {"blockdev", required_argument, NULL, OPTION_BLOCKDEV},
 {"help", no_argument, NULL, 'h'},
+{"nbd-server", required_argument, NULL, OPTION_NBD_SERVER},
 {"object", required_argument, NULL, OPTION_OBJECT},
 {"trace", required_argument, NULL, 'T'},
 {"version", no_argument, NULL, 'V'},
@@ -1

[PULL 14/29] qemu-storage-daemon: Add --object option

2020-03-06 Thread Kevin Wolf
Add a command line option to create user-creatable QOM objects.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-9-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qemu-storage-daemon.c | 47 +++
 Makefile.objs |  2 +-
 qom/Makefile.objs |  1 +
 3 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
index c30caaf59e..0cd8144c81 100644
--- a/qemu-storage-daemon.c
+++ b/qemu-storage-daemon.c
@@ -33,15 +33,19 @@
 #include "qapi/error.h"
 #include "qapi/qapi-visit-block-core.h"
 #include "qapi/qapi-commands-block-core.h"
+#include "qapi/qmp/qdict.h"
 #include "qapi/qobject-input-visitor.h"
 
 #include "qemu-common.h"
 #include "qemu-version.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
+#include "qemu/help_option.h"
 #include "qemu/log.h"
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
+#include "qemu/option.h"
+#include "qom/object_interfaces.h"
 
 #include "trace/control.h"
 
@@ -63,12 +67,31 @@ static void help(void)
 " [,driver specific parameters...]\n"
 " configure a block backend\n"
 "\n"
+"  --object help  list object types that can be added\n"
+"  --object ,help   list properties for the given object type\n"
+"  --object [,=...]\n"
+" create a new object of type , setting\n"
+" properties in the order they are specified. Note\n"
+" that the 'id' property must be set.\n"
+" See the qemu(1) man page for documentation of the\n"
+" objects that can be added.\n"
+"\n"
 QEMU_HELP_BOTTOM "\n",
 error_get_progname());
 }
 
 enum {
 OPTION_BLOCKDEV = 256,
+OPTION_OBJECT,
+};
+
+static QemuOptsList qemu_object_opts = {
+.name = "object",
+.implied_opt_name = "qom-type",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
+.desc = {
+{ }
+},
 };
 
 static void process_options(int argc, char *argv[])
@@ -78,6 +101,7 @@ static void process_options(int argc, char *argv[])
 static const struct option long_options[] = {
 {"blockdev", required_argument, NULL, OPTION_BLOCKDEV},
 {"help", no_argument, NULL, 'h'},
+{"object", required_argument, NULL, OPTION_OBJECT},
 {"trace", required_argument, NULL, 'T'},
 {"version", no_argument, NULL, 'V'},
 {0, 0, 0, 0}
@@ -121,6 +145,29 @@ static void process_options(int argc, char *argv[])
 qapi_free_BlockdevOptions(options);
 break;
 }
+case OPTION_OBJECT:
+{
+QemuOpts *opts;
+const char *type;
+QDict *args;
+QObject *ret_data = NULL;
+
+/* FIXME The keyval parser rejects 'help' arguments, so we must
+ * unconditionall try QemuOpts first. */
+opts = qemu_opts_parse(&qemu_object_opts,
+   optarg, true, &error_fatal);
+type = qemu_opt_get(opts, "qom-type");
+if (type && user_creatable_print_help(type, opts)) {
+exit(EXIT_SUCCESS);
+}
+qemu_opts_del(opts);
+
+args = keyval_parse(optarg, "qom-type", &error_fatal);
+qmp_object_add(args, &ret_data, &error_fatal);
+qobject_unref(args);
+qobject_unref(ret_data);
+break;
+}
 default:
 g_assert_not_reached();
 }
diff --git a/Makefile.objs b/Makefile.objs
index 3db3a7db6e..b5d9e1e134 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -31,7 +31,7 @@ endif # CONFIG_SOFTMMU or CONFIG_TOOLS
 # storage-daemon-obj-y is code used by qemu-storage-daemon (these objects are
 # used for system emulation, too, but specified separately there)
 
-storage-daemon-obj-y = block/
+storage-daemon-obj-y = block/ qom/
 storage-daemon-obj-y += blockdev.o iothread.o
 
 ##
diff --git a/qom/Makefile.objs b/qom/Makefile.objs
index f9d77350ac..1b45d104ba 100644
--- a/qom/Makefile.objs
+++ b/qom/Makefile.objs
@@ -2,3 +2,4 @@ qom-obj-y = object.o container.o qom-qobject.o
 qom-obj-y += object_interfaces.o
 
 common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o
+storage-daemon-obj-y += qom-qmp-cmds.o
-- 
2.20.1




[PULL 17/29] qemu-storage-daemon: Add --export option

2020-03-06 Thread Kevin Wolf
Add a --export option to qemu-storage-daemon to export a block node. For
now, only NBD exports are implemented. Apart from the 'type' option
(which is the implied key), it maps the arguments for nbd-server-add to
the command line. Example:

--export nbd,device=disk,name=test-export,writable=on

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-12-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qapi/block-core.json  | 27 +++
 qemu-storage-daemon.c | 31 +++
 2 files changed, 58 insertions(+)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index cdc585385c..48631218fa 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -5201,6 +5201,33 @@
 ##
 { 'command': 'nbd-server-stop' }
 
+##
+# @BlockExportType:
+#
+# An enumeration of block export types
+#
+# @nbd: NBD export
+#
+# Since: 4.2
+##
+{ 'enum': 'BlockExportType',
+  'data': [ 'nbd' ] }
+
+##
+# @BlockExport:
+#
+# Describes a block export, i.e. how single node should be exported on an
+# external interface.
+#
+# Since: 4.2
+##
+{ 'union': 'BlockExport',
+  'base': { 'type': 'BlockExportType' },
+  'discriminator': 'type',
+  'data': {
+  'nbd': 'BlockExportNbd'
+   } }
+
 ##
 # @QuorumOpType:
 #
diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
index 276a412915..5904d3c5b4 100644
--- a/qemu-storage-daemon.c
+++ b/qemu-storage-daemon.c
@@ -70,6 +70,11 @@ static void help(void)
 " [,driver specific parameters...]\n"
 " configure a block backend\n"
 "\n"
+"  --export [type=]nbd,device=[,name=]\n"
+"   [,writable=on|off][,bitmap=]\n"
+" export the specified block node over NBD\n"
+" (requires --nbd-server)\n"
+"\n"
 "  --nbd-server addr.type=inet,addr.host=,addr.port=\n"
 "   [,tls-creds=][,tls-authz=]\n"
 "  --nbd-server addr.type=unix,addr.path=\n"
@@ -91,6 +96,7 @@ QEMU_HELP_BOTTOM "\n",
 
 enum {
 OPTION_BLOCKDEV = 256,
+OPTION_EXPORT,
 OPTION_NBD_SERVER,
 OPTION_OBJECT,
 };
@@ -104,12 +110,24 @@ static QemuOptsList qemu_object_opts = {
 },
 };
 
+static void init_export(BlockExport *export, Error **errp)
+{
+switch (export->type) {
+case BLOCK_EXPORT_TYPE_NBD:
+qmp_nbd_server_add(&export->u.nbd, errp);
+break;
+default:
+g_assert_not_reached();
+}
+}
+
 static void process_options(int argc, char *argv[])
 {
 int c;
 
 static const struct option long_options[] = {
 {"blockdev", required_argument, NULL, OPTION_BLOCKDEV},
+{"export", required_argument, NULL, OPTION_EXPORT},
 {"help", no_argument, NULL, 'h'},
 {"nbd-server", required_argument, NULL, OPTION_NBD_SERVER},
 {"object", required_argument, NULL, OPTION_OBJECT},
@@ -156,6 +174,19 @@ static void process_options(int argc, char *argv[])
 qapi_free_BlockdevOptions(options);
 break;
 }
+case OPTION_EXPORT:
+{
+Visitor *v;
+BlockExport *export;
+
+v = qobject_input_visitor_new_str(optarg, "type", 
&error_fatal);
+visit_type_BlockExport(v, NULL, &export, &error_fatal);
+visit_free(v);
+
+init_export(export, &error_fatal);
+qapi_free_BlockExport(export);
+break;
+}
 case OPTION_NBD_SERVER:
 {
 Visitor *v;
-- 
2.20.1




[PULL 16/29] blockdev-nbd: Boxed argument type for nbd-server-add

2020-03-06 Thread Kevin Wolf
Move the arguments of nbd-server-add to a new struct BlockExportNbd and
convert the command to 'boxed': true. This makes it easier to share code
with the storage daemon.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-11-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 qapi/block-core.json | 18 ++
 blockdev-nbd.c   | 35 ---
 monitor/hmp-cmds.c   | 21 +
 3 files changed, 47 insertions(+), 27 deletions(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index ff06c8..cdc585385c 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -5112,9 +5112,9 @@
 '*tls-authz': 'str'} }
 
 ##
-# @nbd-server-add:
+# @BlockExportNbd:
 #
-# Export a block node to QEMU's embedded NBD server.
+# An NBD block export.
 #
 # @device: The device name or node name of the node to be exported
 #
@@ -5131,14 +5131,24 @@
 #  NBD client can use NBD_OPT_SET_META_CONTEXT with
 #  "qemu:dirty-bitmap:NAME" to inspect the bitmap. (since 4.0)
 #
+# Since: 5.0
+##
+{ 'struct': 'BlockExportNbd',
+  'data': {'device': 'str', '*name': 'str', '*description': 'str',
+   '*writable': 'bool', '*bitmap': 'str' } }
+
+##
+# @nbd-server-add:
+#
+# Export a block node to QEMU's embedded NBD server.
+#
 # Returns: error if the server is not running, or export with the same name
 #  already exists.
 #
 # Since: 1.3.0
 ##
 { 'command': 'nbd-server-add',
-  'data': {'device': 'str', '*name': 'str', '*description': 'str',
-   '*writable': 'bool', '*bitmap': 'str' } }
+  'data': 'BlockExportNbd', 'boxed': true }
 
 ##
 # @NbdServerRemoveMode:
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index d8c892f7da..1a95d89f00 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -148,10 +148,7 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr,
 qapi_free_SocketAddress(addr_flat);
 }
 
-void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
-bool has_description, const char *description,
-bool has_writable, bool writable,
-bool has_bitmap, const char *bitmap, Error **errp)
+void qmp_nbd_server_add(BlockExportNbd *arg, Error **errp)
 {
 BlockDriverState *bs = NULL;
 BlockBackend *on_eject_blk;
@@ -164,28 +161,28 @@ void qmp_nbd_server_add(const char *device, bool 
has_name, const char *name,
 return;
 }
 
-if (!has_name) {
-name = device;
+if (!arg->has_name) {
+arg->name = arg->device;
 }
 
-if (strlen(name) > NBD_MAX_STRING_SIZE) {
-error_setg(errp, "export name '%s' too long", name);
+if (strlen(arg->name) > NBD_MAX_STRING_SIZE) {
+error_setg(errp, "export name '%s' too long", arg->name);
 return;
 }
 
-if (has_description && strlen(description) > NBD_MAX_STRING_SIZE) {
-error_setg(errp, "description '%s' too long", description);
+if (arg->description && strlen(arg->description) > NBD_MAX_STRING_SIZE) {
+error_setg(errp, "description '%s' too long", arg->description);
 return;
 }
 
-if (nbd_export_find(name)) {
-error_setg(errp, "NBD server already has export named '%s'", name);
+if (nbd_export_find(arg->name)) {
+error_setg(errp, "NBD server already has export named '%s'", 
arg->name);
 return;
 }
 
-on_eject_blk = blk_by_name(device);
+on_eject_blk = blk_by_name(arg->device);
 
-bs = bdrv_lookup_bs(device, device, errp);
+bs = bdrv_lookup_bs(arg->device, arg->device, errp);
 if (!bs) {
 return;
 }
@@ -199,15 +196,15 @@ void qmp_nbd_server_add(const char *device, bool 
has_name, const char *name,
 goto out;
 }
 
-if (!has_writable) {
-writable = false;
+if (!arg->has_writable) {
+arg->writable = false;
 }
 if (bdrv_is_read_only(bs)) {
-writable = false;
+arg->writable = false;
 }
 
-exp = nbd_export_new(bs, 0, len, name, description, bitmap,
- !writable, !writable,
+exp = nbd_export_new(bs, 0, len, arg->name, arg->description, arg->bitmap,
+ !arg->writable, !arg->writable,
  NULL, false, on_eject_blk, errp);
 if (!exp) {
 goto out;
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 30313858c2..fb4c2fd2a8 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -2341,6 +2341,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict 
*qdict)
 Error *local_err = NULL;
 BlockInfoList *block_list, *info;
 SocketAddress *addr;
+BlockExportNbd export;
 
 if (writable && !all) {
 error_setg(&local_err, "-w only valid together with -a");
@@ -2373,8 +2374,13 @@ void hmp_nbd_server_start(Monitor *mon, const QDict 
*qdict)
 continue;
 }
 
-qmp_nbd_server_add(info->value->device, false, NULL, fa

[PULL 03/29] iotests/026: Test EIO on allocation in a data-file

2020-03-06 Thread Kevin Wolf
From: Max Reitz 

Test what happens when writing data to an external data file, where the
write requires an L2 entry to be allocated, but the data write fails.

Signed-off-by: Max Reitz 
Message-Id: <20200225143130.111267-4-mre...@redhat.com>
Signed-off-by: Kevin Wolf 
---
 tests/qemu-iotests/026 | 32 ++
 tests/qemu-iotests/026.out |  6 ++
 tests/qemu-iotests/026.out.nocache |  6 ++
 3 files changed, 44 insertions(+)

diff --git a/tests/qemu-iotests/026 b/tests/qemu-iotests/026
index 0c1273c339..b05a4692cf 100755
--- a/tests/qemu-iotests/026
+++ b/tests/qemu-iotests/026
@@ -30,6 +30,7 @@ _cleanup()
 {
_cleanup_test_img
 rm "$TEST_DIR/blkdebug.conf"
+rm -f "$TEST_IMG.data_file"
 }
 trap "_cleanup; exit \$status" 0 1 2 3 15
 
@@ -239,6 +240,37 @@ $QEMU_IO -c "write 0 $CLUSTER_SIZE" "$BLKDBG_TEST_IMG" | 
_filter_qemu_io
 
 _check_test_img
 
+echo
+echo === Avoid freeing external data clusters on failure ===
+echo
+
+# Similar test as the last one, except we test what happens when there
+# is an error when writing to an external data file instead of when
+# writing to a preallocated zero cluster
+_make_test_img -o "data_file=$TEST_IMG.data_file" $CLUSTER_SIZE
+
+# Put blkdebug above the data-file, and a raw node on top of that so
+# that blkdebug will see a write_aio event and emit an error
+$QEMU_IO -c "write 0 $CLUSTER_SIZE" \
+"json:{
+ 'driver': 'qcow2',
+ 'file': { 'driver': 'file', 'filename': '$TEST_IMG' },
+ 'data-file': {
+ 'driver': 'raw',
+ 'file': {
+ 'driver': 'blkdebug',
+ 'config': '$TEST_DIR/blkdebug.conf',
+ 'image': {
+ 'driver': 'file',
+ 'filename': '$TEST_IMG.data_file'
+ }
+ }
+ }
+ }" \
+| _filter_qemu_io
+
+_check_test_img
+
 # success, all done
 echo "*** done"
 rm -f $seq.full
diff --git a/tests/qemu-iotests/026.out b/tests/qemu-iotests/026.out
index 83989996ff..c1b3b58482 100644
--- a/tests/qemu-iotests/026.out
+++ b/tests/qemu-iotests/026.out
@@ -653,4 +653,10 @@ wrote 1024/1024 bytes at offset 0
 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 write failed: Input/output error
 No errors were found on the image.
+
+=== Avoid freeing external data clusters on failure ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1024 
data_file=TEST_DIR/t.IMGFMT.data_file
+write failed: Input/output error
+No errors were found on the image.
 *** done
diff --git a/tests/qemu-iotests/026.out.nocache 
b/tests/qemu-iotests/026.out.nocache
index 9359d26d7e..8d5001648a 100644
--- a/tests/qemu-iotests/026.out.nocache
+++ b/tests/qemu-iotests/026.out.nocache
@@ -661,4 +661,10 @@ wrote 1024/1024 bytes at offset 0
 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 write failed: Input/output error
 No errors were found on the image.
+
+=== Avoid freeing external data clusters on failure ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1024 
data_file=TEST_DIR/t.IMGFMT.data_file
+write failed: Input/output error
+No errors were found on the image.
 *** done
-- 
2.20.1




[PULL 04/29] block: Fix leak in bdrv_create_file_fallback()

2020-03-06 Thread Kevin Wolf
From: Max Reitz 

@options is leaked by the first two return statements in this function.

Note that blk_new_open() takes the reference to @options even on
failure, so all we need to do to fix the leak is to move the QDict
allocation down to where we actually need it.

Reported-by: Coverity (CID 1419884)
Fixes: fd17146cd93d1704cd96d7c2757b325fc7aac6fd
   ("block: Generic file creation fallback")
Signed-off-by: Max Reitz 
Message-Id: <20200225155618.133412-1-mre...@redhat.com>
Signed-off-by: Kevin Wolf 
---
 block.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block.c b/block.c
index 1bdb9c679d..876bd45182 100644
--- a/block.c
+++ b/block.c
@@ -600,7 +600,7 @@ static int bdrv_create_file_fallback(const char *filename, 
BlockDriver *drv,
  QemuOpts *opts, Error **errp)
 {
 BlockBackend *blk;
-QDict *options = qdict_new();
+QDict *options;
 int64_t size = 0;
 char *buf = NULL;
 PreallocMode prealloc;
@@ -623,6 +623,7 @@ static int bdrv_create_file_fallback(const char *filename, 
BlockDriver *drv,
 return -ENOTSUP;
 }
 
+options = qdict_new();
 qdict_put_str(options, "driver", drv->format_name);
 
 blk = blk_new_open(filename, NULL, options,
-- 
2.20.1




[PULL 08/29] stubs: Add arch_type

2020-03-06 Thread Kevin Wolf
blockdev.c uses the arch_type constant, so before we can use the file in
tools (i.e. outside of the system emulator), we need to add a stub for
it. A new QEMU_ARCH_NONE is introduced for this case.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-3-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 include/sysemu/arch_init.h | 2 ++
 stubs/arch_type.c  | 4 
 stubs/Makefile.objs| 1 +
 3 files changed, 7 insertions(+)
 create mode 100644 stubs/arch_type.c

diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 62c6fe4cf1..01392dc945 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -24,6 +24,8 @@ enum {
 QEMU_ARCH_NIOS2 = (1 << 17),
 QEMU_ARCH_HPPA = (1 << 18),
 QEMU_ARCH_RISCV = (1 << 19),
+
+QEMU_ARCH_NONE = (1 << 31),
 };
 
 extern const uint32_t arch_type;
diff --git a/stubs/arch_type.c b/stubs/arch_type.c
new file mode 100644
index 00..fc5423bc98
--- /dev/null
+++ b/stubs/arch_type.c
@@ -0,0 +1,4 @@
+#include "qemu/osdep.h"
+#include "sysemu/arch_init.h"
+
+const uint32_t arch_type = QEMU_ARCH_NONE;
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 7afbe5fb61..24062ce7d9 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -1,3 +1,4 @@
+stub-obj-y += arch_type.o
 stub-obj-y += bdrv-next-monitor-owned.o
 stub-obj-y += blk-commit-all.o
 stub-obj-y += blockdev-close-all-bdrv-states.o
-- 
2.20.1




[PULL 07/29] qemu-storage-daemon: Add barebone tool

2020-03-06 Thread Kevin Wolf
This adds a new binary qemu-storage-daemon that doesn't yet do more than
some typical initialisation for tools and parsing the basic command
options --version, --help and --trace.

Even though this doesn't add any options yet that create things (like
--object or --blockdev), already document that we're planning to process
them in the order they are given on the command line rather than trying
(and failing, like vl.c) to resolve dependencies between options
automatically.

Signed-off-by: Kevin Wolf 
Message-Id: <20200224143008.13362-2-kw...@redhat.com>
Acked-by: Stefan Hajnoczi 
Signed-off-by: Kevin Wolf 
---
 configure |   2 +-
 qemu-storage-daemon.c | 127 ++
 Makefile  |   1 +
 3 files changed, 129 insertions(+), 1 deletion(-)
 create mode 100644 qemu-storage-daemon.c

diff --git a/configure b/configure
index fab6281eb7..cbf864bff1 100755
--- a/configure
+++ b/configure
@@ -6316,7 +6316,7 @@ tools=""
 if test "$want_tools" = "yes" ; then
   tools="qemu-img\$(EXESUF) qemu-io\$(EXESUF) qemu-edid\$(EXESUF) $tools"
   if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then
-tools="qemu-nbd\$(EXESUF) $tools"
+tools="qemu-nbd\$(EXESUF) qemu-storage-daemon\$(EXESUF) $tools"
   fi
   if [ "$ivshmem" = "yes" ]; then
 tools="ivshmem-client\$(EXESUF) ivshmem-server\$(EXESUF) $tools"
diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
new file mode 100644
index 00..fc4aef572b
--- /dev/null
+++ b/qemu-storage-daemon.c
@@ -0,0 +1,127 @@
+/*
+ * QEMU storage daemon
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2019 Kevin Wolf 
+ *
+ * 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 
+
+#include "block/block.h"
+#include "crypto/init.h"
+
+#include "qapi/error.h"
+#include "qemu-common.h"
+#include "qemu-version.h"
+#include "qemu/config-file.h"
+#include "qemu/error-report.h"
+#include "qemu/log.h"
+#include "qemu/main-loop.h"
+#include "qemu/module.h"
+
+#include "trace/control.h"
+
+static void help(void)
+{
+printf(
+"Usage: %s [options]\n"
+"QEMU storage daemon\n"
+"\n"
+"  -h, --help display this help and exit\n"
+"  -T, --trace [[enable=]][,events=][,file=]\n"
+" specify tracing options\n"
+"  -V, --version  output version information and exit\n"
+"\n"
+QEMU_HELP_BOTTOM "\n",
+error_get_progname());
+}
+
+static void process_options(int argc, char *argv[])
+{
+int c;
+
+static const struct option long_options[] = {
+{"help", no_argument, NULL, 'h'},
+{"trace", required_argument, NULL, 'T'},
+{"version", no_argument, NULL, 'V'},
+{0, 0, 0, 0}
+};
+
+/*
+ * In contrast to the system emulator, options are processed in the order
+ * they are given on the command lines. This means that things must be
+ * defined first before they can be referenced in another option.
+ */
+while ((c = getopt_long(argc, argv, "hT:V", long_options, NULL)) != -1) {
+switch (c) {
+case '?':
+exit(EXIT_FAILURE);
+case 'h':
+help();
+exit(EXIT_SUCCESS);
+case 'T':
+{
+char *trace_file = trace_opt_parse(optarg);
+trace_init_file(trace_file);
+g_free(trace_file);
+break;
+}
+case 'V':
+printf("qemu-storage-daemon version "
+   QEMU_FULL_VERSION "\n" QEMU_COPYRIGHT "\n");
+exit(EXIT_SUCCESS);
+default:
+g_assert_not_reached();
+}
+}
+if (optind != argc) {
+error_report("Unexpected argument: %s", argv[optind]);
+exit(EXIT_FAILURE);
+}
+}
+
+int main(int argc, char *argv[])
+{
+#ifdef CONFIG_POSIX
+signal(SIGPIPE, SIG_IGN);
+#endif
+
+error_init(argv[0]);
+qemu_init_exec_dir(ar

[PULL 01/29] qcow2: Fix alloc_cluster_abort() for pre-existing clusters

2020-03-06 Thread Kevin Wolf
From: Max Reitz 

handle_alloc() reuses preallocated zero clusters.  If anything goes
wrong during the data write, we do not change their L2 entry, so we
must not let qcow2_alloc_cluster_abort() free them.

Fixes: 8b24cd141549b5b264baeddd4e72902cfb5de23b
Cc: qemu-sta...@nongnu.org
Signed-off-by: Max Reitz 
Message-Id: <20200225143130.111267-2-mre...@redhat.com>
Signed-off-by: Kevin Wolf 
---
 block/qcow2-cluster.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 78c95dfa16..17f1363279 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1026,7 +1026,7 @@ err:
 void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m)
 {
 BDRVQcow2State *s = bs->opaque;
-if (!has_data_file(bs)) {
+if (!has_data_file(bs) && !m->keep_old_clusters) {
 qcow2_free_clusters(bs, m->alloc_offset,
 m->nb_clusters << s->cluster_bits,
 QCOW2_DISCARD_NEVER);
-- 
2.20.1




[PULL 00/29] Block layer patches

2020-03-06 Thread Kevin Wolf
The following changes since commit f4c4357fbfca0fb14e477bf661ae7384b4b9b283:

  Merge remote-tracking branch 'remotes/pmaydell/tags/pull-docs-20200306' into 
staging (2020-03-06 11:11:54 +)

are available in the Git repository at:

  git://repo.or.cz/qemu/kevin.git tags/for-upstream

for you to fetch changes up to 1de6b45fb5c1489b450df7d1a4c692bba9678ce6:

  block: bdrv_reopen() with backing file in different AioContext (2020-03-06 
17:34:09 +0100)


Block layer patches:

- Add qemu-storage-daemon (still experimental)
- rbd: Add support for ceph namespaces
- Fix bdrv_reopen() with backing file in different AioContext
- qcow2: Fix read-write reopen with persistent dirty bitmaps
- qcow2: Fix alloc_cluster_abort() for pre-existing clusters


Florian Florensa (1):
  block/rbd: Add support for ceph namespaces

Kevin Wolf (22):
  qemu-storage-daemon: Add barebone tool
  stubs: Add arch_type
  block: Move system emulator QMP commands to block/qapi-sysemu.c
  block: Move common QMP commands to block-core QAPI module
  block: Move sysemu QMP commands to QAPI block module
  qemu-storage-daemon: Add --blockdev option
  qapi: Flatten object-add
  qemu-storage-daemon: Add --object option
  qemu-storage-daemon: Add --nbd-server option
  blockdev-nbd: Boxed argument type for nbd-server-add
  qemu-storage-daemon: Add --export option
  qemu-storage-daemon: Add main loop
  qemu-storage-daemon: Add --chardev option
  stubs: Update monitor stubs for qemu-storage-daemon
  qapi: Create 'pragma' module
  monitor: Create QAPIfied monitor_init()
  qmp: Fail gracefully if chardev is already in use
  hmp: Fail gracefully if chardev is already in use
  monitor: Add allow_hmp parameter to monitor_init()
  qemu-storage-daemon: Add --monitor option
  iotests: Refactor blockdev-reopen test for iothreads
  block: bdrv_reopen() with backing file in different AioContext

Max Reitz (4):
  qcow2: Fix alloc_cluster_abort() for pre-existing clusters
  iotests/026: Test EIO on preallocated zero cluster
  iotests/026: Test EIO on allocation in a data-file
  block: Fix leak in bdrv_create_file_fallback()

Peter Krempa (2):
  block: Introduce 'bdrv_reopen_commit_post' step
  block/qcow2: Move bitmap reopen into bdrv_reopen_commit_post

 qapi/block-core.json | 733 +--
 qapi/block.json  | 512 ++--
 qapi/control.json|  37 ++
 qapi/pragma.json |  24 ++
 qapi/qapi-schema.json|  25 +-
 qapi/qom.json|  12 +-
 qapi/transaction.json|   2 +-
 docs/system/deprecated.rst   |   5 +
 configure|   2 +-
 include/block/block_int.h|   1 +
 include/block/nbd.h  |   1 +
 include/monitor/monitor.h|   6 +-
 include/qom/object_interfaces.h  |   7 +
 include/sysemu/arch_init.h   |   2 +
 block.c  |  44 ++-
 block/qapi-sysemu.c  | 590 
 block/qcow2-cluster.c|   2 +-
 block/qcow2.c|   7 +-
 block/rbd.c  |  44 ++-
 blockdev-nbd.c   |  40 +-
 blockdev.c   | 559 --
 chardev/char.c   |   8 +-
 gdbstub.c|   2 +-
 hw/block/xen-block.c |  11 +-
 monitor/hmp-cmds.c   |  21 +-
 monitor/hmp.c|   8 +-
 monitor/misc.c   |   2 +
 monitor/monitor.c|  86 ++--
 monitor/qmp-cmds.c   |   2 +-
 monitor/qmp.c|  11 +-
 qemu-storage-daemon.c| 340 
 qom/qom-qmp-cmds.c   |  42 +-
 stubs/arch_type.c|   4 +
 stubs/monitor-core.c |  21 +
 stubs/monitor.c  |  17 +-
 tests/test-util-sockets.c|   4 +-
 scripts/qapi/gen.py  |   5 +
 Makefile |  37 ++
 Makefile.objs|   9 +
 block/Makefile.objs  |   4 +-
 monitor/Makefile.objs|   2 +
 qapi/Makefile.objs   |   7 +-
 qom/Makefile.objs|   1 +
 storage-daemon/Makefile.objs |   1 +
 storage-daemon/qapi/Makefile.objs|   1 +
 storage-daemon/qapi/qapi-schema.json |  26 ++
 stubs/Makefile.objs  |   2 +
 tests/qemu-iotests/026   |  53 +++
 tests/qemu-iotests/026.out   |  16 +
 tests/qemu-iotests/026.out.nocache   |  16 +
 tests/qemu-iotests/245  

[PULL 05/29] block: Introduce 'bdrv_reopen_commit_post' step

2020-03-06 Thread Kevin Wolf
From: Peter Krempa 

Add another step in the reopen process where driver can execute code
after permission changes are comitted.

Signed-off-by: Peter Krempa 
Message-Id: 

Signed-off-by: Kevin Wolf 
---
 include/block/block_int.h | 1 +
 block.c   | 9 +
 2 files changed, 10 insertions(+)

diff --git a/include/block/block_int.h b/include/block/block_int.h
index 6f9fd5e20e..f422c0bff0 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -122,6 +122,7 @@ struct BlockDriver {
 int (*bdrv_reopen_prepare)(BDRVReopenState *reopen_state,
BlockReopenQueue *queue, Error **errp);
 void (*bdrv_reopen_commit)(BDRVReopenState *reopen_state);
+void (*bdrv_reopen_commit_post)(BDRVReopenState *reopen_state);
 void (*bdrv_reopen_abort)(BDRVReopenState *reopen_state);
 void (*bdrv_join_options)(QDict *options, QDict *old_options);
 
diff --git a/block.c b/block.c
index 876bd45182..aaa387504e 100644
--- a/block.c
+++ b/block.c
@@ -3695,6 +3695,15 @@ cleanup_perm:
 }
 }
 }
+
+if (ret == 0) {
+QTAILQ_FOREACH_REVERSE(bs_entry, bs_queue, entry) {
+BlockDriverState *bs = bs_entry->state.bs;
+
+if (bs->drv->bdrv_reopen_commit_post)
+bs->drv->bdrv_reopen_commit_post(&bs_entry->state);
+}
+}
 cleanup:
 QTAILQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) {
 if (ret) {
-- 
2.20.1




[PULL 02/29] iotests/026: Test EIO on preallocated zero cluster

2020-03-06 Thread Kevin Wolf
From: Max Reitz 

Test what happens when writing data to a preallocated zero cluster, but
the data write fails.

Signed-off-by: Max Reitz 
Message-Id: <20200225143130.111267-3-mre...@redhat.com>
Signed-off-by: Kevin Wolf 
---
 tests/qemu-iotests/026 | 21 +
 tests/qemu-iotests/026.out | 10 ++
 tests/qemu-iotests/026.out.nocache | 10 ++
 3 files changed, 41 insertions(+)

diff --git a/tests/qemu-iotests/026 b/tests/qemu-iotests/026
index a4aa74764f..0c1273c339 100755
--- a/tests/qemu-iotests/026
+++ b/tests/qemu-iotests/026
@@ -218,6 +218,27 @@ _make_test_img 64M
 $QEMU_IO -c "write 0 1M" -c "write 0 1M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
 _check_test_img
 
+echo
+echo === Avoid freeing preallocated zero clusters on failure ===
+echo
+
+cat > "$TEST_DIR/blkdebug.conf" <

[PATCH] build-sys: Move the print-variable rule to rules.mak

2020-03-06 Thread Philippe Mathieu-Daudé
Currently the print-variable rule can only be used in the
root directory:

  $ make print-vhost-user-json-y
  vhost-user-json-y= contrib/vhost-user-gpu/50-qemu-gpu.json 
tools/virtiofsd/50-qemu-virtiofsd.json

  $ make -C i386-softmmu print-obj-y
  make: Entering directory 'build/i386-softmmu'
  make: *** No rule to make target 'print-obj-y'.  Stop.
  make: Leaving directory 'build/i386-softmmu'

Move it to rules.mak so we can use it from other directories:

  $ make -C i386-softmmu print-obj-y
  make: Entering directory 'build/i386-softmmu'
  obj-y=qapi-introspect.o qapi-types-machine-target.o qapi-types-misc-target.o 
qapi-types.o qapi-visit-machine-target.o qapi-visit-misc-target.o qapi-visit.o 
qapi-events-machine-target.o qapi-events-misc-target.o qapi-events.o 
qapi-commands-machine-target.o qapi-commands-misc-target.o qapi-commands.o 
qapi-init-commands.o
  make: Leaving directory 'build/i386-softmmu'

Signed-off-by: Philippe Mathieu-Daudé 
---
 Makefile  | 3 ---
 rules.mak | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 9d4b224126..fdc5d29bb9 100644
--- a/Makefile
+++ b/Makefile
@@ -15,9 +15,6 @@ UNCHECKED_GOALS := %clean TAGS cscope ctags dist \
 help check-help print-% \
 docker docker-% vm-help vm-test vm-build-%
 
-print-%:
-   @echo '$*=$($*)'
-
 # All following code might depend on configuration variables
 ifneq ($(wildcard config-host.mak),)
 # Put the all: rule here so that config-host.mak can contain dependencies.
diff --git a/rules.mak b/rules.mak
index e39b073d46..694865b63e 100644
--- a/rules.mak
+++ b/rules.mak
@@ -435,3 +435,6 @@ sentinel = .$(subst $(SPACE),_,$(subst /,_,$1)).sentinel.
 atomic = $(eval $1: $(call sentinel,$1) ; @:) \
  $(call sentinel,$1) : $2 ; @touch $$@ \
  $(foreach t,$1,$(if $(wildcard $t),,$(shell rm -f $(call 
sentinel,$1
+
+print-%:
+   @echo '$*=$($*)'
-- 
2.21.1




Re: [PULL 0/3] Block patches

2020-03-06 Thread Peter Maydell
On Fri, 6 Mar 2020 at 14:23, Stefan Hajnoczi  wrote:
>
> The following changes since commit ef9f8fcbec6276414921dcd042575129a6331a2d:
>
>   Merge remote-tracking branch 
> 'remotes/stefanberger/tags/pull-tpm-2020-03-04-2' into staging (2020-03-05 
> 19:39:47 +)
>
> are available in the Git repository at:
>
>   https://github.com/stefanha/qemu.git tags/block-pull-request
>
> for you to fetch changes up to 1f40ace7b5634f93801c8474b9eb77fe2e00289c:
>
>   tests: Fix a bug with count variables (2020-03-06 10:35:15 +)
>
> 
> Pull request
>
> These patches would have gone through Thomas Huth but he is away on leave.
>
> 



Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.0
for any user-visible changes.

-- PMM



Re: [PATCH v3 12/13] migration/ram: Use offset_in_ramblock() in range checks

2020-03-06 Thread Dr. David Alan Gilbert
* David Hildenbrand (da...@redhat.com) wrote:
> We never read or write beyond the used_length of memory blocks when
> migrating. Make this clearer by using offset_in_ramblock() consistently.
> 
> Cc: "Dr. David Alan Gilbert" 
> Cc: Juan Quintela 
> Cc: Peter Xu 
> Signed-off-by: David Hildenbrand 

Reviewed-by: Dr. David Alan Gilbert 

> ---
>  migration/ram.c | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/migration/ram.c b/migration/ram.c
> index ee5c3d5784..5cc9993899 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -1309,8 +1309,8 @@ static bool find_dirty_block(RAMState *rs, 
> PageSearchStatus *pss, bool *again)
>  *again = false;
>  return false;
>  }
> -if ram_addr_t)pss->page) << TARGET_PAGE_BITS)
> ->= pss->block->used_length) {
> +if (!offset_in_ramblock(pss->block,
> +((ram_addr_t)pss->page) << TARGET_PAGE_BITS)) {
>  /* Didn't find anything in this RAM Block */
>  pss->page = 0;
>  pss->block = QLIST_NEXT_RCU(pss->block, next);
> @@ -1514,7 +1514,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t 
> start, ram_addr_t len)
>  rs->last_req_rb = ramblock;
>  }
>  trace_ram_save_queue_pages(ramblock->idstr, start, len);
> -if (start+len > ramblock->used_length) {
> +if (!offset_in_ramblock(ramblock, start + len - 1)) {
>  error_report("%s request overrun start=" RAM_ADDR_FMT " len="
>   RAM_ADDR_FMT " blocklen=" RAM_ADDR_FMT,
>   __func__, start, len, ramblock->used_length);
> @@ -3325,8 +3325,8 @@ static void colo_flush_ram_cache(void)
>  while (block) {
>  offset = migration_bitmap_find_dirty(ram_state, block, offset);
>  
> -if (((ram_addr_t)offset) << TARGET_PAGE_BITS
> ->= block->used_length) {
> +if (!offset_in_ramblock(block,
> +((ram_addr_t)offset) << 
> TARGET_PAGE_BITS)) {
>  offset = 0;
>  block = QLIST_NEXT_RCU(block, next);
>  } else {
> -- 
> 2.24.1
> 
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK




[PATCH] tests/qemu-iotests: Fix socket_scm_helper build path

2020-03-06 Thread Philippe Mathieu-Daudé
The socket_scm_helper path got corrupted during the mechanical
refactor moving the qtests files into their own sub-directory.

Fixes: 1e8a1fae7 ("test: Move qtests to a separate directory")
Signed-off-by: Philippe Mathieu-Daudé 
---
 tests/Makefile.include   | 1 +
 tests/qtest/Makefile.include | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index edcbd475aa..67e8fcddda 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -589,6 +589,7 @@ include $(SRC_PATH)/tests/qtest/Makefile.include
 tests/test-qga$(EXESUF): qemu-ga$(EXESUF)
 tests/test-qga$(EXESUF): tests/test-qga.o $(qtest-obj-y)
 tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o $(test-util-obj-y) 
libvhost-user.a
+tests/qemu-iotests/socket_scm_helper$(EXESUF): 
tests/qemu-iotests/socket_scm_helper.o
 
 SPEED = quick
 
diff --git a/tests/qtest/Makefile.include b/tests/qtest/Makefile.include
index 383b0ab217..76672990a7 100644
--- a/tests/qtest/Makefile.include
+++ b/tests/qtest/Makefile.include
@@ -287,7 +287,6 @@ tests/qtest/usb-hcd-ehci-test$(EXESUF): 
tests/qtest/usb-hcd-ehci-test.o $(libqos
 tests/qtest/usb-hcd-xhci-test$(EXESUF): tests/qtest/usb-hcd-xhci-test.o 
$(libqos-usb-obj-y)
 tests/qtest/cpu-plug-test$(EXESUF): tests/qtest/cpu-plug-test.o
 tests/qtest/migration-test$(EXESUF): tests/qtest/migration-test.o 
tests/qtest/migration-helpers.o
-tests/qtest/qemu-iotests/qtest/socket_scm_helper$(EXESUF): 
tests/qtest/qemu-iotests/qtest/socket_scm_helper.o
 tests/qtest/test-netfilter$(EXESUF): tests/qtest/test-netfilter.o 
$(qtest-obj-y)
 tests/qtest/test-filter-mirror$(EXESUF): tests/qtest/test-filter-mirror.o 
$(qtest-obj-y)
 tests/qtest/test-filter-redirector$(EXESUF): 
tests/qtest/test-filter-redirector.o $(qtest-obj-y)
-- 
2.21.1




Re: [PATCH v3 11/13] migration/multifd: Print used_length of memory block

2020-03-06 Thread Dr. David Alan Gilbert
* David Hildenbrand (da...@redhat.com) wrote:
> We actually want to print the used_length, against which we check.
> 
> Cc: "Dr. David Alan Gilbert" 
> Cc: Juan Quintela 
> Cc: Peter Xu 
> Signed-off-by: David Hildenbrand 

Reviewed-by: Dr. David Alan Gilbert 

> ---
>  migration/multifd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/migration/multifd.c b/migration/multifd.c
> index b3e8ae9bcc..dd9e88c5f1 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -222,7 +222,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams 
> *p, Error **errp)
>  if (offset > (block->used_length - qemu_target_page_size())) {
>  error_setg(errp, "multifd: offset too long %" PRIu64
> " (max " RAM_ADDR_FMT ")",
> -   offset, block->max_length);
> +   offset, block->used_length);
>  return -1;
>  }
>  p->pages->iov[i].iov_base = block->host + offset;
> -- 
> 2.24.1
> 
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK




Re: [PATCH v3 10/13] migration/ram: Handle RAM block resizes during postcopy

2020-03-06 Thread Dr. David Alan Gilbert
* David Hildenbrand (da...@redhat.com) wrote:
> Resizing while migrating is dangerous and does not work as expected.
> The whole migration code works on the usable_length of ram blocks and does
> not expect this to change at random points in time.
> 
> In the case of postcopy, relying on used_length is racy as soon as the
> guest is running. Also, when used_length changes we might leave the
> uffd handler registered for some memory regions, reject valid pages
> when migrating and fail when sending the recv bitmap to the source.
> 
> Resizing can be trigger *after* (but not during) a reset in
> ACPI code by the guest
> - hw/arm/virt-acpi-build.c:acpi_ram_update()
> - hw/i386/acpi-build.c:acpi_ram_update()
> 
> Let's remember the original used_length in a separate variable and
> use it in relevant postcopy code. Make sure to update it when we resize
> during precopy, when synchronizing the RAM block sizes with the source.
> 
> Reviewed-by: Peter Xu 
> Cc: "Dr. David Alan Gilbert" 
> Cc: Juan Quintela 
> Cc: Eduardo Habkost 
> Cc: Paolo Bonzini 
> Cc: Igor Mammedov 
> Cc: "Michael S. Tsirkin" 
> Cc: Richard Henderson 
> Cc: Shannon Zhao 
> Cc: Alex Bennée 
> Cc: Peter Xu 
> Signed-off-by: David Hildenbrand 
> ---
>  include/exec/ramblock.h  | 10 ++
>  migration/postcopy-ram.c | 15 ---
>  migration/ram.c  | 11 +--
>  3 files changed, 31 insertions(+), 5 deletions(-)
> 
> diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h
> index 07d50864d8..664701b759 100644
> --- a/include/exec/ramblock.h
> +++ b/include/exec/ramblock.h
> @@ -59,6 +59,16 @@ struct RAMBlock {
>   */
>  unsigned long *clear_bmap;
>  uint8_t clear_bmap_shift;
> +
> +/*
> + * RAM block length that corresponds to the used_length on the migration
> + * source (after RAM block sizes were synchronized). Especially, after
> + * starting to run the guest, used_length and postcopy_length can differ.
> + * Used to register/unregister uffd handlers and as the size of the 
> received
> + * bitmap. Receiving any page beyond this length will bail out, as it
> + * could not have been valid on the source.
> + */
> +ram_addr_t postcopy_length;
>  };
>  #endif
>  #endif
> diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
> index a36402722b..c68caf4e42 100644
> --- a/migration/postcopy-ram.c
> +++ b/migration/postcopy-ram.c
> @@ -17,6 +17,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/rcu.h"
>  #include "exec/target_page.h"
>  #include "migration.h"
>  #include "qemu-file.h"
> @@ -31,6 +32,7 @@
>  #include "qemu/error-report.h"
>  #include "trace.h"
>  #include "hw/boards.h"
> +#include "exec/ramblock.h"
>  
>  /* Arbitrary limit on size of each discard command,
>   * keeps them around ~200 bytes
> @@ -456,6 +458,13 @@ static int init_range(RAMBlock *rb, void *opaque)
>  ram_addr_t length = qemu_ram_get_used_length(rb);
>  trace_postcopy_init_range(block_name, host_addr, offset, length);
>  
> +/*
> + * Save the used_length before running the guest. In case we have to
> + * resize RAM blocks when syncing RAM block sizes from the source during
> + * precopy, we'll update it manually via the ram block notifier.
> + */
> +rb->postcopy_length = length;
> +
>  /*
>   * We need the whole of RAM to be truly empty for postcopy, so things
>   * like ROMs and any data tables built during init must be zero'd
> @@ -478,7 +487,7 @@ static int cleanup_range(RAMBlock *rb, void *opaque)
>  const char *block_name = qemu_ram_get_idstr(rb);
>  void *host_addr = qemu_ram_get_host_addr(rb);
>  ram_addr_t offset = qemu_ram_get_offset(rb);
> -ram_addr_t length = qemu_ram_get_used_length(rb);
> +ram_addr_t length = rb->postcopy_length;
>  MigrationIncomingState *mis = opaque;
>  struct uffdio_range range_struct;
>  trace_postcopy_cleanup_range(block_name, host_addr, offset, length);
> @@ -600,7 +609,7 @@ static int nhp_range(RAMBlock *rb, void *opaque)
>  const char *block_name = qemu_ram_get_idstr(rb);
>  void *host_addr = qemu_ram_get_host_addr(rb);
>  ram_addr_t offset = qemu_ram_get_offset(rb);
> -ram_addr_t length = qemu_ram_get_used_length(rb);
> +ram_addr_t length = rb->postcopy_length;
>  trace_postcopy_nhp_range(block_name, host_addr, offset, length);
>  
>  /*
> @@ -644,7 +653,7 @@ static int ram_block_enable_notify(RAMBlock *rb, void 
> *opaque)
>  struct uffdio_register reg_struct;
>  
>  reg_struct.range.start = (uintptr_t)qemu_ram_get_host_addr(rb);
> -reg_struct.range.len = qemu_ram_get_used_length(rb);
> +reg_struct.range.len = rb->postcopy_length;
>  reg_struct.mode = UFFDIO_REGISTER_MODE_MISSING;
>  
>  /* Now tell our userfault_fd that it's responsible for this area */
> diff --git a/migration/ram.c b/migration/ram.c
> index 1a5ff07997..ee5c3d5784 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -244,7 +244,7

Re: [PATCH v5 32/50] multi-process: Use separate MMIO communication channel

2020-03-06 Thread Stefan Hajnoczi
This went unanswered in the last revision:

On Thu, Nov 21, 2019 at 12:31:42PM +, Stefan Hajnoczi wrote:
> On Wed, Nov 13, 2019 at 11:14:50AM -0500, Jag Raman wrote:
> > On 11/11/2019 11:21 AM, Stefan Hajnoczi wrote:
> > > On Thu, Oct 24, 2019 at 05:09:13AM -0400, Jagannathan Raman wrote:
> > > > Using a separate communication channel for MMIO helps
> > > > with improving Performance
> > > 
> > > Why?
> > 
> > Typical initiation of IO operations involves multiple MMIO accesses per
> > IO operation. In some legacy devices like LSI, the completion of the IO
> > operations is also accomplished by polling on MMIO registers. Therefore,
> > MMIO traffic can be hefty in some cases and contribute to Performance.
> > 
> > Having a dedicated channel for MMIO ensures that it doesn't have to
> > compete with other messages to the remote process, especially when there
> > are multiple devices emulated by a single remote process.
> 
> A vCPU doing a polling read on an MMIO register will cause a BAR_READ
> message to be sent to the remote process.  The vCPU thread waits for the
> response to this message.
> 
> When there are multiple remote devices each has its own socket, so
> communication with different remote processes does not interfere.
> 
> The only scenarios I can think of are:
> 1. Interference within a single device between vCPUs and/or the QEMU
>monitor.
> 2. A single process serving multiple devices that is implemented in a
>way such that different devices interfere with each other.
> 
> It sounds like you are saying the problem is #2, but this is still
> unclear to me.  If the remote process can be implemented in a way such
> that there is no interference when each device has a special MMIO
> socket, then why can't it be implemented in a way such that there is no
> interference when each device's main socket is used (each device has
> it's own!).
> 
> Maybe I've missed the point.  It would be good if you could explain in
> more detail.
> 
> Stefan


signature.asc
Description: PGP signature


[Bug 1813165] Re: KVM internal error. Suberror: 1 emulation failure

2020-03-06 Thread tstrike
Nested Configuration check
tstrike39@islandhealthcenter-media:~$ sudo cat 
/sys/module/kvm_intel/parameters/nested
[sudo] password for tstrike39: 
Y


Not UEFI enabled

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

Title:
  KVM internal error. Suberror: 1 emulation failure

Status in QEMU:
  New

Bug description:
  Hello Devs.

  Having problems getting VM to run with qemu 3.1.0. I should mention
  it's a nested configuration.

  2019-01-24 13:46:08.648+: starting up libvirt version: 4.10.0, qemu 
version: 3.1.0, kernel: 4.14.94, hostname: one
  LC_ALL=C 
PATH=/bin:/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin
 HOME=/root USER=root QEMU_AUDIO_DRV=none /usr/bin/kvm -name 
guest=one-266,debug-threads=on -S -object 
secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-1-one-266/master-key.aes
 -machine pc-i440fx-2.9,accel=kvm,usb=off,dump-guest-core=off -cpu 
Skylake-Client-IBRS,ss=on,hypervisor=on,tsc_adjust=on,clflushopt=on,ssbd=on,xsaves=on,pdpe1gb=on
 -m 1024 -realtime mlock=off -smp 2,sockets=2,cores=1,threads=1 -uuid 
b219b45d-a2f0-4128-a948-8673a7abf968 -no-user-config -nodefaults -chardev 
socket,id=charmonitor,fd=21,server,nowait -mon 
chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown -boot 
strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive 
file=/var/lib/one//datastores/0/266/disk.0,format=qcow2,if=none,id=drive-virtio-disk0,cache=none
 -device 
virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1,write-cache=on
 -drive 
file=/var/lib/one//datastores/0/266/disk.1,format=raw,if=none,id=drive-ide0-0-0,readonly=on
 -device ide-cd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 -netdev 
tap,fd=23,id=hostnet0 -device 
rtl8139,netdev=hostnet0,id=net0,mac=02:00:00:76:69:85,bus=pci.0,addr=0x3 
-chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 
-vnc 0.0.0.0:266 -device cirrus-vga,id=video0,bus=pci.0,addr=0x2 -device 
virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 -sandbox 
on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny -msg 
timestamp=on
  char device redirected to /dev/pts/1 (label charserial0)
  KVM internal error. Suberror: 1
  emulation failure
  EAX=0001 EBX=000f7c2c ECX=0001 EDX=0001
  ESI=6a26 EDI=3ffbdc48 EBP=69e6 ESP=000a8000
  EIP=000fd057 EFL=00010016 [AP-] CPL=0 II=0 A20=1 SMM=1 HLT=0
  ES =0010   00c09300
  CS =  0fff 00809b00
  SS =0010   00c09300
  DS =0010   00c09300
  FS =0010   00c09300
  GS =0010   00c09300
  LDT=   8200
  TR =   8b00
  GDT= 10387cfe fe6c
  IDT= 0010387c 3810
  CR0=0010 CR2= CR3= CR4=
  DR0= DR1= DR2= 
DR3=
  DR6=fffecffc DR7=0e1e0400
  EFER=
  Code=cb 66 ba 4d d0 0f 00 e9 c8 fe bc 00 80 0a 00 e8 31 3a ff ff <0f> aa fa 
fc 66 ba 66 d0 0f 00 e9 b1 fe f3 90 f0 0f ba 2d ac 3b 0f 00 00 72 f3 8b 25 a8 3b
  2019-01-24T13:47:39.383366Z kvm: terminating on signal 15 from pid 2708 
(/usr/sbin/libvirtd)

  Someone has an idea whats going wrong here?

  thanks and cheers
  t.

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



Re: [PATCH v5 50/50] multi-process: add configure and usage information

2020-03-06 Thread Stefan Hajnoczi
On Fri, Feb 28, 2020 at 10:43:44AM -0800, Elena Ufimtseva wrote:
> On Thu, Feb 27, 2020 at 04:58:04PM +, Stefan Hajnoczi wrote:
> > On Mon, Feb 24, 2020 at 03:55:41PM -0500, Jagannathan Raman wrote:
> > > +* The devices to be emulated in the separate process are defined as
> > > +  before with addition of "rid" suboption that serves as a remote group
> > > +  identificator.
> > > +
> > > +  -device ,rid="remote process id"
> > > +
> > > +  For example, for non multi-process qemu:
> > > +-device lsi53c895a,id=scsi0 device
> > > +-device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0
> > > +-drive id=drive0,file=data-disk.img
> > > +
> > > +  and for multi-process qemu and no libvirt
> > > +  support (i.e. QEMU forks child processes):
> > > +-device lsi53c895a,id=scsi0,rid=0
> > > +-device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid=0
> > 
> > This approach is invasive:
> >  * lsi53c895a should not need to be modified with a new rid= option.
> >  * QEMU should not know about the scsi-hd device or drive0.  Only the
> >device emulation process needs to know about scsi-hd.
> > 
> > In order to cleanly separate QEMU and the device emulation process
> > syntax like this is needed:
> > 
> >   -object remote-device,id=rid0,...
> >   -device remote-pci-device,id=scsi0,remote-device=rid0
> > 
> > The "remote-device" object could be part of remote-pci-device, but
> > keeping it separate may be useful in the future in order to support
> > things like reconnection.
> > 
> > The generic "remote-pci-device" device handles any remote PCI device,
> > not just the LSI SCSI controller.
> > 
> > Do you agree with this approach?
> > 
> 
> We discussed these changes and they seem to be along the lines with
> the future work on vfio over socket approach we will be working on later.
> 
> Could we for this experimental version have the changes you propose here
> with one modification - instead of having generic remote-pci-device imply 
> that that is LSI
> device? And while we work towards vfio over socket this will become any remote
> PCI device?

Yes, that sounds good.

> > > +  The drives to be emulated by the remote process are specified as part 
> > > of
> > > +  this command sub-option. The device to be used to connect to the 
> > > monitor
> > > +  is also specified as part of this suboption.
> > > +
> > > +  For example, the following option adds a drive and monitor to the 
> > > remote
> > > +  process:
> > > +  -remote rid=0,exec="qemu-scsi-dev",command="-drive 
> > > id=drive0,,file=data-disk.img -monitor 
> > > unix:/home/qmp-sock,,server,,nowait"
> > > +
> > > +  Note: There's an issue with this "command" sub-option which we are in 
> > > the
> > > +  process of fixing. To work around this issue, it requires additional
> > > +  "comma" characters as illustrated above, and in the example below.
> > 
> > command= (which could be called args= for clarity) will be difficult to
> > use not just because of comma escaping but also because of double-quote
> > escaping.  How do you pass a command-line argument that contains spaces?
> 
> Yes, this is not great. And spaces are the problem at the moment.
> I am looking if the -object has some properties that can allow for arbitrary
> strings. Maybe such as data for "secret" object  would do?

I'm not aware of a way to avoid the comma escaping.  The space escaping
is a question of how the remote process is spawned.  If the command-line
is processed by a shell like with system(3) then backslash can be used
to escape spaces.

Stefan


signature.asc
Description: PGP signature


Re: [PATCH v3 09/13] migration/ram: Consolidate variable reset after placement in ram_load_postcopy()

2020-03-06 Thread Dr. David Alan Gilbert
* David Hildenbrand (da...@redhat.com) wrote:
> Let's consolidate resetting the variables.
> 
> Cc: "Dr. David Alan Gilbert" 
> Cc: Juan Quintela 
> Cc: Peter Xu 
> Signed-off-by: David Hildenbrand 

Thanks, I think that's actually fixing a case where huge zero pages
weren't placed as zero pages?

Dave

> ---
>  migration/ram.c | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/migration/ram.c b/migration/ram.c
> index f815f4e532..1a5ff07997 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -3126,7 +3126,7 @@ static int ram_load_postcopy(QEMUFile *f)
>  /* Temporary page that is later 'placed' */
>  void *postcopy_host_page = mis->postcopy_tmp_page;
>  void *host_page = NULL;
> -bool all_zero = false;
> +bool all_zero = true;
>  int target_pages = 0;
>  
>  while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) {
> @@ -3152,7 +3152,6 @@ static int ram_load_postcopy(QEMUFile *f)
>  addr &= TARGET_PAGE_MASK;
>  
>  trace_ram_load_postcopy_loop((uint64_t)addr, flags);
> -place_needed = false;
>  if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE |
>   RAM_SAVE_FLAG_COMPRESS_PAGE)) {
>  block = ram_block_from_stream(f, flags);
> @@ -3180,9 +3179,7 @@ static int ram_load_postcopy(QEMUFile *f)
>   */
>  page_buffer = postcopy_host_page +
>host_page_offset_from_ram_block_offset(block, 
> addr);
> -/* If all TP are zero then we can optimise the place */
>  if (target_pages == 1) {
> -all_zero = true;
>  host_page = host_page_from_ram_block_offset(block, addr);
>  } else if (host_page != host_page_from_ram_block_offset(block,
>  addr)) {
> @@ -3199,7 +3196,6 @@ static int ram_load_postcopy(QEMUFile *f)
>   */
>  if (target_pages == (block->page_size / TARGET_PAGE_SIZE)) {
>  place_needed = true;
> -target_pages = 0;
>  }
>  place_source = postcopy_host_page;
>  }
> @@ -3276,6 +3272,10 @@ static int ram_load_postcopy(QEMUFile *f)
>  ret = postcopy_place_page(mis, host_page, place_source,
>block);
>  }
> +place_needed = false;
> +target_pages = 0;
> +/* Assume we have a zero page until we detect something 
> different */
> +all_zero = true;
>  }
>  }
>  
> -- 
> 2.24.1
> 
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK




  1   2   3   >