linux-user: signal handling fixes
PATCH 1/3 enable tb unlinking when compiled with NPTL
In reply to [email protected]From: Riku Voipio <[email protected]>
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.
--- exec.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
exec.c +3 -5
@@ -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 */
Signature · 1 line
1.6.3.3
PATCH 2/3 linux-user: Fix mmap_lock ordering
In reply to [email protected]From: Riku Voipio <[email protected]>
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().
--- linux-user/main.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
linux-user/main.c +2 -2
@@ -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
Signature · 1 line
1.6.3.3
PATCH 3/3 linux-user: cleanup force_sig() calls
In reply to [email protected]From: Riku Voipio <[email protected]>
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.
--- linux-user/signal.c | 40 ++++++++++++++++++++-------------------- 1 files changed, 20 insertions(+), 20 deletions(-)
linux-user/signal.c +20 -20
@@ -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)
Signature · 1 line
1.6.3.3
cover linux-user: signal handling fixes
From: Riku Voipio <[email protected]>
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(-)