1. 17 3月, 2017 1 次提交
    • C
      qemu-thread: fix qemu_thread_set_name() race in qemu_thread_create() · f47bf082
      Caoxinhua 提交于
      QEMU will crash with the follow backtrace if the new created thread exited before
      we call qemu_thread_set_name() for it.
      
        (gdb) bt
        #0 0x00007f9a68b095d7 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
        #1 0x00007f9a68b0acc8 in __GI_abort () at abort.c:90
        #2 0x00007f9a69cda389 in PAT_abort () from /usr/lib64/libuvpuserhotfix.so
        #3 0x00007f9a69cdda0d in patchIllInsHandler () from /usr/lib64/libuvpuserhotfix.so
        #4 <signal handler called>
        #5 pthread_setname_np (th=140298470549248, name=name@entry=0x8cc74a "io-task-worker") at ../nptl/sysdeps/unix/sysv/linux/pthread_setname.c:49
        #6 0x00000000007f5f20 in qemu_thread_set_name (thread=thread@entry=0x7ffd2ac09680, name=name@entry=0x8cc74a "io-task-worker") at util/qemu_thread_posix.c:459
        #7 0x00000000007f679e in qemu_thread_create (thread=thread@entry=0x7ffd2ac09680, name=name@entry=0x8cc74a "io-task-worker",start_routine=start_routine@entry=0x7c1300 <qio_task_thread_worker>, arg=arg@entry=0x7f99b8001720, mode=mode@entry=1) at util/qemu_thread_posix.c:498
        #8 0x00000000007c15b6 in qio_task_run_in_thread (task=task@entry=0x7f99b80033d0, worker=worker@entry=0x7bd920 <qio_channel_socket_connect_worker>, opaque=0x7f99b8003370, destroy=0x7c6220 <qapi_free_SocketAddress>) at io/task.c:133
        #9 0x00000000007bda04 in qio_channel_socket_connect_async (ioc=0x7f99b80014c0, addr=0x37235d0, callback=callback@entry=0x54ad00 <qemu_chr_socket_connected>, opaque=opaque@entry=0x38118b0, destroy=destroy@entry=0x0) at io/channel_socket.c:191
        #10 0x00000000005487f6 in socket_reconnect_timeout (opaque=0x38118b0) at qemu_char.c:4402
        #11 0x00007f9a6a1533b3 in g_timeout_dispatch () from /usr/lib64/libglib-2.0.so.0
        #12 0x00007f9a6a15299a in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
        #13 0x0000000000747386 in glib_pollfds_poll () at main_loop.c:227
        #14 0x0000000000747424 in os_host_main_loop_wait (timeout=404000000) at main_loop.c:272
        #15 0x0000000000747575 in main_loop_wait (nonblocking=nonblocking@entry=0) at main_loop.c:520
        #16 0x0000000000557d31 in main_loop () at vl.c:2170
        #17 0x000000000041c8b7 in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at vl.c:5083
      
      Let's detach the new thread after calling qemu_thread_set_name().
      Signed-off-by: NCaoxinhua <caoxinhua@huawei.com>
      Signed-off-by: Nzhanghailiang <zhang.zhanghailiang@huawei.com>
      Message-Id: <1483493521-9604-1-git-send-email-zhang.zhanghailiang@huawei.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      (cherry picked from commit 2f75bd73)
      Signed-off-by: NMichael Roth <mdroth@linux.vnet.ibm.com>
      f47bf082
  2. 28 10月, 2016 1 次提交
  3. 24 10月, 2016 1 次提交
    • P
      qemu-thread: use acquire/release to clarify semantics of QemuEvent · 374293ca
      Paolo Bonzini 提交于
      Do not use the somewhat mysterious atomic_mb_read/atomic_mb_set,
      instead make sure that the operations on QemuEvent are annotated
      with the desired acquire and release semantics.
      
      In particular, qemu_event_set wakes up the waiting thread, so it must
      be a release from the POV of the waker (compare with qemu_mutex_unlock).
      And it actually needs a full barrier, because that's the only thing that
      provides something like a "load-release".
      
      Use smp_mb_acquire until we have atomic_load_acquire and
      atomic_store_release in atomic.h.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      374293ca
  4. 05 2月, 2016 1 次提交
    • P
      util: Clean up includes · aafd7584
      Peter Maydell 提交于
      Clean up includes so that osdep.h is included first and headers
      which it implies are not included manually.
      
      This commit was created with scripts/clean-includes.
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      Message-id: 1454089805-5470-6-git-send-email-peter.maydell@linaro.org
      aafd7584
  5. 11 9月, 2015 1 次提交
  6. 03 9月, 2015 1 次提交
  7. 10 3月, 2015 1 次提交
    • P
      qemu-thread: do not use PTHREAD_MUTEX_ERRORCHECK · 24fa9049
      Paolo Bonzini 提交于
      PTHREAD_MUTEX_ERRORCHECK is completely broken with respect to fork.
      The way to safely do fork is to bring all threads to a quiescent
      state by acquiring locks (either in callers---as we do for the
      iothread mutex---or using pthread_atfork's prepare callbacks)
      and then release them in the child.
      
      The problem is that releasing error-checking locks in the child
      fails under glibc with EPERM, because the mutex stores a different
      owner tid than the duplicated thread in the child process.  We
      could make it work for locks acquired via pthread_atfork, by
      recreating the mutex in the child instead of unlocking it
      (we know that there are no other threads that could have taken
      the mutex; but when the lock is acquired in fork's caller
      that would not be possible.
      
      The simplest solution is just to forgo error checking.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      24fa9049
  8. 02 2月, 2015 1 次提交
    • P
      qemu-thread: fix qemu_event without futexes · 158ef8cb
      Paolo Bonzini 提交于
      This had a possible deadlock that was visible with rcutorture.
      
          qemu_event_set                    qemu_event_wait
          ----------------------------------------------------------------
                                            cmpxchg reads FREE, writes BUSY
                                            futex_wait: pthread_mutex_lock
                                            futex_wait: value == BUSY
          xchg reads BUSY, writes SET
          futex_wake: pthread_cond_broadcast
                                            futex_wait: pthread_cond_wait
                                            <deadlock>
      
      The fix is simply to avoid condvar tricks and do the obvious locking
      around pthread_cond_broadcast:
      
          qemu_event_set        qemu_event_wait
          ----------------------------------------------------------------
                                            cmpxchg reads FREE, writes BUSY
                                            futex_wait: pthread_mutex_lock
                                            futex_wait: value == BUSY
          xchg reads BUSY, writes SET
          futex_wake: pthread_mutex_lock
          (blocks)
                                            futex_wait: pthread_cond_wait
          (mutex unlocked)
          futex_wake: pthread_cond_broadcast
          futex_wake: pthread_mutex_unlock
                                            futex_wait: pthread_mutex_unlock
      
      Cc: qemu-stable@nongnu.org
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      158ef8cb
  9. 13 1月, 2015 1 次提交
    • P
      qemu-thread: add per-thread atexit functions · ef57137f
      Paolo Bonzini 提交于
      Destructors are the main additional feature of pthread TLS compared
      to __thread.  If we were using C++ (hint, hint!) we could have used
      thread-local objects with a destructor.  Since we are not, instead,
      we add a simple Notifier-based API.
      
      Note that the notifier must be per-thread as well.  We can add a
      global list as well later, perhaps.
      
      The Win32 implementation has some complications because a) detached
      threads used not to have a QemuThreadData; b) the main thread does
      not go through win32_start_routine, so we have to use atexit too.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Reviewed-by: NFam Zheng <famz@redhat.com>
      Message-id: 1417518350-6167-3-git-send-email-pbonzini@redhat.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      ef57137f
  10. 27 3月, 2014 1 次提交
  11. 12 3月, 2014 1 次提交
  12. 10 3月, 2014 2 次提交
  13. 17 10月, 2013 1 次提交
    • P
      qemu-thread: add QemuEvent · c7c4d063
      Paolo Bonzini 提交于
      This emulates Win32 manual-reset events using futexes or conditional
      variables.  Typical ways to use them are with multi-producer,
      single-consumer data structures, to test for a complex condition whose
      elements come from different threads:
      
          for (;;) {
              qemu_event_reset(ev);
              ... test complex condition ...
              if (condition is true) {
                  break;
              }
              qemu_event_wait(ev);
          }
      
      Or more efficiently (but with some duplication):
      
          ... evaluate condition ...
          while (!condition) {
              qemu_event_reset(ev);
              ... evaluate condition ...
              if (!condition) {
                  qemu_event_wait(ev);
                  ... evaluate condition ...
              }
          }
      
      QemuEvent provides a very fast userspace path in the common case when
      no other thread is waiting, or the event is not changing state.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      c7c4d063
  14. 06 8月, 2013 1 次提交
    • I
      semaphore: fix a hangup problem under load on NetBSD hosts. · 79761c66
      Izumi Tsutsui 提交于
      Fix following bugs in "fallback implementation of counting semaphores
      with mutex+condvar" added in c166cb72:
       - waiting threads are not restarted properly if more than one threads
         are waiting unblock signals in qemu_sem_timedwait()
       - possible missing pthread_cond_signal(3) calls when waiting threads
         are returned by ETIMEDOUT
       - fix an uninitialized variable
      The problem is analyzed by and fix is provided by Noriyuki Soda.
      
      Also put additional cleanup suggested by Laszlo Ersek:
       - make QemuSemaphore.count unsigned (it won't be negative)
       - check a return value of in pthread_cond_wait() in qemu_sem_wait()
      Signed-off-by: NIzumi Tsutsui <tsutsui@ceres.dti.ne.jp>
      Reviewed-by: NLaszlo Ersek <lersek@redhat.com>
      Message-id: 1372841894-10634-1-git-send-email-tsutsui@ceres.dti.ne.jp
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      79761c66
  15. 13 1月, 2013 1 次提交
  16. 29 12月, 2012 2 次提交
  17. 19 12月, 2012 1 次提交
  18. 03 11月, 2012 1 次提交
  19. 31 10月, 2012 1 次提交
  20. 03 8月, 2012 1 次提交
  21. 13 12月, 2011 2 次提交
  22. 21 9月, 2011 1 次提交
  23. 19 3月, 2011 1 次提交
  24. 13 3月, 2011 4 次提交
  25. 27 7月, 2010 1 次提交
  26. 15 6月, 2010 1 次提交
  27. 22 7月, 2009 1 次提交
  28. 25 4月, 2009 1 次提交