All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] linux-user/ppc: Deliver SIGTRAP on tw[i]/td[i]
@ 2022-01-03 16:56 matheus.ferst
  2022-01-03 16:56 ` [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP matheus.ferst
  2022-01-03 16:56 ` [PATCH 2/2] tests/tcg/ppc64le: change signal_save_restore_xer to use SIGTRAP matheus.ferst
  0 siblings, 2 replies; 7+ messages in thread
From: matheus.ferst @ 2022-01-03 16:56 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc
  Cc: danielhb413, richard.henderson, laurent, groug, clg,
	Matheus Ferst, david

From: Matheus Ferst <matheus.ferst@eldorado.org.br>

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(-)

-- 
2.25.1



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

* [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP
  2022-01-03 16:56 [PATCH 0/2] linux-user/ppc: Deliver SIGTRAP on tw[i]/td[i] matheus.ferst
@ 2022-01-03 16:56 ` matheus.ferst
  2022-01-03 17:50   ` Richard Henderson
  2022-01-03 16:56 ` [PATCH 2/2] tests/tcg/ppc64le: change signal_save_restore_xer to use SIGTRAP matheus.ferst
  1 sibling, 1 reply; 7+ messages in thread
From: matheus.ferst @ 2022-01-03 16:56 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc
  Cc: danielhb413, richard.henderson, laurent, groug, clg,
	Matheus Ferst, david

From: Matheus Ferst <matheus.ferst@eldorado.org.br>

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

Signed-off-by: Matheus Ferst <matheus.ferst@eldorado.org.br>
---
 linux-user/ppc/cpu_loop.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c
index 30c82f2354..8fbaa772dc 100644
--- a/linux-user/ppc/cpu_loop.c
+++ b/linux-user/ppc/cpu_loop.c
@@ -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 ! */
-- 
2.25.1



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

* [PATCH 2/2] tests/tcg/ppc64le: change signal_save_restore_xer to use SIGTRAP
  2022-01-03 16:56 [PATCH 0/2] linux-user/ppc: Deliver SIGTRAP on tw[i]/td[i] matheus.ferst
  2022-01-03 16:56 ` [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP matheus.ferst
@ 2022-01-03 16:56 ` matheus.ferst
  2022-01-03 17:53   ` Richard Henderson
  1 sibling, 1 reply; 7+ messages in thread
From: matheus.ferst @ 2022-01-03 16:56 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc
  Cc: danielhb413, richard.henderson, laurent, groug, clg,
	Matheus Ferst, david

From: Matheus Ferst <matheus.ferst@eldorado.org.br>

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 <richard.henderson@linaro.org>
Signed-off-by: Matheus Ferst <matheus.ferst@eldorado.org.br>
---
 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 e4f8a07dd7..9227f4f455 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));
-- 
2.25.1



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

* Re: [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP
  2022-01-03 16:56 ` [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP matheus.ferst
@ 2022-01-03 17:50   ` Richard Henderson
  2022-01-03 18:12     ` Matheus K. Ferst
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Henderson @ 2022-01-03 17:50 UTC (permalink / raw)
  To: matheus.ferst, qemu-devel, qemu-ppc
  Cc: laurent, groug, danielhb413, clg, david

On 1/3/22 8:56 AM, matheus.ferst@eldorado.org.br wrote:
> From: Matheus Ferst <matheus.ferst@eldorado.org.br>
> 
> 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
> 
> Signed-off-by: Matheus Ferst <matheus.ferst@eldorado.org.br>
> ---
>   linux-user/ppc/cpu_loop.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c
> index 30c82f2354..8fbaa772dc 100644
> --- a/linux-user/ppc/cpu_loop.c
> +++ b/linux-user/ppc/cpu_loop.c
> @@ -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~


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

* Re: [PATCH 2/2] tests/tcg/ppc64le: change signal_save_restore_xer to use SIGTRAP
  2022-01-03 16:56 ` [PATCH 2/2] tests/tcg/ppc64le: change signal_save_restore_xer to use SIGTRAP matheus.ferst
@ 2022-01-03 17:53   ` Richard Henderson
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 2022-01-03 17:53 UTC (permalink / raw)
  To: matheus.ferst, qemu-devel, qemu-ppc
  Cc: laurent, groug, danielhb413, clg, david

On 1/3/22 8:56 AM, matheus.ferst@eldorado.org.br wrote:
> From: Matheus Ferst<matheus.ferst@eldorado.org.br>
> 
> 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<richard.henderson@linaro.org>
> Signed-off-by: Matheus Ferst<matheus.ferst@eldorado.org.br>
> ---
>   tests/tcg/ppc64le/signal_save_restore_xer.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


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

* Re: [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP
  2022-01-03 17:50   ` Richard Henderson
@ 2022-01-03 18:12     ` Matheus K. Ferst
  2022-01-03 18:20       ` Richard Henderson
  0 siblings, 1 reply; 7+ messages in thread
From: Matheus K. Ferst @ 2022-01-03 18:12 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel, qemu-ppc
  Cc: laurent, groug, danielhb413, clg, david

On 03/01/2022 14:50, Richard Henderson wrote:
> On 1/3/22 8:56 AM, matheus.ferst@eldorado.org.br wrote:
>> From: Matheus Ferst <matheus.ferst@eldorado.org.br>
>>
>> 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
>>
>> Signed-off-by: Matheus Ferst <matheus.ferst@eldorado.org.br>
>> ---
>>   linux-user/ppc/cpu_loop.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c
>> index 30c82f2354..8fbaa772dc 100644
>> --- a/linux-user/ppc/cpu_loop.c
>> +++ b/linux-user/ppc/cpu_loop.c
>> @@ -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 
> 

After this switch-case, there is a

info._sifields._sigfault._addr = env->nip;

Is there anything else to be set?

> 
> 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>


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

* Re: [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP
  2022-01-03 18:12     ` Matheus K. Ferst
@ 2022-01-03 18:20       ` Richard Henderson
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 2022-01-03 18:20 UTC (permalink / raw)
  To: Matheus K. Ferst, qemu-devel, qemu-ppc
  Cc: laurent, groug, danielhb413, clg, david

On 1/3/22 10:12 AM, Matheus K. Ferst wrote:
> On 03/01/2022 14:50, Richard Henderson wrote:
>> On 1/3/22 8:56 AM, matheus.ferst@eldorado.org.br wrote:
>>> From: Matheus Ferst <matheus.ferst@eldorado.org.br>
>>>
>>> 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
>>>
>>> Signed-off-by: Matheus Ferst <matheus.ferst@eldorado.org.br>
>>> ---
>>>   linux-user/ppc/cpu_loop.c | 4 +++-
>>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c
>>> index 30c82f2354..8fbaa772dc 100644
>>> --- a/linux-user/ppc/cpu_loop.c
>>> +++ b/linux-user/ppc/cpu_loop.c
>>> @@ -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
> 
> 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~


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

end of thread, other threads:[~2022-01-03 18:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-03 16:56 [PATCH 0/2] linux-user/ppc: Deliver SIGTRAP on tw[i]/td[i] matheus.ferst
2022-01-03 16:56 ` [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP matheus.ferst
2022-01-03 17:50   ` Richard Henderson
2022-01-03 18:12     ` Matheus K. Ferst
2022-01-03 18:20       ` Richard Henderson
2022-01-03 16:56 ` [PATCH 2/2] tests/tcg/ppc64le: change signal_save_restore_xer to use SIGTRAP matheus.ferst
2022-01-03 17:53   ` Richard Henderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.