From 4ff17cf0aa8854941dc0538c74d4f1677a570575 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Fri, 14 Jan 2022 15:50:32 +0000 Subject: linux-user: Remove stale "not threadsafe" comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In linux-user/signal.c we have two FIXME comments claiming that parts of the signal-handling code are not threadsafe. These are very old, as they were first introduced in commit 624f7979058 in 2008. Since then we've radically overhauled the signal-handling logic, while carefully preserving these FIXME comments. It's unclear exactly what thread-safety issue the original author was trying to point out -- the relevant data structures are in the TaskStruct, which makes them per-thread and only operated on by that thread. The old code at the time of that commit did have various races involving signal handlers being invoked at awkward times; possibly this was what was meant. Delete these FIXME comments: * they were written at a time when the way we handled signals was completely different * the code today appears to us to not have thread-safety issues * nobody knows what the problem the comments were trying to point out was so they are serving no useful purpose for us today. Signed-off-by: Peter Maydell Reviewed-by: Alex Bennée Reviewed-by: Warner Losh Message-Id: <20220114155032.3767771-1-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/signal.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 27a0ff3..2a3f3cc 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -999,7 +999,6 @@ int do_sigaction(int sig, const struct target_sigaction *act, oact->sa_mask = k->sa_mask; } if (act) { - /* FIXME: This is not threadsafe. */ __get_user(k->_sa_handler, &act->_sa_handler); __get_user(k->sa_flags, &act->sa_flags); #ifdef TARGET_ARCH_HAS_SA_RESTORER @@ -1149,7 +1148,6 @@ void process_pending_signals(CPUArchState *cpu_env) sigset_t *blocked_set; while (qatomic_read(&ts->signal_pending)) { - /* FIXME: This is not threadsafe. */ sigfillset(&set); sigprocmask(SIG_SETMASK, &set, 0); -- cgit v1.1 From 083fe9a12d2025bb719ce8fb8cef86266f9bdddd Mon Sep 17 00:00:00 2001 From: Matheus Ferst Date: Thu, 13 Jan 2022 14:04:54 -0300 Subject: linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP Handle POWERPC_EXCP_TRAP in cpu_loop to deliver SIGTRAP on tw[i]/td[i]. The si_code comes from do_program_check in the kernel source file arch/powerpc/kernel/traps.c Reviewed-by: Richard Henderson Signed-off-by: Matheus Ferst Message-Id: <20220113170456.1796911-2-matheus.ferst@eldorado.org.br> Signed-off-by: Laurent Vivier --- linux-user/ppc/cpu_loop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c index c5d8099..b468f19 100644 --- a/linux-user/ppc/cpu_loop.c +++ b/linux-user/ppc/cpu_loop.c @@ -181,7 +181,8 @@ void cpu_loop(CPUPPCState *env) } break; case POWERPC_EXCP_TRAP: - cpu_abort(cs, "Tried to call a TRAP\n"); + si_signo = TARGET_SIGTRAP; + si_code = TARGET_TRAP_BRKPT; break; default: /* Should not happen ! */ -- cgit v1.1 From 62089c849d49f92823c68624720cdac8fa4b43e0 Mon Sep 17 00:00:00 2001 From: Matheus Ferst Date: Thu, 13 Jan 2022 14:04:55 -0300 Subject: tests/tcg/ppc64le: change signal_save_restore_xer to use SIGTRAP Now that linux-user delivers the signal on tw, we can change signal_save_restore_xer to use SIGTRAP instead of SIGILL. Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Signed-off-by: Matheus Ferst Message-Id: <20220113170456.1796911-3-matheus.ferst@eldorado.org.br> Signed-off-by: Laurent Vivier --- tests/tcg/ppc64le/signal_save_restore_xer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/tcg/ppc64le/signal_save_restore_xer.c b/tests/tcg/ppc64le/signal_save_restore_xer.c index e4f8a07..9227f4f 100644 --- a/tests/tcg/ppc64le/signal_save_restore_xer.c +++ b/tests/tcg/ppc64le/signal_save_restore_xer.c @@ -11,7 +11,7 @@ uint64_t saved; -void sigill_handler(int sig, siginfo_t *si, void *ucontext) +void sigtrap_handler(int sig, siginfo_t *si, void *ucontext) { ucontext_t *uc = ucontext; uc->uc_mcontext.regs->nip += 4; @@ -23,14 +23,14 @@ int main(void) { uint64_t initial = XER_CA | XER_CA32, restored; struct sigaction sa = { - .sa_sigaction = sigill_handler, + .sa_sigaction = sigtrap_handler, .sa_flags = SA_SIGINFO }; - sigaction(SIGILL, &sa, NULL); + sigaction(SIGTRAP, &sa, NULL); asm("mtspr 1, %1\n\t" - ".long 0x0\n\t" + "trap\n\t" "mfspr %0, 1\n\t" : "=r" (restored) : "r" (initial)); -- cgit v1.1