Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame^] | 1 | Upstream-Status: Submitted |
| 2 | |
| 3 | From f354b9333408d411854af058cc44cceda60b4473 Mon Sep 17 00:00:00 2001 |
| 4 | From: =?UTF-8?q?An=C3=ADbal=20Lim=C3=B3n?= <anibal.limon@linux.intel.com> |
| 5 | Date: Thu, 3 Sep 2015 14:07:34 -0500 |
| 6 | Subject: [PATCH] cpus.c: qemu_mutex_lock_iothread fix race condition at cpu |
| 7 | thread init |
| 8 | MIME-Version: 1.0 |
| 9 | Content-Type: text/plain; charset=UTF-8 |
| 10 | Content-Transfer-Encoding: 8bit |
| 11 | |
| 12 | When QEMU starts the RCU thread executes qemu_mutex_lock_thread |
| 13 | causing error "qemu:qemu_cpu_kick_thread: No such process" and exits. |
| 14 | |
| 15 | This isn't occur frequently but in glibc the thread id can exist and |
| 16 | this not guarantee that the thread is on active/running state. If is |
| 17 | inserted a sleep(1) after newthread assignment [1] the issue appears. |
| 18 | |
| 19 | So not make assumption that thread exist if first_cpu->thread is set |
| 20 | then change the validation of cpu to created that is set into cpu |
| 21 | threads (kvm, tcg, dummy). |
| 22 | |
| 23 | [1] https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_create.c;h=d10f4ea8004e1d8f3a268b95cc0f8d93b8d89867;hb=HEAD#l621 |
| 24 | |
| 25 | Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> |
| 26 | --- |
| 27 | cpus.c | 2 +- |
| 28 | 1 file changed, 1 insertion(+), 1 deletion(-) |
| 29 | |
| 30 | diff --git a/cpus.c b/cpus.c |
| 31 | index 7e4786e..05e5400 100644 |
| 32 | --- a/cpus.c |
| 33 | +++ b/cpus.c |
| 34 | @@ -1171,7 +1171,7 @@ void qemu_mutex_lock_iothread(void) |
| 35 | * TCG code execution. |
| 36 | */ |
| 37 | if (!tcg_enabled() || qemu_in_vcpu_thread() || |
| 38 | - !first_cpu || !first_cpu->thread) { |
| 39 | + !first_cpu || !first_cpu->created) { |
| 40 | qemu_mutex_lock(&qemu_global_mutex); |
| 41 | atomic_dec(&iothread_requesting_mutex); |
| 42 | } else { |
| 43 | -- |
| 44 | 1.9.1 |
| 45 | |