Re: [PATCH] hw/i386/kvm/ioapic.c: fix typo in error message

2020-09-01 Thread Laurent Vivier
Le 17/07/2020 à 14:35, Kenta Ishiguro a écrit :
> Fix a typo in an error message for KVM_SET_IRQCHIP ioctl:
> "KVM_GET_IRQCHIP" should be "KVM_SET_IRQCHIP".
> 
> Signed-off-by: Kenta Ishiguro 
> ---
>  hw/i386/kvm/ioapic.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/i386/kvm/ioapic.c b/hw/i386/kvm/ioapic.c
> index 4ba8e47251..c5528df942 100644
> --- a/hw/i386/kvm/ioapic.c
> +++ b/hw/i386/kvm/ioapic.c
> @@ -97,7 +97,7 @@ static void kvm_ioapic_put(IOAPICCommonState *s)
>  
>  ret = kvm_vm_ioctl(kvm_state, KVM_SET_IRQCHIP, &chip);
>  if (ret < 0) {
> -fprintf(stderr, "KVM_GET_IRQCHIP failed: %s\n", strerror(ret));
> +fprintf(stderr, "KVM_SET_IRQCHIP failed: %s\n", strerror(ret));
>  abort();
>  }
>  }
> 

Applied to my trivial-patches branch.

Thanks,
Laurent




Re: [PATCH 4/6] target/microblaze: Handle DISAS_EXIT_NEXT in delay slot

2020-09-01 Thread Edgar E. Iglesias
On Mon, Aug 31, 2020 at 11:40:16AM -0700, Richard Henderson wrote:
> 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.
> 
> 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 9c52448c06..b116a0ce4f 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 finish any return-from branch.

Typo, 2x finish.

With that fixed:
Reviewed-by: Edgar E. Iglesias 




Re: [PATCH-for-5.1 v2] hw/isa/isa-superio: Fix IDE controller realization

2020-09-01 Thread Laurent Vivier
Le 21/07/2020 à 14:45, Philippe Mathieu-Daudé a écrit :
> When realizing a Super I/O with IDE controller [*], we get:
> 
>   qom/object.c:1684: object_property_try_add_child: Assertion 
> `!child->parent' failed.
>   Aborted (core dumped)
> 
> This is because the device is already realized when we try to
> add the QOM property to the parent. Fix by realizing *after*
> adding the QOM relationship.
> 
> [*] Set ISASuperIOClass::ide.count = N with N not zero
> (no such thing currently exists; the bug is latent)
> 
> Fixes: e508430619 ("hw/isa/superio: Make the components QOM children")
> Reviewed-by: Markus Armbruster 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
> v2: Reword bug is latent (Markus)
> ---
>  hw/isa/isa-superio.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/isa/isa-superio.c b/hw/isa/isa-superio.c
> index e2e47d8fd9..179c185695 100644
> --- a/hw/isa/isa-superio.c
> +++ b/hw/isa/isa-superio.c
> @@ -158,8 +158,8 @@ static void isa_superio_realize(DeviceState *dev, Error 
> **errp)
>  if (k->ide.get_irq) {
>  qdev_prop_set_uint32(d, "irq", k->ide.get_irq(sio, 0));
>  }
> -isa_realize_and_unref(isa, bus, &error_fatal);
>  object_property_add_child(OBJECT(sio), "isa-ide", OBJECT(isa));
> +isa_realize_and_unref(isa, bus, &error_fatal);
>  sio->ide = isa;
>  trace_superio_create_ide(0,
>   k->ide.get_iobase ?
> 

Applied to my trivial-patches branch.

Thanks,
Laurent




[PATCH v2] meson: use pkg-config method to find dependencies

2020-09-01 Thread Paolo Bonzini
We do not need to ask cmake for the dependencies, so just use the
pkg-config mechanism.  Keep "auto" for SDL so that it tries using
sdl-config too.

The documentation is adjusted to use SDL2_image as the example,
rather than SDL which does not use the "pkg-config" method.

Signed-off-by: Paolo Bonzini 
---
 docs/devel/build-system.rst | 27 ++-
 meson.build |  8 
 2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/docs/devel/build-system.rst b/docs/devel/build-system.rst
index 58bf392430..0c09fb9a54 100644
--- a/docs/devel/build-system.rst
+++ b/docs/devel/build-system.rst
@@ -66,46 +66,47 @@ following tasks:
upon completion.
 
 
-Taking the probe for SDL as an example, we have the following pieces
+Taking the probe for SDL2_Image as an example, we have the following pieces
 in configure::
 
   # Initial variable state
-  sdl=auto
+  sdl_image=auto
 
   ..snip..
 
   # Configure flag processing
-  --disable-gnutls) sdl=disabled
+  --disable-sdl-image) sdl_image=disabled
   ;;
-  --enable-gnutls) sdl=enabled
+  --enable-sdl-image) sdl_image=enabled
   ;;
 
   ..snip..
 
   # Help output feature message
-  sdl SDL UI
+  sdl-image SDL Image support for icons
 
   ..snip..
 
   # Meson invocation
-  -Dsdl=$sdl
+  -Dsdl_image=$sdl_image
 
 In meson_options.txt::
 
-  option('sdl', type : 'feature', value : 'auto')
+  option('sdl', type : 'feature', value : 'auto',
+ description: 'SDL Image support for icons')
 
 In meson.build::
 
   # Detect dependency
-  sdl = dependency('sdl2',
-   required: get_option('sdl'),
-   static: enable_static)
+  sdl_image = dependency('SDL2_image', required: get_option('sdl_image'),
+ method: 'pkg-config',
+ static: enable_static)
 
-  # Create config-host.h
-  config_host_data.set('CONFIG_SDL', sdl.found())
+  # Create config-host.h (if applicable)
+  config_host_data.set('CONFIG_SDL_IMAGE', sdl_image.found())
 
   # Summary
-  summary_info += {'SDL support':   sdl.found()}
+  summary_info += {'SDL image support': sdl_image.found()}
 
 
 
diff --git a/meson.build b/meson.build
index 78ac86f3a1..0e2d884f5c 100644
--- a/meson.build
+++ b/meson.build
@@ -129,7 +129,7 @@ endif
 pixman = not_found
 if have_system or have_tools
   pixman = dependency('pixman-1', required: have_system, version:'>=0.21.8',
-  static: enable_static)
+  method: 'pkg-config', static: enable_static)
 endif
 pam = not_found
 if 'CONFIG_AUTH_PAM' in config_host
@@ -168,7 +168,7 @@ if get_option('xkbcommon').auto() and not have_system and 
not have_tools
   xkbcommon = not_found
 else
   xkbcommon = dependency('xkbcommon', required: get_option('xkbcommon'),
- static: enable_static)
+ method: 'pkg-config', static: enable_static)
 endif
 slirp = not_found
 if config_host.has_key('CONFIG_SLIRP')
@@ -247,7 +247,7 @@ if sdl.found()
   sdl = declare_dependency(compile_args: '-Wno-undef',
dependencies: sdl)
   sdl_image = dependency('SDL2_image', required: get_option('sdl_image'),
- static: enable_static)
+ method: 'pkg-config', static: enable_static)
 else
   if get_option('sdl_image').enabled()
 error('sdl-image required, but SDL was @0@',
@@ -332,7 +332,7 @@ sasl = not_found
 if get_option('vnc').enabled()
   vnc = declare_dependency() # dummy dependency
   png = dependency('libpng', required: get_option('vnc_png'),
-   static: enable_static)
+   method: 'pkg-config', static: enable_static)
   jpeg = cc.find_library('jpeg', has_headers: ['jpeglib.h'],
  required: get_option('vnc_jpeg'),
  static: enable_static)
-- 
2.26.2




Re: [PATCH 0/6] target/microblaze: Use tcg_gen_lookup_and_goto_ptr

2020-09-01 Thread Edgar E. Iglesias
On Mon, Aug 31, 2020 at 11:40:12AM -0700, Richard Henderson wrote:
> Based-on: <20200831160601.833692-1-richard.hender...@linaro.org>
> ("[PULL 00/76] target/microblaze improvements")
> 
> Hello again, Edgar.
> 
> I had dropped the tcg_gen_lookup_and_goto_ptr patch from the
> previous omnibus patch set, as you had reported lockups.
> 
> I have identified, by inspection, two cases in which we failed
> to return to the main loop even though we should have:
> 
> (1) Return-from-exception type instructions.
> 
> I had missed these before because they hadn't set cpustate_changed.
> This still worked fine because they are all indirect branches, and
> had exited immediately.
> 
> Fixed by distinguishing these cases from normal indirect branches
> before we start using lookup_and_goto_ptr.
> 
> (2) MTS in a branch delay slot.
> 
> We did not check dc->cpustate_changed before setting
> dc->base.is_jmp to DISAS_JUMP, which lost the fact that we
> need to return to the main loop.
> 
> This mostly works fine without lookup_and_goto_ptr, because
> we either (a) finished an indirect branch and returned to the
> main loop anyway or (b) we'd return to the main loop via some
> subsequent indirect branch, which would happen "soon enough".
> 
> We should have been able to see soft-lockup with the existing
> code in the case of a cpustate_changed in the delay slot of
> a loop of direct branches that all use goto_tb.  E.g.
> 
>   brid0
>msrset MSR_IE
> 
> I.e. an immediate branch back to the same branch insn,
> re-enabling interrupts in the delay slot.  Probably not
> something that shows up in the wild.


Nice! Yes, this seems to fix the problem we ran into before.
Series looks good both in review and testing except for minor typo in a comment.

With the typo in patch #4 fixed:
Reviewed-by: Edgar E. Iglesias 
Tested-by: Edgar E. Iglesias 



> 
> 
> 
> Follow-up question: The manual says that several classes of
> instructions are invalid in a branch delay slot, but does
> not say what action is taken, if any.
> 
> Some of these invalid cases could leave qemu in an inconsistent
> state.  Would it be legal for us to diagnose these cases with
> trap_illegal?  If not, what *should* we be doing?  We could also
> LOG_GUEST_ERROR for these either way.
> 
> I've added some TODO comments in these patches that are relevant.

Thanks, I'll try to dig out some details. A guest-error will likely
be needed anyway since some cores don't have exceptions enabled.
But we may want both.

Cheers,
Edgar



Re: [PATCH-for-5.2] stubs/cmos: Use correct include

2020-09-01 Thread Laurent Vivier
Le 24/07/2020 à 10:43, Philippe Mathieu-Daudé a écrit :
> cmos_get_fd_drive_type() is declared in "hw/block/fdc.h".
> This currently works because "hw/i386/pc.h" happens to
> include it. Simplify including the correct header.
> 
> Fixes: 2055dbc1c9 ("acpi: move aml builder code for floppy device")
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  stubs/cmos.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/stubs/cmos.c b/stubs/cmos.c
> index 416cbe4055..3fdbae2c69 100644
> --- a/stubs/cmos.c
> +++ b/stubs/cmos.c
> @@ -1,5 +1,5 @@
>  #include "qemu/osdep.h"
> -#include "hw/i386/pc.h"
> +#include "hw/block/fdc.h"
>  
>  int cmos_get_fd_drive_type(FloppyDriveType fd0)
>  {
> 

Applied to my trivial-patches branch.

Thanks,
Laurent




Re: [PATCH] cirrus: handle wraparound in cirrus_invalidate_region

2020-09-01 Thread Gerd Hoffmann
  Hi,

> +/* wraparound */
> +memory_region_set_dirty(&s->vga.vram, off_cur,
> s->cirrus_addr_mask - off_cur);

> So the len is 's->cirrus_addr_mask->off_cur+1'.

Correct.

> +memory_region_set_dirty(&s->vga.vram, 0, off_cur_end);
> 
> For the 'off_cur_end' here, why we add 1 at the first?:
> 
> "off_cur_end = ((off_cur + bytesperline - 1) & s->cirrus_addr_mask) + 1;"
 
> This addition '1' is what I think should be substracted in wrapped cases.

The +1 balances the -1 done before ...

take care,
  Gerd




Re: [PATCH] qemu-options.hx: Fix typo for netdev documentation

2020-09-01 Thread Laurent Vivier
Le 27/08/2020 à 15:03, Peter Maydell a écrit :
> On Thu, 27 Aug 2020 at 14:00, Tianjia Zhang
>  wrote:
>> Other opinions needed?
> 
> No, the patch just got lost by accident; sorry.
> 
> Jason, could you take this via your net tree, please?
> 
> thanks
> -- PMM
> 
>>
>> On 7/27/20 5:44 PM, Michael S. Tsirkin wrote:
>>> On Mon, Jul 27, 2020 at 12:59:25PM +0800, Tianjia Zhang wrote:
 This patch fixes the netdev document description typo in qemu-option.hx.

 Signed-off-by: Tianjia Zhang 
>>> Reviewed-by: Michael S. Tsirkin 
>>>
>>> Trivial tree? Jason's ?

I'm taking it via the trivial tree.

Thanks,
Laurent



Re: [RFC PATCH v4 1/2] hw/riscv: sifive_u: Add backend drive support

2020-09-01 Thread Green Wan
Hi Bin,

Thanks for the remindings. I didn't notice the write operation and
will add the write functionality based on bit by bit mechanism.

Regards,
Green


On Fri, Aug 28, 2020 at 8:54 PM Bin Meng  wrote:
>
> Hi Green,
>
> On Thu, Aug 27, 2020 at 3:47 PM Green Wan  wrote:
> >
> > Add '-drive' support to OTP device. Allow users to assign a raw file
> > as OTP image.
> >
> > Signed-off-by: Green Wan 
> > ---
> >  hw/riscv/sifive_u_otp.c | 50 +
> >  include/hw/riscv/sifive_u_otp.h |  2 ++
> >  2 files changed, 52 insertions(+)
> >
> > diff --git a/hw/riscv/sifive_u_otp.c b/hw/riscv/sifive_u_otp.c
> > index f6ecbaa2ca..aab2220494 100644
> > --- a/hw/riscv/sifive_u_otp.c
> > +++ b/hw/riscv/sifive_u_otp.c
> > @@ -24,6 +24,8 @@
> >  #include "qemu/log.h"
> >  #include "qemu/module.h"
> >  #include "hw/riscv/sifive_u_otp.h"
> > +#include "sysemu/blockdev.h"
> > +#include "sysemu/block-backend.h"
> >
> >  static uint64_t sifive_u_otp_read(void *opaque, hwaddr addr, unsigned int 
> > size)
> >  {
> > @@ -46,6 +48,16 @@ static uint64_t sifive_u_otp_read(void *opaque, hwaddr 
> > addr, unsigned int size)
> >  if ((s->pce & SIFIVE_U_OTP_PCE_EN) &&
> >  (s->pdstb & SIFIVE_U_OTP_PDSTB_EN) &&
> >  (s->ptrim & SIFIVE_U_OTP_PTRIM_EN)) {
> > +
> > +/* read from backend */
> > +if (s->blk) {
> > +int32_t buf;
> > +
> > +blk_pread(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD, &buf,
> > +  SIFIVE_U_OTP_FUSE_WORD);
> > +return buf;
> > +}
> > +
> >  return s->fuse[s->pa & SIFIVE_U_OTP_PA_MASK];
> >  } else {
> >  return 0xff;
> > @@ -123,6 +135,12 @@ static void sifive_u_otp_write(void *opaque, hwaddr 
> > addr,
> >  s->ptrim = val32;
> >  break;
> >  case SIFIVE_U_OTP_PWE:
> > +/* write to backend */
> > +if (s->blk) {
> > +blk_pwrite(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD, &val32,
>
> The logic looks wrong to me. According to the U-Boot driver
> (sifive-otp.c) the content to be written to the OTP memory comes from
> s->pdin bit by bit. Here val32 represents whether to disable write or
> enable write.
>
> I think we should arrange patches like this:
>
> patch 1 to add OTP write functionality, to the existing s->fuse[] mechanism
> patch 2 to add file based backend write support
>
> > +   SIFIVE_U_OTP_FUSE_WORD, 0);
> > +}
> > +
> >  s->pwe = val32;
> >  break;
> >  default:
> > @@ -143,16 +161,48 @@ static const MemoryRegionOps sifive_u_otp_ops = {
> >
> >  static Property sifive_u_otp_properties[] = {
> >  DEFINE_PROP_UINT32("serial", SiFiveUOTPState, serial, 0),
> > +DEFINE_PROP_DRIVE("drive", SiFiveUOTPState, blk),
> >  DEFINE_PROP_END_OF_LIST(),
> >  };
> >
> >  static void sifive_u_otp_realize(DeviceState *dev, Error **errp)
> >  {
> >  SiFiveUOTPState *s = SIFIVE_U_OTP(dev);
> > +DriveInfo *dinfo;
> >
> >  memory_region_init_io(&s->mmio, OBJECT(dev), &sifive_u_otp_ops, s,
> >TYPE_SIFIVE_U_OTP, SIFIVE_U_OTP_REG_SIZE);
> >  sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio);
> > +
> > +dinfo = drive_get_next(IF_NONE);
> > +if (dinfo) {
> > +int ret;
> > +uint64_t perm;
> > +int filesize;
> > +BlockBackend *blk;
> > +
> > +blk = blk_by_legacy_dinfo(dinfo);
> > +filesize = SIFIVE_U_OTP_NUM_FUSES * SIFIVE_U_OTP_FUSE_WORD;
> > +if (blk_getlength(blk) < filesize) {
> > +qemu_log_mask(LOG_GUEST_ERROR, "OTP drive size < 16K\n");
> > +return;
> > +}
> > +
> > +qdev_prop_set_drive(dev, "drive", blk);
> > +
> > +perm = BLK_PERM_CONSISTENT_READ |
> > +(blk_is_read_only(s->blk) ? 0 : BLK_PERM_WRITE);
> > +ret = blk_set_perm(s->blk, perm, BLK_PERM_ALL, errp);
> > +if (ret < 0) {
> > +qemu_log_mask(LOG_GUEST_ERROR, "set perm error.");
> > +}
> > +
> > +if (blk_pread(s->blk, 0, s->fuse, filesize) != filesize) {
> > +qemu_log_mask(LOG_GUEST_ERROR,
> > +  "failed to read the initial flash content");
> > +return;
> > +}
> > +}
> >  }
> >
> >  static void sifive_u_otp_reset(DeviceState *dev)
> > diff --git a/include/hw/riscv/sifive_u_otp.h 
> > b/include/hw/riscv/sifive_u_otp.h
> > index 639297564a..13d2552e43 100644
> > --- a/include/hw/riscv/sifive_u_otp.h
> > +++ b/include/hw/riscv/sifive_u_otp.h
> > @@ -43,6 +43,7 @@
> >
> >  #define SIFIVE_U_OTP_PA_MASK0xfff
> >  #define SIFIVE_U_OTP_NUM_FUSES  0x1000
> > +#define SIFIVE_U_OTP_FUSE_WORD  4
> >  #define SIFIVE_U_OTP_SERIAL_ADDR0xfc
> >
> >  #define SIFIVE_U_OTP_REG_SIZE   0x1000
> > @@ -75,6 +76,7 @@ typedef struct SiFiveUOTPState {
> >  uint32_t fuse[SIFIVE_U_OTP_NUM_FUSES];

[PATCH v6 02/16] icount: rename functions to be consistent with the module name

2020-09-01 Thread Claudio Fontana
Signed-off-by: Claudio Fontana 
---
 accel/tcg/cpu-exec.c|  4 ++--
 docs/replay.txt |  6 +++---
 include/sysemu/cpu-timers.h | 16 +++---
 include/sysemu/replay.h |  4 ++--
 replay/replay.c |  2 +-
 softmmu/cpu-timers.c|  4 ++--
 softmmu/cpus.c  |  6 +++---
 softmmu/icount.c| 42 ++---
 softmmu/vl.c|  2 +-
 stubs/icount.c  | 16 +++---
 target/arm/helper.c |  4 ++--
 target/riscv/csr.c  |  4 ++--
 util/main-loop.c|  2 +-
 util/qemu-timer.c   |  4 ++--
 14 files changed, 58 insertions(+), 58 deletions(-)

diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 279169d47d..b44e92b753 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -71,7 +71,7 @@ static void align_clocks(SyncClocks *sc, CPUState *cpu)
 }
 
 cpu_icount = cpu->icount_extra + cpu_neg(cpu)->icount_decr.u16.low;
-sc->diff_clk += cpu_icount_to_ns(sc->last_cpu_icount - cpu_icount);
+sc->diff_clk += icount_to_ns(sc->last_cpu_icount - cpu_icount);
 sc->last_cpu_icount = cpu_icount;
 
 if (sc->diff_clk > VM_CLOCK_ADVANCE) {
@@ -664,7 +664,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, 
TranslationBlock *tb,
 assert(icount_enabled());
 #ifndef CONFIG_USER_ONLY
 /* Ensure global icount has gone forward */
-cpu_update_icount(cpu);
+icount_update(cpu);
 /* Refill decrementer and continue execution.  */
 insns_left = MIN(0x, cpu->icount_budget);
 cpu_neg(cpu)->icount_decr.u16.low = insns_left;
diff --git a/docs/replay.txt b/docs/replay.txt
index 70c27edb36..8952e6d852 100644
--- a/docs/replay.txt
+++ b/docs/replay.txt
@@ -184,11 +184,11 @@ is then incremented (which is called "warping" the 
virtual clock) as
 soon as the timer fires or the CPUs need to go out of the idle state.
 Two functions are used for this purpose; because these actions change
 virtual machine state and must be deterministic, each of them creates a
-checkpoint.  qemu_start_warp_timer checks if the CPUs are idle and if so
-starts accounting real time to virtual clock.  qemu_account_warp_timer
+checkpoint.  icount_start_warp_timer checks if the CPUs are idle and if so
+starts accounting real time to virtual clock.  icount_account_warp_timer
 is called when the CPUs get an interrupt or when the warp timer fires,
 and it warps the virtual clock by the amount of real time that has passed
-since qemu_start_warp_timer.
+since icount_start_warp_timer.
 
 Bottom halves
 -
diff --git a/include/sysemu/cpu-timers.h b/include/sysemu/cpu-timers.h
index 4b621fea51..7726e005cd 100644
--- a/include/sysemu/cpu-timers.h
+++ b/include/sysemu/cpu-timers.h
@@ -35,30 +35,30 @@ extern int use_icount;
  * Update the icount with the executed instructions. Called by
  * cpus-tcg vCPU thread so the main-loop can see time has moved forward.
  */
-void cpu_update_icount(CPUState *cpu);
+void icount_update(CPUState *cpu);
 
 /* get raw icount value */
-int64_t cpu_get_icount_raw(void);
+int64_t icount_get_raw(void);
 
 /* return the virtual CPU time in ns, based on the instruction counter. */
-int64_t cpu_get_icount(void);
+int64_t icount_get(void);
 /*
  * convert an instruction counter value to ns, based on the icount shift.
  * This shift is set as a fixed value with the icount "shift" option
  * (precise mode), or it is constantly approximated and corrected at
  * runtime in adaptive mode.
  */
-int64_t cpu_icount_to_ns(int64_t icount);
+int64_t icount_to_ns(int64_t icount);
 
 /* configure the icount options, including "shift" */
-void configure_icount(QemuOpts *opts, Error **errp);
+void icount_configure(QemuOpts *opts, Error **errp);
 
 /* used by tcg vcpu thread to calc icount budget */
-int64_t qemu_icount_round(int64_t count);
+int64_t icount_round(int64_t count);
 
 /* if the CPUs are idle, start accounting real time to virtual clock. */
-void qemu_start_warp_timer(void);
-void qemu_account_warp_timer(void);
+void icount_start_warp_timer(void);
+void icount_account_warp_timer(void);
 
 /*
  * CPU Ticks and Clock
diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h
index 5471bb514d..a140d69a73 100644
--- a/include/sysemu/replay.h
+++ b/include/sysemu/replay.h
@@ -109,12 +109,12 @@ int64_t replay_read_clock(ReplayClockKind kind);
 #define REPLAY_CLOCK(clock, value)  \
 (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock))   \
 : replay_mode == REPLAY_MODE_RECORD \
-? replay_save_clock((clock), (value), cpu_get_icount_raw()) \
+? replay_save_clock((clock), (value), icount_get_raw()) \
 : (value))
 #define REPLAY_CLOCK_LOCKED(clock, value)   \
 (replay_mode == REPLAY_MODE_PLAY ? replay_read_clock((clock))   \
 : replay_mode == REPLAY_MODE_RECORD   

[PATCH v6 04/16] cpus: extract out TCG-specific code to accel/tcg

2020-09-01 Thread Claudio Fontana
TCG is the first accelerator to register a "CpusAccel" interface
on initialization, providing functions for starting a vcpu,
kicking a vcpu, sychronizing state and getting virtual clock
and ticks.

Signed-off-by: Claudio Fontana 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
[added const]
Signed-off-by: Claudio Fontana 
---
 accel/tcg/meson.build |   2 +-
 accel/tcg/tcg-all.c   |  12 +-
 accel/tcg/tcg-cpus.c  | 541 ++
 accel/tcg/tcg-cpus.h  |  17 ++
 softmmu/cpus.c| 496 +-
 5 files changed, 567 insertions(+), 501 deletions(-)
 create mode 100644 accel/tcg/tcg-cpus.c
 create mode 100644 accel/tcg/tcg-cpus.h

diff --git a/accel/tcg/meson.build b/accel/tcg/meson.build
index 2a335b50f2..3207ba07f3 100644
--- a/accel/tcg/meson.build
+++ b/accel/tcg/meson.build
@@ -12,4 +12,4 @@ tcg_ss.add(when: 'CONFIG_SOFTMMU', if_false: 
files('user-exec-stub.c'))
 tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: files('plugin-gen.c'))
 specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss)
 
-specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: 
files('tcg-all.c', 'cputlb.c'))
+specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: 
files('tcg-all.c', 'cputlb.c', 'tcg-cpus.c'))
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index f1feea20c8..01957b130d 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -24,19 +24,17 @@
  */
 
 #include "qemu/osdep.h"
-#include "sysemu/accel.h"
+#include "qemu-common.h"
 #include "sysemu/tcg.h"
-#include "qom/object.h"
-#include "cpu.h"
-#include "sysemu/cpus.h"
 #include "sysemu/cpu-timers.h"
-#include "qemu/main-loop.h"
 #include "tcg/tcg.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "hw/boards.h"
 #include "qapi/qapi-builtin-visit.h"
 
+#include "tcg-cpus.h"
+
 typedef struct TCGState {
 AccelState parent_obj;
 
@@ -123,6 +121,8 @@ static void tcg_accel_instance_init(Object *obj)
 s->mttcg_enabled = default_mttcg_enabled();
 }
 
+bool mttcg_enabled;
+
 static int tcg_init(MachineState *ms)
 {
 TCGState *s = TCG_STATE(current_accel());
@@ -130,6 +130,8 @@ static int tcg_init(MachineState *ms)
 tcg_exec_init(s->tb_size * 1024 * 1024);
 cpu_interrupt_handler = tcg_handle_interrupt;
 mttcg_enabled = s->mttcg_enabled;
+cpus_register_accel(&tcg_cpus);
+
 return 0;
 }
 
diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
new file mode 100644
index 00..72696f6d86
--- /dev/null
+++ b/accel/tcg/tcg-cpus.c
@@ -0,0 +1,541 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2014 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "sysemu/tcg.h"
+#include "sysemu/replay.h"
+#include "qemu/main-loop.h"
+#include "qemu/guest-random.h"
+#include "exec/exec-all.h"
+
+#include "tcg-cpus.h"
+
+/* Kick all RR vCPUs */
+static void qemu_cpu_kick_rr_cpus(void)
+{
+CPUState *cpu;
+
+CPU_FOREACH(cpu) {
+cpu_exit(cpu);
+};
+}
+
+static void tcg_kick_vcpu_thread(CPUState *cpu)
+{
+if (qemu_tcg_mttcg_enabled()) {
+cpu_exit(cpu);
+} else {
+qemu_cpu_kick_rr_cpus();
+}
+}
+
+/*
+ * TCG vCPU kick timer
+ *
+ * The kick timer is responsible for moving single threaded vCPU
+ * emulation on to the next vCPU. If more than one vCPU is running a
+ * timer event with force a cpu->exit so the next vCPU can get
+ * scheduled.
+ *
+ * The timer is removed if all vCPUs are idle and restarted again once
+ * idleness is complete.
+ */
+
+static QEMUTimer *tcg_kick_vcpu_timer;
+static CPUState *tcg_current_rr_cpu;
+
+#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10)
+
+static inline int64_t qemu_tcg_next_kick(void)
+{
+return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + TCG_KICK_PERIOD;
+}
+
+/* Kick the currently round-robi

[PATCH v6 07/16] cpus: extract out hax-specific code to target/i386/

2020-09-01 Thread Claudio Fontana
register a "CpusAccel" interface for HAX as well.

Signed-off-by: Claudio Fontana 
Reviewed-by: Richard Henderson 
---
 softmmu/cpus.c| 80 +---
 target/i386/hax-all.c |  6 ++-
 target/i386/hax-cpus.c| 85 +++
 target/i386/hax-cpus.h| 17 
 target/i386/hax-i386.h|  2 +
 target/i386/hax-posix.c   | 12 ++
 target/i386/hax-windows.c | 20 +
 target/i386/meson.build   |  9 -
 8 files changed, 149 insertions(+), 82 deletions(-)
 create mode 100644 target/i386/hax-cpus.c
 create mode 100644 target/i386/hax-cpus.h

diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index fd5bd6d809..cadaec5b95 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -33,7 +33,6 @@
 #include "exec/gdbstub.h"
 #include "sysemu/hw_accel.h"
 #include "sysemu/kvm.h"
-#include "sysemu/hax.h"
 #include "sysemu/hvf.h"
 #include "sysemu/whpx.h"
 #include "exec/exec-all.h"
@@ -179,9 +178,6 @@ void cpu_synchronize_state(CPUState *cpu)
 if (cpus_accel && cpus_accel->synchronize_state) {
 cpus_accel->synchronize_state(cpu);
 }
-if (hax_enabled()) {
-hax_cpu_synchronize_state(cpu);
-}
 if (whpx_enabled()) {
 whpx_cpu_synchronize_state(cpu);
 }
@@ -192,9 +188,6 @@ void cpu_synchronize_post_reset(CPUState *cpu)
 if (cpus_accel && cpus_accel->synchronize_post_reset) {
 cpus_accel->synchronize_post_reset(cpu);
 }
-if (hax_enabled()) {
-hax_cpu_synchronize_post_reset(cpu);
-}
 if (whpx_enabled()) {
 whpx_cpu_synchronize_post_reset(cpu);
 }
@@ -205,9 +198,6 @@ void cpu_synchronize_post_init(CPUState *cpu)
 if (cpus_accel && cpus_accel->synchronize_post_init) {
 cpus_accel->synchronize_post_init(cpu);
 }
-if (hax_enabled()) {
-hax_cpu_synchronize_post_init(cpu);
-}
 if (whpx_enabled()) {
 whpx_cpu_synchronize_post_init(cpu);
 }
@@ -218,9 +208,6 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu)
 if (cpus_accel && cpus_accel->synchronize_pre_loadvm) {
 cpus_accel->synchronize_pre_loadvm(cpu);
 }
-if (hax_enabled()) {
-hax_cpu_synchronize_pre_loadvm(cpu);
-}
 if (hvf_enabled()) {
 hvf_cpu_synchronize_pre_loadvm(cpu);
 }
@@ -416,35 +403,6 @@ void qemu_wait_io_event(CPUState *cpu)
 qemu_wait_io_event_common(cpu);
 }
 
-static void *qemu_hax_cpu_thread_fn(void *arg)
-{
-CPUState *cpu = arg;
-int r;
-
-rcu_register_thread();
-qemu_mutex_lock_iothread();
-qemu_thread_get_self(cpu->thread);
-
-cpu->thread_id = qemu_get_thread_id();
-current_cpu = cpu;
-hax_init_vcpu(cpu);
-cpu_thread_signal_created(cpu);
-qemu_guest_random_seed_thread_part2(cpu->random_seed);
-
-do {
-if (cpu_can_run(cpu)) {
-r = hax_smp_cpu_exec(cpu);
-if (r == EXCP_DEBUG) {
-cpu_handle_guest_debug(cpu);
-}
-}
-
-qemu_wait_io_event(cpu);
-} while (!cpu->unplug || cpu_can_run(cpu));
-rcu_unregister_thread();
-return NULL;
-}
-
 /* The HVF-specific vCPU thread function. This one should only run when the 
host
  * CPU supports the VMX "unrestricted guest" feature. */
 static void *qemu_hvf_cpu_thread_fn(void *arg)
@@ -529,12 +487,6 @@ static void *qemu_whpx_cpu_thread_fn(void *arg)
 return NULL;
 }
 
-#ifdef _WIN32
-static void CALLBACK dummy_apc_func(ULONG_PTR unused)
-{
-}
-#endif
-
 void cpus_kick_thread(CPUState *cpu)
 {
 #ifndef _WIN32
@@ -553,10 +505,6 @@ void cpus_kick_thread(CPUState *cpu)
 if (!qemu_cpu_is_self(cpu)) {
 if (whpx_enabled()) {
 whpx_vcpu_kick(cpu);
-} else if (!QueueUserAPC(dummy_apc_func, cpu->hThread, 0)) {
-fprintf(stderr, "%s: QueueUserAPC failed with error %lu\n",
-__func__, GetLastError());
-exit(1);
 }
 }
 #endif
@@ -567,14 +515,7 @@ void qemu_cpu_kick(CPUState *cpu)
 qemu_cond_broadcast(cpu->halt_cond);
 if (cpus_accel && cpus_accel->kick_vcpu_thread) {
 cpus_accel->kick_vcpu_thread(cpu);
-} else {
-if (hax_enabled()) {
-/*
- * FIXME: race condition with the exit_request check in
- * hax_vcpu_hax_exec
- */
-cpu->exit_request = 1;
-}
+} else { /* default */
 cpus_kick_thread(cpu);
 }
 }
@@ -722,23 +663,6 @@ void cpu_remove_sync(CPUState *cpu)
 qemu_mutex_lock_iothread();
 }
 
-static void qemu_hax_start_vcpu(CPUState *cpu)
-{
-char thread_name[VCPU_THREAD_NAME_SIZE];
-
-cpu->thread = g_malloc0(sizeof(QemuThread));
-cpu->halt_cond = g_malloc0(sizeof(QemuCond));
-qemu_cond_init(cpu->halt_cond);
-
-snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HAX",
- cpu->cpu_index);
-qemu_thread_create(cpu->thread, thread_name, qemu_hax_cpu_thread_fn,
-   cpu, QEMU_THREAD_JOINABLE);
-#ifdef 

[PATCH v6 09/16] cpus: extract out hvf-specific code to target/i386/hvf/

2020-09-01 Thread Claudio Fontana
register a "CpusAccel" interface for HVF as well.

Signed-off-by: Claudio Fontana 
Reviewed-by: Roman Bolshakov 
[added const]
Signed-off-by: Claudio Fontana 
Reviewed-by: Richard Henderson 
---
 softmmu/cpus.c  |  66 --
 target/i386/hvf/hvf-cpus.c  | 131 
 target/i386/hvf/hvf-cpus.h  |  17 +
 target/i386/hvf/hvf.c   |   3 +
 target/i386/hvf/meson.build |   1 +
 5 files changed, 152 insertions(+), 66 deletions(-)
 create mode 100644 target/i386/hvf/hvf-cpus.c
 create mode 100644 target/i386/hvf/hvf-cpus.h

diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index a99eacd6a6..2420a447eb 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -33,7 +33,6 @@
 #include "exec/gdbstub.h"
 #include "sysemu/hw_accel.h"
 #include "sysemu/kvm.h"
-#include "sysemu/hvf.h"
 #include "exec/exec-all.h"
 #include "qemu/thread.h"
 #include "qemu/plugin.h"
@@ -198,9 +197,6 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu)
 if (cpus_accel && cpus_accel->synchronize_pre_loadvm) {
 cpus_accel->synchronize_pre_loadvm(cpu);
 }
-if (hvf_enabled()) {
-hvf_cpu_synchronize_pre_loadvm(cpu);
-}
 }
 
 int64_t cpus_get_virtual_clock(void)
@@ -390,48 +386,6 @@ void qemu_wait_io_event(CPUState *cpu)
 qemu_wait_io_event_common(cpu);
 }
 
-/* The HVF-specific vCPU thread function. This one should only run when the 
host
- * CPU supports the VMX "unrestricted guest" feature. */
-static void *qemu_hvf_cpu_thread_fn(void *arg)
-{
-CPUState *cpu = arg;
-
-int r;
-
-assert(hvf_enabled());
-
-rcu_register_thread();
-
-qemu_mutex_lock_iothread();
-qemu_thread_get_self(cpu->thread);
-
-cpu->thread_id = qemu_get_thread_id();
-cpu->can_do_io = 1;
-current_cpu = cpu;
-
-hvf_init_vcpu(cpu);
-
-/* signal CPU creation */
-cpu_thread_signal_created(cpu);
-qemu_guest_random_seed_thread_part2(cpu->random_seed);
-
-do {
-if (cpu_can_run(cpu)) {
-r = hvf_vcpu_exec(cpu);
-if (r == EXCP_DEBUG) {
-cpu_handle_guest_debug(cpu);
-}
-}
-qemu_wait_io_event(cpu);
-} while (!cpu->unplug || cpu_can_run(cpu));
-
-hvf_vcpu_destroy(cpu);
-cpu_thread_signal_destroyed(cpu);
-qemu_mutex_unlock_iothread();
-rcu_unregister_thread();
-return NULL;
-}
-
 void cpus_kick_thread(CPUState *cpu)
 {
 #ifndef _WIN32
@@ -602,24 +556,6 @@ void cpu_remove_sync(CPUState *cpu)
 qemu_mutex_lock_iothread();
 }
 
-static void qemu_hvf_start_vcpu(CPUState *cpu)
-{
-char thread_name[VCPU_THREAD_NAME_SIZE];
-
-/* HVF currently does not support TCG, and only runs in
- * unrestricted-guest mode. */
-assert(hvf_enabled());
-
-cpu->thread = g_malloc0(sizeof(QemuThread));
-cpu->halt_cond = g_malloc0(sizeof(QemuCond));
-qemu_cond_init(cpu->halt_cond);
-
-snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HVF",
- cpu->cpu_index);
-qemu_thread_create(cpu->thread, thread_name, qemu_hvf_cpu_thread_fn,
-   cpu, QEMU_THREAD_JOINABLE);
-}
-
 void cpus_register_accel(const CpusAccel *ca)
 {
 assert(ca != NULL);
@@ -647,8 +583,6 @@ void qemu_init_vcpu(CPUState *cpu)
 if (cpus_accel) {
 /* accelerator already implements the CpusAccel interface */
 cpus_accel->create_vcpu_thread(cpu);
-} else if (hvf_enabled()) {
-qemu_hvf_start_vcpu(cpu);
 } else {
 g_assert_not_reached();
 }
diff --git a/target/i386/hvf/hvf-cpus.c b/target/i386/hvf/hvf-cpus.c
new file mode 100644
index 00..817b3d7452
--- /dev/null
+++ b/target/i386/hvf/hvf-cpus.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2008 IBM Corporation
+ *   2008 Red Hat, Inc.
+ * Copyright 2011 Intel Corporation
+ * Copyright 2016 Veertu, Inc.
+ * Copyright 2017 The Android Open Source Project
+ *
+ * QEMU Hypervisor.framework support
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see .
+ *
+ * This file contain code under public domain from the hvdos project:
+ * https://github.com/mist64/hvdos
+ *
+ * Parts Copyright (c) 2011 NetApp, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer

[PATCH v6 01/16] cpu-timers, icount: new modules

2020-09-01 Thread Claudio Fontana
refactoring of cpus.c continues with cpu timer state extraction.

cpu-timers: responsible for the softmmu cpu timers state,
including cpu clocks and ticks.

icount: counts the TCG instructions executed. As such it is specific to
the TCG accelerator. Therefore, it is built only under CONFIG_TCG.

One complication is due to qtest, which uses an icount field to warp time
as part of qtest (qtest_clock_warp).

In order to solve this problem, provide a separate counter for qtest.

This requires fixing assumptions scattered in the code that
qtest_enabled() implies icount_enabled(), checking each specific case.

Signed-off-by: Claudio Fontana 
---
 MAINTAINERS  |   2 +
 accel/qtest.c|   6 +-
 accel/tcg/cpu-exec.c |  39 +-
 accel/tcg/tcg-all.c  |   7 +-
 accel/tcg/translate-all.c|   3 +-
 dma-helpers.c|   4 +-
 exec.c   |   4 -
 hw/core/ptimer.c |   8 +-
 hw/i386/x86.c|   1 +
 include/exec/cpu-all.h   |   4 +
 include/exec/exec-all.h  |   4 +-
 include/qemu/timer.h |  24 +-
 include/sysemu/cpu-timers.h  |  87 
 include/sysemu/cpus.h|  12 +-
 include/sysemu/qtest.h   |   2 +
 replay/replay.c  |   4 +-
 softmmu/cpu-timers.c | 284 +
 softmmu/cpus.c   | 744 +--
 softmmu/icount.c | 492 +++
 softmmu/meson.build  |  10 +-
 softmmu/qtest.c  |  34 +-
 softmmu/timers-state.h   |  69 
 softmmu/vl.c |   9 +-
 stubs/clock-warp.c   |   7 -
 stubs/cpu-get-clock.c|   3 +-
 stubs/cpu-get-icount.c   |  21 -
 stubs/icount.c   |  45 +++
 stubs/meson.build|   4 +-
 stubs/qemu-timer-notify-cb.c |   8 +
 stubs/qtest.c|   5 +
 target/alpha/translate.c |   3 +-
 target/arm/helper.c  |   3 +-
 target/riscv/csr.c   |   4 +-
 tests/ptimer-test-stubs.c|   5 +-
 tests/test-timed-average.c   |   2 +-
 util/main-loop.c |  12 +-
 util/qemu-timer.c|  10 +-
 37 files changed, 1138 insertions(+), 847 deletions(-)
 create mode 100644 include/sysemu/cpu-timers.h
 create mode 100644 softmmu/cpu-timers.c
 create mode 100644 softmmu/icount.c
 create mode 100644 softmmu/timers-state.h
 delete mode 100644 stubs/clock-warp.c
 delete mode 100644 stubs/cpu-get-icount.c
 create mode 100644 stubs/icount.c
 create mode 100644 stubs/qemu-timer-notify-cb.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 5a22c8be42..f5361360a2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2286,6 +2286,8 @@ F: softmmu/vl.c
 F: softmmu/main.c
 F: softmmu/cpus.c
 F: softmmu/cpu-throttle.c
+F: softmmu/cpu-timers.c
+F: softmmu/icount.c
 F: qapi/run-state.json
 
 Human Monitor (HMP)
diff --git a/accel/qtest.c b/accel/qtest.c
index 5b88f55921..119d0f16a4 100644
--- a/accel/qtest.c
+++ b/accel/qtest.c
@@ -19,14 +19,10 @@
 #include "sysemu/accel.h"
 #include "sysemu/qtest.h"
 #include "sysemu/cpus.h"
+#include "sysemu/cpu-timers.h"
 
 static int qtest_init_accel(MachineState *ms)
 {
-QemuOpts *opts = qemu_opts_create(qemu_find_opts("icount"), NULL, 0,
-  &error_abort);
-qemu_opt_set(opts, "shift", "0", &error_abort);
-configure_icount(opts, &error_abort);
-qemu_opts_del(opts);
 return 0;
 }
 
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 66d38f9d85..279169d47d 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -19,6 +19,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/qemu-print.h"
 #include "cpu.h"
 #include "trace.h"
 #include "disas/disas.h"
@@ -36,6 +37,8 @@
 #include "hw/i386/apic.h"
 #endif
 #include "sysemu/cpus.h"
+#include "exec/cpu-all.h"
+#include "sysemu/cpu-timers.h"
 #include "sysemu/replay.h"
 
 /* -icount align implementation. */
@@ -56,6 +59,9 @@ typedef struct SyncClocks {
 #define MAX_DELAY_PRINT_RATE 20LL
 #define MAX_NB_PRINTS 100
 
+static int64_t max_delay;
+static int64_t max_advance;
+
 static void align_clocks(SyncClocks *sc, CPUState *cpu)
 {
 int64_t cpu_icount;
@@ -98,9 +104,9 @@ static void print_delay(const SyncClocks *sc)
 (-sc->diff_clk / (float)10LL <
  (threshold_delay - THRESHOLD_REDUCE))) {
 threshold_delay = (-sc->diff_clk / 10LL) + 1;
-printf("Warning: The guest is now late by %.1f to %.1f seconds\n",
-   threshold_delay - 1,
-   threshold_delay);
+qemu_printf("Warning: The guest is now late by %.1f to %.1f 
seconds\n",
+threshold_delay - 1,
+threshold_delay);
 nb_prints++;
 last_realtime_clock = sc->realtime_clock;
 }
@@ -614,7 +620,7 @@ static inline bool cpu_handle_interrupt(CPUState *cpu,
 
 /* Finally, check if we need to exit t

[PATCH v6 10/16] cpus: cleanup now unneeded includes

2020-09-01 Thread Claudio Fontana
Signed-off-by: Claudio Fontana 
Reviewed-by: Richard Henderson 
---
 softmmu/cpus.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index 2420a447eb..3d8350fba9 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -29,20 +29,13 @@
 #include "qapi/qapi-commands-misc.h"
 #include "qapi/qapi-events-run-state.h"
 #include "qapi/qmp/qerror.h"
-#include "sysemu/tcg.h"
 #include "exec/gdbstub.h"
 #include "sysemu/hw_accel.h"
-#include "sysemu/kvm.h"
 #include "exec/exec-all.h"
 #include "qemu/thread.h"
 #include "qemu/plugin.h"
 #include "sysemu/cpus.h"
-#include "qemu/main-loop.h"
-#include "qemu/option.h"
-#include "qemu/bitmap.h"
-#include "qemu/seqlock.h"
 #include "qemu/guest-random.h"
-#include "tcg/tcg.h"
 #include "hw/nmi.h"
 #include "sysemu/replay.h"
 #include "sysemu/runstate.h"
-- 
2.26.2




[PATCH v6 00/16] QEMU cpus.c refactoring part2

2020-09-01 Thread Claudio Fontana
Motivation and higher level steps:

https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg04628.html

Main Open topics:

* in some cases the virtual clock is queried before an accelerator
  is set or ticks are enabled with

  qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL)
  
  by the qcow2.c code (ending up in 0); maybe this should not happen at all,
  as it could hurt migrations with the clock jumping up from 0?
  Should it be QEMU_CLOCK_REALTIME? (Berto, Paolo)

* currently the per-accelerator CpusAccel structs use NULL to mean
  "default", and only explicitly define non-default behavior
  in the methods. Should this be changed? (Richard / Paolo)

* refactoring of tcg start vcpu code, so that more common parts can be
  reused in providing multiple structs for normal, icount, mttcg.
  Could this be part of another series (before or after this)?
  (Alex, Richard)

* question around naming of functions for the cpus module,
  currently using cpus_ in the newly implemented functionality.
  (Roman)

Ciao,

Claudio

PATCH v5 -> PATCH v6:

* moved to mason build system

* patch (new): cpus: remove checks for non-NULL cpus_accel (Richard)

  This has however a big caveat: in some cases the virtual clock is
  queried before an accelerator is set or ticks are enabled; this is
  currently special cased (keeping the NULL check in cpus_get_virtual_clock),
  but maybe this should not happen at all? (Paolo, Berto)

* in patch "cpu-timers, icount: new modules"
  do not change (yet) icount_enabled() to a function.
  Mimic instead what is done with tcg_enabled(). (Richard)

* split the changes into two separate patches, with name-only changes
  extracted out into a separate patch (Richard).
  Removed existing Reviewed-by because of these changes (Alex)-
  Alex are you ok with them?

* in patch "cpus: prepare new CpusAccel cpu accelerator interface"
  remove some unneeded stubs from stubs/cpu-synchronize-state.c
  Use const for the CpusAccel interface. (Richard)

* in patch "cpus: extract out TCG-specific code to accel/tcg"
  use const for the CpusAccel interface. (Richard)

* in patch "cpus: extract out qtest-specific code to accel/qtest"
  use const for the CpusAccel interface;
  use g_assert_not_reached (Richard)

* in patch "cpus: extract out kvm-specific code to accel/kvm"
  use const for the CpusAccel interface. (Richard)

* in patch "cpus: extract out hax-specific code to target/i386/"
  use const for the CpusAccel interface. (Richard)

* in patch "cpus: extract out whpx-specific code to target/i386/"
  use const for the CpusAccel interface. (Richard)

* in patch "cpus: extract out hvf-specific code to target/i386/hvf/"
  use const for the CpusAccel interface. (Richard)


RFC v4 -> PATCH v5:

* in patch 2, move comment about cpus_get_elapsed_ticks from patch 3
  (Philippe)

* in patch 11-14, do not create separate xxx-int.h files,
  instead use the xxx-cpus.h files (Philippe)

RFC v3 -> v4:

* added patch 9: cleanup unneeded includes

* added patch 10: add handle_interrupt to the interface (Roman)

* added patch 11-14: remove accelerator specific internal functions
  from global includes (Roman)

* in patch 2, removed leftover "if hvf_enabled" hunk

* in patch 2, convert if (!tcg_enabled) with more punctual if (hax_enabled)
  when eating dummy APC



RFC v2 -> v3:

* provided defaults for all methods.
  Only create_vcpu_thread is now a mandatory field. (Paolo)

* separated new CpusAccel patch from its first user, new patch nr. 2:
  "cpus: prepare new CpusAccel cpu accelerator interface"

* new CpusAccel methods: get_virtual_clock and get_elapsed_ticks.
  (Paolo)

  In this series, get_virtual_clock has a separate implementation
  between TCG/icount and qtest,
  while get_elapsed_ticks only returns a virtual counter for icount.

  Looking for more comments in this area.



RFC v1 -> v2:

* split the cpus.c accelerator refactoring into 6 patches.

* other minor changes to be able to proceed step by step.



* Rebased on commit 255ae6e2158c743717bed76c9a2365ee4bcd326e,
"replay: notify the main loop when there are no instructions"

[SPLIT into part1 and part2]



v6 -> v7:

* rebased changes on top of Pavel Dovgalyuk changes to dma-helpers.c
  "icount: make dma reads deterministic"



v5 -> v6:

* rebased changes on top of Emilio G. Cota changes to cpus.c
  "cpu: convert queued work to a QSIMPLEQ"

* keep a pointer in cpus.c instead of a copy of CpusAccel
  (Alex)




v4 -> v5: rebase on latest master

* rebased changes on top of roman series to remove one of the extra states for 
hvf.
  (Is the result now functional for HVF?)

* rebased changes on top of icount changes and fixes to icount_configure and
  the new shift vmstate. (Markus)

v3 -> v4:

* overall: added copyright headers to all files that were missing them
  (used copyright and license of the module the stuff was extracted from).
  For the new interface files, added SUSE LLC.

* 1/4 (move softmmu only files from root):

  MAINTAINERS: moved 

[PATCH v6 03/16] cpus: prepare new CpusAccel cpu accelerator interface

2020-09-01 Thread Claudio Fontana
The new interface starts unused, will start being used by the
next patches.

It provides methods for each accelerator to start a vcpu, kick a vcpu,
synchronize state, get cpu virtual clock and elapsed ticks.

In qemu_wait_io_event, make it clear that APC is used only for HAX
on Windows.

Signed-off-by: Claudio Fontana 
---
 hw/core/cpu.c  |   1 +
 hw/i386/x86.c  |   2 +-
 include/sysemu/cpu-timers.h|   9 +-
 include/sysemu/cpus.h  |  36 ++
 include/sysemu/hw_accel.h  |  69 +---
 softmmu/cpu-timers.c   |   9 +-
 softmmu/cpus.c | 195 ++---
 stubs/cpu-synchronize-state.c  |   9 ++
 stubs/cpus-get-virtual-clock.c |   8 ++
 stubs/meson.build  |   2 +
 util/qemu-timer.c  |   8 +-
 11 files changed, 225 insertions(+), 123 deletions(-)
 create mode 100644 stubs/cpu-synchronize-state.c
 create mode 100644 stubs/cpus-get-virtual-clock.c

diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index 22bc3f974a..fa8602493b 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -33,6 +33,7 @@
 #include "hw/qdev-properties.h"
 #include "trace/trace-root.h"
 #include "qemu/plugin.h"
+#include "sysemu/hw_accel.h"
 
 CPUInterruptHandler cpu_interrupt_handler;
 
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index b0ae118de5..f6de6888c0 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -264,7 +264,7 @@ static long get_file_size(FILE *f)
 /* TSC handling */
 uint64_t cpu_get_tsc(CPUX86State *env)
 {
-return cpu_get_ticks();
+return cpus_get_elapsed_ticks();
 }
 
 /* IRQ handling */
diff --git a/include/sysemu/cpu-timers.h b/include/sysemu/cpu-timers.h
index 7726e005cd..ed6ee5c46c 100644
--- a/include/sysemu/cpu-timers.h
+++ b/include/sysemu/cpu-timers.h
@@ -70,9 +70,8 @@ void cpu_enable_ticks(void);
 void cpu_disable_ticks(void);
 
 /*
- * return the time elapsed in VM between vm_start and vm_stop.  Unless
- * icount is active, cpu_get_ticks() uses units of the host CPU cycle
- * counter.
+ * return the time elapsed in VM between vm_start and vm_stop.
+ * cpu_get_ticks() uses units of the host CPU cycle counter.
  */
 int64_t cpu_get_ticks(void);
 
@@ -84,4 +83,8 @@ int64_t cpu_get_clock(void);
 
 void qemu_timer_notify_cb(void *opaque, QEMUClockType type);
 
+/* get the VIRTUAL clock and VM elapsed ticks via the cpus accel interface */
+int64_t cpus_get_virtual_clock(void);
+int64_t cpus_get_elapsed_ticks(void);
+
 #endif /* SYSEMU_CPU_TIMERS_H */
diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h
index 149de000a0..26171697f5 100644
--- a/include/sysemu/cpus.h
+++ b/include/sysemu/cpus.h
@@ -4,7 +4,43 @@
 #include "qemu/timer.h"
 
 /* cpus.c */
+
+/* CPU execution threads */
+
+typedef struct CpusAccel {
+void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY */
+void (*kick_vcpu_thread)(CPUState *cpu);
+
+void (*synchronize_post_reset)(CPUState *cpu);
+void (*synchronize_post_init)(CPUState *cpu);
+void (*synchronize_state)(CPUState *cpu);
+void (*synchronize_pre_loadvm)(CPUState *cpu);
+
+int64_t (*get_virtual_clock)(void);
+int64_t (*get_elapsed_ticks)(void);
+} CpusAccel;
+
+/* register accel-specific cpus interface implementation */
+void cpus_register_accel(const CpusAccel *i);
+
+/* interface available for cpus accelerator threads */
+
+/* For temporary buffers for forming a name */
+#define VCPU_THREAD_NAME_SIZE 16
+
+void cpus_kick_thread(CPUState *cpu);
+bool cpu_work_list_empty(CPUState *cpu);
+bool cpu_thread_is_idle(CPUState *cpu);
 bool all_cpu_threads_idle(void);
+bool cpu_can_run(CPUState *cpu);
+void qemu_wait_io_event_common(CPUState *cpu);
+void qemu_wait_io_event(CPUState *cpu);
+void cpu_thread_signal_created(CPUState *cpu);
+void cpu_thread_signal_destroyed(CPUState *cpu);
+void cpu_handle_guest_debug(CPUState *cpu);
+
+/* end interface for cpus accelerator threads */
+
 bool qemu_in_vcpu_thread(void);
 void qemu_init_cpu_loop(void);
 void resume_all_vcpus(void);
diff --git a/include/sysemu/hw_accel.h b/include/sysemu/hw_accel.h
index e128f8b06b..ffed6192a3 100644
--- a/include/sysemu/hw_accel.h
+++ b/include/sysemu/hw_accel.h
@@ -1,5 +1,5 @@
 /*
- * QEMU Hardware accelertors support
+ * QEMU Hardware accelerators support
  *
  * Copyright 2016 Google, Inc.
  *
@@ -17,68 +17,9 @@
 #include "sysemu/hvf.h"
 #include "sysemu/whpx.h"
 
-static inline void cpu_synchronize_state(CPUState *cpu)
-{
-if (kvm_enabled()) {
-kvm_cpu_synchronize_state(cpu);
-}
-if (hax_enabled()) {
-hax_cpu_synchronize_state(cpu);
-}
-if (hvf_enabled()) {
-hvf_cpu_synchronize_state(cpu);
-}
-if (whpx_enabled()) {
-whpx_cpu_synchronize_state(cpu);
-}
-}
-
-static inline void cpu_synchronize_post_reset(CPUState *cpu)
-{
-if (kvm_enabled()) {
-kvm_cpu_synchronize_post_reset(cpu);
-}
-if (hax_enabled()) {
-hax_cpu_synchronize_post_reset(cpu);
-}
-if (hvf_enabled()) {
-h

[PATCH v6 12/16] cpus: add handle_interrupt to the CpusAccel interface

2020-09-01 Thread Claudio Fontana
kvm: uses the generic handler
qtest: uses the generic handler
whpx: changed to use the generic handler (identical implementation)
hax: changed to use the generic handler (identical implementation)
hvf: changed to use the generic handler (identical implementation)
tcg: adapt tcg-cpus to point to the tcg-specific handler

Signed-off-by: Claudio Fontana 
---
 accel/tcg/tcg-all.c| 26 --
 accel/tcg/tcg-cpus.c   | 28 
 hw/core/cpu.c  | 13 -
 include/hw/core/cpu.h  | 14 --
 include/sysemu/cpus.h  |  2 ++
 softmmu/cpus.c | 18 ++
 target/i386/hax-all.c  | 10 --
 target/i386/hvf/hvf.c  |  9 -
 target/i386/whpx-all.c | 10 --
 9 files changed, 48 insertions(+), 82 deletions(-)

diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
index 01957b130d..af9bf5c5bb 100644
--- a/accel/tcg/tcg-all.c
+++ b/accel/tcg/tcg-all.c
@@ -47,31 +47,6 @@ typedef struct TCGState {
 #define TCG_STATE(obj) \
 OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL)
 
-/* mask must never be zero, except for A20 change call */
-static void tcg_handle_interrupt(CPUState *cpu, int mask)
-{
-int old_mask;
-g_assert(qemu_mutex_iothread_locked());
-
-old_mask = cpu->interrupt_request;
-cpu->interrupt_request |= mask;
-
-/*
- * If called from iothread context, wake the target cpu in
- * case its halted.
- */
-if (!qemu_cpu_is_self(cpu)) {
-qemu_cpu_kick(cpu);
-} else {
-atomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1);
-if (icount_enabled() &&
-!cpu->can_do_io
-&& (mask & ~old_mask) != 0) {
-cpu_abort(cpu, "Raised interrupt while not in I/O function");
-}
-}
-}
-
 /*
  * We default to false if we know other options have been enabled
  * which are currently incompatible with MTTCG. Otherwise when each
@@ -128,7 +103,6 @@ static int tcg_init(MachineState *ms)
 TCGState *s = TCG_STATE(current_accel());
 
 tcg_exec_init(s->tb_size * 1024 * 1024);
-cpu_interrupt_handler = tcg_handle_interrupt;
 mttcg_enabled = s->mttcg_enabled;
 cpus_register_accel(&tcg_cpus);
 
diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
index 72696f6d86..2bb209e2c6 100644
--- a/accel/tcg/tcg-cpus.c
+++ b/accel/tcg/tcg-cpus.c
@@ -533,9 +533,37 @@ static int64_t tcg_get_elapsed_ticks(void)
 return cpu_get_ticks();
 }
 
+/* mask must never be zero, except for A20 change call */
+static void tcg_handle_interrupt(CPUState *cpu, int mask)
+{
+int old_mask;
+g_assert(qemu_mutex_iothread_locked());
+
+old_mask = cpu->interrupt_request;
+cpu->interrupt_request |= mask;
+
+/*
+ * If called from iothread context, wake the target cpu in
+ * case its halted.
+ */
+if (!qemu_cpu_is_self(cpu)) {
+qemu_cpu_kick(cpu);
+} else {
+atomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1);
+if (icount_enabled() &&
+!cpu->can_do_io
+&& (mask & ~old_mask) != 0) {
+cpu_abort(cpu, "Raised interrupt while not in I/O function");
+}
+}
+}
+
 const CpusAccel tcg_cpus = {
 .create_vcpu_thread = tcg_start_vcpu_thread,
 .kick_vcpu_thread = tcg_kick_vcpu_thread,
+
+.handle_interrupt = tcg_handle_interrupt,
+
 .get_virtual_clock = tcg_get_virtual_clock,
 .get_elapsed_ticks = tcg_get_elapsed_ticks,
 };
diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index fa8602493b..451b3d5ee7 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -35,8 +35,6 @@
 #include "qemu/plugin.h"
 #include "sysemu/hw_accel.h"
 
-CPUInterruptHandler cpu_interrupt_handler;
-
 CPUState *cpu_by_arch_id(int64_t id)
 {
 CPUState *cpu;
@@ -394,17 +392,6 @@ static vaddr cpu_adjust_watchpoint_address(CPUState *cpu, 
vaddr addr, int len)
 return addr;
 }
 
-static void generic_handle_interrupt(CPUState *cpu, int mask)
-{
-cpu->interrupt_request |= mask;
-
-if (!qemu_cpu_is_self(cpu)) {
-qemu_cpu_kick(cpu);
-}
-}
-
-CPUInterruptHandler cpu_interrupt_handler = generic_handle_interrupt;
-
 static void cpu_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 8f145733ce..efd33d87fd 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -838,12 +838,6 @@ bool cpu_exists(int64_t id);
  */
 CPUState *cpu_by_arch_id(int64_t id);
 
-#ifndef CONFIG_USER_ONLY
-
-typedef void (*CPUInterruptHandler)(CPUState *, int);
-
-extern CPUInterruptHandler cpu_interrupt_handler;
-
 /**
  * cpu_interrupt:
  * @cpu: The CPU to set an interrupt on.
@@ -851,17 +845,9 @@ extern CPUInterruptHandler cpu_interrupt_handler;
  *
  * Invokes the interrupt handler.
  */
-static inline void cpu_interrupt(CPUState *cpu, int mask)
-{
-cpu_interrupt_handler(cpu, mask);
-}
-
-#else /* USER_ONLY */
 
 void cpu_interrupt(CPUState *cpu, int mask);
 
-#endif 

[PATCH v6 13/16] hvf: remove hvf specific functions from global includes

2020-09-01 Thread Claudio Fontana
Signed-off-by: Claudio Fontana 
Reviewed-by: Richard Henderson 
---
 accel/stubs/hvf-stub.c | 30 --
 accel/stubs/meson.build|  1 -
 include/sysemu/hvf.h   |  8 
 target/i386/hvf/hvf-cpus.h |  8 
 target/i386/hvf/x86hvf.c   |  2 ++
 target/i386/hvf/x86hvf.h   |  1 -
 6 files changed, 10 insertions(+), 40 deletions(-)
 delete mode 100644 accel/stubs/hvf-stub.c

diff --git a/accel/stubs/hvf-stub.c b/accel/stubs/hvf-stub.c
deleted file mode 100644
index e81dfe888c..00
--- a/accel/stubs/hvf-stub.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * QEMU HVF support
- *
- * Copyright 2017 Red Hat, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2 or later, as published by the Free Software Foundation,
- * and may be copied, distributed, and modified under those terms.
- *
- * See the COPYING file in the top-level directory.
- *
- */
-
-#include "qemu/osdep.h"
-#include "cpu.h"
-#include "sysemu/hvf.h"
-
-int hvf_init_vcpu(CPUState *cpu)
-{
-return -ENOSYS;
-}
-
-int hvf_vcpu_exec(CPUState *cpu)
-{
-return -ENOSYS;
-}
-
-void hvf_vcpu_destroy(CPUState *cpu)
-{
-}
diff --git a/accel/stubs/meson.build b/accel/stubs/meson.build
index 314e3cfff4..3fbe34e5bb 100644
--- a/accel/stubs/meson.build
+++ b/accel/stubs/meson.build
@@ -1,6 +1,5 @@
 specific_ss.add(when: 'CONFIG_HAX', if_false: files('hax-stub.c'))
 specific_ss.add(when: 'CONFIG_XEN', if_false: files('xen-stub.c'))
-specific_ss.add(when: 'CONFIG_HVF', if_false: files('hvf-stub.c'))
 specific_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
 specific_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c'))
 specific_ss.add(when: 'CONFIG_WHPX', if_false: files('whpx-stub.c'))
diff --git a/include/sysemu/hvf.h b/include/sysemu/hvf.h
index 760d6c79a2..7324e59db6 100644
--- a/include/sysemu/hvf.h
+++ b/include/sysemu/hvf.h
@@ -25,14 +25,6 @@ extern bool hvf_allowed;
 #define hvf_get_supported_cpuid(func, idx, reg) 0
 #endif /* !CONFIG_HVF */
 
-int hvf_init_vcpu(CPUState *);
-int hvf_vcpu_exec(CPUState *);
-void hvf_cpu_synchronize_state(CPUState *);
-void hvf_cpu_synchronize_post_reset(CPUState *);
-void hvf_cpu_synchronize_post_init(CPUState *);
-void hvf_cpu_synchronize_pre_loadvm(CPUState *);
-void hvf_vcpu_destroy(CPUState *);
-
 #define TYPE_HVF_ACCEL ACCEL_CLASS_NAME("hvf")
 
 typedef struct HVFState HVFState;
diff --git a/target/i386/hvf/hvf-cpus.h b/target/i386/hvf/hvf-cpus.h
index 262e449fd6..ced31b82c0 100644
--- a/target/i386/hvf/hvf-cpus.h
+++ b/target/i386/hvf/hvf-cpus.h
@@ -14,4 +14,12 @@
 
 extern const CpusAccel hvf_cpus;
 
+int hvf_init_vcpu(CPUState *);
+int hvf_vcpu_exec(CPUState *);
+void hvf_cpu_synchronize_state(CPUState *);
+void hvf_cpu_synchronize_post_reset(CPUState *);
+void hvf_cpu_synchronize_post_init(CPUState *);
+void hvf_cpu_synchronize_pre_loadvm(CPUState *);
+void hvf_vcpu_destroy(CPUState *);
+
 #endif /* HVF_CPUS_H */
diff --git a/target/i386/hvf/x86hvf.c b/target/i386/hvf/x86hvf.c
index 5cbcb32ab6..b986213c0f 100644
--- a/target/i386/hvf/x86hvf.c
+++ b/target/i386/hvf/x86hvf.c
@@ -32,6 +32,8 @@
 #include 
 #include 
 
+#include "hvf-cpus.h"
+
 void hvf_set_segment(struct CPUState *cpu, struct vmx_segment *vmx_seg,
  SegmentCache *qseg, bool is_tr)
 {
diff --git a/target/i386/hvf/x86hvf.h b/target/i386/hvf/x86hvf.h
index 79539f7282..4fabc6d582 100644
--- a/target/i386/hvf/x86hvf.h
+++ b/target/i386/hvf/x86hvf.h
@@ -35,5 +35,4 @@ void hvf_get_msrs(CPUState *cpu_state);
 void vmx_clear_int_window_exiting(CPUState *cpu);
 void hvf_get_segments(CPUState *cpu_state);
 void vmx_update_tpr(CPUState *cpu);
-void hvf_cpu_synchronize_state(CPUState *cpu_state);
 #endif
-- 
2.26.2




[PATCH v6 06/16] cpus: extract out kvm-specific code to accel/kvm

2020-09-01 Thread Claudio Fontana
register a "CpusAccel" interface for KVM as well.

Signed-off-by: Claudio Fontana 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
[added const]
Signed-off-by: Claudio Fontana 
Reviewed-by: Richard Henderson 
---
 accel/kvm/kvm-all.c| 14 ++-
 accel/kvm/kvm-cpus.c   | 88 ++
 accel/kvm/kvm-cpus.h   | 17 
 accel/kvm/meson.build  |  5 ++-
 accel/stubs/kvm-stub.c |  3 +-
 include/sysemu/kvm.h   |  2 +-
 softmmu/cpus.c | 77 
 7 files changed, 124 insertions(+), 82 deletions(-)
 create mode 100644 accel/kvm/kvm-cpus.c
 create mode 100644 accel/kvm/kvm-cpus.h

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 63ef6af9a1..fbd82cb444 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -44,6 +44,9 @@
 #include "qapi/qapi-types-common.h"
 #include "qapi/qapi-visit-common.h"
 #include "sysemu/reset.h"
+#include "qemu/guest-random.h"
+#include "sysemu/hw_accel.h"
+#include "kvm-cpus.h"
 
 #include "hw/boards.h"
 
@@ -378,7 +381,7 @@ err:
 return ret;
 }
 
-int kvm_destroy_vcpu(CPUState *cpu)
+static int do_kvm_destroy_vcpu(CPUState *cpu)
 {
 KVMState *s = kvm_state;
 long mmap_size;
@@ -412,6 +415,14 @@ err:
 return ret;
 }
 
+void kvm_destroy_vcpu(CPUState *cpu)
+{
+if (do_kvm_destroy_vcpu(cpu) < 0) {
+error_report("kvm_destroy_vcpu failed");
+exit(EXIT_FAILURE);
+}
+}
+
 static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
 {
 struct KVMParkedVcpu *cpu;
@@ -2232,6 +2243,7 @@ static int kvm_init(MachineState *ms)
 assert(!ret);
 }
 
+cpus_register_accel(&kvm_cpus);
 return 0;
 
 err:
diff --git a/accel/kvm/kvm-cpus.c b/accel/kvm/kvm-cpus.c
new file mode 100644
index 00..a120601564
--- /dev/null
+++ b/accel/kvm/kvm-cpus.c
@@ -0,0 +1,88 @@
+/*
+ * QEMU KVM support
+ *
+ * Copyright IBM, Corp. 2008
+ *   Red Hat, Inc. 2008
+ *
+ * Authors:
+ *  Anthony Liguori   
+ *  Glauber Costa 
+ *
+ * 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 "qemu/error-report.h"
+#include "qemu/main-loop.h"
+#include "sysemu/kvm_int.h"
+#include "sysemu/runstate.h"
+#include "sysemu/cpus.h"
+#include "qemu/guest-random.h"
+
+#include "kvm-cpus.h"
+
+static void *kvm_vcpu_thread_fn(void *arg)
+{
+CPUState *cpu = arg;
+int r;
+
+rcu_register_thread();
+
+qemu_mutex_lock_iothread();
+qemu_thread_get_self(cpu->thread);
+cpu->thread_id = qemu_get_thread_id();
+cpu->can_do_io = 1;
+current_cpu = cpu;
+
+r = kvm_init_vcpu(cpu);
+if (r < 0) {
+error_report("kvm_init_vcpu failed: %s", strerror(-r));
+exit(1);
+}
+
+kvm_init_cpu_signals(cpu);
+
+/* signal CPU creation */
+cpu_thread_signal_created(cpu);
+qemu_guest_random_seed_thread_part2(cpu->random_seed);
+
+do {
+if (cpu_can_run(cpu)) {
+r = kvm_cpu_exec(cpu);
+if (r == EXCP_DEBUG) {
+cpu_handle_guest_debug(cpu);
+}
+}
+qemu_wait_io_event(cpu);
+} while (!cpu->unplug || cpu_can_run(cpu));
+
+kvm_destroy_vcpu(cpu);
+cpu_thread_signal_destroyed(cpu);
+qemu_mutex_unlock_iothread();
+rcu_unregister_thread();
+return NULL;
+}
+
+static void kvm_start_vcpu_thread(CPUState *cpu)
+{
+char thread_name[VCPU_THREAD_NAME_SIZE];
+
+cpu->thread = g_malloc0(sizeof(QemuThread));
+cpu->halt_cond = g_malloc0(sizeof(QemuCond));
+qemu_cond_init(cpu->halt_cond);
+snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/KVM",
+ cpu->cpu_index);
+qemu_thread_create(cpu->thread, thread_name, kvm_vcpu_thread_fn,
+   cpu, QEMU_THREAD_JOINABLE);
+}
+
+const CpusAccel kvm_cpus = {
+.create_vcpu_thread = kvm_start_vcpu_thread,
+
+.synchronize_post_reset = kvm_cpu_synchronize_post_reset,
+.synchronize_post_init = kvm_cpu_synchronize_post_init,
+.synchronize_state = kvm_cpu_synchronize_state,
+.synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm,
+};
diff --git a/accel/kvm/kvm-cpus.h b/accel/kvm/kvm-cpus.h
new file mode 100644
index 00..547fbee111
--- /dev/null
+++ b/accel/kvm/kvm-cpus.h
@@ -0,0 +1,17 @@
+/*
+ * Accelerator CPUS Interface
+ *
+ * Copyright 2020 SUSE LLC
+ *
+ * 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 KVM_CPUS_H
+#define KVM_CPUS_H
+
+#include "sysemu/cpus.h"
+
+extern const CpusAccel kvm_cpus;
+
+#endif /* KVM_CPUS_H */
diff --git a/accel/kvm/meson.build b/accel/kvm/meson.build
index 4db2388e2f..7e9dafe24c 100644
--- a/accel/kvm/meson.build
+++ b/accel/kvm/meson.build
@@ -1,5 +1,8 @@
 kvm_ss = ss.source_set()
-kvm_ss.add(files('kvm-all.c'))
+kvm_ss.add(files(
+  'kvm-all.c',
+  'kvm-cpus.c',
+))
 

[PATCH v6 14/16] whpx: remove whpx specific functions from global includes

2020-09-01 Thread Claudio Fontana
Signed-off-by: Claudio Fontana 
Reviewed-by: Richard Henderson 
---
 accel/stubs/meson.build |  1 -
 accel/stubs/whpx-stub.c | 47 -
 include/sysemu/whpx.h   | 19 -
 target/i386/whpx-cpus.h | 17 +++
 4 files changed, 17 insertions(+), 67 deletions(-)
 delete mode 100644 accel/stubs/whpx-stub.c

diff --git a/accel/stubs/meson.build b/accel/stubs/meson.build
index 3fbe34e5bb..12dd1539af 100644
--- a/accel/stubs/meson.build
+++ b/accel/stubs/meson.build
@@ -2,4 +2,3 @@ specific_ss.add(when: 'CONFIG_HAX', if_false: 
files('hax-stub.c'))
 specific_ss.add(when: 'CONFIG_XEN', if_false: files('xen-stub.c'))
 specific_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
 specific_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c'))
-specific_ss.add(when: 'CONFIG_WHPX', if_false: files('whpx-stub.c'))
diff --git a/accel/stubs/whpx-stub.c b/accel/stubs/whpx-stub.c
deleted file mode 100644
index 1efb89f25e..00
--- a/accel/stubs/whpx-stub.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * QEMU Windows Hypervisor Platform accelerator (WHPX) stub
- *
- * Copyright Microsoft Corp. 2017
- *
- * 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 "cpu.h"
-#include "sysemu/whpx.h"
-
-int whpx_init_vcpu(CPUState *cpu)
-{
-return -1;
-}
-
-int whpx_vcpu_exec(CPUState *cpu)
-{
-return -1;
-}
-
-void whpx_destroy_vcpu(CPUState *cpu)
-{
-}
-
-void whpx_vcpu_kick(CPUState *cpu)
-{
-}
-
-void whpx_cpu_synchronize_state(CPUState *cpu)
-{
-}
-
-void whpx_cpu_synchronize_post_reset(CPUState *cpu)
-{
-}
-
-void whpx_cpu_synchronize_post_init(CPUState *cpu)
-{
-}
-
-void whpx_cpu_synchronize_pre_loadvm(CPUState *cpu)
-{
-}
diff --git a/include/sysemu/whpx.h b/include/sysemu/whpx.h
index a84b49e749..59edf13742 100644
--- a/include/sysemu/whpx.h
+++ b/include/sysemu/whpx.h
@@ -13,18 +13,6 @@
 #ifndef QEMU_WHPX_H
 #define QEMU_WHPX_H
 
-
-int whpx_init_vcpu(CPUState *cpu);
-int whpx_vcpu_exec(CPUState *cpu);
-void whpx_destroy_vcpu(CPUState *cpu);
-void whpx_vcpu_kick(CPUState *cpu);
-
-
-void whpx_cpu_synchronize_state(CPUState *cpu);
-void whpx_cpu_synchronize_post_reset(CPUState *cpu);
-void whpx_cpu_synchronize_post_init(CPUState *cpu);
-void whpx_cpu_synchronize_pre_loadvm(CPUState *cpu);
-
 #ifdef CONFIG_WHPX
 
 int whpx_enabled(void);
@@ -35,11 +23,4 @@ int whpx_enabled(void);
 
 #endif /* CONFIG_WHPX */
 
-/* state subset only touched by the VCPU itself during runtime */
-#define WHPX_SET_RUNTIME_STATE   1
-/* state subset modified during VCPU reset */
-#define WHPX_SET_RESET_STATE 2
-/* full state set, modified during initialization or on vmload */
-#define WHPX_SET_FULL_STATE  3
-
 #endif /* QEMU_WHPX_H */
diff --git a/target/i386/whpx-cpus.h b/target/i386/whpx-cpus.h
index 2393944954..bdb367d1d0 100644
--- a/target/i386/whpx-cpus.h
+++ b/target/i386/whpx-cpus.h
@@ -14,4 +14,21 @@
 
 extern const CpusAccel whpx_cpus;
 
+int whpx_init_vcpu(CPUState *cpu);
+int whpx_vcpu_exec(CPUState *cpu);
+void whpx_destroy_vcpu(CPUState *cpu);
+void whpx_vcpu_kick(CPUState *cpu);
+
+void whpx_cpu_synchronize_state(CPUState *cpu);
+void whpx_cpu_synchronize_post_reset(CPUState *cpu);
+void whpx_cpu_synchronize_post_init(CPUState *cpu);
+void whpx_cpu_synchronize_pre_loadvm(CPUState *cpu);
+
+/* state subset only touched by the VCPU itself during runtime */
+#define WHPX_SET_RUNTIME_STATE   1
+/* state subset modified during VCPU reset */
+#define WHPX_SET_RESET_STATE 2
+/* full state set, modified during initialization or on vmload */
+#define WHPX_SET_FULL_STATE  3
+
 #endif /* WHPX_CPUS_H */
-- 
2.26.2




[PATCH v6 08/16] cpus: extract out whpx-specific code to target/i386/

2020-09-01 Thread Claudio Fontana
register a "CpusAccel" interface for WHPX as well.

Signed-off-by: Claudio Fontana 
Reviewed-by: Richard Henderson 
---
 MAINTAINERS |  1 +
 softmmu/cpus.c  | 79 -
 target/i386/meson.build |  5 ++-
 target/i386/whpx-all.c  |  3 ++
 target/i386/whpx-cpus.c | 96 +
 target/i386/whpx-cpus.h | 17 
 6 files changed, 121 insertions(+), 80 deletions(-)
 create mode 100644 target/i386/whpx-cpus.c
 create mode 100644 target/i386/whpx-cpus.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 314ce0ded5..8d2b2679a9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -450,6 +450,7 @@ WHPX CPUs
 M: Sunil Muthuswamy 
 S: Supported
 F: target/i386/whpx-all.c
+F: target/i386/whpx-cpus.c
 F: target/i386/whp-dispatch.h
 F: accel/stubs/whpx-stub.c
 F: include/sysemu/whpx.h
diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index cadaec5b95..a99eacd6a6 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -34,7 +34,6 @@
 #include "sysemu/hw_accel.h"
 #include "sysemu/kvm.h"
 #include "sysemu/hvf.h"
-#include "sysemu/whpx.h"
 #include "exec/exec-all.h"
 #include "qemu/thread.h"
 #include "qemu/plugin.h"
@@ -178,9 +177,6 @@ void cpu_synchronize_state(CPUState *cpu)
 if (cpus_accel && cpus_accel->synchronize_state) {
 cpus_accel->synchronize_state(cpu);
 }
-if (whpx_enabled()) {
-whpx_cpu_synchronize_state(cpu);
-}
 }
 
 void cpu_synchronize_post_reset(CPUState *cpu)
@@ -188,9 +184,6 @@ void cpu_synchronize_post_reset(CPUState *cpu)
 if (cpus_accel && cpus_accel->synchronize_post_reset) {
 cpus_accel->synchronize_post_reset(cpu);
 }
-if (whpx_enabled()) {
-whpx_cpu_synchronize_post_reset(cpu);
-}
 }
 
 void cpu_synchronize_post_init(CPUState *cpu)
@@ -198,9 +191,6 @@ void cpu_synchronize_post_init(CPUState *cpu)
 if (cpus_accel && cpus_accel->synchronize_post_init) {
 cpus_accel->synchronize_post_init(cpu);
 }
-if (whpx_enabled()) {
-whpx_cpu_synchronize_post_init(cpu);
-}
 }
 
 void cpu_synchronize_pre_loadvm(CPUState *cpu)
@@ -211,9 +201,6 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu)
 if (hvf_enabled()) {
 hvf_cpu_synchronize_pre_loadvm(cpu);
 }
-if (whpx_enabled()) {
-whpx_cpu_synchronize_pre_loadvm(cpu);
-}
 }
 
 int64_t cpus_get_virtual_clock(void)
@@ -445,48 +432,6 @@ static void *qemu_hvf_cpu_thread_fn(void *arg)
 return NULL;
 }
 
-static void *qemu_whpx_cpu_thread_fn(void *arg)
-{
-CPUState *cpu = arg;
-int r;
-
-rcu_register_thread();
-
-qemu_mutex_lock_iothread();
-qemu_thread_get_self(cpu->thread);
-cpu->thread_id = qemu_get_thread_id();
-current_cpu = cpu;
-
-r = whpx_init_vcpu(cpu);
-if (r < 0) {
-fprintf(stderr, "whpx_init_vcpu failed: %s\n", strerror(-r));
-exit(1);
-}
-
-/* signal CPU creation */
-cpu_thread_signal_created(cpu);
-qemu_guest_random_seed_thread_part2(cpu->random_seed);
-
-do {
-if (cpu_can_run(cpu)) {
-r = whpx_vcpu_exec(cpu);
-if (r == EXCP_DEBUG) {
-cpu_handle_guest_debug(cpu);
-}
-}
-while (cpu_thread_is_idle(cpu)) {
-qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex);
-}
-qemu_wait_io_event_common(cpu);
-} while (!cpu->unplug || cpu_can_run(cpu));
-
-whpx_destroy_vcpu(cpu);
-cpu_thread_signal_destroyed(cpu);
-qemu_mutex_unlock_iothread();
-rcu_unregister_thread();
-return NULL;
-}
-
 void cpus_kick_thread(CPUState *cpu)
 {
 #ifndef _WIN32
@@ -501,12 +446,6 @@ void cpus_kick_thread(CPUState *cpu)
 fprintf(stderr, "qemu:%s: %s", __func__, strerror(err));
 exit(1);
 }
-#else /* _WIN32 */
-if (!qemu_cpu_is_self(cpu)) {
-if (whpx_enabled()) {
-whpx_vcpu_kick(cpu);
-}
-}
 #endif
 }
 
@@ -681,22 +620,6 @@ static void qemu_hvf_start_vcpu(CPUState *cpu)
cpu, QEMU_THREAD_JOINABLE);
 }
 
-static void qemu_whpx_start_vcpu(CPUState *cpu)
-{
-char thread_name[VCPU_THREAD_NAME_SIZE];
-
-cpu->thread = g_malloc0(sizeof(QemuThread));
-cpu->halt_cond = g_malloc0(sizeof(QemuCond));
-qemu_cond_init(cpu->halt_cond);
-snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX",
- cpu->cpu_index);
-qemu_thread_create(cpu->thread, thread_name, qemu_whpx_cpu_thread_fn,
-   cpu, QEMU_THREAD_JOINABLE);
-#ifdef _WIN32
-cpu->hThread = qemu_thread_get_handle(cpu->thread);
-#endif
-}
-
 void cpus_register_accel(const CpusAccel *ca)
 {
 assert(ca != NULL);
@@ -726,8 +649,6 @@ void qemu_init_vcpu(CPUState *cpu)
 cpus_accel->create_vcpu_thread(cpu);
 } else if (hvf_enabled()) {
 qemu_hvf_start_vcpu(cpu);
-} else if (whpx_enabled()) {
-qemu_whpx_start_vcpu(cpu);
 } else {
 g_assert_not_reached();
 }
diff --git a/target/i386/meson.bu

[PATCH v6 05/16] cpus: extract out qtest-specific code to accel/qtest

2020-09-01 Thread Claudio Fontana
register a "CpusAccel" interface for qtest as well.

Signed-off-by: Claudio Fontana 
---
 MAINTAINERS   |  2 +-
 accel/meson.build |  2 +-
 accel/qtest/meson.build   |  7 +++
 accel/qtest/qtest-cpus.c  | 91 +++
 accel/qtest/qtest-cpus.h  | 17 
 accel/{ => qtest}/qtest.c |  7 +++
 softmmu/cpus.c| 64 +--
 7 files changed, 125 insertions(+), 65 deletions(-)
 create mode 100644 accel/qtest/meson.build
 create mode 100644 accel/qtest/qtest-cpus.c
 create mode 100644 accel/qtest/qtest-cpus.h
 rename accel/{ => qtest}/qtest.c (86%)

diff --git a/MAINTAINERS b/MAINTAINERS
index f5361360a2..314ce0ded5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2443,7 +2443,7 @@ M: Laurent Vivier 
 R: Paolo Bonzini 
 S: Maintained
 F: softmmu/qtest.c
-F: accel/qtest.c
+F: accel/qtest/
 F: tests/qtest/
 X: tests/qtest/bios-tables-test-allowed-diff.h
 
diff --git a/accel/meson.build b/accel/meson.build
index 26c503e480..bb00d0fd13 100644
--- a/accel/meson.build
+++ b/accel/meson.build
@@ -1,6 +1,6 @@
 softmmu_ss.add(files('accel.c'))
-specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'], if_true: 
files('qtest.c'))
 
+subdir('qtest')
 subdir('kvm')
 subdir('tcg')
 subdir('xen')
diff --git a/accel/qtest/meson.build b/accel/qtest/meson.build
new file mode 100644
index 00..e477cb2ae2
--- /dev/null
+++ b/accel/qtest/meson.build
@@ -0,0 +1,7 @@
+qtest_ss = ss.source_set()
+qtest_ss.add(files(
+  'qtest.c',
+  'qtest-cpus.c',
+))
+
+specific_ss.add_all(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'], if_true: 
qtest_ss)
diff --git a/accel/qtest/qtest-cpus.c b/accel/qtest/qtest-cpus.c
new file mode 100644
index 00..7c5399ed9d
--- /dev/null
+++ b/accel/qtest/qtest-cpus.c
@@ -0,0 +1,91 @@
+/*
+ * QTest accelerator code
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   
+ *
+ * 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 "qemu/rcu.h"
+#include "qapi/error.h"
+#include "qemu/module.h"
+#include "qemu/option.h"
+#include "qemu/config-file.h"
+#include "sysemu/accel.h"
+#include "sysemu/qtest.h"
+#include "sysemu/cpus.h"
+#include "sysemu/cpu-timers.h"
+#include "qemu/guest-random.h"
+#include "qemu/main-loop.h"
+#include "hw/core/cpu.h"
+
+#include "qtest-cpus.h"
+
+static void *qtest_cpu_thread_fn(void *arg)
+{
+#ifdef _WIN32
+error_report("qtest is not supported under Windows");
+exit(1);
+#else
+CPUState *cpu = arg;
+sigset_t waitset;
+int r;
+
+rcu_register_thread();
+
+qemu_mutex_lock_iothread();
+qemu_thread_get_self(cpu->thread);
+cpu->thread_id = qemu_get_thread_id();
+cpu->can_do_io = 1;
+current_cpu = cpu;
+
+sigemptyset(&waitset);
+sigaddset(&waitset, SIG_IPI);
+
+/* signal CPU creation */
+cpu_thread_signal_created(cpu);
+qemu_guest_random_seed_thread_part2(cpu->random_seed);
+
+do {
+qemu_mutex_unlock_iothread();
+do {
+int sig;
+r = sigwait(&waitset, &sig);
+} while (r == -1 && (errno == EAGAIN || errno == EINTR));
+if (r == -1) {
+perror("sigwait");
+exit(1);
+}
+qemu_mutex_lock_iothread();
+qemu_wait_io_event(cpu);
+} while (!cpu->unplug);
+
+qemu_mutex_unlock_iothread();
+rcu_unregister_thread();
+return NULL;
+#endif
+}
+
+static void qtest_start_vcpu_thread(CPUState *cpu)
+{
+char thread_name[VCPU_THREAD_NAME_SIZE];
+
+cpu->thread = g_malloc0(sizeof(QemuThread));
+cpu->halt_cond = g_malloc0(sizeof(QemuCond));
+qemu_cond_init(cpu->halt_cond);
+snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY",
+ cpu->cpu_index);
+qemu_thread_create(cpu->thread, thread_name, qtest_cpu_thread_fn, cpu,
+   QEMU_THREAD_JOINABLE);
+}
+
+const CpusAccel qtest_cpus = {
+.create_vcpu_thread = qtest_start_vcpu_thread,
+.get_virtual_clock = qtest_get_virtual_clock,
+};
diff --git a/accel/qtest/qtest-cpus.h b/accel/qtest/qtest-cpus.h
new file mode 100644
index 00..739519a472
--- /dev/null
+++ b/accel/qtest/qtest-cpus.h
@@ -0,0 +1,17 @@
+/*
+ * Accelerator CPUS Interface
+ *
+ * Copyright 2020 SUSE LLC
+ *
+ * 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 QTEST_CPUS_H
+#define QTEST_CPUS_H
+
+#include "sysemu/cpus.h"
+
+extern const CpusAccel qtest_cpus;
+
+#endif /* QTEST_CPUS_H */
diff --git a/accel/qtest.c b/accel/qtest/qtest.c
similarity index 86%
rename from accel/qtest.c
rename to accel/qtest/qtest.c
index 119d0f16a4..537e8b449c 100644
--- a/accel/qtest.c
+++ b/accel/qtest/qtest.c
@@ -12,6 +12,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/rcu.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
 #include "qemu/option.h

[PATCH] configure: remove dead code for in-tree builds

2020-09-01 Thread Paolo Bonzini
The $pwd_is_source_path variable is never "y", since
configure re-executes itself from a build directory.
Remove code that will never run.

Cc: Daniel P. Berrangé 
Signed-off-by: Paolo Bonzini 
---
 configure | 14 ++
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/configure b/configure
index 8a3acef89d..7598bfbe4d 100755
--- a/configure
+++ b/configure
@@ -665,14 +665,6 @@ QEMU_INCLUDES="$QEMU_INCLUDES -iquote 
${source_path}/disas/libvixl"
 CFLAGS="-std=gnu99 -Wall"
 
 
-# running configure in the source tree?
-# we know that's the case if configure is there.
-if test -f "./configure"; then
-pwd_is_source_path="y"
-else
-pwd_is_source_path="n"
-fi
-
 check_define() {
 cat > $TMPC <

[PATCH v6 11/16] cpus: remove checks for non-NULL cpus_accel

2020-09-01 Thread Claudio Fontana
now that all accelerators support the CpusAccel interface,
we can remove most checks for non-NULL cpus_accel,
we just add a sanity check/assert at vcpu creation.

Signed-off-by: Claudio Fontana 
---
 softmmu/cpus.c | 33 +
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index 3d8350fba9..f32ecb4bb9 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -166,34 +166,46 @@ void cpu_synchronize_all_pre_loadvm(void)
 
 void cpu_synchronize_state(CPUState *cpu)
 {
-if (cpus_accel && cpus_accel->synchronize_state) {
+if (cpus_accel->synchronize_state) {
 cpus_accel->synchronize_state(cpu);
 }
 }
 
 void cpu_synchronize_post_reset(CPUState *cpu)
 {
-if (cpus_accel && cpus_accel->synchronize_post_reset) {
+if (cpus_accel->synchronize_post_reset) {
 cpus_accel->synchronize_post_reset(cpu);
 }
 }
 
 void cpu_synchronize_post_init(CPUState *cpu)
 {
-if (cpus_accel && cpus_accel->synchronize_post_init) {
+if (cpus_accel->synchronize_post_init) {
 cpus_accel->synchronize_post_init(cpu);
 }
 }
 
 void cpu_synchronize_pre_loadvm(CPUState *cpu)
 {
-if (cpus_accel && cpus_accel->synchronize_pre_loadvm) {
+if (cpus_accel->synchronize_pre_loadvm) {
 cpus_accel->synchronize_pre_loadvm(cpu);
 }
 }
 
 int64_t cpus_get_virtual_clock(void)
 {
+/*
+ * XXX
+ *
+ * need to check that cpus_accel is not NULL, because qcow2 calls
+ * qemu_get_clock_ns(CLOCK_VIRTUAL) without any accel initialized and
+ * with ticks disabled in some io-tests:
+ * 030 040 041 060 099 120 127 140 156 161 172 181 191 192 195 203 229 249 
256 267
+ *
+ * is this expected?
+ *
+ * XXX
+ */
 if (cpus_accel && cpus_accel->get_virtual_clock) {
 return cpus_accel->get_virtual_clock();
 }
@@ -207,7 +219,7 @@ int64_t cpus_get_virtual_clock(void)
  */
 int64_t cpus_get_elapsed_ticks(void)
 {
-if (cpus_accel && cpus_accel->get_elapsed_ticks) {
+if (cpus_accel->get_elapsed_ticks) {
 return cpus_accel->get_elapsed_ticks();
 }
 return cpu_get_ticks();
@@ -399,7 +411,7 @@ void cpus_kick_thread(CPUState *cpu)
 void qemu_cpu_kick(CPUState *cpu)
 {
 qemu_cond_broadcast(cpu->halt_cond);
-if (cpus_accel && cpus_accel->kick_vcpu_thread) {
+if (cpus_accel->kick_vcpu_thread) {
 cpus_accel->kick_vcpu_thread(cpu);
 } else { /* default */
 cpus_kick_thread(cpu);
@@ -573,12 +585,9 @@ void qemu_init_vcpu(CPUState *cpu)
 cpu_address_space_init(cpu, 0, "cpu-memory", cpu->memory);
 }
 
-if (cpus_accel) {
-/* accelerator already implements the CpusAccel interface */
-cpus_accel->create_vcpu_thread(cpu);
-} else {
-g_assert_not_reached();
-}
+/* accelerators all implement the CpusAccel interface */
+g_assert(cpus_accel != NULL && cpus_accel->create_vcpu_thread != NULL);
+cpus_accel->create_vcpu_thread(cpu);
 
 while (!cpu->created) {
 qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
-- 
2.26.2




Re: [PATCH-for-5.2 2/2] hw/core/sysbus: Assert memory region index is in range

2020-09-01 Thread Laurent Vivier
Le 06/08/2020 à 15:09, Philippe Mathieu-Daudé a écrit :
> Devices incorrectly modelled might use invalid index while
> calling sysbus_mmio_get_region(), leading to OOB access.
> Help developers by asserting the index is in range.
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/core/sysbus.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
> index 77ab351ce1..294f90b7de 100644
> --- a/hw/core/sysbus.c
> +++ b/hw/core/sysbus.c
> @@ -199,6 +199,7 @@ void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion 
> *memory)
>  
>  MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n)
>  {
> +assert(n >= 0 && n < QDEV_MAX_MMIO);
>  return dev->mmio[n].memory;
>  }
>  
> 

Applied to my trivial-patches branch.

Thanks,
Laurent




[PATCH v6 15/16] hax: remove hax specific functions from global includes

2020-09-01 Thread Claudio Fontana
Signed-off-by: Claudio Fontana 
Reviewed-by: Richard Henderson 
---
 accel/stubs/hax-stub.c| 10 --
 include/sysemu/hax.h  | 17 -
 target/i386/hax-all.c |  1 -
 target/i386/hax-cpus.c|  1 -
 target/i386/hax-cpus.h| 16 
 target/i386/hax-mem.c |  2 +-
 target/i386/hax-posix.c   |  3 +--
 target/i386/hax-windows.c |  2 +-
 target/i386/hax-windows.h |  2 ++
 9 files changed, 21 insertions(+), 33 deletions(-)

diff --git a/accel/stubs/hax-stub.c b/accel/stubs/hax-stub.c
index 7ad190cae2..1a9da83185 100644
--- a/accel/stubs/hax-stub.c
+++ b/accel/stubs/hax-stub.c
@@ -21,13 +21,3 @@ int hax_sync_vcpus(void)
 {
 return 0;
 }
-
-int hax_init_vcpu(CPUState *cpu)
-{
-return -ENOSYS;
-}
-
-int hax_smp_cpu_exec(CPUState *cpu)
-{
-return -ENOSYS;
-}
diff --git a/include/sysemu/hax.h b/include/sysemu/hax.h
index 9b27e65cc7..12fb54f990 100644
--- a/include/sysemu/hax.h
+++ b/include/sysemu/hax.h
@@ -22,29 +22,12 @@
 #ifndef QEMU_HAX_H
 #define QEMU_HAX_H
 
-
 int hax_sync_vcpus(void);
-int hax_init_vcpu(CPUState *cpu);
-int hax_smp_cpu_exec(CPUState *cpu);
-int hax_populate_ram(uint64_t va, uint64_t size);
-
-void hax_cpu_synchronize_state(CPUState *cpu);
-void hax_cpu_synchronize_post_reset(CPUState *cpu);
-void hax_cpu_synchronize_post_init(CPUState *cpu);
-void hax_cpu_synchronize_pre_loadvm(CPUState *cpu);
 
 #ifdef CONFIG_HAX
 
 int hax_enabled(void);
 
-#include "qemu/bitops.h"
-#include "exec/memory.h"
-int hax_vcpu_destroy(CPUState *cpu);
-void hax_raise_event(CPUState *cpu);
-void hax_reset_vcpu_state(void *opaque);
-#include "target/i386/hax-interface.h"
-#include "target/i386/hax-i386.h"
-
 #else /* CONFIG_HAX */
 
 #define hax_enabled() (0)
diff --git a/target/i386/hax-all.c b/target/i386/hax-all.c
index fd1ab673d7..fecfe8cd6e 100644
--- a/target/i386/hax-all.c
+++ b/target/i386/hax-all.c
@@ -28,7 +28,6 @@
 #include "exec/address-spaces.h"
 
 #include "qemu-common.h"
-#include "hax-i386.h"
 #include "sysemu/accel.h"
 #include "sysemu/reset.h"
 #include "sysemu/runstate.h"
diff --git a/target/i386/hax-cpus.c b/target/i386/hax-cpus.c
index 9aad98bc7a..99770e590c 100644
--- a/target/i386/hax-cpus.c
+++ b/target/i386/hax-cpus.c
@@ -22,7 +22,6 @@
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
-#include "hax-i386.h"
 #include "sysemu/runstate.h"
 #include "sysemu/cpus.h"
 #include "qemu/guest-random.h"
diff --git a/target/i386/hax-cpus.h b/target/i386/hax-cpus.h
index a64417fe2d..ee8ab7a631 100644
--- a/target/i386/hax-cpus.h
+++ b/target/i386/hax-cpus.h
@@ -14,4 +14,20 @@
 
 extern const CpusAccel hax_cpus;
 
+#include "hax-interface.h"
+#include "hax-i386.h"
+
+int hax_init_vcpu(CPUState *cpu);
+int hax_smp_cpu_exec(CPUState *cpu);
+int hax_populate_ram(uint64_t va, uint64_t size);
+
+void hax_cpu_synchronize_state(CPUState *cpu);
+void hax_cpu_synchronize_post_reset(CPUState *cpu);
+void hax_cpu_synchronize_post_init(CPUState *cpu);
+void hax_cpu_synchronize_pre_loadvm(CPUState *cpu);
+
+int hax_vcpu_destroy(CPUState *cpu);
+void hax_raise_event(CPUState *cpu);
+void hax_reset_vcpu_state(void *opaque);
+
 #endif /* HAX_CPUS_H */
diff --git a/target/i386/hax-mem.c b/target/i386/hax-mem.c
index 6bb5a24917..71e637cf16 100644
--- a/target/i386/hax-mem.c
+++ b/target/i386/hax-mem.c
@@ -13,7 +13,7 @@
 #include "exec/address-spaces.h"
 #include "qemu/error-report.h"
 
-#include "target/i386/hax-i386.h"
+#include "hax-cpus.h"
 #include "qemu/queue.h"
 
 #define DEBUG_HAX_MEM 0
diff --git a/target/i386/hax-posix.c b/target/i386/hax-posix.c
index 6fb7867d11..735a749d4b 100644
--- a/target/i386/hax-posix.c
+++ b/target/i386/hax-posix.c
@@ -14,9 +14,8 @@
 #include "qemu/osdep.h"
 #include 
 
-#include "target/i386/hax-i386.h"
-
 #include "sysemu/cpus.h"
+#include "hax-cpus.h"
 
 hax_fd hax_mod_open(void)
 {
diff --git a/target/i386/hax-windows.c b/target/i386/hax-windows.c
index 469b48e608..6c82dfb54f 100644
--- a/target/i386/hax-windows.c
+++ b/target/i386/hax-windows.c
@@ -12,7 +12,7 @@
 
 #include "qemu/osdep.h"
 #include "cpu.h"
-#include "hax-i386.h"
+#include "hax-cpus.h"
 
 /*
  * return 0 when success, -1 when driver not loaded,
diff --git a/target/i386/hax-windows.h b/target/i386/hax-windows.h
index 12cbd813dc..a5ce12d663 100644
--- a/target/i386/hax-windows.h
+++ b/target/i386/hax-windows.h
@@ -23,6 +23,8 @@
 #include 
 #include 
 
+#include "hax-cpus.h"
+
 #define HAX_INVALID_FD INVALID_HANDLE_VALUE
 
 static inline void hax_mod_close(struct hax_state *hax)
-- 
2.26.2




Re: [PATCH-for-5.2 1/2] hw/core/sysbus: Fix a typo

2020-09-01 Thread Laurent Vivier
Le 06/08/2020 à 15:09, Philippe Mathieu-Daudé a écrit :
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/core/sysbus.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
> index 70239b7e7d..77ab351ce1 100644
> --- a/hw/core/sysbus.c
> +++ b/hw/core/sysbus.c
> @@ -64,7 +64,7 @@ void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc 
> *func, void *opaque)
>  .opaque = opaque,
>  };
>  
> -/* Loop through all sysbus devices that were spawened outside the 
> machine */
> +/* Loop through all sysbus devices that were spawned outside the machine 
> */
>  container = container_get(qdev_get_machine(), "/peripheral");
>  find_sysbus_device(container, &find);
>  container = container_get(qdev_get_machine(), "/peripheral-anon");
> 

Applied to my trivial-patches branch.

Thanks,
Laurent




[PATCH v6 16/16] kvm: remove kvm specific functions from global includes

2020-09-01 Thread Claudio Fontana
Signed-off-by: Claudio Fontana 
Reviewed-by: Richard Henderson 
---
 accel/kvm/kvm-cpus.h   |  7 +++
 accel/stubs/kvm-stub.c | 22 --
 include/sysemu/kvm.h   |  7 ---
 3 files changed, 7 insertions(+), 29 deletions(-)

diff --git a/accel/kvm/kvm-cpus.h b/accel/kvm/kvm-cpus.h
index 547fbee111..60c5a554c2 100644
--- a/accel/kvm/kvm-cpus.h
+++ b/accel/kvm/kvm-cpus.h
@@ -14,4 +14,11 @@
 
 extern const CpusAccel kvm_cpus;
 
+int kvm_init_vcpu(CPUState *cpu);
+int kvm_cpu_exec(CPUState *cpu);
+void kvm_destroy_vcpu(CPUState *cpu);
+void kvm_cpu_synchronize_post_reset(CPUState *cpu);
+void kvm_cpu_synchronize_post_init(CPUState *cpu);
+void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu);
+
 #endif /* KVM_CPUS_H */
diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c
index 69f8a842da..680e099463 100644
--- a/accel/stubs/kvm-stub.c
+++ b/accel/stubs/kvm-stub.c
@@ -32,15 +32,6 @@ bool kvm_readonly_mem_allowed;
 bool kvm_ioeventfd_any_length_allowed;
 bool kvm_msi_use_devid;
 
-void kvm_destroy_vcpu(CPUState *cpu)
-{
-}
-
-int kvm_init_vcpu(CPUState *cpu)
-{
-return -ENOSYS;
-}
-
 void kvm_flush_coalesced_mmio_buffer(void)
 {
 }
@@ -49,19 +40,6 @@ void kvm_cpu_synchronize_state(CPUState *cpu)
 {
 }
 
-void kvm_cpu_synchronize_post_reset(CPUState *cpu)
-{
-}
-
-void kvm_cpu_synchronize_post_init(CPUState *cpu)
-{
-}
-
-int kvm_cpu_exec(CPUState *cpu)
-{
-abort();
-}
-
 bool kvm_has_sync_mmu(void)
 {
 return false;
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index f166aa5260..5de1166a64 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -222,10 +222,6 @@ int kvm_has_many_ioeventfds(void);
 int kvm_has_gsi_routing(void);
 int kvm_has_intx_set_mask(void);
 
-int kvm_init_vcpu(CPUState *cpu);
-int kvm_cpu_exec(CPUState *cpu);
-void kvm_destroy_vcpu(CPUState *cpu);
-
 /**
  * kvm_arm_supports_user_irq
  *
@@ -485,9 +481,6 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void 
*ram_addr,
 #endif /* NEED_CPU_H */
 
 void kvm_cpu_synchronize_state(CPUState *cpu);
-void kvm_cpu_synchronize_post_reset(CPUState *cpu);
-void kvm_cpu_synchronize_post_init(CPUState *cpu);
-void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu);
 
 void kvm_init_cpu_signals(CPUState *cpu);
 
-- 
2.26.2




Re: [PATCH] docs: Fix broken links

2020-09-01 Thread Laurent Vivier
Le 07/08/2020 à 12:17, Han Han a écrit :
> Signed-off-by: Han Han 
> ---
>  docs/amd-memory-encryption.txt | 4 ++--
>  docs/pvrdma.txt| 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/docs/amd-memory-encryption.txt b/docs/amd-memory-encryption.txt
> index 43bf3ee6a5..80b8eb00e9 100644
> --- a/docs/amd-memory-encryption.txt
> +++ b/docs/amd-memory-encryption.txt
> @@ -95,10 +95,10 @@ References
>  -
>  
>  AMD Memory Encryption whitepaper:
> -http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/12/AMD_Memory_Encryption_Whitepaper_v7-Public.pdf
> +https://developer.amd.com/wordpress/media/2013/12/AMD_Memory_Encryption_Whitepaper_v7-Public.pdf
>  
>  Secure Encrypted Virtualization Key Management:
> -[1] http://support.amd.com/TechDocs/55766_SEV-KM API_Specification.pdf
> +[1] 
> http://developer.amd.com/wordpress/media/2017/11/55766_SEV-KM-API_Specification.pdf
>  
>  KVM Forum slides:
>  
> http://www.linux-kvm.org/images/7/74/02x08A-Thomas_Lendacky-AMDs_Virtualizatoin_Memory_Encryption_Technology.pdf
> diff --git a/docs/pvrdma.txt b/docs/pvrdma.txt
> index 0f0dd8a7e5..5c122fe818 100644
> --- a/docs/pvrdma.txt
> +++ b/docs/pvrdma.txt
> @@ -18,7 +18,7 @@ over-commit and, even if not implemented yet, migration 
> support will be
>  possible with some HW assistance.
>  
>  A project presentation accompany this document:
> -- 
> http://events.linuxfoundation.org/sites/events/files/slides/lpc-2017-pvrdma-marcel-apfelbaum-yuval-shaia.pdf
> +- 
> https://blog.linuxplumbersconf.org/2017/ocw/system/presentations/4730/original/lpc-2017-pvrdma-marcel-apfelbaum-yuval-shaia.pdf
>  
>  
>  
> 

Applied to my trivial-patches branch.

Thanks,
Laurent




Re: [PATCH-for-5.2] Revert "mailmap: Update philmd email address"

2020-09-01 Thread Laurent Vivier
Le 06/08/2020 à 15:58, Philippe Mathieu-Daudé a écrit :
> This mailmap entry does not work as I expected. I am receiving
> emails related to my hobbyist contributions in my work mailbox
> and I get distracted :) Remove the entry to keep things separated.
> 
> This reverts commit 289371239153b24cb7bd96b6948c6b40b4627a9b.
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  .mailmap | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/.mailmap b/.mailmap
> index 81c2ce0937..2d97a14af3 100644
> --- a/.mailmap
> +++ b/.mailmap
> @@ -54,7 +54,6 @@ Radoslaw Biernacki  
> 
>  Paul Burton  
>  Paul Burton  
>  Paul Burton  
> -Philippe Mathieu-Daudé  
>  Stefan Brankovic  
> 
>  Yongbok Kim  
>  
> 

Applied to my trivial-patches branch.

Thanks,
Laurent




Re: [kvm-unit-tests RFC 4/4] spe: Test Profiling Buffer Events

2020-09-01 Thread Auger Eric
Hi,

On 8/31/20 9:34 PM, Eric Auger wrote:
> Setup the infrastructure to check the occurence of events.
> The test checks the Buffer Full event occurs when no space
> is available. The PPI is handled and we check the syndrome register
> against the expected event.
> 
> Signed-off-by: Eric Auger 
> ---
>  arm/spe.c | 141 +-
>  arm/unittests.cfg |   8 +++
>  2 files changed, 148 insertions(+), 1 deletion(-)
> 
> diff --git a/arm/spe.c b/arm/spe.c
> index 7996f79..2f5ee35 100644
> --- a/arm/spe.c
> +++ b/arm/spe.c
> @@ -19,6 +19,7 @@
>  #include "alloc_page.h"
>  #include 
>  #include "alloc.h"
> +#include 
>  
>  struct spe {
>   int min_interval;
> @@ -36,13 +37,37 @@ struct spe {
>   bool unique_record_size;
>  };
>  
> +enum spe_event_exception_class {
> + EC_STAGE1_DATA_ABORT =  0x24,
> + EC_STAGE2_DATA_ABORT = 0x25,
> + EC_OTHER = 0,
> +};
> +
> +struct spe_event {
> + enum spe_event_exception_class ec;
> + bool dl;/* data lost */
> + bool ea;/* external abort */
> + bool s; /* service */
> + bool coll;  /* collision */
> + union {
> + bool buffer_filled; /* ec = other */
> + } mss;
> +};
> +
>  static struct spe spe;
>  
> +struct spe_stats {
> + struct spe_event observed;
> + bool unexpected;
> +};
> +static struct spe_stats spe_stats;
> +
>  #ifdef __arm__
>  
>  static bool spe_probe(void) { return false; }
>  static void test_spe_introspection(void) { }
>  static void test_spe_buffer(void) { }
> +static void test_spe_events(void) { }
>  
>  #else
>  
> @@ -95,6 +120,16 @@ static void test_spe_buffer(void) { }
>  #define PMSCR_EL1_TS 0x20
>  #define PMSCR_EL1_PCT0x40
>  
> +#define PMBSR_EL1_COLL   0x1
> +#define PMBSR_EL1_S  0x2
> +#define PMBSR_EL1_EA 0x4
> +#define PMBSR_EL1_DL 0x8
> +#define PMBSR_EL1_EC_SHIFT   26
> +#define PMBSR_EL1_EC_MASK0x3F
> +#define PMBSR_EL1_MISS_MASK  0x
> +
> +#define SPE_PPI 21
> +
>  static int min_interval(uint8_t idr_bits)
>  {
>   switch (idr_bits) {
> @@ -119,6 +154,44 @@ static int min_interval(uint8_t idr_bits)
>   }
>  }
>  
> +static int decode_syndrome_register(uint64_t sr, struct spe_event *event, 
> bool verbose)
> +{
> + if (!sr)
> + return 0;
> +
> + if (sr & PMBSR_EL1_S)
> + event->s = true;
> + if (sr & PMBSR_EL1_COLL)
> + event->coll = true;
> + if (sr & PMBSR_EL1_EA)
> + event->ea = true;
> + if (sr & PMBSR_EL1_DL)
> + event->dl = true;
> + if (verbose)
> + report_info("PMBSR_EL1: Service=%d Collision=%d External 
> Fault=%d DataLost=%d",
> + event->s, event->coll, event->ea, event->dl);
> +
> + switch ((sr >> PMBSR_EL1_EC_SHIFT) & PMBSR_EL1_EC_MASK) {
> + case EC_OTHER:
> + event->ec = EC_OTHER;
> + event->mss.buffer_filled = sr & 0x1;
> + if (verbose)
> + report_info("PMBSR_EL1: EC = OTHER buffer filled=%d", 
> event->mss.buffer_filled);
> + break;
> + case EC_STAGE1_DATA_ABORT:
> + event->ec = EC_STAGE1_DATA_ABORT;
> + report_info("PMBSR_EL1: EC = stage 1 data abort");
> + break;
> + case EC_STAGE2_DATA_ABORT:
> + event->ec = EC_STAGE2_DATA_ABORT;
> + report_info("PMBSR_EL1: EC = stage 2 data abort");
> + break;
> + default:
> + return -1;
> + }
> + return 0;
> +}
> +
>  static bool spe_probe(void)
>  {
>   uint64_t pmbidr_el1, pmsidr_el1;
> @@ -224,6 +297,13 @@ static void reset(void)
>  
>   /* Make sure the syndrome register is void */
>   write_sysreg_s(0, PMBSR_EL1);
> +
> + memset(&spe_stats, 0, sizeof(spe_stats));
> +}
> +
> +inline bool event_match(struct spe_event *observed, struct spe_event 
> *expected)
> +{
> + return !memcmp(observed, expected, sizeof(struct spe_event));
>  }
>  
>  static inline void drain(void)
> @@ -235,6 +315,7 @@ static inline void drain(void)
>  
>  static void test_spe_buffer(void)
>  {
> + struct spe_event observed = {}, expected = {};
>   uint64_t pmbsr_el1, val1, val2;
>   void *addr = malloc(10 * PAGE_SIZE);
>  
> @@ -290,7 +371,61 @@ static void test_spe_buffer(void)
>   report_info("This corresponds to %ld record(s) of %d bytes",
>   val2 / spe.maxsize, spe.maxsize);
>   pmbsr_el1 = read_sysreg_s(PMBSR_EL1);
> - report(!pmbsr_el1, "PMBSR_EL1: no event");
> + report(!(decode_syndrome_register(pmbsr_el1, &observed, true)) &&
> +event_match(&observed, &expected), "PMBSR_EL1: no event");
> +
> + free(addr);
> +}
> +
> +static void irq_handler(struct pt_regs *regs)
> +{
> + uint32_t irqstat, irqnr;
> +
> +

RE: [PATCH v4 5/7] misc: Add versal-usb2-regs module

2020-09-01 Thread Sai Pavan Boddu
Hi Gred,

> -Original Message-
> From: Gerd Hoffmann 
> Sent: Monday, August 31, 2020 12:33 PM
> To: Sai Pavan Boddu 
> Cc: Peter Maydell ; Markus Armbruster
> ; 'Marc-André Lureau'
> ; Paolo Bonzini ;
> Edgar Iglesias ; Francisco Eduardo Iglesias
> ; qemu-devel@nongnu.org; Alistair Francis
> ; Eduardo Habkost ;
> Ying Fang ; 'Philippe Mathieu-Daudé'
> ; Vikram Garhwal ; Paul
> Zimmerman 
> Subject: Re: [PATCH v4 5/7] misc: Add versal-usb2-regs module
> 
> On Sat, Aug 29, 2020 at 12:49:38AM +0530, Sai Pavan Boddu wrote:
> > This is a dummy module to emulate control registers of versal usb2
> > controller.
> 
> --verbose please.  xhci supports all usb speeds, including usb2.
[Sai Pavan Boddu] This module is has soc specific control/status register to 
control the phy-reset, adjust frame length time  and coherency properties for 
the transactions.

> 
> So why this hardware is here, what does it on a real device and what is the
> emulation doing?  "dummy" sounds like it does just enough to make the
> guest driver happy, probably pretending nothing is connected?
Yes, this is added to make guest happy.

I will the commit message with more info

Regards,
Sai Pavan
> 
> thanks,
>   Gerd




Re: [PATCH] cirrus: handle wraparound in cirrus_invalidate_region

2020-09-01 Thread Li Qiang
Gerd Hoffmann  于2020年9月1日周二 下午3:16写道:
>
>   Hi,
>
> > +/* wraparound */
> > +memory_region_set_dirty(&s->vga.vram, off_cur,
> > s->cirrus_addr_mask - off_cur);
>
> > So the len is 's->cirrus_addr_mask->off_cur+1'.
>
> Correct.

So do you agree me the first set size should be 's->cirrus_addr_mask -
off_cur+1'?



>
> > +memory_region_set_dirty(&s->vga.vram, 0, off_cur_end);
> >
> > For the 'off_cur_end' here, why we add 1 at the first?:
> >
> > "off_cur_end = ((off_cur + bytesperline - 1) & s->cirrus_addr_mask) + 1;"
>  
> > This addition '1' is what I think should be substracted in wrapped cases.
>
> The +1 balances the -1 done before ...

Then the second set size is ok.

Thanks,
Li Qiang

>
> take care,
>   Gerd
>



[Bug 1893744] [NEW] meson: incomplete 'make help'

2020-09-01 Thread Philippe Mathieu-Daudé
Public bug reported:

Since the meson switch, 'make help' doesn't list various targets.

Diff before/after:

---
 Generic targets:
   all- Build all
   dir/file.o - Build specified target only
   install- Install QEMU
   ctags/TAGS - Generate tags file for editors
   cscope - Generate cscope index
-
-Architecture specific targets:
-  aarch64-softmmu/all- Build for aarch64-softmmu
-  alpha-softmmu/all  - Build for alpha-softmmu
-  arm-softmmu/all- Build for arm-softmmu
-  avr-softmmu/all- Build for avr-softmmu
-  cris-softmmu/all   - Build for cris-softmmu
-  hppa-softmmu/all   - Build for hppa-softmmu
-  i386-softmmu/all   - Build for i386-softmmu
-  lm32-softmmu/all   - Build for lm32-softmmu
-  m68k-softmmu/all   - Build for m68k-softmmu
-  microblazeel-softmmu/all   - Build for microblazeel-softmmu
-  microblaze-softmmu/all - Build for microblaze-softmmu
-  mips64el-softmmu/all   - Build for mips64el-softmmu
-  mips64-softmmu/all - Build for mips64-softmmu
-  mipsel-softmmu/all - Build for mipsel-softmmu
-  mips-softmmu/all   - Build for mips-softmmu
-  moxie-softmmu/all  - Build for moxie-softmmu
-  nios2-softmmu/all  - Build for nios2-softmmu
-  or1k-softmmu/all   - Build for or1k-softmmu
-  ppc64-softmmu/all  - Build for ppc64-softmmu
-  ppc-softmmu/all- Build for ppc-softmmu
-  riscv32-softmmu/all- Build for riscv32-softmmu
-  riscv64-softmmu/all- Build for riscv64-softmmu
-  rx-softmmu/all - Build for rx-softmmu
-  s390x-softmmu/all  - Build for s390x-softmmu
-  sh4eb-softmmu/all  - Build for sh4eb-softmmu
-  sh4-softmmu/all- Build for sh4-softmmu
-  sparc64-softmmu/all- Build for sparc64-softmmu
-  sparc-softmmu/all  - Build for sparc-softmmu
-  tricore-softmmu/all- Build for tricore-softmmu
-  unicore32-softmmu/all  - Build for unicore32-softmmu
-  x86_64-softmmu/all - Build for x86_64-softmmu
-  xtensaeb-softmmu/all   - Build for xtensaeb-softmmu
-  xtensa-softmmu/all - Build for xtensa-softmmu
-  aarch64_be-linux-user/all  - Build for aarch64_be-linux-user
-  aarch64-linux-user/all - Build for aarch64-linux-user
-  alpha-linux-user/all   - Build for alpha-linux-user
-  armeb-linux-user/all   - Build for armeb-linux-user
-  arm-linux-user/all - Build for arm-linux-user
-  cris-linux-user/all- Build for cris-linux-user
-  hppa-linux-user/all- Build for hppa-linux-user
-  i386-linux-user/all- Build for i386-linux-user
-  m68k-linux-user/all- Build for m68k-linux-user
-  microblazeel-linux-user/all- Build for microblazeel-linux-user
-  microblaze-linux-user/all  - Build for microblaze-linux-user
-  mips64el-linux-user/all- Build for mips64el-linux-user
-  mips64-linux-user/all  - Build for mips64-linux-user
-  mipsel-linux-user/all  - Build for mipsel-linux-user
-  mips-linux-user/all- Build for mips-linux-user
-  mipsn32el-linux-user/all   - Build for mipsn32el-linux-user
-  mipsn32-linux-user/all - Build for mipsn32-linux-user
-  nios2-linux-user/all   - Build for nios2-linux-user
-  or1k-linux-user/all- Build for or1k-linux-user
-  ppc64abi32-linux-user/all  - Build for ppc64abi32-linux-user
-  ppc64le-linux-user/all - Build for ppc64le-linux-user
-  ppc64-linux-user/all   - Build for ppc64-linux-user
-  ppc-linux-user/all - Build for ppc-linux-user
-  riscv32-linux-user/all - Build for riscv32-linux-user
-  riscv64-linux-user/all - Build for riscv64-linux-user
-  s390x-linux-user/all   - Build for s390x-linux-user
-  sh4eb-linux-user/all   - Build for sh4eb-linux-user
-  sh4-linux-user/all - Build for sh4-linux-user
-  sparc32plus-linux-user/all - Build for sparc32plus-linux-user
-  sparc64-linux-user/all - Build for sparc64-linux-user
-  sparc-linux-user/all   - Build for sparc-linux-user
-  tilegx-linux-user/all  - Build for tilegx-linux-user
-  x86_64-linux-user/all  - Build for x86_64-linux-user
-  xtensaeb-linux-user/all- Build for xtensaeb-linux-user
-  xtensa-linux-user/all  - Build for xtensa-linux-user
-
-Helper targets:
-  fsdev/virtfs-proxy-helper  - Build virtfs-proxy-helper
-  scsi/qemu-pr-helper- Build qemu-pr-helper
-  qemu-bridge-helper - Build qemu-bridge-helper
-  vhost-user-gpu - Build vhost-user-gpu
-  virtiofsd  - Build virtio

Re: [PATCH v2 2/7] vhost: check queue state in the vhost_dev_set_log routine

2020-09-01 Thread Dima Stepanov
On Mon, Aug 31, 2020 at 11:22:14PM -0400, Raphael Norwitz wrote:
> On Mon, Aug 31, 2020 at 4:37 AM Dima Stepanov  wrote:
> >
> > On Thu, Aug 27, 2020 at 09:46:03PM -0400, Raphael Norwitz wrote:
> > > On Mon, Aug 24, 2020 at 4:41 AM Dima Stepanov  
> > > wrote:
> > > >
> > > > If the vhost-user-blk daemon provides only one virtqueue, but device was
> > > > added with several queues, then QEMU will send more VHOST-USER command
> > > > than expected by daemon side. The vhost_virtqueue_start() routine
> > > > handles such case by checking the return value from the
> > > > virtio_queue_get_desc_addr() function call. Add the same check to the
> > > > vhost_dev_set_log() routine.
> > > >
> > > > Signed-off-by: Dima Stepanov 
> > > > ---
> > > >  hw/virtio/vhost.c | 12 
> > > >  1 file changed, 12 insertions(+)
> > > >
> > > > diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> > > > index ffef7ab..a33ffd4 100644
> > > > --- a/hw/virtio/vhost.c
> > > > +++ b/hw/virtio/vhost.c
> > > > @@ -825,12 +825,24 @@ static int vhost_dev_set_features(struct 
> > > > vhost_dev *dev,
> > > >  static int vhost_dev_set_log(struct vhost_dev *dev, bool enable_log)
> > > >  {
> > > >  int r, i, idx;
> > > > +hwaddr addr;
> > > > +
> > > >  r = vhost_dev_set_features(dev, enable_log);
> > > >  if (r < 0) {
> > > >  goto err_features;
> > > >  }
> > > >  for (i = 0; i < dev->nvqs; ++i) {
> > > >  idx = dev->vhost_ops->vhost_get_vq_index(dev, dev->vq_index + 
> > > > i);
> > > > +addr = virtio_queue_get_desc_addr(dev->vdev, idx);
> > > > +if (!addr) {
> > > > +/*
> > > > + * The queue might not be ready for start. If this
> > > > + * is the case there is no reason to continue the process.
> > > > + * The similar logic is used by the vhost_virtqueue_start()
> > > > + * routine.
> > > > + */
> > >
> > > Shouldn’t we goto err_vq here to reset the logging state of any vqs
> > > which have already been set?
> > As i understand it, no we shouldn't reset the state of other queues. In
> > general it is pretty valid case. Let's assume that the backend
> > vhost-user device supports only two queues. But for instance, the QEMU
> > command line is using value 4 to define number of virtqueues of such
> > device. In this case only 2 queues will be initializaed.
> 
> I see - makes more sense now.
> 
> >
> > I've tried to reflect it in the comment section, that the
> > vhost_virtqueue_start() routine has been alread made the same:
> >   "if a queue isn't ready for start, just return 0 without any error"
> > So i made the same here.
> >
> 
> In your example is a reason why, if queue 3 is uninitialized, queue 4
> must also be uninitialized? I realize queue 4 being initialized while
> queue 3 is not is a strange case, but it may still make the code more
> robust to use a "continue" here instead of a "break". This also seems
> more like the logic in vhost_virtqueue_start()/vhost_dev_start().
Good point! Should really use "continue" instead of a "break" to keep
the logic. Will update it in v4. Hope to get some review feedback for
the qtest framework update aswell ).

> 
> > I've found this issue, while testing migration with the default
> > vhost-user-blk daemon. It fails with assert or sigsegv (don't remember),
> > because it receives NULL for the queues it doesn't have. In general
> > the daemon should not fall, because of unexpected VHOST_USER
> > communication, but also there is no reason for QEMU to send additional
> > packets.
> >
> > >
> > > > +break;
> > > > +}
> > > >  r = vhost_virtqueue_set_addr(dev, dev->vqs + i, idx,
> > > >   enable_log);
> > > >  if (r < 0) {
> > > > --
> > > > 2.7.4
> > > >
> > > >



Re: [PATCH] cirrus.yml: Split FreeBSD job into two parts

2020-09-01 Thread Daniel P . Berrangé
On Mon, Aug 31, 2020 at 05:44:05PM +0200, Thomas Huth wrote:
> The FreeBSD jobs currently hit the 1h time limit in the Cirrus-CI.
> We have to split the build targets here to make sure that the job
> finishes in time again. According to the Cirrus-CI docs and some
> tests that I did, it also seems like the total amount of CPUs that
> can be used for FreeBSD jobs is limited to 8, so each job now only
> gets 4 CPUs. That increases the compilation time of each job a little
> bit, but it still seems to be better to run two jobs with 4 CPUs each
> in parallel than to run two jobs with 8 CPUs sequentially.
> 
> Signed-off-by: Thomas Huth 
> ---
>  .cirrus.yml | 32 ++--
>  1 file changed, 26 insertions(+), 6 deletions(-)

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 :|




Re: [PATCH] configure: remove dead code for in-tree builds

2020-09-01 Thread Daniel P . Berrangé
On Tue, Sep 01, 2020 at 03:24:06AM -0400, Paolo Bonzini wrote:
> The $pwd_is_source_path variable is never "y", since
> configure re-executes itself from a build directory.
> Remove code that will never run.
> 
> Cc: Daniel P. Berrangé 
> Signed-off-by: Paolo Bonzini 
> ---
>  configure | 14 ++
>  1 file changed, 2 insertions(+), 12 deletions(-)

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 :|




Re: [PATCH v2] .mailmap: Update Paul Burton email address

2020-09-01 Thread Laurent Vivier
Le 07/07/2020 à 04:25, Philippe Mathieu-Daudé a écrit :
> Following the Linux kernel equivalent patch posted on
> linux-m...@vger.kernel.org [*], update Paul Burton email
> address to avoid emails bouncing.
> 
> [*] 'MAINTAINERS: Use @kernel.org address for Paul Burton'
> https://lore.kernel.org/patchwork/patch/1140341/
> 
> Cc: Paul Burton 
> Suggested-by: Paolo Bonzini 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  .mailmap | 7 ---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/.mailmap b/.mailmap
> index 926cac6bb8..fe4c561338 100644
> --- a/.mailmap
> +++ b/.mailmap
> @@ -49,9 +49,10 @@ Filip Bozuta  
> 
>  Frederic Konrad  
>  James Hogan  
>  Leif Lindholm  
> -Paul Burton  
> -Paul Burton  
> -Paul Burton  
> +Paul Burton  
> +Paul Burton  
> +Paul Burton  
> +Paul Burton  
>  Philippe Mathieu-Daudé  
>  Stefan Brankovic  
> 
>  Yongbok Kim  
> 

Applied to my trivial-patches branch.

Thanks,
Laurent




Re: [PATCH-for-5.2 0/3] trivial: Remove 'and and' in descriptions

2020-09-01 Thread Laurent Vivier
Le 11/08/2020 à 17:16, Philippe Mathieu-Daudé a écrit :
> Remove duplicated 'and' in comments.
> 
> Philippe Mathieu-Daudé (3):
>   hw/i2c: Fix typo in description
>   util/qemu-timer: Fix typo in description
>   util/vfio-helpers: Fix typo in description
> 
>  include/hw/i2c/i2c.h | 2 +-
>  util/qemu-timer.c| 2 +-
>  util/vfio-helpers.c  | 4 ++--
>  3 files changed, 4 insertions(+), 4 deletions(-)
> 

Applied to my trivial-patches branch.

Thanks,
Laurent



[PULL 00/24] Meson changes for 2020-09-01

2020-09-01 Thread Paolo Bonzini
The following changes since commit 2f4c51c0f384d7888a04b4815861e6d5fd244d75:

  Merge remote-tracking branch 'remotes/kraxel/tags/usb-20200831-pull-request' 
into staging (2020-08-31 19:39:13 +0100)

are available in the Git repository at:

  https://gitlab.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to 703230593ffda7699ae81811967b4d2c76a425c1:

  meson: add description to options (2020-09-01 03:10:36 -0400)


meson fixes:
* bump submodule to 0.55.1
* SDL, pixman and zlib fixes
* firmwarepath fix
* fix firmware builds

meson related:
* move install to Meson
* move NSIS to Meson
* do not make meson use cmake
* add description to options


Marc-André Lureau (14):
  meson: install pc-bios blobs
  meson: install scripts/qemu-trace-stap
  meson: install icons
  meson: install desktop file
  meson: install $localstatedir/run for qga
  build-sys: remove install target from Makefile
  configure: rename confsuffix option
  configure: always /-seperate directory from qemu_suffix
  configure: build docdir like other suffixed directories
  meson: pass qemu_suffix option
  meson: use meson datadir instead of qemu_datadir
  meson: pass docdir option
  meson: use meson mandir instead of qemu_mandir
  meson: add NSIS building

Paolo Bonzini (8):
  meson: bump submodule to 0.55.1
  block: always link with zlib
  meson: move zlib detection to meson
  meson: add pixman dependency to UI modules
  configure: do not include ${prefix} in firmwarepath
  meson: use pkg-config method to find dependencies
  build: fix recurse-all target
  meson: add description to options

Stefan Weil (1):
  meson: add pixman dependency to chardev/baum module

Volker Rümelin (1):
  meson: fix SDL2_image detection

 Makefile   | 122 +
 block/meson.build  |   4 +-
 chardev/meson.build|   2 +-
 configure  |  65 ++--
 contrib/vhost-user-gpu/meson.build |   2 +-
 docs/devel/build-system.rst|  27 
 docs/meson.build   |   4 +-
 meson  |   2 +-
 meson.build|  53 +++-
 meson_options.txt  |  33 +++---
 pc-bios/descriptors/meson.build|   2 +-
 pc-bios/keymaps/meson.build|   6 +-
 pc-bios/meson.build|  65 +++-
 pc-bios/optionrom/Makefile |  10 +--
 pc-bios/s390-ccw/Makefile  |   3 +-
 qga/meson.build|   2 +
 scripts/meson.build|   3 +
 scripts/nsis.py|  78 
 tools/virtiofsd/meson.build|   2 +-
 trace/meson.build  |   2 +-
 ui/icons/meson.build   |  13 
 ui/meson.build |   9 ++-
 22 files changed, 281 insertions(+), 228 deletions(-)
 create mode 100644 scripts/meson.build
 create mode 100644 scripts/nsis.py
 create mode 100644 ui/icons/meson.build
-- 
2.26.2




[PULL 09/24] build-sys: remove install target from Makefile

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

Now covered by meson

Signed-off-by: Marc-André Lureau 
Message-Id: <20200826130622.553318-7-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 Makefile | 5 -
 1 file changed, 5 deletions(-)

diff --git a/Makefile b/Makefile
index 9a9e7c0301..75db8be52e 100644
--- a/Makefile
+++ b/Makefile
@@ -229,13 +229,8 @@ distclean: clean ninja-distclean
rm -f linux-headers/asm
rm -Rf .sdk
 
-install-datadir:
-   $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)"
-
 # Needed by "meson install"
 export DESTDIR
-install: all install-datadir
-   $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps"
 
 ifdef CONFIG_WIN32
 
-- 
2.26.2





[PULL 01/24] meson: bump submodule to 0.55.1

2020-09-01 Thread Paolo Bonzini
This version includes an important bugfix to avoid including unnecessary
-Wl,-rpath flags.  It also avoids the warnings on custom_targets with
more than one output.

Reported-by: Laurent Vivier 
Reviewed-by: Laurent Vivier 
Tested-by: Laurent Vivier 
Signed-off-by: Paolo Bonzini 
---
 configure | 2 +-
 meson | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 8dc981684b..f81900880a 100755
--- a/configure
+++ b/configure
@@ -2023,7 +2023,7 @@ python_version=$($python -c 'import sys; print("%d.%d.%d" 
% (sys.version_info[0]
 python="$python -B"
 
 if test -z "$meson"; then
-if test "$explicit_python" = no && has meson && version_ge "$(meson 
--version)" 0.55.0; then
+if test "$explicit_python" = no && has meson && version_ge "$(meson 
--version)" 0.55.1; then
 meson=meson
 elif test -e "${source_path}/.git" && test $git_update = 'yes' ; then
 meson=git
diff --git a/meson b/meson
index d0c68dc115..68ed748f84 16
--- a/meson
+++ b/meson
@@ -1 +1 @@
-Subproject commit d0c68dc11507a47b9b85de508e023d9590d60565
+Subproject commit 68ed748f84f14c2d4e62dcbd123816e5898eb04c
-- 
2.26.2





[PULL 03/24] meson: fix SDL2_image detection

2020-09-01 Thread Paolo Bonzini
From: Volker Rümelin 

Configure used to probe for SDL2_image in sdl_image_probe (). Meson
should do the same.

This fixes the following error on my system:

Run-time dependency sdl2 found: YES 2.0.8
Found CMake: /usr/bin/cmake (3.17.0)
Run-time dependency sdl-image found: NO (tried pkgconfig and cmake)

../qemu-master/meson.build:256:2: ERROR: Dependency "sdl-image" not
found, tried pkgconfig and cmake

A full log can be found at /home/ruemelin/rpmbuild/BUILD
/qemu-5.1.50-build/meson-logs/meson-log.txt

ERROR: meson setup failed

Signed-off-by: Volker Rümelin 
Message-Id: <20200829104158.7461-1-vr_q...@t-online.de>
Signed-off-by: Paolo Bonzini 
---
 meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 1e7aee85e3..3c919e32f1 100644
--- a/meson.build
+++ b/meson.build
@@ -248,7 +248,7 @@ if sdl.found()
   # work around 2.0.8 bug
   sdl = declare_dependency(compile_args: '-Wno-undef',
dependencies: sdl)
-  sdl_image = dependency('sdl-image', required: get_option('sdl_image'),
+  sdl_image = dependency('SDL2_image', required: get_option('sdl_image'),
  static: enable_static)
 else
   if get_option('sdl_image').enabled()
-- 
2.26.2





[PULL 02/24] block: always link with zlib

2020-09-01 Thread Paolo Bonzini
The qcow2 driver needs the zlib dependency.  While emulators
provided it through the migration code, this is not true of
the tools.  Move the dependency from the qcow1 rule directly
into block_ss so that it is included unconditionally.

Fixes build with --disable-qcow1.

Reported-by: Thomas Huth 
Reviewed-by: Thomas Huth 
Cc: qemu-bl...@nongnu.org
Signed-off-by: Paolo Bonzini 
---
 block/meson.build | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/meson.build b/block/meson.build
index 4dbbfe60b4..a3e56b7cd1 100644
--- a/block/meson.build
+++ b/block/meson.build
@@ -40,9 +40,9 @@ block_ss.add(files(
   'vmdk.c',
   'vpc.c',
   'write-threshold.c',
-), zstd)
+), zstd, zlib)
 
-block_ss.add(when: [zlib, 'CONFIG_QCOW1'], if_true: files('qcow.c'))
+block_ss.add(when: 'CONFIG_QCOW1', if_true: files('qcow.c'))
 block_ss.add(when: 'CONFIG_VDI', if_true: files('vdi.c'))
 block_ss.add(when: 'CONFIG_CLOOP', if_true: files('cloop.c'))
 block_ss.add(when: 'CONFIG_BOCHS', if_true: files('bochs.c'))
-- 
2.26.2





[PULL 06/24] meson: install icons

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Message-Id: <20200826130622.553318-4-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 Makefile | 12 
 ui/icons/meson.build | 13 +
 ui/meson.build   |  1 +
 3 files changed, 14 insertions(+), 12 deletions(-)
 create mode 100644 ui/icons/meson.build

diff --git a/Makefile b/Makefile
index 058cf87f54..d1a3cd77a5 100644
--- a/Makefile
+++ b/Makefile
@@ -239,22 +239,10 @@ ifeq ($(CONFIG_GUEST_AGENT),y)
 endif
 endif
 
-ICON_SIZES=16x16 24x24 32x32 48x48 64x64 128x128 256x256 512x512
 
 # Needed by "meson install"
 export DESTDIR
 install: all install-datadir install-localstatedir
-   for s in $(ICON_SIZES); do \
-   mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/$${s}/apps"; \
-   $(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu_$${s}.png \
-   
"$(DESTDIR)$(qemu_icondir)/hicolor/$${s}/apps/qemu.png"; \
-   done; \
-   mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/32x32/apps"; \
-   $(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu_32x32.bmp \
-   "$(DESTDIR)$(qemu_icondir)/hicolor/32x32/apps/qemu.bmp"; \
-   mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/scalable/apps"; \
-   $(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu.svg \
-   "$(DESTDIR)$(qemu_icondir)/hicolor/scalable/apps/qemu.svg"
mkdir -p "$(DESTDIR)$(qemu_desktopdir)"
$(INSTALL_DATA) $(SRC_PATH)/ui/qemu.desktop \
"$(DESTDIR)$(qemu_desktopdir)/qemu.desktop"
diff --git a/ui/icons/meson.build b/ui/icons/meson.build
new file mode 100644
index 00..b6e21f6ad7
--- /dev/null
+++ b/ui/icons/meson.build
@@ -0,0 +1,13 @@
+foreach s: [16, 24, 32, 48, 64, 128, 256, 512]
+  s = '@0@x@0@'.format(s.to_string())
+  install_data('qemu_@0@.png'.format(s),
+   rename: 'qemu.png',
+   install_dir: config_host['qemu_icondir'] / 'hicolor' / s / 
'apps')
+endforeach
+
+install_data('qemu_32x32.bmp',
+ rename: 'qemu.bmp',
+ install_dir: config_host['qemu_icondir'] / 'hicolor' / '32x32' / 
'apps')
+
+install_data('qemu.svg',
+ install_dir: config_host['qemu_icondir'] / 'hicolor' / 'scalable' 
/ 'apps')
diff --git a/ui/meson.build b/ui/meson.build
index 962e776569..dddffc9a7a 100644
--- a/ui/meson.build
+++ b/ui/meson.build
@@ -112,5 +112,6 @@ if have_system or xkbcommon.found()
 endif
 
 subdir('shader')
+subdir('icons')
 
 modules += {'ui': ui_modules}
-- 
2.26.2





[PULL 08/24] meson: install $localstatedir/run for qga

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Message-Id: <20200826130622.553318-6-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 Makefile| 10 +-
 qga/meson.build |  2 ++
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile
index dc3c20dd5e..9a9e7c0301 100644
--- a/Makefile
+++ b/Makefile
@@ -232,17 +232,9 @@ distclean: clean ninja-distclean
 install-datadir:
$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)"
 
-install-localstatedir:
-ifdef CONFIG_POSIX
-ifeq ($(CONFIG_GUEST_AGENT),y)
-   $(INSTALL_DIR) "$(DESTDIR)$(qemu_localstatedir)"/run
-endif
-endif
-
-
 # Needed by "meson install"
 export DESTDIR
-install: all install-datadir install-localstatedir
+install: all install-datadir
$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps"
 
 ifdef CONFIG_WIN32
diff --git a/qga/meson.build b/qga/meson.build
index 3f28f74b52..e5c5778a3e 100644
--- a/qga/meson.build
+++ b/qga/meson.build
@@ -82,6 +82,8 @@ if targetos == 'windows'
 all_qga += [qga_msi]
 alias_target('msi', qga_msi)
   endif
+else
+  install_subdir('run', install_dir: get_option('localstatedir'))
 endif
 
 alias_target('qemu-ga', all_qga)
-- 
2.26.2





[PULL 05/24] meson: install scripts/qemu-trace-stap

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Message-Id: <20200826130622.553318-3-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 Makefile| 3 ---
 meson.build | 1 +
 scripts/meson.build | 3 +++
 3 files changed, 4 insertions(+), 3 deletions(-)
 create mode 100644 scripts/meson.build

diff --git a/Makefile b/Makefile
index 16b2ffa7fe..058cf87f54 100644
--- a/Makefile
+++ b/Makefile
@@ -244,9 +244,6 @@ ICON_SIZES=16x16 24x24 32x32 48x48 64x64 128x128 256x256 
512x512
 # Needed by "meson install"
 export DESTDIR
 install: all install-datadir install-localstatedir
-ifdef CONFIG_TRACE_SYSTEMTAP
-   $(INSTALL_PROG) "scripts/qemu-trace-stap" $(DESTDIR)$(bindir)
-endif
for s in $(ICON_SIZES); do \
mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/$${s}/apps"; \
$(INSTALL_DATA) $(SRC_PATH)/ui/icons/qemu_$${s}.png \
diff --git a/meson.build b/meson.build
index 3c919e32f1..6b2fc76933 100644
--- a/meson.build
+++ b/meson.build
@@ -1138,6 +1138,7 @@ if have_tools
   endif
 endif
 
+subdir('scripts')
 subdir('tools')
 subdir('pc-bios')
 subdir('tests')
diff --git a/scripts/meson.build b/scripts/meson.build
new file mode 100644
index 00..e8cc63896d
--- /dev/null
+++ b/scripts/meson.build
@@ -0,0 +1,3 @@
+if 'CONFIG_TRACE_SYSTEMTAP' in config_host
+  install_data('qemu-trace-stap', install_dir: get_option('bindir'))
+endif
-- 
2.26.2





[PULL 07/24] meson: install desktop file

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Message-Id: <20200826130622.553318-5-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 Makefile   | 3 ---
 ui/meson.build | 2 ++
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index d1a3cd77a5..dc3c20dd5e 100644
--- a/Makefile
+++ b/Makefile
@@ -243,9 +243,6 @@ endif
 # Needed by "meson install"
 export DESTDIR
 install: all install-datadir install-localstatedir
-   mkdir -p "$(DESTDIR)$(qemu_desktopdir)"
-   $(INSTALL_DATA) $(SRC_PATH)/ui/qemu.desktop \
-   "$(DESTDIR)$(qemu_desktopdir)/qemu.desktop"
$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps"
 
 ifdef CONFIG_WIN32
diff --git a/ui/meson.build b/ui/meson.build
index dddffc9a7a..aa8aa31516 100644
--- a/ui/meson.build
+++ b/ui/meson.build
@@ -114,4 +114,6 @@ endif
 subdir('shader')
 subdir('icons')
 
+install_data('qemu.desktop', install_dir: config_host['qemu_desktopdir'])
+
 modules += {'ui': ui_modules}
-- 
2.26.2





[PULL 21/24] configure: do not include ${prefix} in firmwarepath

2020-09-01 Thread Paolo Bonzini
Left out in commit 22a87800e6 ("configure: expand path variables for
meson configure", 2020-08-21), do it now.

Signed-off-by: Paolo Bonzini 
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index b9e977f13d..8a3acef89d 100755
--- a/configure
+++ b/configure
@@ -473,7 +473,6 @@ LDFLAGS_SHARED="-shared"
 modules="no"
 module_upgrades="no"
 prefix="/usr/local"
-firmwarepath="\${prefix}/share/qemu-firmware"
 qemu_suffix="qemu"
 slirp=""
 oss_lib=""
@@ -1677,6 +1676,7 @@ for opt do
   esac
 done
 
+firmwarepath="${firmwarepath:-$prefix/share/qemu-firmware}"
 libdir="${libdir:-$prefix/lib}"
 libexecdir="${libexecdir:-$prefix/libexec}"
 includedir="${includedir:-$prefix/include}"
-- 
2.26.2





[PULL 10/24] meson: move zlib detection to meson

2020-09-01 Thread Paolo Bonzini
Meson includes the same logic that tries to look for -lz if
pkg-config (and cmake) cannot find zlib.  The undocumented
--disable-zlib-test option becomes a no-op.

There is still an instance of "-lz" in the LIBS directory.
It will go away as soon as tests are converted to meson,
because the zlib dependency does not propagate from libblock.fa
to the Makefile-build unit tests.

Reviewed-by: Marc-André Lureau 
Signed-off-by: Paolo Bonzini 
---
 configure   | 32 +---
 meson.build |  6 +-
 2 files changed, 2 insertions(+), 36 deletions(-)

diff --git a/configure b/configure
index f81900880a..e8946aeefb 100755
--- a/configure
+++ b/configure
@@ -502,7 +502,6 @@ opengl=""
 opengl_dmabuf="no"
 cpuid_h="no"
 avx2_opt=""
-zlib="yes"
 capstone=""
 lzo=""
 snappy=""
@@ -1428,7 +1427,7 @@ for opt do
   ;;
   --enable-usb-redir) usb_redir="yes"
   ;;
-  --disable-zlib-test) zlib="no"
+  --disable-zlib-test)
   ;;
   --disable-lzo) lzo="no"
   ;;
@@ -3904,30 +3903,6 @@ if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; 
then
 fi
 fi
 
-#
-# zlib check
-
-if test "$zlib" != "no" ; then
-if $pkg_config --exists zlib; then
-zlib_cflags=$($pkg_config --cflags zlib)
-zlib_libs=$($pkg_config --libs zlib)
-QEMU_CFLAGS="$zlib_cflags $QEMU_CFLAGS"
-LIBS="$zlib_libs $LIBS"
-else
-cat > $TMPC << EOF
-#include 
-int main(void) { zlibVersion(); return 0; }
-EOF
-if compile_prog "" "-lz" ; then
-zlib_libs=-lz
-LIBS="$LIBS $zlib_libs"
-else
-error_exit "zlib check failed" \
-"Make sure to have the zlib libs and headers installed."
-fi
-fi
-fi
-
 ##
 # SHA command probe for modules
 if test "$modules" = yes; then
@@ -7135,11 +7110,6 @@ fi
 if test "$posix_memalign" = "yes" ; then
   echo "CONFIG_POSIX_MEMALIGN=y" >> $config_host_mak
 fi
-if test "$zlib" != "no" ; then
-echo "CONFIG_ZLIB=y" >> $config_host_mak
-echo "ZLIB_CFLAGS=$zlib_cflags" >> $config_host_mak
-echo "ZLIB_LIBS=$zlib_libs" >> $config_host_mak
-fi
 if test "$spice" = "yes" ; then
   echo "CONFIG_SPICE=y" >> $config_host_mak
   echo "SPICE_CFLAGS=$spice_cflags" >> $config_host_mak
diff --git a/meson.build b/meson.build
index 6b2fc76933..8b28ecff28 100644
--- a/meson.build
+++ b/meson.build
@@ -134,11 +134,7 @@ if 'CONFIG_AUTH_PAM' in config_host
   pam = cc.find_library('pam')
 endif
 libaio = cc.find_library('aio', required: false)
-zlib = not_found
-if 'CONFIG_ZLIB' in config_host
-  zlib = declare_dependency(compile_args: config_host['ZLIB_CFLAGS'].split(),
-link_args: config_host['ZLIB_LIBS'].split())
-endif
+zlib = dependency('zlib', required: true)
 linux_io_uring = not_found
 if 'CONFIG_LINUX_IO_URING' in config_host
   linux_io_uring = declare_dependency(compile_args: 
config_host['LINUX_IO_URING_CFLAGS'].split(),
-- 
2.26.2





[PULL 04/24] meson: install pc-bios blobs

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Message-Id: <20200826130622.553318-2-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 Makefile| 31 --
 pc-bios/meson.build | 63 +
 2 files changed, 63 insertions(+), 31 deletions(-)

diff --git a/Makefile b/Makefile
index 81794d5c34..16b2ffa7fe 100644
--- a/Makefile
+++ b/Makefile
@@ -229,32 +229,6 @@ distclean: clean ninja-distclean
rm -f linux-headers/asm
rm -Rf .sdk
 
-ifdef INSTALL_BLOBS
-BLOBS=bios.bin bios-256k.bin bios-microvm.bin sgabios.bin vgabios.bin 
vgabios-cirrus.bin \
-vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin vgabios-virtio.bin \
-vgabios-ramfb.bin vgabios-bochs-display.bin vgabios-ati.bin \
-openbios-sparc32 openbios-sparc64 openbios-ppc QEMU,tcx.bin QEMU,cgthree.bin \
-pxe-e1000.rom pxe-eepro100.rom pxe-ne2k_pci.rom \
-pxe-pcnet.rom pxe-rtl8139.rom pxe-virtio.rom \
-efi-e1000.rom efi-eepro100.rom efi-ne2k_pci.rom \
-efi-pcnet.rom efi-rtl8139.rom efi-virtio.rom \
-efi-e1000e.rom efi-vmxnet3.rom \
-qemu-nsis.bmp \
-bamboo.dtb canyonlands.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \
-multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin \
-s390-ccw.img s390-netboot.img \
-slof.bin skiboot.lid \
-palcode-clipper \
-u-boot.e500 u-boot-sam460-20100605.bin \
-qemu_vga.ndrv \
-edk2-licenses.txt \
-hppa-firmware.img \
-opensbi-riscv32-generic-fw_dynamic.bin opensbi-riscv64-generic-fw_dynamic.bin \
-opensbi-riscv32-generic-fw_dynamic.elf opensbi-riscv64-generic-fw_dynamic.elf
-else
-BLOBS=
-endif
-
 install-datadir:
$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)"
 
@@ -272,11 +246,6 @@ export DESTDIR
 install: all install-datadir install-localstatedir
 ifdef CONFIG_TRACE_SYSTEMTAP
$(INSTALL_PROG) "scripts/qemu-trace-stap" $(DESTDIR)$(bindir)
-endif
-ifneq ($(BLOBS),)
-   set -e; for x in $(BLOBS); do \
-   $(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x 
"$(DESTDIR)$(qemu_datadir)"; \
-   done
 endif
for s in $(ICON_SIZES); do \
mkdir -p "$(DESTDIR)$(qemu_icondir)/hicolor/$${s}/apps"; \
diff --git a/pc-bios/meson.build b/pc-bios/meson.build
index b6389f5148..f608c2cdba 100644
--- a/pc-bios/meson.build
+++ b/pc-bios/meson.build
@@ -24,5 +24,68 @@ if 'DECOMPRESS_EDK2_BLOBS' in config_host
   endforeach
 endif
 
+blobs = files(
+  'bios.bin',
+  'bios-256k.bin',
+  'bios-microvm.bin',
+  'sgabios.bin',
+  'vgabios.bin',
+  'vgabios-cirrus.bin',
+  'vgabios-stdvga.bin',
+  'vgabios-vmware.bin',
+  'vgabios-qxl.bin',
+  'vgabios-virtio.bin',
+  'vgabios-ramfb.bin',
+  'vgabios-bochs-display.bin',
+  'vgabios-ati.bin',
+  'openbios-sparc32',
+  'openbios-sparc64',
+  'openbios-ppc',
+  'QEMU,tcx.bin',
+  'QEMU,cgthree.bin',
+  'pxe-e1000.rom',
+  'pxe-eepro100.rom',
+  'pxe-ne2k_pci.rom',
+  'pxe-pcnet.rom',
+  'pxe-rtl8139.rom',
+  'pxe-virtio.rom',
+  'efi-e1000.rom',
+  'efi-eepro100.rom',
+  'efi-ne2k_pci.rom',
+  'efi-pcnet.rom',
+  'efi-rtl8139.rom',
+  'efi-virtio.rom',
+  'efi-e1000e.rom',
+  'efi-vmxnet3.rom',
+  'qemu-nsis.bmp',
+  'bamboo.dtb',
+  'canyonlands.dtb',
+  'petalogix-s3adsp1800.dtb',
+  'petalogix-ml605.dtb',
+  'multiboot.bin',
+  'linuxboot.bin',
+  'linuxboot_dma.bin',
+  'kvmvapic.bin',
+  'pvh.bin',
+  's390-ccw.img',
+  's390-netboot.img',
+  'slof.bin',
+  'skiboot.lid',
+  'palcode-clipper',
+  'u-boot.e500',
+  'u-boot-sam460-20100605.bin',
+  'qemu_vga.ndrv',
+  'edk2-licenses.txt',
+  'hppa-firmware.img',
+  'opensbi-riscv32-generic-fw_dynamic.bin',
+  'opensbi-riscv64-generic-fw_dynamic.bin',
+  'opensbi-riscv32-generic-fw_dynamic.elf',
+  'opensbi-riscv64-generic-fw_dynamic.elf',
+)
+
+if install_blobs
+  install_data(blobs, install_dir: config_host['qemu_datadir'])
+endif
+
 subdir('descriptors')
 subdir('keymaps')
-- 
2.26.2





[PULL 22/24] meson: use pkg-config method to find dependencies

2020-09-01 Thread Paolo Bonzini
We do not need to ask cmake for the dependencies, so just use the
pkg-config mechanism.  Keep "auto" for SDL so that it tries using
sdl-config too.

The documentation is adjusted to use SDL2_image as the example,
rather than SDL which does not use the "pkg-config" method.

Signed-off-by: Paolo Bonzini 
---
 docs/devel/build-system.rst | 27 ++-
 meson.build |  8 
 2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/docs/devel/build-system.rst b/docs/devel/build-system.rst
index 58bf392430..0c09fb9a54 100644
--- a/docs/devel/build-system.rst
+++ b/docs/devel/build-system.rst
@@ -66,46 +66,47 @@ following tasks:
upon completion.
 
 
-Taking the probe for SDL as an example, we have the following pieces
+Taking the probe for SDL2_Image as an example, we have the following pieces
 in configure::
 
   # Initial variable state
-  sdl=auto
+  sdl_image=auto
 
   ..snip..
 
   # Configure flag processing
-  --disable-gnutls) sdl=disabled
+  --disable-sdl-image) sdl_image=disabled
   ;;
-  --enable-gnutls) sdl=enabled
+  --enable-sdl-image) sdl_image=enabled
   ;;
 
   ..snip..
 
   # Help output feature message
-  sdl SDL UI
+  sdl-image SDL Image support for icons
 
   ..snip..
 
   # Meson invocation
-  -Dsdl=$sdl
+  -Dsdl_image=$sdl_image
 
 In meson_options.txt::
 
-  option('sdl', type : 'feature', value : 'auto')
+  option('sdl', type : 'feature', value : 'auto',
+ description: 'SDL Image support for icons')
 
 In meson.build::
 
   # Detect dependency
-  sdl = dependency('sdl2',
-   required: get_option('sdl'),
-   static: enable_static)
+  sdl_image = dependency('SDL2_image', required: get_option('sdl_image'),
+ method: 'pkg-config',
+ static: enable_static)
 
-  # Create config-host.h
-  config_host_data.set('CONFIG_SDL', sdl.found())
+  # Create config-host.h (if applicable)
+  config_host_data.set('CONFIG_SDL_IMAGE', sdl_image.found())
 
   # Summary
-  summary_info += {'SDL support':   sdl.found()}
+  summary_info += {'SDL image support': sdl_image.found()}
 
 
 
diff --git a/meson.build b/meson.build
index 78ac86f3a1..0e2d884f5c 100644
--- a/meson.build
+++ b/meson.build
@@ -129,7 +129,7 @@ endif
 pixman = not_found
 if have_system or have_tools
   pixman = dependency('pixman-1', required: have_system, version:'>=0.21.8',
-  static: enable_static)
+  method: 'pkg-config', static: enable_static)
 endif
 pam = not_found
 if 'CONFIG_AUTH_PAM' in config_host
@@ -168,7 +168,7 @@ if get_option('xkbcommon').auto() and not have_system and 
not have_tools
   xkbcommon = not_found
 else
   xkbcommon = dependency('xkbcommon', required: get_option('xkbcommon'),
- static: enable_static)
+ method: 'pkg-config', static: enable_static)
 endif
 slirp = not_found
 if config_host.has_key('CONFIG_SLIRP')
@@ -247,7 +247,7 @@ if sdl.found()
   sdl = declare_dependency(compile_args: '-Wno-undef',
dependencies: sdl)
   sdl_image = dependency('SDL2_image', required: get_option('sdl_image'),
- static: enable_static)
+ method: 'pkg-config', static: enable_static)
 else
   if get_option('sdl_image').enabled()
 error('sdl-image required, but SDL was @0@',
@@ -332,7 +332,7 @@ sasl = not_found
 if get_option('vnc').enabled()
   vnc = declare_dependency() # dummy dependency
   png = dependency('libpng', required: get_option('vnc_png'),
-   static: enable_static)
+   method: 'pkg-config', static: enable_static)
   jpeg = cc.find_library('jpeg', has_headers: ['jpeglib.h'],
  required: get_option('vnc_jpeg'),
  static: enable_static)
-- 
2.26.2





[PULL 14/24] meson: pass qemu_suffix option

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

The following patches will make use of it to fix installation paths.

Signed-off-by: Marc-André Lureau 
Message-Id: <20200826110419.528931-5-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 configure | 1 +
 meson_options.txt | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/configure b/configure
index 625b7ba062..78aae9c2a0 100755
--- a/configure
+++ b/configure
@@ -8198,6 +8198,7 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \
 --mandir "${pre_prefix}$mandir" \
 --sysconfdir "${pre_prefix}$sysconfdir" \
 --localstatedir "${pre_prefix}$local_statedir" \
+-Dqemu_suffix="$qemu_suffix" \
 -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) 
\
 -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo 
false; fi) \
 -Dwerror=$(if test "$werror" = yes; then echo true; else echo false; 
fi) \
diff --git a/meson_options.txt b/meson_options.txt
index aef2de6523..dfdcf85063 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,3 +1,5 @@
+option('qemu_suffix', type : 'string', value: '/qemu',
+   description: 'Suffix for QEMU data/modules/config directories (can be 
empty)')
 option('gettext', type : 'boolean', value : true)
 option('sdl', type : 'feature', value : 'auto')
 option('sdl_image', type : 'feature', value : 'auto')
-- 
2.26.2





[PATCH v8 1/8] Introduce yank feature

2020-09-01 Thread Lukas Straub
The yank feature allows to recover from hanging qemu by "yanking"
at various parts. Other qemu systems can register themselves and
multiple yank functions. Then all yank functions for selected
instances can be called by the 'yank' out-of-band qmp command.
Available instances can be queried by a 'query-yank' oob command.

Signed-off-by: Lukas Straub 
Acked-by: Stefan Hajnoczi 
---
 include/qemu/yank.h |  81 +++
 qapi/misc.json  |  62 +++
 util/meson.build|   1 +
 util/yank.c | 187 
 4 files changed, 331 insertions(+)
 create mode 100644 include/qemu/yank.h
 create mode 100644 util/yank.c

diff --git a/include/qemu/yank.h b/include/qemu/yank.h
new file mode 100644
index 00..c5ab53965a
--- /dev/null
+++ b/include/qemu/yank.h
@@ -0,0 +1,81 @@
+/*
+ * QEMU yank feature
+ *
+ * Copyright (c) Lukas Straub 
+ *
+ * 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 YANK_H
+#define YANK_H
+
+typedef void (YankFn)(void *opaque);
+
+/**
+ * yank_register_instance: Register a new instance.
+ *
+ * This registers a new instance for yanking. Must be called before any yank
+ * function is registered for this instance.
+ *
+ * This function is thread-safe.
+ *
+ * @instance_name: The globally unique name of the instance.
+ * @errp: Error object.
+ */
+void yank_register_instance(const char *instance_name, Error **errp);
+
+/**
+ * yank_unregister_instance: Unregister a instance.
+ *
+ * This unregisters a instance. Must be called only after every yank function
+ * of the instance has been unregistered.
+ *
+ * This function is thread-safe.
+ *
+ * @instance_name: The name of the instance.
+ */
+void yank_unregister_instance(const char *instance_name);
+
+/**
+ * yank_register_function: Register a yank function
+ *
+ * This registers a yank function. All limitations of qmp oob commands apply
+ * to the yank function as well. See docs/devel/qapi-code-gen.txt under
+ * "An OOB-capable command handler must satisfy the following conditions".
+ *
+ * This function is thread-safe.
+ *
+ * @instance_name: The name of the instance
+ * @func: The yank function
+ * @opaque: Will be passed to the yank function
+ */
+void yank_register_function(const char *instance_name,
+YankFn *func,
+void *opaque);
+
+/**
+ * yank_unregister_function: Unregister a yank function
+ *
+ * This unregisters a yank function.
+ *
+ * This function is thread-safe.
+ *
+ * @instance_name: The name of the instance
+ * @func: func that was passed to yank_register_function
+ * @opaque: opaque that was passed to yank_register_function
+ */
+void yank_unregister_function(const char *instance_name,
+  YankFn *func,
+  void *opaque);
+
+/**
+ * yank_generic_iochannel: Generic yank function for iochannel
+ *
+ * This is a generic yank function which will call qio_channel_shutdown on the
+ * provided QIOChannel.
+ *
+ * @opaque: QIOChannel to shutdown
+ */
+void yank_generic_iochannel(void *opaque);
+#endif
diff --git a/qapi/misc.json b/qapi/misc.json
index 9d32820dc1..7de330416a 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -1615,3 +1615,65 @@
 ##
 { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }

+##
+# @YankInstances:
+#
+# @instances: List of yank instances.
+#
+# A yank instance can be yanked with the "yank" qmp command to recover from a
+# hanging qemu.
+#
+# Yank instances are named after the following schema:
+# "blockdev:" refers to a block device. Currently only nbd block
+# devices are implemented.
+# "chardev:" refers to a chardev. Currently only socket chardevs
+# are implemented.
+# "migration" refers to the migration currently in progress.
+#
+# Currently implemented yank instances:
+#  -nbd block device:
+#   Yanking it will shutdown the connection to the nbd server without
+#   attempting to reconnect.
+#  -socket chardev:
+#   Yanking it will shutdown the connected socket.
+#  -migration:
+#   Yanking it will shutdown all migration connections.
+#
+# Since: 5.2
+##
+{ 'struct': 'YankInstances', 'data': {'instances': ['str'] } }
+
+##
+# @yank:
+#
+# Recover from hanging qemu by yanking the specified instances. See
+# "YankInstances" for more information.
+#
+# Takes @YankInstances as argument.
+#
+# Returns: nothing.
+#
+# Example:
+#
+# -> { "execute": "yank", "arguments": { "instances": ["blockdev:nbd0"] } }
+# <- { "return": {} }
+#
+# Since: 5.2
+##
+{ 'command': 'yank', 'data': 'YankInstances', 'allow-oob': true }
+
+##
+# @query-yank:
+#
+# Query yank instances. See "YankInstances" for more information.
+#
+# Returns: @YankInstances
+#
+# Example:
+#
+# -> { "execute": "query-yank" }
+# <- { "return": { "instances": ["blockdev:nbd0"] } }
+#
+# Since: 5.2
+##
+{ 'command': 'query-yank', 'returns': 'YankInstances', 'allow-oob': tr

[PULL 11/24] configure: rename confsuffix option

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

The value is used to construct conf/mod/data directories.

Signed-off-by: Marc-André Lureau 
Message-Id: <20200826110419.528931-2-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 configure | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/configure b/configure
index e8946aeefb..46fe7914c3 100755
--- a/configure
+++ b/configure
@@ -474,7 +474,7 @@ modules="no"
 module_upgrades="no"
 prefix="/usr/local"
 firmwarepath="\${prefix}/share/qemu-firmware"
-confsuffix="/qemu"
+qemu_suffix="/qemu"
 slirp=""
 oss_lib=""
 bsd="no"
@@ -1012,7 +1012,7 @@ if test "$mingw32" = "yes" ; then
 LIBS="-liberty $LIBS"
   fi
   prefix="c:/Program Files/QEMU"
-  confsuffix=""
+  qemu_suffix=""
   libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi 
-lnetapi32 $libs_qga"
 fi
 
@@ -1122,7 +1122,7 @@ for opt do
   ;;
   --datadir=*) datadir="$optarg"
   ;;
-  --with-confsuffix=*) confsuffix="$optarg"
+  --with-suffix=*) qemu_suffix="$optarg"
   ;;
   --docdir=*) qemu_docdir="$optarg"
   ;;
@@ -1832,16 +1832,16 @@ Advanced options (experts only):
   --with-git=GIT   use specified git [$git]
   --static enable static build [$static]
   --mandir=PATHinstall man pages in PATH
-  --datadir=PATH   install firmware in PATH$confsuffix
-  --docdir=PATHinstall documentation in PATH$confsuffix
+  --datadir=PATH   install firmware in PATH$qemu_suffix
+  --docdir=PATHinstall documentation in PATH$qemu_suffix
   --bindir=PATHinstall binaries in PATH
   --libdir=PATHinstall libraries in PATH
   --libexecdir=PATHinstall helper binaries in PATH
-  --sysconfdir=PATHinstall config in PATH$confsuffix
+  --sysconfdir=PATHinstall config in PATH$qemu_suffix
   --localstatedir=PATH install local state in PATH (set at runtime on 
win32)
   --firmwarepath=PATH  search PATH for firmware files
   --efi-aarch64=PATH   PATH of efi file to use for aarch64 VMs.
-  --with-confsuffix=SUFFIX suffix for QEMU data inside 
datadir/libdir/sysconfdir [$confsuffix]
+  --with-suffix=SUFFIX suffix for QEMU data inside 
datadir/libdir/sysconfdir [$qemu_suffix]
   --with-pkgversion=VERS   use specified string as sub-version of the package
   --enable-debug   enable common debug build options
   --enable-sanitizers  enable default sanitizers
@@ -6449,9 +6449,9 @@ EOF
 fi
 fi
 
-qemu_confdir=$sysconfdir$confsuffix
-qemu_moddir=$libdir$confsuffix
-qemu_datadir=$datadir$confsuffix
+qemu_confdir=$sysconfdir$qemu_suffix
+qemu_moddir=$libdir$qemu_suffix
+qemu_datadir=$datadir$qemu_suffix
 qemu_localedir="$datadir/locale"
 qemu_icondir="$datadir/icons"
 qemu_desktopdir="$datadir/applications"
-- 
2.26.2





[PULL 12/24] configure: always /-seperate directory from qemu_suffix

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

Otherwise, we may accept very strange directory names...

While at it, quote the variables.

Signed-off-by: Marc-André Lureau 
Message-Id: <20200826110419.528931-3-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 configure | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/configure b/configure
index 46fe7914c3..66d7a72aa9 100755
--- a/configure
+++ b/configure
@@ -474,7 +474,7 @@ modules="no"
 module_upgrades="no"
 prefix="/usr/local"
 firmwarepath="\${prefix}/share/qemu-firmware"
-qemu_suffix="/qemu"
+qemu_suffix="qemu"
 slirp=""
 oss_lib=""
 bsd="no"
@@ -1832,12 +1832,12 @@ Advanced options (experts only):
   --with-git=GIT   use specified git [$git]
   --static enable static build [$static]
   --mandir=PATHinstall man pages in PATH
-  --datadir=PATH   install firmware in PATH$qemu_suffix
-  --docdir=PATHinstall documentation in PATH$qemu_suffix
+  --datadir=PATH   install firmware in PATH/$qemu_suffix
+  --docdir=PATHinstall documentation in PATH/$qemu_suffix
   --bindir=PATHinstall binaries in PATH
   --libdir=PATHinstall libraries in PATH
   --libexecdir=PATHinstall helper binaries in PATH
-  --sysconfdir=PATHinstall config in PATH$qemu_suffix
+  --sysconfdir=PATHinstall config in PATH/$qemu_suffix
   --localstatedir=PATH install local state in PATH (set at runtime on 
win32)
   --firmwarepath=PATH  search PATH for firmware files
   --efi-aarch64=PATH   PATH of efi file to use for aarch64 VMs.
@@ -6449,9 +6449,9 @@ EOF
 fi
 fi
 
-qemu_confdir=$sysconfdir$qemu_suffix
-qemu_moddir=$libdir$qemu_suffix
-qemu_datadir=$datadir$qemu_suffix
+qemu_confdir="$sysconfdir/$qemu_suffix"
+qemu_moddir="$libdir/$qemu_suffix"
+qemu_datadir="$datadir/$qemu_suffix"
 qemu_localedir="$datadir/locale"
 qemu_icondir="$datadir/icons"
 qemu_desktopdir="$datadir/applications"
-- 
2.26.2





[PULL 13/24] configure: build docdir like other suffixed directories

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

As documented in --help for --docdir.

Signed-off-by: Marc-André Lureau 
Message-Id: <20200826110419.528931-4-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 configure | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 66d7a72aa9..625b7ba062 100755
--- a/configure
+++ b/configure
@@ -1684,14 +1684,14 @@ includedir="${includedir:-$prefix/include}"
 if test "$mingw32" = "yes" ; then
 mandir="$prefix"
 datadir="$prefix"
-qemu_docdir="$prefix"
+docdir="$prefix"
 bindir="$prefix"
 sysconfdir="$prefix"
 local_statedir=
 else
 mandir="${mandir:-$prefix/share/man}"
 datadir="${datadir:-$prefix/share}"
-qemu_docdir="${qemu_docdir:-$prefix/share/doc/qemu}"
+docdir="${docdir:-$prefix/share/doc}"
 bindir="${bindir:-$prefix/bin}"
 sysconfdir="${sysconfdir:-$prefix/etc}"
 local_statedir="${local_statedir:-$prefix/var}"
@@ -1841,7 +1841,7 @@ Advanced options (experts only):
   --localstatedir=PATH install local state in PATH (set at runtime on 
win32)
   --firmwarepath=PATH  search PATH for firmware files
   --efi-aarch64=PATH   PATH of efi file to use for aarch64 VMs.
-  --with-suffix=SUFFIX suffix for QEMU data inside 
datadir/libdir/sysconfdir [$qemu_suffix]
+  --with-suffix=SUFFIX suffix for QEMU data inside 
datadir/libdir/sysconfdir/docdir [$qemu_suffix]
   --with-pkgversion=VERS   use specified string as sub-version of the package
   --enable-debug   enable common debug build options
   --enable-sanitizers  enable default sanitizers
@@ -6452,6 +6452,7 @@ fi
 qemu_confdir="$sysconfdir/$qemu_suffix"
 qemu_moddir="$libdir/$qemu_suffix"
 qemu_datadir="$datadir/$qemu_suffix"
+qemu_docdir="$docdir/$qemu_suffix"
 qemu_localedir="$datadir/locale"
 qemu_icondir="$datadir/icons"
 qemu_desktopdir="$datadir/applications"
-- 
2.26.2





[PULL 18/24] meson: add NSIS building

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20200826110419.528931-9-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 Makefile| 56 ---
 meson.build | 25 
 scripts/nsis.py | 78 +
 3 files changed, 103 insertions(+), 56 deletions(-)
 create mode 100644 scripts/nsis.py

diff --git a/Makefile b/Makefile
index 75db8be52e..f187ddf47a 100644
--- a/Makefile
+++ b/Makefile
@@ -232,62 +232,6 @@ distclean: clean ninja-distclean
 # Needed by "meson install"
 export DESTDIR
 
-ifdef CONFIG_WIN32
-
-INSTALLER = qemu-setup-$(VERSION)$(EXESUF)
-
-nsisflags = -V2 -NOCD
-
-ifneq ($(wildcard $(SRC_PATH)/dll),)
-ifeq ($(ARCH),x86_64)
-# 64 bit executables
-DLL_PATH = $(SRC_PATH)/dll/w64
-nsisflags += -DW64
-else
-# 32 bit executables
-DLL_PATH = $(SRC_PATH)/dll/w32
-endif
-endif
-
-.PHONY: installer
-installer: $(INSTALLER)
-
-INSTDIR=/tmp/qemu-nsis
-
-$(INSTALLER): $(SRC_PATH)/qemu.nsi
-   $(MAKE) install DESTDIR=${INSTDIR}
-ifdef SIGNCODE
-   (cd ${INSTDIR}/${bindir}; \
- for i in *.exe; do \
-   $(SIGNCODE) $${i}; \
- done \
-)
-endif # SIGNCODE
-   (cd ${INSTDIR}/${bindir}; \
- for i in qemu-system-*.exe; do \
-   arch=$${i%.exe}; \
-   arch=$${arch#qemu-system-}; \
-   echo Section \"$$arch\" Section_$$arch; \
-   echo SetOutPath \"\$$INSTDIR\"; \
-   echo File \"\$${BINDIR}\\$$i\"; \
-   echo SectionEnd; \
- done \
-) >${INSTDIR}/${bindir}/system-emulations.nsh
-   makensis $(nsisflags) \
-$(if $(BUILD_DOCS),-DCONFIG_DOCUMENTATION="y") \
-$(if $(CONFIG_GTK),-DCONFIG_GTK="y") \
--DBINDIR="${INSTDIR}/${bindir}" \
-$(if $(DLL_PATH),-DDLLDIR="$(DLL_PATH)") \
--DSRCDIR="$(SRC_PATH)" \
--DOUTFILE="$(INSTALLER)" \
--DDISPLAYVERSION="$(VERSION)" \
-$(SRC_PATH)/qemu.nsi
-   rm -r ${INSTDIR}
-ifdef SIGNCODE
-   $(SIGNCODE) $(INSTALLER)
-endif # SIGNCODE
-endif # CONFIG_WIN
-
 # Add a dependency on the generated files, so that they are always
 # rebuilt before other object files
 ifneq ($(wildcard config-host.mak),)
diff --git a/meson.build b/meson.build
index a71b199c5e..78ac86f3a1 100644
--- a/meson.build
+++ b/meson.build
@@ -1230,6 +1230,31 @@ if build_docs
   endif
 endif
 
+if host_machine.system() == 'windows'
+  nsis_cmd = [
+find_program('scripts/nsis.py'),
+'@OUTPUT@',
+get_option('prefix'),
+meson.current_source_dir(),
+host_machine.cpu_family(),
+'--',
+'-DDISPLAYVERSION=' + meson.project_version(),
+  ]
+  if build_docs
+nsis_cmd += '-DCONFIG_DOCUMENTATION=y'
+  endif
+  if 'CONFIG_GTK' in config_host
+nsis_cmd += '-DCONFIG_GTK=y'
+  endif
+
+  nsis = custom_target('nsis',
+   output: 'qemu-setup-' + meson.project_version() + 
'.exe',
+   input: files('qemu.nsi'),
+   build_always_stale: true,
+   command: nsis_cmd + ['@INPUT@'])
+  alias_target('installer', nsis)
+endif
+
 summary_info = {}
 summary_info += {'Install prefix':config_host['prefix']}
 summary_info += {'BIOS directory':config_host['qemu_datadir']}
diff --git a/scripts/nsis.py b/scripts/nsis.py
new file mode 100644
index 00..e1c409344e
--- /dev/null
+++ b/scripts/nsis.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2020 Red Hat, Inc.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import argparse
+import glob
+import os
+import shutil
+import subprocess
+import tempfile
+
+
+def signcode(path):
+cmd = os.environ.get("SIGNCODE")
+if not cmd:
+return
+subprocess.run([cmd, path])
+
+
+def main():
+parser = argparse.ArgumentParser(description="QEMU NSIS build helper.")
+parser.add_argument("outfile")
+parser.add_argument("prefix")
+parser.add_argument("srcdir")
+parser.add_argument("cpu")
+parser.add_argument("nsisargs", nargs="*")
+args = parser.parse_args()
+
+destdir = tempfile.mkdtemp()
+try:
+subprocess.run(["make", "install", "DESTDIR=" + destdir + os.path.sep])
+with open(
+os.path.join(destdir + args.prefix, "system-emulations.nsh"), "w"
+) as nsh:
+for exe in glob.glob(
+os.path.join(destdir + args.prefix, "qemu-system-*.exe")
+):
+exe = os.path.basename(exe)
+arch = exe[12:-4]
+nsh.write(
+"""
+Section "{0}" Section_{0}
+SetOutPath "$INSTDIR"
+File "${{BINDIR}}\\{1}"
+SectionEnd
+""".format(
+arch, exe
+)
+)
+
+for exe in glob.g

[PULL 17/24] meson: use meson mandir instead of qemu_mandir

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

When cross-compiling, by default qemu_mandir is 'c:\Program
Files\QEMU', which is not recognized as being an absolute path, and
meson will end up adding the prefix again.

Use the pre-prefixed meson mandir option instead.

Reviewed-by: Daniel P. Berrangé 
Signed-off-by: Marc-André Lureau 
Message-Id: <20200826110419.528931-8-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 configure   | 1 -
 meson.build | 4 ++--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 1f478a46a9..b9e977f13d 100755
--- a/configure
+++ b/configure
@@ -6648,7 +6648,6 @@ echo "bindir=$bindir" >> $config_host_mak
 echo "libdir=$libdir" >> $config_host_mak
 echo "libexecdir=$libexecdir" >> $config_host_mak
 echo "includedir=$includedir" >> $config_host_mak
-echo "mandir=$mandir" >> $config_host_mak
 echo "sysconfdir=$sysconfdir" >> $config_host_mak
 echo "qemu_confdir=$qemu_confdir" >> $config_host_mak
 echo "qemu_datadir=$qemu_datadir" >> $config_host_mak
diff --git a/meson.build b/meson.build
index 43e2c6e43d..a71b199c5e 100644
--- a/meson.build
+++ b/meson.build
@@ -1223,7 +1223,7 @@ if build_docs
   output: man,
   capture: true,
   install: true,
-  install_dir: config_host['mandir'] / 'man7',
+  install_dir: get_option('mandir') / 'man7',
   command: [pod2man, '--utf8', '--section=7', 
'--center=" "',
 '--release=" "', '@INPUT@'])
 endforeach
@@ -1242,7 +1242,7 @@ summary_info += {'include directory': 
config_host['includedir']}
 summary_info += {'config directory':  config_host['sysconfdir']}
 if targetos != 'windows'
   summary_info += {'local state directory': config_host['qemu_localstatedir']}
-  summary_info += {'Manual directory':  config_host['mandir']}
+  summary_info += {'Manual directory':  get_option('mandir')}
 else
   summary_info += {'local state directory': 'queried at runtime'}
 endif
-- 
2.26.2





[PULL 23/24] build: fix recurse-all target

2020-09-01 Thread Paolo Bonzini
The missing "/all" suffix prevents the pc-bios/ parts of the build
from running.

In the meanwhile, -Wall has moved from QEMU_CFLAGS to CFLAGS.  Simplify
everything by not passing down CFLAGS, and add -Wall in the recursive
Makefiles.

Reported-by: Miroslav Rezanina 
Reviewed-by: Miroslav Rezanina 
Tested-by: Thomas Huth 
Fixes: 5e6d1573b4 ("remove Makefile.target", 2020-08-21)
Signed-off-by: Paolo Bonzini 
---
 Makefile   |  4 ++--
 pc-bios/optionrom/Makefile | 10 +++---
 pc-bios/s390-ccw/Makefile  |  3 ++-
 3 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index f187ddf47a..c1a93c66a0 100644
--- a/Makefile
+++ b/Makefile
@@ -186,10 +186,10 @@ ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), 
$(ROM_DIRS)))
 # Only keep -O and -g cflags
 .PHONY: $(ROM_DIRS_RULES)
 $(ROM_DIRS_RULES):
-   $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" 
TARGET_DIR="$(dir $@)" CFLAGS="$(filter -O% -g%,$(CFLAGS))" $(notdir $@),)
+   $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" 
TARGET_DIR="$(dir $@)" $(notdir $@),)
 
 .PHONY: recurse-all recurse-clean
-recurse-all: $(ROM_DIRS)
+recurse-all: $(addsuffix /all, $(ROM_DIRS))
 recurse-clean: $(addsuffix /clean, $(ROM_DIRS))
 
 ##
diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
index 51cb6ca9d8..084fc10f05 100644
--- a/pc-bios/optionrom/Makefile
+++ b/pc-bios/optionrom/Makefile
@@ -8,15 +8,12 @@ all: multiboot.bin linuxboot.bin linuxboot_dma.bin 
kvmvapic.bin pvh.bin
@true
 
 include ../../config-host.mak
+CFLAGS = -O2 -g
 
 quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, @$1))
-cc-option = $(if $(shell $(CC) $1 -S -o /dev/null -xc /dev/null >/dev/null 
2>&1 && echo OK), $1, $2)
+cc-option = $(if $(shell $(CC) $1 -c -o /dev/null -xc /dev/null >/dev/null 
2>&1 && echo OK), $1, $2)
 
-# Compiling with no optimization creates ROMs that are too large
-ifeq ($(lastword $(filter -O%, -O0 $(CFLAGS))),-O0)
-override CFLAGS += -O2
-endif
-override CFLAGS += -march=i486
+override CFLAGS += -march=i486 -Wall
 
 # Flags for dependency generation
 override CPPFLAGS += -MMD -MP -MT $@ -MF $(@D)/$(*F).d
@@ -42,7 +39,6 @@ Wa = -Wa,
 override ASFLAGS += -32
 override CFLAGS += $(call cc-option, $(Wa)-32)
 
-
 LD_I386_EMULATION ?= elf_i386
 override LDFLAGS = -m $(LD_I386_EMULATION) -T $(SRC_DIR)/flat.lds
 override LDFLAGS += $(LDFLAGS_NOPIE)
diff --git a/pc-bios/s390-ccw/Makefile b/pc-bios/s390-ccw/Makefile
index cc0f77baa6..3eb785048a 100644
--- a/pc-bios/s390-ccw/Makefile
+++ b/pc-bios/s390-ccw/Makefile
@@ -3,6 +3,7 @@ all: build-all
@true
 
 include ../../config-host.mak
+CFLAGS = -O2 -g
 
 quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, @$1))
 cc-option = $(if $(shell $(CC) $1 -S -o /dev/null -xc /dev/null > /dev/null \
@@ -28,7 +29,7 @@ QEMU_DGFLAGS = -MMD -MP -MT $@ -MF $(@D)/$(*F).d
 OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o \
  virtio.o virtio-scsi.o virtio-blkdev.o libc.o cio.o dasd-ipl.o
 
-QEMU_CFLAGS := $(filter -W%, $(QEMU_CFLAGS))
+QEMU_CFLAGS := -Wall $(filter -W%, $(QEMU_CFLAGS))
 QEMU_CFLAGS += -ffreestanding -fno-delete-null-pointer-checks -msoft-float
 QEMU_CFLAGS += -march=z900 -fPIE -fno-strict-aliasing
 QEMU_CFLAGS += -fno-asynchronous-unwind-tables
-- 
2.26.2





[PULL 16/24] meson: pass docdir option

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

When cross-compiling, by default qemu_docdir is 'c:\Program Files\QEMU\'
which is not recognized as being an absolute path, and meson will end up
adding the prefix again.

Add an option to pass docdir location to meson, pre-prefixed like we do
with other directories, build qemu_docdir with the common suffix and use
that instead of config_host['qemu_docdir'].

Signed-off-by: Marc-André Lureau 
Message-Id: <20200826110419.528931-7-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 configure | 2 +-
 docs/meson.build  | 4 ++--
 meson.build   | 4 +++-
 meson_options.txt | 2 ++
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 78aae9c2a0..1f478a46a9 100755
--- a/configure
+++ b/configure
@@ -6653,7 +6653,6 @@ echo "sysconfdir=$sysconfdir" >> $config_host_mak
 echo "qemu_confdir=$qemu_confdir" >> $config_host_mak
 echo "qemu_datadir=$qemu_datadir" >> $config_host_mak
 echo "qemu_firmwarepath=$firmwarepath" >> $config_host_mak
-echo "qemu_docdir=$qemu_docdir" >> $config_host_mak
 echo "qemu_moddir=$qemu_moddir" >> $config_host_mak
 if test "$mingw32" = "no" ; then
   echo "qemu_localstatedir=$local_statedir" >> $config_host_mak
@@ -8198,6 +8197,7 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \
 --mandir "${pre_prefix}$mandir" \
 --sysconfdir "${pre_prefix}$sysconfdir" \
 --localstatedir "${pre_prefix}$local_statedir" \
+-Ddocdir="${pre_prefix}$docdir" \
 -Dqemu_suffix="$qemu_suffix" \
 -Doptimization=$(if test "$debug" = yes; then echo 0; else echo 2; fi) 
\
 -Ddebug=$(if test "$debug_info" = yes; then echo true; else echo 
false; fi) \
diff --git a/docs/meson.build b/docs/meson.build
index 8b059a8e39..50f367349b 100644
--- a/docs/meson.build
+++ b/docs/meson.build
@@ -10,7 +10,7 @@ if build_docs
   configure_file(output: 'index.html',
  input: files('index.html.in'),
  configuration: {'VERSION': meson.project_version()},
- install_dir: config_host['qemu_docdir'])
+ install_dir: qemu_docdir)
   manuals = [ 'devel', 'interop', 'tools', 'specs', 'system', 'user' ]
   man_pages = {
 'interop' : {
@@ -48,7 +48,7 @@ if build_docs
   input_dir, output_dir])
 sphinxdocs += this_manual
 if build_docs and manual != 'devel'
-  install_subdir(output_dir, install_dir: config_host['qemu_docdir'])
+  install_subdir(output_dir, install_dir: qemu_docdir)
 endif
 
 these_man_pages = []
diff --git a/meson.build b/meson.build
index bf6d1b3153..43e2c6e43d 100644
--- a/meson.build
+++ b/meson.build
@@ -19,6 +19,7 @@ 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 = []
 
@@ -1182,7 +1183,7 @@ if build_docs
   input: input,
   output: output,
   install: true,
-  install_dir: config_host['qemu_docdir'] / 'interop',
+  install_dir: qemu_docdir / 'interop',
   command: cmd + args)
   endforeach
   alias_target(ext, t)
@@ -1245,6 +1246,7 @@ if targetos != 'windows'
 else
   summary_info += {'local state directory': 'queried at runtime'}
 endif
+summary_info += {'Doc directory': get_option('docdir')}
 summary_info += {'Build directory':   meson.current_build_dir()}
 summary_info += {'Source path':   meson.current_source_dir()}
 summary_info += {'GIT binary':config_host['GIT']}
diff --git a/meson_options.txt b/meson_options.txt
index f4275691bd..c3120fa359 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,5 +1,7 @@
 option('qemu_suffix', type : 'string', value: 'qemu',
description: 'Suffix for QEMU data/modules/config directories (can be 
empty)')
+option('docdir', type : 'string', value : 'doc',
+   description: 'Base directory for documentation installation (can be 
empty)')
 option('gettext', type : 'boolean', value : true)
 option('sdl', type : 'feature', value : 'auto')
 option('sdl_image', type : 'feature', value : 'auto')
-- 
2.26.2





[PULL 15/24] meson: use meson datadir instead of qemu_datadir

2020-09-01 Thread Paolo Bonzini
From: Marc-André Lureau 

When cross-compiling, by default qemu_datadir is 'c:\Program
Files\QEMU', which is not recognized as being an absolute path, and
meson will end up adding the prefix again.

Signed-off-by: Marc-André Lureau 
Message-Id: <20200826110419.528931-6-marcandre.lur...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 contrib/vhost-user-gpu/meson.build | 2 +-
 meson.build| 3 ++-
 meson_options.txt  | 2 +-
 pc-bios/descriptors/meson.build| 2 +-
 pc-bios/keymaps/meson.build| 6 +++---
 pc-bios/meson.build| 2 +-
 tools/virtiofsd/meson.build| 2 +-
 trace/meson.build  | 2 +-
 8 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/contrib/vhost-user-gpu/meson.build 
b/contrib/vhost-user-gpu/meson.build
index 12d608c2e7..7d9b29da8b 100644
--- a/contrib/vhost-user-gpu/meson.build
+++ b/contrib/vhost-user-gpu/meson.build
@@ -10,5 +10,5 @@ if 'CONFIG_TOOLS' in config_host and 'CONFIG_VIRGL' in 
config_host \
   configure_file(input: '50-qemu-gpu.json.in',
  output: '50-qemu-gpu.json',
  configuration: config_host,
- install_dir: config_host['qemu_datadir'] / 'vhost-user')
+ install_dir: qemu_datadir / 'vhost-user')
 endif
diff --git a/meson.build b/meson.build
index 8b28ecff28..bf6d1b3153 100644
--- a/meson.build
+++ b/meson.build
@@ -18,6 +18,7 @@ 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')
 config_host_data = configuration_data()
 genh = []
 
@@ -1055,7 +1056,7 @@ foreach target : target_dirs
   output: exe['name'] + stp['ext'],
   capture: true,
   install: stp['install'],
-  install_dir: config_host['qemu_datadir'] / 
'../systemtap/tapset',
+  install_dir: qemu_datadir / '../systemtap/tapset',
   command: [
 tracetool, '--group=all', '--format=' + stp['fmt'],
 '--binary=' + stp['bin'],
diff --git a/meson_options.txt b/meson_options.txt
index dfdcf85063..f4275691bd 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,4 +1,4 @@
-option('qemu_suffix', type : 'string', value: '/qemu',
+option('qemu_suffix', type : 'string', value: 'qemu',
description: 'Suffix for QEMU data/modules/config directories (can be 
empty)')
 option('gettext', type : 'boolean', value : true)
 option('sdl', type : 'feature', value : 'auto')
diff --git a/pc-bios/descriptors/meson.build b/pc-bios/descriptors/meson.build
index 7c715bace8..3798d32372 100644
--- a/pc-bios/descriptors/meson.build
+++ b/pc-bios/descriptors/meson.build
@@ -10,5 +10,5 @@ foreach f: [
  output: f,
  configuration: {'DATADIR': config_host['qemu_datadir']},
  install: install_blobs,
- install_dir: config_host['qemu_datadir'] / 'firmware')
+ install_dir: qemu_datadir / 'firmware')
 endforeach
diff --git a/pc-bios/keymaps/meson.build b/pc-bios/keymaps/meson.build
index b737c82230..bbac83ece3 100644
--- a/pc-bios/keymaps/meson.build
+++ b/pc-bios/keymaps/meson.build
@@ -44,13 +44,13 @@ foreach km, args: keymaps
  build_by_default: true,
  output: km,
  command: [native_qemu_keymap, '-f', '@OUTPUT@', 
args.split()],
- install_dir: config_host['qemu_datadir'] / 'keymaps')
+ install_dir: qemu_datadir / 'keymaps')
 endforeach
 if t.length() > 0
   alias_target('update-keymaps', t)
 else
   # install from the source tree
-  install_data(keymaps.keys(), install_dir: config_host['qemu_datadir'] / 
'keymaps')
+  install_data(keymaps.keys(), install_dir: qemu_datadir / 'keymaps')
 endif
 
-install_data(['sl', 'sv'], install_dir: config_host['qemu_datadir'] / 
'keymaps')
+install_data(['sl', 'sv'], install_dir: qemu_datadir / 'keymaps')
diff --git a/pc-bios/meson.build b/pc-bios/meson.build
index f608c2cdba..8087e5c0a7 100644
--- a/pc-bios/meson.build
+++ b/pc-bios/meson.build
@@ -19,7 +19,7 @@ if 'DECOMPRESS_EDK2_BLOBS' in config_host
   input: '@0@.bz2'.format(f),
   capture: true,
   install: install_blobs,
-  install_dir: config_host['qemu_datadir'],
+  install_dir: qemu_datadir,
   command: [ bzip2, '-dc', '@INPUT0@' ])
   endforeach
 endif
diff --git a/tools/virtiofsd/meson.build b/tools/virtiofsd/meson.build
index d1e23c5760..50022ed89e 100644
--- a/tools/virtiofsd/meson.build
+++ b/tools/virtiofsd/meson.build
@@ -16,4 +16,4 @@ executable('virtiofsd', files(
 configure_file(input: '50-qemu-virtiofsd.json.in',

[PULL 19/24] meson: add pixman dependency to chardev/baum module

2020-09-01 Thread Paolo Bonzini
From: Stefan Weil 

Signed-off-by: Stefan Weil 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20200830204640.482214-1...@weilnetz.de>
Signed-off-by: Paolo Bonzini 
---
 chardev/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/chardev/meson.build b/chardev/meson.build
index 7726837e34..27a9a28f4c 100644
--- a/chardev/meson.build
+++ b/chardev/meson.build
@@ -38,7 +38,7 @@ chardev_modules = {}
 
 if config_host.has_key('CONFIG_BRLAPI') and sdl.found()
   module_ss = ss.source_set()
-  module_ss.add(when: [sdl, brlapi], if_true: files('baum.c'))
+  module_ss.add(when: [sdl, brlapi], if_true: [files('baum.c'), pixman])
   chardev_modules += { 'baum': module_ss }
 endif
 
-- 
2.26.2





Re: [PATCH] mailmap: Add entry for Greg Kurz

2020-09-01 Thread Laurent Vivier
Le 12/08/2020 à 17:37, Greg Kurz a écrit :
> I had stopped using gk...@linux.vnet.ibm.com a while back already but
> this email address was shutdown last June when I quit IBM. It's about
> time to map it to gr...@kaod.org.
> 
> Signed-off-by: Greg Kurz 
> ---
>  .mailmap |1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/.mailmap b/.mailmap
> index 81c2ce09370c..896e2d195d86 100644
> --- a/.mailmap
> +++ b/.mailmap
> @@ -48,6 +48,7 @@ Alexander Graf  
>  Anthony Liguori  Anthony Liguori 
>  Filip Bozuta  
>  Frederic Konrad  
> +Greg Kurz  
>  James Hogan  
>  Leif Lindholm  
>  Radoslaw Biernacki  
> 
> 
> 

Applied to my trivial-patches branch.

Thanks,
Laurent




[PULL 20/24] meson: add pixman dependency to UI modules

2020-09-01 Thread Paolo Bonzini
Pixman used to be included directly in QEMU_CFLAGS and therefore the
include path was added to every compiler invocation.  Now that (just
like basically everything else) it is a separate dependency, we
need to add it to all build target, especially UI modules that need
it due to their including ui/console.h.

Reported-by: Stefan Weil 
Signed-off-by: Paolo Bonzini 
---
 ui/meson.build | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ui/meson.build b/ui/meson.build
index aa8aa31516..82f60756d9 100644
--- a/ui/meson.build
+++ b/ui/meson.build
@@ -40,7 +40,7 @@ ui_modules = {}
 
 if config_host.has_key('CONFIG_CURSES')
   curses_ss = ss.source_set()
-  curses_ss.add(when: [curses, iconv], if_true: files('curses.c'))
+  curses_ss.add(when: [curses, iconv], if_true: [files('curses.c'), pixman])
   ui_modules += {'curses' : curses_ss}
 endif
 
@@ -48,7 +48,7 @@ if config_host.has_key('CONFIG_GTK')
   softmmu_ss.add(when: 'CONFIG_WIN32', if_true: files('win32-kbd-hook.c'))
 
   gtk_ss = ss.source_set()
-  gtk_ss.add(gtk, vte, files('gtk.c'))
+  gtk_ss.add(gtk, vte, pixman, files('gtk.c'))
   gtk_ss.add(when: [x11, 'CONFIG_X11'], if_true: files('x_keymap.c'))
   gtk_ss.add(when: [opengl, 'CONFIG_OPENGL'], if_true: files('gtk-egl.c'))
   gtk_ss.add(when: [opengl, 'CONFIG_GTK_GL'], if_true: files('gtk-gl-area.c'))
@@ -71,7 +71,7 @@ endif
 
 if config_host.has_key('CONFIG_SPICE') and config_host.has_key('CONFIG_GIO')
   spice_ss = ss.source_set()
-  spice_ss.add(spice, gio, files('spice-app.c'))
+  spice_ss.add(spice, gio, pixman, files('spice-app.c'))
   ui_modules += {'spice-app': spice_ss}
 endif
 
-- 
2.26.2





[PATCH v8 4/8] migration: Add yank feature

2020-09-01 Thread Lukas Straub
Register yank functions on sockets to shut them down.

Signed-off-by: Lukas Straub 
Acked-by: Stefan Hajnoczi 
Acked-by: Dr. David Alan Gilbert 
---
 migration/channel.c   | 12 
 migration/migration.c | 25 +
 migration/multifd.c   | 10 ++
 migration/qemu-file-channel.c |  6 ++
 migration/savevm.c|  6 ++
 5 files changed, 59 insertions(+)

diff --git a/migration/channel.c b/migration/channel.c
index 20e4c8e2dc..21fc8046b9 100644
--- a/migration/channel.c
+++ b/migration/channel.c
@@ -18,6 +18,8 @@
 #include "trace.h"
 #include "qapi/error.h"
 #include "io/channel-tls.h"
+#include "io/channel-socket.h"
+#include "qemu/yank.h"

 /**
  * @migration_channel_process_incoming - Create new incoming migration channel
@@ -35,6 +37,11 @@ void migration_channel_process_incoming(QIOChannel *ioc)
 trace_migration_set_incoming_channel(
 ioc, object_get_typename(OBJECT(ioc)));

+if (object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET)) {
+yank_register_function("migration", yank_generic_iochannel,
+   QIO_CHANNEL(ioc));
+}
+
 if (s->parameters.tls_creds &&
 *s->parameters.tls_creds &&
 !object_dynamic_cast(OBJECT(ioc),
@@ -67,6 +74,11 @@ void migration_channel_connect(MigrationState *s,
 ioc, object_get_typename(OBJECT(ioc)), hostname, error);

 if (!error) {
+if (object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET)) {
+yank_register_function("migration", yank_generic_iochannel,
+   QIO_CHANNEL(ioc));
+}
+
 if (s->parameters.tls_creds &&
 *s->parameters.tls_creds &&
 !object_dynamic_cast(OBJECT(ioc),
diff --git a/migration/migration.c b/migration/migration.c
index 58a5452471..61a9e87d22 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -56,6 +56,7 @@
 #include "net/announce.h"
 #include "qemu/queue.h"
 #include "multifd.h"
+#include "qemu/yank.h"

 #define MAX_THROTTLE  (32 << 20)  /* Migration transfer speed throttling */

@@ -244,6 +245,8 @@ void migration_incoming_state_destroy(void)
 qapi_free_SocketAddressList(mis->socket_address_list);
 mis->socket_address_list = NULL;
 }
+
+yank_unregister_instance("migration");
 }

 static void migrate_generate_event(int new_state)
@@ -380,8 +383,14 @@ void qemu_start_incoming_migration(const char *uri, Error 
**errp)
 {
 const char *p = NULL;

+yank_register_instance("migration", errp);
+if (*errp) {
+return;
+}
+
 qapi_event_send_migration(MIGRATION_STATUS_SETUP);
 if (!strcmp(uri, "defer")) {
+yank_unregister_instance("migration");
 deferred_incoming_migration(errp);
 } else if (strstart(uri, "tcp:", &p) ||
strstart(uri, "unix:", NULL) ||
@@ -396,6 +405,7 @@ void qemu_start_incoming_migration(const char *uri, Error 
**errp)
 } else if (strstart(uri, "fd:", &p)) {
 fd_start_incoming_migration(p, errp);
 } else {
+yank_unregister_instance("migration");
 error_setg(errp, "unknown migration protocol: %s", uri);
 }
 }
@@ -1692,6 +1702,7 @@ static void migrate_fd_cleanup(MigrationState *s)
 }
 notifier_list_notify(&migration_state_notifiers, s);
 block_cleanup_parameters(s);
+yank_unregister_instance("migration");
 }

 static void migrate_fd_cleanup_schedule(MigrationState *s)
@@ -1965,6 +1976,7 @@ void qmp_migrate_recover(const char *uri, Error **errp)
  * only re-setup the migration stream and poke existing migration
  * to continue using that newly established channel.
  */
+yank_unregister_instance("migration");
 qemu_start_incoming_migration(uri, errp);
 }

@@ -2102,6 +2114,13 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 return;
 }

+if (!(has_resume && resume)) {
+yank_register_instance("migration", errp);
+if (*errp) {
+return;
+}
+}
+
 if (strstart(uri, "tcp:", &p) ||
 strstart(uri, "unix:", NULL) ||
 strstart(uri, "vsock:", NULL)) {
@@ -2115,6 +2134,9 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 } else if (strstart(uri, "fd:", &p)) {
 fd_start_outgoing_migration(s, p, &local_err);
 } else {
+if (!(has_resume && resume)) {
+yank_unregister_instance("migration");
+}
 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri",
"a valid migration protocol");
 migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
@@ -2124,6 +2146,9 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 }

 if (local_err) {
+if (!(has_resume && resume)) {
+yank_unregister_instance("migration");
+}
 migrate_fd_error(s, local_err);
 error_propagate(errp, local_err);
 return;
diff --git a/migration/mul

[PATCH v8 3/8] chardev/char-socket.c: Add yank feature

2020-09-01 Thread Lukas Straub
Register a yank function to shutdown the socket on yank.

Signed-off-by: Lukas Straub 
Acked-by: Stefan Hajnoczi 
Reviewed-by: Daniel P. Berrangé 
---
 chardev/char-socket.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index ef62dbf3d7..8e2865ca83 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -34,6 +34,7 @@
 #include "qapi/error.h"
 #include "qapi/clone-visitor.h"
 #include "qapi/qapi-visit-sockets.h"
+#include "qemu/yank.h"

 #include "chardev/char-io.h"

@@ -69,6 +70,7 @@ typedef struct {
 size_t read_msgfds_num;
 int *write_msgfds;
 size_t write_msgfds_num;
+char *yank_name;

 SocketAddress *addr;
 bool is_listen;
@@ -413,6 +415,11 @@ static void tcp_chr_free_connection(Chardev *chr)

 tcp_set_msgfds(chr, NULL, 0);
 remove_fd_in_watch(chr);
+if (s->state == TCP_CHARDEV_STATE_CONNECTING
+|| s->state == TCP_CHARDEV_STATE_CONNECTED) {
+yank_unregister_function(s->yank_name, yank_generic_iochannel,
+ QIO_CHANNEL(s->sioc));
+}
 object_unref(OBJECT(s->sioc));
 s->sioc = NULL;
 object_unref(OBJECT(s->ioc));
@@ -916,6 +923,8 @@ static int tcp_chr_add_client(Chardev *chr, int fd)
 }
 tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
 tcp_chr_set_client_ioc_name(chr, sioc);
+yank_register_function(s->yank_name, yank_generic_iochannel,
+   QIO_CHANNEL(sioc));
 ret = tcp_chr_new_client(chr, sioc);
 object_unref(OBJECT(sioc));
 return ret;
@@ -930,6 +939,8 @@ static void tcp_chr_accept(QIONetListener *listener,

 tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
 tcp_chr_set_client_ioc_name(chr, cioc);
+yank_register_function(s->yank_name, yank_generic_iochannel,
+   QIO_CHANNEL(cioc));
 tcp_chr_new_client(chr, cioc);
 }

@@ -945,6 +956,8 @@ static int tcp_chr_connect_client_sync(Chardev *chr, Error 
**errp)
 object_unref(OBJECT(sioc));
 return -1;
 }
+yank_register_function(s->yank_name, yank_generic_iochannel,
+   QIO_CHANNEL(sioc));
 tcp_chr_new_client(chr, sioc);
 object_unref(OBJECT(sioc));
 return 0;
@@ -960,6 +973,8 @@ static void tcp_chr_accept_server_sync(Chardev *chr)
 tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
 sioc = qio_net_listener_wait_client(s->listener);
 tcp_chr_set_client_ioc_name(chr, sioc);
+yank_register_function(s->yank_name, yank_generic_iochannel,
+   QIO_CHANNEL(sioc));
 tcp_chr_new_client(chr, sioc);
 object_unref(OBJECT(sioc));
 }
@@ -1070,6 +1085,10 @@ static void char_socket_finalize(Object *obj)
 object_unref(OBJECT(s->tls_creds));
 }
 g_free(s->tls_authz);
+if (s->yank_name) {
+yank_unregister_instance(s->yank_name);
+g_free(s->yank_name);
+}

 qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
 }
@@ -1085,6 +1104,8 @@ static void qemu_chr_socket_connected(QIOTask *task, void 
*opaque)

 if (qio_task_propagate_error(task, &err)) {
 tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);
+yank_unregister_function(s->yank_name, yank_generic_iochannel,
+ QIO_CHANNEL(sioc));
 check_report_connect_error(chr, err);
 goto cleanup;
 }
@@ -1118,6 +1139,8 @@ static void tcp_chr_connect_client_async(Chardev *chr)
 tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
 sioc = qio_channel_socket_new();
 tcp_chr_set_client_ioc_name(chr, sioc);
+yank_register_function(s->yank_name, yank_generic_iochannel,
+   QIO_CHANNEL(sioc));
 /*
  * Normally code would use the qio_channel_socket_connect_async
  * method which uses a QIOTask + qio_task_set_error internally
@@ -1360,6 +1383,14 @@ static void qmp_chardev_open_socket(Chardev *chr,
 qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_FD_PASS);
 }

+s->yank_name = g_strconcat("chardev:", chr->label, NULL);
+yank_register_instance(s->yank_name, errp);
+if (*errp) {
+g_free(s->yank_name);
+s->yank_name = NULL;
+return;
+}
+
 /* be isn't opened until we get a connection */
 *be_opened = false;

--
2.20.1



pgppGpzZvm8xq.pgp
Description: OpenPGP digital signature


[PULL 24/24] meson: add description to options

2020-09-01 Thread Paolo Bonzini
This will be useful in the future to generate configure
command line parsing from meson_options.txt.

Signed-off-by: Paolo Bonzini 
---
 meson_options.txt | 29 -
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/meson_options.txt b/meson_options.txt
index c3120fa359..3e772f55b3 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -2,12 +2,23 @@ option('qemu_suffix', type : 'string', value: 'qemu',
description: 'Suffix for QEMU data/modules/config directories (can be 
empty)')
 option('docdir', type : 'string', value : 'doc',
description: 'Base directory for documentation installation (can be 
empty)')
-option('gettext', type : 'boolean', value : true)
-option('sdl', type : 'feature', value : 'auto')
-option('sdl_image', type : 'feature', value : 'auto')
-option('u2f', type : 'feature', value : 'auto')
-option('vnc', type : 'feature', value : 'enabled')
-option('vnc_jpeg', type : 'feature', value : 'auto')
-option('vnc_png', type : 'feature', value : 'auto')
-option('vnc_sasl', type : 'feature', value : 'auto')
-option('xkbcommon', type : 'feature', value : 'auto')
+
+option('gettext', type : 'boolean', value : true,
+   description: 'Localizationo of the GTK+ user interface')
+
+option('sdl', type : 'feature', value : 'auto',
+   description: 'SDL user interface')
+option('sdl_image', type : 'feature', value : 'auto',
+   description: 'SDL Image support for icons')
+option('u2f', type : 'feature', value : 'auto',
+   description: 'U2F emulation support')
+option('vnc', type : 'feature', value : 'enabled',
+   description: 'VNC server')
+option('vnc_jpeg', type : 'feature', value : 'auto',
+   description: 'JPEG lossy compression for VNC server')
+option('vnc_png', type : 'feature', value : 'auto',
+   description: 'PNG compression for VNC server')
+option('vnc_sasl', type : 'feature', value : 'auto',
+   description: 'SASL authentication for VNC server')
+option('xkbcommon', type : 'feature', value : 'auto',
+   description: 'xkbcommon support')
-- 
2.26.2




[PATCH v8 0/8] Introduce 'yank' oob qmp command to recover from hanging qemu

2020-09-01 Thread Lukas Straub
Hello Everyone,
So here is v8. We still need ACKs from NBD and chardev maintainers.

Changes:

v8:
 -add Reviewed-by and Acked-by tags
 -rebase onto master
  -minor change to migration
  -convert to meson
 -change "Since:" to 5.2
 -varios code style fixes (Markus Armbruster)
 -point to oob restrictions in comment to yank_register_function
  (Markus Armbruster)
 -improve qmp documentation (Markus Armbruster)
 -document oob suitability of qio_channel and io_shutdown (Markus Armbruster)

v7:
 -yank_register_instance now returns error via Error **errp instead of aborting
 -dropped "chardev/char.c: Check for duplicate id before  creating chardev"

v6:
 -add Reviewed-by and Acked-by tags
 -rebase on master
 -lots of changes in nbd due to rebase
 -only take maintainership of util/yank.c and include/qemu/yank.h (Daniel P. 
Berrangé)
 -fix a crash discovered by the newly added chardev test
 -fix the test itself

v5:
 -move yank.c to util/
 -move yank.h to include/qemu/
 -add license to yank.h
 -use const char*
 -nbd: use atomic_store_release and atomic_load_aqcuire
 -io-channel: ensure thread-safety and document it
 -add myself as maintainer for yank

v4:
 -fix build errors...

v3:
 -don't touch softmmu/vl.c, use __contructor__ attribute instead (Paolo Bonzini)
 -fix build errors
 -rewrite migration patch so it actually passes all tests

v2:
 -don't touch io/ code anymore
 -always register yank functions
 -'yank' now takes a list of instances to yank
 -'query-yank' returns a list of yankable instances

Overview:
Hello Everyone,
In many cases, if qemu has a network connection (qmp, migration, chardev, etc.)
to some other server and that server dies or hangs, qemu hangs too.
These patches introduce the new 'yank' out-of-band qmp command to recover from
these kinds of hangs. The different subsystems register callbacks which get
executed with the yank command. For example the callback can shutdown() a
socket. This is intended for the colo use-case, but it can be used for other
things too of course.

Regards,
Lukas Straub

Lukas Straub (8):
  Introduce yank feature
  block/nbd.c: Add yank feature
  chardev/char-socket.c: Add yank feature
  migration: Add yank feature
  io/channel-tls.c: make qio_channel_tls_shutdown thread-safe
  io: Document qmp oob suitability of qio_channel_shutdown and
io_shutdown
  MAINTAINERS: Add myself as maintainer for yank feature
  tests/test-char.c: Wait for the chardev to connect in
char_socket_client_dupid_test

 MAINTAINERS   |   6 ++
 block/nbd.c   | 129 ++-
 chardev/char-socket.c |  31 ++
 include/io/channel.h  |   5 +-
 include/qemu/yank.h   |  81 +++
 io/channel-tls.c  |   6 +-
 migration/channel.c   |  12 +++
 migration/migration.c |  25 +
 migration/multifd.c   |  10 ++
 migration/qemu-file-channel.c |   6 ++
 migration/savevm.c|   6 ++
 qapi/misc.json|  62 +++
 tests/test-char.c |   1 +
 util/meson.build  |   1 +
 util/yank.c   | 187 ++
 15 files changed, 516 insertions(+), 52 deletions(-)
 create mode 100644 include/qemu/yank.h
 create mode 100644 util/yank.c

--
2.20.1


pgpZ_gkYEGL6Y.pgp
Description: OpenPGP digital signature


Re: [PATCH 0/7] block: Use definitions instead of magic values

2020-09-01 Thread Laurent Vivier
Le 14/08/2020 à 10:28, Philippe Mathieu-Daudé a écrit :
> Trivial block patches:
> - Fix a typo
> - Replace '1 << 30' by '1 * GiB' in null-co
> - Replace 512 by BDRV_SECTOR_SIZE when appropriate.
> 
> Philippe Mathieu-Daudé (7):
>   block/null: Make more explicit the driver default size is 1GiB
>   hw/ide/core: Trivial typo fix
>   hw/ide/core: Replace magic '512' value by BDRV_SECTOR_SIZE
>   hw/ide/ahci: Replace magic '512' value by BDRV_SECTOR_SIZE
>   hw/ide/atapi: Replace magic '512' value by BDRV_SECTOR_SIZE
>   hw/ide/pci: Replace magic '512' value by BDRV_SECTOR_SIZE
>   hw/scsi/scsi-disk: Replace magic '512' value by BDRV_SECTOR_SIZE
> 
>  block/null.c|  4 +++-
>  hw/ide/ahci.c   |  5 +++--
>  hw/ide/atapi.c  |  8 
>  hw/ide/core.c   | 25 +
>  hw/ide/pci.c|  2 +-
>  hw/scsi/scsi-disk.c | 44 +++-
>  6 files changed, 47 insertions(+), 41 deletions(-)
> 

Applied to my trivial-patches branch.

Except the following ones that have comment from Kevin:

[PATCH 1/7] block/null: Make more explicit the driver default size is 1GiB
[PATCH 3/7] hw/ide/core: Replace magic '512' value by BDRV_SECTOR_SIZE

Thanks,
Laurent



Re: [PATCH] docs/system/target-avr: Improve the AVR docs and add to MAINTAINERS

2020-09-01 Thread Laurent Vivier
Le 12/08/2020 à 17:53, Thomas Huth a écrit :
> The examples look nicer when using "::" code blocks.
> Also mention that "-d in_asm" only outputs instructions that have not
> been translated by the JIT layer yet.
> And while we're at it, also add the AVR doc file to the MAINTAINERS file.
> 
> Signed-off-by: Thomas Huth 
> ---
>  MAINTAINERS|  1 +
>  docs/system/target-avr.rst | 47 +++---
>  2 files changed, 30 insertions(+), 18 deletions(-)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 0886eb3d2b..5b21962bc6 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -171,6 +171,7 @@ AVR TCG CPUs
>  M: Michael Rolnik 
>  R: Sarah Harris 
>  S: Maintained
> +F: docs/system/target-avr.rst
>  F: gdb-xml/avr-cpu.xml
>  F: target/avr/
>  F: tests/acceptance/machine_avr6.py
> diff --git a/docs/system/target-avr.rst b/docs/system/target-avr.rst
> index dc99afc895..1410031f5e 100644
> --- a/docs/system/target-avr.rst
> +++ b/docs/system/target-avr.rst
> @@ -17,21 +17,32 @@ 
> https://github.com/seharris/qemu-avr-tests/blob/master/free-rtos/Demo/AVR_ATMega
>  Following are examples of possible usages, assuming demo.elf is compiled for
>  AVR cpu
>  
> - - Continuous non interrupted execution:
> -   ``qemu-system-avr -machine mega2560 -bios demo.elf``
> -
> - - Continuous non interrupted execution with serial output into telnet 
> window:
> -   ``qemu-system-avr -machine mega2560 -bios demo.elf -serial
> -   tcp::5678,server,nowait -nographic``
> -   and then in another shell
> -   ``telnet localhost 5678``
> -
> - - Debugging wit GDB debugger:
> -   ``qemu-system-avr -machine mega2560 -bios demo.elf -s -S``
> -   and then in another shell
> -   ``avr-gdb demo.elf``
> -   and then within GDB shell
> -   ``target remote :1234``
> -
> - - Print out executed instructions:
> -   ``qemu-system-avr -machine mega2560 -bios demo.elf -d in_asm``
> +- Continuous non interrupted execution::
> +
> +   qemu-system-avr -machine mega2560 -bios demo.elf
> +
> +- Continuous non interrupted execution with serial output into telnet 
> window::
> +
> +   qemu-system-avr -M mega2560 -bios demo.elf -nographic \
> +   -serial tcp::5678,server,nowait 
> +
> +  and then in another shell::
> +
> +   telnet localhost 5678
> +
> +- Debugging wit GDB debugger::
> +
> +   qemu-system-avr -machine mega2560 -bios demo.elf -s -S
> +
> +  and then in another shell::
> +
> +   avr-gdb demo.elf
> +
> +  and then within GDB shell::
> +
> +   target remote :1234
> +
> +- Print out executed instructions (that have not been translated by the JIT
> +  compiler yet)::
> +
> +   qemu-system-avr -machine mega2560 -bios demo.elf -d in_asm
> 

Applied to my trivial-patches branch.
(I have removed the trailing whitespace)

Thanks,
Laurent




[PATCH v8 6/8] io: Document qmp oob suitability of qio_channel_shutdown and io_shutdown

2020-09-01 Thread Lukas Straub
Migration and yank code assume that qio_channel_shutdown is thread
-safe and can be called from qmp oob handler. Document this after
checking the code.

Signed-off-by: Lukas Straub 
Acked-by: Stefan Hajnoczi 
---
 include/io/channel.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/io/channel.h b/include/io/channel.h
index d4557f0930..46156d84f5 100644
--- a/include/io/channel.h
+++ b/include/io/channel.h
@@ -98,7 +98,8 @@ struct QIOChannel {
  * provide additional optional features.
  *
  * Consult the corresponding public API docs for a description
- * of the semantics of each callback
+ * of the semantics of each callback. io_shutdown in particular
+ * must be thread-safe, terminate quickly and must not block.
  */
 struct QIOChannelClass {
 ObjectClass parent;
@@ -516,6 +517,8 @@ int qio_channel_close(QIOChannel *ioc,
  * QIO_CHANNEL_FEATURE_SHUTDOWN prior to calling
  * this method.
  *
+ * This function is thread-safe, terminates quickly and does not block.
+ *
  * Returns: 0 on success, -1 on error
  */
 int qio_channel_shutdown(QIOChannel *ioc,
--
2.20.1



pgpYgJDmWdnAx.pgp
Description: OpenPGP digital signature


Re: [PATCH] hw/net/xilinx_axienet: Remove unused code

2020-09-01 Thread Laurent Vivier
Le 14/08/2020 à 15:30, Philippe Mathieu-Daudé a écrit :
> Most of the MDIOBus fields are unused.  The ADVERTISE_10HALF
> definition is unused.  Remove unused code.
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/net/xilinx_axienet.c | 23 ---
>  1 file changed, 23 deletions(-)
> 
> diff --git a/hw/net/xilinx_axienet.c b/hw/net/xilinx_axienet.c
> index 1e48eb70c9..2e89f236b4 100644
> --- a/hw/net/xilinx_axienet.c
> +++ b/hw/net/xilinx_axienet.c
> @@ -54,7 +54,6 @@
>   TYPE_XILINX_AXI_ENET_CONTROL_STREAM)
>  
>  /* Advertisement control register. */
> -#define ADVERTISE_10HALF0x0020  /* Try for 10mbps half-duplex  */
>  #define ADVERTISE_10FULL0x0040  /* Try for 10mbps full-duplex  */
>  #define ADVERTISE_100HALF   0x0080  /* Try for 100mbps half-duplex */
>  #define ADVERTISE_100FULL   0x0100  /* Try for 100mbps full-duplex */
> @@ -169,28 +168,6 @@ tdk_init(struct PHY *phy)
>  }
>  
>  struct MDIOBus {
> -/* bus.  */
> -int mdc;
> -int mdio;
> -
> -/* decoder.  */
> -enum {
> -PREAMBLE,
> -SOF,
> -OPC,
> -ADDR,
> -REQ,
> -TURNAROUND,
> -DATA
> -} state;
> -unsigned int drive;
> -
> -unsigned int cnt;
> -unsigned int addr;
> -unsigned int opc;
> -unsigned int req;
> -unsigned int data;
> -
>  struct PHY *devs[32];
>  };
>  
> 

Applied to my trivial-patches branch.

Thanks,
Laurent




Re: [PATCH 01/13] fuzz: use qemu_get_exec_dir

2020-09-01 Thread Thomas Huth
On 01/09/2020 08.20, Paolo Bonzini wrote:
> Make things consistent with how softmmu/vl.c uses os_find_datadir.
> Initializing the path to the executables will also be needed for
> get_relocatable_path to work.
> 
> Signed-off-by: Paolo Bonzini 
> ---
>  tests/qtest/fuzz/fuzz.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c
> index 1ceea84702..391223219d 100644
> --- a/tests/qtest/fuzz/fuzz.c
> +++ b/tests/qtest/fuzz/fuzz.c
> @@ -152,6 +152,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char 
> ***envp)
>  module_call_init(MODULE_INIT_QOM);
>  module_call_init(MODULE_INIT_LIBQOS);
>  
> +qemu_init_exec_dir(**argv);
>  target_name = strstr(**argv, "-target-");
>  if (target_name) {/* The binary name specifies the target */
>  target_name += strlen("-target-");
> @@ -164,7 +165,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char 
> ***envp)
>   * location of the executable. Using this we add exec_dir/pc-bios to
>   * the datadirs.
>   */
> -bindir = g_path_get_dirname(**argv);
> +bindir = qemu_get_exec_dir();
>  datadir = g_build_filename(bindir, "pc-bios", NULL);
>  g_free(bindir);
>  if (g_file_test(datadir, G_FILE_TEST_IS_DIR)) {
> 

Reviewed-by: Thomas Huth 




Re: [PATCH v6 13/16] hvf: remove hvf specific functions from global includes

2020-09-01 Thread Roman Bolshakov
On Tue, Sep 01, 2020 at 09:21:58AM +0200, Claudio Fontana wrote:
> Signed-off-by: Claudio Fontana 
> Reviewed-by: Richard Henderson 
> ---
>  accel/stubs/hvf-stub.c | 30 --
>  accel/stubs/meson.build|  1 -
>  include/sysemu/hvf.h   |  8 
>  target/i386/hvf/hvf-cpus.h |  8 
>  target/i386/hvf/x86hvf.c   |  2 ++
>  target/i386/hvf/x86hvf.h   |  1 -
>  6 files changed, 10 insertions(+), 40 deletions(-)
>  delete mode 100644 accel/stubs/hvf-stub.c
> 

Reviewed-by: Roman Bolshakov 

Thanks,
Roman



[PATCH v8 2/8] block/nbd.c: Add yank feature

2020-09-01 Thread Lukas Straub
Register a yank function which shuts down the socket and sets
s->state = NBD_CLIENT_QUIT. This is the same behaviour as if an
error occured.

Signed-off-by: Lukas Straub 
Acked-by: Stefan Hajnoczi 
Reviewed-by: Daniel P. Berrangé 
---
 block/nbd.c | 129 
 1 file changed, 80 insertions(+), 49 deletions(-)

diff --git a/block/nbd.c b/block/nbd.c
index 7bb881fef4..8632cf5340 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -35,6 +35,7 @@
 #include "qemu/option.h"
 #include "qemu/cutils.h"
 #include "qemu/main-loop.h"
+#include "qemu/atomic.h"

 #include "qapi/qapi-visit-sockets.h"
 #include "qapi/qmp/qstring.h"
@@ -43,6 +44,8 @@
 #include "block/nbd.h"
 #include "block/block_int.h"

+#include "qemu/yank.h"
+
 #define EN_OPTSTR ":exportname="
 #define MAX_NBD_REQUESTS16

@@ -84,6 +87,8 @@ typedef struct BDRVNBDState {
 NBDReply reply;
 BlockDriverState *bs;

+char *yank_name;
+
 /* Connection parameters */
 uint32_t reconnect_delay;
 SocketAddress *saddr;
@@ -93,10 +98,10 @@ typedef struct BDRVNBDState {
 char *x_dirty_bitmap;
 } BDRVNBDState;

-static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr,
-  Error **errp);
-static int nbd_client_handshake(BlockDriverState *bs, QIOChannelSocket *sioc,
-Error **errp);
+static int nbd_establish_connection(BlockDriverState *bs, SocketAddress *saddr,
+Error **errp);
+static int nbd_client_handshake(BlockDriverState *bs, Error **errp);
+static void nbd_yank(void *opaque);

 static void nbd_clear_bdrvstate(BDRVNBDState *s)
 {
@@ -109,17 +114,19 @@ static void nbd_clear_bdrvstate(BDRVNBDState *s)
 s->tlscredsid = NULL;
 g_free(s->x_dirty_bitmap);
 s->x_dirty_bitmap = NULL;
+g_free(s->yank_name);
+s->yank_name = NULL;
 }

 static void nbd_channel_error(BDRVNBDState *s, int ret)
 {
 if (ret == -EIO) {
-if (s->state == NBD_CLIENT_CONNECTED) {
+if (atomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED) {
 s->state = s->reconnect_delay ? NBD_CLIENT_CONNECTING_WAIT :
 NBD_CLIENT_CONNECTING_NOWAIT;
 }
 } else {
-if (s->state == NBD_CLIENT_CONNECTED) {
+if (atomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED) {
 qio_channel_shutdown(s->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
 }
 s->state = NBD_CLIENT_QUIT;
@@ -170,7 +177,7 @@ static void nbd_client_attach_aio_context(BlockDriverState 
*bs,
  * s->connection_co is either yielded from nbd_receive_reply or from
  * nbd_co_reconnect_loop()
  */
-if (s->state == NBD_CLIENT_CONNECTED) {
+if (atomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED) {
 qio_channel_attach_aio_context(QIO_CHANNEL(s->ioc), new_context);
 }

@@ -237,20 +244,20 @@ static void nbd_teardown_connection(BlockDriverState *bs)

 static bool nbd_client_connecting(BDRVNBDState *s)
 {
-return s->state == NBD_CLIENT_CONNECTING_WAIT ||
-s->state == NBD_CLIENT_CONNECTING_NOWAIT;
+NBDClientState state = atomic_load_acquire(&s->state);
+return state == NBD_CLIENT_CONNECTING_WAIT ||
+state == NBD_CLIENT_CONNECTING_NOWAIT;
 }

 static bool nbd_client_connecting_wait(BDRVNBDState *s)
 {
-return s->state == NBD_CLIENT_CONNECTING_WAIT;
+return atomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTING_WAIT;
 }

 static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s)
 {
 int ret;
 Error *local_err = NULL;
-QIOChannelSocket *sioc;

 if (!nbd_client_connecting(s)) {
 return;
@@ -283,21 +290,21 @@ static coroutine_fn void 
nbd_reconnect_attempt(BDRVNBDState *s)
 /* Finalize previous connection if any */
 if (s->ioc) {
 nbd_client_detach_aio_context(s->bs);
+yank_unregister_function(s->yank_name, nbd_yank, s->bs);
 object_unref(OBJECT(s->sioc));
 s->sioc = NULL;
 object_unref(OBJECT(s->ioc));
 s->ioc = NULL;
 }

-sioc = nbd_establish_connection(s->saddr, &local_err);
-if (!sioc) {
+if (nbd_establish_connection(s->bs, s->saddr, &local_err) < 0) {
 ret = -ECONNREFUSED;
 goto out;
 }

 bdrv_dec_in_flight(s->bs);

-ret = nbd_client_handshake(s->bs, sioc, &local_err);
+ret = nbd_client_handshake(s->bs, &local_err);

 if (s->drained) {
 s->wait_drained_end = true;
@@ -334,7 +341,7 @@ static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDState 
*s)
 nbd_reconnect_attempt(s);

 while (nbd_client_connecting(s)) {
-if (s->state == NBD_CLIENT_CONNECTING_WAIT &&
+if (atomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTING_WAIT &&
 qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start_time_ns > delay_ns)
 {
 s->state = NBD_CLIENT_CONNECTING_NOWAIT;
@@ -371,7 +378,7 @@ static cor

Re: [PATCH v6 11/16] cpus: remove checks for non-NULL cpus_accel

2020-09-01 Thread Roman Bolshakov
On Tue, Sep 01, 2020 at 09:21:56AM +0200, Claudio Fontana wrote:
> now that all accelerators support the CpusAccel interface,
> we can remove most checks for non-NULL cpus_accel,
> we just add a sanity check/assert at vcpu creation.
> 
> Signed-off-by: Claudio Fontana 
> ---
>  softmmu/cpus.c | 33 +
>  1 file changed, 21 insertions(+), 12 deletions(-)
> 
> diff --git a/softmmu/cpus.c b/softmmu/cpus.c
> index 3d8350fba9..f32ecb4bb9 100644
> --- a/softmmu/cpus.c
> +++ b/softmmu/cpus.c
> @@ -166,34 +166,46 @@ void cpu_synchronize_all_pre_loadvm(void)
>  
>  void cpu_synchronize_state(CPUState *cpu)
>  {
> -if (cpus_accel && cpus_accel->synchronize_state) {
> +if (cpus_accel->synchronize_state) {
>  cpus_accel->synchronize_state(cpu);
>  }
>  }
>  
>  void cpu_synchronize_post_reset(CPUState *cpu)
>  {
> -if (cpus_accel && cpus_accel->synchronize_post_reset) {
> +if (cpus_accel->synchronize_post_reset) {
>  cpus_accel->synchronize_post_reset(cpu);
>  }
>  }
>  
>  void cpu_synchronize_post_init(CPUState *cpu)
>  {
> -if (cpus_accel && cpus_accel->synchronize_post_init) {
> +if (cpus_accel->synchronize_post_init) {
>  cpus_accel->synchronize_post_init(cpu);
>  }
>  }
>  
>  void cpu_synchronize_pre_loadvm(CPUState *cpu)
>  {
> -if (cpus_accel && cpus_accel->synchronize_pre_loadvm) {
> +if (cpus_accel->synchronize_pre_loadvm) {
>  cpus_accel->synchronize_pre_loadvm(cpu);
>  }
>  }
>  
>  int64_t cpus_get_virtual_clock(void)
>  {
> +/*
> + * XXX
> + *
> + * need to check that cpus_accel is not NULL, because qcow2 calls
> + * qemu_get_clock_ns(CLOCK_VIRTUAL) without any accel initialized and
> + * with ticks disabled in some io-tests:
> + * 030 040 041 060 099 120 127 140 156 161 172 181 191 192 195 203 229 
> 249 256 267
> + *
> + * is this expected?
> + *
> + * XXX
> + */
>  if (cpus_accel && cpus_accel->get_virtual_clock) {
>  return cpus_accel->get_virtual_clock();
>  }
> @@ -207,7 +219,7 @@ int64_t cpus_get_virtual_clock(void)
>   */
>  int64_t cpus_get_elapsed_ticks(void)
>  {
> -if (cpus_accel && cpus_accel->get_elapsed_ticks) {
> +if (cpus_accel->get_elapsed_ticks) {
>  return cpus_accel->get_elapsed_ticks();
>  }
>  return cpu_get_ticks();
> @@ -399,7 +411,7 @@ void cpus_kick_thread(CPUState *cpu)
>  void qemu_cpu_kick(CPUState *cpu)
>  {
>  qemu_cond_broadcast(cpu->halt_cond);
> -if (cpus_accel && cpus_accel->kick_vcpu_thread) {
> +if (cpus_accel->kick_vcpu_thread) {
>  cpus_accel->kick_vcpu_thread(cpu);
>  } else { /* default */
>  cpus_kick_thread(cpu);
> @@ -573,12 +585,9 @@ void qemu_init_vcpu(CPUState *cpu)
>  cpu_address_space_init(cpu, 0, "cpu-memory", cpu->memory);
>  }
>  
> -if (cpus_accel) {
> -/* accelerator already implements the CpusAccel interface */
> -cpus_accel->create_vcpu_thread(cpu);
> -} else {
> -g_assert_not_reached();
> -}
> +/* accelerators all implement the CpusAccel interface */
> +g_assert(cpus_accel != NULL && cpus_accel->create_vcpu_thread != NULL);
> +cpus_accel->create_vcpu_thread(cpu);
>  
>  while (!cpu->created) {
>  qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
> -- 
> 2.26.2
> 

Reviewed-by: Roman Bolshakov 

but I still find the condition (if cpus_accel->func) redundant, is it
feasible to drop it?

Regards,
Roman



Re: [PATCH v4 9/9] scsi/scsi_bus: fix races in REPORT LUNS

2020-09-01 Thread Maxim Levitsky
On Mon, 2020-08-31 at 18:01 +0300, Maxim Levitsky wrote:
> Currently scsi_target_emulate_report_luns iterates
> over child devices list twice, and there is guarantee, that
> it will not be changed meanwhile.
> 
> This reason for two loops is that it needs to know how much memory
> to allocate.
> 
> Avoid this by iterating once, and allocating the memory for the output
> dynamically with reserving enought memory so that in practice it won't
> be reallocated often.
Just too many spelling/grammar mistakes in the commit message. Sorry about that.

It should be something like that:

Currently scsi_target_emulate_report_luns iterates over the child device list
twice, and there is no guarantee that this list is the same in both iterations.

The reason for iterating twise is that the first iteration calculates 
how much memory to allocate.

However if we use a dynamic array we can avoid iterating twice, and therefore
we avoid this race.

Best regards,
Maxim Levitsky


> 
> Bugzilla for reference: https://bugzilla.redhat.com/show_bug.cgi?id=1866707
> 
> Signed-off-by: Maxim Levitsky 
> ---
>  hw/scsi/scsi-bus.c | 62 ++
>  1 file changed, 29 insertions(+), 33 deletions(-)
> 
> diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
> index feab20b76d..150dee2e6a 100644
> --- a/hw/scsi/scsi-bus.c
> +++ b/hw/scsi/scsi-bus.c
> @@ -438,19 +438,25 @@ struct SCSITargetReq {
>  static void store_lun(uint8_t *outbuf, int lun)
>  {
>  if (lun < 256) {
> +/* Simple logical unit addressing method*/
> +outbuf[0] = 0;
>  outbuf[1] = lun;
> -return;
> +} else {
> +/* Flat space addressing method */
> +outbuf[0] = 0x40 | (lun >> 8);
> +outbuf[1] = (lun & 255);
>  }
> -outbuf[1] = (lun & 255);
> -outbuf[0] = (lun >> 8) | 0x40;
>  }
>  
>  static bool scsi_target_emulate_report_luns(SCSITargetReq *r)
>  {
>  BusChild *kid;
> -int i, len, n;
>  int channel, id;
> -bool found_lun0;
> +uint8_t tmp[8] = {0};
> +int len = 0;
> +
> +/* reserve space for 63 LUNs*/
> +GByteArray *buf = g_byte_array_sized_new(512);
>  
>  if (r->req.cmd.xfer < 16) {
>  return false;
> @@ -460,46 +466,36 @@ static bool 
> scsi_target_emulate_report_luns(SCSITargetReq *r)
>  }
>  channel = r->req.dev->channel;
>  id = r->req.dev->id;
> -found_lun0 = false;
> -n = 0;
>  
> -rcu_read_lock();
>  
> -QTAILQ_FOREACH_RCU(kid, &r->req.bus->qbus.children, sibling) {
> -DeviceState *qdev = kid->child;
> -SCSIDevice *dev = SCSI_DEVICE(qdev);
> +/* add size (will be updated later to correct value */
> +g_byte_array_append(buf, tmp, 8);
> +len += 8;
>  
> -if (dev->channel == channel && dev->id == id) {
> -if (dev->lun == 0) {
> -found_lun0 = true;
> -}
> -n += 8;
> -}
> -}
> -if (!found_lun0) {
> -n += 8;
> -}
> -
> -scsi_target_alloc_buf(&r->req, n + 8);
> +/* add LUN0 */
> +g_byte_array_append(buf, tmp, 8);
> +len += 8;
>  
> -len = MIN(n + 8, r->req.cmd.xfer & ~7);
> -memset(r->buf, 0, len);
> -stl_be_p(&r->buf[0], n);
> -i = found_lun0 ? 8 : 16;
> +rcu_read_lock();
>  QTAILQ_FOREACH_RCU(kid, &r->req.bus->qbus.children, sibling) {
>  DeviceState *qdev = kid->child;
>  SCSIDevice *dev = SCSI_DEVICE(qdev);
>  
> -if (dev->channel == channel && dev->id == id) {
> -store_lun(&r->buf[i], dev->lun);
> -i += 8;
> +if (dev->channel == channel && dev->id == id && dev->lun != 0) {
> +store_lun(tmp, dev->lun);
> +g_byte_array_append(buf, tmp, 8);
> +len += 8;
>  }
>  }
> -
>  rcu_read_unlock();
>  
> -assert(i == n + 8);
> -r->len = len;
> +r->buf_len = len;
> +r->buf = g_byte_array_free(buf, FALSE);
> +r->len = MIN(len, r->req.cmd.xfer & ~7);
> +
> +/* store the LUN list length */
> +stl_be_p(&r->buf[0], len - 8);
> +
>  return true;
>  }
>  





Re: [PATCH] util/vfio-helpers: Unify trace-events size format

2020-09-01 Thread Laurent Vivier
Le 20/08/2020 à 19:10, Philippe Mathieu-Daudé a écrit :
> Some 'qemu_vfio_*' trace events sizes are displayed using
> decimal notation, other using hexadecimal notation:
> 
>   qemu_vfio_ram_block_added s 0xf2448d90 host 0x5bc0 size 
> 0x400
>   qemu_vfio_dma_map s 0xf2448d90 host 0x5bc0 size 67108864 
> temporary 0 iova (nil)
>   qemu_vfio_find_mapping s 0xf2448d90 host 0x5bc0
>   qemu_vfio_new_mapping s 0xf2448d90 host 0x5bc0 size 67108864 
> index 4 iova 0x114000
>   qemu_vfio_do_mapping s 0xf2448d90 host 0x5bc0 size 67108864 
> iova 0x114000
> 
> As it is hard to follow, unify using hexadecimal for all sizes:
> 
>   qemu_vfio_ram_block_added s 0xf1c60d90 host 0x2bc0 size 
> 0x400
>   qemu_vfio_dma_map s 0xf1c60d90 host 0x2bc0 size 0x400 
> temporary 0 iova (nil)
>   qemu_vfio_find_mapping s 0xf1c60d90 host 0x2bc0
>   qemu_vfio_new_mapping s 0xf1c60d90 host 0x2bc0 size 0x400 
> index 4 iova 0x114000
>   qemu_vfio_do_mapping s 0xf1c60d90 host 0x2bc0 size 0x400 
> iova 0x114000
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  util/trace-events | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/util/trace-events b/util/trace-events
> index 0ce42822eba..d9a0b4f8c63 100644
> --- a/util/trace-events
> +++ b/util/trace-events
> @@ -79,7 +79,7 @@ qemu_vfio_dma_reset_temporary(void *s) "s %p"
>  qemu_vfio_ram_block_added(void *s, void *p, size_t size) "s %p host %p size 
> 0x%zx"
>  qemu_vfio_ram_block_removed(void *s, void *p, size_t size) "s %p host %p 
> size 0x%zx"
>  qemu_vfio_find_mapping(void *s, void *p) "s %p host %p"
> -qemu_vfio_new_mapping(void *s, void *host, size_t size, int index, uint64_t 
> iova) "s %p host %p size %zu index %d iova 0x%"PRIx64
> -qemu_vfio_do_mapping(void *s, void *host, size_t size, uint64_t iova) "s %p 
> host %p size %zu iova 0x%"PRIx64
> -qemu_vfio_dma_map(void *s, void *host, size_t size, bool temporary, uint64_t 
> *iova) "s %p host %p size %zu temporary %d iova %p"
> +qemu_vfio_new_mapping(void *s, void *host, size_t size, int index, uint64_t 
> iova) "s %p host %p size 0x%zx index %d iova 0x%"PRIx64
> +qemu_vfio_do_mapping(void *s, void *host, size_t size, uint64_t iova) "s %p 
> host %p size 0x%zx iova 0x%"PRIx64
> +qemu_vfio_dma_map(void *s, void *host, size_t size, bool temporary, uint64_t 
> *iova) "s %p host %p size 0x%zx temporary %d iova %p"
>  qemu_vfio_dma_unmap(void *s, void *host) "s %p host %p"
> 

Applied to my trivial-patches branch.

Thanks,
Laurent




[PATCH v8 5/8] io/channel-tls.c: make qio_channel_tls_shutdown thread-safe

2020-09-01 Thread Lukas Straub
Make qio_channel_tls_shutdown thread-safe by using atomics when
accessing tioc->shutdown.

Signed-off-by: Lukas Straub 
Acked-by: Stefan Hajnoczi 
Reviewed-by: Daniel P. Berrangé 
---
 io/channel-tls.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/io/channel-tls.c b/io/channel-tls.c
index 7ec8ceff2f..b350c84640 100644
--- a/io/channel-tls.c
+++ b/io/channel-tls.c
@@ -23,6 +23,7 @@
 #include "qemu/module.h"
 #include "io/channel-tls.h"
 #include "trace.h"
+#include "qemu/atomic.h"


 static ssize_t qio_channel_tls_write_handler(const char *buf,
@@ -277,7 +278,8 @@ static ssize_t qio_channel_tls_readv(QIOChannel *ioc,
 return QIO_CHANNEL_ERR_BLOCK;
 }
 } else if (errno == ECONNABORTED &&
-   (tioc->shutdown & QIO_CHANNEL_SHUTDOWN_READ)) {
+   (atomic_load_acquire(&tioc->shutdown) &
+QIO_CHANNEL_SHUTDOWN_READ)) {
 return 0;
 }

@@ -361,7 +363,7 @@ static int qio_channel_tls_shutdown(QIOChannel *ioc,
 {
 QIOChannelTLS *tioc = QIO_CHANNEL_TLS(ioc);

-tioc->shutdown |= how;
+atomic_or(&tioc->shutdown, how);

 return qio_channel_shutdown(tioc->master, how, errp);
 }
--
2.20.1



pgpedP5RzLChg.pgp
Description: OpenPGP digital signature


Re: [PATCH v6 12/16] cpus: add handle_interrupt to the CpusAccel interface

2020-09-01 Thread Roman Bolshakov
On Tue, Sep 01, 2020 at 09:21:57AM +0200, Claudio Fontana wrote:
> kvm: uses the generic handler
> qtest: uses the generic handler
> whpx: changed to use the generic handler (identical implementation)
> hax: changed to use the generic handler (identical implementation)
> hvf: changed to use the generic handler (identical implementation)
> tcg: adapt tcg-cpus to point to the tcg-specific handler
> 
> Signed-off-by: Claudio Fontana 
> ---
>  accel/tcg/tcg-all.c| 26 --
>  accel/tcg/tcg-cpus.c   | 28 
>  hw/core/cpu.c  | 13 -
>  include/hw/core/cpu.h  | 14 --
>  include/sysemu/cpus.h  |  2 ++
>  softmmu/cpus.c | 18 ++
>  target/i386/hax-all.c  | 10 --
>  target/i386/hvf/hvf.c  |  9 -
>  target/i386/whpx-all.c | 10 --
>  9 files changed, 48 insertions(+), 82 deletions(-)
> 
> diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
> index 01957b130d..af9bf5c5bb 100644
> --- a/accel/tcg/tcg-all.c
> +++ b/accel/tcg/tcg-all.c
> @@ -47,31 +47,6 @@ typedef struct TCGState {
>  #define TCG_STATE(obj) \
>  OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL)
>  
> -/* mask must never be zero, except for A20 change call */
> -static void tcg_handle_interrupt(CPUState *cpu, int mask)
> -{
> -int old_mask;
> -g_assert(qemu_mutex_iothread_locked());
> -
> -old_mask = cpu->interrupt_request;
> -cpu->interrupt_request |= mask;
> -
> -/*
> - * If called from iothread context, wake the target cpu in
> - * case its halted.
> - */
> -if (!qemu_cpu_is_self(cpu)) {
> -qemu_cpu_kick(cpu);
> -} else {
> -atomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1);
> -if (icount_enabled() &&
> -!cpu->can_do_io
> -&& (mask & ~old_mask) != 0) {
> -cpu_abort(cpu, "Raised interrupt while not in I/O function");
> -}
> -}
> -}
> -
>  /*
>   * We default to false if we know other options have been enabled
>   * which are currently incompatible with MTTCG. Otherwise when each
> @@ -128,7 +103,6 @@ static int tcg_init(MachineState *ms)
>  TCGState *s = TCG_STATE(current_accel());
>  
>  tcg_exec_init(s->tb_size * 1024 * 1024);
> -cpu_interrupt_handler = tcg_handle_interrupt;
>  mttcg_enabled = s->mttcg_enabled;
>  cpus_register_accel(&tcg_cpus);
>  
> diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
> index 72696f6d86..2bb209e2c6 100644
> --- a/accel/tcg/tcg-cpus.c
> +++ b/accel/tcg/tcg-cpus.c
> @@ -533,9 +533,37 @@ static int64_t tcg_get_elapsed_ticks(void)
>  return cpu_get_ticks();
>  }
>  
> +/* mask must never be zero, except for A20 change call */
> +static void tcg_handle_interrupt(CPUState *cpu, int mask)
> +{
> +int old_mask;
> +g_assert(qemu_mutex_iothread_locked());
> +
> +old_mask = cpu->interrupt_request;
> +cpu->interrupt_request |= mask;
> +
> +/*
> + * If called from iothread context, wake the target cpu in
> + * case its halted.
> + */
> +if (!qemu_cpu_is_self(cpu)) {
> +qemu_cpu_kick(cpu);
> +} else {
> +atomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1);
> +if (icount_enabled() &&
> +!cpu->can_do_io
> +&& (mask & ~old_mask) != 0) {
> +cpu_abort(cpu, "Raised interrupt while not in I/O function");
> +}
> +}
> +}
> +
>  const CpusAccel tcg_cpus = {
>  .create_vcpu_thread = tcg_start_vcpu_thread,
>  .kick_vcpu_thread = tcg_kick_vcpu_thread,
> +
> +.handle_interrupt = tcg_handle_interrupt,
> +
>  .get_virtual_clock = tcg_get_virtual_clock,
>  .get_elapsed_ticks = tcg_get_elapsed_ticks,
>  };
> diff --git a/hw/core/cpu.c b/hw/core/cpu.c
> index fa8602493b..451b3d5ee7 100644
> --- a/hw/core/cpu.c
> +++ b/hw/core/cpu.c
> @@ -35,8 +35,6 @@
>  #include "qemu/plugin.h"
>  #include "sysemu/hw_accel.h"
>  
> -CPUInterruptHandler cpu_interrupt_handler;
> -
>  CPUState *cpu_by_arch_id(int64_t id)
>  {
>  CPUState *cpu;
> @@ -394,17 +392,6 @@ static vaddr cpu_adjust_watchpoint_address(CPUState 
> *cpu, vaddr addr, int len)
>  return addr;
>  }
>  
> -static void generic_handle_interrupt(CPUState *cpu, int mask)
> -{
> -cpu->interrupt_request |= mask;
> -
> -if (!qemu_cpu_is_self(cpu)) {
> -qemu_cpu_kick(cpu);
> -}
> -}
> -
> -CPUInterruptHandler cpu_interrupt_handler = generic_handle_interrupt;
> -
>  static void cpu_class_init(ObjectClass *klass, void *data)
>  {
>  DeviceClass *dc = DEVICE_CLASS(klass);
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 8f145733ce..efd33d87fd 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -838,12 +838,6 @@ bool cpu_exists(int64_t id);
>   */
>  CPUState *cpu_by_arch_id(int64_t id);
>  
> -#ifndef CONFIG_USER_ONLY
> -
> -typedef void (*CPUInterruptHandler)(CPUState *, int);
> -
> -extern CPUInterruptHandler cpu_interrupt_handler;
> -

[PATCH v8 8/8] tests/test-char.c: Wait for the chardev to connect in char_socket_client_dupid_test

2020-09-01 Thread Lukas Straub
A connecting chardev object has an additional reference by the connecting
thread, so if the chardev is still connecting by the end of the test,
then the chardev object won't be freed. This in turn means that the yank
instance won't be unregistered and when running the next test-case
yank_register_instance will abort, because the yank instance is
already/still registered.

Signed-off-by: Lukas Straub 
Reviewed-by: Daniel P. Berrangé 
---
 tests/test-char.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/test-char.c b/tests/test-char.c
index d35cc839bc..2ced07de69 100644
--- a/tests/test-char.c
+++ b/tests/test-char.c
@@ -937,6 +937,7 @@ static void char_socket_client_dupid_test(gconstpointer 
opaque)
 g_assert_nonnull(opts);
 chr1 = qemu_chr_new_from_opts(opts, NULL, &error_abort);
 g_assert_nonnull(chr1);
+qemu_chr_wait_connected(chr1, &error_abort);

 chr2 = qemu_chr_new_from_opts(opts, NULL, &local_err);
 g_assert_null(chr2);
--
2.20.1


pgpgrkSnG5vhK.pgp
Description: OpenPGP digital signature


[PATCH v8 7/8] MAINTAINERS: Add myself as maintainer for yank feature

2020-09-01 Thread Lukas Straub
I'll maintain this for now as the colo usecase is the first user
of this functionality.

Signed-off-by: Lukas Straub 
Acked-by: Stefan Hajnoczi 
Reviewed-by: Daniel P. Berrangé 
---
 MAINTAINERS | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 5a22c8be42..c1d450e25a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2615,6 +2615,12 @@ F: util/uuid.c
 F: include/qemu/uuid.h
 F: tests/test-uuid.c

+Yank feature
+M: Lukas Straub 
+S: Odd fixes
+F: util/yank.c
+F: include/qemu/yank.h
+
 COLO Framework
 M: zhanghailiang 
 S: Maintained
--
2.20.1



pgpqh0yL44Jtq.pgp
Description: OpenPGP digital signature


Re: [PATCH v3 08/16] hw/riscv: microchip_pfsoc: Connect a Cadence SDHCI controller and an SD card

2020-09-01 Thread Philippe Mathieu-Daudé
On 9/1/20 3:39 AM, Bin Meng wrote:
> From: Bin Meng 
> 
> Microchip PolarFire SoC integrates one Cadence SDHCI controller.
> On the Icicle Kit board, one eMMC chip and an external SD card
> connect to this controller depending on different configuration.
> 
> As QEMU does not support eMMC yet, we just emulate the SD card
> configuration. To test this, the Hart Software Services (HSS)
> should choose the SD card configuration:
> 
> $ cp boards/icicle-kit-es/def_config.sdcard .config
> $ make BOARD=icicle-kit-es
> 
> The SD card image can be built from the Yocto BSP at:
> https://github.com/polarfire-soc/meta-polarfire-soc-yocto-bsp
> 
> Note the generated SD card image should be resized before use:
> $ qemu-img resize /path/to/sdcard.img 4G
> 
> Launch QEMU with the following command:
> $ qemu-system-riscv64 -nographic -M microchip-icicle-kit -sd sdcard.img
> 
> Signed-off-by: Bin Meng 
> 
> ---
> 
> (no changes since v2)
> 
> Changes in v2:
> - do not initialize TYPE_SYSBUS_SDHCI in the SoC instance_init(),
>   instead move that to the cadence_sdhci model
> - do not access generic-sdhci's state directly,
>   instead move that to the cadence_sdhci model
> 
>  include/hw/riscv/microchip_pfsoc.h |  4 
>  hw/riscv/microchip_pfsoc.c | 23 +++
>  hw/riscv/Kconfig   |  1 +
>  3 files changed, 28 insertions(+)
> 
> diff --git a/include/hw/riscv/microchip_pfsoc.h 
> b/include/hw/riscv/microchip_pfsoc.h
> index a5efa1d..d810ee8 100644
> --- a/include/hw/riscv/microchip_pfsoc.h
> +++ b/include/hw/riscv/microchip_pfsoc.h
> @@ -23,6 +23,7 @@
>  #define HW_MICROCHIP_PFSOC_H
>  
>  #include "hw/char/mchp_pfsoc_mmuart.h"
> +#include "hw/sd/cadence_sdhci.h"
>  
>  typedef struct MicrochipPFSoCState {
>  /*< private >*/
> @@ -39,6 +40,7 @@ typedef struct MicrochipPFSoCState {
>  MchpPfSoCMMUartState *serial2;
>  MchpPfSoCMMUartState *serial3;
>  MchpPfSoCMMUartState *serial4;
> +CadenceSDHCIState sdhci;
>  } MicrochipPFSoCState;
>  
>  #define TYPE_MICROCHIP_PFSOC"microchip.pfsoc"
> @@ -74,6 +76,7 @@ enum {
>  MICROCHIP_PFSOC_MMUART0,
>  MICROCHIP_PFSOC_SYSREG,
>  MICROCHIP_PFSOC_MPUCFG,
> +MICROCHIP_PFSOC_EMMC_SD,
>  MICROCHIP_PFSOC_MMUART1,
>  MICROCHIP_PFSOC_MMUART2,
>  MICROCHIP_PFSOC_MMUART3,
> @@ -85,6 +88,7 @@ enum {
>  };
>  
>  enum {
> +MICROCHIP_PFSOC_EMMC_SD_IRQ = 88,
>  MICROCHIP_PFSOC_MMUART0_IRQ = 90,
>  MICROCHIP_PFSOC_MMUART1_IRQ = 91,
>  MICROCHIP_PFSOC_MMUART2_IRQ = 92,
> diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
> index cee959a..0b2e9ca 100644
> --- a/hw/riscv/microchip_pfsoc.c
> +++ b/hw/riscv/microchip_pfsoc.c
> @@ -12,6 +12,7 @@
>   * 1) PLIC (Platform Level Interrupt Controller)
>   * 2) eNVM (Embedded Non-Volatile Memory)
>   * 3) MMUARTs (Multi-Mode UART)
> + * 4) Cadence eMMC/SDHC controller and an SD card connected to it
>   *
>   * This board currently generates devicetree dynamically that indicates at 
> least
>   * two harts and up to five harts.
> @@ -75,6 +76,7 @@ static const struct MemmapEntry {
>  [MICROCHIP_PFSOC_MMUART0] = { 0x2000, 0x1000 },
>  [MICROCHIP_PFSOC_SYSREG] =  { 0x20002000, 0x2000 },
>  [MICROCHIP_PFSOC_MPUCFG] =  { 0x20005000, 0x1000 },
> +[MICROCHIP_PFSOC_EMMC_SD] = { 0x20008000, 0x1000 },
>  [MICROCHIP_PFSOC_MMUART1] = { 0x2010, 0x1000 },
>  [MICROCHIP_PFSOC_MMUART2] = { 0x20102000, 0x1000 },
>  [MICROCHIP_PFSOC_MMUART3] = { 0x20104000, 0x1000 },
> @@ -111,6 +113,9 @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
>  qdev_prop_set_string(DEVICE(&s->u_cpus), "cpu-type",
>   TYPE_RISCV_CPU_SIFIVE_U54);
>  qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", RESET_VECTOR);
> +
> +object_initialize_child(obj, "sd-controller", &s->sdhci,
> +TYPE_CADENCE_SDHCI);
>  }
>  
>  static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
> @@ -223,6 +228,13 @@ static void microchip_pfsoc_soc_realize(DeviceState 
> *dev, Error **errp)
>  memmap[MICROCHIP_PFSOC_MPUCFG].base,
>  memmap[MICROCHIP_PFSOC_MPUCFG].size);
>  
> +/* SDHCI */
> +sysbus_realize(SYS_BUS_DEVICE(&s->sdhci), errp);
> +sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdhci), 0,
> +memmap[MICROCHIP_PFSOC_EMMC_SD].base);
> +sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci), 0,
> +qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_EMMC_SD_IRQ));
> +
>  /* MMUARTs */
>  s->serial0 = mchp_pfsoc_mmuart_create(system_memory,
>  memmap[MICROCHIP_PFSOC_MMUART0].base,
> @@ -290,6 +302,7 @@ static void 
> microchip_icicle_kit_machine_init(MachineState *machine)
>  MicrochipIcicleKitState *s = MICROCHIP_ICICLE_KIT_MACHINE(machine);
>  MemoryRegion *system_memory = get_system_memory();
>  MemoryRegion *main_mem = g_ne

Re: [PATCH v6 11/16] cpus: remove checks for non-NULL cpus_accel

2020-09-01 Thread Claudio Fontana
On 9/1/20 11:34 AM, Roman Bolshakov wrote:
> On Tue, Sep 01, 2020 at 09:21:56AM +0200, Claudio Fontana wrote:
>> now that all accelerators support the CpusAccel interface,
>> we can remove most checks for non-NULL cpus_accel,
>> we just add a sanity check/assert at vcpu creation.
>>
>> Signed-off-by: Claudio Fontana 
>> ---
>>  softmmu/cpus.c | 33 +
>>  1 file changed, 21 insertions(+), 12 deletions(-)
>>
>> diff --git a/softmmu/cpus.c b/softmmu/cpus.c
>> index 3d8350fba9..f32ecb4bb9 100644
>> --- a/softmmu/cpus.c
>> +++ b/softmmu/cpus.c
>> @@ -166,34 +166,46 @@ void cpu_synchronize_all_pre_loadvm(void)
>>  
>>  void cpu_synchronize_state(CPUState *cpu)
>>  {
>> -if (cpus_accel && cpus_accel->synchronize_state) {
>> +if (cpus_accel->synchronize_state) {
>>  cpus_accel->synchronize_state(cpu);
>>  }
>>  }
>>  
>>  void cpu_synchronize_post_reset(CPUState *cpu)
>>  {
>> -if (cpus_accel && cpus_accel->synchronize_post_reset) {
>> +if (cpus_accel->synchronize_post_reset) {
>>  cpus_accel->synchronize_post_reset(cpu);
>>  }
>>  }
>>  
>>  void cpu_synchronize_post_init(CPUState *cpu)
>>  {
>> -if (cpus_accel && cpus_accel->synchronize_post_init) {
>> +if (cpus_accel->synchronize_post_init) {
>>  cpus_accel->synchronize_post_init(cpu);
>>  }
>>  }
>>  
>>  void cpu_synchronize_pre_loadvm(CPUState *cpu)
>>  {
>> -if (cpus_accel && cpus_accel->synchronize_pre_loadvm) {
>> +if (cpus_accel->synchronize_pre_loadvm) {
>>  cpus_accel->synchronize_pre_loadvm(cpu);
>>  }
>>  }
>>  
>>  int64_t cpus_get_virtual_clock(void)
>>  {
>> +/*
>> + * XXX
>> + *
>> + * need to check that cpus_accel is not NULL, because qcow2 calls
>> + * qemu_get_clock_ns(CLOCK_VIRTUAL) without any accel initialized and
>> + * with ticks disabled in some io-tests:
>> + * 030 040 041 060 099 120 127 140 156 161 172 181 191 192 195 203 229 
>> 249 256 267
>> + *
>> + * is this expected?
>> + *
>> + * XXX
>> + */
>>  if (cpus_accel && cpus_accel->get_virtual_clock) {
>>  return cpus_accel->get_virtual_clock();
>>  }
>> @@ -207,7 +219,7 @@ int64_t cpus_get_virtual_clock(void)
>>   */
>>  int64_t cpus_get_elapsed_ticks(void)
>>  {
>> -if (cpus_accel && cpus_accel->get_elapsed_ticks) {
>> +if (cpus_accel->get_elapsed_ticks) {
>>  return cpus_accel->get_elapsed_ticks();
>>  }
>>  return cpu_get_ticks();
>> @@ -399,7 +411,7 @@ void cpus_kick_thread(CPUState *cpu)
>>  void qemu_cpu_kick(CPUState *cpu)
>>  {
>>  qemu_cond_broadcast(cpu->halt_cond);
>> -if (cpus_accel && cpus_accel->kick_vcpu_thread) {
>> +if (cpus_accel->kick_vcpu_thread) {
>>  cpus_accel->kick_vcpu_thread(cpu);
>>  } else { /* default */
>>  cpus_kick_thread(cpu);
>> @@ -573,12 +585,9 @@ void qemu_init_vcpu(CPUState *cpu)
>>  cpu_address_space_init(cpu, 0, "cpu-memory", cpu->memory);
>>  }
>>  
>> -if (cpus_accel) {
>> -/* accelerator already implements the CpusAccel interface */
>> -cpus_accel->create_vcpu_thread(cpu);
>> -} else {
>> -g_assert_not_reached();
>> -}
>> +/* accelerators all implement the CpusAccel interface */
>> +g_assert(cpus_accel != NULL && cpus_accel->create_vcpu_thread != NULL);
>> +cpus_accel->create_vcpu_thread(cpu);
>>  
>>  while (!cpu->created) {
>>  qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
>> -- 
>> 2.26.2
>>
> 
> Reviewed-by: Roman Bolshakov 
> 
> but I still find the condition (if cpus_accel->func) redundant, is it
> feasible to drop it?
> 
> Regards,
> Roman
> 

Hi Roman,

indeed currently not, because currently we use a NULL function pointer to mean 
"use generic/default behaviour".
This is one of the open questions in the cover letter.

It has the advantage that only "interesting" information is present in each 
data structure,
with only non-default behaviour being explicit, this has been changed to 
satisfy Paolo's requirement.

It has the disadvantage of an additional check.

I am ok with both outcomes, but I'd like Paolo's take on this if we are to 
change this again?

Thanks,

Claudio





Re: [PATCH v8 1/8] Introduce yank feature

2020-09-01 Thread Daniel P . Berrangé
On Tue, Sep 01, 2020 at 11:15:07AM +0200, Lukas Straub wrote:
> The yank feature allows to recover from hanging qemu by "yanking"
> at various parts. Other qemu systems can register themselves and
> multiple yank functions. Then all yank functions for selected
> instances can be called by the 'yank' out-of-band qmp command.
> Available instances can be queried by a 'query-yank' oob command.
> 
> Signed-off-by: Lukas Straub 
> Acked-by: Stefan Hajnoczi 
> ---
>  include/qemu/yank.h |  81 +++
>  qapi/misc.json  |  62 +++
>  util/meson.build|   1 +
>  util/yank.c | 187 
>  4 files changed, 331 insertions(+)
>  create mode 100644 include/qemu/yank.h
>  create mode 100644 util/yank.c

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 :|




Re: [PATCH] usb: call usb_packet_cleanup on usb_packet_map failure

2020-09-01 Thread Philippe Mathieu-Daudé
On 9/1/20 7:27 AM, Gerd Hoffmann wrote:

Reported-by: Prasad J Pandit 

> Signed-off-by: Gerd Hoffmann 

Reviewed-by: Philippe Mathieu-Daudé 

> ---
>  hw/usb/hcd-ehci.c | 2 ++
>  hw/usb/hcd-xhci.c | 1 +
>  2 files changed, 3 insertions(+)
> 
> diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
> index 2b995443fbfd..67847a9cf5f1 100644
> --- a/hw/usb/hcd-ehci.c
> +++ b/hw/usb/hcd-ehci.c
> @@ -1373,6 +1373,7 @@ static int ehci_execute(EHCIPacket *p, const char 
> *action)
>  usb_packet_setup(&p->packet, p->pid, ep, 0, p->qtdaddr, spd,
>   (p->qtd.token & QTD_TOKEN_IOC) != 0);
>  if (usb_packet_map(&p->packet, &p->sgl)) {
> +usb_packet_cleanup(&p->packet);
>  qemu_sglist_destroy(&p->sgl);
>  return -1;
>  }
> @@ -1456,6 +1457,7 @@ static int ehci_process_itd(EHCIState *ehci,
>  usb_packet_setup(&ehci->ipacket, pid, ep, 0, addr, false,
>   (itd->transact[i] & ITD_XACT_IOC) != 0);
>  if (usb_packet_map(&ehci->ipacket, &ehci->isgl)) {
> +usb_packet_cleanup(&ehci->ipacket);
>  qemu_sglist_destroy(&ehci->isgl);
>  return -1;
>  }
> diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
> index 46a2186d912a..9b156048920d 100644
> --- a/hw/usb/hcd-xhci.c
> +++ b/hw/usb/hcd-xhci.c
> @@ -1616,6 +1616,7 @@ static int xhci_setup_packet(XHCITransfer *xfer)
>  usb_packet_setup(&xfer->packet, dir, ep, xfer->streamid,
>   xfer->trbs[0].addr, false, xfer->int_req);
>  if (usb_packet_map(&xfer->packet, &xfer->sgl)) {
> +usb_packet_cleanup(&xfer->packet);
>  qemu_sglist_destroy(&xfer->sgl);
>  return -1;
>  }
> 




Re: [PATCH v8 4/8] migration: Add yank feature

2020-09-01 Thread Daniel P . Berrangé
On Tue, Sep 01, 2020 at 11:15:18AM +0200, Lukas Straub wrote:
> Register yank functions on sockets to shut them down.
> 
> Signed-off-by: Lukas Straub 
> Acked-by: Stefan Hajnoczi 
> Acked-by: Dr. David Alan Gilbert 
> ---
>  migration/channel.c   | 12 
>  migration/migration.c | 25 +
>  migration/multifd.c   | 10 ++
>  migration/qemu-file-channel.c |  6 ++
>  migration/savevm.c|  6 ++
>  5 files changed, 59 insertions(+)

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 :|




Re: [PATCH v8 6/8] io: Document qmp oob suitability of qio_channel_shutdown and io_shutdown

2020-09-01 Thread Daniel P . Berrangé
On Tue, Sep 01, 2020 at 11:15:25AM +0200, Lukas Straub wrote:
> Migration and yank code assume that qio_channel_shutdown is thread
> -safe and can be called from qmp oob handler. Document this after
> checking the code.
> 
> Signed-off-by: Lukas Straub 
> Acked-by: Stefan Hajnoczi 
> ---
>  include/io/channel.h | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)

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 :|




Re: [PATCH v3 15/16] hw/riscv: clint: Avoid using hard-coded timebase frequency

2020-09-01 Thread Philippe Mathieu-Daudé
On 9/1/20 3:39 AM, Bin Meng wrote:
> From: Bin Meng 
> 
> At present the CLINT timestamp is using a hard-coded timebase
> frequency value SIFIVE_CLINT_TIMEBASE_FREQ. This might not be
> true for all boards.
> 
> Add a new 'timebase-freq' property to the CLINT device, and
> update various functions to accept this as a parameter.
> 
> Signed-off-by: Bin Meng 
> Reviewed-by: Alistair Francis 
> 
> ---
> 
> (no changes since v1)
> 
>  include/hw/riscv/sifive_clint.h |  4 +++-
>  target/riscv/cpu.h  |  6 --
>  hw/riscv/microchip_pfsoc.c  |  6 +-
>  hw/riscv/sifive_clint.c | 26 +++---
>  hw/riscv/sifive_e.c |  3 ++-
>  hw/riscv/sifive_u.c |  3 ++-
>  hw/riscv/spike.c|  3 ++-
>  hw/riscv/virt.c |  3 ++-
>  target/riscv/cpu_helper.c   |  4 +++-
>  target/riscv/csr.c  |  4 ++--
>  10 files changed, 40 insertions(+), 22 deletions(-)
> 
> diff --git a/include/hw/riscv/sifive_clint.h b/include/hw/riscv/sifive_clint.h
> index 9f5fb3d..a30be0f 100644
> --- a/include/hw/riscv/sifive_clint.h
> +++ b/include/hw/riscv/sifive_clint.h
> @@ -39,11 +39,13 @@ typedef struct SiFiveCLINTState {
>  uint32_t timecmp_base;
>  uint32_t time_base;
>  uint32_t aperture_size;
> +uint32_t timebase_freq;
>  } SiFiveCLINTState;
>  
>  DeviceState *sifive_clint_create(hwaddr addr, hwaddr size,
>  uint32_t hartid_base, uint32_t num_harts, uint32_t sip_base,
> -uint32_t timecmp_base, uint32_t time_base, bool provide_rdtime);
> +uint32_t timecmp_base, uint32_t time_base, uint32_t timebase_freq,
> +bool provide_rdtime);

As an future improvement, consider using the recently introduced Clock API.

Regards,

Phil.



Re: [PATCH v6 12/16] cpus: add handle_interrupt to the CpusAccel interface

2020-09-01 Thread Claudio Fontana
On 9/1/20 11:38 AM, Roman Bolshakov wrote:
> On Tue, Sep 01, 2020 at 09:21:57AM +0200, Claudio Fontana wrote:
>> kvm: uses the generic handler
>> qtest: uses the generic handler
>> whpx: changed to use the generic handler (identical implementation)
>> hax: changed to use the generic handler (identical implementation)
>> hvf: changed to use the generic handler (identical implementation)
>> tcg: adapt tcg-cpus to point to the tcg-specific handler
>>
>> Signed-off-by: Claudio Fontana 
>> ---
>>  accel/tcg/tcg-all.c| 26 --
>>  accel/tcg/tcg-cpus.c   | 28 
>>  hw/core/cpu.c  | 13 -
>>  include/hw/core/cpu.h  | 14 --
>>  include/sysemu/cpus.h  |  2 ++
>>  softmmu/cpus.c | 18 ++
>>  target/i386/hax-all.c  | 10 --
>>  target/i386/hvf/hvf.c  |  9 -
>>  target/i386/whpx-all.c | 10 --
>>  9 files changed, 48 insertions(+), 82 deletions(-)
>>
>> diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
>> index 01957b130d..af9bf5c5bb 100644
>> --- a/accel/tcg/tcg-all.c
>> +++ b/accel/tcg/tcg-all.c
>> @@ -47,31 +47,6 @@ typedef struct TCGState {
>>  #define TCG_STATE(obj) \
>>  OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL)
>>  
>> -/* mask must never be zero, except for A20 change call */
>> -static void tcg_handle_interrupt(CPUState *cpu, int mask)
>> -{
>> -int old_mask;
>> -g_assert(qemu_mutex_iothread_locked());
>> -
>> -old_mask = cpu->interrupt_request;
>> -cpu->interrupt_request |= mask;
>> -
>> -/*
>> - * If called from iothread context, wake the target cpu in
>> - * case its halted.
>> - */
>> -if (!qemu_cpu_is_self(cpu)) {
>> -qemu_cpu_kick(cpu);
>> -} else {
>> -atomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1);
>> -if (icount_enabled() &&
>> -!cpu->can_do_io
>> -&& (mask & ~old_mask) != 0) {
>> -cpu_abort(cpu, "Raised interrupt while not in I/O function");
>> -}
>> -}
>> -}
>> -
>>  /*
>>   * We default to false if we know other options have been enabled
>>   * which are currently incompatible with MTTCG. Otherwise when each
>> @@ -128,7 +103,6 @@ static int tcg_init(MachineState *ms)
>>  TCGState *s = TCG_STATE(current_accel());
>>  
>>  tcg_exec_init(s->tb_size * 1024 * 1024);
>> -cpu_interrupt_handler = tcg_handle_interrupt;
>>  mttcg_enabled = s->mttcg_enabled;
>>  cpus_register_accel(&tcg_cpus);
>>  
>> diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
>> index 72696f6d86..2bb209e2c6 100644
>> --- a/accel/tcg/tcg-cpus.c
>> +++ b/accel/tcg/tcg-cpus.c
>> @@ -533,9 +533,37 @@ static int64_t tcg_get_elapsed_ticks(void)
>>  return cpu_get_ticks();
>>  }
>>  
>> +/* mask must never be zero, except for A20 change call */
>> +static void tcg_handle_interrupt(CPUState *cpu, int mask)
>> +{
>> +int old_mask;
>> +g_assert(qemu_mutex_iothread_locked());
>> +
>> +old_mask = cpu->interrupt_request;
>> +cpu->interrupt_request |= mask;
>> +
>> +/*
>> + * If called from iothread context, wake the target cpu in
>> + * case its halted.
>> + */
>> +if (!qemu_cpu_is_self(cpu)) {
>> +qemu_cpu_kick(cpu);
>> +} else {
>> +atomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1);
>> +if (icount_enabled() &&
>> +!cpu->can_do_io
>> +&& (mask & ~old_mask) != 0) {
>> +cpu_abort(cpu, "Raised interrupt while not in I/O function");
>> +}
>> +}
>> +}
>> +
>>  const CpusAccel tcg_cpus = {
>>  .create_vcpu_thread = tcg_start_vcpu_thread,
>>  .kick_vcpu_thread = tcg_kick_vcpu_thread,
>> +
>> +.handle_interrupt = tcg_handle_interrupt,
>> +
>>  .get_virtual_clock = tcg_get_virtual_clock,
>>  .get_elapsed_ticks = tcg_get_elapsed_ticks,
>>  };
>> diff --git a/hw/core/cpu.c b/hw/core/cpu.c
>> index fa8602493b..451b3d5ee7 100644
>> --- a/hw/core/cpu.c
>> +++ b/hw/core/cpu.c
>> @@ -35,8 +35,6 @@
>>  #include "qemu/plugin.h"
>>  #include "sysemu/hw_accel.h"
>>  
>> -CPUInterruptHandler cpu_interrupt_handler;
>> -
>>  CPUState *cpu_by_arch_id(int64_t id)
>>  {
>>  CPUState *cpu;
>> @@ -394,17 +392,6 @@ static vaddr cpu_adjust_watchpoint_address(CPUState 
>> *cpu, vaddr addr, int len)
>>  return addr;
>>  }
>>  
>> -static void generic_handle_interrupt(CPUState *cpu, int mask)
>> -{
>> -cpu->interrupt_request |= mask;
>> -
>> -if (!qemu_cpu_is_self(cpu)) {
>> -qemu_cpu_kick(cpu);
>> -}
>> -}
>> -
>> -CPUInterruptHandler cpu_interrupt_handler = generic_handle_interrupt;
>> -
>>  static void cpu_class_init(ObjectClass *klass, void *data)
>>  {
>>  DeviceClass *dc = DEVICE_CLASS(klass);
>> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
>> index 8f145733ce..efd33d87fd 100644
>> --- a/include/hw/core/cpu.h
>> +++ b/include/hw/core/cpu.h
>> @@ -838,12 +838,6 @@ bool cpu_exists(int64_t id);
>>   */
>>  CPU

Re: [PATCH v3 01/16] target/riscv: cpu: Add a new 'resetvec' property

2020-09-01 Thread Philippe Mathieu-Daudé
On 9/1/20 3:38 AM, Bin Meng wrote:
> From: Bin Meng 
> 
> Currently the reset vector address is hard-coded in a RISC-V CPU's
> instance_init() routine. In a real world we can have 2 exact same
> CPUs except for the reset vector address, which is pretty common in
> the RISC-V core IP licensing business.
> 
> Normally reset vector address is a configurable parameter. Let's
> create a 64-bit property to store the reset vector address which
> covers both 32-bit and 64-bit CPUs.
> 
> Signed-off-by: Bin Meng 
> Reviewed-by: Alistair Francis 
> ---
> 
> (no changes since v1)
> 
>  target/riscv/cpu.h | 1 +
>  target/riscv/cpu.c | 1 +
>  2 files changed, 2 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé 




Re: [PATCH v3 02/16] hw/riscv: hart: Add a new 'resetvec' property

2020-09-01 Thread Philippe Mathieu-Daudé
On 9/1/20 3:38 AM, Bin Meng wrote:
> From: Bin Meng 
> 
> RISC-V machines do not instantiate RISC-V CPUs directly, instead
> they do that via the hart array. Add a new property for the reset
> vector address to allow the value to be passed to the CPU, before
> CPU is realized.
> 
> Signed-off-by: Bin Meng 
> Reviewed-by: Alistair Francis 
> ---
> 
> (no changes since v1)
> 
>  include/hw/riscv/riscv_hart.h | 1 +
>  hw/riscv/riscv_hart.c | 3 +++
>  2 files changed, 4 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé 



[PATCH] piix4: don't reserve hw resources when hotplug is off globally

2020-09-01 Thread Ani Sinha
When acpi hotplug is turned off for both root pci bus as well as for pci
bridges, we should not generate the related amls for DSDT table or initialize
related hw ports or reserve hw resources. This change makes sure all those
operations are turned off in the case acpi pci hotplug is off globally.

Signed-off-by: Ani Sinha 
---
 hw/acpi/piix4.c  |  6 --
 hw/i386/acpi-build.c | 10 --
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index e6163bb6ce..b70b1f98af 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -596,8 +596,10 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion 
*parent,
   "acpi-gpe0", GPE_LEN);
 memory_region_add_subregion(parent, GPE_BASE, &s->io_gpe);
 
-acpi_pcihp_init(OBJECT(s), &s->acpi_pci_hotplug, bus, parent,
-s->use_acpi_hotplug_bridge);
+if (s->use_acpi_hotplug_bridge || s->use_acpi_root_pci_hotplug) {
+acpi_pcihp_init(OBJECT(s), &s->acpi_pci_hotplug, bus, parent,
+s->use_acpi_hotplug_bridge);
+}
 
 s->cpu_hotplug_legacy = true;
 object_property_add_bool(OBJECT(s), "cpu-hotplug-legacy",
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index b7bc2a..5365b3d290 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -95,6 +95,7 @@ typedef struct AcpiPmInfo {
 bool s3_disabled;
 bool s4_disabled;
 bool pcihp_bridge_en;
+bool pcihp_root_en;
 uint8_t s4_val;
 AcpiFadtData fadt;
 uint16_t cpu_hp_io_base;
@@ -245,6 +246,9 @@ static void acpi_get_pm_info(MachineState *machine, 
AcpiPmInfo *pm)
 pm->pcihp_bridge_en =
 object_property_get_bool(obj, "acpi-pci-hotplug-with-bridge-support",
  NULL);
+pm->pcihp_root_en =
+object_property_get_bool(obj, "acpi-root-pci-hotplug",
+ NULL);
 }
 
 static void acpi_get_misc_info(AcpiMiscInfo *info)
@@ -1504,7 +1508,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
 build_hpet_aml(dsdt);
 build_piix4_isa_bridge(dsdt);
 build_isa_devices_aml(dsdt);
-build_piix4_pci_hotplug(dsdt);
+if (pm->pcihp_bridge_en || pm->pcihp_root_en) {
+build_piix4_pci_hotplug(dsdt);
+}
 build_piix4_pci0_int(dsdt);
 } else {
 sb_scope = aml_scope("_SB");
@@ -1698,7 +1704,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
 crs_range_set_free(&crs_range_set);
 
 /* reserve PCIHP resources */
-if (pm->pcihp_io_len) {
+if (pm->pcihp_io_len && (pm->pcihp_bridge_en || pm->pcihp_root_en)) {
 dev = aml_device("PHPR");
 aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A06")));
 aml_append(dev,
-- 
2.17.1




Re: [kvm-unit-tests RFC 0/4] KVM: arm64: Statistical Profiling Extension Tests

2020-09-01 Thread Alexandru Elisei
Hi Eric,

These patches are extremely welcome! I took over the KVM SPE patches from Andrew
Murray, and I was working on something similar to help with development.

The KVM series on the public mailing list work only by chance because it is
impossible to reliably map the SPE buffer at EL2 when profiling triggers a 
stage 2
data abort. That's because the DABT is reported asynchronously via the buffer
management interrupt and the faulting IPA is not reported anywhere. I'm trying 
to
fix this issue in the next iteration of the series, and then I'll come back to
your patches for review and testing.

Thanks,

Alex

On 8/31/20 8:34 PM, Eric Auger wrote:
> This series implements tests exercising the Statistical Profiling
> Extensions.
>
> This was tested with associated unmerged kernel [1] and QEMU [2]
> series.
>
> Depending on the comments, I can easily add other tests checking
> more configs, additional events and testing migration too. I hope
> this can be useful when respinning both series.
>
> All SPE tests can be launched with:
> ./run_tests.sh -g spe
> Tests also can be launched individually. For example:
> ./arm-run arm/spe.flat -append 'spe-buffer'
>
> The series can be found at:
> https://github.com/eauger/kut/tree/spe_rfc
>
> References:
> [1] [PATCH v2 00/18] arm64: KVM: add SPE profiling support
> [2] [PATCH 0/7] target/arm: Add vSPE support to KVM guest
>
> Eric Auger (4):
>   arm64: Move get_id_aa64dfr0() in processor.h
>   spe: Probing and Introspection Test
>   spe: Add profiling buffer test
>   spe: Test Profiling Buffer Events
>
>  arm/Makefile.common   |   1 +
>  arm/pmu.c |   1 -
>  arm/spe.c | 463 ++
>  arm/unittests.cfg |  24 ++
>  lib/arm64/asm/barrier.h   |   1 +
>  lib/arm64/asm/processor.h |   5 +
>  6 files changed, 494 insertions(+), 1 deletion(-)
>  create mode 100644 arm/spe.c
>



Re: [PATCH v7 4/8] ppc/e500: Use start-powered-off CPUState property

2020-09-01 Thread Philippe Mathieu-Daudé
On 8/26/20 7:55 AM, Thiago Jung Bauermann wrote:
> Instead of setting CPUState::halted to 1 in ppce500_cpu_reset_sec(), use
> the start-powered-off property which makes cpu_common_reset() initialize it
> to 1 in common code.
> 
> Also change creation of CPU object from cpu_create() to object_new() and
> qdev_realize_and_unref() because cpu_create() realizes the CPU and it's not
> possible to set a property after the object is realized.
> 
> Signed-off-by: Thiago Jung Bauermann 
> ---
>  hw/ppc/e500.c | 13 +
>  1 file changed, 9 insertions(+), 4 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé 




Re: [PATCH v3 03/16] target/riscv: cpu: Set reset vector based on the configured property value

2020-09-01 Thread Philippe Mathieu-Daudé
On 9/1/20 3:38 AM, Bin Meng wrote:
> From: Bin Meng 
> 
> Now that we have the newly introduced 'resetvec' property in the
> RISC-V CPU and HART, instead of hard-coding the reset vector addr
> in the CPU's instance_init(), move that to riscv_cpu_realize()
> based on the configured property value from the RISC-V machines.
> 
> Signed-off-by: Bin Meng 
> Reviewed-by: Alistair Francis 
> ---
> 
> (no changes since v1)
> 
>  hw/riscv/opentitan.c | 1 +
>  hw/riscv/sifive_e.c  | 1 +
>  hw/riscv/sifive_u.c  | 2 ++
>  target/riscv/cpu.c   | 7 ++-
>  4 files changed, 6 insertions(+), 5 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé 



Re: [PATCH v3 11/16] hw/net: cadence_gem: Add a new 'phy-addr' property

2020-09-01 Thread Philippe Mathieu-Daudé
On 9/1/20 3:39 AM, Bin Meng wrote:
> From: Bin Meng 
> 
> At present the PHY address of the PHY connected to GEM is hard-coded
> to either 23 (BOARD_PHY_ADDRESS) or 0. This might not be the case for
> all boards. Add a new 'phy-addr' property so that board can specify
> the PHY address for each GEM instance.
> 
> Signed-off-by: Bin Meng 
> 
> ---
> 
> (no changes since v2)
> 
> Changes in v2:
> - change "phy-addr" default value to BOARD_PHY_ADDRESS
> 
>  include/hw/net/cadence_gem.h | 2 ++
>  hw/net/cadence_gem.c | 5 +++--
>  2 files changed, 5 insertions(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé 



Re: [PATCH v7 6/8] sparc/sun4m: Don't set cs->halted = 0 in main_cpu_reset()

2020-09-01 Thread Philippe Mathieu-Daudé
On 8/26/20 7:55 AM, Thiago Jung Bauermann wrote:
> We rely on cpu_common_reset() to set cs->halted to 0, it's redundant to do
> it in main_cpu_reset().
> 
> Signed-off-by: Thiago Jung Bauermann 
> ---
>  hw/sparc/sun4m.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
> index cf7dfa4af5..7484aa4438 100644
> --- a/hw/sparc/sun4m.c
> +++ b/hw/sparc/sun4m.c
> @@ -224,7 +224,6 @@ static void main_cpu_reset(void *opaque)
>  CPUState *cs = CPU(cpu);
>  
>  cpu_reset(cs);
> -cs->halted = 0;
>  }
>  
>  static void secondary_cpu_reset(void *opaque)
> 

Reviewed-by: Philippe Mathieu-Daudé 




  1   2   3   4   5   6   >