From nobody Thu Nov 6 20:33:17 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487745368839346.1201483296521; Tue, 21 Feb 2017 22:36:08 -0800 (PST) Received: from localhost ([::1]:50128 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgQX1-0004VG-J9 for importer@patchew.org; Wed, 22 Feb 2017 01:36:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37565) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgQV1-0002x1-DG for qemu-devel@nongnu.org; Wed, 22 Feb 2017 01:34:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgQV0-0007v7-1X for qemu-devel@nongnu.org; Wed, 22 Feb 2017 01:34:03 -0500 Received: from ozlabs.org ([103.22.144.67]:55219) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgQUz-0007qt-N3; Wed, 22 Feb 2017 01:34:01 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3vSndH3CNjz9s9r; Wed, 22 Feb 2017 17:33:55 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1487745235; bh=iQyVbTlLn6IqU+ETejMRhYmPvMxhxYk9qe9Y/uJK7Y4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GellAoVOIBXnDXmTUXy+YNb+24X43keMn75LDVTRHhSfow4bz3j+b8pcAzJHWhNev fuUnEq+CNQm6ZOuJbwe07iVisWZ3K5uWGne+EvdolNFFvco85r6tirMgndK+5omRC9 2Jxtqcdtlcb6QTJVn+/+kbZ6qouzDy5Q971RBxVg= From: David Gibson To: peter.maydell@linaro.org Date: Wed, 22 Feb 2017 17:33:23 +1100 Message-Id: <20170222063348.32176-19-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170222063348.32176-1-david@gibson.dropbear.id.au> References: <20170222063348.32176-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 18/43] target-ppc, tcg: fix usermode segfault with pthread_create() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, imammedo@redhat.com, Sam Bobroff , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: 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. Signed-off-by: Sam Bobroff Reviewed-by: Laurent Vivier Reviewed-by: Peter Maydell Signed-off-by: David Gibson --- linux-user/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux-user/main.c b/linux-user/main.c index 4fd49ce..9645122 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -1712,10 +1712,12 @@ void cpu_loop(CPUPPCState *env) * in syscalls. */ env->crf[0] &=3D ~0x1; + env->nip +=3D 4; ret =3D 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 =3D=3D -TARGET_ERESTARTSYS) { + env->nip -=3D 4; break; } if (ret =3D=3D (target_ulong)(-TARGET_QEMU_ESIGRETURN)) { @@ -1723,7 +1725,6 @@ void cpu_loop(CPUPPCState *env) Avoid corrupting register state. */ break; } - env->nip +=3D 4; if (ret > (target_ulong)(-515)) { env->crf[0] |=3D 0x1; ret =3D -ret; --=20 2.9.3