From patchwork Tue Nov 5 18:11:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1189884 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 476yf84Q22z9sNx for ; Wed, 6 Nov 2019 05:21:04 +1100 (AEDT) Received: from localhost ([::1]:47224 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iS3Ru-00084q-9G for incoming@patchwork.ozlabs.org; Tue, 05 Nov 2019 13:21:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52121) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iS3Iv-00063a-6y for qemu-devel@nongnu.org; Tue, 05 Nov 2019 13:11:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iS3Iu-0004kP-0N for qemu-devel@nongnu.org; Tue, 05 Nov 2019 13:11:45 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:40493) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iS3It-0004jc-Mn for qemu-devel@nongnu.org; Tue, 05 Nov 2019 13:11:43 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N18I8-1hmgvt0OEc-012U31; Tue, 05 Nov 2019 19:11:35 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 12/13] linux-user/sparc: Fix cpu_clone_regs_* Date: Tue, 5 Nov 2019 19:11:18 +0100 Message-Id: <20191105181119.26779-13-laurent@vivier.eu> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191105181119.26779-1-laurent@vivier.eu> References: <20191105181119.26779-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:r0fsDaXcjdF5yek/2ye+ffad8EIzMItAXWG2mxZr0KG49yKk4bM r6x5+0N/PsYIKpypyw/IcyzyxzEDV8HuJGD93ticAO5401fkuqNp9E+ppiSfAqi7o71wz/7 508IDhZdOiFAa1XcyU49aG3qUFueGBIfTEP1mTu921+aEAVAvtqzb88wqzMR3oseiuYXyuR LMKSyIFMOpw32BbUVvu4w== X-UI-Out-Filterresults: notjunk:1; V03:K0:7vuyFv4tAO0=:E1kQfaPBg84H11y3SJxux9 Q8oqQUHY3ABsFvwqbbo3gw82DhqjvG3t7z6adjbDb//RYAWdcO0aYcsdnO45ZOQXG9GXCHy+k h7Z6NiCTVCoguq+6hJSrr4kaHMlehvPz0dwNZEzoG3Z36Ug1BvJaccsWMrdzu3PBaeq7NK4jE A/ZFmCtdL1HhZw/wagK0/MmEJjxERd2AYmIHungteXIIlsrkpTmfBdZLmeHqFXdnpFiThD1k1 qSDMcM8NE6bdfTCRDkvpAdZtIIdT0JfRhsuVfexSsFXuuFYPI3FyB2nygm9HT4PCvSArEGeWi 7hI1QipPgORitrxShIHNXy0YltW7zqWgUJkKSBwnW/beifWP2tjvvjQBNqwDbeU5C6GZ8TKd+ 29ABBi2o3oFtmfmmtA31J+qzhUhBmU2RlG8sPaLjTZTZ6fjX5lgPggqqyNPJ3WgG7moNgQebe PJY7RcSI3Us2yBzHA9vTX0wYA+yrAn+R5pIDKDMoQFWqr9fx1hrCcKd09bCTRW/WEG8mFxzYi wO8PedrBkViRYltXdfIEisvyIpWSkKKNXlcasfv8QP0D59Q5BvEcQviDCFvH2UCwHrrCIBR6M bo4hgEKqwBVfDg11kcWTBH80Pur12Y8jw/mYalakU5d7HuIEUTJNz8m3HnW3udKNc1XWEQGWj AZk4AWbkaVGmiYqIpMYcNTB+VcJXf61x988U8gLz/g4djL0hM2ONcjLVyaakd836Rbxaw4sk3 fsOI8T08hKd94P/tXsZeb8XaEVX+8k1jQYmz5fiISdHw31t+4t6ItmHXJIASbUk8k1HX8tHLF KLra5I8zkS8MlkJkNWxQyCIN57KcFPGZou75i4Iwi7GGBXZlWkHPQ+wTWQ69E0MlYq8ZCjIES 82+TS8OQxuPbcipeiR5w== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.13 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , Riku Voipio , Richard Henderson , Laurent Vivier , =?utf-8?q?Alex_Benn=C3=A9e?= , Artyom Tarasenko Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson We failed to set the secondary return value in %o1 we failed to advance the PC past the syscall, we failed to adjust regwptr into the new structure, we stored the stack pointer into the wrong register. Signed-off-by: Richard Henderson Message-Id: <20191025113921.9412-12-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/sparc/target_cpu.h | 43 +++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/linux-user/sparc/target_cpu.h b/linux-user/sparc/target_cpu.h index 8ff706adcef7..14b21589699b 100644 --- a/linux-user/sparc/target_cpu.h +++ b/linux-user/sparc/target_cpu.h @@ -23,22 +23,51 @@ static inline void cpu_clone_regs_child(CPUSPARCState *env, target_ulong newsp, unsigned flags) { + /* + * After cpu_copy, env->regwptr is pointing into the old env. + * Update the new cpu to use its own register window. + */ + env->regwptr = env->regbase + (env->cwp * 16); + if (newsp) { - env->regwptr[22] = newsp; + /* When changing stacks, do it with clean register windows. */ +#ifdef TARGET_SPARC64 + env->cansave = env->nwindows - 2; + env->cleanwin = env->nwindows - 2; + env->canrestore = 0; +#else + env->wim = 1 << env->cwp; +#endif + /* ??? The kernel appears to copy one stack frame to the new stack. */ + /* ??? The kernel force aligns the new stack. */ + env->regwptr[WREG_SP] = newsp; } - /* syscall return for clone child: 0, and clear CF since - * this counts as a success return value. - */ - env->regwptr[0] = 0; + + if (flags & CLONE_VM) { + /* + * Syscall return for clone child: %o0 = 0 and clear CF since this + * counts as a success return value. Advance the PC past the syscall. + * For fork child, all of this happens in cpu_loop, and we must not + * do the pc advance twice. + */ + env->regwptr[WREG_O0] = 0; #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) - env->xcc &= ~PSR_CARRY; + env->xcc &= ~PSR_CARRY; #else - env->psr &= ~PSR_CARRY; + env->psr &= ~PSR_CARRY; #endif + env->pc = env->npc; + env->npc = env->npc + 4; + } + + /* Set the second return value for the child: %o1 = 1. */ + env->regwptr[WREG_O1] = 1; } static inline void cpu_clone_regs_parent(CPUSPARCState *env, unsigned flags) { + /* Set the second return value for the parent: %o1 = 0. */ + env->regwptr[WREG_O1] = 0; } static inline void cpu_set_tls(CPUSPARCState *env, target_ulong newtls)