qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/3] linux-user: signal handling fixes
@ 2009-12-04 13:16 riku.voipio
  2009-12-04 13:16 ` [Qemu-devel] [PATCH 1/3] enable tb unlinking when compiled with NPTL riku.voipio
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: riku.voipio @ 2009-12-04 13:16 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio

From: Riku Voipio <riku.voipio@nokia.com>

Same stuff can be grabbed with:

git pull git://gitorious.org/qemu-maemo/qemu-maemo.git linux-user-for-upstream


Riku Voipio (3):
  enable tb unlinking when compiled with NPTL
  linux-user: Fix mmap_lock ordering
  linux-user: cleanup force_sig() calls

 exec.c              |    8 +++-----
 linux-user/main.c   |    4 ++--
 linux-user/signal.c |   40 ++++++++++++++++++++--------------------
 3 files changed, 25 insertions(+), 27 deletions(-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 1/3] enable tb unlinking when compiled with NPTL
  2009-12-04 13:16 [Qemu-devel] [PATCH 0/3] linux-user: signal handling fixes riku.voipio
@ 2009-12-04 13:16 ` riku.voipio
  2009-12-04 13:16 ` [Qemu-devel] [PATCH 2/3] linux-user: Fix mmap_lock ordering riku.voipio
  2009-12-04 13:16 ` [Qemu-devel] [PATCH 3/3] linux-user: cleanup force_sig() calls riku.voipio
  2 siblings, 0 replies; 4+ messages in thread
From: riku.voipio @ 2009-12-04 13:16 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio

From: Riku Voipio <riku.voipio@nokia.com>

Fixes recieving signals when guest code is being executed in a tight
loop. For an example, try interrupting the following code with ctrl-c.

http://nchipin.kos.to/test-loop.c

The tight loop is ofcourse brainless, but it is also exactly how the waitpid* testcases
are implemented.

Signed-off-by: Riku Voipio <riku.voipio@nokia.com>
---
 exec.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/exec.c b/exec.c
index eb1ee51..3f7e4eb 100644
--- a/exec.c
+++ b/exec.c
@@ -1526,24 +1526,22 @@ void cpu_set_log_filename(const char *filename)
 
 static void cpu_unlink_tb(CPUState *env)
 {
-#if defined(CONFIG_USE_NPTL)
     /* FIXME: TB unchaining isn't SMP safe.  For now just ignore the
        problem and hope the cpu will stop of its own accord.  For userspace
        emulation this often isn't actually as bad as it sounds.  Often
        signals are used primarily to interrupt blocking syscalls.  */
-#else
     TranslationBlock *tb;
     static spinlock_t interrupt_lock = SPIN_LOCK_UNLOCKED;
 
     tb = env->current_tb;
     /* if the cpu is currently executing code, we must unlink it and
        all the potentially executing TB */
-    if (tb && !testandset(&interrupt_lock)) {
+    if (tb) {
+        spin_lock(&interrupt_lock);
         env->current_tb = NULL;
         tb_reset_jump_recursive(tb);
-        resetlock(&interrupt_lock);
+        spin_unlock(&interrupt_lock);
     }
-#endif
 }
 
 /* mask must never be zero, except for A20 change call */
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 2/3] linux-user: Fix mmap_lock ordering
  2009-12-04 13:16 [Qemu-devel] [PATCH 0/3] linux-user: signal handling fixes riku.voipio
  2009-12-04 13:16 ` [Qemu-devel] [PATCH 1/3] enable tb unlinking when compiled with NPTL riku.voipio
@ 2009-12-04 13:16 ` riku.voipio
  2009-12-04 13:16 ` [Qemu-devel] [PATCH 3/3] linux-user: cleanup force_sig() calls riku.voipio
  2 siblings, 0 replies; 4+ messages in thread
From: riku.voipio @ 2009-12-04 13:16 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio

From: Riku Voipio <riku.voipio@nokia.com>

mmap_lock() can be called while tb_lock() is being held. To
avoid deadlock when one thread is holding mmap_lock and another
tb_lock, _always_ lock first tb_lock().

Signed-off-by: Riku Voipio <riku.voipio@nokia.com>
---
 linux-user/main.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 5fbcda2..2015f32 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -99,13 +99,14 @@ static int pending_cpus;
 /* Make sure everything is in a consistent state for calling fork().  */
 void fork_start(void)
 {
-    mmap_fork_start();
     pthread_mutex_lock(&tb_lock);
     pthread_mutex_lock(&exclusive_lock);
+    mmap_fork_start();
 }
 
 void fork_end(int child)
 {
+    mmap_fork_end(child);
     if (child) {
         /* Child processes created by fork() only have a single thread.
            Discard information about the parent threads.  */
@@ -122,7 +123,6 @@ void fork_end(int child)
         pthread_mutex_unlock(&exclusive_lock);
         pthread_mutex_unlock(&tb_lock);
     }
-    mmap_fork_end(child);
 }
 
 /* Wait for pending exclusive operations to complete.  The exclusive lock
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 3/3] linux-user: cleanup force_sig() calls
  2009-12-04 13:16 [Qemu-devel] [PATCH 0/3] linux-user: signal handling fixes riku.voipio
  2009-12-04 13:16 ` [Qemu-devel] [PATCH 1/3] enable tb unlinking when compiled with NPTL riku.voipio
  2009-12-04 13:16 ` [Qemu-devel] [PATCH 2/3] linux-user: Fix mmap_lock ordering riku.voipio
@ 2009-12-04 13:16 ` riku.voipio
  2 siblings, 0 replies; 4+ messages in thread
From: riku.voipio @ 2009-12-04 13:16 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio

From: Riku Voipio <riku.voipio@nokia.com>

Force_sig should be always called with TARGET_ signals.
Not that it really matters with SEGV, so this patch is
just for cleanup and improving consistency.

Signed-off-by: Riku Voipio <riku.voipio@nokia.com>
---
 linux-user/signal.c |   40 ++++++++++++++++++++--------------------
 1 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index df189c3..b0faf2e 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -366,19 +366,19 @@ static inline void free_sigqueue(CPUState *env, struct sigqueue *q)
 }
 
 /* abort execution with signal */
-static void QEMU_NORETURN force_sig(int sig)
+static void QEMU_NORETURN force_sig(int target_sig)
 {
     TaskState *ts = (TaskState *)thread_env->opaque;
     int host_sig, core_dumped = 0;
     struct sigaction act;
-    host_sig = target_to_host_signal(sig);
-    gdb_signalled(thread_env, sig);
+    host_sig = target_to_host_signal(target_sig);
+    gdb_signalled(thread_env, target_sig);
 
     /* dump core if supported by target binary format */
-    if (core_dump_signal(sig) && (ts->bprm->core_dump != NULL)) {
+    if (core_dump_signal(target_sig) && (ts->bprm->core_dump != NULL)) {
         stop_all_tasks();
         core_dumped =
-            ((*ts->bprm->core_dump)(sig, thread_env) == 0);
+            ((*ts->bprm->core_dump)(target_sig, thread_env) == 0);
     }
     if (core_dumped) {
         /* we already dumped the core of target process, we don't want
@@ -388,7 +388,7 @@ static void QEMU_NORETURN force_sig(int sig)
         nodump.rlim_cur=0;
         setrlimit(RLIMIT_CORE, &nodump);
         (void) fprintf(stderr, "qemu: uncaught target signal %d (%s) - %s\n",
-            sig, strsignal(host_sig), "core dumped" );
+            target_sig, strsignal(host_sig), "core dumped" );
     }
 
     /* The proper exit code for dieing from an uncaught signal is
@@ -1487,7 +1487,7 @@ static long do_sigreturn_v1(CPUState *env)
 
 badframe:
 	unlock_user_struct(frame, frame_addr, 0);
-        force_sig(SIGSEGV /* , current */);
+        force_sig(TARGET_SIGSEGV /* , current */);
 	return 0;
 }
 
@@ -1539,7 +1539,7 @@ static long do_sigreturn_v2(CPUState *env)
 
 badframe:
 	unlock_user_struct(frame, frame_addr, 0);
-        force_sig(SIGSEGV /* , current */);
+        force_sig(TARGET_SIGSEGV /* , current */);
 	return 0;
 }
 
@@ -1589,7 +1589,7 @@ static long do_rt_sigreturn_v1(CPUState *env)
 
 badframe:
 	unlock_user_struct(frame, frame_addr, 0);
-        force_sig(SIGSEGV /* , current */);
+        force_sig(TARGET_SIGSEGV /* , current */);
 	return 0;
 }
 
@@ -1618,7 +1618,7 @@ static long do_rt_sigreturn_v2(CPUState *env)
 
 badframe:
 	unlock_user_struct(frame, frame_addr, 0);
-        force_sig(SIGSEGV /* , current */);
+        force_sig(TARGET_SIGSEGV /* , current */);
 	return 0;
 }
 
@@ -2160,7 +2160,7 @@ void sparc64_set_context(CPUSPARCState *env)
     return;
  do_sigsegv:
     unlock_user_struct(ucp, ucp_addr, 0);
-    force_sig(SIGSEGV);
+    force_sig(TARGET_SIGSEGV);
 }
 
 void sparc64_get_context(CPUSPARCState *env)
@@ -2254,7 +2254,7 @@ void sparc64_get_context(CPUSPARCState *env)
     return;
  do_sigsegv:
     unlock_user_struct(ucp, ucp_addr, 1);
-    force_sig(SIGSEGV);
+    force_sig(TARGET_SIGSEGV);
 }
 #endif
 #elif defined(TARGET_ABI_MIPSN64)
@@ -2908,7 +2908,7 @@ static void setup_frame(int sig, struct target_sigaction *ka,
 
 give_sigsegv:
     unlock_user_struct(frame, frame_addr, 1);
-    force_sig(SIGSEGV);
+    force_sig(TARGET_SIGSEGV);
 }
 
 static void setup_rt_frame(int sig, struct target_sigaction *ka,
@@ -2971,7 +2971,7 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka,
 
 give_sigsegv:
     unlock_user_struct(frame, frame_addr, 1);
-    force_sig(SIGSEGV);
+    force_sig(TARGET_SIGSEGV);
 }
 
 long do_sigreturn(CPUState *regs)
@@ -3850,7 +3850,7 @@ sigsegv:
     unlock_user_struct(frame, frame_addr, 1);
     if (logfile)
         fprintf (logfile, "segfaulting from setup_frame\n");
-    force_sig(SIGSEGV);
+    force_sig(TARGET_SIGSEGV);
 }
 
 static void setup_rt_frame(int sig, struct target_sigaction *ka,
@@ -3919,7 +3919,7 @@ sigsegv:
     unlock_user_struct(rt_sf, rt_sf_addr, 1);
     if (logfile)
         fprintf (logfile, "segfaulting from setup_rt_frame\n");
-    force_sig(SIGSEGV);
+    force_sig(TARGET_SIGSEGV);
 
 }
 
@@ -3961,7 +3961,7 @@ sigsegv:
     unlock_user_struct(sc, sc_addr, 1);
     if (logfile)
         fprintf (logfile, "segfaulting from do_sigreturn\n");
-    force_sig(SIGSEGV);
+    force_sig(TARGET_SIGSEGV);
     return 0;
 }
 
@@ -4024,7 +4024,7 @@ sigsegv:
     unlock_user_struct(rt_sf, rt_sf_addr, 1);
     if (logfile)
         fprintf (logfile, "segfaulting from do_rt_sigreturn\n");
-    force_sig(SIGSEGV);
+    force_sig(TARGET_SIGSEGV);
     return 0;
 }
 
@@ -4194,7 +4194,7 @@ static void setup_frame(int sig, struct target_sigaction *ka,
 
 give_sigsegv:
     unlock_user_struct(frame, frame_addr, 1);
-    force_sig(SIGSEGV);
+    force_sig(TARGET_SIGSEGV);
 }
 
 static inline int target_rt_setup_ucontext(struct target_ucontext *uc,
@@ -4336,7 +4336,7 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka,
 
 give_sigsegv:
     unlock_user_struct(frame, frame_addr, 1);
-    force_sig(SIGSEGV);
+    force_sig(TARGET_SIGSEGV);
 }
 
 long do_sigreturn(CPUState *env)
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-12-04 13:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-04 13:16 [Qemu-devel] [PATCH 0/3] linux-user: signal handling fixes riku.voipio
2009-12-04 13:16 ` [Qemu-devel] [PATCH 1/3] enable tb unlinking when compiled with NPTL riku.voipio
2009-12-04 13:16 ` [Qemu-devel] [PATCH 2/3] linux-user: Fix mmap_lock ordering riku.voipio
2009-12-04 13:16 ` [Qemu-devel] [PATCH 3/3] linux-user: cleanup force_sig() calls riku.voipio

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).