linux-user/ppc: Deliver SIGTRAP on tw[i]/td[i]
cover linux-user/ppc: Deliver SIGTRAP on tw[i]/td[i]
From: Matheus Ferst <[email protected]>
In the review of 66c6b40aba1, Richard Henderson suggested[1] using "trap" instead of ".long 0x0" to generate the signal to test XER save/restore behavior. However, linux-user aborts when a trap exception is raised, so we kept the patch with SIGILL.
This patch series is a follow-up to remove the cpu_abort call, deliver SIGTRAP instead (using TRAP_BRKPT as si_code), and apply the suggestion to the signal_save_restore_xer test.
This change may impact issue #588[2], but I had some problems building with --static, so I couldn't test if it solves the problem.
[1] https://lists.gnu.org/archive/html/qemu-ppc/2021-10/msg00143.html
[2] https://gitlab.com/qemu-project/qemu/-/issues/588
Matheus Ferst (2):
linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP tests/tcg/ppc64le: change signal_save_restore_xer to use SIGTRAP
linux-user/ppc/cpu_loop.c | 4 +++- tests/tcg/ppc64le/signal_save_restore_xer.c | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/2 linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP
From: Matheus Ferst <[email protected]>
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
--- linux-user/ppc/cpu_loop.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
linux-user/ppc/cpu_loop.c +3 -1
@@ -242,7 +242,9 @@ void cpu_loop(CPUPPCState *env) }break ;case POWERPC_EXCP_TRAP : -cpu_abort (cs,"Tried to call a TRAP\n" ); + info.si_signo =TARGET_SIGTRAP ; + info.si_errno =0 ; + info.si_code =TARGET_TRAP_BRKPT ;break ;default :/* Should not happen ! */
Signature · 1 line
2.25.1
Re: [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP
Quoted 16 lines · On 1/3/22 8:56 AM, [email protected] wrote:
From: Matheus Ferst <[email protected]>
Handle
POWERPC_EXCP_TRAPincpu_loopto deliver SIGTRAP on tw[i]/td[i]. Thesi_codecomes fromdo_program_checkin the kernel source filearch/powerpc/kernel/traps.cSigned-off-by Matheus Ferst <[email protected]>--- linux-user/ppc/cpu_loop.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)linux-user/ppc/cpu_loop.c +0
-0
linux-user/ppc/cpu_loop.c void cpu_loop(CPUPPCState *env) · line 247
Quoted 7 lines
linux-user/ppc/cpu_loop.c +3
-1@@ -242,7 +242,9 @@ void cpu_loop(CPUPPCState *env) }break ;case POWERPC_EXCP_TRAP : -cpu_abort (cs,"Tried to call a TRAP\n" ); + info.si_signo =TARGET_SIGTRAP ; + info.si_errno =0 ; + info.si_code =TARGET_TRAP_BRKPT ;
You're missing the address, which should be nip.
https://github.com/torvalds/linux/blob/master/arch/powerpc/kernel/traps.c#L1503
Please use force_sig_fault. (I have a pending patch set to convert all other instances; hopefully that can be merged soon...)
r~
Re: [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP
Quoted 27 lines · Richard Henderson
Quoted 18 lines · On 1/3/22 8:56 AM, [email protected] wrote:
From: Matheus Ferst <[email protected]>
Handle
POWERPC_EXCP_TRAPincpu_loopto deliver SIGTRAP on tw[i]/td[i]. Thesi_codecomes fromdo_program_checkin the kernel source filearch/powerpc/kernel/traps.cSigned-off-by Matheus Ferst <[email protected]>---
linux-user/ppc/cpu_loop.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)linux-user/ppc/cpu_loop.c +0
-0@@ -242,7 +242,9 @@ void cpu_loop(CPUPPCState *env) } break;Quoted 5 lines
case
POWERPC_EXCP_TRAP:
-cpu_abort(cs, "Tried to call a TRAP\n"); + info.si_signo =TARGET_SIGTRAP; + info.si_errno = 0;
+ info.si_code =TARGET_TRAP_BRKPT;You're missing the address, which should be nip.
After this switch-case, there is a
info._sifields._sigfault._addr = env->nip;
Is there anything else to be set?
Quoted 4 lines
Please use force_sig_fault. (I have a pending patch set to convert all other instances; hopefully that can be merged soon...)
I'll send v2 with a Based-on
Thanks,
Matheus K. Ferst
Instituto de Pesquisas ELDORADO <http://www.eldorado.org.br/>
Analista de Software
Aviso Legal - Disclaimer <https://www.eldorado.org.br/disclaimer.html>
Re: [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP
Quoted 28 lines · Matheus K. Ferst
Quoted 27 lines · Richard Henderson
Quoted 18 lines · On 1/3/22 8:56 AM, [email protected] wrote:
From: Matheus Ferst <[email protected]>
Handle
POWERPC_EXCP_TRAPincpu_loopto deliver SIGTRAP on tw[i]/td[i]. Thesi_codecomes fromdo_program_checkin the kernel source filearch/powerpc/kernel/traps.cSigned-off-by Matheus Ferst <[email protected]>---
linux-user/ppc/cpu_loop.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)linux-user/ppc/cpu_loop.c +0
-0@@ -242,7 +242,9 @@ void cpu_loop(CPUPPCState *env) } break;Quoted 5 lines
case
POWERPC_EXCP_TRAP:
-cpu_abort(cs, "Tried to call a TRAP\n"); + info.si_signo =TARGET_SIGTRAP; + info.si_errno = 0;
+ info.si_code =TARGET_TRAP_BRKPT;You're missing the address, which should be nip.
Quoted 7 lines
After this switch-case, there is a
info._sifields._sigfault._addr =
env->nip;Is there anything else to be set?
Nope, sorry I missed that.
r~
PATCH 2/2 tests/tcg/ppc64le: change signal_save_restore_xer to use SIGTRAP
In reply to [email protected]From: Matheus Ferst <[email protected]>
Now that linux-user delivers the signal on tw, we can change signal_save_restore_xer to use SIGTRAP instead of SIGILL.
--- tests/tcg/ppc64le/signal_save_restore_xer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tests/tcg/ppc64le/signal_save_restore_xer.c +4 -4
@@ -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));
Signature · 1 line
2.25.1
Re: [PATCH 2/2] tests/tcg/ppc64le: change signal_save_restore_xer to use SIGTRAP
Quoted 10 lines · On 1/3/22 8:56 AM, [email protected] wrote:
From: Matheus Ferst<[email protected]>
Now that linux-user delivers the signal on tw, we can change
signal_save_restore_xerto use SIGTRAP instead of SIGILL.Suggested-by Richard Henderson<[email protected]>Signed-off-by Matheus Ferst<[email protected]>--- tests/tcg/ppc64le/signal_save_restore_xer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
r~