[PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP

matheus.ferst@eldorado.org.br posted 2 patches 4 years, 1 month ago
Maintainers: Laurent Vivier <laurent@vivier.eu>
There is a newer version of this series
[PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP
Posted by matheus.ferst@eldorado.org.br 4 years, 1 month ago
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


Re: [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP
Posted by Richard Henderson 4 years, 1 month ago
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~

Re: [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP
Posted by Matheus K. Ferst 4 years, 1 month ago
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>

Re: [PATCH 1/2] linux-user/ppc: deliver SIGTRAP on POWERPC_EXCP_TRAP
Posted by Richard Henderson 4 years, 1 month ago
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~