[PATCH for-10.1 1/2] linux-user/aarch64: Check syndrome for EXCP_UDEF

Richard Henderson posted 2 patches 3 months, 3 weeks ago
Maintainers: Laurent Vivier <laurent@vivier.eu>
There is a newer version of this series
[PATCH for-10.1 1/2] linux-user/aarch64: Check syndrome for EXCP_UDEF
Posted by Richard Henderson 3 months, 3 weeks ago
Note that we have been passing the incorrect code for
uncategorized and bti faults.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/aarch64/cpu_loop.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c
index fea43cefa6..43a471b535 100644
--- a/linux-user/aarch64/cpu_loop.c
+++ b/linux-user/aarch64/cpu_loop.c
@@ -32,6 +32,7 @@ void cpu_loop(CPUARMState *env)
 {
     CPUState *cs = env_cpu(env);
     int trapnr, ec, fsc, si_code, si_signo;
+    uint64_t addr;
     abi_long ret;
 
     for (;;) {
@@ -63,10 +64,12 @@ void cpu_loop(CPUARMState *env)
             /* just indicate that signals should be handled asap */
             break;
         case EXCP_UDEF:
-            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->pc);
-            break;
+            addr = env->pc;
+            goto do_syndrome;
         case EXCP_PREFETCH_ABORT:
         case EXCP_DATA_ABORT:
+            addr = env->exception.vaddress;
+        do_syndrome:
             ec = syn_get_ec(env->exception.syndrome);
             switch (ec) {
             case EC_DATAABORT:
@@ -99,10 +102,19 @@ void cpu_loop(CPUARMState *env)
                 si_signo = TARGET_SIGBUS;
                 si_code = TARGET_BUS_ADRALN;
                 break;
+            case EC_UNCATEGORIZED:
+            case EC_BTITRAP:
+                si_signo = TARGET_SIGILL;
+                si_code = TARGET_ILL_ILLOPC;
+                break;
+            case EC_PACFAIL:
+                si_signo = TARGET_SIGILL;
+                si_code = TARGET_ILL_ILLOPN;
+                break;
             default:
                 g_assert_not_reached();
             }
-            force_sig_fault(si_signo, si_code, env->exception.vaddress);
+            force_sig_fault(si_signo, si_code, addr);
             break;
         case EXCP_DEBUG:
         case EXCP_BKPT:
-- 
2.43.0
Re: [PATCH for-10.1 1/2] linux-user/aarch64: Check syndrome for EXCP_UDEF
Posted by Pierrick Bouvier 3 months, 3 weeks ago
On 7/25/25 9:51 AM, Richard Henderson wrote:
> Note that we have been passing the incorrect code for
> uncategorized and bti faults.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   linux-user/aarch64/cpu_loop.c | 18 +++++++++++++++---
>   1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c
> index fea43cefa6..43a471b535 100644
> --- a/linux-user/aarch64/cpu_loop.c
> +++ b/linux-user/aarch64/cpu_loop.c
> @@ -32,6 +32,7 @@ void cpu_loop(CPUARMState *env)
>   {
>       CPUState *cs = env_cpu(env);
>       int trapnr, ec, fsc, si_code, si_signo;
> +    uint64_t addr;
>       abi_long ret;
>   
>       for (;;) {
> @@ -63,10 +64,12 @@ void cpu_loop(CPUARMState *env)
>               /* just indicate that signals should be handled asap */
>               break;
>           case EXCP_UDEF:
> -            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->pc);
> -            break;
> +            addr = env->pc;
> +            goto do_syndrome;
>           case EXCP_PREFETCH_ABORT:
>           case EXCP_DATA_ABORT:
> +            addr = env->exception.vaddress;
> +        do_syndrome:
>               ec = syn_get_ec(env->exception.syndrome);
>               switch (ec) {
>               case EC_DATAABORT:
> @@ -99,10 +102,19 @@ void cpu_loop(CPUARMState *env)
>                   si_signo = TARGET_SIGBUS;
>                   si_code = TARGET_BUS_ADRALN;
>                   break;
> +            case EC_UNCATEGORIZED:
> +            case EC_BTITRAP:
> +                si_signo = TARGET_SIGILL;
> +                si_code = TARGET_ILL_ILLOPC;
> +                break;
> +            case EC_PACFAIL:
> +                si_signo = TARGET_SIGILL;
> +                si_code = TARGET_ILL_ILLOPN;
> +                break;
>               default:
>                   g_assert_not_reached();
>               }
> -            force_sig_fault(si_signo, si_code, env->exception.vaddress);
> +            force_sig_fault(si_signo, si_code, addr);
>               break;
>           case EXCP_DEBUG:
>           case EXCP_BKPT:

It may be worth for lisibility to extract do_syndrome to a proper 
function. It's just a recommendation though.

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>