Skip to contentSkip to conversation

linux-user/hppa: Fix segfaults on page zero

PATCH Applied Helge Deller 3 participants 3 messages Jul 18, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 linux-user/hppa: Fix segfaults on page zero

This program:

    int main(void) { asm("bv %r0(%r0)"); return 0; }

produces on real hppa hardware the expected segfault:

SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x3} --- killed by SIGSEGV +++
Segmentation fault

But when run on linux-user you get instead internal qemu errors:

ERROR: linux-user/hppa/cpu_loop.c:172:cpu_loop: code should not be reached Bail out! ERROR: linux-user/hppa/cpu_loop.c:172:cpu_loop: code should not be reached
ERROR: accel/tcg/cpu-exec.c:933:cpu_exec: assertion failed: (cpu == current_cpu) Bail out! ERROR: accel/tcg/cpu-exec.c:933:cpu_exec: assertion failed: (cpu == current_cpu)

Fix it by adding the missing case for the EXCP_IMP trap in cpu_loop() and raise a segfault.

---
Changes:

v2: Dropped the "+++" in the commit message - it confused b4 and git-am.
no functional changes.

---

linux-user/hppa/cpu_loop.c +3 -0
index a576d1a249..8f374aeef6 100644
@@ -143,6 +143,9 @@ void cpu_loop(CPUHPPAState *env)
             env->iaoq_f = env->gr[31];
             env->iaoq_b = env->gr[31] + 4;
             break;
+        case EXCP_IMP:
+            force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, env->iaoq_f);
+            break;
         case EXCP_ILL:
             force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->iaoq_f);
             break;
Reviewed-by on v2 1/1
#1 lore raw
Quoted 21 lines · Helge Deller

This program:

    int main(void) { asm("bv %r0(%r0)"); return 0; }

produces on real hppa hardware the expected segfault:

SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x3} --- killed by SIGSEGV +++
Segmentation fault

But when run on linux-user you get instead internal qemu errors:

ERROR: linux-user/hppa/cpu_loop.c:172:cpu_loop: code should not be reached Bail out! ERROR: linux-user/hppa/cpu_loop.c:172:cpu_loop: code should not be reached
ERROR: accel/tcg/cpu-exec.c:933:cpu_exec: assertion failed: (cpu == current_cpu) Bail out! ERROR: accel/tcg/cpu-exec.c:933:cpu_exec: assertion failed: (cpu == current_cpu)

Fix it by adding the missing case for the EXCP_IMP trap in cpu_loop() and raise a segfault.

Quoted 6 lines

---
Changes:

v2: Dropped the "+++" in the commit message - it confused b4 and git-am.
no functional changes.

thanks
-- PMM

#2 lore raw
In reply to Helge Deller

Le 18/07/2022 à 18:40, Helge Deller a écrit :

Quoted 36 lines

This program:

     int main(void) { asm("bv %r0(%r0)"); return 0; }

produces on real hppa hardware the expected segfault:

SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x3} --- killed by SIGSEGV +++
Segmentation fault

But when run on linux-user you get instead internal qemu errors:

ERROR: linux-user/hppa/cpu_loop.c:172:cpu_loop: code should not be reached Bail out! ERROR: linux-user/hppa/cpu_loop.c:172:cpu_loop: code should not be reached
ERROR: accel/tcg/cpu-exec.c:933:cpu_exec: assertion failed: (cpu == current_cpu) Bail out! ERROR: accel/tcg/cpu-exec.c:933:cpu_exec: assertion failed: (cpu == current_cpu)

Fix it by adding the missing case for the EXCP_IMP trap in cpu_loop() and raise a segfault.

---
Changes:

v2: Dropped the "+++" in the commit message - it confused b4 and git-am.
no functional changes.

---

linux-user/hppa/cpu_loop.c +0 -0
index a576d1a249..8f374aeef6 100644

linux-user/hppa/cpu_loop.c void cpu_loop(CPUHPPAState *env) · line 151

Quoted 9 lines
linux-user/hppa/cpu_loop.c +3 -0
@@ -143,6 +143,9 @@ void cpu_loop(CPUHPPAState *env)
              env->iaoq_f = env->gr[31];
              env->iaoq_b = env->gr[31] + 4;
              break;
+        case EXCP_IMP:
+            force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, env->iaoq_f);
+            break;
          case EXCP_ILL:
              force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->iaoq_f);
              break;

Applied to my linux-user-for-7.1 branch.

Thanks,
Laurent