From patchwork Mon Apr 2 17:13:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10320085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CF39A60247 for ; Mon, 2 Apr 2018 17:15:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C001428A31 for ; Mon, 2 Apr 2018 17:15:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4D7628A3A; Mon, 2 Apr 2018 17:15:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 558B928A31 for ; Mon, 2 Apr 2018 17:15:50 +0000 (UTC) Received: from localhost ([::1]:49749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f333d-0005aC-EV for patchwork-qemu-devel@patchwork.kernel.org; Mon, 02 Apr 2018 13:15:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f332C-0004EC-RQ for qemu-devel@nongnu.org; Mon, 02 Apr 2018 13:14:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f332B-0004aB-Tp for qemu-devel@nongnu.org; Mon, 02 Apr 2018 13:14:20 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:52121) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f332B-0004Zj-NU for qemu-devel@nongnu.org; Mon, 02 Apr 2018 13:14:19 -0400 Received: by mail-wm0-x242.google.com with SMTP id v21so27101833wmc.1 for ; Mon, 02 Apr 2018 10:14:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n8y8Ot2g0qWhlP/G6JcPHg5mO4aeLBxQcQIBGMLbAKc=; b=WS83QEB+jdjS+s7mQcZfoxFdf+XYPVMRf2qWzCIQNTOOoPVdaJ/H5WE7zbgsBYlZdm 0feCdqJglsqawvStL8asRcbcdeASBQJMEO+8XIvm+hc7pu2xMxengFhTm8J4xA7yzkHv h+CQPrt9uP3KWCenLtj6FPy/HcS68zcWQV/uWhNZDTrPnp/KHAwTJolMjyiwYfslDc0i 1AM3jJaGYexR+Ulnud7F2/7HwebBX7YFwboXDdpAj7EJeR3fAxu/mBkqOMc1+4Db2mmD PcPtsiWqrGDvQiyni5JD6j3JUkF7OUXEfC4XwDOkmDDfKS7bcDDphDWRirc/K1wdZYeY Jxqw== 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=n8y8Ot2g0qWhlP/G6JcPHg5mO4aeLBxQcQIBGMLbAKc=; b=pMSWGddyUEsznOglBzEOCSZAt5WVjQql/hoTR+L34IqyiXdI0I8oTF1TzWI2oePmA2 dDdL7iwFMHtOxz+WxdNoxzXURioGXJDDk8nBXcNK9uP7rZ8GhMZAdiq/+blH13RnsrAG c3beT9FcA7/qxuTfOKA2jDkuHhnKHpqSVqLaQ3R1oYtJ5b2puWAl/cuPp2aEoNpltuP0 2XJd7ihUOKi2gkPROztR1yLNusIKjTJYJkTvERvUpHFVym0rxvDlVEfQ+tvuD4JTjV0b 8v3V//NZ69lRVhEZ8YyuQCKjEta0iCiUxHM1buPIIRkDc8AFlKZxBNJm8UOoGK6cxOu1 y+Gg== X-Gm-Message-State: ALQs6tBNec6J2VZXi0oZ6PlOvsKQ+qWcWGIrryX+eYEq54zeS2VmJF2S s0iaapNxCcUl1Ojjg9+xyRSNPQ== X-Google-Smtp-Source: AIpwx49/RlBx6Hh48IBBXxklQCJOGHjowtp2mWsF5ztm3Vls7e7sBaFdxXCt6kCYt0HEqaRQfgnxkg== X-Received: by 10.46.154.145 with SMTP id p17mr6268628lji.28.1522689258476; Mon, 02 Apr 2018 10:14:18 -0700 (PDT) Received: from octofox.cadence.com (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id s87-v6sm142360lfk.69.2018.04.02.10.14.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Apr 2018 10:14:17 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Mon, 2 Apr 2018 10:13:47 -0700 Message-Id: <20180402171354.27706-2-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180402171354.27706-1-jcmvbkbc@gmail.com> References: <20180402171354.27706-1-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PULL 1/8] target/xtensa: fix flush_window_regs 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: Peter Maydell , Riku Voipio , Laurent Vivier , Max Filippov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP flush_window_regs uses wrong stack frame to save overflow registers in call8 and call12 frames, which results in wrong register values in callers of a function that received a signal. Reimplement flush_window_regs closely following window overflow sequence. Signed-off-by: Max Filippov --- linux-user/signal.c | 55 +++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 2ea3e0321f4d..33d5ced30c98 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -7094,52 +7094,45 @@ static abi_ulong get_sigframe(struct target_sigaction *sa, static int flush_window_regs(CPUXtensaState *env) { - const uint32_t nareg_mask = env->config->nareg - 1; uint32_t wb = env->sregs[WINDOW_BASE]; - uint32_t ws = (xtensa_replicate_windowstart(env) >> (wb + 1)) & - ((1 << env->config->nareg / 4) - 1); - uint32_t d = ctz32(ws) + 1; - uint32_t sp; - abi_long ret = 0; - - wb += d; - ws >>= d; + uint32_t ws = xtensa_replicate_windowstart(env) >> (wb + 1); + unsigned d = ctz32(ws) + 1; + unsigned i; + int ret = 0; - xtensa_sync_phys_from_window(env); - sp = env->phys_regs[(wb * 4 + 1) & nareg_mask]; + for (i = d; i < env->config->nareg / 4; i += d) { + uint32_t ssp, osp; + unsigned j; - while (ws && ret == 0) { - int d; - int i; - int idx; + ws >>= d; + xtensa_rotate_window(env, d); if (ws & 0x1) { - ws >>= 1; + ssp = env->regs[5]; d = 1; } else if (ws & 0x2) { - ws >>= 2; + ssp = env->regs[9]; + ret |= get_user_ual(osp, env->regs[1] - 12); + osp -= 32; d = 2; - for (i = 0; i < 4; ++i) { - idx = (wb * 4 + 4 + i) & nareg_mask; - ret |= put_user_ual(env->phys_regs[idx], sp + (i - 12) * 4); - } } else if (ws & 0x4) { - ws >>= 3; + ssp = env->regs[13]; + ret |= get_user_ual(osp, env->regs[1] - 12); + osp -= 48; d = 3; - for (i = 0; i < 8; ++i) { - idx = (wb * 4 + 4 + i) & nareg_mask; - ret |= put_user_ual(env->phys_regs[idx], sp + (i - 16) * 4); - } } else { g_assert_not_reached(); } - sp = env->phys_regs[((wb + d) * 4 + 1) & nareg_mask]; - for (i = 0; i < 4; ++i) { - idx = (wb * 4 + i) & nareg_mask; - ret |= put_user_ual(env->phys_regs[idx], sp + (i - 4) * 4); + + for (j = 0; j < 4; ++j) { + ret |= put_user_ual(env->regs[j], ssp - 16 + j * 4); + } + for (j = 4; j < d * 4; ++j) { + ret |= put_user_ual(env->regs[j], osp - 16 + j * 4); } - wb += d; } + xtensa_rotate_window(env, d); + g_assert(env->sregs[WINDOW_BASE] == wb); return ret == 0; }