Skip to contentSkip to conversation

Fix signal handling of SIG_IPI when io-thread is enabled

PATCH Applied Alexandre Raymond 3 participants 5 messages Jun 15, 2011 – Jul 16, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix signal handling of SIG_IPI when io-thread is enabled

Both the signal thread (via sigwait()) and the cpu thread (via a normal signal handler) were attempting to catch SIG_IPI.

This resulted in random freezes under Darwin.

This patch separates SIG_IPI from the rest of the signals handled by the signal thread, because it is independently caught by the cpu thread.

---
 cpus.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
cpus.c +9 -1
index 18a1522..84ffd1c 100644
@@ -394,10 +394,18 @@ static int qemu_signal_init(void)
     sigaddset(&set, SIGUSR2);
     pthread_sigmask(SIG_UNBLOCK, &set, NULL);
 
+    /*
+     * SIG_IPI must be blocked in the main thread and must not be caught
+     * by sigwait() in the signal thread. Otherwise, the cpu thread will
+     * not catch it reliably.
+     */
+    sigemptyset(&set);
+    sigaddset(&set, SIG_IPI);
+    pthread_sigmask(SIG_BLOCK, &set, NULL);
+
     sigemptyset(&set);
     sigaddset(&set, SIGIO);
     sigaddset(&set, SIGALRM);
-    sigaddset(&set, SIG_IPI);
     sigaddset(&set, SIGBUS);
 #else
     sigemptyset(&set);
Signature · 1 line
1.7.5
Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · Alexandre Raymond

Both the signal thread (via sigwait()) and the cpu thread (via a normal signal handler) were attempting to catch SIG_IPI.

Why? Ahh, because of qemu_cpu_kick_self: raise(SIG_IPI)! That should generate a per-process SIG_IPI. And that may not only affect Darwin. Looks good.

Quoted 36 lines

This resulted in random freezes under Darwin.

This patch separates SIG_IPI from the rest of the signals handled by the signal thread, because it is independently caught by the cpu thread.

---
 cpus.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
cpus.c +9 -1
index 18a1522..84ffd1c 100644
@@ -394,10 +394,18 @@ static int qemu_signal_init(void)
     sigaddset(&set, SIGUSR2);
     pthread_sigmask(SIG_UNBLOCK, &set, NULL);
 
+    /*
+     * SIG_IPI must be blocked in the main thread and must not be caught
+     * by sigwait() in the signal thread. Otherwise, the cpu thread will
+     * not catch it reliably.
+     */
+    sigemptyset(&set);
+    sigaddset(&set, SIG_IPI);
+    pthread_sigmask(SIG_BLOCK, &set, NULL);
+
     sigemptyset(&set);
     sigaddset(&set, SIGIO);
     sigaddset(&set, SIGALRM);
-    sigaddset(&set, SIG_IPI);
     sigaddset(&set, SIGBUS);
 #else
     sigemptyset(&set);
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#2 lore raw

Hi Jan,

Quoted 3 lines

Why? Ahh, because of qemu_cpu_kick_self: raise(SIG_IPI)! That should generate a per-process SIG_IPI. And that may not only affect Darwin. Looks good.

Actually, with io-thread enabled, it goes through qemu_cpu_kick_self() -> qemu_cpu_kick_thread() -> pthread_kill(..., SIG_IPI).

I think the problem is with sigwait(). It doesn't state so in the Linux or Darwin man pages, but on Solaris, it says : "All signals identified by the set argument must be blocked on all threads, including the calling thread; otherwise, sigwait() might not work correctly", which might correspond to the issue I've been witnessing (ie: sigwait() unblocking once in a while on a SIGUSR1 (SIG_IPI) in the event thread).

In any case, I don't think it should attempt to catch this signal at all since the cpu thread is already catching it.

Alexandre

#3 lore raw

ping?

Quoted 22 lines · Alexandre Raymond

Hi Jan,

Quoted 3 lines

Why? Ahh, because of qemu_cpu_kick_self: raise(SIG_IPI)! That should generate a per-process SIG_IPI. And that may not only affect Darwin. Looks good.

Actually, with io-thread enabled, it goes through qemu_cpu_kick_self() -> qemu_cpu_kick_thread() -> pthread_kill(..., SIG_IPI).

I think the problem is with sigwait(). It doesn't state so in the Linux or Darwin man pages, but on Solaris, it says : "All signals identified by the set argument must be blocked on all threads, including the calling thread; otherwise, sigwait() might not work correctly", which might correspond to the issue I've been witnessing (ie: sigwait() unblocking once in a while on a SIGUSR1 (SIG_IPI) in the event thread).

In any case, I don't think it should attempt to catch this signal at all since the cpu thread is already catching it.

Alexandre

Applied
#4 lore raw

Thanks, applied.

Quoted 27 lines · Alexandre Raymond

ping?

Quoted 22 lines · Alexandre Raymond

Hi Jan,

Quoted 3 lines

Why? Ahh, because of qemu_cpu_kick_self: raise(SIG_IPI)! That should generate a per-process SIG_IPI. And that may not only affect Darwin. Looks good.

Actually, with io-thread enabled, it goes through qemu_cpu_kick_self() -> qemu_cpu_kick_thread() -> pthread_kill(..., SIG_IPI).

I think the problem is with sigwait(). It doesn't state so in the Linux or Darwin man pages, but on Solaris, it says : "All signals identified by the set argument must be blocked on all threads, including the calling thread; otherwise, sigwait() might not work correctly", which might correspond to the issue I've been witnessing (ie: sigwait() unblocking once in a while on a SIGUSR1 (SIG_IPI) in the event thread).

In any case, I don't think it should attempt to catch this signal at all since the cpu thread is already catching it.

Alexandre