From patchwork Mon Apr 29 17:00:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 163061 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp2149854ill; Mon, 29 Apr 2019 10:17:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxmE31AtJEKN10tS4RimsuZEB9f48kbTBQqQ1DBgFOOXIKytQ7MTdx+QaJwNZiJPhPvoTHS X-Received: by 2002:a5d:6848:: with SMTP id o8mr26042343wrw.204.1556558263916; Mon, 29 Apr 2019 10:17:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556558263; cv=none; d=google.com; s=arc-20160816; b=bMsDQS/Jyi6Omqlax134hfwHC7ZbZUO/f0Hd/NQINfmZBQXjlMvt22t+IgXjFs/fBC FI5EruZXiD86mdI0ydV2sdwfdv9RRcZW7N23t4Pu6hQYIqChjdv7K4k8ButVdRomLnZO 2ttiUgAys90IVVcvOqG9gEmmIBVVGoWiLrd0Kunj0hcT11cQh6NbOQeEvA/aF6VmMrg+ OQRV/C01YrV5lFD/Lr8TSIWxzlCMfkae+aoyDaH6t5pyJ+S7WyEBYzgtm3G3Askwqt8R 3tw74fLaUosaT4lFjOGQZsU7RSQq6cFl6U1uP49jn73UeONAJ8KdtB4mBUfoWD/XwS13 /+EQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=RtlQ82TUzUcT8MTo+xmZT8H33g6MULgoaobSGr/GhBo=; b=Dw8WairvrAuLTq4eydv6Hc4Gq4Xr5SLmZliym5KSBq/WN7x1FHCZGEkpCeeaHL0IxN yHGWV60YFuEUDoaKy6Ot67c3/QQftz48cMLrhs5nkqWcus458oa70QurnapWbh+Rx5+x DXvw3Nl9kaI/vs4SPQNQL4T6uH1PadSbhB/g74+U9U4sIDtnjm4/Pj2DwNnzUqCKTH+H OLk4MAcLMTmV1/tjQXxHmjNcV6bFJMpJHc1WCWv0vl1Nfwfkq/w49Opw3bYK/0vqTlJF 1GLr2dNQ/bUKnzZqfo5jrSyLyIzYoNUxznMOY9o4AWt/5PwJKq/kkPAmrS9uAurFy3Ib S9rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=R3Fg1kr+; 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 d67si76255wmf.19.2019.04.29.10.17.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 29 Apr 2019 10:17:43 -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=R3Fg1kr+; 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 ([127.0.0.1]:60831 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hL9uQ-0001av-PL for patch@linaro.org; Mon, 29 Apr 2019 13:17:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hL9et-0004uW-A3 for qemu-devel@nongnu.org; Mon, 29 Apr 2019 13:01:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hL9er-0006mW-HO for qemu-devel@nongnu.org; Mon, 29 Apr 2019 13:01:39 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:52919) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hL9ep-0006Oe-IN for qemu-devel@nongnu.org; Mon, 29 Apr 2019 13:01:36 -0400 Received: by mail-wm1-x334.google.com with SMTP id j13so174106wmh.2 for ; Mon, 29 Apr 2019 10:00:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=RtlQ82TUzUcT8MTo+xmZT8H33g6MULgoaobSGr/GhBo=; b=R3Fg1kr+/bJywVAVh9UhQ8ebU3OSEpENcab8BviRt55TtFIDzvOwqo3x08XJ67D9vV AVjWnUvLu34OmfrKgANyEQgOTrDaa/JA0y/JdHPMS2NKX+XCdK1YBi+BXtbcdYNkcNR2 7/alVBz+u/8jiL/dGOXGdR5o9xBElnvWP5fXtV0HlWc5viwck4Uk7ubUgyNzlxx3PDFB lbMlChWHU0YjEd94qOlrUor4kskfbmSJvXpPYUcVTdIqpHGPuDBL0yZb1KnGVdGhPG7S S9cgtb31QXdtrMr2GKlzvzA8gWUdipt5M3QrgXL1v0ztnRBAmTkoK265hrmcPRJO3vhP dWWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RtlQ82TUzUcT8MTo+xmZT8H33g6MULgoaobSGr/GhBo=; b=IgEiLrwGslaelWSeavytNEJ4wMzOvDYHi06EBtXtglQ1zWItB2CVk8esP2Qcn3zxos e6nsGeF9HAO0xUodyQdzxsxubrALXGBAFaA5aCl6jJhZr3VwzFdyXzOD22tdBIAMUds+ p6E+oyViFExl3Mw1F8vWoTnOIGRIB49rBlEIB0uX15a/E0Wm/BJHW+N2WPhWzMssw6zo LYS2p+4MjuLC5y2AxXAMW400qB58wK9X9Nq2ZY0ifPqPU+yjb3xCf/dffbmcT06BiMXC JWUBCxo0TsyzYsybGSupJHRGf4jD5hoUm4TbVd6ZMG54RRnR7tCYwt5NeqHiDF89QI1u AyZQ== X-Gm-Message-State: APjAAAWRlA1l2SqzNIkWuL2mnUiqeSD4HP4raCovS2qL2cpHAcHHvdbN AtH2wrsvnvW0MZmO9A1YK7AlKkO55rE= X-Received: by 2002:a1c:7008:: with SMTP id l8mr29807wmc.49.1556557247875; Mon, 29 Apr 2019 10:00:47 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a13sm36896wmj.39.2019.04.29.10.00.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Apr 2019 10:00:46 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 29 Apr 2019 18:00:00 +0100 Message-Id: <20190429170030.11323-13-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190429170030.11323-1-peter.maydell@linaro.org> References: <20190429170030.11323-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::334 Subject: [Qemu-devel] [PULL 12/42] target/arm/helper: don't return early for STKOF faults during stacking 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Currently the code in v7m_push_stack() which detects a violation of the v8M stack limit simply returns early if it does so. This is OK for the current integer-only code, but won't work for the floating point handling we're about to add. We need to continue executing the rest of the function so that we check for other exceptions like not having permission to use the FPU and so that we correctly set the FPCCR state if we are doing lazy stacking. Refactor to avoid the early return. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20190416125744.27770-10-peter.maydell@linaro.org --- target/arm/helper.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) -- 2.20.1 diff --git a/target/arm/helper.c b/target/arm/helper.c index e801744673f..142d301b651 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -8182,7 +8182,7 @@ static bool v7m_push_stack(ARMCPU *cpu) * should ignore further stack faults trying to process * that derived exception.) */ - bool stacked_ok; + bool stacked_ok = true, limitviol = false; CPUARMState *env = &cpu->env; uint32_t xpsr = xpsr_read(env); uint32_t frameptr = env->regs[13]; @@ -8213,7 +8213,14 @@ static bool v7m_push_stack(ARMCPU *cpu) armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, env->v7m.secure); env->regs[13] = limit; - return true; + /* + * We won't try to perform any further memory accesses but + * we must continue through the following code to check for + * permission faults during FPU state preservation, and we + * must update FPCCR if lazy stacking is enabled. + */ + limitviol = true; + stacked_ok = false; } } @@ -8222,7 +8229,7 @@ static bool v7m_push_stack(ARMCPU *cpu) * (which may be taken in preference to the one we started with * if it has higher priority). */ - stacked_ok = + stacked_ok = stacked_ok && v7m_stack_write(cpu, frameptr, env->regs[0], mmu_idx, false) && v7m_stack_write(cpu, frameptr + 4, env->regs[1], mmu_idx, false) && v7m_stack_write(cpu, frameptr + 8, env->regs[2], mmu_idx, false) && @@ -8232,8 +8239,14 @@ static bool v7m_push_stack(ARMCPU *cpu) v7m_stack_write(cpu, frameptr + 24, env->regs[15], mmu_idx, false) && v7m_stack_write(cpu, frameptr + 28, xpsr, mmu_idx, false); - /* Update SP regardless of whether any of the stack accesses failed. */ - env->regs[13] = frameptr; + /* + * If we broke a stack limit then SP was already updated earlier; + * otherwise we update SP regardless of whether any of the stack + * accesses failed or we took some other kind of fault. + */ + if (!limitviol) { + env->regs[13] = frameptr; + } return !stacked_ok; }