1. 16 8月, 2019 3 次提交
  2. 06 7月, 2019 1 次提交
  3. 02 7月, 2019 2 次提交
  4. 21 6月, 2019 1 次提交
    • C
      hax: Honor CPUState::halted · 6f38dca6
      Colin Xu 提交于
      QEMU tracks whether a vcpu is halted using CPUState::halted. E.g.,
      after initialization or reset, halted is 0 for the BSP (vcpu 0)
      and 1 for the APs (vcpu 1, 2, ...). A halted vcpu should not be
      handed to the hypervisor to run (e.g. hax_vcpu_run()).
      
      Under HAXM, Android Emulator sometimes boots into a "vcpu shutdown
      request" error while executing in SeaBIOS, with the HAXM driver
      logging a guest triple fault in vcpu 1, 2, ... at RIP 0x3. That is
      ultimately because the HAX accelerator asks HAXM to run those APs
      when they are still in the halted state.
      
      Normally, the vcpu thread for an AP will start by looping in
      qemu_wait_io_event(), until the BSP kicks it via a pair of IPIs
      (INIT followed by SIPI). But because the HAX accelerator does not
      honor cpu->halted, it allows the AP vcpu thread to proceed to
      hax_vcpu_run() as soon as it receives any kick, even if the kick
      does not come from the BSP. It turns out that emulator has a
      worker thread which periodically kicks every vcpu thread (possibly
      to collect CPU usage data), and if one of these kicks comes before
      those by the BSP, the AP will start execution from the wrong RIP,
      resulting in the aforementioned SMP boot failure.
      
      The solution is inspired by the KVM accelerator (credit to
      Chuanxiao Dong <chuanxiao.dong@intel.com> for the pointer):
      
      1. Get rid of questionable logic that unconditionally resets
         cpu->halted before hax_vcpu_run(). Instead, only reset it at the
         right moments (there are only a few "unhalt" events).
      2. Add a check for cpu->halted before hax_vcpu_run().
      
      Note that although the non-Unrestricted Guest (!ug_platform) code
      path also forcibly resets cpu->halted, it is left untouched,
      because only the UG code path supports SMP guests.
      
      The patch is first merged to android emulator with Change-Id:
      I9c5752cc737fd305d7eace1768ea12a07309d716
      
      Cc: Yu Ning <yu.ning@intel.com>
      Cc: Chuanxiao Dong <chuanxiao.dong@intel.com>
      Signed-off-by: NColin Xu <colin.xu@intel.com>
      Message-Id: <20190610021939.13669-1-colin.xu@intel.com>
      6f38dca6
  5. 12 6月, 2019 2 次提交
    • M
      Include qemu-common.h exactly where needed · a8d25326
      Markus Armbruster 提交于
      No header includes qemu-common.h after this commit, as prescribed by
      qemu-common.h's file comment.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190523143508.25387-5-armbru@redhat.com>
      [Rebased with conflicts resolved automatically, except for
      include/hw/arm/xlnx-zynqmp.h hw/arm/nrf51_soc.c hw/arm/msf2-soc.c
      block/qcow2-refcount.c block/qcow2-cluster.c block/qcow2-cache.c
      target/arm/cpu.h target/lm32/cpu.h target/m68k/cpu.h target/mips/cpu.h
      target/moxie/cpu.h target/nios2/cpu.h target/openrisc/cpu.h
      target/riscv/cpu.h target/tilegx/cpu.h target/tricore/cpu.h
      target/unicore32/cpu.h target/xtensa/cpu.h; bsd-user/main.c and
      net/tap-bsd.c fixed up]
      a8d25326
    • M
      qemu-common: Move tcg_enabled() etc. to sysemu/tcg.h · 14a48c1d
      Markus Armbruster 提交于
      Other accelerators have their own headers: sysemu/hax.h, sysemu/hvf.h,
      sysemu/kvm.h, sysemu/whpx.h.  Only tcg_enabled() & friends sit in
      qemu-common.h.  This necessitates inclusion of qemu-common.h into
      headers, which is against the rules spelled out in qemu-common.h's
      file comment.
      
      Move tcg_enabled() & friends into their own header sysemu/tcg.h, and
      adjust #include directives.
      
      Cc: Richard Henderson <rth@twiddle.net>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190523143508.25387-2-armbru@redhat.com>
      Reviewed-by: NRichard Henderson <richard.henderson@linaro.org>
      [Rebased with conflicts resolved automatically, except for
      accel/tcg/tcg-all.c]
      14a48c1d
  6. 10 6月, 2019 1 次提交
  7. 23 5月, 2019 1 次提交
  8. 19 4月, 2019 3 次提交
    • M
      qom/cpu: Simplify how CPUClass:cpu_dump_state() prints · 90c84c56
      Markus Armbruster 提交于
      CPUClass method dump_statistics() takes an fprintf()-like callback and
      a FILE * to pass to it.  Most callers pass fprintf() and stderr.
      log_cpu_state() passes fprintf() and qemu_log_file.
      hmp_info_registers() passes monitor_fprintf() and the current monitor
      cast to FILE *.  monitor_fprintf() casts it right back, and is
      otherwise identical to monitor_printf().
      
      The callback gets passed around a lot, which is tiresome.  The
      type-punning around monitor_fprintf() is ugly.
      
      Drop the callback, and call qemu_fprintf() instead.  Also gets rid of
      the type-punning, since qemu_fprintf() takes NULL instead of the
      current monitor cast to FILE *.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NDr. David Alan Gilbert <dgilbert@redhat.com>
      Message-Id: <20190417191805.28198-15-armbru@redhat.com>
      90c84c56
    • M
      target: Simplify how the TARGET_cpu_list() print · 0442428a
      Markus Armbruster 提交于
      The various TARGET_cpu_list() take an fprintf()-like callback and a
      FILE * to pass to it.  Their callers (vl.c's main() via list_cpus(),
      bsd-user/main.c's main(), linux-user/main.c's main()) all pass
      fprintf() and stdout.  Thus, the flexibility provided by the (rather
      tiresome) indirection isn't actually used.
      
      Drop the callback, and call qemu_printf() instead.
      
      Calling printf() would also work, but would make the code unsuitable
      for monitor context without making it simpler.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190417191805.28198-10-armbru@redhat.com>
      Reviewed-by: NDr. David Alan Gilbert <dgilbert@redhat.com>
      0442428a
    • M
      tcg: Simplify how dump_drift_info() prints · 76c86615
      Markus Armbruster 提交于
      dump_drift_info() takes an fprintf()-like callback and a FILE * to pass
      to it.
      
      Its only caller hmp_info_jit() passes monitor_fprintf() and a Monitor
      * cast to FILE *.  monitor_fprintf() casts it right back, and is
      otherwise identical to monitor_printf().  The type-punning is ugly.
      
      Drop the callback, and call qemu_printf() instead.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NDr. David Alan Gilbert <dgilbert@redhat.com>
      Message-Id: <20190417191805.28198-6-armbru@redhat.com>
      76c86615
  9. 26 2月, 2019 1 次提交
  10. 05 2月, 2019 1 次提交
  11. 07 1月, 2019 1 次提交
    • P
      cpus.c: Fix race condition in cpu_stop_current() · 0ec7e677
      Peter Maydell 提交于
      We use cpu_stop_current() to ensure the current CPU has stopped
      from places like qemu_system_reset_request(). Unfortunately its
      current implementation has a race. It calls qemu_cpu_stop(),
      which sets cpu->stopped to true even though the CPU hasn't
      actually stopped yet. The main thread will look at the flags
      set by qemu_system_reset_request() and call pause_all_vcpus().
      pause_all_vcpus() waits for every cpu to have cpu->stopped true,
      so it can continue (and we will start the system reset operation)
      before the vcpu thread has got back to its top level loop.
      
      Instead, just set cpu->stop and call cpu_exit(). This will
      cause the vcpu to exit back to the top level loop, and there
      (as part of the wait_io_event code) it will call qemu_cpu_stop().
      
      This fixes bugs where the reset request appeared to be ignored
      or the CPU misbehaved because the reset operation started
      to change vcpu state while the vcpu thread was still using it.
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: NEmilio G. Cota <cota@braap.org>
      Tested-by: NJaap Crezee <jaap@jcz.nl>
      Message-id: 20181207155911.12710-1-peter.maydell@linaro.org
      0ec7e677
  12. 27 11月, 2018 1 次提交
  13. 07 11月, 2018 1 次提交
  14. 19 10月, 2018 3 次提交
  15. 03 10月, 2018 6 次提交
  16. 29 8月, 2018 1 次提交
  17. 28 8月, 2018 1 次提交
  18. 24 8月, 2018 5 次提交
    • P
      cpus: allow cpu_get_ticks out of BQL · f2a4ad6d
      Paolo Bonzini 提交于
      Because of cpu_ticks_prev, we cannot use a seqlock.  But then the conversion
      is even easier. :)
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      f2a4ad6d
    • P
      cpus: protect TimerState writes with a spinlock · 94377115
      Paolo Bonzini 提交于
      In the next patch, we will need to write cpu_ticks_offset from any
      thread, even outside the BQL.  Currently, it is protected by the BQL
      just because cpu_enable_ticks and cpu_disable_ticks happen to hold it,
      but the critical sections are well delimited and it's easy to remove
      the BQL dependency.
      
      Add a spinlock that matches vm_clock_seqlock, and hold it when writing
      to the TimerState.  This also lets us fix cpu_update_icount when 64-bit
      atomics are not available.
      
      Fields of TiemrState are reordered to avoid padding.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      94377115
    • P
      cpus: protect all icount computation with seqlock · c1ff073c
      Paolo Bonzini 提交于
      Move the icount->ns computation to cpu_get_icount, and make
      cpu_get_icount_locked return the raw value.  This makes the
      atomic_read__nocheck safe, because it now happens always inside a
      seqlock and any torn reads will be retried.  qemu_icount_bias and
      icount_time_shift also need to be accessed with atomics.  At the
      same time, however, you don't need atomic_read within the writer,
      because no concurrent writes are possible.
      
      The fix to vmstate lets us keep the struct nicely packed.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      c1ff073c
    • E
      qom: convert the CPU list to RCU · 068a5ea0
      Emilio G. Cota 提交于
      Iterating over the list without using atomics is undefined behaviour,
      since the list can be modified concurrently by other threads (e.g.
      every time a new thread is created in user-mode).
      
      Fix it by implementing the CPU list as an RCU QTAILQ. This requires
      a little bit of extra work to traverse list in reverse order (see
      previous patch), but other than that the conversion is trivial.
      Signed-off-by: NEmilio G. Cota <cota@braap.org>
      Message-Id: <20180819091335.22863-12-cota@braap.org>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      068a5ea0
    • E
      qsp: track BQL callers explicitly · cb764d06
      Emilio G. Cota 提交于
      The BQL is acquired via qemu_mutex_lock_iothread(), which makes
      the profiler assign the associated wait time (i.e. most of
      BQL wait time) entirely to that function. This loses the original
      call site information, which does not help diagnose BQL contention.
      Fix it by tracking the callers explicitly.
      Signed-off-by: NEmilio G. Cota <cota@braap.org>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      cb764d06
  19. 23 6月, 2018 1 次提交
  20. 22 6月, 2018 1 次提交
  21. 09 5月, 2018 2 次提交
    • C
      cpus: tcg: fix never exiting loop on unplug · 54961aac
      Cédric Le Goater 提交于
      Commit 9b0605f9 ("cpus: tcg: unregister thread with RCU, fix
      exiting of loop on unplug") changed the exit condition of the loop in
      the vCPU thread function but forgot to remove the beginning 'while (1)'
      statement. The resulting code :
      
      	while (1) {
      	...
      	} while (!cpu->unplug || cpu_can_run(cpu));
      
      is a sequence of two distinct two while() loops, the first not exiting
      in case of an unplug event.
      
      Remove the first while (1) to fix CPU unplug.
      Signed-off-by: NCédric Le Goater <clg@kaod.org>
      Message-Id: <20180425131828.15604-1-clg@kaod.org>
      Cc: qemu-stable@nongnu.org
      Fixes: 9b0605f9Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NCédric Le Goater <clg@kaod.org>
      54961aac
    • M
      cpus: Fix event order on resume of stopped guest · f056158d
      Markus Armbruster 提交于
      When resume of a stopped guest immediately runs into block device
      errors, the BLOCK_IO_ERROR event is sent before the RESUME event.
      
      Reproducer:
      
      1. Create a scratch image
         $ dd if=/dev/zero of=scratch.img bs=1M count=100
      
         Size doesn't actually matter.
      
      2. Prepare blkdebug configuration:
      
         $ cat >blkdebug.conf <<EOF
         [inject-error]
         event = "write_aio"
         errno = "5"
         EOF
      
         Note that errno 5 is EIO.
      
      3. Run a guest with an additional scratch disk, i.e. with additional
         arguments
         -drive if=none,id=scratch-drive,format=raw,werror=stop,file=blkdebug:blkdebug.conf:scratch.img
         -device virtio-blk-pci,id=scratch,drive=scratch-drive
      
         The blkdebug part makes all writes to the scratch drive fail with
         EIO.  The werror=stop pauses the guest on write errors.
      
      4. Connect to the QMP socket e.g. like this:
         $ socat UNIX:/your/qmp/socket READLINE,history=$HOME/.qmp_history,prompt='QMP> '
      
         Issue QMP command 'qmp_capabilities':
         QMP> { "execute": "qmp_capabilities" }
      
      5. Boot the guest.
      
      6. In the guest, write to the scratch disk, e.g. like this:
      
         # dd if=/dev/zero of=/dev/vdb count=1
      
         Do double-check the device specified with of= is actually the
         scratch device!
      
      7. Issue QMP command 'cont':
         QMP> { "execute": "cont" }
      
      After step 6, I get a BLOCK_IO_ERROR event followed by a STOP event.  Good.
      
      After step 7, I get BLOCK_IO_ERROR, then RESUME, then STOP.  Not so
      good; I'd expect RESUME, then BLOCK_IO_ERROR, then STOP.
      
      The funny event order confuses libvirt: virsh -r domstate DOMAIN
      --reason reports "paused (unknown)" rather than "paused (I/O error)".
      
      The culprit is vm_prepare_start().
      
          /* Ensure that a STOP/RESUME pair of events is emitted if a
           * vmstop request was pending.  The BLOCK_IO_ERROR event, for
           * example, according to documentation is always followed by
           * the STOP event.
           */
          if (runstate_is_running()) {
              qapi_event_send_stop(&error_abort);
              res = -1;
          } else {
              replay_enable_events();
              cpu_enable_ticks();
              runstate_set(RUN_STATE_RUNNING);
              vm_state_notify(1, RUN_STATE_RUNNING);
          }
      
          /* We are sending this now, but the CPUs will be resumed shortly later */
          qapi_event_send_resume(&error_abort);
          return res;
      
      When resuming a stopped guest, we take the else branch before we get
      to sending RESUME.  vm_state_notify() runs virtio_vmstate_change(),
      among other things.  This restarts I/O, triggering the BLOCK_IO_ERROR
      event.
      
      Reshuffle vm_prepare_start() to send the RESUME event earlier.
      
      Fixes RHBZ 1566153.
      
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20180423084518.2426-1-armbru@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      f056158d
  22. 04 5月, 2018 1 次提交