From patchwork Wed Nov 6 11:33:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 178676 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp485608ilf; Wed, 6 Nov 2019 03:42:32 -0800 (PST) X-Google-Smtp-Source: APXvYqyzY7LKusqd12s32XMi+9gy5eAVLiN+SD2Ad4QVYV3Zq+N+ba2YOAXgF2vx6W8KnixO5yEN X-Received: by 2002:a37:7bc7:: with SMTP id w190mr1513496qkc.132.1573040552093; Wed, 06 Nov 2019 03:42:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573040552; cv=none; d=google.com; s=arc-20160816; b=JVC1c0k10nHVNdxe/tWBG3blp8AZ4hcJal3itlhuituSccSmqmGYFceWalodUgyk7E FAYBcSe6XK4xUDUBMt+EaXDRO46B/ZVidJT7LJRvUWKnzmcl0UPOqpMyABHVVZs8wRoU bNXj430oEeXvpxGHv6YsJECTlYT815iVmlHXJitYHQWUlSaX/hp7PrAXH3yJwvOxn6Gn SjRJoCbAlOHaqt8/gCqPHUdls2wNvtGqgBojFjwKWatnHgzDX1OxZa1JLnHwuohrmPW/ SN8Ch9xZIPUj3XHZSboxb0f46PPNnkUwSmjMq8ZvVvCWh4DJYzscjKUQn2bgKNkc8940 srHA== 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:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=sbKKp8L4DTtLJPEKrjfc6knlBHmQBSkQGz/jGwEjATY=; b=nRZpDxSX7p0BiVKVSN2AeC/zVJjdUhHd0+pnEsw1hN8oBwGKxascA7xQr5a94Vy85f OVYONZM3Drh8qRgplYiSYyZ2yjhIZtOyECe/5GQUSnJmXb0DJugfmscnJV9uf2lshEos 7IBZym/ge/0VLUk4Z4kBRhcmMMlUu8WyAInH6PNZD20BH8PYVnEiu5Aqh1lnvp5wTgH3 r1Oe9SCtnxYdEadsM8DFRaQwRSyY7uZcGDFyDX+ahHIF+90c2rciuo2mbHpT+dnYRHr8 e75NrXlELIk/PW1J6wbxirs51QlCKzWn/g7UXnA82EWfUc6kSHdBmIO61mCghQ2FM5s1 Kjqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WABOzADH; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y69si17353717qkb.344.2019.11.06.03.42.32 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Nov 2019 03:42:32 -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; dkim=pass header.i=@linaro.org header.s=google header.b=WABOzADH; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56482 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iSJhn-0006Fp-Ah for patch@linaro.org; Wed, 06 Nov 2019 06:42:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37999) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iSJZP-000457-3f for qemu-devel@nongnu.org; Wed, 06 Nov 2019 06:33:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iSJZM-0007aR-Oo for qemu-devel@nongnu.org; Wed, 06 Nov 2019 06:33:50 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36040) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iSJZM-0007Zf-HW for qemu-devel@nongnu.org; Wed, 06 Nov 2019 06:33:48 -0500 Received: by mail-wr1-x443.google.com with SMTP id w18so25349001wrt.3 for ; Wed, 06 Nov 2019 03:33:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sbKKp8L4DTtLJPEKrjfc6knlBHmQBSkQGz/jGwEjATY=; b=WABOzADHchxJEGyitvP+N0YSkKanAt2OEt4DwBQGeyv9E/strudqoGBJhTS+fAzjOD dlAC6BDK1tUavFyNN208UYl0bcIjwByA6Buh6/W0wcl7fZ9HMbJ4YfSYfYfoVPnGsUvT NzzbGG62RLSAboY4rKiYTQU/eq5PlrvACmr1uVf14/OwVvAAx91X9LrqOmdpDdO0+21q Mwh+Px8GsLgrajH0PLlD6DhERIfBhJPkZa1QFnyvXUgmJzczh2f8F636PZ6qkAVPf5zg akF+Z7lL5P6cDiVeb7Nn6EtfXBbJ2uARrvGXeyH4/R2dy6xEYFVARhjALf+6xLr5CHNB Y6Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sbKKp8L4DTtLJPEKrjfc6knlBHmQBSkQGz/jGwEjATY=; b=D8J0E6+UPIGPv+UKqy95q5J0CcNtONN0K0NXlcSRsT7FkQuDaPEKON5T9fefiEEIHE 63pZKTgHsvcnTQGTj8IOy78mYWmvt3ycA/pjExFFB6ULFbIV1uurklcHrK+I3dtu3iX+ e5c+cUd9C2l8pAHdXA5CJ+NfX9H3Icu3RaBmFQRF6azHdnUknpGz5giU3J2JYlcZAP8M K3MtaY3w/ICosnzOf3PtLUJXSoNrDYHXYDPqfH7jSVxTU3M15Udyq/UAZ7bE6d9GQWEi 2ZPyxQ95q0YOFT+g3tDfDlCSIPOyhKbxZXIKaqWMX6olnXpilknWOnz+tRhhAXFGWat7 U7uQ== X-Gm-Message-State: APjAAAXGBCyWRNsecGSXKgt9ANZ4wYe77bX2hpoaSlou904FOA0XaCB1 Sc1dK3uhcrBiENvdknKhg4pyM3xePeKW5Q== X-Received: by 2002:a5d:5686:: with SMTP id f6mr2239807wrv.231.1573040024513; Wed, 06 Nov 2019 03:33:44 -0800 (PST) Received: from localhost.localdomain (31.red-176-87-122.dynamicip.rima-tde.net. [176.87.122.31]) by smtp.gmail.com with ESMTPSA id q124sm1776907wme.13.2019.11.06.03.33.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2019 03:33:43 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 11/12] linux-user/sparc: Fix cpu_clone_regs_* Date: Wed, 6 Nov 2019 12:33:17 +0100 Message-Id: <20191106113318.10226-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191106113318.10226-1-richard.henderson@linaro.org> References: <20191106113318.10226-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 | 47 ++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/linux-user/sparc/target_cpu.h b/linux-user/sparc/target_cpu.h index 8ff706adce..14b2158969 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) { - if (newsp) { - env->regwptr[22] = newsp; - } - /* syscall return for clone child: 0, and clear CF since - * this counts as a success return value. + /* + * After cpu_copy, env->regwptr is pointing into the old env. + * Update the new cpu to use its own register window. */ - env->regwptr[0] = 0; -#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) - env->xcc &= ~PSR_CARRY; + env->regwptr = env->regbase + (env->cwp * 16); + + if (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->psr &= ~PSR_CARRY; + 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; + } + + 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; +#else + 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)