From patchwork Thu Sep 14 17:52:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 112607 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1067375qgf; Thu, 14 Sep 2017 11:11:32 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAgXFYK6h9YSNRplh/PETAfxwsap3EG3s1gheTqpmAZIVbpVzLtmoAp4ScMfbb6n8549Jc2 X-Received: by 10.200.41.143 with SMTP id 15mr24257252qts.56.1505412692033; Thu, 14 Sep 2017 11:11:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505412692; cv=none; d=google.com; s=arc-20160816; b=HV3UXpY37pX4pvkl0WxtTCY8MX3xWOXtIbQweQZ82J/zHw2AEM02r90VTIHdcGeIu4 NuqsufLYbk3lBFghWSO5h/i3f5cvWgjgLHJKW9W0TxORRAneyJ3RtpP4LwdkfA2A5mEo ruWShYiMNZy0hgrlrr9iJ4yD6zFVpJ7PMjcm0CsRhlWTEEdSNviHJ4MrTjPijyVlyP/h IKig6SB9tYPJRQJrx+EtU1RHM8Stqh6q2oKZHnIpwT8GOt7tEbJ3UTjVAXC7pIQei+bs 5ARpIl85vkk0Oy7efrxMoIuQagK/qniPYol18gvFmGK6nOiek3kERQf86nBDa5+ROoiX w6UQ== 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:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=BKWZjFruR27NZ33MwAXeMwVMmCJbyQSwL+I8VWhQYgg=; b=T2M/Pnl4X5aoQG/1bQ/eeZHhZm2yimnQFC0RsMTadQuSoVAFYOdSwro8NGNq0AA/ic PdQFdcSVGLFAG0AjALeLUK/k10t/ntxSJOYO6bNGdhLUDiOTRzSI1Npn48rcv3pVILJB MfSPlv5O37X9w1w4kAfjl9/Zt3csDqE/pnH0rncxzj5NZcn9erHpYjkEOYAGqJy/3nFX sf4RyLfDj42uZ4RWk80B6JXRXX7LaT8m3yI/YBB0Qy8yEgluS5OJwiD/dnV63nEch2qs LoKrQBi7iJEKLfeQKm33eseekkxtW7MF3GX99FaCSSCPixAcIDMBYhIBI4UmmBvR83P1 FOHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 81si18177339qkw.22.2017.09.14.11.11.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Sep 2017 11:11:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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]:49298 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsYbp-0004SU-Vs for patch@linaro.org; Thu, 14 Sep 2017 14:11:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46603) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsYJc-00088Z-GZ for qemu-devel@nongnu.org; Thu, 14 Sep 2017 13:52:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsYJb-00083Z-Do for qemu-devel@nongnu.org; Thu, 14 Sep 2017 13:52:40 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37368) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsYJb-0007x0-5h for qemu-devel@nongnu.org; Thu, 14 Sep 2017 13:52:39 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1dsYJN-0005nI-TW for qemu-devel@nongnu.org; Thu, 14 Sep 2017 18:52:25 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 14 Sep 2017 18:52:37 +0100 Message-Id: <1505411573-27848-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505411573-27848-1-git-send-email-peter.maydell@linaro.org> References: <1505411573-27848-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 02/18] target/arm: Clear exclusive monitor on v7M reset, exception entry/exit 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" For M profile we must clear the exclusive monitor on reset, exception entry and exception exit. We weren't doing any of these things; fix this bug. Signed-off-by: Peter Maydell Reviewed-by: Alistair Francis Reviewed-by: Richard Henderson Message-id: 1505137930-13255-3-git-send-email-peter.maydell@linaro.org --- target/arm/internals.h | 10 ++++++++++ target/arm/cpu.c | 6 ++++++ target/arm/helper.c | 2 ++ target/arm/op_helper.c | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/target/arm/internals.h b/target/arm/internals.h index 5d7f24c..a315354 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -444,6 +444,16 @@ void arm_handle_psci_call(ARMCPU *cpu); #endif /** + * arm_clear_exclusive: clear the exclusive monitor + * @env: CPU env + * Clear the CPU's exclusive monitor, like the guest CLREX instruction. + */ +static inline void arm_clear_exclusive(CPUARMState *env) +{ + env->exclusive_addr = -1; +} + +/** * ARMMMUFaultInfo: Information describing an ARM MMU Fault * @s2addr: Address that caused a fault at stage 2 * @stage2: True if we faulted at stage 2 diff --git a/target/arm/cpu.c b/target/arm/cpu.c index a1acce3..412e94c 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -235,6 +235,12 @@ static void arm_cpu_reset(CPUState *s) env->regs[15] = 0xFFFF0000; } + /* M profile requires that reset clears the exclusive monitor; + * A profile does not, but clearing it makes more sense than having it + * set with an exclusive access on address zero. + */ + arm_clear_exclusive(env); + env->vfp.xregs[ARM_VFP_FPEXC] = 0; #endif diff --git a/target/arm/helper.c b/target/arm/helper.c index 329e517..668e367 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -6175,6 +6175,7 @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr) armv7m_nvic_acknowledge_irq(env->nvic); switch_v7m_sp(env, 0); + arm_clear_exclusive(env); /* Clear IT bits */ env->condexec_bits = 0; env->regs[14] = lr; @@ -6354,6 +6355,7 @@ static void do_v7m_exception_exit(ARMCPU *cpu) } /* Otherwise, we have a successful exception exit. */ + arm_clear_exclusive(env); qemu_log_mask(CPU_LOG_INT, "...successful exception return\n"); } diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c index d1bca46..6a60464 100644 --- a/target/arm/op_helper.c +++ b/target/arm/op_helper.c @@ -1022,7 +1022,7 @@ void HELPER(exception_return)(CPUARMState *env) aarch64_save_sp(env, cur_el); - env->exclusive_addr = -1; + arm_clear_exclusive(env); /* We must squash the PSTATE.SS bit to zero unless both of the * following hold: