Re: [PATCH 5/6] tests: handling signal on win32 properly

2020-09-03 Thread Paolo Bonzini
Yes, I guess that's true. I will queue it instead.

Paolo

Il gio 3 set 2020, 07:58 Thomas Huth  ha scritto:

> On 02/09/2020 19.04, Paolo Bonzini wrote:
> > On 02/09/20 19:00, Yonggang Luo wrote:
> >> SIGABRT should use signal(SIGABRT, sigabrt_handler) to handle on win32
> >>
> >> The error:
> >> E:/CI-Cor-Ready/xemu/qemu.org/tests/test-replication.c:559:33: error:
> invalid use of undefined type 'struct sigaction'
> >>   559 | sigact = (struct sigaction) {
> >>   | ^
> >>
> >> Signed-off-by: Yonggang Luo 
> >> ---
> >>  tests/test-replication.c | 4 
> >>  1 file changed, 4 insertions(+)
> >>
> >> diff --git a/tests/test-replication.c b/tests/test-replication.c
> >> index e0b03dafc2..9ab3666a90 100644
> >> --- a/tests/test-replication.c
> >> +++ b/tests/test-replication.c
> >> @@ -554,6 +554,9 @@ static void sigabrt_handler(int signo)
> >>
> >>  static void setup_sigabrt_handler(void)
> >>  {
> >> +#ifdef _WIN32
> >> +signal(SIGABRT, sigabrt_handler);
> >> +#else
> >>  struct sigaction sigact;
> >>
> >>  sigact = (struct sigaction) {
> >> @@ -562,6 +565,7 @@ static void setup_sigabrt_handler(void)
> >>  };
> >>  sigemptyset(&sigact.sa_mask);
> >>  sigaction(SIGABRT, &sigact, NULL);
> >> +#endif
> >>  }
> >>
> >>  int main(int argc, char **argv)
> >>
> >
> > This is already fixed by a patch from Thomas.
>
> Well, my patch was to simply disable test-replication on Windows ... if
> it is working with this modification here, that's certainly better than
> disabling it.
>
>  Thomas
>
>


Re: [PATCH v2 3/3] nbd: disable signals and forking on Windows builds

2020-09-03 Thread Yonggang Luo
On Thu, Sep 3, 2020 at 7:29 AM Eric Blake  wrote:

> On 9/2/20 5:07 PM, 罗勇刚(Yonggang Luo) wrote:
> > On Tue, Aug 25, 2020 at 6:40 PM Daniel P. Berrangé 
> > wrote:
> >
> >> Disabling these parts are sufficient to get the qemu-nbd program
> >> compiling in a Windows build.
> >>
> >> Signed-off-by: Daniel P. Berrangé 
> >> ---
> >>   meson.build | 7 ++-
> >>   qemu-nbd.c  | 5 +
> >>   2 files changed, 7 insertions(+), 5 deletions(-)
>
> >> +++ b/qemu-nbd.c
> >> @@ -899,6 +899,7 @@ int main(int argc, char **argv)
> >>   #endif
> >>
> >>   if ((device && !verbose) || fork_process) {
> >> +#ifndef WIN32
> >>   int stderr_fd[2];
> >>   pid_t pid;
> >>   int ret;
> >> @@ -962,6 +963,10 @@ int main(int argc, char **argv)
> >>*/
> >>   exit(errors);
> >>   }
> >> +#else /* WIN32 */
> >> +error_report("Unable to fork into background on Windows
> hosts");
> >> +exit(EXIT_FAILURE);
> >> +#endif /* WIN32 */
> >>   }
> >>
> > May us replace fork with alternative such as spawn?
>
> You're certainly welcome to propose a patch along those lines, if
> spawning a task is a common Windows counterpart to the Unix notion of
> forking off a daemon.  But even requiring qemu-nbd to run in the
> foreground is already an improvement over what we had previously, so any
> change to use spawn will be a separate series, and will not hold up this
>
Yes, of cause.

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

-- 
 此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo


Re: [PATCH] stubs: Move qemu_fd_register stub to util/main-loop.c

2020-09-03 Thread Yonggang Luo
I am also facing some problem alike:

  LINKtests/test-qdev-global-props.exe
  LINKtests/test-timed-average.exe
C:/CI-Tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
libqemuutil.a(util_main-loop.c.obj): in function `qemu_notify_event':
C:\work\xemu\qemu-build/../qemu/util/main-loop.c:139: multiple definition
of `qemu_notify_event';
libqemuutil.a(stubs_notify-event.c.obj):C:\work\xemu\qemu-build/../qemu/stubs/notify-event.c:6:
first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [C:/work/xemu/qemu/rules.mak:88:tests/test-timed-average.exe] 错误 1

On Thu, Sep 3, 2020 at 1:46 PM Thomas Huth  wrote:

> The linker of MinGW sometimes runs into the following problem:
>
> libqemuutil.a(util_main-loop.c.obj): In function `qemu_fd_register':
> /builds/huth/qemu/build/../util/main-loop.c:331: multiple definition of
>  `qemu_fd_register'
>
> libqemuutil.a(stubs_fd-register.c.obj):/builds/huth/qemu/stubs/fd-register.c:5:
>  first defined here
> collect2: error: ld returned 1 exit status
> /builds/huth/qemu/rules.mak:88: recipe for target
> 'tests/test-timed-average.exe'
>  failed
>
> qemu_fd_register() is defined in util/main-loop.c for WIN32, so let's
> simply
> move the stub also there in the #else part of the corresponding #ifndef
> to fix this problem.
>
> Signed-off-by: Thomas Huth 
> ---
>  stubs/fd-register.c | 6 --
>  stubs/meson.build   | 1 -
>  util/main-loop.c| 4 
>  3 files changed, 4 insertions(+), 7 deletions(-)
>  delete mode 100644 stubs/fd-register.c
>
> diff --git a/stubs/fd-register.c b/stubs/fd-register.c
> deleted file mode 100644
> index 63a4abdb20..00
> --- a/stubs/fd-register.c
> +++ /dev/null
> @@ -1,6 +0,0 @@
> -#include "qemu/osdep.h"
> -#include "qemu/main-loop.h"
> -
> -void qemu_fd_register(int fd)
> -{
> -}
> diff --git a/stubs/meson.build b/stubs/meson.build
> index e2dfedc2a7..e0b322bc28 100644
> --- a/stubs/meson.build
> +++ b/stubs/meson.build
> @@ -9,7 +9,6 @@ stub_ss.add(files('cpu-get-clock.c'))
>  stub_ss.add(files('cpu-get-icount.c'))
>  stub_ss.add(files('dump.c'))
>  stub_ss.add(files('error-printf.c'))
> -stub_ss.add(files('fd-register.c'))
>  stub_ss.add(files('fdset.c'))
>  stub_ss.add(files('fw_cfg.c'))
>  stub_ss.add(files('gdbstub.c'))
> diff --git a/util/main-loop.c b/util/main-loop.c
> index f69f055013..217c8d6056 100644
> --- a/util/main-loop.c
> +++ b/util/main-loop.c
> @@ -179,6 +179,10 @@ static int max_priority;
>  static int glib_pollfds_idx;
>  static int glib_n_poll_fds;
>
> +void qemu_fd_register(int fd)
> +{
> +}
> +
>  static void glib_pollfds_fill(int64_t *cur_timeout)
>  {
>  GMainContext *context = g_main_context_default();
> --
> 2.18.2
>
>
>

-- 
 此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo


[PATCH v1] sd: sdhci: assert data_count is within fifo_buffer

2020-09-03 Thread P J P
From: Prasad J Pandit 

While doing multi block SDMA, transfer block size may exceed
the 's->fifo_buffer[s->buf_maxsz]' size. It may leave the
current element pointer 's->data_count' pointing out of bounds.
Leading the subsequent DMA r/w operation to OOB access issue.
Assert that 's->data_count' is within fifo_buffer.

 -> https://ruhr-uni-bochum.sciebo.de/s/NNWP2GfwzYKeKwE?path=%2Fsdhci_oob_write1
 ==1459837==ERROR: AddressSanitizer: heap-buffer-overflow
 WRITE of size 54722048 at 0x6151e280 thread T3
 #0  __interceptor_memcpy (/lib64/libasan.so.6+0x3a71d)
 #1  flatview_read_continue ../exec.c:3245
 #2  flatview_read ../exec.c:3278
 #3  address_space_read_full ../exec.c:3291
 #4  address_space_rw ../exec.c:3319
 #5  dma_memory_rw_relaxed ../include/sysemu/dma.h:87
 #6  dma_memory_rw ../include/sysemu/dma.h:110
 #7  dma_memory_read ../include/sysemu/dma.h:116
 #8  sdhci_sdma_transfer_multi_blocks ../hw/sd/sdhci.c:629
 #9  sdhci_write ../hw/sd/sdhci.c:1097
 #10 memory_region_write_accessor ../softmmu/memory.c:483
 ...

Reported-by: Ruhr-University 
Suggested-by: Philippe Mathieu-Daudé 
Signed-off-by: Prasad J Pandit 
---
 hw/sd/sdhci.c | 2 ++
 1 file changed, 2 insertions(+)

Update v1: use assert(3) calls
  -> https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg00966.html

diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 1785d7e1f7..023acbed41 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -604,6 +604,7 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
 s->blkcnt--;
 }
 }
+assert(s->data_count <= s->buf_maxsz && s->data_count > begin);
 dma_memory_write(s->dma_as, s->sdmasysad,
  &s->fifo_buffer[begin], s->data_count - begin);
 s->sdmasysad += s->data_count - begin;
@@ -626,6 +627,7 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
 s->data_count = block_size;
 boundary_count -= block_size - begin;
 }
+assert(s->data_count <= s->buf_maxsz && s->data_count > begin);
 dma_memory_read(s->dma_as, s->sdmasysad,
 &s->fifo_buffer[begin], s->data_count - begin);
 s->sdmasysad += s->data_count - begin;
-- 
2.26.2




[PATCH v2 08/12] target/microblaze: Replace cpustate_changed with DISAS_EXIT_NEXT

2020-09-03 Thread Richard Henderson
Rather than look for the combination of DISAS_NEXT with a separate
variable, go ahead and set is_jmp to the desired state.

Reviewed-by: Edgar E. Iglesias 
Tested-by: Edgar E. Iglesias 
Signed-off-by: Richard Henderson 
---
 target/microblaze/translate.c | 34 ++
 1 file changed, 10 insertions(+), 24 deletions(-)

diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c
index 2abef328a3..6bf299a826 100644
--- a/target/microblaze/translate.c
+++ b/target/microblaze/translate.c
@@ -70,7 +70,6 @@ typedef struct DisasContext {
 
 /* Decoder.  */
 uint32_t ext_imm;
-unsigned int cpustate_changed;
 unsigned int tb_flags;
 unsigned int tb_flags_to_set;
 int mem_index;
@@ -1255,7 +1254,7 @@ static bool trans_mbar(DisasContext *dc, arg_mbar *arg)
  *
  * Therefore, choose to end the TB always.
  */
-dc->cpustate_changed = 1;
+dc->base.is_jmp = DISAS_EXIT_NEXT;
 return true;
 }
 
@@ -1307,19 +1306,6 @@ static void msr_read(DisasContext *dc, TCGv_i32 d)
 tcg_temp_free_i32(t);
 }
 
-#ifndef CONFIG_USER_ONLY
-static void msr_write(DisasContext *dc, TCGv_i32 v)
-{
-dc->cpustate_changed = 1;
-
-/* Install MSR_C.  */
-tcg_gen_extract_i32(cpu_msr_c, v, 2, 1);
-
-/* Clear MSR_C and MSR_CC; MSR_PVR is not writable, and is always clear. */
-tcg_gen_andi_i32(cpu_msr, v, ~(MSR_C | MSR_CC | MSR_PVR));
-}
-#endif
-
 static bool do_msrclrset(DisasContext *dc, arg_type_msr *arg, bool set)
 {
 uint32_t imm = arg->imm;
@@ -1352,7 +1338,7 @@ static bool do_msrclrset(DisasContext *dc, arg_type_msr 
*arg, bool set)
 } else {
 tcg_gen_andi_i32(cpu_msr, cpu_msr, ~imm);
 }
-dc->cpustate_changed = 1;
+dc->base.is_jmp = DISAS_EXIT_NEXT;
 }
 return true;
 }
@@ -1385,7 +1371,13 @@ static bool trans_mts(DisasContext *dc, arg_mts *arg)
 TCGv_i32 src = reg_for_read(dc, arg->ra);
 switch (arg->rs) {
 case SR_MSR:
-msr_write(dc, src);
+/* Install MSR_C.  */
+tcg_gen_extract_i32(cpu_msr_c, src, 2, 1);
+/*
+ * Clear MSR_C and MSR_CC;
+ * MSR_PVR is not writable, and is always clear.
+ */
+tcg_gen_andi_i32(cpu_msr, src, ~(MSR_C | MSR_CC | MSR_PVR));
 break;
 case SR_FSR:
 tcg_gen_st_i32(src, cpu_env, offsetof(CPUMBState, fsr));
@@ -1417,7 +1409,7 @@ static bool trans_mts(DisasContext *dc, arg_mts *arg)
 qemu_log_mask(LOG_GUEST_ERROR, "Invalid mts reg 0x%x\n", arg->rs);
 return true;
 }
-dc->cpustate_changed = 1;
+dc->base.is_jmp = DISAS_EXIT_NEXT;
 return true;
 #endif
 }
@@ -1629,7 +1621,6 @@ static void mb_tr_init_disas_context(DisasContextBase 
*dcb, CPUState *cs)
 
 dc->cpu = cpu;
 dc->tb_flags = dc->base.tb->flags;
-dc->cpustate_changed = 0;
 dc->ext_imm = dc->base.tb->cs_base;
 dc->r0 = NULL;
 dc->r0_set = false;
@@ -1714,11 +1705,6 @@ static void mb_tr_translate_insn(DisasContextBase *dcb, 
CPUState *cs)
 }
 dc->base.is_jmp = DISAS_JUMP;
 }
-
-/* Force an exit if the per-tb cpu state has changed.  */
-if (dc->base.is_jmp == DISAS_NEXT && dc->cpustate_changed) {
-dc->base.is_jmp = DISAS_EXIT_NEXT;
-}
 }
 
 static void mb_tr_tb_stop(DisasContextBase *dcb, CPUState *cs)
-- 
2.25.1




[PATCH v2 02/12] target/microblaze: Renumber D_FLAG

2020-09-03 Thread Richard Henderson
ESS[DS] is bit 19 in the manual, but the manual uses big-endian bit
numbering.  This corresponds to bit 12 in little-endian numbering.
Let the comment about matching the ESR be true by renumbering it.

Signed-off-by: Richard Henderson 
---
 target/microblaze/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h
index a25a2b427f..32811f773d 100644
--- a/target/microblaze/cpu.h
+++ b/target/microblaze/cpu.h
@@ -264,10 +264,10 @@ struct CPUMBState {
 /* MSR_UM   (1 << 11) */
 /* MSR_VM   (1 << 13) */
 /* ESR_ESS_MASK [11:5]-- unwind into iflags for unaligned excp */
+#define D_FLAG (1 << 12)  /* Bit in ESR.  */
 #define DRTI_FLAG  (1 << 16)
 #define DRTE_FLAG  (1 << 17)
 #define DRTB_FLAG  (1 << 18)
-#define D_FLAG (1 << 19)  /* Bit in ESR.  */
 
 /* TB dependent CPUMBState.  */
 #define IFLAGS_TB_MASK  (D_FLAG | BIMM_FLAG | IMM_FLAG | \
-- 
2.25.1




[PATCH v2 01/12] target/microblaze: Collected fixes for env->iflags

2020-09-03 Thread Richard Henderson
There are several problems here that can result in soft lockup,
depending on exactly where an interrupt or exception is delivered:

Include BIMM_FLAG in IFLAGS_TB_MASK, since it needs to follow D_FLAG.
Ensure that iflags is 0 when entering an interrupt/exception handler.
Add mb_cpu_synchronize_from_tb to restore iflags from tb->flags.
The change to t_sync_flags is cosmetic, but makes the code clearer.

This fixes the reported regression in acceptance/replay_kernel.py.

Fixes: 683a247ed7a4 ("target/microblaze: Store "current" iflags in insn_start")
Reported-by: Thomas Huth 
Signed-off-by: Richard Henderson 
---
 target/microblaze/cpu.h   |  3 ++-
 target/microblaze/cpu.c   | 11 +++
 target/microblaze/helper.c| 17 +++--
 target/microblaze/translate.c |  4 ++--
 4 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h
index d11b6fa995..a25a2b427f 100644
--- a/target/microblaze/cpu.h
+++ b/target/microblaze/cpu.h
@@ -270,7 +270,8 @@ struct CPUMBState {
 #define D_FLAG (1 << 19)  /* Bit in ESR.  */
 
 /* TB dependent CPUMBState.  */
-#define IFLAGS_TB_MASK  (D_FLAG | IMM_FLAG | DRTI_FLAG | DRTE_FLAG | DRTB_FLAG)
+#define IFLAGS_TB_MASK  (D_FLAG | BIMM_FLAG | IMM_FLAG | \
+ DRTI_FLAG | DRTE_FLAG | DRTB_FLAG)
 #define MSR_TB_MASK (MSR_UM | MSR_VM | MSR_EE)
 
 uint32_t iflags;
diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c
index 67017ecc33..6392524135 100644
--- a/target/microblaze/cpu.c
+++ b/target/microblaze/cpu.c
@@ -80,6 +80,16 @@ static void mb_cpu_set_pc(CPUState *cs, vaddr value)
 MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
 
 cpu->env.pc = value;
+/* Ensure D_FLAG and IMM_FLAG are clear for the new PC */
+cpu->env.iflags = 0;
+}
+
+static void mb_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
+{
+MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
+
+cpu->env.pc = tb->pc;
+cpu->env.iflags = tb->flags & IFLAGS_TB_MASK;
 }
 
 static bool mb_cpu_has_work(CPUState *cs)
@@ -321,6 +331,7 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data)
 cc->cpu_exec_interrupt = mb_cpu_exec_interrupt;
 cc->dump_state = mb_cpu_dump_state;
 cc->set_pc = mb_cpu_set_pc;
+cc->synchronize_from_tb = mb_cpu_synchronize_from_tb;
 cc->gdb_read_register = mb_cpu_gdb_read_register;
 cc->gdb_write_register = mb_cpu_gdb_write_register;
 cc->tlb_fill = mb_cpu_tlb_fill;
diff --git a/target/microblaze/helper.c b/target/microblaze/helper.c
index 48547385b0..00090526da 100644
--- a/target/microblaze/helper.c
+++ b/target/microblaze/helper.c
@@ -113,7 +113,10 @@ void mb_cpu_do_interrupt(CPUState *cs)
 uint32_t t, msr = mb_cpu_read_msr(env);
 
 /* IMM flag cannot propagate across a branch and into the dslot.  */
-assert(!((env->iflags & D_FLAG) && (env->iflags & IMM_FLAG)));
+assert((env->iflags & (D_FLAG | IMM_FLAG)) != (D_FLAG | IMM_FLAG));
+/* BIMM flag cannot be set without D_FLAG. */
+assert((env->iflags & (D_FLAG | BIMM_FLAG)) != BIMM_FLAG);
+/* RTI flags are private to translate. */
 assert(!(env->iflags & (DRTI_FLAG | DRTE_FLAG | DRTB_FLAG)));
 env->res_addr = RES_ADDR_NONE;
 switch (cs->exception_index) {
@@ -146,7 +149,7 @@ void mb_cpu_do_interrupt(CPUState *cs)
   env->pc, env->ear,
   env->esr, env->iflags);
 log_cpu_state_mask(CPU_LOG_INT, cs, 0);
-env->iflags &= ~(IMM_FLAG | D_FLAG);
+env->iflags = 0;
 env->pc = cpu->cfg.base_vectors + 0x20;
 break;
 
@@ -186,14 +189,14 @@ void mb_cpu_do_interrupt(CPUState *cs)
   "exception at pc=%x ear=%" PRIx64 " iflags=%x\n",
   env->pc, env->ear, env->iflags);
 log_cpu_state_mask(CPU_LOG_INT, cs, 0);
-env->iflags &= ~(IMM_FLAG | D_FLAG);
+env->iflags = 0;
 env->pc = cpu->cfg.base_vectors + 0x20;
 break;
 
 case EXCP_IRQ:
 assert(!(msr & (MSR_EIP | MSR_BIP)));
 assert(msr & MSR_IE);
-assert(!(env->iflags & D_FLAG));
+assert(!(env->iflags & (D_FLAG | IMM_FLAG)));
 
 t = (msr & (MSR_VM | MSR_UM)) << 1;
 
@@ -226,13 +229,14 @@ void mb_cpu_do_interrupt(CPUState *cs)
 mb_cpu_write_msr(env, msr);
 
 env->regs[14] = env->pc;
+env->iflags = 0;
 env->pc = cpu->cfg.base_vectors + 0x10;
 //log_cpu_state_mask(CPU_LOG_INT, cs, 0);
 break;
 
 case EXCP_HW_BREAK:
-assert(!(env->iflags & IMM_FLAG));
-assert(!(env->iflags & D_FLAG));
+assert(!(env->iflags & (D_FLAG | IMM_FLAG)));
+
 t = (msr & (MSR_VM | MSR_UM)) << 1;
 qemu_log_mask(CPU_LOG_INT,
   "break at pc=%x msr=%x %x iflags=%x\n",
@@ -242,6 +246,7 @@ void mb_cpu_do_inter

[PATCH v2 00/12] target/microblaze improvements

2020-09-03 Thread Richard Henderson
Version 2 includes fixes for iflags that could cause lockups.

It seems it was easier to do so with icount=7, which is what we do during
the replay acceptance tests.  This causes TBs to contain no more than 7
insns, and often less to make up for an incomplete count elsewhere.
Which stressed the iflags bits around delay slots and imm in ways that
pure single-step doesn't.

In addition, cpu vmstate is filled in and interrupt logging is tidied.


r~


Richard Henderson (12):
  target/microblaze: Collected fixes for env->iflags
  target/microblaze: Renumber D_FLAG
  target/microblaze: Cleanup mb_cpu_do_interrupt
  target/microblaze: Rename mmu structs
  target/microblaze: Fill in VMStateDescription for cpu
  target/microblaze: Rename DISAS_UPDATE to DISAS_EXIT
  target/microblaze: Introduce DISAS_EXIT_NEXT, DISAS_EXIT_JUMP
  target/microblaze: Replace cpustate_changed with DISAS_EXIT_NEXT
  target/microblaze: Handle DISAS_EXIT_NEXT in delay slot
  target/microblaze: Force rtid, rted, rtbd to exit
  target/microblaze: Use tcg_gen_lookup_and_goto_ptr
  target/microblaze: Diagnose invalid insns in delay slots

 target/microblaze/cpu.h   |  11 +-
 target/microblaze/mmu.h   |  15 +--
 target/microblaze/cpu.c   |  19 +--
 target/microblaze/helper.c| 216 +++---
 target/microblaze/machine.c   | 112 ++
 target/microblaze/mmu.c   |  11 +-
 target/microblaze/translate.c | 166 ++
 target/microblaze/meson.build |   5 +-
 8 files changed, 362 insertions(+), 193 deletions(-)
 create mode 100644 target/microblaze/machine.c

-- 
2.25.1




[PATCH v2 10/12] target/microblaze: Force rtid, rted, rtbd to exit

2020-09-03 Thread Richard Henderson
These return-from-exception type instructions have modified
MSR to re-enable various forms of interrupt.  Force a return
to the main loop.

Consolidate the cleanup of tb_flags into mb_tr_translate_insn.

Reviewed-by: Edgar E. Iglesias 
Tested-by: Edgar E. Iglesias 
Signed-off-by: Richard Henderson 
---
 target/microblaze/translate.c | 27 ---
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c
index 608d413c83..da84fdb20b 100644
--- a/target/microblaze/translate.c
+++ b/target/microblaze/translate.c
@@ -1518,7 +1518,6 @@ static void do_rti(DisasContext *dc)
 tcg_gen_or_i32(cpu_msr, cpu_msr, tmp);
 
 tcg_temp_free_i32(tmp);
-dc->tb_flags &= ~DRTI_FLAG;
 }
 
 static void do_rtb(DisasContext *dc)
@@ -1531,7 +1530,6 @@ static void do_rtb(DisasContext *dc)
 tcg_gen_or_i32(cpu_msr, cpu_msr, tmp);
 
 tcg_temp_free_i32(tmp);
-dc->tb_flags &= ~DRTB_FLAG;
 }
 
 static void do_rte(DisasContext *dc)
@@ -1545,7 +1543,6 @@ static void do_rte(DisasContext *dc)
 tcg_gen_or_i32(cpu_msr, cpu_msr, tmp);
 
 tcg_temp_free_i32(tmp);
-dc->tb_flags &= ~DRTE_FLAG;
 }
 
 /* Insns connected to FSL or AXI stream attached devices.  */
@@ -1700,12 +1697,16 @@ static void mb_tr_translate_insn(DisasContextBase *dcb, 
CPUState *cs)
  * Finish any return-from branch.
  * TODO: Diagnose rtXd in delay slot of rtYd earlier.
  */
-if (dc->tb_flags & DRTI_FLAG) {
-do_rti(dc);
-} else if (dc->tb_flags & DRTB_FLAG) {
-do_rtb(dc);
-} else if (dc->tb_flags & DRTE_FLAG) {
-do_rte(dc);
+uint32_t rt_ibe = dc->tb_flags & (DRTI_FLAG | DRTB_FLAG | DRTE_FLAG);
+if (unlikely(rt_ibe != 0)) {
+dc->tb_flags &= ~(DRTI_FLAG | DRTB_FLAG | DRTE_FLAG);
+if (rt_ibe & DRTI_FLAG) {
+do_rti(dc);
+} else if (rt_ibe & DRTB_FLAG) {
+do_rtb(dc);
+} else {
+do_rte(dc);
+}
 }
 
 /* Complete the branch, ending the TB. */
@@ -1723,8 +1724,12 @@ static void mb_tr_translate_insn(DisasContextBase *dcb, 
CPUState *cs)
  */
 break;
 case DISAS_NEXT:
-/* Normal insn a delay slot.  */
-dc->base.is_jmp = DISAS_JUMP;
+/*
+ * Normal insn a delay slot.
+ * However, the return-from-exception type insns should
+ * return to the main loop, as they have adjusted MSR.
+ */
+dc->base.is_jmp = (rt_ibe ? DISAS_EXIT_JUMP : DISAS_JUMP);
 break;
 case DISAS_EXIT_NEXT:
 /*
-- 
2.25.1




[PATCH v2 04/12] target/microblaze: Rename mmu structs

2020-09-03 Thread Richard Henderson
Introduce typedefs and follow CODING_STYLE for naming.
Rename struct microblaze_mmu to MicroBlazeMMU.
Rename struct microblaze_mmu_lookup to MicroBlazeMMULookup.

Signed-off-by: Richard Henderson 
---
 target/microblaze/cpu.h|  2 +-
 target/microblaze/mmu.h| 15 ++-
 target/microblaze/helper.c |  4 ++--
 target/microblaze/mmu.c| 11 +--
 4 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h
index 32811f773d..20c2979396 100644
--- a/target/microblaze/cpu.h
+++ b/target/microblaze/cpu.h
@@ -278,7 +278,7 @@ struct CPUMBState {
 
 #if !defined(CONFIG_USER_ONLY)
 /* Unified MMU.  */
-struct microblaze_mmu mmu;
+MicroBlazeMMU mmu;
 #endif
 
 /* Fields up to this point are cleared by a CPU reset */
diff --git a/target/microblaze/mmu.h b/target/microblaze/mmu.h
index 75e5301c79..c1feb811b9 100644
--- a/target/microblaze/mmu.h
+++ b/target/microblaze/mmu.h
@@ -63,8 +63,7 @@
 
 #define TLB_ENTRIES64
 
-struct microblaze_mmu
-{
+typedef struct {
 /* Data and tag brams.  */
 uint64_t rams[2][TLB_ENTRIES];
 /* We keep a separate ram for the tids to avoid the 48 bit tag width.  */
@@ -76,10 +75,9 @@ struct microblaze_mmu
 int c_mmu_tlb_access;
 int c_mmu_zones;
 uint64_t c_addr_mask; /* Mask to apply to physical addresses.  */
-};
+} MicroBlazeMMU;
 
-struct microblaze_mmu_lookup
-{
+typedef struct {
 uint32_t paddr;
 uint32_t vaddr;
 unsigned int size;
@@ -88,13 +86,12 @@ struct microblaze_mmu_lookup
 enum {
 ERR_PROT, ERR_MISS, ERR_HIT
 } err;
-};
+} MicroBlazeMMULookup;
 
-unsigned int mmu_translate(struct microblaze_mmu *mmu,
-   struct microblaze_mmu_lookup *lu,
+unsigned int mmu_translate(MicroBlazeMMU *mmu, MicroBlazeMMULookup *lu,
target_ulong vaddr, int rw, int mmu_idx);
 uint32_t mmu_read(CPUMBState *env, bool ea, uint32_t rn);
 void mmu_write(CPUMBState *env, bool ea, uint32_t rn, uint32_t v);
-void mmu_init(struct microblaze_mmu *mmu);
+void mmu_init(MicroBlazeMMU *mmu);
 
 #endif
diff --git a/target/microblaze/helper.c b/target/microblaze/helper.c
index 27a24bb99a..3c2fd388fb 100644
--- a/target/microblaze/helper.c
+++ b/target/microblaze/helper.c
@@ -52,7 +52,7 @@ bool mb_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
 {
 MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
 CPUMBState *env = &cpu->env;
-struct microblaze_mmu_lookup lu;
+MicroBlazeMMULookup lu;
 unsigned int hit;
 int prot;
 
@@ -235,7 +235,7 @@ hwaddr mb_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
 MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
 CPUMBState *env = &cpu->env;
 target_ulong vaddr, paddr = 0;
-struct microblaze_mmu_lookup lu;
+MicroBlazeMMULookup lu;
 int mmu_idx = cpu_mmu_index(env, false);
 unsigned int hit;
 
diff --git a/target/microblaze/mmu.c b/target/microblaze/mmu.c
index 6e583d78d9..0546cfd0bc 100644
--- a/target/microblaze/mmu.c
+++ b/target/microblaze/mmu.c
@@ -35,7 +35,7 @@ static unsigned int tlb_decode_size(unsigned int f)
 static void mmu_flush_idx(CPUMBState *env, unsigned int idx)
 {
 CPUState *cs = env_cpu(env);
-struct microblaze_mmu *mmu = &env->mmu;
+MicroBlazeMMU *mmu = &env->mmu;
 unsigned int tlb_size;
 uint32_t tlb_tag, end, t;
 
@@ -55,7 +55,7 @@ static void mmu_flush_idx(CPUMBState *env, unsigned int idx)
 
 static void mmu_change_pid(CPUMBState *env, unsigned int newpid) 
 {
-struct microblaze_mmu *mmu = &env->mmu;
+MicroBlazeMMU *mmu = &env->mmu;
 unsigned int i;
 uint32_t t;
 
@@ -73,8 +73,7 @@ static void mmu_change_pid(CPUMBState *env, unsigned int 
newpid)
 }
 
 /* rw - 0 = read, 1 = write, 2 = fetch.  */
-unsigned int mmu_translate(struct microblaze_mmu *mmu,
-   struct microblaze_mmu_lookup *lu,
+unsigned int mmu_translate(MicroBlazeMMU *mmu, MicroBlazeMMULookup *lu,
target_ulong vaddr, int rw, int mmu_idx)
 {
 unsigned int i, hit = 0;
@@ -290,7 +289,7 @@ void mmu_write(CPUMBState *env, bool ext, uint32_t rn, 
uint32_t v)
 break;
 case MMU_R_TLBSX:
 {
-struct microblaze_mmu_lookup lu;
+MicroBlazeMMULookup lu;
 int hit;
 
 if (env->mmu.c_mmu_tlb_access <= 1) {
@@ -314,7 +313,7 @@ void mmu_write(CPUMBState *env, bool ext, uint32_t rn, 
uint32_t v)
}
 }
 
-void mmu_init(struct microblaze_mmu *mmu)
+void mmu_init(MicroBlazeMMU *mmu)
 {
 int i;
 for (i = 0; i < ARRAY_SIZE(mmu->regs); i++) {
-- 
2.25.1




[PATCH v2 03/12] target/microblaze: Cleanup mb_cpu_do_interrupt

2020-09-03 Thread Richard Henderson
Reindent; remove dead/commented code.
Use D_FLAG to set ESS[DS].
Sink MSR adjustment for kernel entry, iflags and res_addr clear.
Improve CPU_LOG_INT formatting; report pc and msr before and after.

Signed-off-by: Richard Henderson 
---
 target/microblaze/helper.c | 209 -
 1 file changed, 91 insertions(+), 118 deletions(-)

diff --git a/target/microblaze/helper.c b/target/microblaze/helper.c
index 00090526da..27a24bb99a 100644
--- a/target/microblaze/helper.c
+++ b/target/microblaze/helper.c
@@ -111,6 +111,7 @@ void mb_cpu_do_interrupt(CPUState *cs)
 MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
 CPUMBState *env = &cpu->env;
 uint32_t t, msr = mb_cpu_read_msr(env);
+bool set_esr;
 
 /* IMM flag cannot propagate across a branch and into the dslot.  */
 assert((env->iflags & (D_FLAG | IMM_FLAG)) != (D_FLAG | IMM_FLAG));
@@ -118,142 +119,114 @@ void mb_cpu_do_interrupt(CPUState *cs)
 assert((env->iflags & (D_FLAG | BIMM_FLAG)) != BIMM_FLAG);
 /* RTI flags are private to translate. */
 assert(!(env->iflags & (DRTI_FLAG | DRTE_FLAG | DRTB_FLAG)));
-env->res_addr = RES_ADDR_NONE;
+
 switch (cs->exception_index) {
-case EXCP_HW_EXCP:
-if (!(env->pvr.regs[0] & PVR0_USE_EXC_MASK)) {
-qemu_log_mask(LOG_GUEST_ERROR, "Exception raised on system 
without exceptions!\n");
-return;
-}
+case EXCP_HW_EXCP:
+if (!(env->pvr.regs[0] & PVR0_USE_EXC_MASK)) {
+qemu_log_mask(LOG_GUEST_ERROR,
+  "Exception raised on system without exceptions!\n");
+return;
+}
 
-env->regs[17] = env->pc + 4;
-env->esr &= ~(1 << 12);
+qemu_log_mask(CPU_LOG_INT,
+  "INT: HWE at pc=%08x msr=%08x iflags=%x\n",
+  env->pc, msr, env->iflags);
 
-/* Exception breaks branch + dslot sequence?  */
-if (env->iflags & D_FLAG) {
-env->esr |= 1 << 12 ;
-env->btr = env->btarget;
-}
+/* Exception breaks branch + dslot sequence?  */
+set_esr = true;
+env->esr &= ~D_FLAG;
+if (env->iflags & D_FLAG) {
+env->esr |= D_FLAG;
+env->btr = env->btarget;
+}
 
-/* Disable the MMU.  */
-t = (msr & (MSR_VM | MSR_UM)) << 1;
-msr &= ~(MSR_VMS | MSR_UMS | MSR_VM | MSR_UM);
-msr |= t;
-/* Exception in progress.  */
-msr |= MSR_EIP;
-mb_cpu_write_msr(env, msr);
+/* Exception in progress. */
+msr |= MSR_EIP;
+env->regs[17] = env->pc + 4;
+env->pc = cpu->cfg.base_vectors + 0x20;
+break;
 
-qemu_log_mask(CPU_LOG_INT,
-  "hw exception at pc=%x ear=%" PRIx64 " "
-  "esr=%x iflags=%x\n",
-  env->pc, env->ear,
-  env->esr, env->iflags);
-log_cpu_state_mask(CPU_LOG_INT, cs, 0);
-env->iflags = 0;
-env->pc = cpu->cfg.base_vectors + 0x20;
-break;
+case EXCP_MMU:
+qemu_log_mask(CPU_LOG_INT,
+  "INT: MMU at pc=%08x msr=%08x "
+  "ear=%" PRIx64 " iflags=%x\n",
+  env->pc, msr, env->ear, env->iflags);
 
-case EXCP_MMU:
+/* Exception breaks branch + dslot sequence? */
+set_esr = true;
+env->esr &= ~D_FLAG;
+if (env->iflags & D_FLAG) {
+env->esr |= D_FLAG;
+env->btr = env->btarget;
+/* Reexecute the branch. */
+env->regs[17] = env->pc - (env->iflags & BIMM_FLAG ? 8 : 4);
+} else if (env->iflags & IMM_FLAG) {
+/* Reexecute the imm. */
+env->regs[17] = env->pc - 4;
+} else {
 env->regs[17] = env->pc;
+}
 
-qemu_log_mask(CPU_LOG_INT,
-  "MMU exception at pc=%x iflags=%x ear=%" PRIx64 "\n",
-  env->pc, env->iflags, env->ear);
+/* Exception in progress. */
+msr |= MSR_EIP;
+env->pc = cpu->cfg.base_vectors + 0x20;
+break;
 
-env->esr &= ~(1 << 12);
-/* Exception breaks branch + dslot sequence?  */
-if (env->iflags & D_FLAG) {
-env->esr |= 1 << 12 ;
-env->btr = env->btarget;
+case EXCP_IRQ:
+assert(!(msr & (MSR_EIP | MSR_BIP)));
+assert(msr & MSR_IE);
+assert(!(env->iflags & (D_FLAG | IMM_FLAG)));
 
-/* Reexecute the branch.  */
-env->regs[17] -= 4;
-/* was the branch immprefixed?.  */
-if (env->iflags & BIMM_FLAG) {
-env->regs[17] -= 4;
-log_cpu_state_mask(CPU_LOG_INT, cs, 0);
-}
-} else if (env->

[PATCH v2 09/12] target/microblaze: Handle DISAS_EXIT_NEXT in delay slot

2020-09-03 Thread Richard Henderson
It is legal to put an mts instruction into a delay slot.
We should continue to return to the main loop in that
case so that we recognize any pending interrupts.

Reviewed-by: Edgar E. Iglesias 
Tested-by: Edgar E. Iglesias 
Signed-off-by: Richard Henderson 
---
 target/microblaze/translate.c | 34 +-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c
index 6bf299a826..608d413c83 100644
--- a/target/microblaze/translate.c
+++ b/target/microblaze/translate.c
@@ -1696,6 +1696,10 @@ static void mb_tr_translate_insn(DisasContextBase *dcb, 
CPUState *cs)
 dc->base.pc_next += 4;
 
 if (dc->jmp_cond != TCG_COND_NEVER && !(dc->tb_flags & D_FLAG)) {
+/*
+ * Finish any return-from branch.
+ * TODO: Diagnose rtXd in delay slot of rtYd earlier.
+ */
 if (dc->tb_flags & DRTI_FLAG) {
 do_rti(dc);
 } else if (dc->tb_flags & DRTB_FLAG) {
@@ -1703,7 +1707,35 @@ static void mb_tr_translate_insn(DisasContextBase *dcb, 
CPUState *cs)
 } else if (dc->tb_flags & DRTE_FLAG) {
 do_rte(dc);
 }
-dc->base.is_jmp = DISAS_JUMP;
+
+/* Complete the branch, ending the TB. */
+switch (dc->base.is_jmp) {
+case DISAS_NORETURN:
+/*
+ * E.g. illegal insn in a delay slot.  We've already exited
+ * and will handle D_FLAG in mb_cpu_do_interrupt.
+ */
+break;
+case DISAS_EXIT:
+/*
+ * TODO: diagnose brk/brki in delay slot earlier.
+ * This would then fold into the illegal insn case above.
+ */
+break;
+case DISAS_NEXT:
+/* Normal insn a delay slot.  */
+dc->base.is_jmp = DISAS_JUMP;
+break;
+case DISAS_EXIT_NEXT:
+/*
+ * E.g. mts insn in a delay slot.  Continue with btarget,
+ * but still return to the main loop.
+ */
+dc->base.is_jmp = DISAS_EXIT_JUMP;
+break;
+default:
+g_assert_not_reached();
+}
 }
 }
 
-- 
2.25.1




[PATCH v2 05/12] target/microblaze: Fill in VMStateDescription for cpu

2020-09-03 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 target/microblaze/cpu.h   |   4 ++
 target/microblaze/cpu.c   |   8 +--
 target/microblaze/machine.c   | 112 ++
 target/microblaze/meson.build |   5 +-
 4 files changed, 121 insertions(+), 8 deletions(-)
 create mode 100644 target/microblaze/machine.c

diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h
index 20c2979396..133ebaa4d4 100644
--- a/target/microblaze/cpu.h
+++ b/target/microblaze/cpu.h
@@ -419,4 +419,8 @@ static inline int cpu_mmu_index(CPUMBState *env, bool 
ifetch)
 return MMU_KERNEL_IDX;
 }
 
+#ifndef CONFIG_USER_ONLY
+extern const VMStateDescription vmstate_mb_cpu;
+#endif
+
 #endif
diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c
index 6392524135..388605ccca 100644
--- a/target/microblaze/cpu.c
+++ b/target/microblaze/cpu.c
@@ -26,7 +26,6 @@
 #include "cpu.h"
 #include "qemu/module.h"
 #include "hw/qdev-properties.h"
-#include "migration/vmstate.h"
 #include "exec/exec-all.h"
 #include "fpu/softfloat-helpers.h"
 
@@ -254,11 +253,6 @@ static void mb_cpu_initfn(Object *obj)
 #endif
 }
 
-static const VMStateDescription vmstate_mb_cpu = {
-.name = "cpu",
-.unmigratable = 1,
-};
-
 static Property mb_properties[] = {
 DEFINE_PROP_UINT32("base-vectors", MicroBlazeCPU, cfg.base_vectors, 0),
 DEFINE_PROP_BOOL("use-stack-protection", MicroBlazeCPU, cfg.stackprot,
@@ -338,8 +332,8 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data)
 #ifndef CONFIG_USER_ONLY
 cc->do_transaction_failed = mb_cpu_transaction_failed;
 cc->get_phys_page_debug = mb_cpu_get_phys_page_debug;
-#endif
 dc->vmsd = &vmstate_mb_cpu;
+#endif
 device_class_set_props(dc, mb_properties);
 cc->gdb_num_core_regs = 32 + 27;
 
diff --git a/target/microblaze/machine.c b/target/microblaze/machine.c
new file mode 100644
index 00..aad3c5d1d3
--- /dev/null
+++ b/target/microblaze/machine.c
@@ -0,0 +1,112 @@
+/*
+ *  Microblaze VMState for qemu.
+ *
+ *  Copyright (c) 2020 Linaro, Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see .
+ */
+
+#include "qemu/osdep.h"
+#include "cpu.h"
+#include "migration/cpu.h"
+
+
+static VMStateField vmstate_mmu_fields[] = {
+VMSTATE_UINT64_2DARRAY(rams, MicroBlazeMMU, 2, TLB_ENTRIES),
+VMSTATE_UINT8_ARRAY(tids, MicroBlazeMMU, TLB_ENTRIES),
+VMSTATE_UINT32_ARRAY(regs, MicroBlazeMMU, 3),
+VMSTATE_INT32(c_mmu, MicroBlazeMMU),
+VMSTATE_INT32(c_mmu_tlb_access, MicroBlazeMMU),
+VMSTATE_INT32(c_mmu_zones, MicroBlazeMMU),
+VMSTATE_UINT64(c_addr_mask, MicroBlazeMMU),
+VMSTATE_END_OF_LIST()
+};
+
+static const VMStateDescription vmstate_mmu = {
+.name = "mmu",
+.version_id = 0,
+.minimum_version_id = 0,
+.fields = vmstate_mmu_fields,
+};
+
+static int get_msr(QEMUFile *f, void *opaque, size_t size,
+   const VMStateField *field)
+{
+CPUMBState *env = container_of(opaque, CPUMBState, msr);
+
+mb_cpu_write_msr(env, qemu_get_be32(f));
+return 0;
+}
+
+static int put_msr(QEMUFile *f, void *opaque, size_t size,
+   const VMStateField *field, QJSON *vmdesc)
+{
+CPUMBState *env = container_of(opaque, CPUMBState, msr);
+
+qemu_put_be32(f, mb_cpu_read_msr(env));
+return 0;
+}
+
+static const VMStateInfo vmstate_msr = {
+.name = "msr",
+.get = get_msr,
+.put = put_msr,
+};
+
+static VMStateField vmstate_env_fields[] = {
+VMSTATE_UINT32_ARRAY(regs, CPUMBState, 32),
+
+VMSTATE_UINT32(pc, CPUMBState),
+VMSTATE_SINGLE(msr, CPUMBState, 0, vmstate_msr, uint32_t),
+VMSTATE_UINT32(esr, CPUMBState),
+VMSTATE_UINT32(fsr, CPUMBState),
+VMSTATE_UINT32(btr, CPUMBState),
+VMSTATE_UINT32(edr, CPUMBState),
+VMSTATE_UINT32(slr, CPUMBState),
+VMSTATE_UINT32(shr, CPUMBState),
+VMSTATE_UINT64(ear, CPUMBState),
+
+VMSTATE_UINT32(btarget, CPUMBState),
+VMSTATE_UINT32(imm, CPUMBState),
+VMSTATE_UINT32(iflags, CPUMBState),
+
+VMSTATE_UINT32(res_val, CPUMBState),
+VMSTATE_UINTTL(res_addr, CPUMBState),
+
+VMSTATE_UINT32_ARRAY(pvr.regs, CPUMBState, 13),
+
+VMSTATE_STRUCT(mmu, CPUMBState, 0, vmstate_mmu, MicroBlazeMMU),
+
+VMSTATE_END_OF_LIST()
+};
+
+static const VMStateDescription vmstate_env = {
+.name = "env",
+.version_id = 0,
+.minimum_version_id = 0,
+.fields = vmstat

[PATCH v2 07/12] target/microblaze: Introduce DISAS_EXIT_NEXT, DISAS_EXIT_JUMP

2020-09-03 Thread Richard Henderson
Like DISAS_EXIT, except we need to update cpu_pc,
either to pc_next or to btarget respectively.

Reviewed-by: Edgar E. Iglesias 
Tested-by: Edgar E. Iglesias 
Signed-off-by: Richard Henderson 
---
 target/microblaze/translate.c | 29 +
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c
index 8ceb04f4f0..2abef328a3 100644
--- a/target/microblaze/translate.c
+++ b/target/microblaze/translate.c
@@ -39,6 +39,11 @@
 #define DISAS_JUMPDISAS_TARGET_0 /* only pc was modified dynamically */
 #define DISAS_EXITDISAS_TARGET_1 /* all cpu state modified dynamically */
 
+/* cpu state besides pc was modified dynamically; update pc to next */
+#define DISAS_EXIT_NEXT DISAS_TARGET_2
+/* cpu state besides pc was modified dynamically; update pc to btarget */
+#define DISAS_EXIT_JUMP DISAS_TARGET_3
+
 static TCGv_i32 cpu_R[32];
 static TCGv_i32 cpu_pc;
 static TCGv_i32 cpu_msr;
@@ -1712,8 +1717,7 @@ static void mb_tr_translate_insn(DisasContextBase *dcb, 
CPUState *cs)
 
 /* Force an exit if the per-tb cpu state has changed.  */
 if (dc->base.is_jmp == DISAS_NEXT && dc->cpustate_changed) {
-dc->base.is_jmp = DISAS_EXIT;
-tcg_gen_movi_i32(cpu_pc, dc->base.pc_next);
+dc->base.is_jmp = DISAS_EXIT_NEXT;
 }
 }
 
@@ -1734,12 +1738,14 @@ static void mb_tr_tb_stop(DisasContextBase *dcb, 
CPUState *cs)
 return;
 
 case DISAS_EXIT:
-if (unlikely(cs->singlestep_enabled)) {
-gen_raise_exception(dc, EXCP_DEBUG);
-} else {
-tcg_gen_exit_tb(NULL, 0);
-}
-return;
+break;
+case DISAS_EXIT_NEXT:
+tcg_gen_movi_i32(cpu_pc, dc->base.pc_next);
+break;
+case DISAS_EXIT_JUMP:
+tcg_gen_mov_i32(cpu_pc, cpu_btarget);
+tcg_gen_discard_i32(cpu_btarget);
+break;
 
 case DISAS_JUMP:
 if (dc->jmp_dest != -1 && !cs->singlestep_enabled) {
@@ -1781,6 +1787,13 @@ static void mb_tr_tb_stop(DisasContextBase *dcb, 
CPUState *cs)
 default:
 g_assert_not_reached();
 }
+
+/* Finish DISAS_EXIT_* */
+if (unlikely(cs->singlestep_enabled)) {
+gen_raise_exception(dc, EXCP_DEBUG);
+} else {
+tcg_gen_exit_tb(NULL, 0);
+}
 }
 
 static void mb_tr_disas_log(const DisasContextBase *dcb, CPUState *cs)
-- 
2.25.1




[PATCH v2 11/12] target/microblaze: Use tcg_gen_lookup_and_goto_ptr

2020-09-03 Thread Richard Henderson
Normal indirect jumps, or page-crossing direct jumps, can use
tcg_gen_lookup_and_goto_ptr to avoid returning to the main loop
simply to find an existing TB for the next pc.

Reviewed-by: Edgar E. Iglesias 
Tested-by: Edgar E. Iglesias 
Signed-off-by: Richard Henderson 
---
 target/microblaze/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c
index da84fdb20b..d98572fab9 100644
--- a/target/microblaze/translate.c
+++ b/target/microblaze/translate.c
@@ -147,7 +147,7 @@ static void gen_goto_tb(DisasContext *dc, int n, 
target_ulong dest)
 tcg_gen_exit_tb(dc->base.tb, n);
 } else {
 tcg_gen_movi_i32(cpu_pc, dest);
-tcg_gen_exit_tb(NULL, 0);
+tcg_gen_lookup_and_goto_ptr();
 }
 dc->base.is_jmp = DISAS_NORETURN;
 }
@@ -1803,7 +1803,7 @@ static void mb_tr_tb_stop(DisasContextBase *dcb, CPUState 
*cs)
 if (unlikely(cs->singlestep_enabled)) {
 gen_raise_exception(dc, EXCP_DEBUG);
 } else {
-tcg_gen_exit_tb(NULL, 0);
+tcg_gen_lookup_and_goto_ptr();
 }
 return;
 
-- 
2.25.1




[PATCH v2 06/12] target/microblaze: Rename DISAS_UPDATE to DISAS_EXIT

2020-09-03 Thread Richard Henderson
The name "update" suggests that something needs updating, but
this is not the case.  Use "exit" to emphasize that nothing
needs doing except to exit.

Reviewed-by: Edgar E. Iglesias 
Tested-by: Edgar E. Iglesias 
Signed-off-by: Richard Henderson 
---
 target/microblaze/translate.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c
index a8a3249185..8ceb04f4f0 100644
--- a/target/microblaze/translate.c
+++ b/target/microblaze/translate.c
@@ -37,7 +37,7 @@
 
 /* is_jmp field values */
 #define DISAS_JUMPDISAS_TARGET_0 /* only pc was modified dynamically */
-#define DISAS_UPDATE  DISAS_TARGET_1 /* cpu state was modified dynamically */
+#define DISAS_EXITDISAS_TARGET_1 /* all cpu state modified dynamically */
 
 static TCGv_i32 cpu_R[32];
 static TCGv_i32 cpu_pc;
@@ -1161,7 +1161,7 @@ static bool trans_brk(DisasContext *dc, arg_typea_br *arg)
 tcg_gen_ori_i32(cpu_msr, cpu_msr, MSR_BIP);
 tcg_gen_movi_tl(cpu_res_addr, -1);
 
-dc->base.is_jmp = DISAS_UPDATE;
+dc->base.is_jmp = DISAS_EXIT;
 return true;
 }
 
@@ -1202,7 +1202,7 @@ static bool trans_brki(DisasContext *dc, arg_typeb_br 
*arg)
  ~(MSR_VMS | MSR_UMS | MSR_VM | MSR_UM));
 }
 tcg_gen_ori_i32(cpu_msr, cpu_msr, msr_to_set);
-dc->base.is_jmp = DISAS_UPDATE;
+dc->base.is_jmp = DISAS_EXIT;
 #endif
 
 return true;
@@ -1712,7 +1712,7 @@ static void mb_tr_translate_insn(DisasContextBase *dcb, 
CPUState *cs)
 
 /* Force an exit if the per-tb cpu state has changed.  */
 if (dc->base.is_jmp == DISAS_NEXT && dc->cpustate_changed) {
-dc->base.is_jmp = DISAS_UPDATE;
+dc->base.is_jmp = DISAS_EXIT;
 tcg_gen_movi_i32(cpu_pc, dc->base.pc_next);
 }
 }
@@ -1733,7 +1733,7 @@ static void mb_tr_tb_stop(DisasContextBase *dcb, CPUState 
*cs)
 gen_goto_tb(dc, 0, dc->base.pc_next);
 return;
 
-case DISAS_UPDATE:
+case DISAS_EXIT:
 if (unlikely(cs->singlestep_enabled)) {
 gen_raise_exception(dc, EXCP_DEBUG);
 } else {
-- 
2.25.1




[PATCH v2 12/12] target/microblaze: Diagnose invalid insns in delay slots

2020-09-03 Thread Richard Henderson
These cases result in undefined and undocumented behaviour but the
behaviour is deterministic, i.e cores will not lock-up or expose
security issues.  However, RTL will not raise exceptions either.

Therefore, log a GUEST_ERROR and treat these cases as nops, to
avoid corner cases which could put qemu into an invalid state.

Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Richard Henderson 
---
v2: Log pc as well.
---
 target/microblaze/translate.c | 48 ++-
 1 file changed, 41 insertions(+), 7 deletions(-)

diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c
index d98572fab9..ff0cb7dbb6 100644
--- a/target/microblaze/translate.c
+++ b/target/microblaze/translate.c
@@ -179,6 +179,21 @@ static bool trap_userspace(DisasContext *dc, bool cond)
 return cond_user;
 }
 
+/*
+ * Return true, and log an error, if the current insn is
+ * within a delay slot.
+ */
+static bool invalid_delay_slot(DisasContext *dc, const char *insn_type)
+{
+if (dc->tb_flags & D_FLAG) {
+qemu_log_mask(LOG_GUEST_ERROR,
+  "Invalid insn in delay slot: %s at %08x\n",
+  insn_type, (uint32_t)dc->base.pc_next);
+return true;
+}
+return false;
+}
+
 static TCGv_i32 reg_for_read(DisasContext *dc, int reg)
 {
 if (likely(reg != 0)) {
@@ -500,6 +515,9 @@ DO_TYPEA_CFG(idivu, use_div, true, gen_idivu)
 
 static bool trans_imm(DisasContext *dc, arg_imm *arg)
 {
+if (invalid_delay_slot(dc, "imm")) {
+return true;
+}
 dc->ext_imm = arg->imm << 16;
 tcg_gen_movi_i32(cpu_imm, dc->ext_imm);
 dc->tb_flags_to_set = IMM_FLAG;
@@ -1067,6 +1085,9 @@ static bool do_branch(DisasContext *dc, int dest_rb, int 
dest_imm,
 {
 uint32_t add_pc;
 
+if (invalid_delay_slot(dc, "branch")) {
+return true;
+}
 if (delay) {
 setup_dslot(dc, dest_rb < 0);
 }
@@ -1106,6 +1127,9 @@ static bool do_bcc(DisasContext *dc, int dest_rb, int 
dest_imm,
 {
 TCGv_i32 zero, next;
 
+if (invalid_delay_slot(dc, "bcc")) {
+return true;
+}
 if (delay) {
 setup_dslot(dc, dest_rb < 0);
 }
@@ -1158,6 +1182,10 @@ static bool trans_brk(DisasContext *dc, arg_typea_br 
*arg)
 if (trap_userspace(dc, true)) {
 return true;
 }
+if (invalid_delay_slot(dc, "brk")) {
+return true;
+}
+
 tcg_gen_mov_i32(cpu_pc, reg_for_read(dc, arg->rb));
 if (arg->rd) {
 tcg_gen_movi_i32(cpu_R[arg->rd], dc->base.pc_next);
@@ -1176,6 +1204,10 @@ static bool trans_brki(DisasContext *dc, arg_typeb_br 
*arg)
 if (trap_userspace(dc, imm != 0x8 && imm != 0x18)) {
 return true;
 }
+if (invalid_delay_slot(dc, "brki")) {
+return true;
+}
+
 tcg_gen_movi_i32(cpu_pc, imm);
 if (arg->rd) {
 tcg_gen_movi_i32(cpu_R[arg->rd], dc->base.pc_next);
@@ -1216,6 +1248,11 @@ static bool trans_mbar(DisasContext *dc, arg_mbar *arg)
 {
 int mbar_imm = arg->imm;
 
+/* Note that mbar is a specialized branch instruction. */
+if (invalid_delay_slot(dc, "mbar")) {
+return true;
+}
+
 /* Data access memory barrier.  */
 if ((mbar_imm & 2) == 0) {
 tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL);
@@ -1263,6 +1300,10 @@ static bool do_rts(DisasContext *dc, arg_typeb_bc *arg, 
int to_set)
 if (trap_userspace(dc, to_set)) {
 return true;
 }
+if (invalid_delay_slot(dc, "rts")) {
+return true;
+}
+
 dc->tb_flags_to_set |= to_set;
 setup_dslot(dc, true);
 
@@ -1695,7 +1736,6 @@ static void mb_tr_translate_insn(DisasContextBase *dcb, 
CPUState *cs)
 if (dc->jmp_cond != TCG_COND_NEVER && !(dc->tb_flags & D_FLAG)) {
 /*
  * Finish any return-from branch.
- * TODO: Diagnose rtXd in delay slot of rtYd earlier.
  */
 uint32_t rt_ibe = dc->tb_flags & (DRTI_FLAG | DRTB_FLAG | DRTE_FLAG);
 if (unlikely(rt_ibe != 0)) {
@@ -1717,12 +1757,6 @@ static void mb_tr_translate_insn(DisasContextBase *dcb, 
CPUState *cs)
  * and will handle D_FLAG in mb_cpu_do_interrupt.
  */
 break;
-case DISAS_EXIT:
-/*
- * TODO: diagnose brk/brki in delay slot earlier.
- * This would then fold into the illegal insn case above.
- */
-break;
 case DISAS_NEXT:
 /*
  * Normal insn a delay slot.
-- 
2.25.1




[PATCH v3 01/12] configure: fixes dtc not cloned when running msys2 CI

2020-09-03 Thread Yonggang Luo
Symlink dtc after git submodule update, because on win32 symlink to non-exist 
folder are forbidden.

Signed-off-by: Yonggang Luo 
---
 configure | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/configure b/configure
index 8a3acef89d..30f8c4db29 100755
--- a/configure
+++ b/configure
@@ -2053,9 +2053,6 @@ fi
 if test "$meson" = git; then
 git_submodules="${git_submodules} meson"
 fi
-if test "$git_update" = yes; then
-(cd "${source_path}" && GIT="$git" "./scripts/git-submodule.sh" update 
"$git_submodules")
-fi
 
 case "$meson" in
 git | internal)
@@ -4261,9 +4258,6 @@ EOF
   if test -d "${source_path}/dtc/libfdt" || test -e "${source_path}/.git" 
; then
   fdt=git
   mkdir -p dtc
-  if [ "$pwd_is_source_path" != "y" ] ; then
-  symlink "$source_path/dtc/Makefile" "dtc/Makefile"
-  fi
   fdt_cflags="-I${source_path}/dtc/libfdt"
   fdt_ldflags="-L$PWD/dtc/libfdt"
   fdt_libs="$fdt_libs"
@@ -6593,6 +6587,16 @@ if test "$cpu" = "s390x" ; then
   fi
 fi
 
+if test $git_update = 'yes' ; then
+(cd "${source_path}" && GIT="$git" "./scripts/git-submodule.sh" update 
"$git_submodules")
+
+if test "$fdt" = "git" ; then
+if [ "$pwd_is_source_path" != "y" ] ; then
+symlink "$source_path/dtc/Makefile" "dtc/Makefile"
+fi
+fi
+fi
+
 # Check that the C++ compiler exists and works with the C compiler.
 # All the QEMU_CXXFLAGS are based on QEMU_CFLAGS. Keep this at the end to 
don't miss any other that could be added.
 if has $cxx; then
-- 
2.28.0.windows.1




[PATCH v3 05/12] configure: Fix include and linkage issue on msys2

2020-09-03 Thread Yonggang Luo
On msys2, the -I/e/path/to/qemu -L/e/path/to/qemu are not recognized by the 
compiler
Cause $PWD are result posix style path such as /e/path/to/qemu that can not be 
recognized
by mingw gcc, and `pwd -W` are result Windows style path such as 
E:/path/to/qemu that can
be recognized by the mingw gcc. So we replace all $PWD with $build_path that can
building qemu under msys2/mingw environment.

Signed-off-by: Yonggang Luo 
---
 configure | 28 +++-
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/configure b/configure
index 30f8c4db29..5f2bcc4b57 100755
--- a/configure
+++ b/configure
@@ -13,8 +13,13 @@ export CCACHE_RECACHE=yes
 
 # make source path absolute
 source_path=$(cd "$(dirname -- "$0")"; pwd)
+build_path=$PWD
+if [ "$MSYSTEM" = "MINGW64" -o  "$MSYSTEM" = "MINGW32" ]; then
+source_path=$(cd "$(dirname -- "$0")"; pwd -W)
+build_path=`pwd -W`
+fi
 
-if test "$PWD" = "$source_path"
+if test "$build_path" = "$source_path"
 then
 echo "Using './build' as the directory for build output"
 
@@ -346,7 +351,12 @@ ld_has() {
 $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
 }
 
-if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
+check_valid_build_path="[[:space:]:]"
+if [ "$MSYSTEM" = "MINGW64" -o  "$MSYSTEM" = "MINGW32" ]; then
+check_valid_build_path="[[:space:]]"
+fi
+
+if printf %s\\n "$source_path" "$build_path" | grep -q 
"$check_valid_build_path";
 then
   error_exit "main directory cannot contain spaces nor colons"
 fi
@@ -943,7 +953,7 @@ Linux)
   linux="yes"
   linux_user="yes"
   kvm="yes"
-  QEMU_INCLUDES="-isystem ${source_path}/linux-headers -I$PWD/linux-headers 
$QEMU_INCLUDES"
+  QEMU_INCLUDES="-isystem ${source_path}/linux-headers 
-I${build_path}/linux-headers $QEMU_INCLUDES"
   libudev="yes"
 ;;
 esac
@@ -4259,7 +4269,7 @@ EOF
   fdt=git
   mkdir -p dtc
   fdt_cflags="-I${source_path}/dtc/libfdt"
-  fdt_ldflags="-L$PWD/dtc/libfdt"
+  fdt_ldflags="-L${build_path}/dtc/libfdt"
   fdt_libs="$fdt_libs"
   elif test "$fdt" = "yes" ; then
   # Not a git build & no libfdt found, prompt for system install
@@ -5244,7 +5254,7 @@ case "$capstone" in
 else
   LIBCAPSTONE=libcapstone.a
 fi
-capstone_libs="-L$PWD/capstone -lcapstone"
+capstone_libs="-L${build_path}/capstone -lcapstone"
 capstone_cflags="-I${source_path}/capstone/include"
 ;;
 
@@ -6244,8 +6254,8 @@ case "$slirp" in
   git_submodules="${git_submodules} slirp"
 fi
 mkdir -p slirp
-slirp_cflags="-I${source_path}/slirp/src -I$PWD/slirp/src"
-slirp_libs="-L$PWD/slirp -lslirp"
+slirp_cflags="-I${source_path}/slirp/src -I${build_path}/slirp/src"
+slirp_libs="-L${build_path}/slirp -lslirp"
 if test "$mingw32" = "yes" ; then
   slirp_libs="$slirp_libs -lws2_32 -liphlpapi"
 fi
@@ -8190,7 +8200,7 @@ fi
 mv $cross config-meson.cross
 
 rm -rf meson-private meson-info meson-logs
-NINJA=${ninja:-$PWD/ninjatool} $meson setup \
+NINJA=${ninja:-${build_path}/ninjatool} $meson setup \
 --prefix "${pre_prefix}$prefix" \
 --libdir "${pre_prefix}$libdir" \
 --libexecdir "${pre_prefix}$libexecdir" \
@@ -8212,7 +8222,7 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \
-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png 
\
-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\
 $cross_arg \
-"$PWD" "$source_path"
+"$build_path" "$source_path"
 
 if test "$?" -ne 0 ; then
 error_exit "meson setup failed"
-- 
2.28.0.windows.1




[PATCH v3 02/12] meson: Convert undefsym.sh to undefsym.py

2020-09-03 Thread Yonggang Luo
undefsym.sh are not msys2 compatible, convert it to python script

Signed-off-by: Yonggang Luo 
---
 meson.build | 2994 +--
 scripts/undefsym.py |   57 +
 scripts/undefsym.sh |   20 -
 3 files changed, 1554 insertions(+), 1517 deletions(-)
 create mode 100644 scripts/undefsym.py
 delete mode 100755 scripts/undefsym.sh

diff --git a/meson.build b/meson.build
index 55c7d2318c..c9f5d05664 100644
--- a/meson.build
+++ b/meson.build
@@ -1,1497 +1,1497 @@
-project('qemu', ['c'], meson_version: '>=0.55.0',
-default_options: ['warning_level=1', 'c_std=gnu99', 'cpp_std=gnu++11',
-  'b_lundef=false','b_colorout=auto'],
-version: run_command('head', meson.source_root() / 
'VERSION').stdout().strip())
-
-not_found = dependency('', required: false)
-if meson.version().version_compare('>=0.56.0')
-  keyval = import('keyval')
-else
-  keyval = import('unstable-keyval')
-endif
-ss = import('sourceset')
-
-sh = find_program('sh')
-cc = meson.get_compiler('c')
-config_host = keyval.load(meson.current_build_dir() / 'config-host.mak')
-config_all_disas = keyval.load(meson.current_build_dir() / 
'config-all-disas.mak')
-enable_modules = 'CONFIG_MODULES' in config_host
-enable_static = 'CONFIG_STATIC' in config_host
-build_docs = 'BUILD_DOCS' in config_host
-qemu_datadir = get_option('datadir') / get_option('qemu_suffix')
-qemu_docdir = get_option('docdir') / get_option('qemu_suffix')
-config_host_data = configuration_data()
-genh = []
-
-target_dirs = config_host['TARGET_DIRS'].split()
-have_user = false
-have_system = false
-foreach target : target_dirs
-  have_user = have_user or target.endswith('-user')
-  have_system = have_system or target.endswith('-softmmu')
-endforeach
-have_tools = 'CONFIG_TOOLS' in config_host
-have_block = have_system or have_tools
-
-add_project_arguments(config_host['QEMU_CFLAGS'].split(),
-  native: false, language: ['c', 'objc'])
-add_project_arguments(config_host['QEMU_CXXFLAGS'].split(),
-  native: false, language: 'cpp')
-add_project_link_arguments(config_host['QEMU_LDFLAGS'].split(),
-   native: false, language: ['c', 'cpp', 'objc'])
-add_project_arguments(config_host['QEMU_INCLUDES'].split(),
-  language: ['c', 'cpp', 'objc'])
-
-python = import('python').find_installation()
-
-link_language = meson.get_external_property('link_language', 'cpp')
-if link_language == 'cpp'
-  add_languages('cpp', required: true, native: false)
-endif
-if host_machine.system() == 'darwin'
-  add_languages('objc', required: false, native: false)
-endif
-
-if 'SPARSE_CFLAGS' in config_host
-  run_target('sparse',
- command: [find_program('scripts/check_sparse.py'),
-   config_host['SPARSE_CFLAGS'].split(),
-   'compile_commands.json'])
-endif
-
-configure_file(input: files('scripts/ninjatool.py'),
-   output: 'ninjatool',
-   configuration: config_host)
-
-supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 
'sunos', 'linux']
-supported_cpus = ['ppc', 'ppc64', 's390x', 'sparc64', 'riscv32', 'riscv64', 
'x86', 'x86_64',
-  'arm', 'aarch64', 'mips', 'mips64', 'sparc', 'sparc64']
-
-cpu = host_machine.cpu_family()
-targetos = host_machine.system()
-
-m = cc.find_library('m', required: false)
-util = cc.find_library('util', required: false)
-winmm = []
-socket = []
-version_res = []
-coref = []
-iokit = []
-cocoa = []
-hvf = []
-if targetos == 'windows'
-  socket = cc.find_library('ws2_32')
-  winmm = cc.find_library('winmm')
-
-  win = import('windows')
-  version_res = win.compile_resources('version.rc',
-  depend_files: 
files('pc-bios/qemu-nsis.ico'),
-  include_directories: 
include_directories('.'))
-elif targetos == 'darwin'
-  coref = dependency('appleframeworks', modules: 'CoreFoundation')
-  iokit = dependency('appleframeworks', modules: 'IOKit')
-  cocoa = dependency('appleframeworks', modules: 'Cocoa')
-  hvf = dependency('appleframeworks', modules: 'Hypervisor')
-elif targetos == 'sunos'
-  socket = [cc.find_library('socket'),
-cc.find_library('nsl'),
-cc.find_library('resolv')]
-elif targetos == 'haiku'
-  socket = [cc.find_library('posix_error_mapper'),
-cc.find_library('network'),
-cc.find_library('bsd')]
-endif
-glib = declare_dependency(compile_args: config_host['GLIB_CFLAGS'].split(),
-  link_args: config_host['GLIB_LIBS'].split())
-gio = not_found
-if 'CONFIG_GIO' in config_host
-  gio = declare_dependency(compile_args: config_host['GIO_CFLAGS'].split(),
-   link_args: config_host['GIO_LIBS'].split())
-endif
-lttng = not_found
-if 'CONFIG_TRACE_UST' in config_host
-  lttng = declare_dependency(link_args: config_host['LTTNG_UST_LIBS'].split())
-endif
-urcubp = not_found

[PATCH v3 00/12] Green the msys2 CI make

2020-09-03 Thread Yonggang Luo
Also it's fixes issues about make check

Yonggang Luo (12):
  configure: fixes dtc not cloned when running msys2 CI
  meson: Convert undefsym.sh to undefsym.py
  tcg: Fixes dup_const link error
  tests: handling signal on win32 properly
  configure: Fix include and linkage issue on msys2
  block: Fixes nfs on msys2/mingw
  osdep: These function are only available on Non-Win32 system.
  ci: fixes msys2 build by upgrading capstone to 4.0.2
  stubs: qemu_notify_event have no need to stub
  meson: Fixes qapi tests.
  tests: Disable test-image-locking that not works under Win32
  ci: Enable msys2 ci in cirrus

 .cirrus.yml |   108 +-
 block/nfs.c |  1812 +--
 capstone| 2 +-
 configure   | 16560 +-
 include/qemu/osdep.h|  1372 +--
 include/tcg/tcg.h   |  2898 ++---
 meson.build |  2994 ++---
 scripts/ci/windows/msys2_build.sh   |33 +
 scripts/ci/windows/msys2_install.sh |31 +
 scripts/undefsym.py |57 +
 scripts/undefsym.sh |20 -
 stubs/notify-event.c| 8 +-
 tcg/tcg-op-gvec.c   |  7012 +--
 tests/Makefile.include  |  1086 +-
 tests/qapi-schema/meson.build   |   451 +-
 tests/test-replication.c|  1214 +-
 16 files changed, 17904 insertions(+), 17754 deletions(-)
 create mode 100644 scripts/ci/windows/msys2_build.sh
 create mode 100644 scripts/ci/windows/msys2_install.sh
 create mode 100644 scripts/undefsym.py
 delete mode 100755 scripts/undefsym.sh

-- 
2.28.0.windows.1




[PATCH v3 06/12] block: Fixes nfs on msys2/mingw

2020-09-03 Thread Yonggang Luo
Signed-off-by: Yonggang Luo 
---
 block/nfs.c | 1812 ++-
 1 file changed, 910 insertions(+), 902 deletions(-)

diff --git a/block/nfs.c b/block/nfs.c
index 61a249a9fc..34b2cd5708 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -1,902 +1,910 @@
-/*
- * QEMU Block driver for native access to files on NFS shares
- *
- * Copyright (c) 2014-2017 Peter Lieven 
- *
- * 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 "qemu/config-file.h"
-#include "qemu/error-report.h"
-#include "qapi/error.h"
-#include "block/block_int.h"
-#include "block/qdict.h"
-#include "trace.h"
-#include "qemu/iov.h"
-#include "qemu/main-loop.h"
-#include "qemu/module.h"
-#include "qemu/option.h"
-#include "qemu/uri.h"
-#include "qemu/cutils.h"
-#include "sysemu/sysemu.h"
-#include "sysemu/replay.h"
-#include "qapi/qapi-visit-block-core.h"
-#include "qapi/qmp/qdict.h"
-#include "qapi/qmp/qstring.h"
-#include "qapi/qobject-input-visitor.h"
-#include "qapi/qobject-output-visitor.h"
-#include 
-
-
-#define QEMU_NFS_MAX_READAHEAD_SIZE 1048576
-#define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE)
-#define QEMU_NFS_MAX_DEBUG_LEVEL 2
-
-typedef struct NFSClient {
-struct nfs_context *context;
-struct nfsfh *fh;
-int events;
-bool has_zero_init;
-AioContext *aio_context;
-QemuMutex mutex;
-blkcnt_t st_blocks;
-bool cache_used;
-NFSServer *server;
-char *path;
-int64_t uid, gid, tcp_syncnt, readahead, pagecache, debug;
-} NFSClient;
-
-typedef struct NFSRPC {
-BlockDriverState *bs;
-int ret;
-int complete;
-QEMUIOVector *iov;
-struct stat *st;
-Coroutine *co;
-NFSClient *client;
-} NFSRPC;
-
-static int nfs_parse_uri(const char *filename, QDict *options, Error **errp)
-{
-URI *uri = NULL;
-QueryParams *qp = NULL;
-int ret = -EINVAL, i;
-
-uri = uri_parse(filename);
-if (!uri) {
-error_setg(errp, "Invalid URI specified");
-goto out;
-}
-if (g_strcmp0(uri->scheme, "nfs") != 0) {
-error_setg(errp, "URI scheme must be 'nfs'");
-goto out;
-}
-
-if (!uri->server) {
-error_setg(errp, "missing hostname in URI");
-goto out;
-}
-
-if (!uri->path) {
-error_setg(errp, "missing file path in URI");
-goto out;
-}
-
-qp = query_params_parse(uri->query);
-if (!qp) {
-error_setg(errp, "could not parse query parameters");
-goto out;
-}
-
-qdict_put_str(options, "server.host", uri->server);
-qdict_put_str(options, "server.type", "inet");
-qdict_put_str(options, "path", uri->path);
-
-for (i = 0; i < qp->n; i++) {
-unsigned long long val;
-if (!qp->p[i].value) {
-error_setg(errp, "Value for NFS parameter expected: %s",
-   qp->p[i].name);
-goto out;
-}
-if (parse_uint_full(qp->p[i].value, &val, 0)) {
-error_setg(errp, "Illegal value for NFS parameter: %s",
-   qp->p[i].name);
-goto out;
-}
-if (!strcmp(qp->p[i].name, "uid")) {
-qdict_put_str(options, "user", qp->p[i].value);
-} else if (!strcmp(qp->p[i].name, "gid")) {
-qdict_put_str(options, "group", qp->p[i].value);
-} else if (!strcmp(qp->p[i].name, "tcp-syncnt")) {
-qdict_put_str(options, "tcp-syn-count", qp->p[i].value);
-} else if (!strcmp(qp->p[i].name, "readahead")) {
-qdict_put_str(options, "readahead-size", qp->p[i].value);
-} else if (!strcmp(qp->p[i].name, "pagecache")) {
-qdict_put_str(options, "page-cache-size", qp->p[i].value);
-} else if (!strcmp(qp->p[i].name, "debug")) {
-qdict_put_str(options, "debug", qp->p[i].value);
-} else {
-error_setg(errp, "Unknown NFS parameter name: %s",
- 

[PATCH v3 04/12] tests: handling signal on win32 properly

2020-09-03 Thread Yonggang Luo
SIGABRT should use signal(SIGABRT, sigabrt_handler) to handle on win32

The error:
E:/CI-Cor-Ready/xemu/qemu.org/tests/test-replication.c:559:33: error: invalid 
use of undefined type 'struct sigaction'
  559 | sigact = (struct sigaction) {
  | ^

Signed-off-by: Yonggang Luo 
---
 tests/test-replication.c | 1214 +++---
 1 file changed, 609 insertions(+), 605 deletions(-)

diff --git a/tests/test-replication.c b/tests/test-replication.c
index e0b03dafc2..9ab3666a90 100644
--- a/tests/test-replication.c
+++ b/tests/test-replication.c
@@ -1,605 +1,609 @@
-/*
- * Block replication tests
- *
- * Copyright (c) 2016 FUJITSU LIMITED
- * Author: Changlong Xie 
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or
- * later.  See the COPYING file in the top-level directory.
- */
-
-#include "qemu/osdep.h"
-
-#include "qapi/error.h"
-#include "qapi/qmp/qdict.h"
-#include "qemu/option.h"
-#include "qemu/main-loop.h"
-#include "replication.h"
-#include "block/block_int.h"
-#include "block/qdict.h"
-#include "sysemu/block-backend.h"
-
-#define IMG_SIZE (64 * 1024 * 1024)
-
-/* primary */
-#define P_ID "primary-id"
-static char p_local_disk[] = "/tmp/p_local_disk.XX";
-
-/* secondary */
-#define S_ID "secondary-id"
-#define S_LOCAL_DISK_ID "secondary-local-disk-id"
-static char s_local_disk[] = "/tmp/s_local_disk.XX";
-static char s_active_disk[] = "/tmp/s_active_disk.XX";
-static char s_hidden_disk[] = "/tmp/s_hidden_disk.XX";
-
-/* FIXME: steal from blockdev.c */
-QemuOptsList qemu_drive_opts = {
-.name = "drive",
-.head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head),
-.desc = {
-{ /* end of list */ }
-},
-};
-
-#define NOT_DONE 0x7fff
-
-static void blk_rw_done(void *opaque, int ret)
-{
-*(int *)opaque = ret;
-}
-
-static void test_blk_read(BlockBackend *blk, long pattern,
-  int64_t pattern_offset, int64_t pattern_count,
-  int64_t offset, int64_t count,
-  bool expect_failed)
-{
-void *pattern_buf = NULL;
-QEMUIOVector qiov;
-void *cmp_buf = NULL;
-int async_ret = NOT_DONE;
-
-if (pattern) {
-cmp_buf = g_malloc(pattern_count);
-memset(cmp_buf, pattern, pattern_count);
-}
-
-pattern_buf = g_malloc(count);
-if (pattern) {
-memset(pattern_buf, pattern, count);
-} else {
-memset(pattern_buf, 0x00, count);
-}
-
-qemu_iovec_init(&qiov, 1);
-qemu_iovec_add(&qiov, pattern_buf, count);
-
-blk_aio_preadv(blk, offset, &qiov, 0, blk_rw_done, &async_ret);
-while (async_ret == NOT_DONE) {
-main_loop_wait(false);
-}
-
-if (expect_failed) {
-g_assert(async_ret != 0);
-} else {
-g_assert(async_ret == 0);
-if (pattern) {
-g_assert(memcmp(pattern_buf + pattern_offset,
-cmp_buf, pattern_count) <= 0);
-}
-}
-
-g_free(pattern_buf);
-g_free(cmp_buf);
-qemu_iovec_destroy(&qiov);
-}
-
-static void test_blk_write(BlockBackend *blk, long pattern, int64_t offset,
-   int64_t count, bool expect_failed)
-{
-void *pattern_buf = NULL;
-QEMUIOVector qiov;
-int async_ret = NOT_DONE;
-
-pattern_buf = g_malloc(count);
-if (pattern) {
-memset(pattern_buf, pattern, count);
-} else {
-memset(pattern_buf, 0x00, count);
-}
-
-qemu_iovec_init(&qiov, 1);
-qemu_iovec_add(&qiov, pattern_buf, count);
-
-blk_aio_pwritev(blk, offset, &qiov, 0, blk_rw_done, &async_ret);
-while (async_ret == NOT_DONE) {
-main_loop_wait(false);
-}
-
-if (expect_failed) {
-g_assert(async_ret != 0);
-} else {
-g_assert(async_ret == 0);
-}
-
-g_free(pattern_buf);
-qemu_iovec_destroy(&qiov);
-}
-
-/*
- * Create a uniquely-named empty temporary file.
- */
-static void make_temp(char *template)
-{
-int fd;
-
-fd = mkstemp(template);
-g_assert(fd >= 0);
-close(fd);
-}
-
-static void prepare_imgs(void)
-{
-make_temp(p_local_disk);
-make_temp(s_local_disk);
-make_temp(s_active_disk);
-make_temp(s_hidden_disk);
-
-/* Primary */
-bdrv_img_create(p_local_disk, "qcow2", NULL, NULL, NULL, IMG_SIZE,
-BDRV_O_RDWR, true, &error_abort);
-
-/* Secondary */
-bdrv_img_create(s_local_disk, "qcow2", NULL, NULL, NULL, IMG_SIZE,
-BDRV_O_RDWR, true, &error_abort);
-bdrv_img_create(s_active_disk, "qcow2", NULL, NULL, NULL, IMG_SIZE,
-BDRV_O_RDWR, true, &error_abort);
-bdrv_img_create(s_hidden_disk, "qcow2", NULL, NULL, NULL, IMG_SIZE,
-BDRV_O_RDWR, true, &error_abort);
-}
-
-static void cleanup_imgs(void)
-{
-/* Primary */
-unlink(p_local_disk);
-
-/* Secondary */
-unlink(s_local_disk);
-unlink(s_active_disk);
-unlink(s_

[PATCH v3 07/12] osdep: These function are only available on Non-Win32 system.

2020-09-03 Thread Yonggang Luo
int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive);
int qemu_unlock_fd(int fd, int64_t start, int64_t len);
int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive);
bool qemu_has_ofd_lock(void);

Signed-off-by: Yonggang Luo 
---
 include/qemu/osdep.h | 1372 +-
 1 file changed, 686 insertions(+), 686 deletions(-)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 412962d91a..e80fddd1e8 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -1,686 +1,686 @@
-/*
- * OS includes and handling of OS dependencies
- *
- * This header exists to pull in some common system headers that
- * most code in QEMU will want, and to fix up some possible issues with
- * it (missing defines, Windows weirdness, and so on).
- *
- * To avoid getting into possible circular include dependencies, this
- * file should not include any other QEMU headers, with the exceptions
- * of config-host.h, config-target.h, qemu/compiler.h,
- * sysemu/os-posix.h, sysemu/os-win32.h, glib-compat.h and
- * qemu/typedefs.h, all of which are doing a similar job to this file
- * and are under similar constraints.
- *
- * This header also contains prototypes for functions defined in
- * os-*.c and util/oslib-*.c; those would probably be better split
- * out into separate header files.
- *
- * In an ideal world this header would contain only:
- *  (1) things which everybody needs
- *  (2) things without which code would work on most platforms but
- *  fail to compile or misbehave on a minority of host OSes
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- */
-#ifndef QEMU_OSDEP_H
-#define QEMU_OSDEP_H
-
-#include "config-host.h"
-#ifdef NEED_CPU_H
-#include CONFIG_TARGET
-#else
-#include "exec/poison.h"
-#endif
-
-#include "qemu/compiler.h"
-
-/* Older versions of C++ don't get definitions of various macros from
- * stdlib.h unless we define these macros before first inclusion of
- * that system header.
- */
-#ifndef __STDC_CONSTANT_MACROS
-#define __STDC_CONSTANT_MACROS
-#endif
-#ifndef __STDC_LIMIT_MACROS
-#define __STDC_LIMIT_MACROS
-#endif
-#ifndef __STDC_FORMAT_MACROS
-#define __STDC_FORMAT_MACROS
-#endif
-
-/* The following block of code temporarily renames the daemon() function so the
- * compiler does not see the warning associated with it in stdlib.h on OSX
- */
-#ifdef __APPLE__
-#define daemon qemu_fake_daemon_function
-#include 
-#undef daemon
-extern int daemon(int, int);
-#endif
-
-#ifdef _WIN32
-/* as defined in sdkddkver.h */
-#ifndef _WIN32_WINNT
-#define _WIN32_WINNT 0x0600 /* Vista */
-#endif
-/* reduces the number of implicitly included headers */
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-#endif
-
-/* enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) */
-#ifdef __MINGW32__
-#define __USE_MINGW_ANSI_STDIO 1
-#endif
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-/* Put unistd.h before time.h as that triggers localtime_r/gmtime_r
- * function availability on recentish Mingw-w64 platforms. */
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-/* setjmp must be declared before sysemu/os-win32.h
- * because it is redefined there. */
-#include 
-#include 
-
-#ifdef HAVE_SYS_SIGNAL_H
-#include 
-#endif
-
-#ifndef _WIN32
-#include 
-#else
-#define WIFEXITED(x)   1
-#define WEXITSTATUS(x) (x)
-#endif
-
-#ifdef _WIN32
-#include "sysemu/os-win32.h"
-#endif
-
-#ifdef CONFIG_POSIX
-#include "sysemu/os-posix.h"
-#endif
-
-#include "glib-compat.h"
-#include "qemu/typedefs.h"
-
-/*
- * For mingw, as of v6.0.0, the function implementing the assert macro is
- * not marked as noreturn, so the compiler cannot delete code following an
- * assert(false) as unused.  We rely on this within the code base to delete
- * code that is unreachable when features are disabled.
- * All supported versions of Glib's g_assert() satisfy this requirement.
- */
-#ifdef __MINGW32__
-#undef assert
-#define assert(x)  g_assert(x)
-#endif
-
-/*
- * According to waitpid man page:
- * WCOREDUMP
- *  This  macro  is  not  specified  in POSIX.1-2001 and is not
- *  available on some UNIX implementations (e.g., AIX, SunOS).
- *  Therefore, enclose its use inside #ifdef WCOREDUMP ... #endif.
- */
-#ifndef WCOREDUMP
-#define WCOREDUMP(status) 0
-#endif
-/*
- * We have a lot of unaudited code that may fail in strange ways, or
- * even be a security risk during migration, if you disable assertions
- * at compile-time.  You may comment out these safety checks if you
- * absolutely want to disable assertion overhead, but it is not
- * supported upstream so the risk is all yours.  Meanwhile, please
- * submit patches to remove any side-effects inside an assertion, or
- * fixing error handling that should use Error instead of assert.
-

[PATCH v3 10/12] meson: Fixes qapi tests.

2020-09-03 Thread Yonggang Luo
The error are:
+@end table
+
+@end deftypefn
+
make: *** [Makefile.mtest:63: check-qapi-schema] Error 1

Signed-off-by: Yonggang Luo 
---
 tests/qapi-schema/meson.build | 451 +-
 1 file changed, 226 insertions(+), 225 deletions(-)

diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build
index c87d141417..67ba0a5ebd 100644
--- a/tests/qapi-schema/meson.build
+++ b/tests/qapi-schema/meson.build
@@ -1,225 +1,226 @@
-test_env = environment()
-test_env.set('PYTHONPATH', meson.source_root() / 'scripts')
-test_env.set('PYTHONIOENCODING', 'utf-8')
-
-schemas = [
-  'alternate-any.json',
-  'alternate-array.json',
-  'alternate-base.json',
-  'alternate-branch-if-invalid.json',
-  'alternate-clash.json',
-  'alternate-conflict-dict.json',
-  'alternate-conflict-enum-bool.json',
-  'alternate-conflict-enum-int.json',
-  'alternate-conflict-string.json',
-  'alternate-conflict-bool-string.json',
-  'alternate-conflict-num-string.json',
-  'alternate-empty.json',
-  'alternate-invalid-dict.json',
-  'alternate-nested.json',
-  'alternate-unknown.json',
-  'args-alternate.json',
-  'args-any.json',
-  'args-array-empty.json',
-  'args-array-unknown.json',
-  'args-bad-boxed.json',
-  'args-boxed-anon.json',
-  'args-boxed-string.json',
-  'args-int.json',
-  'args-invalid.json',
-  'args-member-array-bad.json',
-  'args-member-case.json',
-  'args-member-unknown.json',
-  'args-name-clash.json',
-  'args-union.json',
-  'args-unknown.json',
-  'bad-base.json',
-  'bad-data.json',
-  'bad-ident.json',
-  'bad-if.json',
-  'bad-if-empty.json',
-  'bad-if-empty-list.json',
-  'bad-if-list.json',
-  'bad-type-bool.json',
-  'bad-type-dict.json',
-  'bad-type-int.json',
-  'base-cycle-direct.json',
-  'base-cycle-indirect.json',
-  'command-int.json',
-  'comments.json',
-  'doc-bad-alternate-member.json',
-  'doc-bad-boxed-command-arg.json',
-  'doc-bad-command-arg.json',
-  'doc-bad-enum-member.json',
-  'doc-bad-event-arg.json',
-  'doc-bad-feature.json',
-  'doc-bad-section.json',
-  'doc-bad-symbol.json',
-  'doc-bad-union-member.json',
-  'doc-before-include.json',
-  'doc-before-pragma.json',
-  'doc-duplicated-arg.json',
-  'doc-duplicated-return.json',
-  'doc-duplicated-since.json',
-  'doc-empty-arg.json',
-  'doc-empty-section.json',
-  'doc-empty-symbol.json',
-  'doc-good.json',
-  'doc-interleaved-section.json',
-  'doc-invalid-end.json',
-  'doc-invalid-end2.json',
-  'doc-invalid-return.json',
-  'doc-invalid-section.json',
-  'doc-invalid-start.json',
-  'doc-missing-colon.json',
-  'doc-missing-expr.json',
-  'doc-missing-space.json',
-  'doc-missing.json',
-  'doc-no-symbol.json',
-  'doc-undoc-feature.json',
-  'double-type.json',
-  'duplicate-key.json',
-  'empty.json',
-  'enum-bad-member.json',
-  'enum-bad-name.json',
-  'enum-bad-prefix.json',
-  'enum-clash-member.json',
-  'enum-dict-member-unknown.json',
-  'enum-if-invalid.json',
-  'enum-int-member.json',
-  'enum-member-case.json',
-  'enum-missing-data.json',
-  'enum-wrong-data.json',
-  'event-boxed-empty.json',
-  'event-case.json',
-  'event-member-invalid-dict.json',
-  'event-nest-struct.json',
-  'features-bad-type.json',
-  'features-deprecated-type.json',
-  'features-duplicate-name.json',
-  'features-if-invalid.json',
-  'features-missing-name.json',
-  'features-name-bad-type.json',
-  'features-no-list.json',
-  'features-unknown-key.json',
-  'flat-union-array-branch.json',
-  'flat-union-bad-base.json',
-  'flat-union-bad-discriminator.json',
-  'flat-union-base-any.json',
-  'flat-union-base-union.json',
-  'flat-union-clash-member.json',
-  'flat-union-discriminator-bad-name.json',
-  'flat-union-empty.json',
-  'flat-union-inline.json',
-  'flat-union-inline-invalid-dict.json',
-  'flat-union-int-branch.json',
-  'flat-union-invalid-branch-key.json',
-  'flat-union-invalid-discriminator.json',
-  'flat-union-invalid-if-discriminator.json',
-  'flat-union-no-base.json',
-  'flat-union-optional-discriminator.json',
-  'flat-union-string-discriminator.json',
-  'funny-char.json',
-  'funny-word.json',
-  'ident-with-escape.json',
-  'include-before-err.json',
-  'include-cycle.json',
-  'include-extra-junk.json',
-  'include-nested-err.json',
-  'include-no-file.json',
-  'include-non-file.json',
-  'include-repetition.json',
-  'include-self-cycle.json',
-  'include-simple.json',
-  'indented-expr.json',
-  'leading-comma-list.json',
-  'leading-comma-object.json',
-  'missing-colon.json',
-  'missing-comma-list.json',
-  'missing-comma-object.json',
-  'missing-type.json',
-  'nested-struct-data.json',
-  'nested-struct-data-invalid-dict.json',
-  'non-objects.json',
-  'oob-test.json',
-  'allow-preconfig-test.json',
-  'pragma-doc-required-crap.json',
-  'pragma-extra-junk.json',
-  'pragma-name-case-whitelist-crap.json',
-  'pragma-non-dict.json',
-  'pragma-unknown.json',
-  'pragma-returns-whitelist-crap.json',
-  'qapi-schema-test.json',
-  'quoted-structural-chars.js

[PATCH v3 09/12] stubs: qemu_notify_event have no need to stub

2020-09-03 Thread Yonggang Luo
  LINKtests/test-qdev-global-props.exe
  LINKtests/test-timed-average.exe
C:/CI-Tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 libqemuutil.a(util_main-loop.c.obj): in function `qemu_notify_event':
C:\work\xemu\qemu-build/../qemu/util/main-loop.c:139: multiple definition of 
`qemu_notify_event'; 
libqemuutil.a(stubs_notify-event.c.obj):C:\work\xemu\qemu-build/../qemu/stubs/notify-event.c:6:
 first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [C:/work/xemu/qemu/rules.mak:88:tests/test-timed-average.exe] 错误 1

Signed-off-by: Yonggang Luo 
---
 stubs/notify-event.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/stubs/notify-event.c b/stubs/notify-event.c
index 827bb52d1a..59935db11e 100644
--- a/stubs/notify-event.c
+++ b/stubs/notify-event.c
@@ -1,6 +1,2 @@
-#include "qemu/osdep.h"
-#include "qemu/main-loop.h"
-
-void qemu_notify_event(void)
-{
-}
+#include "qemu/osdep.h"
+#include "qemu/main-loop.h"
-- 
2.28.0.windows.1




[PATCH v3 12/12] ci: Enable msys2 ci in cirrus

2020-09-03 Thread Yonggang Luo
Install msys2 in a proper way refer to 
https://github.com/cirruslabs/cirrus-ci-docs/issues/699
The https://wiki.qemu.org/Hosts/W32#Native_builds_with_MSYS2 need to be updated.
There is no need of --cross-prefix, open mingw64.exe instead of msys2.exe then 
we don't
need the --cross-prefix, besides using ENV
MSYS: winsymlinks:nativestrict
MSYSTEM: MINGW64
CHERE_INVOKING: 1
to opening mingw64 native shell.

Signed-off-by: Yonggang Luo 
---
 .cirrus.yml | 108 +---
 scripts/ci/windows/msys2_build.sh   |  33 +
 scripts/ci/windows/msys2_install.sh |  31 
 3 files changed, 130 insertions(+), 42 deletions(-)
 create mode 100644 scripts/ci/windows/msys2_build.sh
 create mode 100644 scripts/ci/windows/msys2_install.sh

diff --git a/.cirrus.yml b/.cirrus.yml
index f287d23c5b..0bfb465193 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -1,42 +1,66 @@
-env:
-  CIRRUS_CLONE_DEPTH: 1
-
-freebsd_12_task:
-  freebsd_instance:
-image_family: freebsd-12-1
-cpu: 8
-memory: 8G
-  install_script: ASSUME_ALWAYS_YES=yes pkg bootstrap -f ; pkg install -y
-bash curl cyrus-sasl git glib gmake gnutls gsed
-nettle perl5 pixman pkgconf png usbredir
-  script:
-- mkdir build
-- cd build
-- ../configure || { cat config.log; exit 1; }
-- gmake -j8
-- gmake V=1 check
-
-macos_task:
-  osx_instance:
-image: mojave-base
-  install_script:
-- brew install pkg-config python gnu-sed glib pixman make sdl2 bash
-  script:
-- mkdir build
-- cd build
-- ../configure --python=/usr/local/bin/python3 || { cat config.log; exit 
1; }
-- gmake -j$(sysctl -n hw.ncpu)
-- gmake check
-
-macos_xcode_task:
-  osx_instance:
-# this is an alias for the latest Xcode
-image: mojave-xcode
-  install_script:
-- brew install pkg-config gnu-sed glib pixman make sdl2 bash
-  script:
-- mkdir build
-- cd build
-- ../configure --cc=clang || { cat config.log; exit 1; }
-- gmake -j$(sysctl -n hw.ncpu)
-- gmake check
+env:
+  CIRRUS_CLONE_DEPTH: 1
+
+freebsd_12_task:
+  freebsd_instance:
+image_family: freebsd-12-1
+cpu: 8
+memory: 8G
+  install_script: ASSUME_ALWAYS_YES=yes pkg bootstrap -f ; pkg install -y
+bash curl cyrus-sasl git glib gmake gnutls gsed
+nettle perl5 pixman pkgconf png usbredir
+  script:
+- mkdir build
+- cd build
+- ../configure || { cat config.log; exit 1; }
+- gmake -j8
+- gmake V=1 check
+
+macos_task:
+  osx_instance:
+image: mojave-base
+  install_script:
+- brew install pkg-config python gnu-sed glib pixman make sdl2 bash
+  script:
+- mkdir build
+- cd build
+- ../configure --python=/usr/local/bin/python3 || { cat config.log; exit 
1; }
+- gmake -j$(sysctl -n hw.ncpu)
+- gmake check
+
+macos_xcode_task:
+  osx_instance:
+# this is an alias for the latest Xcode
+image: mojave-xcode
+  install_script:
+- brew install pkg-config gnu-sed glib pixman make sdl2 bash
+  script:
+- mkdir build
+- cd build
+- ../configure --cc=clang || { cat config.log; exit 1; }
+- gmake -j$(sysctl -n hw.ncpu)
+- gmake check
+
+windows_msys2_task:
+  windows_container:
+image: cirrusci/windowsservercore:cmake
+os_version: 2019
+cpu: 8
+memory: 8G
+  env:
+MSYS: winsymlinks:nativestrict
+MSYSTEM: MINGW64
+CHERE_INVOKING: 1
+  printenv_script:
+- C:\tools\msys64\usr\bin\bash.exe -lc 'printenv'
+  install_script:
+- C:\tools\msys64\usr\bin\bash.exe -lc "cd /c/tools && curl -O 
http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz";
+- C:\tools\msys64\usr\bin\bash.exe -lc "cd /c/tools && curl -O 
http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig";
+- C:\tools\msys64\usr\bin\bash.exe -lc "cd /c/tools && pacman -U 
--noconfirm msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz"
+- C:\tools\msys64\usr\bin\bash.exe -lc "pacman -Sy --noconfirm"
+- C:\tools\msys64\usr\bin\bash.exe -lc "pacman --needed --noconfirm -S 
bash pacman pacman-mirrors msys2-runtime"
+- taskkill /F /IM gpg-agent.exe
+- C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -Su"
+- C:\tools\msys64\usr\bin\bash.exe -lc "sh 
scripts/ci/windows/msys2_install.sh"
+  script:
+- C:\tools\msys64\usr\bin\bash.exe -lc "sh 
scripts/ci/windows/msys2_build.sh"
diff --git a/scripts/ci/windows/msys2_build.sh 
b/scripts/ci/windows/msys2_build.sh
new file mode 100644
index 00..3ba89a4206
--- /dev/null
+++ b/scripts/ci/windows/msys2_build.sh
@@ -0,0 +1,33 @@
+mkdir build
+cd build
+../configure \
+  --python=python3 \
+  --enable-gtk --enable-sdl \
+  --enable-capstone=git \
+  --enable-stack-protector \
+  --ninja=ninja \
+  --enable-gnutls \
+  --enable-nettle \
+  --enable-vnc \
+  --enable-vnc-sasl \
+  --enable-vnc-jpeg \
+  --enable-vnc-png \
+  --enable-membarrier \
+  --enable-slirp=git \
+  --disable-kvm \
+  --enable-hax \

[PATCH v3 11/12] tests: Disable test-image-locking that not works under Win32

2020-09-03 Thread Yonggang Luo
Signed-off-by: Yonggang Luo 
---
 tests/Makefile.include | 1086 
 1 file changed, 544 insertions(+), 542 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 9ac8f5b86a..497f1f21ff 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -1,542 +1,544 @@
-# -*- Mode: makefile -*-
-
-.PHONY: check-help
-check-help:
-   @echo "Regression testing targets:"
-   @echo
-   @echo " $(MAKE) checkRun block, qapi-schema, unit, 
softfloat, qtest and decodetree tests"
-   @echo
-   @echo " $(MAKE) check-qtest-TARGET   Run qtest tests for given target"
-   @echo " $(MAKE) check-qtest  Run qtest tests"
-   @echo " $(MAKE) check-unit   Run qobject tests"
-   @echo " $(MAKE) check-speed  Run qobject speed tests"
-   @echo " $(MAKE) check-qapi-schemaRun QAPI schema tests"
-   @echo " $(MAKE) check-block  Run block tests"
-ifeq ($(CONFIG_TCG),y)
-   @echo " $(MAKE) check-tcgRun TCG tests"
-   @echo " $(MAKE) check-softfloat  Run FPU emulation tests"
-endif
-   @echo " $(MAKE) check-acceptance Run all acceptance (functional) 
tests"
-   @echo
-   @echo " $(MAKE) check-report.tap Generates an aggregated TAP test 
report"
-   @echo " $(MAKE) check-venv   Creates a Python venv for tests"
-   @echo " $(MAKE) check-clean  Clean the tests and related data"
-   @echo
-   @echo "The following are useful for CI builds"
-   @echo " $(MAKE) check-build  Build most test binaris"
-   @echo " $(MAKE) get-vm-imagesDownloads all images used by 
acceptance tests, according to configured targets (~350 MB each, 1.5 GB max)"
-   @echo
-   @echo
-   @echo "The variable SPEED can be set to control the gtester speed 
setting."
-   @echo "Default options are -k and (for $(MAKE) V=1) --verbose; they can 
be"
-   @echo "changed with variable GTESTER_OPTIONS."
-
-ifneq ($(wildcard config-host.mak),)
-export SRC_PATH
-
-# TODO don't duplicate $(SRC_PATH)/Makefile's qapi-py here
-qapi-py = $(SRC_PATH)/scripts/qapi/__init__.py \
-$(SRC_PATH)/scripts/qapi/commands.py \
-$(SRC_PATH)/scripts/qapi/common.py \
-$(SRC_PATH)/scripts/qapi/doc.py \
-$(SRC_PATH)/scripts/qapi/error.py \
-$(SRC_PATH)/scripts/qapi/events.py \
-$(SRC_PATH)/scripts/qapi/expr.py \
-$(SRC_PATH)/scripts/qapi/gen.py \
-$(SRC_PATH)/scripts/qapi/introspect.py \
-$(SRC_PATH)/scripts/qapi/parser.py \
-$(SRC_PATH)/scripts/qapi/schema.py \
-$(SRC_PATH)/scripts/qapi/source.py \
-$(SRC_PATH)/scripts/qapi/types.py \
-$(SRC_PATH)/scripts/qapi/visit.py \
-$(SRC_PATH)/scripts/qapi-gen.py
-
-# Get the list of all supported sysemu targets
-SYSEMU_TARGET_LIST := $(subst -softmmu.mak,,$(notdir \
-   $(wildcard $(SRC_PATH)/default-configs/*-softmmu.mak)))
-
-check-unit-y += tests/check-qdict$(EXESUF)
-check-unit-y += tests/check-block-qdict$(EXESUF)
-check-unit-y += tests/check-qnum$(EXESUF)
-check-unit-y += tests/check-qstring$(EXESUF)
-check-unit-y += tests/check-qlist$(EXESUF)
-check-unit-y += tests/check-qnull$(EXESUF)
-check-unit-y += tests/check-qobject$(EXESUF)
-check-unit-y += tests/check-qjson$(EXESUF)
-check-unit-y += tests/check-qlit$(EXESUF)
-check-unit-y += tests/test-qobject-output-visitor$(EXESUF)
-check-unit-y += tests/test-clone-visitor$(EXESUF)
-check-unit-y += tests/test-qobject-input-visitor$(EXESUF)
-check-unit-$(CONFIG_SOFTMMU) += tests/test-qmp-cmds$(EXESUF)
-check-unit-y += tests/test-string-input-visitor$(EXESUF)
-check-unit-y += tests/test-string-output-visitor$(EXESUF)
-check-unit-y += tests/test-qmp-event$(EXESUF)
-check-unit-y += tests/test-opts-visitor$(EXESUF)
-check-unit-$(CONFIG_BLOCK) += tests/test-coroutine$(EXESUF)
-check-unit-y += tests/test-visitor-serialization$(EXESUF)
-check-unit-$(CONFIG_SOFTMMU) += tests/test-iov$(EXESUF)
-check-unit-y += tests/test-bitmap$(EXESUF)
-check-unit-$(CONFIG_BLOCK) += tests/test-aio$(EXESUF)
-check-unit-$(CONFIG_BLOCK) += tests/test-aio-multithread$(EXESUF)
-check-unit-$(CONFIG_BLOCK) += tests/test-throttle$(EXESUF)
-check-unit-$(CONFIG_BLOCK) += tests/test-thread-pool$(EXESUF)
-check-unit-$(CONFIG_BLOCK) += tests/test-hbitmap$(EXESUF)
-check-unit-$(CONFIG_BLOCK) += tests/test-bdrv-drain$(EXESUF)
-check-unit-$(CONFIG_BLOCK) += tests/test-bdrv-graph-mod$(EXESUF)
-check-unit-$(CONFIG_BLOCK) += tests/test-blockjob$(EXESUF)
-check-unit-$(CONFIG_BLOCK) += tests/test-blockjob-txn$(EXESUF)
-check-unit-$(CONFIG_BLOCK) += tests/test-block-backend$(EXESUF)
-check-unit-$(CONFIG_BLOCK) += tests/test-block-iothread$(EXESUF)
-check-unit-$(CONFIG_BLOCK) += tests/test-image-locking$(EXESUF)
-check-unit-y += tests/test-x86-cpuid$(EXESUF)
-# all code tested by test-x86-cpuid is inside topology.h
-ifeq ($(CONFIG_SOFTMMU),y)
-check-unit-y += tests/test-xbzrle$(EXESUF)
-check-unit-$(CONFIG_POSIX) += tests/test-vmstate$(EXESUF)
-endif
-check-unit-y += tests/test-cutils$(EX

Re: [PATCH v3 00/12] Green the msys2 CI make

2020-09-03 Thread Paolo Bonzini
Please send patches more slowly. You already have several queued, and
resending them only adds confusion.

Paolo

Il gio 3 set 2020, 09:43 Yonggang Luo  ha scritto:

> Also it's fixes issues about make check
>
> Yonggang Luo (12):
>   configure: fixes dtc not cloned when running msys2 CI
>   meson: Convert undefsym.sh to undefsym.py
>   tcg: Fixes dup_const link error
>   tests: handling signal on win32 properly
>   configure: Fix include and linkage issue on msys2
>   block: Fixes nfs on msys2/mingw
>   osdep: These function are only available on Non-Win32 system.
>   ci: fixes msys2 build by upgrading capstone to 4.0.2
>   stubs: qemu_notify_event have no need to stub
>   meson: Fixes qapi tests.
>   tests: Disable test-image-locking that not works under Win32
>   ci: Enable msys2 ci in cirrus
>
>  .cirrus.yml |   108 +-
>  block/nfs.c |  1812 +--
>  capstone| 2 +-
>  configure   | 16560 +-
>  include/qemu/osdep.h|  1372 +--
>  include/tcg/tcg.h   |  2898 ++---
>  meson.build |  2994 ++---
>  scripts/ci/windows/msys2_build.sh   |33 +
>  scripts/ci/windows/msys2_install.sh |31 +
>  scripts/undefsym.py |57 +
>  scripts/undefsym.sh |20 -
>  stubs/notify-event.c| 8 +-
>  tcg/tcg-op-gvec.c   |  7012 +--
>  tests/Makefile.include  |  1086 +-
>  tests/qapi-schema/meson.build   |   451 +-
>  tests/test-replication.c|  1214 +-
>  16 files changed, 17904 insertions(+), 17754 deletions(-)
>  create mode 100644 scripts/ci/windows/msys2_build.sh
>  create mode 100644 scripts/ci/windows/msys2_install.sh
>  create mode 100644 scripts/undefsym.py
>  delete mode 100755 scripts/undefsym.sh
>
> --
> 2.28.0.windows.1
>
>
>


Re: [PATCH v3 00/12] Green the msys2 CI make

2020-09-03 Thread Yonggang Luo
On Thu, Sep 3, 2020 at 3:58 PM Paolo Bonzini  wrote:

> Please send patches more slowly. You already have several queued, and
> resending them only adds confusion.
>
> OK, sorry for that.

> Paolo
>
> Il gio 3 set 2020, 09:43 Yonggang Luo  ha scritto:
>
>> Also it's fixes issues about make check
>>
>> Yonggang Luo (12):
>>   configure: fixes dtc not cloned when running msys2 CI
>>   meson: Convert undefsym.sh to undefsym.py
>>   tcg: Fixes dup_const link error
>>   tests: handling signal on win32 properly
>>   configure: Fix include and linkage issue on msys2
>>   block: Fixes nfs on msys2/mingw
>>   osdep: These function are only available on Non-Win32 system.
>>   ci: fixes msys2 build by upgrading capstone to 4.0.2
>>   stubs: qemu_notify_event have no need to stub
>>   meson: Fixes qapi tests.
>>   tests: Disable test-image-locking that not works under Win32
>>   ci: Enable msys2 ci in cirrus
>>
>>  .cirrus.yml |   108 +-
>>  block/nfs.c |  1812 +--
>>  capstone| 2 +-
>>  configure   | 16560 +-
>>  include/qemu/osdep.h|  1372 +--
>>  include/tcg/tcg.h   |  2898 ++---
>>  meson.build |  2994 ++---
>>  scripts/ci/windows/msys2_build.sh   |33 +
>>  scripts/ci/windows/msys2_install.sh |31 +
>>  scripts/undefsym.py |57 +
>>  scripts/undefsym.sh |20 -
>>  stubs/notify-event.c| 8 +-
>>  tcg/tcg-op-gvec.c   |  7012 +--
>>  tests/Makefile.include  |  1086 +-
>>  tests/qapi-schema/meson.build   |   451 +-
>>  tests/test-replication.c|  1214 +-
>>  16 files changed, 17904 insertions(+), 17754 deletions(-)
>>  create mode 100644 scripts/ci/windows/msys2_build.sh
>>  create mode 100644 scripts/ci/windows/msys2_install.sh
>>  create mode 100644 scripts/undefsym.py
>>  delete mode 100755 scripts/undefsym.sh
>>
>> --
>> 2.28.0.windows.1
>>
>>
>>

-- 
 此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo


Re: [PATCH v3 10/12] meson: Fixes qapi tests.

2020-09-03 Thread Paolo Bonzini
Your patch is rewriting the whole file, I think there's a git option to fix
the line endings on commit.

Also the commit message should describe why it's failing. I can see you
added --strip-trailing-cr, but still it should be mentioned.

Paolo

Il gio 3 set 2020, 09:44 Yonggang Luo  ha scritto:

> The error are:
> +@end table
> +
> +@end deftypefn
> +
> make: *** [Makefile.mtest:63: check-qapi-schema] Error 1
>
> Signed-off-by: Yonggang Luo 
> ---
>  tests/qapi-schema/meson.build | 451 +-
>  1 file changed, 226 insertions(+), 225 deletions(-)
>
> diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build
> index c87d141417..67ba0a5ebd 100644
> --- a/tests/qapi-schema/meson.build
> +++ b/tests/qapi-schema/meson.build
> @@ -1,225 +1,226 @@
> -test_env = environment()
> -test_env.set('PYTHONPATH', meson.source_root() / 'scripts')
> -test_env.set('PYTHONIOENCODING', 'utf-8')
> -
> -schemas = [
> -  'alternate-any.json',
> -  'alternate-array.json',
> -  'alternate-base.json',
> -  'alternate-branch-if-invalid.json',
> -  'alternate-clash.json',
> -  'alternate-conflict-dict.json',
> -  'alternate-conflict-enum-bool.json',
> -  'alternate-conflict-enum-int.json',
> -  'alternate-conflict-string.json',
> -  'alternate-conflict-bool-string.json',
> -  'alternate-conflict-num-string.json',
> -  'alternate-empty.json',
> -  'alternate-invalid-dict.json',
> -  'alternate-nested.json',
> -  'alternate-unknown.json',
> -  'args-alternate.json',
> -  'args-any.json',
> -  'args-array-empty.json',
> -  'args-array-unknown.json',
> -  'args-bad-boxed.json',
> -  'args-boxed-anon.json',
> -  'args-boxed-string.json',
> -  'args-int.json',
> -  'args-invalid.json',
> -  'args-member-array-bad.json',
> -  'args-member-case.json',
> -  'args-member-unknown.json',
> -  'args-name-clash.json',
> -  'args-union.json',
> -  'args-unknown.json',
> -  'bad-base.json',
> -  'bad-data.json',
> -  'bad-ident.json',
> -  'bad-if.json',
> -  'bad-if-empty.json',
> -  'bad-if-empty-list.json',
> -  'bad-if-list.json',
> -  'bad-type-bool.json',
> -  'bad-type-dict.json',
> -  'bad-type-int.json',
> -  'base-cycle-direct.json',
> -  'base-cycle-indirect.json',
> -  'command-int.json',
> -  'comments.json',
> -  'doc-bad-alternate-member.json',
> -  'doc-bad-boxed-command-arg.json',
> -  'doc-bad-command-arg.json',
> -  'doc-bad-enum-member.json',
> -  'doc-bad-event-arg.json',
> -  'doc-bad-feature.json',
> -  'doc-bad-section.json',
> -  'doc-bad-symbol.json',
> -  'doc-bad-union-member.json',
> -  'doc-before-include.json',
> -  'doc-before-pragma.json',
> -  'doc-duplicated-arg.json',
> -  'doc-duplicated-return.json',
> -  'doc-duplicated-since.json',
> -  'doc-empty-arg.json',
> -  'doc-empty-section.json',
> -  'doc-empty-symbol.json',
> -  'doc-good.json',
> -  'doc-interleaved-section.json',
> -  'doc-invalid-end.json',
> -  'doc-invalid-end2.json',
> -  'doc-invalid-return.json',
> -  'doc-invalid-section.json',
> -  'doc-invalid-start.json',
> -  'doc-missing-colon.json',
> -  'doc-missing-expr.json',
> -  'doc-missing-space.json',
> -  'doc-missing.json',
> -  'doc-no-symbol.json',
> -  'doc-undoc-feature.json',
> -  'double-type.json',
> -  'duplicate-key.json',
> -  'empty.json',
> -  'enum-bad-member.json',
> -  'enum-bad-name.json',
> -  'enum-bad-prefix.json',
> -  'enum-clash-member.json',
> -  'enum-dict-member-unknown.json',
> -  'enum-if-invalid.json',
> -  'enum-int-member.json',
> -  'enum-member-case.json',
> -  'enum-missing-data.json',
> -  'enum-wrong-data.json',
> -  'event-boxed-empty.json',
> -  'event-case.json',
> -  'event-member-invalid-dict.json',
> -  'event-nest-struct.json',
> -  'features-bad-type.json',
> -  'features-deprecated-type.json',
> -  'features-duplicate-name.json',
> -  'features-if-invalid.json',
> -  'features-missing-name.json',
> -  'features-name-bad-type.json',
> -  'features-no-list.json',
> -  'features-unknown-key.json',
> -  'flat-union-array-branch.json',
> -  'flat-union-bad-base.json',
> -  'flat-union-bad-discriminator.json',
> -  'flat-union-base-any.json',
> -  'flat-union-base-union.json',
> -  'flat-union-clash-member.json',
> -  'flat-union-discriminator-bad-name.json',
> -  'flat-union-empty.json',
> -  'flat-union-inline.json',
> -  'flat-union-inline-invalid-dict.json',
> -  'flat-union-int-branch.json',
> -  'flat-union-invalid-branch-key.json',
> -  'flat-union-invalid-discriminator.json',
> -  'flat-union-invalid-if-discriminator.json',
> -  'flat-union-no-base.json',
> -  'flat-union-optional-discriminator.json',
> -  'flat-union-string-discriminator.json',
> -  'funny-char.json',
> -  'funny-word.json',
> -  'ident-with-escape.json',
> -  'include-before-err.json',
> -  'include-cycle.json',
> -  'include-extra-junk.json',
> -  'include-nested-err.json',
> -  'include-no-file.json',
> -  'include-non-file.json',
> -  'include-repetition.json',
> -  'include-self-cycle.json',
> -  'include-simple.json',
> -  'inde

Re: [PATCH] 9pfs: log warning if msize <= 8192

2020-09-03 Thread Christian Schoenebeck
On Mittwoch, 2. September 2020 18:54:22 CEST Greg Kurz wrote:
> > Well, I can do that of course. But somehow I fear users get lost by just
> > pointing them to "man 1 qemu" in the log message. It already starts that
> > e.g. on Debian there is no "man qemu", it is "man qemu-system" there
> > instead. Next issue is that qemu man page is currently not structured in
> > a way that would> 
> > allow me to directly point them to the relevant man heading like:
> > man --pager='less -p ^9P-msize' qemu
> > 
> > So they would need to scroll their way through the entire man page by
> > themselfes and find confusing sections like "-fsdev -device virtio-9p-pci"
> > vs. "-virtfs", etc. I can imagine some people will struggle with that.
> > 
> > With a link like "https://wiki.qemu.org/Documentation/9psetup#msize"; the
> > thing would be crystal clear within seconds.
> > 
> > Just my opinion. Greg?
> 
> Fine by me for this patch.
> 
> For a longer term, maybe we should find a way to advertise some hint
> for msize to the guest... Not sure how to do that though.

On the long term that would be possible, however only with a protocol change 
allowing server to send minimum, maximum and recommended msize to client.

As you know, right now server only has a say in maximum msize.

Best regards,
Christian Schoenebeck





[PULL 1/8] qapi: enable use of g_autoptr with QAPI types

2020-09-03 Thread Markus Armbruster
From: Daniel P. Berrangé 

Currently QAPI generates a type and function for free'ing it:

  typedef struct QCryptoBlockCreateOptions QCryptoBlockCreateOptions;
  void qapi_free_QCryptoBlockCreateOptions(QCryptoBlockCreateOptions *obj);

This is used in the traditional manner:

  QCryptoBlockCreateOptions *opts = NULL;

  opts = g_new0(QCryptoBlockCreateOptions, 1);

  do stuff with opts...

  qapi_free_QCryptoBlockCreateOptions(opts);

Since bumping the min glib to 2.48, QEMU has incrementally adopted the
use of g_auto/g_autoptr. This allows the compiler to run a function to
free a variable when it goes out of scope, the benefit being the
compiler can guarantee it is freed in all possible code ptahs.

This benefit is applicable to QAPI types too, and given the seriously
long method names for some qapi_free_() functions, is much less
typing. This change thus makes the code generator emit:

 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlockCreateOptions,
  qapi_free_QCryptoBlockCreateOptions)

The above code example now becomes

  g_autoptr(QCryptoBlockCreateOptions) opts = NULL;

  opts = g_new0(QCryptoBlockCreateOptions, 1);

  do stuff with opts...

Note, if the local pointer needs to live beyond the scope holding the
variable, then g_steal_pointer can be used. This is useful to return the
pointer to the caller in the success codepath, while letting it be freed
in all error codepaths.

  return g_steal_pointer(&opts);

The crypto/block.h header needs updating to avoid symbol clash now that
the g_autoptr support is a standard QAPI feature.

Signed-off-by: Daniel P. Berrangé 
Message-Id: <20200723153845.2934357-1-berra...@redhat.com>
Reviewed-by: Markus Armbruster 
Reviewed-by: Eric Blake 
Signed-off-by: Markus Armbruster 
---
 docs/devel/qapi-code-gen.txt   |  2 ++
 include/crypto/block.h |  2 --
 tests/test-qobject-input-visitor.c | 23 +++
 scripts/qapi/types.py  |  1 +
 4 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index 69eede6c28..f3e7ced212 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.txt
@@ -1321,6 +1321,7 @@ Example:
 };
 
 void qapi_free_UserDefOne(UserDefOne *obj);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(UserDefOne, qapi_free_UserDefOne)
 
 struct UserDefOneList {
 UserDefOneList *next;
@@ -1328,6 +1329,7 @@ Example:
 };
 
 void qapi_free_UserDefOneList(UserDefOneList *obj);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(UserDefOneList, qapi_free_UserDefOneList)
 
 struct q_obj_my_command_arg {
 UserDefOneList *arg1;
diff --git a/include/crypto/block.h b/include/crypto/block.h
index d274819791..7a65e8e402 100644
--- a/include/crypto/block.h
+++ b/include/crypto/block.h
@@ -311,7 +311,5 @@ uint64_t qcrypto_block_get_sector_size(QCryptoBlock *block);
 void qcrypto_block_free(QCryptoBlock *block);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlock, qcrypto_block_free)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlockCreateOptions,
-  qapi_free_QCryptoBlockCreateOptions)
 
 #endif /* QCRYPTO_BLOCK_H */
diff --git a/tests/test-qobject-input-visitor.c 
b/tests/test-qobject-input-visitor.c
index 6bacabf063..e41b91a2a6 100644
--- a/tests/test-qobject-input-visitor.c
+++ b/tests/test-qobject-input-visitor.c
@@ -417,7 +417,7 @@ static void test_visitor_in_struct(TestInputVisitorData 
*data,
 static void test_visitor_in_struct_nested(TestInputVisitorData *data,
   const void *unused)
 {
-UserDefTwo *udp = NULL;
+g_autoptr(UserDefTwo) udp = NULL;
 Visitor *v;
 
 v = visitor_input_test_init(data, "{ 'string0': 'string0', "
@@ -433,8 +433,6 @@ static void 
test_visitor_in_struct_nested(TestInputVisitorData *data,
 g_assert_cmpstr(udp->dict1->dict2->userdef->string, ==, "string");
 g_assert_cmpstr(udp->dict1->dict2->string, ==, "string2");
 g_assert(udp->dict1->has_dict3 == false);
-
-qapi_free_UserDefTwo(udp);
 }
 
 static void test_visitor_in_list(TestInputVisitorData *data,
@@ -546,7 +544,7 @@ static void test_visitor_in_union_flat(TestInputVisitorData 
*data,
const void *unused)
 {
 Visitor *v;
-UserDefFlatUnion *tmp;
+g_autoptr(UserDefFlatUnion) tmp = NULL;
 UserDefUnionBase *base;
 
 v = visitor_input_test_init(data,
@@ -563,8 +561,6 @@ static void test_visitor_in_union_flat(TestInputVisitorData 
*data,
 
 base = qapi_UserDefFlatUnion_base(tmp);
 g_assert(&base->enum1 == &tmp->enum1);
-
-qapi_free_UserDefFlatUnion(tmp);
 }
 
 static void test_visitor_in_alternate(TestInputVisitorData *data,
@@ -690,7 +686,7 @@ static void 
test_list_union_integer_helper(TestInputVisitorData *data,
const void *unused,
UserDefListUnionKind kind)
 {
-UserDefListUnion *cv

[PULL 7/8] qapi: Document event VSERPORT_CHANGE is rate-limited

2020-09-03 Thread Markus Armbruster
Commit e2ae6159de "virtio-serial: report frontend connection state via
monitor" neglected to document the new event is rate-limited.  Fix
that.

Cc: Marc-André Lureau 
Cc: Eric Blake 
Signed-off-by: Markus Armbruster 
Message-Id: <20200806081147.3123652-3-arm...@redhat.com>
Reviewed-by: Marc-André Lureau 
---
 qapi/char.json | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/qapi/char.json b/qapi/char.json
index 8aeedf96b2..b4d66ec90b 100644
--- a/qapi/char.json
+++ b/qapi/char.json
@@ -562,6 +562,8 @@
 #
 # @open: true if the guest has opened the virtio-serial port
 #
+# Note: This event is rate-limited.
+#
 # Since: 2.1
 #
 # Example:
-- 
2.26.2




[PULL 4/8] scripts/qmp/qom-fuse: Port to current Python module fuse

2020-09-03 Thread Markus Armbruster
Signed-off-by: Markus Armbruster 
Message-Id: <20200723142738.1868568-3-arm...@redhat.com>
Reviewed-by: John Snow 
---
 scripts/qmp/qom-fuse | 93 ++--
 1 file changed, 47 insertions(+), 46 deletions(-)

diff --git a/scripts/qmp/qom-fuse b/scripts/qmp/qom-fuse
index b7dabe8d65..405e6ebd67 100755
--- a/scripts/qmp/qom-fuse
+++ b/scripts/qmp/qom-fuse
@@ -3,16 +3,18 @@
 # QEMU Object Model test tools
 #
 # Copyright IBM, Corp. 2012
+# Copyright (C) 2020 Red Hat, Inc.
 #
 # Authors:
 #  Anthony Liguori   
+#  Markus Armbruster 
 #
 # This work is licensed under the terms of the GNU GPL, version 2 or later.  
See
 # the COPYING file in the top-level directory.
 ##
 
 import fuse, stat
-from fuse import Fuse
+from fuse import FUSE, FuseOSError, Operations
 import os, posix, sys
 from errno import *
 
@@ -21,9 +23,8 @@ from qemu.qmp import QEMUMonitorProtocol
 
 fuse.fuse_python_api = (0, 2)
 
-class QOMFS(Fuse):
-def __init__(self, qmp, *args, **kwds):
-Fuse.__init__(self, *args, **kwds)
+class QOMFS(Operations):
+def __init__(self, qmp):
 self.qmp = qmp
 self.qmp.connect()
 self.ino_map = {}
@@ -65,21 +66,21 @@ class QOMFS(Fuse):
 except:
 return False
 
-def read(self, path, length, offset):
+def read(self, path, length, offset, fh):
 if not self.is_property(path):
 return -ENOENT
 
 path, prop = path.rsplit('/', 1)
 try:
-data = str(self.qmp.command('qom-get', path=path, property=prop))
+data = self.qmp.command('qom-get', path=path, property=prop)
 data += '\n' # make values shell friendly
 except:
-return -EPERM
+raise FuseOSError(EPERM)
 
 if offset > len(data):
 return ''
 
-return str(data[offset:][:length])
+return bytes(data[offset:][:length], encoding='utf-8')
 
 def readlink(self, path):
 if not self.is_link(path):
@@ -89,52 +90,52 @@ class QOMFS(Fuse):
 return prefix + str(self.qmp.command('qom-get', path=path,
  property=prop))
 
-def getattr(self, path):
+def getattr(self, path, fh=None):
 if self.is_link(path):
-value = posix.stat_result((0o755 | stat.S_IFLNK,
-   self.get_ino(path),
-   0,
-   2,
-   1000,
-   1000,
-   4096,
-   0,
-   0,
-   0))
+value = { 'st_mode': 0o755 | stat.S_IFLNK,
+  'st_ino': self.get_ino(path),
+  'st_dev': 0,
+  'st_nlink': 2,
+  'st_uid': 1000,
+  'st_gid': 1000,
+  'st_size': 4096,
+  'st_atime': 0,
+  'st_mtime': 0,
+  'st_ctime': 0 }
 elif self.is_object(path):
-value = posix.stat_result((0o755 | stat.S_IFDIR,
-   self.get_ino(path),
-   0,
-   2,
-   1000,
-   1000,
-   4096,
-   0,
-   0,
-   0))
+value = { 'st_mode': 0o755 | stat.S_IFDIR,
+  'st_ino': self.get_ino(path),
+  'st_dev': 0,
+  'st_nlink': 2,
+  'st_uid': 1000,
+  'st_gid': 1000,
+  'st_size': 4096,
+  'st_atime': 0,
+  'st_mtime': 0,
+  'st_ctime': 0 }
 elif self.is_property(path):
-value = posix.stat_result((0o644 | stat.S_IFREG,
-   self.get_ino(path),
-   0,
-   1,
-   1000,
-   1000,
-   4096,
-   0,
-   0,
-   0))
+value = { 'st_mode': 0o644 | stat.S_IFREG,
+  'st_ino': self.get_ino(path),
+  'st_dev': 0,
+  'st_nlink': 1,
+  'st_uid': 1000,
+  'st_gid': 1000,
+  'st_size': 4096,
+  'st_atime': 0,
+  'st_mtime': 0,
+  

[PULL 0/8] QAPI patches patches for 2020-09-03

2020-09-03 Thread Markus Armbruster
The following changes since commit ed215cec0fcaeaece064b0fdf37fe3bceb06d76c:

  Merge remote-tracking branch 
'remotes/ehabkost/tags/machine-next-pull-request' into staging (2020-09-02 
15:26:38 +0100)

are available in the Git repository at:

  git://repo.or.cz/qemu/armbru.git tags/pull-qapi-2020-09-03

for you to fetch changes up to 923fbd4cbd485dc72e9f2578cd891607ec43ac70:

  docs/qdev-device-use: Don't suggest -drive and -net can do USB (2020-09-03 
09:58:39 +0200)


QAPI patches patches for 2020-09-03


Daniel P. Berrangé (1):
  qapi: enable use of g_autoptr with QAPI types

Kashyap Chamarthy (1):
  qapi/block-core.json: Remove stale description of 'blockdev-add'

Markus Armbruster (6):
  scripts/qmp/qom-fuse: Unbreak import of QEMUMonitorProtocol
  scripts/qmp/qom-fuse: Port to current Python module fuse
  scripts/qmp/qom-fuse: Fix getattr(), read() for files in /
  docs/interop/qmp-spec: Point to the QEMU QMP reference manual
  qapi: Document event VSERPORT_CHANGE is rate-limited
  docs/qdev-device-use: Don't suggest -drive and -net can do USB

 docs/devel/qapi-code-gen.txt   |   2 +
 docs/interop/qmp-spec.txt  |   9 ++--
 docs/qdev-device-use.txt   |  34 +++-
 qapi/block-core.json   |   4 +-
 qapi/char.json |   2 +
 include/crypto/block.h |   2 -
 tests/test-qobject-input-visitor.c |  23 +++-
 scripts/qapi/types.py  |   1 +
 scripts/qmp/qom-fuse   | 107 -
 9 files changed, 108 insertions(+), 76 deletions(-)

-- 
2.26.2




[PULL 8/8] docs/qdev-device-use: Don't suggest -drive and -net can do USB

2020-09-03 Thread Markus Armbruster
Commit 480324ec8d "docs/qdev-device-use: Clean up the sentences
related to -usbdevice" deleted the information on syntax that no
longer works.  Unfortunately, the resulting text suggests you can
configure USB block devices with -drive, and USB network devices with
-net, which is misleading.

Instead of rephrasing the now misleading text, I'm putting the
information back, and just make clear it's about old versions of QEMU.

Cc: Thomas Huth 
Cc: Gerd Hoffmann 
Signed-off-by: Markus Armbruster 
Message-Id: <20200806081147.3123652-4-arm...@redhat.com>
---
 docs/qdev-device-use.txt | 34 --
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/docs/qdev-device-use.txt b/docs/qdev-device-use.txt
index 9889521e3c..245cdf29c7 100644
--- a/docs/qdev-device-use.txt
+++ b/docs/qdev-device-use.txt
@@ -125,7 +125,14 @@ The -device argument differs in detail for each type of 
drive:
 
 * if=pflash, if=mtd, if=sd, if=xen are not yet available with -device
 
-For USB storage devices, you can use something like:
+For USB devices, the old way was actually different:
+
+-usbdevice disk:format=FMT:FILENAME
+
+"Was" because "disk:" is gone since v2.12.0.
+
+The old way provided much less control than -drive's OPTS...  The new
+way fixes that:
 
 -device usb-storage,drive=DRIVE-ID,removable=RMB
 
@@ -178,6 +185,9 @@ The appropriate DEVNAME depends on the machine type.  For 
type "pc":
 
   -device usb-braille,chardev=braille -chardev braille,id=braille
 
+* -usbdevice serial::chardev is gone since v2.12.0.  It became
+  -device usb-serial,chardev=dev.
+
 LEGACY-CHARDEV translates to -chardev HOST-OPTS... as follows:
 
 * null becomes -chardev null
@@ -231,6 +241,12 @@ The old way to define the guest part looks like this:
 
 -net 
nic,netdev=NET-ID,macaddr=MACADDR,model=MODEL,name=ID,addr=STR,vectors=V
 
+Except for USB it looked like this:
+
+-usbdevice net:netdev=NET-ID,macaddr=MACADDR,name=ID
+
+"Looked" because "net:" is gone since v2.12.0.
+
 The new way is -device:
 
 -device DEVNAME,netdev=NET-ID,mac=MACADDR,DEV-OPTS...
@@ -328,6 +344,13 @@ The new way is -device DEVNAME,DEV-OPTS...  Details depend 
on DRIVER:
 * u2f -device u2f-{emulated,passthru}
 * braille See "Character Devices"
 
+Until v2.12.0, we additionally had
+
+* host:...See "Host Device Assignment"
+* disk:...See "Block Devices"
+* serial:...  See "Character Devices"
+* net:... See "Network Devices"
+
 === Watchdog Devices ===
 
 Host and guest part of watchdog devices have always been separate.
@@ -343,7 +366,14 @@ and host USB devices.  PCI devices can only be assigned 
with -device:
 
 -device vfio-pci,host=ADDR,id=ID
 
-To assign a host USB device use:
+The old way to assign a USB host device
+
+-usbdevice host:auto:BUS.ADDR:VID:PRID
+
+was removed in v2.12.0.  Any of BUS, ADDR, VID, PRID could be the
+wildcard *.
+
+The new way is
 
 -device usb-host,hostbus=BUS,hostaddr=ADDR,vendorid=VID,productid=PRID
 
-- 
2.26.2




[PULL 2/8] qapi/block-core.json: Remove stale description of 'blockdev-add'

2020-09-03 Thread Markus Armbruster
From: Kashyap Chamarthy 

On a 'qemu-discuss' thread[1], Kevin identifies that the current doc
blurb for @blockdev-add is stale:

This is actually a documentation bug. @id doesn't exist,
blockdev-add never creates a BlockBackend. This was different in the
very first versions of the patches to add blockdev-add and we
probably just forgot to update the documentation after removing it.

So remove the stale bits.

And the requirement for 'node-name' is already mentioned in the
documentation of @BlockdevOptions:

[...]
# @node-name: the node name of the new node (Since 2.0).
# This option is required on the top level of blockdev-add.
# Valid node names start with an alphabetic character and may
# contain only alphanumeric characters, '-', '.' and '_'. Their
# maximum length is 31 characters.
[...]

[1] https://lists.nongnu.org/archive/html/qemu-discuss/2020-07/msg00071.html
-- equivalent to "-drive if=ide,id=disk0."

Fixes: be4b67bc7d ("blockdev: Allow creation of BDS trees without BB")

Signed-off-by: Kashyap Chamarthy 
Suggested-by: Kevin Wolf 
Message-Id: <20200805100158.1239390-1-kcham...@redhat.com>
Reviewed-by: Eric Blake 
Signed-off-by: Markus Armbruster 
---
 qapi/block-core.json | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index db08c58d78..55b58ba892 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -4036,9 +4036,7 @@
 ##
 # @blockdev-add:
 #
-# Creates a new block device. If the @id option is given at the top level, a
-# BlockBackend will be created; otherwise, @node-name is mandatory at the top
-# level and no BlockBackend will be created.
+# Creates a new block device.
 #
 # Since: 2.9
 #
-- 
2.26.2




[PULL 5/8] scripts/qmp/qom-fuse: Fix getattr(), read() for files in /

2020-09-03 Thread Markus Armbruster
path, prop = "type".rsplit('/', 1) sets path to "", which doesn't
work.  Correct to "/".

Signed-off-by: Markus Armbruster 
Message-Id: <20200723142738.1868568-4-arm...@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: John Snow 
---
 scripts/qmp/qom-fuse | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/scripts/qmp/qom-fuse b/scripts/qmp/qom-fuse
index 405e6ebd67..7c7cff8edf 100755
--- a/scripts/qmp/qom-fuse
+++ b/scripts/qmp/qom-fuse
@@ -45,8 +45,10 @@ class QOMFS(Operations):
 return False
 
 def is_property(self, path):
+path, prop = path.rsplit('/', 1)
+if path == '':
+path = '/'
 try:
-path, prop = path.rsplit('/', 1)
 for item in self.qmp.command('qom-list', path=path):
 if item['name'] == prop:
 return True
@@ -55,8 +57,10 @@ class QOMFS(Operations):
 return False
 
 def is_link(self, path):
+path, prop = path.rsplit('/', 1)
+if path == '':
+path = '/'
 try:
-path, prop = path.rsplit('/', 1)
 for item in self.qmp.command('qom-list', path=path):
 if item['name'] == prop:
 if item['type'].startswith('link<'):
@@ -71,6 +75,8 @@ class QOMFS(Operations):
 return -ENOENT
 
 path, prop = path.rsplit('/', 1)
+if path == '':
+path = '/'
 try:
 data = self.qmp.command('qom-get', path=path, property=prop)
 data += '\n' # make values shell friendly
-- 
2.26.2




Re: [PATCH] stubs: Move qemu_fd_register stub to util/main-loop.c

2020-09-03 Thread Daniel P . Berrangé
On Thu, Sep 03, 2020 at 07:45:03AM +0200, Thomas Huth wrote:
> The linker of MinGW sometimes runs into the following problem:
> 
> libqemuutil.a(util_main-loop.c.obj): In function `qemu_fd_register':
> /builds/huth/qemu/build/../util/main-loop.c:331: multiple definition of
>  `qemu_fd_register'
> libqemuutil.a(stubs_fd-register.c.obj):/builds/huth/qemu/stubs/fd-register.c:5:
>  first defined here
> collect2: error: ld returned 1 exit status
> /builds/huth/qemu/rules.mak:88: recipe for target 
> 'tests/test-timed-average.exe'
>  failed
> 
> qemu_fd_register() is defined in util/main-loop.c for WIN32, so let's simply
> move the stub also there in the #else part of the corresponding #ifndef
> to fix this problem.
> 
> Signed-off-by: Thomas Huth 
> ---
>  stubs/fd-register.c | 6 --
>  stubs/meson.build   | 1 -
>  util/main-loop.c| 4 

>  3 files changed, 4 insertions(+), 7 deletions(-)
>  delete mode 100644 stubs/fd-register.c

The util/meson.build only adds main-loop.c under 'if have_block'.

Since you didn't remove that conditional, I assume that nothing
built in a "if not have_block" scenario was relying on the existing
stub ?

Assuming the answer is yes and/or CI passes 

Reviewed-by: Daniel P. Berrangé 


Regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|




[PULL 3/8] scripts/qmp/qom-fuse: Unbreak import of QEMUMonitorProtocol

2020-09-03 Thread Markus Armbruster
Commit c7b942d7f8 "scripts/qmp: Fix shebang and imports" messed with
it for reasons I don't quite understand.  I do understand how it fails
now: it neglects to import sys.  Fix that.

It now fails because it expects an old version of module fuse.  That's
next.

Fixes: c7b942d7f84ef54f266921bf7668d43f1f2c7c79
Signed-off-by: Markus Armbruster 
Message-Id: <20200723142738.1868568-2-arm...@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: John Snow 
---
 scripts/qmp/qom-fuse | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/qmp/qom-fuse b/scripts/qmp/qom-fuse
index 5fa6b3bf64..b7dabe8d65 100755
--- a/scripts/qmp/qom-fuse
+++ b/scripts/qmp/qom-fuse
@@ -13,7 +13,7 @@
 
 import fuse, stat
 from fuse import Fuse
-import os, posix
+import os, posix, sys
 from errno import *
 
 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
@@ -134,7 +134,7 @@ class QOMFS(Fuse):
 yield fuse.Direntry(str(item['name']))
 
 if __name__ == '__main__':
-import sys, os
+import os
 
 fs = QOMFS(QEMUMonitorProtocol(os.environ['QMP_SOCKET']))
 fs.main(sys.argv)
-- 
2.26.2




[PULL 6/8] docs/interop/qmp-spec: Point to the QEMU QMP reference manual

2020-09-03 Thread Markus Armbruster
Commit 4d8bb958fa0..231aaf3a821 integrated the contents of
docs/qmp-events.txt into QAPI schema doc comments.  It left dangling
references to qmp-events.txt behind.  Fix to point to the QEMU QMP
reference manual generated from the QAPI schema.

Add a similar reference for commands.

Cc: Marc-André Lureau 
Signed-off-by: Markus Armbruster 
Message-Id: <20200806081147.3123652-2-arm...@redhat.com>
Reviewed-by: Marc-André Lureau 
---
 docs/interop/qmp-spec.txt | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/docs/interop/qmp-spec.txt b/docs/interop/qmp-spec.txt
index adcf86754d..cdf5842555 100644
--- a/docs/interop/qmp-spec.txt
+++ b/docs/interop/qmp-spec.txt
@@ -110,6 +110,9 @@ or
   if provided.  The "id" member can be any json-value.  A json-number
   incremented for each successive command works fine.
 
+The actual commands are documented in the QEMU QMP reference manual
+docs/interop/qemu-qmp-ref.{7,html,info,pdf,txt}.
+
 2.3.1 Out-of-band execution
 ---
 
@@ -207,13 +210,13 @@ The format of asynchronous events is:
   there is a failure to retrieve host time, both members of the
   timestamp will be set to -1.
 
-For a listing of supported asynchronous events, please, refer to the
-qmp-events.txt file.
+The actual asynchronous events are documented in the QEMU QMP
+reference manual docs/interop/qemu-qmp-ref.{7,html,info,pdf,txt}.
 
 Some events are rate-limited to at most one per second.  If additional
 "similar" events arrive within one second, all but the last one are
 dropped, and the last one is delayed.  "Similar" normally means same
-event type.  See qmp-events.txt for details.
+event type.
 
 2.6 Forcing the JSON parser into known-good state
 -
-- 
2.26.2




Re: [PATCH v3 06/12] block: Fixes nfs on msys2/mingw

2020-09-03 Thread Daniel P . Berrangé
On Thu, Sep 03, 2020 at 03:43:07PM +0800, Yonggang Luo wrote:
> Signed-off-by: Yonggang Luo 
> ---
>  block/nfs.c | 1812 ++-
>  1 file changed, 910 insertions(+), 902 deletions(-)

The diff for this file is totally messed up, adding/removing every
single line. I presume you've change line endings to DOS style,
so please revert that.

> 
> diff --git a/block/nfs.c b/block/nfs.c
> index 61a249a9fc..34b2cd5708 100644
> --- a/block/nfs.c
> +++ b/block/nfs.c
> @@ -1,902 +1,910 @@
> -/*
> - * QEMU Block driver for native access to files on NFS shares
> - *
> - * Copyright (c) 2014-2017 Peter Lieven 
> - *
> - * 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 "qemu/config-file.h"
> -#include "qemu/error-report.h"
> -#include "qapi/error.h"
> -#include "block/block_int.h"
> -#include "block/qdict.h"
> -#include "trace.h"
> -#include "qemu/iov.h"
> -#include "qemu/main-loop.h"
> -#include "qemu/module.h"
> -#include "qemu/option.h"
> -#include "qemu/uri.h"
> -#include "qemu/cutils.h"
> -#include "sysemu/sysemu.h"
> -#include "sysemu/replay.h"
> -#include "qapi/qapi-visit-block-core.h"
> -#include "qapi/qmp/qdict.h"
> -#include "qapi/qmp/qstring.h"
> -#include "qapi/qobject-input-visitor.h"
> -#include "qapi/qobject-output-visitor.h"
> -#include 
> -
> -
> -#define QEMU_NFS_MAX_READAHEAD_SIZE 1048576
> -#define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE)
> -#define QEMU_NFS_MAX_DEBUG_LEVEL 2
> -
> -typedef struct NFSClient {
> -struct nfs_context *context;
> -struct nfsfh *fh;
> -int events;
> -bool has_zero_init;
> -AioContext *aio_context;
> -QemuMutex mutex;
> -blkcnt_t st_blocks;
> -bool cache_used;
> -NFSServer *server;
> -char *path;
> -int64_t uid, gid, tcp_syncnt, readahead, pagecache, debug;
> -} NFSClient;
> -
> -typedef struct NFSRPC {
> -BlockDriverState *bs;
> -int ret;
> -int complete;
> -QEMUIOVector *iov;
> -struct stat *st;
> -Coroutine *co;
> -NFSClient *client;
> -} NFSRPC;
> -
> -static int nfs_parse_uri(const char *filename, QDict *options, Error **errp)
> -{
> -URI *uri = NULL;
> -QueryParams *qp = NULL;
> -int ret = -EINVAL, i;
> -
> -uri = uri_parse(filename);
> -if (!uri) {
> -error_setg(errp, "Invalid URI specified");
> -goto out;
> -}
> -if (g_strcmp0(uri->scheme, "nfs") != 0) {
> -error_setg(errp, "URI scheme must be 'nfs'");
> -goto out;
> -}
> -
> -if (!uri->server) {
> -error_setg(errp, "missing hostname in URI");
> -goto out;
> -}
> -
> -if (!uri->path) {
> -error_setg(errp, "missing file path in URI");
> -goto out;
> -}
> -
> -qp = query_params_parse(uri->query);
> -if (!qp) {
> -error_setg(errp, "could not parse query parameters");
> -goto out;
> -}
> -
> -qdict_put_str(options, "server.host", uri->server);
> -qdict_put_str(options, "server.type", "inet");
> -qdict_put_str(options, "path", uri->path);
> -
> -for (i = 0; i < qp->n; i++) {
> -unsigned long long val;
> -if (!qp->p[i].value) {
> -error_setg(errp, "Value for NFS parameter expected: %s",
> -   qp->p[i].name);
> -goto out;
> -}
> -if (parse_uint_full(qp->p[i].value, &val, 0)) {
> -error_setg(errp, "Illegal value for NFS parameter: %s",
> -   qp->p[i].name);
> -goto out;
> -}
> -if (!strcmp(qp->p[i].name, "uid")) {
> -qdict_put_str(options, "user", qp->p[i].value);
> -} else if (!strcmp(qp->p[i].name, "gid")) {
> -qdict_put_str(options, "group", qp->p[i].value);
> -} else if (!strcmp(qp->p[i].name, "tcp-syncnt")) {
> -qdict_put_str(opt

Re: [PATCH v3 07/12] osdep: These function are only available on Non-Win32 system.

2020-09-03 Thread Daniel P . Berrangé
On Thu, Sep 03, 2020 at 03:43:08PM +0800, Yonggang Luo wrote:
> int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive);
> int qemu_unlock_fd(int fd, int64_t start, int64_t len);
> int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive);
> bool qemu_has_ofd_lock(void);
> 
> Signed-off-by: Yonggang Luo 
> ---
>  include/qemu/osdep.h | 1372 +-
>  1 file changed, 686 insertions(+), 686 deletions(-)

Again, the diff is messed up adding/removing every single line.

> 
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index 412962d91a..e80fddd1e8 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -1,686 +1,686 @@
> -/*
> - * OS includes and handling of OS dependencies
> - *
> - * This header exists to pull in some common system headers that
> - * most code in QEMU will want, and to fix up some possible issues with
> - * it (missing defines, Windows weirdness, and so on).
> - *
> - * To avoid getting into possible circular include dependencies, this
> - * file should not include any other QEMU headers, with the exceptions
> - * of config-host.h, config-target.h, qemu/compiler.h,
> - * sysemu/os-posix.h, sysemu/os-win32.h, glib-compat.h and
> - * qemu/typedefs.h, all of which are doing a similar job to this file
> - * and are under similar constraints.
> - *
> - * This header also contains prototypes for functions defined in
> - * os-*.c and util/oslib-*.c; those would probably be better split
> - * out into separate header files.
> - *
> - * In an ideal world this header would contain only:
> - *  (1) things which everybody needs
> - *  (2) things without which code would work on most platforms but
> - *  fail to compile or misbehave on a minority of host OSes
> - *
> - * This work is licensed under the terms of the GNU GPL, version 2 or later.
> - * See the COPYING file in the top-level directory.
> - */
> -#ifndef QEMU_OSDEP_H
> -#define QEMU_OSDEP_H
> -
> -#include "config-host.h"
> -#ifdef NEED_CPU_H
> -#include CONFIG_TARGET
> -#else
> -#include "exec/poison.h"
> -#endif
> -
> -#include "qemu/compiler.h"
> -
> -/* Older versions of C++ don't get definitions of various macros from
> - * stdlib.h unless we define these macros before first inclusion of
> - * that system header.
> - */
> -#ifndef __STDC_CONSTANT_MACROS
> -#define __STDC_CONSTANT_MACROS
> -#endif
> -#ifndef __STDC_LIMIT_MACROS
> -#define __STDC_LIMIT_MACROS
> -#endif
> -#ifndef __STDC_FORMAT_MACROS
> -#define __STDC_FORMAT_MACROS
> -#endif
> -
> -/* The following block of code temporarily renames the daemon() function so 
> the
> - * compiler does not see the warning associated with it in stdlib.h on OSX
> - */
> -#ifdef __APPLE__
> -#define daemon qemu_fake_daemon_function
> -#include 
> -#undef daemon
> -extern int daemon(int, int);
> -#endif
> -
> -#ifdef _WIN32
> -/* as defined in sdkddkver.h */
> -#ifndef _WIN32_WINNT
> -#define _WIN32_WINNT 0x0600 /* Vista */
> -#endif
> -/* reduces the number of implicitly included headers */
> -#ifndef WIN32_LEAN_AND_MEAN
> -#define WIN32_LEAN_AND_MEAN
> -#endif
> -#endif
> -
> -/* enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) */
> -#ifdef __MINGW32__
> -#define __USE_MINGW_ANSI_STDIO 1
> -#endif
> -
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -
> -#include 
> -#include 
> -#include 
> -#include 
> -/* Put unistd.h before time.h as that triggers localtime_r/gmtime_r
> - * function availability on recentish Mingw-w64 platforms. */
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -/* setjmp must be declared before sysemu/os-win32.h
> - * because it is redefined there. */
> -#include 
> -#include 
> -
> -#ifdef HAVE_SYS_SIGNAL_H
> -#include 
> -#endif
> -
> -#ifndef _WIN32
> -#include 
> -#else
> -#define WIFEXITED(x)   1
> -#define WEXITSTATUS(x) (x)
> -#endif
> -
> -#ifdef _WIN32
> -#include "sysemu/os-win32.h"
> -#endif
> -
> -#ifdef CONFIG_POSIX
> -#include "sysemu/os-posix.h"
> -#endif
> -
> -#include "glib-compat.h"
> -#include "qemu/typedefs.h"
> -
> -/*
> - * For mingw, as of v6.0.0, the function implementing the assert macro is
> - * not marked as noreturn, so the compiler cannot delete code following an
> - * assert(false) as unused.  We rely on this within the code base to delete
> - * code that is unreachable when features are disabled.
> - * All supported versions of Glib's g_assert() satisfy this requirement.
> - */
> -#ifdef __MINGW32__
> -#undef assert
> -#define assert(x)  g_assert(x)
> -#endif
> -
> -/*
> - * According to waitpid man page:
> - * WCOREDUMP
> - *  This  macro  is  not  specified  in POSIX.1-2001 and is not
> - *  available on some UNIX implementations (e.g., AIX, SunOS).
> - *  Therefore, enclose its use inside #ifdef WCOREDUMP ... #endif.
> - */
> -#ifndef WCOREDUMP
> -#define WCOREDUMP(status) 0
> -#endif
> -/*
> - * We have a lot

[Bug 1731347] Re: VFIO Passthrough of SAS2008-based HBA card fails on E3-1225v3 due to failed DMA mapping (-14)

2020-09-03 Thread Tony.LI
Hello!
   Has your problem been solved? I also encountered a similar problem. My 
ioctl() also returned an error -14(Bad address).

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

Title:
  VFIO Passthrough of SAS2008-based HBA card fails on E3-1225v3 due to
  failed DMA mapping (-14)

Status in QEMU:
  New

Bug description:
  There is a bug preventing multiple people with my combination of
  hardware from using PCI passthrough. I am not actually sure whether
  the bug is in kernel/kvm, vfio or qemu, however, as qemu is the
  highest-level of these, I am reporting the bug here as you will likely
  know better where the origin of the bug may be found.

  When attempting to pass through this device to a KVM using VFIO, this
  results in error -14 (Bad Address):

  # qemu-system-x86_64 -enable-kvm -m 10G -net none -monitor stdio -serial
  # none -parallel none -vnc :1 -device vfio-pci,host=1:00.0 -S
  QEMU 2.9.1 monitor - type 'help' for more information
  (qemu) c
  (qemu) qemu-system-x86_64: VFIO_MAP_DMA: -14
  qemu-system-x86_64: vfio_dma_map(0x7f548f0a1fc0, 0xfebd, 0x2000, 
0x7f54a909d000) = -14 (Bad address)
  qemu: hardware error: vfio: DMA mapping failed, unable to continue

  See also:
  https://bugzilla.proxmox.com/show_bug.cgi?id=1556
  https://www.redhat.com/archives/vfio-users/2016-May/msg00088.html

  This has occurred on Proxmox (Proxmox and Debian packages, Ubuntu kernel), 
Ubuntu,
  and pure Debian packages and kernel on Proxmox. However, this error
  reportedly does NOT occur for:

  - different distributions(!) (Fedora 24, 25)
  - different HBA cards (SAS2308, SAS3008)
  - different CPU (E3-1220v5)

  I would be thankful for any input and I'll be happy to provide any
  further info necessary. This is my first time delving this deep into
  anything close to the kernel.

  Thanks and best regards,
  Johannes Falke

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



[PATCH v4 00/12] Green the msys2 CI make

2020-09-03 Thread Yonggang Luo
Also it's fixes issues about make check

Yonggang Luo (12):
  configure: fixes dtc not cloned when running msys2 CI
  meson: Convert undefsym.sh to undefsym.py
  tcg: Fixes dup_const link error
  tests: handling signal on win32 properly
  configure: Fix include and linkage issue on msys2
  block: Fixes nfs on msys2/mingw
  osdep: These function are only available on Non-Win32 system.
  ci: fixes msys2 build by upgrading capstone to 4.0.2
  stubs: qemu_notify_event have no need to stub
  meson: Fixes qapi tests.
  tests: Disable test-image-locking that not works under Win32
  ci: Enable msys2 ci in cirrus

 .cirrus.yml | 24 
 block/nfs.c | 26 -
 capstone|  2 +-
 configure   | 48 +++-
 include/qemu/osdep.h|  2 +-
 include/tcg/tcg.h   |  6 +--
 meson.build |  2 +-
 scripts/ci/windows/msys2_build.sh   | 33 +
 scripts/ci/windows/msys2_install.sh | 31 
 scripts/undefsym.py | 57 +
 scripts/undefsym.sh | 20 --
 stubs/notify-event.c|  4 --
 tcg/tcg-op-gvec.c   |  2 +-
 tests/Makefile.include  |  2 +
 tests/qapi-schema/meson.build   |  3 +-
 tests/test-replication.c|  4 ++
 16 files changed, 208 insertions(+), 58 deletions(-)
 create mode 100644 scripts/ci/windows/msys2_build.sh
 create mode 100644 scripts/ci/windows/msys2_install.sh
 create mode 100644 scripts/undefsym.py
 delete mode 100755 scripts/undefsym.sh

-- 
2.28.0.windows.1




[PATCH v4 01/12] configure: fixes dtc not cloned when running msys2 CI

2020-09-03 Thread Yonggang Luo
Symlink dtc after git submodule update, because on win32 symlink to non-exist 
folder are forbidden.

Signed-off-by: Yonggang Luo 
---
 configure | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/configure b/configure
index 8a3acef89d..30f8c4db29 100755
--- a/configure
+++ b/configure
@@ -2053,9 +2053,6 @@ fi
 if test "$meson" = git; then
 git_submodules="${git_submodules} meson"
 fi
-if test "$git_update" = yes; then
-(cd "${source_path}" && GIT="$git" "./scripts/git-submodule.sh" update 
"$git_submodules")
-fi
 
 case "$meson" in
 git | internal)
@@ -4261,9 +4258,6 @@ EOF
   if test -d "${source_path}/dtc/libfdt" || test -e "${source_path}/.git" 
; then
   fdt=git
   mkdir -p dtc
-  if [ "$pwd_is_source_path" != "y" ] ; then
-  symlink "$source_path/dtc/Makefile" "dtc/Makefile"
-  fi
   fdt_cflags="-I${source_path}/dtc/libfdt"
   fdt_ldflags="-L$PWD/dtc/libfdt"
   fdt_libs="$fdt_libs"
@@ -6593,6 +6587,16 @@ if test "$cpu" = "s390x" ; then
   fi
 fi
 
+if test $git_update = 'yes' ; then
+(cd "${source_path}" && GIT="$git" "./scripts/git-submodule.sh" update 
"$git_submodules")
+
+if test "$fdt" = "git" ; then
+if [ "$pwd_is_source_path" != "y" ] ; then
+symlink "$source_path/dtc/Makefile" "dtc/Makefile"
+fi
+fi
+fi
+
 # Check that the C++ compiler exists and works with the C compiler.
 # All the QEMU_CXXFLAGS are based on QEMU_CFLAGS. Keep this at the end to 
don't miss any other that could be added.
 if has $cxx; then
-- 
2.28.0.windows.1




[PATCH v4 02/12] meson: Convert undefsym.sh to undefsym.py

2020-09-03 Thread Yonggang Luo
undefsym.sh are not msys2 compatible, convert it to python script

Signed-off-by: Yonggang Luo 
---
 meson.build |  2 +-
 scripts/undefsym.py | 57 +
 scripts/undefsym.sh | 20 
 3 files changed, 58 insertions(+), 21 deletions(-)
 create mode 100644 scripts/undefsym.py
 delete mode 100755 scripts/undefsym.sh

diff --git a/meson.build b/meson.build
index 55c7d2318c..c9f5d05664 100644
--- a/meson.build
+++ b/meson.build
@@ -863,7 +863,7 @@ foreach d, list : modules
 endforeach
 
 nm = find_program('nm')
-undefsym = find_program('scripts/undefsym.sh')
+undefsym = find_program('scripts/undefsym.py')
 block_syms = custom_target('block.syms', output: 'block.syms',
  input: [libqemuutil, block_mods],
  capture: true,
diff --git a/scripts/undefsym.py b/scripts/undefsym.py
new file mode 100644
index 00..c690f88c7a
--- /dev/null
+++ b/scripts/undefsym.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+# Before a shared module's DSO is produced, a static library is built for it
+# and passed to this script.  The script generates -Wl,-u options to force
+# the inclusion of symbol from libqemuutil.a if the shared modules need them,
+# This is necessary because the modules may use functions not needed by the
+# executable itself, which would cause the function to not be linked in.
+# Then the DSO loading would fail because of the missing symbol.
+
+
+"""
+Compare the static library with the shared module for compute the symbol 
duplication
+"""
+
+import sys
+import subprocess
+
+def filter_lines_set(stdout, is_static = True):
+linesSet = set()
+for line in stdout.splitlines():
+tokens = line.split(b' ')
+if len(tokens) >= 1:
+if len(tokens) > 1:
+if is_static and tokens[1] == b'U':
+continue
+if not is_static and tokens[1] != b'U':
+continue
+new_line = b'-Wl,-u,' + tokens[0]
+if not new_line in linesSet:
+linesSet.add(new_line)
+return linesSet
+
+def main(args):
+if len(args) <= 3:
+sys.exit(0)
+
+nm = args[1]
+staticlib = args[2]
+pc = subprocess.run([nm, "-P", "-g", staticlib], stdout=subprocess.PIPE)
+if pc.returncode != 0:
+sys.exit(-1)
+lines_set_left = filter_lines_set(pc.stdout)
+
+shared_modules = args[3:]
+pc = subprocess.run([nm, "-P", "-g"] + shared_modules, 
stdout=subprocess.PIPE)
+if pc.returncode != 0:
+sys.exit(-1)
+lines_set_right = filter_lines_set(pc.stdout, False)
+lines = []
+for line in sorted(list(lines_set_right)):
+if line in lines_set_left:
+lines.append(line)
+sys.stdout.write(b'\n'.join(lines).decode())
+
+if __name__ == "__main__":
+main(sys.argv)
diff --git a/scripts/undefsym.sh b/scripts/undefsym.sh
deleted file mode 100755
index b9ec332e95..00
--- a/scripts/undefsym.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#! /usr/bin/env bash
-
-# Before a shared module's DSO is produced, a static library is built for it
-# and passed to this script.  The script generates -Wl,-u options to force
-# the inclusion of symbol from libqemuutil.a if the shared modules need them,
-# This is necessary because the modules may use functions not needed by the
-# executable itself, which would cause the function to not be linked in.
-# Then the DSO loading would fail because of the missing symbol.
-
-if test $# -le 2; then
-  exit 0
-fi
-
-NM=$1
-staticlib=$2
-shift 2
-# Find symbols defined in static libraries and undefined in shared modules
-comm -12 \
-  <( $NM -P -g $staticlib | awk '$2!="U"{print "-Wl,-u," $1}' | sort -u) \
-  <( $NM -P -g "$@" | awk '$2=="U"{print "-Wl,-u," $1}' | sort -u)
-- 
2.28.0.windows.1




[PATCH v4 09/12] stubs: qemu_notify_event have no need to stub

2020-09-03 Thread Yonggang Luo
  LINKtests/test-qdev-global-props.exe
  LINKtests/test-timed-average.exe
C:/CI-Tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 libqemuutil.a(util_main-loop.c.obj): in function `qemu_notify_event':
C:\work\xemu\qemu-build/../qemu/util/main-loop.c:139: multiple definition of 
`qemu_notify_event'; 
libqemuutil.a(stubs_notify-event.c.obj):C:\work\xemu\qemu-build/../qemu/stubs/notify-event.c:6:
 first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [C:/work/xemu/qemu/rules.mak:88:tests/test-timed-average.exe] 错误 1

Signed-off-by: Yonggang Luo 
---
 stubs/notify-event.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/stubs/notify-event.c b/stubs/notify-event.c
index 827bb52d1a..59935db11e 100644
--- a/stubs/notify-event.c
+++ b/stubs/notify-event.c
@@ -1,6 +1,2 @@
 #include "qemu/osdep.h"
 #include "qemu/main-loop.h"
-
-void qemu_notify_event(void)
-{
-}
-- 
2.28.0.windows.1




Re: [PATCH v3 00/12] Green the msys2 CI make

2020-09-03 Thread Daniel P . Berrangé
On Thu, Sep 03, 2020 at 03:43:01PM +0800, Yonggang Luo wrote:
> Also it's fixes issues about make check
> 
> Yonggang Luo (12):
>   configure: fixes dtc not cloned when running msys2 CI
>   meson: Convert undefsym.sh to undefsym.py
>   tcg: Fixes dup_const link error
>   tests: handling signal on win32 properly
>   configure: Fix include and linkage issue on msys2
>   block: Fixes nfs on msys2/mingw
>   osdep: These function are only available on Non-Win32 system.
>   ci: fixes msys2 build by upgrading capstone to 4.0.2
>   stubs: qemu_notify_event have no need to stub
>   meson: Fixes qapi tests.
>   tests: Disable test-image-locking that not works under Win32
>   ci: Enable msys2 ci in cirrus
> 
>  .cirrus.yml |   108 +-
>  block/nfs.c |  1812 +--
>  capstone| 2 +-
>  configure   | 16560 +-
>  include/qemu/osdep.h|  1372 +--
>  include/tcg/tcg.h   |  2898 ++---
>  meson.build |  2994 ++---
>  scripts/ci/windows/msys2_build.sh   |33 +
>  scripts/ci/windows/msys2_install.sh |31 +
>  scripts/undefsym.py |57 +
>  scripts/undefsym.sh |20 -
>  stubs/notify-event.c| 8 +-
>  tcg/tcg-op-gvec.c   |  7012 +--
>  tests/Makefile.include  |  1086 +-
>  tests/qapi-schema/meson.build   |   451 +-
>  tests/test-replication.c|  1214 +-
>  16 files changed, 17904 insertions(+), 17754 deletions(-)

This whole series is messed up adding/removing 1000's of lines of
code with no change. I'm assuming you've introduced DOS line
endings causing a massive diff


Regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|




[PATCH v4 04/12] tests: handling signal on win32 properly

2020-09-03 Thread Yonggang Luo
SIGABRT should use signal(SIGABRT, sigabrt_handler) to handle on win32

The error:
E:/CI-Cor-Ready/xemu/qemu.org/tests/test-replication.c:559:33: error: invalid 
use of undefined type 'struct sigaction'
  559 | sigact = (struct sigaction) {
  | ^

Signed-off-by: Yonggang Luo 
---
 tests/test-replication.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/tests/test-replication.c b/tests/test-replication.c
index e0b03dafc2..9ab3666a90 100644
--- a/tests/test-replication.c
+++ b/tests/test-replication.c
@@ -554,6 +554,9 @@ static void sigabrt_handler(int signo)
 
 static void setup_sigabrt_handler(void)
 {
+#ifdef _WIN32
+signal(SIGABRT, sigabrt_handler);
+#else
 struct sigaction sigact;
 
 sigact = (struct sigaction) {
@@ -562,6 +565,7 @@ static void setup_sigabrt_handler(void)
 };
 sigemptyset(&sigact.sa_mask);
 sigaction(SIGABRT, &sigact, NULL);
+#endif
 }
 
 int main(int argc, char **argv)
-- 
2.28.0.windows.1




[PATCH v4 03/12] tcg: Fixes dup_const link error

2020-09-03 Thread Yonggang Luo
Rename function dup_const to dup_const_eval for avoid confliction with macro 
dup_const

The link error on msys2

Linking target qemu-system-alpha.exe
C:/CI-Tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 libqemu-alpha-softmmu.fa.p/tcg_optimize.c.obj: in function `tcg_optimize':
E:\CI-Cor-Ready\xemu\qemu-build/../qemu.org/tcg/optimize.c:1106: undefined 
reference to `dup_const'
C:/CI-Tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 libqemu-alpha-softmmu.fa.p/tcg_tcg-op-vec.c.obj: in function 
`tcg_gen_dupi_vec':
E:\CI-Cor-Ready\xemu\qemu-build/../qemu.org/tcg/tcg-op-vec.c:283: undefined 
reference to `dup_const'
collect2.exe: error: ld returned 1 exit status

Signed-off-by: Yonggang Luo 
---
 include/tcg/tcg.h | 6 +++---
 tcg/tcg-op-gvec.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index 53ce94c2c5..7f6fe8454b 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -1251,15 +1251,15 @@ static inline int tcg_can_emit_vec_op(TCGOpcode o, 
TCGType t, unsigned ve)
 void tcg_expand_vec_op(TCGOpcode, TCGType, unsigned, TCGArg, ...);
 
 /* Replicate a constant C accoring to the log2 of the element size.  */
-uint64_t dup_const(unsigned vece, uint64_t c);
+uint64_t dup_const_eval(unsigned vece, uint64_t c);
 
 #define dup_const(VECE, C) \
 (__builtin_constant_p(VECE)\
  ? (  (VECE) == MO_8  ? 0x0101010101010101ull * (uint8_t)(C)   \
 : (VECE) == MO_16 ? 0x0001000100010001ull * (uint16_t)(C)  \
 : (VECE) == MO_32 ? 0x00010001ull * (uint32_t)(C)  \
-: dup_const(VECE, C))  \
- : dup_const(VECE, C))
+: dup_const_eval(VECE, C))  \
+ : dup_const_eval(VECE, C))
 
 
 /*
diff --git a/tcg/tcg-op-gvec.c b/tcg/tcg-op-gvec.c
index 3707c0effb..cbb6cd04bc 100644
--- a/tcg/tcg-op-gvec.c
+++ b/tcg/tcg-op-gvec.c
@@ -359,7 +359,7 @@ static inline bool check_size_impl(uint32_t oprsz, uint32_t 
lnsz)
 static void expand_clr(uint32_t dofs, uint32_t maxsz);
 
 /* Duplicate C as per VECE.  */
-uint64_t (dup_const)(unsigned vece, uint64_t c)
+uint64_t dup_const_eval(unsigned vece, uint64_t c)
 {
 switch (vece) {
 case MO_8:
-- 
2.28.0.windows.1




[PATCH v4 07/12] osdep: These function are only available on Non-Win32 system.

2020-09-03 Thread Yonggang Luo
int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive);
int qemu_unlock_fd(int fd, int64_t start, int64_t len);
int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive);
bool qemu_has_ofd_lock(void);

Signed-off-by: Yonggang Luo 
---
 include/qemu/osdep.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 412962d91a..e80fddd1e8 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -502,11 +502,11 @@ int qemu_close(int fd);
 int qemu_unlink(const char *name);
 #ifndef _WIN32
 int qemu_dup(int fd);
-#endif
 int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive);
 int qemu_unlock_fd(int fd, int64_t start, int64_t len);
 int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive);
 bool qemu_has_ofd_lock(void);
+#endif
 
 #if defined(__HAIKU__) && defined(__i386__)
 #define FMT_pid "%ld"
-- 
2.28.0.windows.1




[PATCH v4 05/12] configure: Fix include and linkage issue on msys2

2020-09-03 Thread Yonggang Luo
On msys2, the -I/e/path/to/qemu -L/e/path/to/qemu are not recognized by the 
compiler
Cause $PWD are result posix style path such as /e/path/to/qemu that can not be 
recognized
by mingw gcc, and `pwd -W` are result Windows style path such as 
E:/path/to/qemu that can
be recognized by the mingw gcc. So we replace all $PWD with $build_path that can
building qemu under msys2/mingw environment.

Signed-off-by: Yonggang Luo 
---
 configure | 28 +++-
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/configure b/configure
index 30f8c4db29..5f2bcc4b57 100755
--- a/configure
+++ b/configure
@@ -13,8 +13,13 @@ export CCACHE_RECACHE=yes
 
 # make source path absolute
 source_path=$(cd "$(dirname -- "$0")"; pwd)
+build_path=$PWD
+if [ "$MSYSTEM" = "MINGW64" -o  "$MSYSTEM" = "MINGW32" ]; then
+source_path=$(cd "$(dirname -- "$0")"; pwd -W)
+build_path=`pwd -W`
+fi
 
-if test "$PWD" = "$source_path"
+if test "$build_path" = "$source_path"
 then
 echo "Using './build' as the directory for build output"
 
@@ -346,7 +351,12 @@ ld_has() {
 $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
 }
 
-if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";
+check_valid_build_path="[[:space:]:]"
+if [ "$MSYSTEM" = "MINGW64" -o  "$MSYSTEM" = "MINGW32" ]; then
+check_valid_build_path="[[:space:]]"
+fi
+
+if printf %s\\n "$source_path" "$build_path" | grep -q 
"$check_valid_build_path";
 then
   error_exit "main directory cannot contain spaces nor colons"
 fi
@@ -943,7 +953,7 @@ Linux)
   linux="yes"
   linux_user="yes"
   kvm="yes"
-  QEMU_INCLUDES="-isystem ${source_path}/linux-headers -I$PWD/linux-headers 
$QEMU_INCLUDES"
+  QEMU_INCLUDES="-isystem ${source_path}/linux-headers 
-I${build_path}/linux-headers $QEMU_INCLUDES"
   libudev="yes"
 ;;
 esac
@@ -4259,7 +4269,7 @@ EOF
   fdt=git
   mkdir -p dtc
   fdt_cflags="-I${source_path}/dtc/libfdt"
-  fdt_ldflags="-L$PWD/dtc/libfdt"
+  fdt_ldflags="-L${build_path}/dtc/libfdt"
   fdt_libs="$fdt_libs"
   elif test "$fdt" = "yes" ; then
   # Not a git build & no libfdt found, prompt for system install
@@ -5244,7 +5254,7 @@ case "$capstone" in
 else
   LIBCAPSTONE=libcapstone.a
 fi
-capstone_libs="-L$PWD/capstone -lcapstone"
+capstone_libs="-L${build_path}/capstone -lcapstone"
 capstone_cflags="-I${source_path}/capstone/include"
 ;;
 
@@ -6244,8 +6254,8 @@ case "$slirp" in
   git_submodules="${git_submodules} slirp"
 fi
 mkdir -p slirp
-slirp_cflags="-I${source_path}/slirp/src -I$PWD/slirp/src"
-slirp_libs="-L$PWD/slirp -lslirp"
+slirp_cflags="-I${source_path}/slirp/src -I${build_path}/slirp/src"
+slirp_libs="-L${build_path}/slirp -lslirp"
 if test "$mingw32" = "yes" ; then
   slirp_libs="$slirp_libs -lws2_32 -liphlpapi"
 fi
@@ -8190,7 +8200,7 @@ fi
 mv $cross config-meson.cross
 
 rm -rf meson-private meson-info meson-logs
-NINJA=${ninja:-$PWD/ninjatool} $meson setup \
+NINJA=${ninja:-${build_path}/ninjatool} $meson setup \
 --prefix "${pre_prefix}$prefix" \
 --libdir "${pre_prefix}$libdir" \
 --libexecdir "${pre_prefix}$libexecdir" \
@@ -8212,7 +8222,7 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \
-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png 
\
-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\
 $cross_arg \
-"$PWD" "$source_path"
+"$build_path" "$source_path"
 
 if test "$?" -ne 0 ; then
 error_exit "meson setup failed"
-- 
2.28.0.windows.1




[PATCH v4 06/12] block: Fixes nfs on msys2/mingw

2020-09-03 Thread Yonggang Luo
Signed-off-by: Yonggang Luo 
---
 block/nfs.c | 26 +-
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/block/nfs.c b/block/nfs.c
index 61a249a9fc..34b2cd5708 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -24,7 +24,9 @@
 
 #include "qemu/osdep.h"
 
+#if !defined(_WIN32)
 #include 
+#endif
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
@@ -51,6 +53,12 @@
 #define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE)
 #define QEMU_NFS_MAX_DEBUG_LEVEL 2
 
+#if defined (_WIN32)
+#define nfs_stat __stat64
+#else
+#define nfs_stat stat
+#endif
+
 typedef struct NFSClient {
 struct nfs_context *context;
 struct nfsfh *fh;
@@ -58,7 +66,7 @@ typedef struct NFSClient {
 bool has_zero_init;
 AioContext *aio_context;
 QemuMutex mutex;
-blkcnt_t st_blocks;
+int64_t st_size;
 bool cache_used;
 NFSServer *server;
 char *path;
@@ -70,7 +78,7 @@ typedef struct NFSRPC {
 int ret;
 int complete;
 QEMUIOVector *iov;
-struct stat *st;
+struct nfs_stat *st;
 Coroutine *co;
 NFSClient *client;
 } NFSRPC;
@@ -419,7 +427,7 @@ static int64_t nfs_client_open(NFSClient *client, 
BlockdevOptionsNfs *opts,
int flags, int open_flags, Error **errp)
 {
 int64_t ret = -EINVAL;
-struct stat st;
+struct nfs_stat st;
 char *file = NULL, *strp = NULL;
 
 qemu_mutex_init(&client->mutex);
@@ -545,7 +553,7 @@ static int64_t nfs_client_open(NFSClient *client, 
BlockdevOptionsNfs *opts,
 }
 
 ret = DIV_ROUND_UP(st.st_size, BDRV_SECTOR_SIZE);
-client->st_blocks = st.st_blocks;
+client->st_size = st.st_size;
 client->has_zero_init = S_ISREG(st.st_mode);
 *strp = '/';
 goto out;
@@ -729,11 +737,11 @@ static int64_t 
nfs_get_allocated_file_size(BlockDriverState *bs)
 {
 NFSClient *client = bs->opaque;
 NFSRPC task = {0};
-struct stat st;
+struct nfs_stat st;
 
 if (bdrv_is_read_only(bs) &&
 !(bs->open_flags & BDRV_O_NOCACHE)) {
-return client->st_blocks * 512;
+return client->st_size;
 }
 
 task.bs = bs;
@@ -746,7 +754,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState 
*bs)
 nfs_set_events(client);
 BDRV_POLL_WHILE(bs, !task.complete);
 
-return (task.ret < 0 ? task.ret : st.st_blocks * 512);
+return (task.ret < 0 ? task.ret : st.st_size);
 }
 
 static int coroutine_fn
@@ -778,7 +786,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state,
   BlockReopenQueue *queue, Error **errp)
 {
 NFSClient *client = state->bs->opaque;
-struct stat st;
+struct nfs_stat st;
 int ret = 0;
 
 if (state->flags & BDRV_O_RDWR && bdrv_is_read_only(state->bs)) {
@@ -800,7 +808,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state,
nfs_get_error(client->context));
 return ret;
 }
-client->st_blocks = st.st_blocks;
+client->st_size = st.st_size;
 }
 
 return 0;
-- 
2.28.0.windows.1




[PATCH v4 11/12] tests: Disable test-image-locking that not works under Win32

2020-09-03 Thread Yonggang Luo
Signed-off-by: Yonggang Luo 
---
 tests/Makefile.include | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 9ac8f5b86a..497f1f21ff 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -87,7 +87,9 @@ check-unit-$(CONFIG_BLOCK) += tests/test-blockjob$(EXESUF)
 check-unit-$(CONFIG_BLOCK) += tests/test-blockjob-txn$(EXESUF)
 check-unit-$(CONFIG_BLOCK) += tests/test-block-backend$(EXESUF)
 check-unit-$(CONFIG_BLOCK) += tests/test-block-iothread$(EXESUF)
+ifeq ($(CONFIG_POSIX),y)
 check-unit-$(CONFIG_BLOCK) += tests/test-image-locking$(EXESUF)
+endif
 check-unit-y += tests/test-x86-cpuid$(EXESUF)
 # all code tested by test-x86-cpuid is inside topology.h
 ifeq ($(CONFIG_SOFTMMU),y)
-- 
2.28.0.windows.1




[PATCH v4 10/12] meson: Fixes qapi tests.

2020-09-03 Thread Yonggang Luo
The error are:
+@end table
+
+@end deftypefn
+
make: *** [Makefile.mtest:63: check-qapi-schema] Error 1

Signed-off-by: Yonggang Luo 
---
 tests/qapi-schema/meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build
index c87d141417..67ba0a5ebd 100644
--- a/tests/qapi-schema/meson.build
+++ b/tests/qapi-schema/meson.build
@@ -220,6 +220,7 @@ qapi_doc = custom_target('QAPI doc',
 
 # "full_path()" needed here to work around
 # https://github.com/mesonbuild/meson/issues/7585
-test('QAPI doc', diff, args: ['-u', files('doc-good.texi'), 
qapi_doc[0].full_path()],
+test('QAPI doc', diff, args: ['--strip-trailing-cr',
+  '-u', files('doc-good.texi'), 
qapi_doc[0].full_path()],
  depends: qapi_doc,
  suite: ['qapi-schema', 'qapi-doc'])
-- 
2.28.0.windows.1




[PATCH v4 08/12] ci: fixes msys2 build by upgrading capstone to 4.0.2

2020-09-03 Thread Yonggang Luo
Signed-off-by: Yonggang Luo 
---
 capstone  | 2 +-
 configure | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/capstone b/capstone
index 22ead3e0bf..1d23053284 16
--- a/capstone
+++ b/capstone
@@ -1 +1 @@
-Subproject commit 22ead3e0bfdb87516656453336160e0a37b066bf
+Subproject commit 1d230532840a37ac032c6ab80128238fc930c6c1
diff --git a/configure b/configure
index 5f2bcc4b57..e42d210e5f 100755
--- a/configure
+++ b/configure
@@ -5248,14 +5248,14 @@ case "$capstone" in
   git_submodules="${git_submodules} capstone"
 fi
 mkdir -p capstone
-QEMU_CFLAGS="$QEMU_CFLAGS -I${source_path}/capstone/include"
+QEMU_CFLAGS="$QEMU_CFLAGS -I${source_path}/capstone/include 
-I${source_path}/capstone/include/capstone"
 if test "$mingw32" = "yes"; then
   LIBCAPSTONE=capstone.lib
 else
   LIBCAPSTONE=libcapstone.a
 fi
 capstone_libs="-L${build_path}/capstone -lcapstone"
-capstone_cflags="-I${source_path}/capstone/include"
+capstone_cflags="-I${source_path}/capstone/include 
-I${source_path}/capstone/include/capstone"
 ;;
 
   system)
-- 
2.28.0.windows.1




[PATCH v4 12/12] ci: Enable msys2 ci in cirrus

2020-09-03 Thread Yonggang Luo
Install msys2 in a proper way refer to 
https://github.com/cirruslabs/cirrus-ci-docs/issues/699
The https://wiki.qemu.org/Hosts/W32#Native_builds_with_MSYS2 need to be updated.
There is no need of --cross-prefix, open mingw64.exe instead of msys2.exe then 
we don't
need the --cross-prefix, besides using ENV
MSYS: winsymlinks:nativestrict
MSYSTEM: MINGW64
CHERE_INVOKING: 1
to opening mingw64 native shell.

Signed-off-by: Yonggang Luo 
---
 .cirrus.yml | 24 +
 scripts/ci/windows/msys2_build.sh   | 33 +
 scripts/ci/windows/msys2_install.sh | 31 +++
 3 files changed, 88 insertions(+)
 create mode 100644 scripts/ci/windows/msys2_build.sh
 create mode 100644 scripts/ci/windows/msys2_install.sh

diff --git a/.cirrus.yml b/.cirrus.yml
index f287d23c5b..0bfb465193 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -40,3 +40,27 @@ macos_xcode_task:
 - ../configure --cc=clang || { cat config.log; exit 1; }
 - gmake -j$(sysctl -n hw.ncpu)
 - gmake check
+
+windows_msys2_task:
+  windows_container:
+image: cirrusci/windowsservercore:cmake
+os_version: 2019
+cpu: 8
+memory: 8G
+  env:
+MSYS: winsymlinks:nativestrict
+MSYSTEM: MINGW64
+CHERE_INVOKING: 1
+  printenv_script:
+- C:\tools\msys64\usr\bin\bash.exe -lc 'printenv'
+  install_script:
+- C:\tools\msys64\usr\bin\bash.exe -lc "cd /c/tools && curl -O 
http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz";
+- C:\tools\msys64\usr\bin\bash.exe -lc "cd /c/tools && curl -O 
http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig";
+- C:\tools\msys64\usr\bin\bash.exe -lc "cd /c/tools && pacman -U 
--noconfirm msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz"
+- C:\tools\msys64\usr\bin\bash.exe -lc "pacman -Sy --noconfirm"
+- C:\tools\msys64\usr\bin\bash.exe -lc "pacman --needed --noconfirm -S 
bash pacman pacman-mirrors msys2-runtime"
+- taskkill /F /IM gpg-agent.exe
+- C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -Su"
+- C:\tools\msys64\usr\bin\bash.exe -lc "sh 
scripts/ci/windows/msys2_install.sh"
+  script:
+- C:\tools\msys64\usr\bin\bash.exe -lc "sh 
scripts/ci/windows/msys2_build.sh"
diff --git a/scripts/ci/windows/msys2_build.sh 
b/scripts/ci/windows/msys2_build.sh
new file mode 100644
index 00..3ba89a4206
--- /dev/null
+++ b/scripts/ci/windows/msys2_build.sh
@@ -0,0 +1,33 @@
+mkdir build
+cd build
+../configure \
+  --python=python3 \
+  --enable-gtk --enable-sdl \
+  --enable-capstone=git \
+  --enable-stack-protector \
+  --ninja=ninja \
+  --enable-gnutls \
+  --enable-nettle \
+  --enable-vnc \
+  --enable-vnc-sasl \
+  --enable-vnc-jpeg \
+  --enable-vnc-png \
+  --enable-membarrier \
+  --enable-slirp=git \
+  --disable-kvm \
+  --enable-hax \
+  --enable-whpx \
+  --disable-spice \
+  --enable-lzo \
+  --enable-snappy \
+  --enable-bzip2 \
+  --enable-vdi \
+  --enable-qcow1 \
+  --enable-tools \
+  --enable-libusb \
+  --enable-usb-redir \
+  --enable-libnfs \
+  --enable-libssh \
+  --disable-pie
+make -j$NUMBER_OF_PROCESSORS
+# make check
diff --git a/scripts/ci/windows/msys2_install.sh 
b/scripts/ci/windows/msys2_install.sh
new file mode 100644
index 00..ff35b73ef2
--- /dev/null
+++ b/scripts/ci/windows/msys2_install.sh
@@ -0,0 +1,31 @@
+pacman --noconfirm -S --needed \
+base-devel \
+git \
+mingw-w64-x86_64-python \
+mingw-w64-x86_64-python-setuptools \
+mingw-w64-x86_64-toolchain \
+mingw-w64-x86_64-SDL2 \
+mingw-w64-x86_64-SDL2_image \
+mingw-w64-x86_64-gtk3 \
+mingw-w64-x86_64-ninja \
+mingw-w64-x86_64-make \
+mingw-w64-x86_64-lzo2 \
+mingw-w64-x86_64-libjpeg-turbo \
+mingw-w64-x86_64-pixman \
+mingw-w64-x86_64-libgcrypt \
+mingw-w64-x86_64-capstone \
+mingw-w64-x86_64-libpng \
+mingw-w64-x86_64-libssh \
+mingw-w64-x86_64-libxml2 \
+mingw-w64-x86_64-snappy \
+mingw-w64-x86_64-libusb \
+mingw-w64-x86_64-usbredir \
+mingw-w64-x86_64-libtasn1 \
+mingw-w64-x86_64-libnfs \
+mingw-w64-x86_64-nettle \
+mingw-w64-x86_64-cyrus-sasl \
+mingw-w64-x86_64-curl \
+mingw-w64-x86_64-gnutls \
+mingw-w64-x86_64-zstd \
+mingw-w64-x86_64-glib2
+
-- 
2.28.0.windows.1




Re: [PATCH v2 04/15] fuzz: Add DMA support to the generic-fuzzer

2020-09-03 Thread Darren Kenny
On Wednesday, 2020-08-19 at 02:10:59 -04, Alexander Bulekov wrote:
> When a virtual-device tries to access some buffer in memory over DMA, we
> add call-backs into the fuzzer(next commit). The fuzzer checks verifies
> that the DMA request maps to a physical RAM address and fills the memory
> with fuzzer-provided data. The patterns that we use to fill this memory
> are specified using add_dma_pattern and clear_dma_patterns operations.
>
> Signed-off-by: Alexander Bulekov 
> ---
>  tests/qtest/fuzz/general_fuzz.c | 178 
>  1 file changed, 178 insertions(+)
>
> diff --git a/tests/qtest/fuzz/general_fuzz.c b/tests/qtest/fuzz/general_fuzz.c
> index 17b572a439..36d41acea0 100644
> --- a/tests/qtest/fuzz/general_fuzz.c
> +++ b/tests/qtest/fuzz/general_fuzz.c
> @@ -25,6 +25,8 @@
>  #include "exec/address-spaces.h"
>  #include "hw/qdev-core.h"
>  #include "hw/pci/pci.h"
> +#include "hw/boards.h"
> +#include "exec/memory-internal.h"
>  
>  /*
>   * SEPARATOR is used to separate "operations" in the fuzz input
> @@ -38,12 +40,16 @@ enum cmds{
>  OP_WRITE,
>  OP_PCI_READ,
>  OP_PCI_WRITE,
> +OP_ADD_DMA_PATTERN,
> +OP_CLEAR_DMA_PATTERNS,
>  OP_CLOCK_STEP,
>  };
>  
>  #define DEFAULT_TIMEOUT_US 10
>  #define USEC_IN_SEC 1
>  
> +#define MAX_DMA_FILL_SIZE 0x1
> +
>  #define PCI_HOST_BRIDGE_CFG 0xcf8
>  #define PCI_HOST_BRIDGE_DATA 0xcfc
>  
> @@ -53,6 +59,24 @@ typedef struct {
>  } address_range;
>  
>  static useconds_t timeout = 10;
> +/*
> + * A pattern used to populate a DMA region or perform a memwrite. This is
> + * useful for e.g. populating tables of unique addresses.
> + * Example {.index = 1; .stride = 2; .len = 3; .data = "\x00\x01\x02"}
> + * Renders as: 00 01 02   00 03 03   00 05 03   00 07 03 ...

TYPO: I think this wrong, and that the last digit should be 02 not 03 in
  each group.

> + */
> +typedef struct {
> +uint8_t index;  /* Index of a byte to increment by stride */
> +uint8_t stride; /* Increment each index'th byte by this amount */
> +size_t len;
> +const uint8_t *data;
> +} pattern;
> +
> +/* Avoid filling the same DMA region between MMIO/PIO commands ? */
> +static bool avoid_double_fetches;
> +
> +static QTestState *qts_global; /* Need a global for the DMA callback */
> +
>  /*
>   * List of memory regions that are children of QOM objects specified by the
>   * user for fuzzing.
> @@ -60,6 +84,116 @@ static useconds_t timeout = 10;
>  static GPtrArray *fuzzable_memoryregions;
>  static GPtrArray *fuzzable_pci_devices;
>  
> +/*
> + * List of dma regions populated since the last fuzzing command. Used to 
> ensure
> + * that we only write to each DMA address once, to avoid race conditions when
> + * building reproducers.
> + */
> +static GArray *dma_regions;
> +
> +static GArray *dma_patterns;
> +static int dma_pattern_index;
> +
> +void fuzz_dma_read_cb(size_t addr, size_t len, MemoryRegion *mr, bool 
> is_write);
> +
> +/*
> + * Allocate a block of memory and populate it with a pattern.
> + */
> +static void *pattern_alloc(pattern p, size_t len)
> +{
> +int i;
> +uint8_t *buf = g_malloc(len);
> +uint8_t sum = 0;
> +
> +for (i = 0; i < len; ++i) {
> +buf[i] = p.data[i % p.len];
> +if ((i % p.len) == p.index) {
> +buf[i] += sum;
> +sum += p.stride;
> +}
> +}
> +return buf;
> +}
> +
> +/*
> + * Call-back for functions that perform DMA reads from guest memory. Confirm
> + * that the region has not already been populated since the last loop in
> + * general_fuzz(), avoiding potential race-conditions, which we don't have
> + * a good way for reproducing right now.
> + */
> +void fuzz_dma_read_cb(size_t addr, size_t len, MemoryRegion *mr, bool 
> is_write)
> +{
> +/* Are we in the general-fuzzer or are we using another fuzz-target? */
> +if (!qts_global) {
> +return;
> +}
> +
> +/*
> + * Return immediately if:
> + * - We have no DMA patterns defined
> + * - The length of the DMA read request is zero
> + * - The DMA read is hitting an MR other than the machine's main RAM
> + * - The DMA request is not a read (what happens for a address_space_map
> + *   with is_write=True? Can the device use the same pointer to do 
> reads?)
> + * - The DMA request hits past the bounds of our RAM
> + */
> +if (dma_patterns->len == 0
> +|| len == 0
> +|| (mr != MACHINE(qdev_get_machine())->ram && !(mr->ops == 
> &unassigned_mem_ops))
> +|| is_write
> +|| addr > current_machine->ram_size) {
> +return;
> +}
> +
> +/*
> + * If we overlap with any existing dma_regions, split the range and only
> + * populate the non-overlapping parts.
> + */
> +for (int i = 0; i < dma_regions->len && avoid_double_fetches; ++i) {
> +address_range region = g_array_index(dma_regions, address_range, i);

NIT: Can be slightly more expensi

Re: [PATCH 55/63] vfio: Rename PCI_VFIO to VFIO_PCI

2020-09-03 Thread Auger Eric
Eduardo,

On 9/3/20 12:43 AM, Eduardo Habkost wrote:
> Make the type checking macro name consistent with the TYPE_*
> constant.
> 
> Signed-off-by: Eduardo Habkost 
Reviewed-by: Eric Auger 

Thanks

Eric
> ---
> Cc: Alex Williamson 
> Cc: qemu-devel@nongnu.org
> ---
>  hw/vfio/pci.h |  2 +-
>  hw/vfio/pci.c | 22 +++---
>  2 files changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
> index 846d60e56c..5e53d5b863 100644
> --- a/hw/vfio/pci.h
> +++ b/hw/vfio/pci.h
> @@ -116,7 +116,7 @@ typedef struct VFIOMSIXInfo {
>  
>  #define TYPE_VFIO_PCI "vfio-pci"
>  typedef struct VFIOPCIDevice VFIOPCIDevice;
> -DECLARE_INSTANCE_CHECKER(VFIOPCIDevice, PCI_VFIO,
> +DECLARE_INSTANCE_CHECKER(VFIOPCIDevice, VFIO_PCI,
>   TYPE_VFIO_PCI)
>  
>  struct VFIOPCIDevice {
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index 3611dcd38b..0d83eb0e47 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -230,7 +230,7 @@ static void vfio_intx_update(VFIOPCIDevice *vdev, 
> PCIINTxRoute *route)
>  
>  static void vfio_intx_routing_notifier(PCIDevice *pdev)
>  {
> -VFIOPCIDevice *vdev = PCI_VFIO(pdev);
> +VFIOPCIDevice *vdev = VFIO_PCI(pdev);
>  PCIINTxRoute route;
>  
>  if (vdev->interrupt != VFIO_INT_INTx) {
> @@ -456,7 +456,7 @@ static void vfio_update_kvm_msi_virq(VFIOMSIVector 
> *vector, MSIMessage msg,
>  static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
> MSIMessage *msg, IOHandler *handler)
>  {
> -VFIOPCIDevice *vdev = PCI_VFIO(pdev);
> +VFIOPCIDevice *vdev = VFIO_PCI(pdev);
>  VFIOMSIVector *vector;
>  int ret;
>  
> @@ -541,7 +541,7 @@ static int vfio_msix_vector_use(PCIDevice *pdev,
>  
>  static void vfio_msix_vector_release(PCIDevice *pdev, unsigned int nr)
>  {
> -VFIOPCIDevice *vdev = PCI_VFIO(pdev);
> +VFIOPCIDevice *vdev = VFIO_PCI(pdev);
>  VFIOMSIVector *vector = &vdev->msi_vectors[nr];
>  
>  trace_vfio_msix_vector_release(vdev->vbasedev.name, nr);
> @@ -1048,7 +1048,7 @@ static const MemoryRegionOps vfio_vga_ops = {
>   */
>  static void vfio_sub_page_bar_update_mapping(PCIDevice *pdev, int bar)
>  {
> -VFIOPCIDevice *vdev = PCI_VFIO(pdev);
> +VFIOPCIDevice *vdev = VFIO_PCI(pdev);
>  VFIORegion *region = &vdev->bars[bar].region;
>  MemoryRegion *mmap_mr, *region_mr, *base_mr;
>  PCIIORegion *r;
> @@ -1094,7 +1094,7 @@ static void vfio_sub_page_bar_update_mapping(PCIDevice 
> *pdev, int bar)
>   */
>  uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len)
>  {
> -VFIOPCIDevice *vdev = PCI_VFIO(pdev);
> +VFIOPCIDevice *vdev = VFIO_PCI(pdev);
>  uint32_t emu_bits = 0, emu_val = 0, phys_val = 0, val;
>  
>  memcpy(&emu_bits, vdev->emulated_config_bits + addr, len);
> @@ -1127,7 +1127,7 @@ uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t 
> addr, int len)
>  void vfio_pci_write_config(PCIDevice *pdev,
> uint32_t addr, uint32_t val, int len)
>  {
> -VFIOPCIDevice *vdev = PCI_VFIO(pdev);
> +VFIOPCIDevice *vdev = VFIO_PCI(pdev);
>  uint32_t val_le = cpu_to_le32(val);
>  
>  trace_vfio_pci_write_config(vdev->vbasedev.name, addr, val, len);
> @@ -2701,7 +2701,7 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice 
> *vdev)
>  
>  static void vfio_realize(PCIDevice *pdev, Error **errp)
>  {
> -VFIOPCIDevice *vdev = PCI_VFIO(pdev);
> +VFIOPCIDevice *vdev = VFIO_PCI(pdev);
>  VFIODevice *vbasedev_iter;
>  VFIOGroup *group;
>  char *tmp, *subsys, group_path[PATH_MAX], *group_name;
> @@ -3033,7 +3033,7 @@ error:
>  
>  static void vfio_instance_finalize(Object *obj)
>  {
> -VFIOPCIDevice *vdev = PCI_VFIO(obj);
> +VFIOPCIDevice *vdev = VFIO_PCI(obj);
>  VFIOGroup *group = vdev->vbasedev.group;
>  
>  vfio_display_finalize(vdev);
> @@ -3057,7 +3057,7 @@ static void vfio_instance_finalize(Object *obj)
>  
>  static void vfio_exitfn(PCIDevice *pdev)
>  {
> -VFIOPCIDevice *vdev = PCI_VFIO(pdev);
> +VFIOPCIDevice *vdev = VFIO_PCI(pdev);
>  
>  vfio_unregister_req_notifier(vdev);
>  vfio_unregister_err_notifier(vdev);
> @@ -3075,7 +3075,7 @@ static void vfio_exitfn(PCIDevice *pdev)
>  
>  static void vfio_pci_reset(DeviceState *dev)
>  {
> -VFIOPCIDevice *vdev = PCI_VFIO(dev);
> +VFIOPCIDevice *vdev = VFIO_PCI(dev);
>  
>  trace_vfio_pci_reset(vdev->vbasedev.name);
>  
> @@ -3115,7 +3115,7 @@ post_reset:
>  static void vfio_instance_init(Object *obj)
>  {
>  PCIDevice *pci_dev = PCI_DEVICE(obj);
> -VFIOPCIDevice *vdev = PCI_VFIO(obj);
> +VFIOPCIDevice *vdev = VFIO_PCI(obj);
>  
>  device_add_bootindex_property(obj, &vdev->bootindex,
>"bootindex", NULL,
> 




Re: [PATCH v2 05/15] fuzz: Declare DMA Read callback function

2020-09-03 Thread Darren Kenny
On Wednesday, 2020-08-19 at 02:11:00 -04, Alexander Bulekov wrote:
> This patch declares the fuzz_dma_read_cb function and uses the
> preprocessor and linker(weak symbols) to handle these cases:
>
> When we build softmmu/all with --enable-fuzzing, there should be no
> strong symbol defined for fuzz_dma_read_cb, and we link against a weak
> stub function.
>
> When we build softmmu/fuzz with --enable-fuzzing, we link agains the

TYPO: s/agains/against/

> strong symbol in general_fuzz.c
>
> When we build softmmu/all without --enable-fuzzing, fuzz_dma_read_cb is
> an empty, inlined function. As long as we don't call any other functions
> when building the arguments, there should be no overhead.
>
> Signed-off-by: Alexander Bulekov 

Reviewed-by: Darren Kenny 

> ---
>  include/exec/memory.h | 15 +++
>  softmmu/memory.c  | 13 +
>  2 files changed, 28 insertions(+)
>
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 307e527835..2ec3b597f1 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -47,6 +47,21 @@
>  OBJECT_GET_CLASS(IOMMUMemoryRegionClass, (obj), \
>   TYPE_IOMMU_MEMORY_REGION)
>  
> +#ifdef CONFIG_FUZZ
> +void fuzz_dma_read_cb(size_t addr,
> +  size_t len,
> +  MemoryRegion *mr,
> +  bool is_write);
> +#else
> +static inline void fuzz_dma_read_cb(size_t addr,
> +size_t len,
> +MemoryRegion *mr,
> +bool is_write)
> +{
> +/* Do Nothing */
> +}
> +#endif
> +
>  extern bool global_dirty_log;
>  
>  typedef struct MemoryRegionOps MemoryRegionOps;
> diff --git a/softmmu/memory.c b/softmmu/memory.c
> index af25987518..b0c2cf2535 100644
> --- a/softmmu/memory.c
> +++ b/softmmu/memory.c
> @@ -3223,6 +3223,19 @@ void memory_region_init_rom_device(MemoryRegion *mr,
>  vmstate_register_ram(mr, owner_dev);
>  }
>  
> +/*
> + * Support softmmu builds with CONFIG_FUZZ using a weak symbol and a stub for
> + * the fuzz_dma_read_cb callback
> + */
> +#ifdef CONFIG_FUZZ
> +void __attribute__((weak)) fuzz_dma_read_cb(size_t addr,
> +  size_t len,
> +  MemoryRegion *mr,
> +  bool is_write)
> +{
> +}
> +#endif
> +
>  static const TypeInfo memory_region_info = {
>  .parent = TYPE_OBJECT,
>  .name   = TYPE_MEMORY_REGION,
> -- 
> 2.27.0



Re: [PATCH v2 06/15] fuzz: Add fuzzer callbacks to DMA-read functions

2020-09-03 Thread Darren Kenny
On Wednesday, 2020-08-19 at 02:11:01 -04, Alexander Bulekov wrote:
> We should be careful to not call any functions besides fuzz_dma_read_cb.
> Without --enable-fuzzing, fuzz_dma_read_cb is an empty inlined function.
>
> Signed-off-by: Alexander Bulekov 

Reviewed-by: Darren Kenny 

> ---
>  exec.c| 2 ++
>  include/exec/memory.h | 1 +
>  include/exec/memory_ldst_cached.inc.h | 3 +++
>  memory_ldst.inc.c | 4 
>  softmmu/memory.c  | 1 +
>  5 files changed, 11 insertions(+)
>
> diff --git a/exec.c b/exec.c
> index 6f381f98e2..c81f41514d 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -3241,6 +3241,7 @@ MemTxResult flatview_read_continue(FlatView *fv, hwaddr 
> addr,
>  stn_he_p(buf, l, val);
>  } else {
>  /* RAM case */
> +fuzz_dma_read_cb(addr, len, mr, false);
>  ram_ptr = qemu_ram_ptr_length(mr->ram_block, addr1, &l, false);
>  memcpy(buf, ram_ptr, l);
>  }
> @@ -3601,6 +3602,7 @@ void *address_space_map(AddressSpace *as,
>  memory_region_ref(mr);
>  *plen = flatview_extend_translation(fv, addr, len, mr, xlat,
>  l, is_write, attrs);
> +fuzz_dma_read_cb(addr, *plen, mr, is_write);
>  ptr = qemu_ram_ptr_length(mr->ram_block, xlat, plen, true);
>  
>  return ptr;
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 2ec3b597f1..f8b943521a 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -2444,6 +2444,7 @@ address_space_read_cached(MemoryRegionCache *cache, 
> hwaddr addr,
>void *buf, hwaddr len)
>  {
>  assert(addr < cache->len && len <= cache->len - addr);
> +fuzz_dma_read_cb(cache->xlat + addr, len, cache->mrs.mr, false);
>  if (likely(cache->ptr)) {
>  memcpy(buf, cache->ptr + addr, len);
>  return MEMTX_OK;
> diff --git a/include/exec/memory_ldst_cached.inc.h 
> b/include/exec/memory_ldst_cached.inc.h
> index fd4bbb40e7..aff574039f 100644
> --- a/include/exec/memory_ldst_cached.inc.h
> +++ b/include/exec/memory_ldst_cached.inc.h
> @@ -28,6 +28,7 @@ static inline uint32_t 
> ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache,
>  hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
>  {
>  assert(addr < cache->len && 4 <= cache->len - addr);
> +fuzz_dma_read_cb(cache->xlat + addr, 4, cache->mrs.mr, false);
>  if (likely(cache->ptr)) {
>  return LD_P(l)(cache->ptr + addr);
>  } else {
> @@ -39,6 +40,7 @@ static inline uint64_t 
> ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache,
>  hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
>  {
>  assert(addr < cache->len && 8 <= cache->len - addr);
> +fuzz_dma_read_cb(cache->xlat + addr, 8, cache->mrs.mr, false);
>  if (likely(cache->ptr)) {
>  return LD_P(q)(cache->ptr + addr);
>  } else {
> @@ -50,6 +52,7 @@ static inline uint32_t 
> ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache,
>  hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
>  {
>  assert(addr < cache->len && 2 <= cache->len - addr);
> +fuzz_dma_read_cb(cache->xlat + addr, 2, cache->mrs.mr, false);
>  if (likely(cache->ptr)) {
>  return LD_P(uw)(cache->ptr + addr);
>  } else {
> diff --git a/memory_ldst.inc.c b/memory_ldst.inc.c
> index c54aee4a95..8d45d2eeff 100644
> --- a/memory_ldst.inc.c
> +++ b/memory_ldst.inc.c
> @@ -42,6 +42,7 @@ static inline uint32_t glue(address_space_ldl_internal, 
> SUFFIX)(ARG1_DECL,
>  MO_32 | devend_memop(endian), attrs);
>  } else {
>  /* RAM case */
> +fuzz_dma_read_cb(addr, 4, mr, false);
>  ptr = qemu_map_ram_ptr(mr->ram_block, addr1);
>  switch (endian) {
>  case DEVICE_LITTLE_ENDIAN:
> @@ -110,6 +111,7 @@ static inline uint64_t glue(address_space_ldq_internal, 
> SUFFIX)(ARG1_DECL,
>  MO_64 | devend_memop(endian), attrs);
>  } else {
>  /* RAM case */
> +fuzz_dma_read_cb(addr, 8, mr, false);
>  ptr = qemu_map_ram_ptr(mr->ram_block, addr1);
>  switch (endian) {
>  case DEVICE_LITTLE_ENDIAN:
> @@ -175,6 +177,7 @@ uint32_t glue(address_space_ldub, SUFFIX)(ARG1_DECL,
>  r = memory_region_dispatch_read(mr, addr1, &val, MO_8, attrs);
>  } else {
>  /* RAM case */
> +fuzz_dma_read_cb(addr, 1, mr, false);
>  ptr = qemu_map_ram_ptr(mr->ram_block, addr1);
>  val = ldub_p(ptr);
>  r = MEMTX_OK;
> @@ -212,6 +215,7 @@ static inline uint32_t glue(address_space_lduw_internal, 
> SUFFIX)(ARG1_DECL,
>  MO_16 | devend_memop(endian), attrs);
>  } else {
>  /* RAM case */
> +fuzz_dma_read_cb(addr, 2, mr, false);
>  ptr = qemu_map_ram_ptr(mr->ram_block, addr1);
>  switch (endian) {
>

Re: [PATCH v2 08/15] fuzz: add a DISABLE_PCI op to general-fuzzer

2020-09-03 Thread Darren Kenny
On Wednesday, 2020-08-19 at 02:11:03 -04, Alexander Bulekov wrote:
> This new operation is used in the next commit, which concatenates two
> fuzzer-generated inputs. With this operation, we can prevent the second
> input from clobbering the PCI configuration performed by the first.
>
> Signed-off-by: Alexander Bulekov 

Reviewed-by: Darren Kenny 

> ---
>  tests/qtest/fuzz/general_fuzz.c | 13 +++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qtest/fuzz/general_fuzz.c b/tests/qtest/fuzz/general_fuzz.c
> index 36d41acea0..26fcd69e45 100644
> --- a/tests/qtest/fuzz/general_fuzz.c
> +++ b/tests/qtest/fuzz/general_fuzz.c
> @@ -40,6 +40,7 @@ enum cmds{
>  OP_WRITE,
>  OP_PCI_READ,
>  OP_PCI_WRITE,
> +OP_DISABLE_PCI,
>  OP_ADD_DMA_PATTERN,
>  OP_CLEAR_DMA_PATTERNS,
>  OP_CLOCK_STEP,
> @@ -93,6 +94,7 @@ static GArray *dma_regions;
>  
>  static GArray *dma_patterns;
>  static int dma_pattern_index;
> +static bool pci_disabled = false;
>  
>  void fuzz_dma_read_cb(size_t addr, size_t len, MemoryRegion *mr, bool 
> is_write);
>  
> @@ -433,7 +435,7 @@ static void op_pci_read(QTestState *s, const unsigned 
> char * data, size_t len)
>  uint8_t base;
>  uint8_t offset;
>  } a;
> -if (len < sizeof(a) || fuzzable_pci_devices->len == 0) {
> +if (len < sizeof(a) || fuzzable_pci_devices->len == 0 || pci_disabled) {
>  return;
>  }
>  memcpy(&a, data, sizeof(a));
> @@ -463,7 +465,7 @@ static void op_pci_write(QTestState *s, const unsigned 
> char * data, size_t len)
>  uint8_t offset;
>  uint32_t value;
>  } a;
> -if (len < sizeof(a) || fuzzable_pci_devices->len == 0) {
> +if (len < sizeof(a) || fuzzable_pci_devices->len == 0 || pci_disabled) {
>  return;
>  }
>  memcpy(&a, data, sizeof(a));
> @@ -518,6 +520,11 @@ static void op_clock_step(QTestState *s, const unsigned 
> char *data, size_t len)
>  qtest_clock_step_next(s);
>  }
>  
> +static void op_disable_pci(QTestState *s, const unsigned char *data, size_t 
> len)
> +{
> +pci_disabled = true;
> +}
> +
>  static void handle_timeout(int sig)
>  {
>  if (getenv("QTEST_LOG")) {
> @@ -559,6 +566,7 @@ static void general_fuzz(QTestState *s, const unsigned 
> char *Data, size_t Size)
>  [OP_WRITE]  = op_write,
>  [OP_PCI_READ]   = op_pci_read,
>  [OP_PCI_WRITE]  = op_pci_write,
> +[OP_DISABLE_PCI]= op_disable_pci,
>  [OP_ADD_DMA_PATTERN]= op_add_dma_pattern,
>  [OP_CLEAR_DMA_PATTERNS] = op_clear_dma_patterns,
>  [OP_CLOCK_STEP] = op_clock_step,
> @@ -591,6 +599,7 @@ static void general_fuzz(QTestState *s, const unsigned 
> char *Data, size_t Size)
>  }
>  
>  op_clear_dma_patterns(s, NULL, 0);
> +pci_disabled = false;
>  
>  while (cmd && Size) {
>  /* Get the length until the next command or end of input */
> -- 
> 2.27.0



Re: [PATCH v2 07/15] fuzz: Add support for custom crossover functions

2020-09-03 Thread Darren Kenny
On Wednesday, 2020-08-19 at 02:11:02 -04, Alexander Bulekov wrote:
> libfuzzer supports a "custom crossover function". Libfuzzer often tries
> to blend two inputs to create a new interesting input. Sometimes, we
> have a better idea about how to blend inputs together. This change
> allows fuzzers to specify a custom function for blending two inputs
> together.
>
> Signed-off-by: Alexander Bulekov 

Reviewed-by: Darren Kenny 

> ---
>  tests/qtest/fuzz/fuzz.c | 13 +
>  tests/qtest/fuzz/fuzz.h | 26 ++
>  2 files changed, 39 insertions(+)
>
> diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c
> index 8234b68754..248fab5f37 100644
> --- a/tests/qtest/fuzz/fuzz.c
> +++ b/tests/qtest/fuzz/fuzz.c
> @@ -118,6 +118,19 @@ static FuzzTarget *fuzz_get_target(char* name)
>  }
>  
>  
> +/* Sometimes called by libfuzzer to mutate two inputs into one */
> +size_t LLVMFuzzerCustomCrossOver(const uint8_t *data1, size_t size1,
> + const uint8_t *data2, size_t size2,
> + uint8_t *out, size_t max_out_size,
> + unsigned int seed)
> +{
> +if(fuzz_target->crossover) {
> +return fuzz_target->crossover(data1, size1, data2, size2, out,
> +  max_out_size, seed);
> +}
> +return 0;
> +}
> +
>  /* Executed for each fuzzing-input */
>  int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size)
>  {
> diff --git a/tests/qtest/fuzz/fuzz.h b/tests/qtest/fuzz/fuzz.h
> index 9ca3d107c5..d36642b5ec 100644
> --- a/tests/qtest/fuzz/fuzz.h
> +++ b/tests/qtest/fuzz/fuzz.h
> @@ -77,6 +77,28 @@ typedef struct FuzzTarget {
>   */
>  void(*fuzz)(QTestState *, const unsigned char *, size_t);
>  
> +/*
> + * The fuzzer can specify a "Custom Crossover" function for combining two
> + * inputs from the corpus. This function is sometimes called by libfuzzer
> + * when mutating inputs.
> + *
> + * data1: location of first input
> + * size1: length of first input
> + * data1: location of second input
> + * size1: length of second input
> + * out: where to place the resulting, mutated input
> + * max_out_size: the maximum length of the input that can be placed in 
> out
> + * seed: the seed that should be used to make mutations deterministic, 
> when needed
> + *
> + * See libfuzzer's LLVMFuzzerCustomCrossOver API for more info.
> + *
> + * Can be NULL
> + */
> +size_t(*crossover)(const uint8_t *data1, size_t size1,
> +   const uint8_t *data2, size_t size2,
> +   uint8_t *out, size_t max_out_size,
> +   unsigned int seed);
> +
>  } FuzzTarget;
>  
>  void flush_events(QTestState *);
> @@ -91,6 +113,10 @@ void fuzz_qtest_set_serialize(bool option);
>   */
>  void fuzz_add_target(const FuzzTarget *target);
>  
> +size_t LLVMFuzzerCustomCrossOver(const uint8_t *data1, size_t size1,
> + const uint8_t *data2, size_t size2,
> + uint8_t *out, size_t max_out_size,
> + unsigned int seed);
>  int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size);
>  int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp);
>  
> -- 
> 2.27.0



Re: [PATCH v5 1/8] monitor: simplify functions for getting a dup'd fdset entry

2020-09-03 Thread Markus Armbruster
Daniel P. Berrangé  writes:

> Currently code has to call monitor_fdset_get_fd, then dup
> the return fd, and then add the duplicate FD back into the
> fdset. This dance is overly verbose for the caller and
> introduces extra failure modes which can be avoided by
> folding all the logic into monitor_fdset_dup_fd_add and
> removing monitor_fdset_get_fd entirely.
>
> Signed-off-by: Daniel P. Berrangé 
> ---
>  include/monitor/monitor.h |  3 +-
>  include/qemu/osdep.h  |  1 +
>  monitor/misc.c| 58 +--
>  stubs/fdset.c |  8 ++
>  util/osdep.c  | 19 ++---
>  5 files changed, 32 insertions(+), 57 deletions(-)
>
> diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
> index 1018d754a6..c0170773d4 100644
> --- a/include/monitor/monitor.h
> +++ b/include/monitor/monitor.h
> @@ -43,8 +43,7 @@ int monitor_read_password(MonitorHMP *mon, ReadLineFunc 
> *readline_func,
>  AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
>  bool has_opaque, const char *opaque,
>  Error **errp);
> -int monitor_fdset_get_fd(int64_t fdset_id, int flags);
> -int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
> +int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags);
>  void monitor_fdset_dup_fd_remove(int dup_fd);
>  int64_t monitor_fdset_dup_fd_find(int dup_fd);
>  
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index 412962d91a..66ee5bc45d 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -501,6 +501,7 @@ int qemu_open(const char *name, int flags, ...);
>  int qemu_close(int fd);
>  int qemu_unlink(const char *name);
>  #ifndef _WIN32
> +int qemu_dup_flags(int fd, int flags);
>  int qemu_dup(int fd);
>  #endif
>  int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive);
> diff --git a/monitor/misc.c b/monitor/misc.c
> index e847b58a8c..98e389e4a8 100644
> --- a/monitor/misc.c
> +++ b/monitor/misc.c
> @@ -1547,69 +1547,61 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool 
> has_fdset_id, int64_t fdset_id,
>  return fdinfo;
>  }
>  
> -int monitor_fdset_get_fd(int64_t fdset_id, int flags)
> +

Extra blank line.

> +int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
>  {
>  #ifdef _WIN32
>  return -ENOENT;
>  #else
>  MonFdset *mon_fdset;
> -MonFdsetFd *mon_fdset_fd;
> -int mon_fd_flags;
> -int ret;
>  
>  qemu_mutex_lock(&mon_fdsets_lock);
>  QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
> +MonFdsetFd *mon_fdset_fd;
> +MonFdsetFd *mon_fdset_fd_dup;
> +int fd = -1;
> +int dup_fd;
> +int mon_fd_flags;
> +
>  if (mon_fdset->id != fdset_id) {
>  continue;
>  }
> +
>  QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) {
>  mon_fd_flags = fcntl(mon_fdset_fd->fd, F_GETFL);
>  if (mon_fd_flags == -1) {
> -ret = -errno;
> -goto out;
> +qemu_mutex_unlock(&mon_fdsets_lock);
> +return -1;
>  }
>  
>  if ((flags & O_ACCMODE) == (mon_fd_flags & O_ACCMODE)) {
> -ret = mon_fdset_fd->fd;
> -goto out;
> +fd = mon_fdset_fd->fd;
> +break;
>  }
>  }
> -ret = -EACCES;
> -goto out;
> -}
> -ret = -ENOENT;
>  
> -out:
> -qemu_mutex_unlock(&mon_fdsets_lock);
> -return ret;
> -#endif
> -}
> -
> -int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd)
> -{
> -MonFdset *mon_fdset;
> -MonFdsetFd *mon_fdset_fd_dup;
> -
> -qemu_mutex_lock(&mon_fdsets_lock);
> -QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
> -if (mon_fdset->id != fdset_id) {
> -continue;
> +if (fd == -1) {
> +errno = EINVAL;
> +return -1;

Missing qemu_mutex_unlock().

>  }

Old monitor_fdset_get_fd() returns -ENOENT when @fdset_id does not
exist, and -EACCES when it doesn't contain a file descriptor matching
@flags.

The new code seems to use EINVAL for the latter case.  Intentional?

> -QLIST_FOREACH(mon_fdset_fd_dup, &mon_fdset->dup_fds, next) {
> -if (mon_fdset_fd_dup->fd == dup_fd) {
> -goto err;
> -}
> +
> +dup_fd = qemu_dup_flags(fd, flags);
> +if (dup_fd == -1) {
> +qemu_mutex_unlock(&mon_fdsets_lock);
> +return -1;
>  }
> +
>  mon_fdset_fd_dup = g_malloc0(sizeof(*mon_fdset_fd_dup));
>  mon_fdset_fd_dup->fd = dup_fd;
>  QLIST_INSERT_HEAD(&mon_fdset->dup_fds, mon_fdset_fd_dup, next);
>  qemu_mutex_unlock(&mon_fdsets_lock);
> -return 0;
> +return dup_fd;
>  }
>  
> -err:
>  qemu_mutex_unlock(&mon_fdsets_lock);
> +errno = ENOENT;
>  return -1;
> +#endif
>  }
>  
>  static int64_t monit

Re: [PATCH v5 2/8] util: split off a helper for dealing with O_CLOEXEC flag

2020-09-03 Thread Markus Armbruster
Daniel P. Berrangé  writes:

> We're going to have multiple callers to open() from qemu_open()
> soon. Readability would thus benefit from having a helper for
> dealing with O_CLOEXEC.
>
> Signed-off-by: Daniel P. Berrangé 

Reviewed-by: Markus Armbruster 




Re: [PATCH v5 3/8] util: rename qemu_open() to qemu_open_old()

2020-09-03 Thread Markus Armbruster
Daniel P. Berrangé  writes:

> We want to introduce a new version of qemu_open() that uses an Error
> object for reporting problems and make this it the preferred interface.
> Rename the existing method to release the namespace for the new impl.
>
> Reviewed-by: Eric Blake 
> Reviewed-by: Philippe Mathieu-Daudé 
> Signed-off-by: Daniel P. Berrangé 

Reviewed-by: Markus Armbruster 




Re: [PATCH v5 4/8] util: refactor qemu_open_old to split off variadic args handling

2020-09-03 Thread Markus Armbruster
Daniel P. Berrangé  writes:

> This simple refactoring prepares for future patches. The variadic args
> handling is split from the main bulk of the open logic. The duplicated
> calls to open() are removed in favour of updating the "flags" variable
> to have O_CLOEXEC.

Drop the second sentence, it is no longer true in this revision.

> Signed-off-by: Daniel P. Berrangé 
> ---
>  util/osdep.c | 25 ++---
>  1 file changed, 18 insertions(+), 7 deletions(-)
>
> diff --git a/util/osdep.c b/util/osdep.c
> index 7504c156e8..dd34b58bb7 100644
> --- a/util/osdep.c
> +++ b/util/osdep.c
> @@ -22,6 +22,7 @@
>   * THE SOFTWARE.
>   */
>  #include "qemu/osdep.h"
> +#include "qapi/error.h"

This patch doesn't use anything from qapi/error.h as far as I can tell.
Does the hunk belong to another patch?

>  
>  /* Needed early for CONFIG_BSD etc. */
>  
> @@ -296,10 +297,10 @@ static int qemu_open_cloexec(const char *name, int 
> flags, mode_t mode)
>  /*
>   * Opens a file with FD_CLOEXEC set
>   */
> -int qemu_open_old(const char *name, int flags, ...)
> +static int
> +qemu_open_internal(const char *name, int flags, mode_t mode)
>  {
>  int ret;
> -int mode = 0;
>  
>  #ifndef _WIN32
>  const char *fdset_id_str;
> @@ -324,15 +325,25 @@ int qemu_open_old(const char *name, int flags, ...)
>  }
>  #endif
>  
> -if (flags & O_CREAT) {
> -va_list ap;
> +ret = qemu_open_cloexec(name, flags, mode);
> +
> +return ret;
> +}
> +
>  
> -va_start(ap, flags);
> +int qemu_open_old(const char *name, int flags, ...)
> +{
> +va_list ap;
> +mode_t mode = 0;
> +int ret;
> +
> +va_start(ap, flags);
> +if (flags & O_CREAT) {
>  mode = va_arg(ap, int);
> -va_end(ap);
>  }
> +va_end(ap);
>  
> -ret = qemu_open_cloexec(name, flags, mode);
> +ret = qemu_open_internal(name, flags, mode);
>  
>  #ifdef O_DIRECT
>  if (ret == -1 && errno == EINVAL && (flags & O_DIRECT)) {

With the minor inaccuracies tidied up:
Reviewed-by: Markus Armbruster 




Re: [PATCH v5 5/8] util: add Error object for qemu_open_internal error reporting

2020-09-03 Thread Markus Armbruster
Daniel P. Berrangé  writes:

> Instead of relying on the limited information from errno, we can now
> also provide detailed error messages to callers that ask for it.
>
> Signed-off-by: Daniel P. Berrangé 
> ---
>  util/osdep.c | 14 --
>  1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/util/osdep.c b/util/osdep.c
> index dd34b58bb7..28aa89adc9 100644
> --- a/util/osdep.c
> +++ b/util/osdep.c
> @@ -298,7 +298,7 @@ static int qemu_open_cloexec(const char *name, int flags, 
> mode_t mode)
>   * Opens a file with FD_CLOEXEC set
>   */
>  static int
> -qemu_open_internal(const char *name, int flags, mode_t mode)
> +qemu_open_internal(const char *name, int flags, mode_t mode, Error **errp)
>  {
>  int ret;
>  
> @@ -312,12 +312,15 @@ qemu_open_internal(const char *name, int flags, mode_t 
> mode)
>  
>  fdset_id = qemu_parse_fdset(fdset_id_str);
>  if (fdset_id == -1) {
> +error_setg(errp, "Could not parse fdset %s", name);
>  errno = EINVAL;
>  return -1;
>  }
>  
>  dupfd = monitor_fdset_dup_fd_add(fdset_id, flags);
>  if (dupfd == -1) {
> +error_setg_errno(errp, errno, "Could not dup FD for %s flags %x",
> + name, flags);

You kept the reporting of flags here.  Intentional?

>  return -1;
>  }
>  
> @@ -327,6 +330,13 @@ qemu_open_internal(const char *name, int flags, mode_t 
> mode)
>  
>  ret = qemu_open_cloexec(name, flags, mode);
>  
> +if (ret == -1) {
> +const char *action = flags & O_CREAT ? "create" : "open";
> +error_setg_errno(errp, errno, "Could not %s '%s'",
> + action, name);
> +}
> +
> +
>  return ret;
>  }

Much neater.  Thanks!

>  
> @@ -343,7 +353,7 @@ int qemu_open_old(const char *name, int flags, ...)
>  }
>  va_end(ap);
>  
> -ret = qemu_open_internal(name, flags, mode);
> +ret = qemu_open_internal(name, flags, mode, NULL);
>  
>  #ifdef O_DIRECT
>  if (ret == -1 && errno == EINVAL && (flags & O_DIRECT)) {

Reviewed-by: Markus Armbruster 




Re: [PATCH v2 09/15] fuzz: add a crossover function to generic-fuzzer

2020-09-03 Thread Darren Kenny
On Wednesday, 2020-08-19 at 02:11:04 -04, Alexander Bulekov wrote:
> Signed-off-by: Alexander Bulekov 
> ---
>  tests/qtest/fuzz/general_fuzz.c | 81 -
>  1 file changed, 80 insertions(+), 1 deletion(-)
>
> diff --git a/tests/qtest/fuzz/general_fuzz.c b/tests/qtest/fuzz/general_fuzz.c
> index 26fcd69e45..2c3716f8cc 100644
> --- a/tests/qtest/fuzz/general_fuzz.c
> +++ b/tests/qtest/fuzz/general_fuzz.c
> @@ -739,6 +739,83 @@ static void general_pre_fuzz(QTestState *s)
>  
>  counter_shm_init();
>  }
> +
> +/*
> + * When libfuzzer gives us two inputs to combine, return a new input with the
> + * following structure:
> + *
> + * Input 1 (data1)
> + * SEPARATOR
> + * Clear out the DMA Patterns
> + * SEPARATOR
> + * Disable the pci_read/write instructions
> + * SEPARATOR
> + * Input 2 (data2)
> + *
> + * The idea is to collate the core behaviors of the two inputs.
> + * For example:
> + * Input 1: maps a device's BARs, sets up three DMA patterns, and triggers
> + *  device functionality A
> + * Input 2: maps a device's BARs, sets up one DMA pattern, and triggers 
> device
> + *  functionality B
> + *
> + * This function attempts to produce an input that:
> + * Ouptut: maps a device's BARs, set up three DMA patterns, triggers
> + *  functionality A device, replaces the DMA patterns with a single
> + *  patten, and triggers device functionality B.
> + */
> +static size_t general_fuzz_crossover(const uint8_t *data1, size_t size1, 
> const
> + uint8_t *data2, size_t size2, uint8_t 
> *out,
> + size_t max_out_size, unsigned int seed)
> +{

I don't see this function as well documented, but it might be a good
idea to check up front whether out is not NULL and that the max_out_size
is capable of holding what you're likely to consume, i.e. approx:

  size1 + size2 + (SEPARATOR * 3) + 2 /* Ops */

If nothing else means you can be sure you won't have to call MIN() all
the time, but also that you won't end up only partially filling it too.

> +size_t copy = 0, size = 0;

NIT: Maybe copy should be copy_len or something rather than a verb?

> +
> +// Copy in the first input
> +copy = MIN(size1, max_out_size);
> +memcpy(out+size, data1, copy);
> +size+= copy;
> +max_out_size-= copy;
> +
> +// Append a separator
> +copy = MIN(strlen(SEPARATOR), max_out_size);
> +memcpy(out+size, SEPARATOR, copy);
> +size+= copy;
> +max_out_size-= copy;
> +
> +// Clear out the
> +copy = MIN(1, max_out_size);
> +if (copy) {
> +out[size] = OP_CLEAR_DMA_PATTERNS;
> +}
> +size+= copy;
> +max_out_size-= copy;
> +
> +copy = MIN(strlen(SEPARATOR), max_out_size);
> +memcpy(out+size, SEPARATOR, copy);
> +size+= copy;
> +max_out_size-= copy;
> +
> +copy = MIN(1, max_out_size);
> +if (copy) {
> +out[size] = OP_DISABLE_PCI;
> +}
> +size+= copy;
> +max_out_size-= copy;
> +
> +copy = MIN(strlen(SEPARATOR), max_out_size);
> +memcpy(out+size, SEPARATOR, copy);
> +size+= copy;
> +max_out_size-= copy;
> +
> +copy = MIN(size2, max_out_size);
> +memcpy(out+size, data2, copy);
> +size+= copy;
> +max_out_size-= copy;
> +
> +return  size;
> +}
> +
> +
>  static GString *general_fuzz_cmdline(FuzzTarget *t)
>  {
>  GString *cmd_line = g_string_new(TARGET_NAME);
> @@ -758,7 +835,9 @@ static void register_general_fuzz_targets(void)
>  .description = "Fuzz based on any qemu command-line args. ",
>  .get_init_cmdline = general_fuzz_cmdline,
>  .pre_fuzz = general_pre_fuzz,
> -.fuzz = general_fuzz});
> +.fuzz = general_fuzz,
> +.crossover = general_fuzz_crossover
> +});
>  }
>  
>  fuzz_target_init(register_general_fuzz_targets);

Thanks,

Darren.



Re: [PATCH v2 10/15] scripts/oss-fuzz: Add wrapper program for generic fuzzer

2020-09-03 Thread Darren Kenny
On Wednesday, 2020-08-19 at 02:11:05 -04, Alexander Bulekov wrote:
> On oss-fuzz we need some sort of wrapper to specify command-line
> arguments or environment variables. When we had a similar problem with
> other targets that I fixed with
> 05509c8e6d ("fuzz: select fuzz target using executable name")
> by selecting the fuzz target based on the executable's name. In the
> future should probably commit to one approach (wrapper binary or
> argv0-based target selection).
>
> Signed-off-by: Alexander Bulekov 

Reviewed-by: Darren Kenny 

> ---
>  scripts/oss-fuzz/target.c | 40 +++
>  1 file changed, 40 insertions(+)
>  create mode 100644 scripts/oss-fuzz/target.c
>
> diff --git a/scripts/oss-fuzz/target.c b/scripts/oss-fuzz/target.c
> new file mode 100644
> index 00..4a7257412a
> --- /dev/null
> +++ b/scripts/oss-fuzz/target.c
> @@ -0,0 +1,40 @@
> +/*
> + * Copyright Red Hat Inc., 2020
> + *
> + * Authors:
> + *  Alexander Bulekov   
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +
> +/* Required for oss-fuzz to consider the binary a target. */
> +static const char *magic __attribute__((used)) = "LLVMFuzzerTestOneInput";
> +static const char args[] = {QEMU_FUZZ_ARGS, 0x00};
> +static const char objects[] = {QEMU_FUZZ_OBJECTS, 0x00};
> +
> +int main(int argc, char *argv[])
> +{
> +char path[PATH_MAX] = {0};
> +char *dir = dirname(argv[0]);
> +strncpy(path, dir, PATH_MAX);
> +strcat(path, "/deps/qemu-fuzz-i386-target-general-fuzz");
> +
> +setenv("QEMU_FUZZ_ARGS", args, 0);
> +setenv("QEMU_FUZZ_OBJECTS", objects, 0);
> +
> +argv[0] = path;
> +int ret = execvp(path, argv);
> +if (ret) {
> +perror("execv");
> +}
> +return ret;
> +}
> -- 
> 2.27.0



Re: [PATCH v2 10/15] scripts/oss-fuzz: Add wrapper program for generic fuzzer

2020-09-03 Thread Darren Kenny
Just thinking after reading later code, that maybe this should be
renamed to something like target.c.tmpl, target_template.c, or similar
so that it is clearer that this is not used directly, but as a template
for generation of other targets.

Thanks,

Darren.


On Wednesday, 2020-08-19 at 02:11:05 -04, Alexander Bulekov wrote:
> On oss-fuzz we need some sort of wrapper to specify command-line
> arguments or environment variables. When we had a similar problem with
> other targets that I fixed with
> 05509c8e6d ("fuzz: select fuzz target using executable name")
> by selecting the fuzz target based on the executable's name. In the
> future should probably commit to one approach (wrapper binary or
> argv0-based target selection).
>
> Signed-off-by: Alexander Bulekov 
> ---
>  scripts/oss-fuzz/target.c | 40 +++
>  1 file changed, 40 insertions(+)
>  create mode 100644 scripts/oss-fuzz/target.c
>
> diff --git a/scripts/oss-fuzz/target.c b/scripts/oss-fuzz/target.c
> new file mode 100644
> index 00..4a7257412a
> --- /dev/null
> +++ b/scripts/oss-fuzz/target.c
> @@ -0,0 +1,40 @@
> +/*
> + * Copyright Red Hat Inc., 2020
> + *
> + * Authors:
> + *  Alexander Bulekov   
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +
> +/* Required for oss-fuzz to consider the binary a target. */
> +static const char *magic __attribute__((used)) = "LLVMFuzzerTestOneInput";
> +static const char args[] = {QEMU_FUZZ_ARGS, 0x00};
> +static const char objects[] = {QEMU_FUZZ_OBJECTS, 0x00};
> +
> +int main(int argc, char *argv[])
> +{
> +char path[PATH_MAX] = {0};
> +char *dir = dirname(argv[0]);
> +strncpy(path, dir, PATH_MAX);
> +strcat(path, "/deps/qemu-fuzz-i386-target-general-fuzz");
> +
> +setenv("QEMU_FUZZ_ARGS", args, 0);
> +setenv("QEMU_FUZZ_OBJECTS", objects, 0);
> +
> +argv[0] = path;
> +int ret = execvp(path, argv);
> +if (ret) {
> +perror("execv");
> +}
> +return ret;
> +}
> -- 
> 2.27.0



Re: [PATCH v2 11/15] scripts/oss-fuzz: Add general-fuzzer build script

2020-09-03 Thread Darren Kenny
On Wednesday, 2020-08-19 at 02:11:06 -04, Alexander Bulekov wrote:
> This parses a yaml file containing general-fuzzer configs and builds a
> separate oss-fuzz wrapper binary for each one, changing some
> preprocessor macros for each configuration. To avoid dealing with
> escaping and stringifying, convert each string into a byte-array
> representation
>
> Signed-off-by: Alexander Bulekov 
> ---
>  scripts/oss-fuzz/build_general_fuzzers.py | 62 +++
>  1 file changed, 62 insertions(+)
>  create mode 100755 scripts/oss-fuzz/build_general_fuzzers.py
>
> diff --git a/scripts/oss-fuzz/build_general_fuzzers.py 
> b/scripts/oss-fuzz/build_general_fuzzers.py
> new file mode 100755
> index 00..79f4664117
> --- /dev/null
> +++ b/scripts/oss-fuzz/build_general_fuzzers.py
> @@ -0,0 +1,62 @@
> +#!/usr/bin/env python3
> +# -*- coding: utf-8 -*-
> +
> +"""
> +This script creates wrapper binaries that invoke the general-device-fuzzer 
> with
> +configurations specified in a yaml config file.
> +"""
> +import sys
> +import os
> +import yaml
> +import tempfile
> +
> +CC = ""
> +TEMPLATE = ""
> +
> +
> +def usage():
> +print("Usage: CC=COMPILER {} CONFIG_PATH \
> +OUTPUT_PATH_PREFIX".format(sys.argv[0]))
> +sys.exit(0)
> +
> +
> +def str_to_c_byte_array(s):
> +"""
> +Convert strings to byte-arrays so we don't worry about formatting
> +strings to play nicely with cc -DQEMU_FUZZARGS etc
> +"""
> +return ','.join('0x{:02x}'.format(ord(x)) for x in s)
> +
> +
> +def compile_wrapper(cfg, path):
> +os.system('$CC -DQEMU_FUZZ_ARGS="{}" -DQEMU_FUZZ_OBJECTS="{}" \
> +{} -o {}'.format(
> +str_to_c_byte_array(cfg["args"].replace("\n", " ")),
> +str_to_c_byte_array(cfg["objects"].replace("\n", " ")),
> +TEMPLATE, path))

NIT: When using multiple placeholders, it is nicer to use names for
them, so that reordering, or adding new ones is easier too.

> +
> +
> +def main():
> +global CC
> +global TEMPLATE
> +
> +if len(sys.argv) != 3:
> +usage()
> +
> +cfg_path = sys.argv[1]
> +out_path = sys.argv[2]
> +
> +CC = os.getenv("CC")

Maybe provide a fall-back/default value if someone is calling it directly?

> +TEMPLATE = os.path.join(os.path.dirname(__file__), "target.c")

No harm to double-check this exists, but also I would suggest that the
string "target.c" should be defined as a global value.

> +
> +with open(cfg_path, "r") as f:
> +configs = yaml.load(f)["configs"]
> +for cfg in configs:
> +assert "name" in cfg
> +assert "args" in cfg
> +assert "objects" in cfg
> +compile_wrapper(cfg, out_path + cfg["name"])
> +
> +
> +if __name__ == '__main__':
> +main()
> -- 
> 2.27.0

Thanks,

Darren.




Re: [PATCH v2 13/15] scripts/oss-fuzz: build the general-fuzzer configs

2020-09-03 Thread Darren Kenny
On Wednesday, 2020-08-19 at 02:11:08 -04, Alexander Bulekov wrote:
> Build general-fuzzer wrappers for each configuration defined in
> general_fuzzer_configs.yml and move the actual general-fuzzer to a
> subdirectory, so oss-fuzz doesn't treat it as a standalone fuzzer.

You didn't mention the removeal of *uhci* from the config below, should
probably be at least referenced.

>
> Signed-off-by: Alexander Bulekov 

With that,

Reviewed-by: Darren Kenny 

Thanks,

Darren.

> ---
>  scripts/oss-fuzz/build.sh   | 8 +++-
>  scripts/oss-fuzz/general_fuzzer_configs.yml | 2 +-
>  2 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/oss-fuzz/build.sh b/scripts/oss-fuzz/build.sh
> index a07b3022e8..2071e77ac2 100755
> --- a/scripts/oss-fuzz/build.sh
> +++ b/scripts/oss-fuzz/build.sh
> @@ -38,7 +38,7 @@ OSS_FUZZ_BUILD_DIR="./build-oss-fuzz/"
>  # remove it, resulting in an unresolved reference to qemu_build_not_reached
>  # Undefine the __OPTIMIZE__ macro which compiler.h relies on to choose 
> whether
>  # to " #define qemu_build_not_reached()  g_assert_not_reached() "
> -EXTRA_CFLAGS="$CFLAGS -U __OPTIMIZE__"
> +EXTRA_CFLAGS="$CFLAGS -U __OPTIMIZE__ -DCONFIG_FUZZ=y"
>  
>  if ! { [ -e "./COPYING" ] &&
> [ -e "./MAINTAINERS" ] &&
> @@ -101,5 +101,11 @@ do
>  cp ./i386-softmmu/qemu-fuzz-i386 
> "$DEST_DIR/qemu-fuzz-i386-target-$target"
>  done
>  
> +mkdir -p "$DEST_DIR/deps"
> +mv "$DEST_DIR/qemu-fuzz-i386-target-general-fuzz" "$DEST_DIR/deps/"
> +
> +./scripts/oss-fuzz/build_general_fuzzers.py \
> +"./scripts/oss-fuzz/general_fuzzer_configs.yml" "$DEST_DIR/general-fuzz-"
> +
>  echo "Done. The fuzzers are located in $DEST_DIR"
>  exit 0
> diff --git a/scripts/oss-fuzz/general_fuzzer_configs.yml 
> b/scripts/oss-fuzz/general_fuzzer_configs.yml
> index 010e92a2a5..f70bacb243 100644
> --- a/scripts/oss-fuzz/general_fuzzer_configs.yml
> +++ b/scripts/oss-fuzz/general_fuzzer_configs.yml
> @@ -92,7 +92,7 @@ configs:
>  -device usb-braille,chardev=cd0 -device usb-ccid -device usb-ccid
>  -device usb-kbd -device usb-mouse -device usb-serial,chardev=cd1
>  -device usb-tablet -device usb-wacom-tablet -device usb-audio
> -  objects: "*usb* *uhci* *xhci*"
> +  objects: "*usb* *xhci*"
>  
>  - name: pc-i440fx
>args: -machine pc
> -- 
> 2.27.0



Re: [PATCH v2 12/15] scripts/oss-fuzz: Add general-fuzzer configs for oss-fuzz

2020-09-03 Thread Darren Kenny
On Wednesday, 2020-08-19 at 02:11:07 -04, Alexander Bulekov wrote:
> Each of these entries is built into a wrapper binary that sets the
> needed environment variables and executes the general virtual-device
> fuzzer. In the future, we will need additional fields, such as arch=arm,
> timeout_per_testcase=0, reset=reboot, etc...
>
> Signed-off-by: Alexander Bulekov 

Reviewed-by: Darren Kenny 

> ---
>  scripts/oss-fuzz/general_fuzzer_configs.yml | 103 
>  1 file changed, 103 insertions(+)
>  create mode 100644 scripts/oss-fuzz/general_fuzzer_configs.yml
>
> diff --git a/scripts/oss-fuzz/general_fuzzer_configs.yml 
> b/scripts/oss-fuzz/general_fuzzer_configs.yml
> new file mode 100644
> index 00..010e92a2a5
> --- /dev/null
> +++ b/scripts/oss-fuzz/general_fuzzer_configs.yml
> @@ -0,0 +1,103 @@
> +configs:
> +- name: virtio-net-pci-slirp
> +  args: >
> +-M q35 -nodefaults
> +-device virtio-net,netdev=net0 -netdev user,id=net0
> +  objects: virtio*
> +
> +- name: virtio-blk
> +  args: >
> +-machine q35 -device virtio-blk,drive=disk0
> +-drive file=null-co://,id=disk0,if=none,format=raw
> +  objects: virtio*
> +
> +- name: virtio-scsi
> +  args: >
> +-machine q35 -device virtio-scsi,num_queues=8
> +-device scsi-hd,drive=disk0
> +-drive file=null-co://,id=disk0,if=none,format=raw
> +  objects: scsi* virtio*
> +
> +- name: virtio-gpu
> +  args: -machine q35 -nodefaults -device virtio-gpu
> +  objects: virtio*
> +
> +- name: virtio-vga
> +  args: -machine q35 -nodefaults -device virtio-vga
> +  objects: virtio*
> +
> +- name: virtio-rng
> +  args: -machine q35 -nodefaults -device virtio-rng
> +  objects: virtio*
> +
> +- name: virtio-balloon
> +  args: -machine q35 -nodefaults -device virtio-balloon
> +  objects: virtio*
> +
> +- name: virtio-serial
> +  args: -machine q35 -nodefaults -device virtio-serial
> +  objects: virtio*
> +
> +- name: virtio-mouse
> +  args: -machine q35 -nodefaults -device virtio-mouse
> +  objects: virtio*
> +
> +- name: e1000
> +  args: >
> +-M q35 -nodefaults
> +-device e1000,netdev=net0 -netdev user,id=net0
> +  objects: e1000
> +
> +- name: e1000e
> +  args: >
> +-M q35 -nodefaults
> +-device e1000e,netdev=net0 -netdev user,id=net0
> +  objects: e1000e
> +
> +- name: cirrus-vga
> +  args: -machine q35 -nodefaults -device cirrus-vga
> +  objects: cirrus*
> +
> +- name: bochs-display
> +  args: -machine q35 -nodefaults -device bochs-display
> +  objects: bochs*
> +
> +- name: intel-hda
> +  args: >
> +-machine q35 -nodefaults -device intel-hda,id=hda0
> +-device hda-output,bus=hda0.0 -device hda-micro,bus=hda0.0
> +-device hda-duplex,bus=hda0.0
> +  objects: intel-hda
> +
> +- name: ide-hd
> +  args: >
> +-machine q35 -nodefaults
> +-drive file=null-co://,if=none,format=raw,id=disk0
> +-device ide-hd,drive=disk0
> +  objects: ahci*
> +
> +- name: floppy
> +  args: >
> +-machine pc -nodefaults -device floppy,id=floppy0
> +-drive id=disk0,file=null-co://,file.read-zeroes=on,if=none
> +-device floppy,drive=disk0,drive-type=288
> +  objects: fd* floppy*
> +
> +- name: xhci
> +  args: >
> +-machine q35 -nodefaults
> +-drive file=null-co://,if=none,format=raw,id=disk0
> +-device qemu-xhci,id=xhci -device usb-tablet,bus=xhci.0 -device 
> usb-bot
> +-device usb-storage,drive=disk0 -chardev null,id=cd0 -chardev 
> null,id=cd1
> +-device usb-braille,chardev=cd0 -device usb-ccid -device usb-ccid
> +-device usb-kbd -device usb-mouse -device usb-serial,chardev=cd1
> +-device usb-tablet -device usb-wacom-tablet -device usb-audio
> +  objects: "*usb* *uhci* *xhci*"
> +
> +- name: pc-i440fx
> +  args: -machine pc
> +  objects: "*"
> +
> +- name: pc-q35
> +  args: -machine q35
> +  objects: "*"
> -- 
> 2.27.0



make -i check resut for msys2

2020-09-03 Thread Yonggang Luo
$ make -i check
Regenerating build files.
Directory does not contain a valid build tree:
C:/work/xemu/qemu/build
make: [Makefile.ninja:5217:build.ninja] 错误 1 (已忽略)
make[1]: 进入目录“/c/work/xemu/qemu/slirp”
make[1]: 对“all”无需做任何事。
make[1]: 离开目录“/c/work/xemu/qemu/slirp”
Generating qemu-version.h with a meson_exe.py custom command
Running test decodetree
Running test QAPI schema regression tests
Running test QAPI doc
Running test QAPI schema regression tests
Running test QAPI doc
  LINKtests/test-aio-multithread.exe
  LINKtests/test-bdrv-drain.exe
  CC  tests/test-qht-par.o
  LINKtests/test-qht-par.exe
  TESTcheck-unit: tests/check-qdict.exe
  TESTcheck-unit: tests/check-block-qdict.exe
  TESTcheck-unit: tests/check-qnum.exe
  TESTcheck-unit: tests/check-qstring.exe
  TESTcheck-unit: tests/check-qlist.exe
  TESTcheck-unit: tests/check-qnull.exe
  TESTcheck-unit: tests/check-qobject.exe
  TESTcheck-unit: tests/check-qjson.exe
  TESTcheck-unit: tests/check-qlit.exe
  TESTcheck-unit: tests/test-qobject-output-visitor.exe
  TESTcheck-unit: tests/test-clone-visitor.exe
  TESTcheck-unit: tests/test-qobject-input-visitor.exe
  TESTcheck-unit: tests/test-qmp-cmds.exe
  TESTcheck-unit: tests/test-string-input-visitor.exe
  TESTcheck-unit: tests/test-string-output-visitor.exe
  TESTcheck-unit: tests/test-qmp-event.exe
  TESTcheck-unit: tests/test-opts-visitor.exe
  TESTcheck-unit: tests/test-coroutine.exe
  TESTcheck-unit: tests/test-visitor-serialization.exe
  TESTcheck-unit: tests/test-iov.exe
  TESTcheck-unit: tests/test-bitmap.exe
  TESTcheck-unit: tests/test-aio.exe
  TESTcheck-unit: tests/test-aio-multithread.exe

(C:\work\xemu\qemu\build\tests\test-aio-multithread.exe:15216):
GLib-CRITICAL **: 17:11:56.670: g_source_remove_poll: assertion
'!SOURCE_DESTROYED (source)' failed
ERROR test-aio-multithread.exe - Bail out! GLib-FATAL-CRITICAL:
g_source_remove_poll: assertion '!SOURCE_DESTROYED (source)' failed
make: [C:/work/xemu/qemu/tests/Makefile.include:426:check-unit] 错误 1 (已忽略)
  TESTcheck-unit: tests/test-throttle.exe
  TESTcheck-unit: tests/test-thread-pool.exe
  TESTcheck-unit: tests/test-hbitmap.exe
  TESTcheck-unit: tests/test-bdrv-drain.exe

(C:\work\xemu\qemu\build\tests\test-bdrv-drain.exe:9152): GLib-CRITICAL **:
17:12:01.403: g_source_remove_poll: assertion '!SOURCE_DESTROYED (source)'
failed
ERROR test-bdrv-drain.exe - Bail out! GLib-FATAL-CRITICAL:
g_source_remove_poll: assertion '!SOURCE_DESTROYED (source)' failed
make: [C:/work/xemu/qemu/tests/Makefile.include:426:check-unit] 错误 1 (已忽略)
  TESTcheck-unit: tests/test-bdrv-graph-mod.exe
  TESTcheck-unit: tests/test-blockjob.exe
  TESTcheck-unit: tests/test-blockjob-txn.exe
  TESTcheck-unit: tests/test-block-backend.exe
  TESTcheck-unit: tests/test-block-iothread.exe
  TESTcheck-unit: tests/test-x86-cpuid.exe
  TESTcheck-unit: tests/test-xbzrle.exe
  TESTcheck-unit: tests/test-cutils.exe
  TESTcheck-unit: tests/test-shift128.exe
  TESTcheck-unit: tests/test-mul64.exe
  TESTcheck-unit: tests/test-int128.exe
  TESTcheck-unit: tests/rcutorture.exe
  TESTcheck-unit: tests/test-rcu-list.exe
  TESTcheck-unit: tests/test-rcu-simpleq.exe
  TESTcheck-unit: tests/test-rcu-tailq.exe
  TESTcheck-unit: tests/test-rcu-slist.exe
  TESTcheck-unit: tests/test-qdist.exe
  TESTcheck-unit: tests/test-qht.exe
  TESTcheck-unit: tests/test-qht-par.exe
系统找不到指定的路径。
**
ERROR:C:/work/xemu/qemu/tests/test-qht-par.c:20:test_qht: assertion failed
(rc == 0): (1 == 0)
ERROR test-qht-par.exe - Bail out!
ERROR:C:/work/xemu/qemu/tests/test-qht-par.c:20:test_qht: assertion failed
(rc == 0): (1 == 0)
make: [C:/work/xemu/qemu/tests/Makefile.include:426:check-unit] 错误 1 (已忽略)
  TESTcheck-unit: tests/test-bitops.exe
  TESTcheck-unit: tests/test-bitcnt.exe
  TESTcheck-unit: tests/test-qgraph.exe
  TESTcheck-unit: tests/check-qom-interface.exe
  TESTcheck-unit: tests/check-qom-proplist.exe
  TESTcheck-unit: tests/test-qemu-opts.exe
  TESTcheck-unit: tests/test-keyval.exe
  TESTcheck-unit: tests/test-write-threshold.exe
  TESTcheck-unit: tests/test-crypto-hash.exe
  TESTcheck-unit: tests/test-crypto-hmac.exe
  TESTcheck-unit: tests/test-crypto-cipher.exe
  TESTcheck-unit: tests/test-crypto-secret.exe
  TESTcheck-unit: tests/test-crypto-tlscredsx509.exe
ERROR test-crypto-tlscredsx509.exe - missing test plan
make: [C:/work/xemu/qemu/tests/Makefile.include:426:check-unit] 错误 1 (已忽略)
  TESTcheck-unit: tests/test-crypto-tlssession.exe
ERROR test-crypto-tlssession.exe - missing test plan
make: [C:/work/xemu/qemu/tests/Makefile.include:426:check-unit] 错误 1 (已忽略)
  TESTcheck-unit: tests/test-qdev-global-props.exe
**
ERROR:C:/work/xemu/qemu/tests/test-qdev-global-props.c:253:test_dynamic_globalprop:
stderr of child process (/qdev/properties/dynamic/glob

Re: [PATCH v2 14/15] scripts/oss-fuzz: Add script to reorder a general-fuzzer trace

2020-09-03 Thread Darren Kenny
On Wednesday, 2020-08-19 at 02:11:09 -04, Alexander Bulekov wrote:
> The general-fuzzer uses hooks to fulfill DMA requests just-in-time.
> This means that if we try to use QTEST_LOG=1 to build a reproducer, the
> DMA writes will be logged _after_ the in/out/read/write that triggered
> the DMA read. To work work around this, the general-fuzzer annotates
> these just-in time DMA fulfilments with a tag that we can use to
> discern them. This script simply iterates over a raw qtest
> trace (including log messages, errors, timestamps etc), filters it and
> re-orders it so that DMA fulfillments are placed directly _before_ the
> qtest command that will cause the DMA access.
>
> Signed-off-by: Alexander Bulekov 

Reviewed-by: Darren Kenny 

> ---
>  .../oss-fuzz/reorder_fuzzer_qtest_trace.py| 94 +++
>  1 file changed, 94 insertions(+)
>  create mode 100755 scripts/oss-fuzz/reorder_fuzzer_qtest_trace.py
>
> diff --git a/scripts/oss-fuzz/reorder_fuzzer_qtest_trace.py 
> b/scripts/oss-fuzz/reorder_fuzzer_qtest_trace.py
> new file mode 100755
> index 00..9fb7edb6ee
> --- /dev/null
> +++ b/scripts/oss-fuzz/reorder_fuzzer_qtest_trace.py
> @@ -0,0 +1,94 @@
> +#!/usr/bin/env python3
> +# -*- coding: utf-8 -*-
> +
> +"""
> +Use this to convert qtest log info from a generic fuzzer input into a qtest
> +trace that you can feed into a standard qemu-system process. Example usage:
> +
> +QEMU_FUZZ_ARGS="-machine q35,accel=qtest" QEMU_FUZZ_OBJECTS="*" \
> +./i386-softmmu/qemu-fuzz-i386 --fuzz-target=general-pci-fuzz
> +# .. Finds some crash
> +QTEST_LOG=1 FUZZ_SERIALIZE_QTEST=1 \
> +QEMU_FUZZ_ARGS="-machine q35,accel=qtest" QEMU_FUZZ_OBJECTS="*" \
> +./i386-softmmu/qemu-fuzz-i386 --fuzz-target=general-pci-fuzz
> +/path/to/crash 2> qtest_log_output
> +scripts/oss-fuzz/reorder_fuzzer_qtest_trace.py qtest_log_output > qtest_trace
> +./i386-softmmu/qemu-fuzz-i386 -machine q35,accel=qtest \
> +-qtest stdin < qtest_trace
> +
> +### Details ###
> +
> +Some fuzzer make use of hooks that allow us to populate some memory range, 
> just
> +before a DMA read from that range. This means that the fuzzer can produce
> +activity that looks like:
> +[start] read from mmio addr
> +[end]   read from mmio addr
> +[start] write to pio addr
> +[start] fill a DMA buffer just in time
> +[end]   fill a DMA buffer just in time
> +[start] fill a DMA buffer just in time
> +[end]   fill a DMA buffer just in time
> +[end]   write to pio addr
> +[start] read from mmio addr
> +[end]   read from mmio addr
> +
> +We annotate these "nested" DMA writes, so with QTEST_LOG=1 the QTest trace
> +might look something like:
> +[R +0.028431] readw 0x1
> +[R +0.028434] outl 0xc000 0xbeef  # Triggers a DMA read from 0xbeef and 
> 0xbf00
> +[DMA][R +0.034639] write 0xbeef 0x2 0x
> +[DMA][R +0.034639] write 0xbf00 0x2 0x
> +[R +0.028431] readw 0xfc000
> +
> +This script would reorder the above trace so it becomes:
> +readw 0x1
> +write 0xbeef 0x2 0x
> +write 0xbf00 0x2 0x
> +outl 0xc000 0xbeef
> +readw 0xfc000
> +
> +I.e. by the time, 0xc000 tries to read from DMA, those DMA buffers have 
> already
> +been set up, removing the need for the DMA hooks. We can simply provide this
> +reordered trace via -qtest stdio to reproduce the input
> +
> +Note: this won't work for traces where the device tries to read from the same
> +DMA region twice in between MMIO/PIO commands. E.g:
> +[R +0.028434] outl 0xc000 0xbeef
> +[DMA][R +0.034639] write 0xbeef 0x2 0x
> +[DMA][R +0.034639] write 0xbeef 0x2 0x
> +"""
> +
> +import sys
> +
> +__author__ = "Alexander Bulekov "
> +__copyright__  = "Copyright (C) 2020, Red Hat, Inc."
> +__license__= "GPL version 2 or (at your option) any later version"
> +
> +__maintainer__ = "Alexander Bulekov"
> +__email__  = "alx...@bu.edu"
> +
> +
> +def usage():
> +sys.exit("Usage: {} /path/to/qtest_log_output".format((sys.argv[0])))
> +
> +
> +def main(filename):
> +with open(filename, "r") as f:
> +trace = f.readlines()
> +
> +# Leave only lines that look like logged qtest commands
> +trace[:] = [x.strip() for x in trace if "[R +" in x
> +or "[S +" in x and "CLOSED" not in x]
> +
> +for i in range(len(trace)):
> +if i+1 < len(trace):
> +if "[DMA]" in trace[i+1]:
> +trace[i], trace[i+1] = trace[i+1], trace[i]
> +for line in trace:
> +print(line.split("]")[-1].strip())
> +
> +
> +if __name__ == '__main__':
> +if len(sys.argv) == 1:
> +usage()
> +main(sys.argv[1])
> -- 
> 2.27.0



Re: [PATCH v2 15/15] scripts/oss-fuzz: Add crash trace minimization script

2020-09-03 Thread Darren Kenny
On Wednesday, 2020-08-19 at 02:11:10 -04, Alexander Bulekov wrote:
> Once we find a crash, we can convert it into a QTest trace. Usually this
> trace will contain many operations that are unneeded to reproduce the
> crash. This script tries to minimize the crashing trace, by removing
> operations and trimming QTest bufwrite(write addr len data...) commands.
>
> Signed-off-by: Alexander Bulekov 
> ---
>  scripts/oss-fuzz/minimize_qtest_trace.py | 118 +++
>  1 file changed, 118 insertions(+)
>  create mode 100755 scripts/oss-fuzz/minimize_qtest_trace.py
>
> diff --git a/scripts/oss-fuzz/minimize_qtest_trace.py 
> b/scripts/oss-fuzz/minimize_qtest_trace.py
> new file mode 100755
> index 00..2f1f4f368e
> --- /dev/null
> +++ b/scripts/oss-fuzz/minimize_qtest_trace.py
> @@ -0,0 +1,118 @@
> +#!/usr/bin/env python3
> +# -*- coding: utf-8 -*-
> +
> +"""
> +This takes a crashing qtest trace and tries to remove superflous operations
> +"""
> +
> +import sys
> +import os
> +import subprocess
> +import time
> +
> +QEMU_ARGS = None
> +QEMU_PATH = None
> +TIMEOUT = 5
> +CRASH_TOKEN = None
> +
> +
> +def usage():
> +sys.exit("""\
> +Usage: QEMU_PATH="/path/to/qemu" QEMU_ARGS="args" {} input_trace output_trace
> +By default, will try to use the second-to-last line in the output to identify
> +whether the crash occred. Optionally, manually set a string that idenitifes 
> the
> +crash by setting CRASH_TOKEN=
> +""".format((sys.argv[0])))
> +
> +
> +def check_if_trace_crashes(trace, path):
> +global CRASH_TOKEN
> +with open(path, "w") as tracefile:
> +tracefile.write("".join(trace))
> +rc = subprocess.Popen("timeout -s 9 {}s {} {} 2>&1 < {}".format(TIMEOUT,
> +  QEMU_PATH, QEMU_ARGS, path),
> +  shell=True, stdin=subprocess.PIPE,
> +  stdout=subprocess.PIPE)

NIT: Similar comment to before, it is nicer to name the placeholders if
 there are more than 1 and you can.

> +stdo = rc.communicate()[0]
> +output = stdo.decode('unicode_escape')
> +if rc.returncode == 137:# Timed Out
> +return False
> +if len(output.splitlines()) < 2:
> +return False
> +
> +if CRASH_TOKEN is None:
> +CRASH_TOKEN = output.splitlines()[-2]
> +
> +return CRASH_TOKEN in output
> +
> +
> +def minimize_trace(inpath, outpath):
> +global TIMEOUT
> +with open(inpath) as f:
> +trace = f.readlines()
> +start = time.time()
> +if not check_if_trace_crashes(trace, outpath):
> +sys.exit("The input qtest trace didn't cause a crash...")
> +end = time.time()
> +print("Crashed in {} seconds".format(end-start))
> +TIMEOUT = (end-start)*5
> +print("Setting the timeout for {} seconds".format(TIMEOUT))
> +print("Identifying Crashes by this string: {}".format(CRASH_TOKEN))
> +
> +i = 0
> +newtrace = trace[:]
> +while i < len(newtrace):
> +prior = newtrace[i]
> +print("Trying to remove {}".format(newtrace[i]))
> +# Try to remove the line completely
> +newtrace[i] = ""
> +if check_if_trace_crashes(newtrace, outpath):
> +i += 1
> +continue
> +newtrace[i] = prior
> +# Try to split up writes into multiple commands, each of which can be
> +# removed.
> +if newtrace[i].startswith("write "):

NIT: Would be good to document the assumptions here, just in case things
 change in future.

> +addr = int(newtrace[i].split()[1], 16)
> +length = int(newtrace[i].split()[2], 16)
> +data = newtrace[i].split()[3][2:]
> +if length > 1:
> +leftlength = int(length/2)
> +rightlength = length - leftlength
> +newtrace.insert(i+1, "")
> +while leftlength > 0:
> +newtrace[i] = "write {} {} 0x{}\n".format(
> +hex(addr),
> +hex(leftlength),
> +data[:leftlength*2])
> +newtrace[i+1] = "write {} {} 0x{}\n".format(
> +hex(addr+leftlength),
> +hex(rightlength),
> +data[leftlength*2:])

NIT: Similar comment w.r.t. naming the placeholders.

> +if check_if_trace_crashes(newtrace, outpath):
> +break
> +else:
> +leftlength -= 1
> +rightlength += 1
> +if check_if_trace_crashes(newtrace, outpath):
> +i -= 1
> +else:
> +newtrace[i] = prior
> +del newtrace[i+1]
> +i += 1
> +check_if_trace_crashes(newtrace, outpath)
> +
> +
> +if __name__ == '__main__':
> +if len(sys.argv) < 3:
> +usage()
> +
> +QEMU_PATH = os.getenv("QEMU_PATH")
> +QEMU

Re: [PATCH] 9pfs: log warning if msize <= 8192

2020-09-03 Thread Greg Kurz
On Thu, 03 Sep 2020 10:20:40 +0200
Christian Schoenebeck  wrote:

> On Mittwoch, 2. September 2020 18:54:22 CEST Greg Kurz wrote:
> > > Well, I can do that of course. But somehow I fear users get lost by just
> > > pointing them to "man 1 qemu" in the log message. It already starts that
> > > e.g. on Debian there is no "man qemu", it is "man qemu-system" there
> > > instead. Next issue is that qemu man page is currently not structured in
> > > a way that would> 
> > > allow me to directly point them to the relevant man heading like:
> > >   man --pager='less -p ^9P-msize' qemu
> > > 
> > > So they would need to scroll their way through the entire man page by
> > > themselfes and find confusing sections like "-fsdev -device virtio-9p-pci"
> > > vs. "-virtfs", etc. I can imagine some people will struggle with that.
> > > 
> > > With a link like "https://wiki.qemu.org/Documentation/9psetup#msize"; the
> > > thing would be crystal clear within seconds.
> > > 
> > > Just my opinion. Greg?
> > 
> > Fine by me for this patch.
> > 
> > For a longer term, maybe we should find a way to advertise some hint
> > for msize to the guest... Not sure how to do that though.
> 
> On the long term that would be possible, however only with a protocol change 
> allowing server to send minimum, maximum and recommended msize to client.
> 

Hmm... not sure adding a new 9P protocol version for this is the
way to go. Not speaking of all the hustle this would cause, these
msizes rather look like properties of the device that the guest
can use to configure the 9P session.

What about adding them to the virtio-9p device config along with
the mount 'tag' and teach trans_virtio.c in linux to expose them
as well in the sysfs entry of the device ?

This could also be the occasion to describe virtio-9p in the virtio
spec [1]. Something that has been sitting on my TODO list for years
but I could never find time to consider...

[1] https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.html

> As you know, right now server only has a say in maximum msize.
> 

I guess you mean minimum size ?

> Best regards,
> Christian Schoenebeck
> 
> 




Re: [PATCH v3 7/7] migration: introduce snapshot-{save, load, delete} QMP commands

2020-09-03 Thread Markus Armbruster
Daniel P. Berrangé  writes:

> On Wed, Sep 02, 2020 at 11:27:17AM +0200, Markus Armbruster wrote:
>> Daniel P. Berrangé  writes:
>> 
>> > On Tue, Sep 01, 2020 at 04:20:47PM +0200, Markus Armbruster wrote:
>> >> Daniel P. Berrangé  writes:
>> >> 
>> >> > savevm, loadvm and delvm are some of the few HMP commands that have 
>> >> > never
>> >> > been converted to use QMP. The primary reason for this lack of 
>> >> > conversion
>> >> > is that they block execution of the thread for as long as they run.
>> >> 
>> >> Nope.  The primary reason is that the HMP interface is bonkers.
>> >
>> > I don't think that's very helpful description. The HMP interface has
>> > some limitations, but it isn't bonkers - it just doesn't cope with
>> > all the use cases we want. Many people use it succesfully without
>> > issue
>> 
>> It's non-bonkers for the case it was designed for: one disk backed by
>> QCOW2, plus maybe a CD-ROM.  The user is responsible for ensuring the
>> CD-ROM's media at loadvm time matches the one at savevm time.  The user
>> is further responsible for ensuring the guest-visible configuration
>> matches the one at savevm time.  No worse than migration.
>
> It is fine for multiple writable disks too, if they're all qcow2 backed.
>
>> It becomes useless as soon as you have writable non-QCOW2 block devices.
>> "Stop machine, take external snapshots, savevm, restart machine" should
>> work, but doesn't.
>
> External snapshots can be made to work today if you're willing to pause
> the VM CPUs while you take the external snapshots, and run the migration
> to capture VM state.

Yes.

Pausing is necessary because we don't have a way to take snapshots when
migration completes.

Even if we had it, live migration to file would be a problematic way to
capture VM state, because it doesn't update changing state in place.

savevm is not live either, of course.

My point is that savevm is "QCOW2 or bust" unnecessarily.  Your proposed
QMP interface isn't.

>  The main reason apps like Boxes / Virt-manager don't
> use external snapshots is that they require more complicated decision
> making. For each type of storage you're dealing with you have a potentially
> different way to manage the external snapshot. Boxes took the view that it
> would only support qcow2 to avoid making those decisions. virt-manager has
> support for all types of storage and simply doesn't want to add the complex
> logic to deal with non-qcow2. 
>
>> It becomes bonkers as soon as you have more than one QCOW2: which one
>> receives the system state?  It depends on the order in which they got
>> configured or some craziness like that.  Undocumented of course.
>
> Saying it is the first configured disk was not that crazy. This has been
> a pretty well defined semantic historically, as disks are usually added
> to QEMU in a predictable order, because that in turn controls how QEMU
> assigns addresses, and thus the order in which guest OS detect them.
>
> The introduction of use of the block layer for UEFI storage really
> threw a spanner in the works from QEMU's side. Even then the semantics
> aren't bad from a app's POV - first disk is still well defined as a
> concept, as UEFI vars isn't really considered a disk from an app POV.
>
>> Therefore, the commit message's claim "the primary reason for this lack
>> of conversion is that they block execution of the thread for as long as
>> they run" is factually wrong.
>
> That part of the commit message is referring to the original reason for
> not porting loadvm/savevm when QMP was first created 10+ years ago, which
> was primarily due to its blocking nature. The issues around disk selection
> post-date that. I'll modify it to describe both issues
>
>
>> >> > +#
>> >> > +# Applications should not assume that the snapshot save is complete
>> >> > +# when this command returns.
>> >> 
>> >> Is it complete then with the current code?  I'm asking because such
>> >> properties have a way to sneakily become de facto ABI.  We may not be
>> >> able to do anything about that now, other than documenting "don't do
>> >> that" like you did, but I'd like to understand the state of affairs all
>> >> the same.
>> >
>> > Yes, the actual snapshot is synchronous with return of the command.
>> 
>> Are there any failure modes where the command succeeds, and query-jobs
>> shows the error?
>
> As implemented in this series, the commands always succeed with the
> errors only ever reported via query-jobs. So for error detection
> you are already forced to use  the job framework.

This is what I hoped for when I asked.  It makes misuse of the interface
unlikely to survive basic testing.  Pretty much eliminates the risk of
misuse becoming de facto ABI over time.

> If you want to see some examples, take a look at the very last patch
> in the series which introduces I/O test 310. The test covers various
> success and failure scenarios, so you can see the behaviour we are
> currently generating with this series.
>
>
>

[Bug 1894071] [NEW] qemu-i386-static ioctl return -14 (Bad Address)

2020-09-03 Thread Tony.LI
Public bug reported:

I use qemu-i386-static on 64 bit ARM.But I don't know how to solve some 
problems.
First I added some ioctl operations.
Then I tried to do some DRM operations like test.c.
This is successful when I use qemu-x86_64-static,but it failed when I use 
qemu-i386-static.
I can get some strace info like this:

403 openat(AT_FDCWD,"/dev/dri/card0",O_RDWR|O_LARGEFILE|O_CLOEXEC) = 4
403 ioctl(4,DRM_IOCTL_GET_CAP,{1,0}) = 0 ({1,1})
403 ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,0,0,0,0,0,0,0,0,0,0,0}) = 0 
({0,0,0,0,0,2,2,2,0,16384,0,16384})
403 brk(NULL) = 0x40006000
403 brk(0x40027000) = 0x40027000
403 brk(0x40028000) = 0x40028000
403 
ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,1073766816,1073766832,1073766848,0,2,2,2,0,16384,0,16384})
 = -1 errno=14 (Bad address)

And there are similar errors in other self driven operations.
I want to know if it is QEMU's problem, so I hope to get some help. 
Thank you!

** Affects: qemu
 Importance: Undecided
 Status: New

** Attachment added: "strace.txt"
   https://bugs.launchpad.net/bugs/1894071/+attachment/5407366/+files/strace.txt

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

Title:
  qemu-i386-static ioctl return -14 (Bad Address)

Status in QEMU:
  New

Bug description:
  I use qemu-i386-static on 64 bit ARM.But I don't know how to solve some 
problems.
  First I added some ioctl operations.
  Then I tried to do some DRM operations like test.c.
  This is successful when I use qemu-x86_64-static,but it failed when I use 
qemu-i386-static.
  I can get some strace info like this:

  403 openat(AT_FDCWD,"/dev/dri/card0",O_RDWR|O_LARGEFILE|O_CLOEXEC) = 4
  403 ioctl(4,DRM_IOCTL_GET_CAP,{1,0}) = 0 ({1,1})
  403 ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,0,0,0,0,0,0,0,0,0,0,0}) = 0 
({0,0,0,0,0,2,2,2,0,16384,0,16384})
  403 brk(NULL) = 0x40006000
  403 brk(0x40027000) = 0x40027000
  403 brk(0x40028000) = 0x40028000
  403 
ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,1073766816,1073766832,1073766848,0,2,2,2,0,16384,0,16384})
 = -1 errno=14 (Bad address)

  And there are similar errors in other self driven operations.
  I want to know if it is QEMU's problem, so I hope to get some help. 
  Thank you!

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



[Bug 1894071] Re: qemu-i386-static ioctl return -14 (Bad Address)

2020-09-03 Thread Tony.LI
** Attachment added: "syscall_types.h"
   
https://bugs.launchpad.net/qemu/+bug/1894071/+attachment/5407370/+files/syscall_types.h

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

Title:
  qemu-i386-static ioctl return -14 (Bad Address)

Status in QEMU:
  New

Bug description:
  I use qemu-i386-static on 64 bit ARM.But I don't know how to solve some 
problems.
  First I added some ioctl operations.
  Then I tried to do some DRM operations like test.c.
  This is successful when I use qemu-x86_64-static,but it failed when I use 
qemu-i386-static.
  I can get some strace info like this:

  403 openat(AT_FDCWD,"/dev/dri/card0",O_RDWR|O_LARGEFILE|O_CLOEXEC) = 4
  403 ioctl(4,DRM_IOCTL_GET_CAP,{1,0}) = 0 ({1,1})
  403 ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,0,0,0,0,0,0,0,0,0,0,0}) = 0 
({0,0,0,0,0,2,2,2,0,16384,0,16384})
  403 brk(NULL) = 0x40006000
  403 brk(0x40027000) = 0x40027000
  403 brk(0x40028000) = 0x40028000
  403 
ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,1073766816,1073766832,1073766848,0,2,2,2,0,16384,0,16384})
 = -1 errno=14 (Bad address)

  And there are similar errors in other self driven operations.
  I want to know if it is QEMU's problem, so I hope to get some help. 
  Thank you!

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



[Bug 1894071] Re: qemu-i386-static ioctl return -14 (Bad Address)

2020-09-03 Thread Tony.LI
** Attachment added: "syscall_defs.h"
   
https://bugs.launchpad.net/qemu/+bug/1894071/+attachment/5407369/+files/syscall_defs.h

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

Title:
  qemu-i386-static ioctl return -14 (Bad Address)

Status in QEMU:
  New

Bug description:
  I use qemu-i386-static on 64 bit ARM.But I don't know how to solve some 
problems.
  First I added some ioctl operations.
  Then I tried to do some DRM operations like test.c.
  This is successful when I use qemu-x86_64-static,but it failed when I use 
qemu-i386-static.
  I can get some strace info like this:

  403 openat(AT_FDCWD,"/dev/dri/card0",O_RDWR|O_LARGEFILE|O_CLOEXEC) = 4
  403 ioctl(4,DRM_IOCTL_GET_CAP,{1,0}) = 0 ({1,1})
  403 ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,0,0,0,0,0,0,0,0,0,0,0}) = 0 
({0,0,0,0,0,2,2,2,0,16384,0,16384})
  403 brk(NULL) = 0x40006000
  403 brk(0x40027000) = 0x40027000
  403 brk(0x40028000) = 0x40028000
  403 
ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,1073766816,1073766832,1073766848,0,2,2,2,0,16384,0,16384})
 = -1 errno=14 (Bad address)

  And there are similar errors in other self driven operations.
  I want to know if it is QEMU's problem, so I hope to get some help. 
  Thank you!

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



[Bug 1894071] Re: qemu-i386-static ioctl return -14 (Bad Address)

2020-09-03 Thread Tony.LI
This problem has bothered me for a long time, but I'm not sure whether
it's the IOCTL () I added or the QEMU with 32 bits. I hope we can
discuss it and help our friends who have other problems.

Thank you,my friends!

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

Title:
  qemu-i386-static ioctl return -14 (Bad Address)

Status in QEMU:
  New

Bug description:
  I use qemu-i386-static on 64 bit ARM.But I don't know how to solve some 
problems.
  First I added some ioctl operations.
  Then I tried to do some DRM operations like test.c.
  This is successful when I use qemu-x86_64-static,but it failed when I use 
qemu-i386-static.
  I can get some strace info like this:

  403 openat(AT_FDCWD,"/dev/dri/card0",O_RDWR|O_LARGEFILE|O_CLOEXEC) = 4
  403 ioctl(4,DRM_IOCTL_GET_CAP,{1,0}) = 0 ({1,1})
  403 ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,0,0,0,0,0,0,0,0,0,0,0}) = 0 
({0,0,0,0,0,2,2,2,0,16384,0,16384})
  403 brk(NULL) = 0x40006000
  403 brk(0x40027000) = 0x40027000
  403 brk(0x40028000) = 0x40028000
  403 
ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,1073766816,1073766832,1073766848,0,2,2,2,0,16384,0,16384})
 = -1 errno=14 (Bad address)

  And there are similar errors in other self driven operations.
  I want to know if it is QEMU's problem, so I hope to get some help. 
  Thank you!

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



[Bug 1894071] Re: qemu-i386-static ioctl return -14 (Bad Address)

2020-09-03 Thread Tony.LI
** Attachment added: "ioctls.h"
   
https://bugs.launchpad.net/qemu/+bug/1894071/+attachment/5407368/+files/ioctls.h

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

Title:
  qemu-i386-static ioctl return -14 (Bad Address)

Status in QEMU:
  New

Bug description:
  I use qemu-i386-static on 64 bit ARM.But I don't know how to solve some 
problems.
  First I added some ioctl operations.
  Then I tried to do some DRM operations like test.c.
  This is successful when I use qemu-x86_64-static,but it failed when I use 
qemu-i386-static.
  I can get some strace info like this:

  403 openat(AT_FDCWD,"/dev/dri/card0",O_RDWR|O_LARGEFILE|O_CLOEXEC) = 4
  403 ioctl(4,DRM_IOCTL_GET_CAP,{1,0}) = 0 ({1,1})
  403 ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,0,0,0,0,0,0,0,0,0,0,0}) = 0 
({0,0,0,0,0,2,2,2,0,16384,0,16384})
  403 brk(NULL) = 0x40006000
  403 brk(0x40027000) = 0x40027000
  403 brk(0x40028000) = 0x40028000
  403 
ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,1073766816,1073766832,1073766848,0,2,2,2,0,16384,0,16384})
 = -1 errno=14 (Bad address)

  And there are similar errors in other self driven operations.
  I want to know if it is QEMU's problem, so I hope to get some help. 
  Thank you!

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



[Bug 1894071] Re: qemu-i386-static ioctl return -14 (Bad Address)

2020-09-03 Thread Tony.LI
** Attachment added: "modeset.c"
   
https://bugs.launchpad.net/qemu/+bug/1894071/+attachment/5407367/+files/modeset.c

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

Title:
  qemu-i386-static ioctl return -14 (Bad Address)

Status in QEMU:
  New

Bug description:
  I use qemu-i386-static on 64 bit ARM.But I don't know how to solve some 
problems.
  First I added some ioctl operations.
  Then I tried to do some DRM operations like test.c.
  This is successful when I use qemu-x86_64-static,but it failed when I use 
qemu-i386-static.
  I can get some strace info like this:

  403 openat(AT_FDCWD,"/dev/dri/card0",O_RDWR|O_LARGEFILE|O_CLOEXEC) = 4
  403 ioctl(4,DRM_IOCTL_GET_CAP,{1,0}) = 0 ({1,1})
  403 ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,0,0,0,0,0,0,0,0,0,0,0}) = 0 
({0,0,0,0,0,2,2,2,0,16384,0,16384})
  403 brk(NULL) = 0x40006000
  403 brk(0x40027000) = 0x40027000
  403 brk(0x40028000) = 0x40028000
  403 
ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,1073766816,1073766832,1073766848,0,2,2,2,0,16384,0,16384})
 = -1 errno=14 (Bad address)

  And there are similar errors in other self driven operations.
  I want to know if it is QEMU's problem, so I hope to get some help. 
  Thank you!

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



[Bug 1894071] Re: qemu-i386-static ioctl return -14 (Bad Address)

2020-09-03 Thread Tony.LI
My environment is that:
schroot + debian(bullseye-i386)
qemu: 5.1.0-rc3

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

Title:
  qemu-i386-static ioctl return -14 (Bad Address)

Status in QEMU:
  New

Bug description:
  I use qemu-i386-static on 64 bit ARM.But I don't know how to solve some 
problems.
  First I added some ioctl operations.
  Then I tried to do some DRM operations like test.c.
  This is successful when I use qemu-x86_64-static,but it failed when I use 
qemu-i386-static.
  I can get some strace info like this:

  403 openat(AT_FDCWD,"/dev/dri/card0",O_RDWR|O_LARGEFILE|O_CLOEXEC) = 4
  403 ioctl(4,DRM_IOCTL_GET_CAP,{1,0}) = 0 ({1,1})
  403 ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,0,0,0,0,0,0,0,0,0,0,0}) = 0 
({0,0,0,0,0,2,2,2,0,16384,0,16384})
  403 brk(NULL) = 0x40006000
  403 brk(0x40027000) = 0x40027000
  403 brk(0x40028000) = 0x40028000
  403 
ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,1073766816,1073766832,1073766848,0,2,2,2,0,16384,0,16384})
 = -1 errno=14 (Bad address)

  And there are similar errors in other self driven operations.
  I want to know if it is QEMU's problem, so I hope to get some help. 
  Thank you!

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



Re: [PATCH] Fix a gap where acpi_pcihp_find_hotplug_bus() returns a non-hotpluggable bus

2020-09-03 Thread Michael S. Tsirkin
On Sat, Aug 29, 2020 at 01:42:33PM +0530, Ani Sinha wrote:
> When ACPI hotplug for the root bus is disabled, the bsel property for that
> bus is not set. Please see the following commit:
> 
> 3d7e78aaf ("Introduce a new flag for i440fx to disable PCI hotplug on the 
> root bus").
> 
> As a result, when acpi_pcihp_find_hotplug_bus() is called
> with bsel set to 0, it may return the root bus. This would be wrong since the
> root bus is not hotpluggable. In general, this can potentially happen to other
> buses as well.
> In this patch, we fix the issue in this function by checking if the bus 
> returned
> by the function is actually hotpluggable. If not, we simply return NULL. This
> avoids the scenario where we are actually returning a non-hotpluggable bus.
> 
> Signed-off-by: Ani Sinha 

What exactly are the consequences though?


> ---
>  hw/acpi/pcihp.c | 15 +++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
> index 39b1f74442..f148e73c89 100644
> --- a/hw/acpi/pcihp.c
> +++ b/hw/acpi/pcihp.c
> @@ -147,6 +147,21 @@ static PCIBus 
> *acpi_pcihp_find_hotplug_bus(AcpiPciHpState *s, int bsel)
>  if (!bsel && !find.bus) {
>  find.bus = s->root;
>  }
> +
> +/*
> + * Check if find.bus is actually hotpluggable. If bsel is set to
> + * NULL for example on the root bus in order to make it
> + * non-hotpluggable, find.bus will match the root bus when bsel
> + * is 0. See acpi_pcihp_test_hotplug_bus() above. Since the
> + * bus is not hotpluggable however, we should not select the bus.
> + * Instead, we should set find.bus to NULL in that case. In the check
> + * below, we generalize this case for all buses, not just the root bus.
> + * The callers of this function check for a null return value and
> + * handle them appropriately.
> + */
> +if (!qbus_is_hotpluggable(BUS(find.bus))) {
> +find.bus = NULL;
> +}
>  return find.bus;
>  }
>  
> -- 
> 2.17.1




Re: [PATCH] Fix a gap where acpi_pcihp_find_hotplug_bus() returns a non-hotpluggable bus

2020-09-03 Thread Ani Sinha
 On Sep 3, 2020, 15:35 +0530, Michael S. Tsirkin , wrote:

On Sat, Aug 29, 2020 at 01:42:33PM +0530, Ani Sinha wrote:

When ACPI hotplug for the root bus is disabled, the bsel property for that

bus is not set. Please see the following commit:


3d7e78aaf ("Introduce a new flag for i440fx to disable PCI hotplug on
the root bus").


As a result, when acpi_pcihp_find_hotplug_bus() is called

with bsel set to 0, it may return the root bus. This would be wrong since
the

root bus is not hotpluggable. In general, this can potentially happen to
other

buses as well.

In this patch, we fix the issue in this function by checking if the bus
returned

by the function is actually hotpluggable. If not, we simply return NULL.
This

avoids the scenario where we are actually returning a non-hotpluggable bus.


Signed-off-by: Ani Sinha 


What exactly are the consequences though?


The root bus might get ejected by the user when it should not if the user
does the following:

outl 0xae10 0
outl 0xae08 your_slot

Please see Julia’s comment:
https://www.mail-archive.com/qemu-devel@nongnu.org/msg734548.html


[Bug 1894071] Re: qemu-i386-static ioctl return -14 (Bad Address)

2020-09-03 Thread Laurent Vivier
Please, send your patches to the QEMU devel mailing list, so we can
review them and comment.

https://wiki.qemu.org/Contribute/SubmitAPatch

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

Title:
  qemu-i386-static ioctl return -14 (Bad Address)

Status in QEMU:
  New

Bug description:
  I use qemu-i386-static on 64 bit ARM.But I don't know how to solve some 
problems.
  First I added some ioctl operations.
  Then I tried to do some DRM operations like test.c.
  This is successful when I use qemu-x86_64-static,but it failed when I use 
qemu-i386-static.
  I can get some strace info like this:

  403 openat(AT_FDCWD,"/dev/dri/card0",O_RDWR|O_LARGEFILE|O_CLOEXEC) = 4
  403 ioctl(4,DRM_IOCTL_GET_CAP,{1,0}) = 0 ({1,1})
  403 ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,0,0,0,0,0,0,0,0,0,0,0}) = 0 
({0,0,0,0,0,2,2,2,0,16384,0,16384})
  403 brk(NULL) = 0x40006000
  403 brk(0x40027000) = 0x40027000
  403 brk(0x40028000) = 0x40028000
  403 
ioctl(4,DRM_IOCTL_MODE_GETRESOURCES,{0,1073766816,1073766832,1073766848,0,2,2,2,0,16384,0,16384})
 = -1 errno=14 (Bad address)

  And there are similar errors in other self driven operations.
  I want to know if it is QEMU's problem, so I hope to get some help. 
  Thank you!

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



Re: [PATCH] Fix a gap where acpi_pcihp_find_hotplug_bus() returns a non-hotpluggable bus

2020-09-03 Thread Ani Sinha
On Thu, Sep 3, 2020 at 3:41 PM Ani Sinha  wrote:
>
> On Sep 3, 2020, 15:35 +0530, Michael S. Tsirkin , wrote:
>
> On Sat, Aug 29, 2020 at 01:42:33PM +0530, Ani Sinha wrote:
>
> When ACPI hotplug for the root bus is disabled, the bsel property for that
>
> bus is not set. Please see the following commit:
>
>
> 3d7e78aaf ("Introduce a new flag for i440fx to disable PCI hotplug on the 
> root bus").
>
>
> As a result, when acpi_pcihp_find_hotplug_bus() is called
>
> with bsel set to 0, it may return the root bus. This would be wrong since the
>
> root bus is not hotpluggable. In general, this can potentially happen to other
>
> buses as well.
>
> In this patch, we fix the issue in this function by checking if the bus 
> returned
>
> by the function is actually hotpluggable. If not, we simply return NULL. This
>
> avoids the scenario where we are actually returning a non-hotpluggable bus.
>
>
> Signed-off-by: Ani Sinha 
>
>
> What exactly are the consequences though?
>
>
> The root bus

s/root bus/any device on the root bus
sorry.

might get ejected by the user when it should not if the user does the following:
>
> outl 0xae10 0
> outl 0xae08 your_slot
>
> Please see Julia’s comment:
> https://www.mail-archive.com/qemu-devel@nongnu.org/msg734548.html
>



Re: [RFC v8 3/5] memory: Add IOMMU_DEVIOTLB_UNMAP IOMMUTLBNotificationType

2020-09-03 Thread Eugenio Perez Martin
Hi Eric,

On Wed, Sep 2, 2020 at 12:32 PM Auger Eric  wrote:
>
> Hi Eugenio,
>
> On 9/1/20 4:26 PM, Eugenio Pérez wrote:
> > Adapt intel and vhost to use this new notification type
> I think you should explain in the commit message what is the benefice to
> introduce this new event type.

Will do, thanks!

> >
> > Signed-off-by: Eugenio Pérez 
> > ---
> >  hw/i386/intel_iommu.c | 2 +-
> >  hw/virtio/vhost.c | 2 +-
> >  include/exec/memory.h | 2 ++
> >  3 files changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
> > index 0c4aef5cb5..cdddb089e7 100644
> > --- a/hw/i386/intel_iommu.c
> > +++ b/hw/i386/intel_iommu.c
> > @@ -2468,7 +2468,7 @@ static bool 
> > vtd_process_device_iotlb_desc(IntelIOMMUState *s,
> >  sz = VTD_PAGE_SIZE;
> >  }
> >
> > -event.type = IOMMU_NOTIFIER_UNMAP;
> > +event.type = IOMMU_NOTIFIER_DEVIOTLB;
> If this is used only for device IOTLB cache invalidation, shouldn't this
> be named IOMMU_NOTIFIER_DEVIOTLB_UNMAP to be consistent with the rest?
> >  event.entry.target_as = &vtd_dev_as->as;
> >  event.entry.addr_mask = sz - 1;
> >  event.entry.iova = addr;
> > diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> > index 1a1384e7a6..6ca168b47e 100644
> > --- a/hw/virtio/vhost.c
> > +++ b/hw/virtio/vhost.c
> > @@ -729,7 +729,7 @@ static void vhost_iommu_region_add(MemoryListener 
> > *listener,
> >  iommu_idx = memory_region_iommu_attrs_to_index(iommu_mr,
> > MEMTXATTRS_UNSPECIFIED);
> >  iommu_notifier_init(&iommu->n, vhost_iommu_unmap_notify,
> > -IOMMU_NOTIFIER_UNMAP,
> > +IOMMU_NOTIFIER_DEVIOTLB,
> >  section->offset_within_region,
> >  int128_get64(end),
> >  iommu_idx);
> > diff --git a/include/exec/memory.h b/include/exec/memory.h
> > index 8a56707169..215e23973d 100644
> > --- a/include/exec/memory.h
> > +++ b/include/exec/memory.h
> > @@ -87,6 +87,8 @@ typedef enum {
> >  IOMMU_NOTIFIER_UNMAP = 0x1,
> >  /* Notify entry changes (newly created entries) */
> >  IOMMU_NOTIFIER_MAP = 0x2,
> > +/* Notify changes on device IOTLB entries */
> > +IOMMU_NOTIFIER_DEVIOTLB = 0x04,
> >  } IOMMUNotifierFlag;
> >
> >  #define IOMMU_NOTIFIER_ALL (IOMMU_NOTIFIER_MAP | IOMMU_NOTIFIER_UNMAP)
> shouldn't we rename this one??
> >
>

Agree, but I'm not sure about the right name. IOMMU_NOTIFIER_ALL_ROOT?
IOMMU_NOTIFIER_ALL_REGULAR?

Thanks!

> Thanks
>
> Eric
>




Re: [PATCH] Fix a gap where acpi_pcihp_find_hotplug_bus() returns a non-hotpluggable bus

2020-09-03 Thread Michael S. Tsirkin
On Thu, Sep 03, 2020 at 03:41:13PM +0530, Ani Sinha wrote:
> On Sep 3, 2020, 15:35 +0530, Michael S. Tsirkin , wrote:
> 
> On Sat, Aug 29, 2020 at 01:42:33PM +0530, Ani Sinha wrote:
> 
> When ACPI hotplug for the root bus is disabled, the bsel property for
> that
> 
> bus is not set. Please see the following commit:
> 
> 
> 
> 3d7e78aaf ("Introduce a new flag for i440fx to disable PCI hotplug
> on the root bus").
> 
> 
> 
> As a result, when acpi_pcihp_find_hotplug_bus() is called
> 
> with bsel set to 0, it may return the root bus. This would be wrong
> since the
> 
> root bus is not hotpluggable. In general, this can potentially happen
> to other
> 
> buses as well.
> 
> In this patch, we fix the issue in this function by checking if the 
> bus
> returned
> 
> by the function is actually hotpluggable. If not, we simply return
> NULL. This
> 
> avoids the scenario where we are actually returning a non-hotpluggable
> bus.
> 
> 
> 
> Signed-off-by: Ani Sinha 
> 
> 
> 
> What exactly are the consequences though?
> 
> 
> The root bus might get ejected by the user when it should not if the user does
> the following:
> 
> outl 0xae10 0
> outl 0xae08 your_slot
> 
> Please see Julia’s comment:
> https://www.mail-archive.com/qemu-devel@nongnu.org/msg734548.html

OK so patch looks good, but please add all this in the commit log.

-- 
MST




Re: [PATCH v3 7/7] migration: introduce snapshot-{save, load, delete} QMP commands

2020-09-03 Thread Kevin Wolf
Am 03.09.2020 um 11:48 hat Markus Armbruster geschrieben:
> Daniel P. Berrangé  writes:
> 
> > On Wed, Sep 02, 2020 at 11:27:17AM +0200, Markus Armbruster wrote:
> >> Daniel P. Berrangé  writes:
> >> 
> >> > On Tue, Sep 01, 2020 at 04:20:47PM +0200, Markus Armbruster wrote:
> >> >> Daniel P. Berrangé  writes:
> >> >> 
> >> >> > savevm, loadvm and delvm are some of the few HMP commands that have 
> >> >> > never
> >> >> > been converted to use QMP. The primary reason for this lack of 
> >> >> > conversion
> >> >> > is that they block execution of the thread for as long as they run.
> >> >> 
> >> >> Nope.  The primary reason is that the HMP interface is bonkers.
> >> >
> >> > I don't think that's very helpful description. The HMP interface has
> >> > some limitations, but it isn't bonkers - it just doesn't cope with
> >> > all the use cases we want. Many people use it succesfully without
> >> > issue
> >> 
> >> It's non-bonkers for the case it was designed for: one disk backed by
> >> QCOW2, plus maybe a CD-ROM.  The user is responsible for ensuring the
> >> CD-ROM's media at loadvm time matches the one at savevm time.  The user
> >> is further responsible for ensuring the guest-visible configuration
> >> matches the one at savevm time.  No worse than migration.
> >
> > It is fine for multiple writable disks too, if they're all qcow2 backed.
> >
> >> It becomes useless as soon as you have writable non-QCOW2 block devices.
> >> "Stop machine, take external snapshots, savevm, restart machine" should
> >> work, but doesn't.

This is because savevm can't snapshot all writable disks and fails in
this case, right? So the proposed alternative with a list of nodes to
create disk snapshots for would solve this.

> > External snapshots can be made to work today if you're willing to pause
> > the VM CPUs while you take the external snapshots, and run the migration
> > to capture VM state.
> 
> Yes.
> 
> Pausing is necessary because we don't have a way to take snapshots when
> migration completes.
> 
> Even if we had it, live migration to file would be a problematic way to
> capture VM state, because it doesn't update changing state in place.

It's also not the semantics you usally want for snapshots. You want to
take a snapshot of the state _now_, not of the state at some arbitrary
time in the future.

That's why I mentioned the post-copy semantics for live snapshots.

> savevm is not live either, of course.
> 
> My point is that savevm is "QCOW2 or bust" unnecessarily.  Your
> proposed QMP interface isn't.

Strictly speaking, not qcow2, but "block driver that supports
snapshots". Not that it matters in practice, but this happens to include
sheepdog.

It also means that we could implement a filter driver that saves the VM
state to an external file, which would allow saving the VM state even if
you use only raw images (of course, only useful if you have means to
snapshot the disk state externally or in combination with external
snapshots).

> > If you want to see some examples, take a look at the very last patch
> > in the series which introduces I/O test 310. The test covers various
> > success and failure scenarios, so you can see the behaviour we are
> > currently generating with this series.
> >
> >
> >> >> > +#
> >> >> > +# If @vmstate is not specified, then the first valid block
> >> >> > +# device will be used for vmstate.
> >> >> 
> >> >> Why is this useful for QMP?
> >> >
> >> > Both of these makes QEMU just "do the right thing" with the majority
> >> > of QEMU guest configurations with no special knowledge needed by
> >> > the mgmt app.
> >> >
> >> > It makes it possible for all existing apps to immediately stop using
> >> > the loadvm/savevm commands via HMP passthrough, and convert to the
> >> > QMP commands.
> >> 
> >> I appreciate your concern for easy migration from HMP savevm/loadvm to
> >> QMP.  I'm unwilling to permanently screw up the QMP interface for it,
> >> though.
> >> 
> >> > Without this, applications will need to first convert to use -blockdev
> >> > before they can use the load-snapshot/save-snapshot commands, because
> >> > the devices are specified exclusively using blockdev node names, not
> >> > the legacy drive IDs.
> >> 
> >> Not true.  *Every* block node has a node name.  If the user doesn't
> >> specify one, the system makes one up.  query-named-block-nodes shows
> >> it.  So does query-block.
> >
> > query-named-block-nodes isn't friendly as a way to lookup node names,
> > as it doesn't include the "id" value for the original -drive, so
> > correlating block nodes to drives is not straightforward.  query-block
> > does seem a bit better in respect.
> >
> > So if an app is currently using loadvm/savevm with human_monitor_command,
> > and is using -drive, they have to go through a mapping process to figure
> > out node names. Not especially friendly if they were happy with the
> > current choice of disks QEMU makes by default. 
> 
> I take "not especially friendly to clients convert

Re: [PATCH v3 7/7] migration: introduce snapshot-{save, load, delete} QMP commands

2020-09-03 Thread Daniel P . Berrangé
On Thu, Sep 03, 2020 at 12:17:29PM +0200, Kevin Wolf wrote:
> Am 03.09.2020 um 11:48 hat Markus Armbruster geschrieben:
> > If having to map from drive ID to node-name really is too much of a
> > burden, we can look for ways to make it easier, or we can make savem
> > optionally accept drive IDs instead of node-names, like we do in several
> > other places for backward compatibility.
> 
> Yes, letting commands accept both node-names and drive IDs is trivial
> and we do it pretty much everywhere. Much better than randomly selecting
> an image to save the VM state to.

Is there anything which guarantees that node-names and drive IDs will
never clash ?  I didn't look for drive IDs as I was trying to ensure
a non-ambiguous lookup in case a string was both a valid node name
and a valid drive ID

Regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|




Re: [RFC qemu 0/6] mirror: implement incremental and bitmap modes

2020-09-03 Thread Fabian Grünbichler
On August 21, 2020 3:03 pm, Max Reitz wrote:
> On 18.02.20 11:07, Fabian Grünbichler wrote:
> 
> [Sorry :/]

same, I've been meaning to ping/pick this back up but other stuff got in 
the way. so thanks for the reminder to get this upstream ;)

> 
>> picking up on John's in-progress patch series from last summer, this is
>> a stab at rebasing and adding test cases for the low-hanging fruits:
>> 
>> - bitmap mirror mode with always/on-success/never bitmap sync mode
>> - incremental mirror mode as sugar for bitmap + on-success
>> 
>> Fabian Grünbichler (4):
>>   mirror: add check for bitmap-mode without bitmap
>>   mirror: switch to bdrv_dirty_bitmap_merge_internal
>>   iotests: add test for bitmap mirror
>>   mirror: move some checks to QMP
>> 
>> John Snow (2):
>>   drive-mirror: add support for sync=bitmap mode=never
>>   drive-mirror: add support for conditional and always bitmap sync modes
> 
> Looks reasonable to me.  I would indeed merge patches 2 through 4 into a
> single one, and perhaps switch patches 5 and 6.
> 
> Also, we still need an S-o-b from John on patch 2.
> 
> I have one question: When the mirror job completes successfully (or is
> cancelled “successfully”), the bitmap is always fully cleared when the
> job completes, right?  (Unless in “never” mode.)

I have to take a closer look as well, it's been a while ;) IIRC the idea 
was that failed mirrors would allow re-using the bitmap for a next 
attempt, unless the mode is always. we are not using that feature (yet) 
though (see below).

> Not that I think we should change the current implementation of “clear
> sync_bitmap; merge dirty_bitmap into sync_bitmap;”.  Just a question for
> understanding.
> 
> 
> Soo...  What’s the plan?

I'll rebase, squash as suggested and resend next week! I am not sure how 
the S-O-B by John is supposed to enter the mix - should I just include 
it in the squashed patch (which would be partly authored, but 
not-yet-signed-off by him otherwise?)? do you pick it up once he's 
replied with one?

FWIW, with been running with this for quite a while downstream with no 
issues, but we are only using the following part:

- create bitmap(s)
- (incrementally) replicate storage volume(s) out of band (using ZFS)
- incrementally drive mirror as part of a live migration of VM
- drop bitmap(s)

so no fancy semi-permanent bitmap that gets re-used here. I've been 
toying with implementing some sort of generic replication feature akin 
to zfs send/recv though, but given that we only have built-in persistent 
bitmaps with qcow2 and the chance of some other tool or the user messing 
up other image formats is high, the safe usage scenarios are a bit 
limited.

we do use such long-running bitmaps for our new backup driver though, 
and it works quite well there!




Re: [PATCH] stubs: Move qemu_fd_register stub to util/main-loop.c

2020-09-03 Thread Thomas Huth
On 03/09/2020 10.24, Daniel P. Berrangé wrote:
> On Thu, Sep 03, 2020 at 07:45:03AM +0200, Thomas Huth wrote:
>> The linker of MinGW sometimes runs into the following problem:
>>
>> libqemuutil.a(util_main-loop.c.obj): In function `qemu_fd_register':
>> /builds/huth/qemu/build/../util/main-loop.c:331: multiple definition of
>>  `qemu_fd_register'
>> libqemuutil.a(stubs_fd-register.c.obj):/builds/huth/qemu/stubs/fd-register.c:5:
>>  first defined here
>> collect2: error: ld returned 1 exit status
>> /builds/huth/qemu/rules.mak:88: recipe for target 
>> 'tests/test-timed-average.exe'
>>  failed
>>
>> qemu_fd_register() is defined in util/main-loop.c for WIN32, so let's simply
>> move the stub also there in the #else part of the corresponding #ifndef
>> to fix this problem.
>>
>> Signed-off-by: Thomas Huth 
>> ---
>>  stubs/fd-register.c | 6 --
>>  stubs/meson.build   | 1 -
>>  util/main-loop.c| 4 
> 
>>  3 files changed, 4 insertions(+), 7 deletions(-)
>>  delete mode 100644 stubs/fd-register.c
> 
> The util/meson.build only adds main-loop.c under 'if have_block'.
> 
> Since you didn't remove that conditional, I assume that nothing
> built in a "if not have_block" scenario was relying on the existing
> stub ?

Right, as far as I can see, this is not used by the linux-user or
bsd-user builds, and since

 have_block = have_system or have_tools

we should be fine without the separate stub.

> Assuming the answer is yes and/or CI passes 

CI compilation succeeded here:

 https://gitlab.com/huth/qemu/-/pipelines/185094808
 (the failed acceptance test is something different)

and:

 https://cirrus-ci.com/build/4756242964938752

> Reviewed-by: Daniel P. Berrangé 

Thanks!

 Thomas




[PATCH v2] Fix a gap where acpi_pcihp_find_hotplug_bus() returns a non-hotpluggable bus

2020-09-03 Thread Ani Sinha
When ACPI hotplug for the root bus is disabled, the bsel property for that
bus is not set. Please see the following commit:

3d7e78aaf ("Introduce a new flag for i440fx to disable PCI hotplug on the 
root bus").

As a result, when acpi_pcihp_find_hotplug_bus() is called
with bsel set to 0, it may return the root bus. This can cause devices attached 
to
the root bus to get hot-unplugged if the user issues the following set of 
commmands:

outl 0xae10 0
outl 0xae08 your_slot

Thanks to Julia for pointing this out here:
https://www.mail-archive.com/qemu-devel@nongnu.org/msg734548.html

In this patch, we fix the issue in this function by checking if the bus which is
returned by the function is actually hotpluggable. If not, we simply return 
NULL.
This avoids the scenario where we were returning a non-hotpluggable bus.

Signed-off-by: Ani Sinha 
---
 hw/acpi/pcihp.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 39b1f74442..f148e73c89 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -147,6 +147,21 @@ static PCIBus *acpi_pcihp_find_hotplug_bus(AcpiPciHpState 
*s, int bsel)
 if (!bsel && !find.bus) {
 find.bus = s->root;
 }
+
+/*
+ * Check if find.bus is actually hotpluggable. If bsel is set to
+ * NULL for example on the root bus in order to make it
+ * non-hotpluggable, find.bus will match the root bus when bsel
+ * is 0. See acpi_pcihp_test_hotplug_bus() above. Since the
+ * bus is not hotpluggable however, we should not select the bus.
+ * Instead, we should set find.bus to NULL in that case. In the check
+ * below, we generalize this case for all buses, not just the root bus.
+ * The callers of this function check for a null return value and
+ * handle them appropriately.
+ */
+if (!qbus_is_hotpluggable(BUS(find.bus))) {
+find.bus = NULL;
+}
 return find.bus;
 }
 
-- 
2.17.1




Re: [PATCH] Fix a gap where acpi_pcihp_find_hotplug_bus() returns a non-hotpluggable bus

2020-09-03 Thread Ani Sinha
On Thu, Sep 3, 2020 at 3:46 PM Michael S. Tsirkin  wrote:
>
> On Thu, Sep 03, 2020 at 03:41:13PM +0530, Ani Sinha wrote:
> > On Sep 3, 2020, 15:35 +0530, Michael S. Tsirkin , wrote:
> >
> > On Sat, Aug 29, 2020 at 01:42:33PM +0530, Ani Sinha wrote:
> >
> > When ACPI hotplug for the root bus is disabled, the bsel property 
> > for
> > that
> >
> > bus is not set. Please see the following commit:
> >
> >
> >
> > 3d7e78aaf ("Introduce a new flag for i440fx to disable PCI 
> > hotplug
> > on the root bus").
> >
> >
> >
> > As a result, when acpi_pcihp_find_hotplug_bus() is called
> >
> > with bsel set to 0, it may return the root bus. This would be wrong
> > since the
> >
> > root bus is not hotpluggable. In general, this can potentially 
> > happen
> > to other
> >
> > buses as well.
> >
> > In this patch, we fix the issue in this function by checking if the 
> > bus
> > returned
> >
> > by the function is actually hotpluggable. If not, we simply return
> > NULL. This
> >
> > avoids the scenario where we are actually returning a 
> > non-hotpluggable
> > bus.
> >
> >
> >
> > Signed-off-by: Ani Sinha 
> >
> >
> >
> > What exactly are the consequences though?
> >
> >
> > The root bus might get ejected by the user when it should not if the user 
> > does
> > the following:
> >
> > outl 0xae10 0
> > outl 0xae08 your_slot
> >
> > Please see Julia’s comment:
> > https://www.mail-archive.com/qemu-devel@nongnu.org/msg734548.html
>
> OK so patch looks good, but please add all this in the commit log.

Done. V2 sent.



  1   2   3   4   5   6   7   >