From patchwork Fri Oct 25 11:39:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 177727 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3577632ill; Fri, 25 Oct 2019 04:49:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzuSv2Cds9Xb81qQ+0QNg0KzMivcIo5Om7ez5v4HI6kKQyU3C3/j3+vQhwDqOLGFizqwDfG X-Received: by 2002:a17:906:5601:: with SMTP id f1mr2919448ejq.151.1572004176608; Fri, 25 Oct 2019 04:49:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572004176; cv=none; d=google.com; s=arc-20160816; b=gCHn9R1KvP7Dv74oRfhuCriKNfI7g34DAQR6vqAxkz1NJkmL63qECxOH/OIesKrXUz 6HQhrcL4Hdp56ofkYGl9d3MboDMS3HK7QqP24so5+cAZiMwIZjULyu/PkFzQwQkaSm8v gs5lfr4caYdRh/ZtUEAiXd0DkZjrUudn6qtaphXk0qFvMMSN5E7FGV8rS8hfmyPjkYtn thiuTyT1ltTwSrnRPx4dnxKjqIbVzGKuZ1EkpsW4ghv0UajkijCSn0SVhh4JxBwysLId yo+WG6Erly+npY6vPO07VwvDTB1L6YPA/VHJf5RpRCMLvOIx4u+ruWx8zgLMhZY0ejtH ptoA== 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=JmqIvZXJ/Mi2RAVnN1+8tsju3fqmNrpX/0K0AAbqa0w=; b=FymK0ZydCV3ILCtUulMIeOmDX7tircl4iEA5KzQcQSQRhZZsi3E2P2+jgs8m8pnt8S 9UDP9Wlg4s4QNgLsGnejN8631ge1cJHIGOV79o9chPPbmzwrwHOUlo7wuvVLDwwfaY1V BTqP+fAHKyZAx3ZLbv1P6H4QT3YvC6arkmevZbuVwv4DneYmxAJ012ylgMaQ/DJzsJJ6 N2utlilxtkzhOY0oX2ZwuZRMQPDNdoCXaWqzR4ajfetVFLn+AX7isMVE/NHEakPpawuh U6+DXlO8kni6PTaOHwMnfSk/kjQix1sOK2yuV4lSzyclWZOTYDslNBSQ48q3LtaPQ63k q8lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ozOmE6t8; 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=fail (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 n2si1059760edq.264.2019.10.25.04.49.36 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Oct 2019 04:49:36 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=ozOmE6t8; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNy62-0003sq-MI for patch@linaro.org; Fri, 25 Oct 2019 07:49:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45129) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNxwV-0006qU-VL for qemu-devel@nongnu.org; Fri, 25 Oct 2019 07:39:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNxwP-0006fz-5E for qemu-devel@nongnu.org; Fri, 25 Oct 2019 07:39:40 -0400 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]:43269) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iNxwO-0006et-VU for qemu-devel@nongnu.org; Fri, 25 Oct 2019 07:39:37 -0400 Received: by mail-qt1-x841.google.com with SMTP id t20so2674389qtr.10 for ; Fri, 25 Oct 2019 04:39:35 -0700 (PDT) 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=JmqIvZXJ/Mi2RAVnN1+8tsju3fqmNrpX/0K0AAbqa0w=; b=ozOmE6t8mQEVMKWSKssY6MJpkE306wwcipCWm7YPvjKlPZShJc5dyAFlKIMvt2sCzx 7ZL5adq5lrl/RrcnG8wBLc2TUdyCVYKiSrGojTnb4NvtmCDNb2YZHOBMfDEQP3Jj4oon z7UobQjtqsCUtUBbk1CV7asmxHtD6tazX9BwmdfS3wj0ol/j2kL5P7zRpvih6CcV7T4e MUq/2zsoz2WVNQpspB9J+rvIOnpWMDRQ961JmuJ1Z5hN/ZJMHHxUAY9oSADOjnkV+d5E 5+8x9fLUDW1qZLmFznjUdv87BNVl8FXmlxGfZ8VbkB0GN7vysWDppu77n0kWRrTO/t1G vHbg== 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=JmqIvZXJ/Mi2RAVnN1+8tsju3fqmNrpX/0K0AAbqa0w=; b=CZCFV1y8YPW7u/xN94OTvV24CBOyqf0LabAKLee/Uqwn+0dtvVX6qcvk+yPrtBEVt5 vbED9wnOLZcTJmJJERhNIzgXzhUum3ikC8zw0FOrVvnp+rHmYLdbSy2EqRVblI++yL3J 8UZXjcZL1WcCdKUrU7LYtZrS6yQwkHQBkq9d3H5NlhXGizVeNC2aVzYEb9ogYWnUOgbh nOVIMF86hJfOdDWQm+PUtdPxoA7/dVHTFf3I3I8/GpiBoBg/1bBPlVmAixRkHXEns94X 6BakgrhnATLTL51zDKYWmfoiblrcgUcfhOOhQHNJ9MvXnCL15Xx76yaQvUePZotnfLkj RTbQ== X-Gm-Message-State: APjAAAXiOcxhAEDT85+s+Ous+wlA48Gx1kEYKWjRVz+V2U0Lba76M1ZP CLVB9uQzbZ4z7aZrIBSzHY+vev3a3qY= X-Received: by 2002:ac8:65cf:: with SMTP id t15mr2535078qto.357.1572003574981; Fri, 25 Oct 2019 04:39:34 -0700 (PDT) Received: from localhost.localdomain (rrcs-172-254-253-50.nyc.biz.rr.com. [172.254.253.50]) by smtp.gmail.com with ESMTPSA id x38sm1473335qtc.64.2019.10.25.04.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 04:39:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 11/12] linux-user/sparc: Fix cpu_clone_regs_* Date: Fri, 25 Oct 2019 07:39:20 -0400 Message-Id: <20191025113921.9412-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191025113921.9412-1-richard.henderson@linaro.org> References: <20191025113921.9412-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::841 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: alex.bennee@linaro.org, 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 --- v2: Take CLONE_VM into account when performing syscall return. --- 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)