Skip to contentSkip to conversation

target-ppc, tcg: fix usermode segfault with pthread_create()

PATCH In review Sam Bobroff 4 participants 4 messages Feb 7, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 target-ppc, tcg: fix usermode segfault with pthread_create()

Programs run under qemu-ppc64 on an x86_64 host currently segfault if they use pthread_create() due to the adjustment made to the NIP in commit bd6fefe71cec5a0c7d2be4ac96307f25db56abf9.

This patch changes cpu_loop() to set the NIP back to the pre-incremented value before calling do_syscall(), which causes the correct address to be used for the new thread and corrects the fault.

---

v2:

* Remove the NIP adjustment from the -TARGET_QEMU_ESIGRETURN case, it must break out with the same NIP as do_syscall().

 linux-user/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/main.c +2 -1
index 30049581ef..4ea49f68be 100644
@@ -1712,10 +1712,12 @@ void cpu_loop(CPUPPCState *env)
              * in syscalls.
              */
             env->crf[0] &= ~0x1;
+            env->nip += 4;
             ret = do_syscall(env, env->gpr[0], env->gpr[3], env->gpr[4],
                              env->gpr[5], env->gpr[6], env->gpr[7],
                              env->gpr[8], 0, 0);
             if (ret == -TARGET_ERESTARTSYS) {
+                env->nip -= 4;
                 break;
             }
             if (ret == (target_ulong)(-TARGET_QEMU_ESIGRETURN)) {
@@ -1723,7 +1725,6 @@ void cpu_loop(CPUPPCState *env)
                    Avoid corrupting register state.  */
                 break;
             }
-            env->nip += 4;
             if (ret > (target_ulong)(-515)) {
                 env->crf[0] |= 0x1;
                 ret = -ret;
Signature · 1 line
2.11.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 38 lines · Sam Bobroff

Programs run under qemu-ppc64 on an x86_64 host currently segfault if they use pthread_create() due to the adjustment made to the NIP in commit bd6fefe71cec5a0c7d2be4ac96307f25db56abf9.

This patch changes cpu_loop() to set the NIP back to the pre-incremented value before calling do_syscall(), which causes the correct address to be used for the new thread and corrects the fault.

---

v2:

* Remove the NIP adjustment from the -TARGET_QEMU_ESIGRETURN case, it must break out with the same NIP as do_syscall().

 linux-user/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/main.c +2 -0
index 30049581ef..4ea49f68be 100644
@@ -1712,10 +1712,12 @@ void cpu_loop(CPUPPCState *env)
              * in syscalls.
              */
             env->crf[0] &= ~0x1;
+            env->nip += 4;
             ret = do_syscall(env, env->gpr[0], env->gpr[3], env->gpr[4],
                              env->gpr[5], env->gpr[6], env->gpr[7],
                              env->gpr[8], 0, 0);
             if (ret == -TARGET_ERESTARTSYS) {
+                env->nip -= 4;
                 break;
             }
             if (ret == (target_ulong)(-TARGET_QEMU_ESIGRETURN)) {

linux-user/main.c void cpu_loop(CPUPPCState *env) · line 1730

Quoted 7 lines
linux-user/main.c +0 -1
@@ -1723,7 +1725,6 @@ void cpu_loop(CPUPPCState *env)
                    Avoid corrupting register state.  */
                 break;
             }
-            env->nip += 4;
             if (ret > (target_ulong)(-515)) {
                 env->crf[0] |= 0x1;
                 ret = -ret;
[my comments on previous patch were inaccurate]

Thanks,
Laurent

Reviewed-by on v2 1/1
#2 lore raw
In reply to Sam Bobroff
Quoted 9 lines · Sam Bobroff

Programs run under qemu-ppc64 on an x86_64 host currently segfault if they use pthread_create() due to the adjustment made to the NIP in commit bd6fefe71cec5a0c7d2be4ac96307f25db56abf9.

This patch changes cpu_loop() to set the NIP back to the pre-incremented value before calling do_syscall(), which causes the correct address to be used for the new thread and corrects the fault.

thanks
-- PMM

#3 lore raw
In reply to Sam Bobroff

Quoting Sam Bobroff (2017-02-06 21:21:39)

Quoted 9 lines

Programs run under qemu-ppc64 on an x86_64 host currently segfault if they use pthread_create() due to the adjustment made to the NIP in commit bd6fefe71cec5a0c7d2be4ac96307f25db56abf9.

This patch changes cpu_loop() to set the NIP back to the pre-incremented value before calling do_syscall(), which causes the correct address to be used for the new thread and corrects the fault.

Cc'ing [email protected]

Quoted 39 lines

---

v2:

* Remove the NIP adjustment from the -TARGET_QEMU_ESIGRETURN case, it must break out with the same NIP as do_syscall().

 linux-user/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/main.c +2 -1
index 30049581ef..4ea49f68be 100644
@@ -1712,10 +1712,12 @@ void cpu_loop(CPUPPCState *env)
              * in syscalls.
              */
             env->crf[0] &= ~0x1;
+            env->nip += 4;
             ret = do_syscall(env, env->gpr[0], env->gpr[3], env->gpr[4],
                              env->gpr[5], env->gpr[6], env->gpr[7],
                              env->gpr[8], 0, 0);
             if (ret == -TARGET_ERESTARTSYS) {
+                env->nip -= 4;
                 break;
             }
             if (ret == (target_ulong)(-TARGET_QEMU_ESIGRETURN)) {
@@ -1723,7 +1725,6 @@ void cpu_loop(CPUPPCState *env)
                    Avoid corrupting register state.  */
                 break;
             }
-            env->nip += 4;
             if (ret > (target_ulong)(-515)) {
                 env->crf[0] |= 0x1;
                 ret = -ret;
Signature · 1 line
2.11.0