From patchwork Wed Nov 6 13:04:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 178683 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp583472ilf; Wed, 6 Nov 2019 05:08:15 -0800 (PST) X-Google-Smtp-Source: APXvYqx+CC6bQmmbMWzRTYTCEKMAx1Kc6ApjGSI2ZQPlRKBHK5N0ZKEB7XAiyjjxNpI//gsEQ34L X-Received: by 2002:a50:c2c2:: with SMTP id u2mr2563786edf.133.1573045695492; Wed, 06 Nov 2019 05:08:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573045695; cv=none; d=google.com; s=arc-20160816; b=sLn0iYWPHpgEd3hfxMh71Z+xbh6YWpe1yp22Q92S/h4iaB6kcco/We9Yl6Vm9v3j4m XaZbYZeF58nlevYfqo8EaL9pOYnsPEsmhpk46wGO2lyENps9yT3hddcCgL4EY7ehVi96 LFJZawij58bAoMGFmvl64fHQS0oMjtK/tfwuKvYB7h63HnrKgbgI3p8BhoieTAnd+Ybl Jb0EZSJYh0P3KZUopqz4w8NPy1d/WUO/2vb2vY4ZqA4unnKsrh6y+IQthxFtRV9TdPRx LhIwqfVdlpXCIQBJ0jssZCKZMMuZCb/lIFDgdrZg1iePcHxbSjQ7LvPHpI/2IcCdNAoE mL0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=u8vrI7e3KAGuA1momMrq3+uxrTD/dnf99cgsCUrF9Oo=; b=SxiBgAafXCQAqP07NjPe+ALgpFvkbwYzt6qm+wjh6mFtrMYty6lUpHWwiwbxhy25jx VOKTJtUFcliI3NmqCstNhviw6M9n20cY2Z4R0zYNZr4t+gmWlH95S9AR6Q4pdEu38T0l D0f0rx6EXS81iMJB0r9/4XueVxtmxnckForje+F7KMdt6Zd2lY2Zk6A3y7Idiz9A1t+c XYwUaTg6JYSv17u+07JMpbzeiLbsVdEuRgZXJf0sTi7fgZo4YWV0ljsT4/1M/KmU8n33 Y0uG4WChLPDAyJ+38mZU+n4G04SQh5wdzItHiQkQ69lk++imT4Re9jvxzECQKHkq5D6U yKvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 1si16392681ejt.404.2019.11.06.05.08.15 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Nov 2019 05:08:15 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:57850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iSL2k-00072T-0s for patch@linaro.org; Wed, 06 Nov 2019 08:08:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36486) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iSKzw-0003Xi-FJ for qemu-devel@nongnu.org; Wed, 06 Nov 2019 08:05:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iSKzv-0002yV-8E for qemu-devel@nongnu.org; Wed, 06 Nov 2019 08:05:20 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:57321) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iSKzu-0002xk-VR for qemu-devel@nongnu.org; Wed, 06 Nov 2019 08:05:19 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N79q8-1hrtHE3bZ6-017Vs9; Wed, 06 Nov 2019 14:05:17 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v2 12/13] linux-user/sparc: Fix cpu_clone_regs_* Date: Wed, 6 Nov 2019 14:04:55 +0100 Message-Id: <20191106130456.6176-13-laurent@vivier.eu> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191106130456.6176-1-laurent@vivier.eu> References: <20191106130456.6176-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:SZJtkQFvalXdI41SeIQoMMrB0GUeVbZcriSYjspiLcEPONjOKc0 4PhKd5249RuZ/k5GjTmVj2q0Sf7IhHTkJYwTHThaH1fyYaoxK6+m2YADd46d+1WLPb8VOKz Q/CIaxNv81mAgDNhb3I2xwMYVqqe0QPudhZ51sQ6yUICnizwgCY6Sx3K+e2kx68GwmoA5OM T5J758/yldGMjXSjYuzvA== X-UI-Out-Filterresults: notjunk:1; V03:K0:UZSje5P6C2M=:9QIQB95eNWbVC/706ZRgYY qDFsYCwalhcYdDszOb85COLpSwcBbMnl5P2apBnX9u96L4oGtlhK6J+JQ4YkOXsPdOmwJ3zhk AeHVZAGzccLhwKKvsw9a5/hcEYtELGGekQDtsLgHKK2RdtH+lqIgkTkhZbyIdB8Lf8NVQVPxW vSY2h3Dzg+oWwu0/+65MYVLBNMxqKTSTwGk4UXHNB1UD7aIGoJRAQqZRsQ6FDOqRYeKi6W/7N i3bGWvQ3pW9FNu93apTtK9FwkqpxE4d6XHWEFKlI+dCZJhJtauMvxt64iIeHkaMnWH+y37j+N NsIkf6DOPaemnaAxjnJsReEUKU9NFTd2iDBK9f4Au0HNTLH/ASwah9ZPoMrUVi/YgHScuGvVn OlbMmVtmc+adooX2yyB1ofPbk9VVkFDTU/2l0pyFXKP1QPkiKZnh+mx9p37pWk7rOxwLcd1Jm QwkzGaP0tCcYkYaUW9hveifubeop81ySfsvC5RFtpnizC/qe/Se8/BONVKe4jReRaXMI5zCPv YfAhV+uwWTd6AgQcYTj6DfQgfWJsW9SDCAUyaYBL3kOgb5+j6nwLz8DR0uJQ9Km1UX06WTEZJ 4r047lJN5jZi6OBM4QulpqgmS3+W3M+JV2nV6yimVOOVIBvdoJ0mgBSu4tROv0jZl1SxXBNCU Qi5PkmgMTBF5cSsfvLnIXRu37gqafSwDwBRxsw4EKxg5crgxk9Y76D8BFnTQHKHOS8wdYbQDp LyfLG7OK2hEARjcgtjMSveqjZfEz/QarvEysB/zHJ2Qzex3gRHG7ReKE7EDjN5xf5ELtEumnM jNQ3bB9HdvfwFsBvEra5y1ArQEQsahFcFetDAPmK+j1YyYyF1Cpsb5zy0lKmA+8AV0b9Nbg+j ZJBdG9pp0Yn6AzK385eg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.134 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: Richard Henderson , Riku Voipio , Mark Cave-Ayland , Laurent Vivier , =?utf-8?q?Alex_Benn=C3=A9e?= , Artyom Tarasenko Errors-To: qemu-devel-bounces+patch=linaro.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: <20191106113318.10226-12-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/sparc/target_cpu.h | 43 +++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) -- 2.21.0 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)