From patchwork Mon Nov 17 16:47:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 40965 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 656EA24035 for ; Mon, 17 Nov 2014 17:02:35 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id l18sf860580wgh.6 for ; Mon, 17 Nov 2014 09:02:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=GZNbdlvXEQFjGGGahvtdaGk1HKOmJ6FwIkkKe7pYIUk=; b=GHk6ivE2VsrF0KoBiOFUgudXpxDpiCGNEypXm2QDzC4kv0Hcd7CfdRhD2Yni8nFmIK pM9PMaov3kXm2sert9qVQ5ngsGDz4rHcEorjasz/+XfvwyNLBW6ZYwlelvHGZIeRDXOx CiyigAe4Jr2SvsqJaWQ+SGe9DdMgRlXc8ZZw8ebMrClxfx+dEoiumfZkwUIpAZn4Q1OO j1sVJPVAwYiPJONZFw0oj/9w8yXDF6rBosQbX3+HS8gQU7yzSLGJl8aAIg7POteNR/dj RbGv9N4u8iM+F4SZScS4aUFqlgzOpY69RKb6i24BZnxX2BLmjhBR1f7on4lqERl4i3fe S/RA== X-Gm-Message-State: ALoCoQl2B9Ukw3n+NmHU2MAhdi+ug5gLuNDXFI9++xuOdPRviBFHVusPYNIWYI0fPLDClVOUakfC X-Received: by 10.194.178.163 with SMTP id cz3mr14189308wjc.1.1416243754725; Mon, 17 Nov 2014 09:02:34 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.121.72 with SMTP id li8ls1286565lab.101.gmail; Mon, 17 Nov 2014 09:02:34 -0800 (PST) X-Received: by 10.112.210.100 with SMTP id mt4mr29133318lbc.31.1416243754454; Mon, 17 Nov 2014 09:02:34 -0800 (PST) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id ci11si8075196lad.53.2014.11.17.09.02.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Nov 2014 09:02:34 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by mail-la0-f53.google.com with SMTP id pn19so1713622lab.26 for ; Mon, 17 Nov 2014 09:02:34 -0800 (PST) X-Received: by 10.112.189.10 with SMTP id ge10mr28870823lbc.23.1416243754326; Mon, 17 Nov 2014 09:02:34 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp1189362lbc; Mon, 17 Nov 2014 09:02:33 -0800 (PST) X-Received: by 10.170.161.10 with SMTP id c10mr28905325ykd.9.1416243748970; Mon, 17 Nov 2014 09:02:28 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 70si35251701yhi.213.2014.11.17.09.02.28 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 17 Nov 2014 09:02:28 -0800 (PST) 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; Received: from localhost ([::1]:48962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqPh6-0000WK-3G for patch@linaro.org; Mon, 17 Nov 2014 12:02:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqPTg-0001kK-Su for qemu-devel@nongnu.org; Mon, 17 Nov 2014 11:48:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XqPTb-0007Dc-KZ for qemu-devel@nongnu.org; Mon, 17 Nov 2014 11:48:36 -0500 Received: from mail-pa0-f45.google.com ([209.85.220.45]:40450) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqPTb-0007D2-AM for qemu-devel@nongnu.org; Mon, 17 Nov 2014 11:48:31 -0500 Received: by mail-pa0-f45.google.com with SMTP id lf10so22664611pab.32 for ; Mon, 17 Nov 2014 08:48:30 -0800 (PST) X-Received: by 10.68.68.226 with SMTP id z2mr30485542pbt.107.1416242910464; Mon, 17 Nov 2014 08:48:30 -0800 (PST) Received: from gbellows-linaro.qualcomm.com (rrcs-67-52-129-61.west.biz.rr.com. [67.52.129.61]) by mx.google.com with ESMTPSA id r2sm18499056pdi.60.2014.11.17.08.48.29 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Nov 2014 08:48:29 -0800 (PST) From: Greg Bellows To: qemu-devel@nongnu.org, serge.fdrv@gmail.com, edgar.iglesias@gmail.com, aggelerf@ethz.ch, peter.maydell@linaro.org Date: Mon, 17 Nov 2014 10:47:46 -0600 Message-Id: <1416242878-876-15-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1416242878-876-1-git-send-email-greg.bellows@linaro.org> References: <1416242878-876-1-git-send-email-greg.bellows@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.220.45 Cc: greg.bellows@linaro.org Subject: [Qemu-devel] [PATCH v11 14/26] target-arm: respect SCR.FW, SCR.AW and SCTLR.NMFI X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 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-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: greg.bellows@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Fabian Aggeler Add checks of SCR AW/FW bits when performing writes of CPSR. These SCR bits are used to control whether the CPSR masking bits can be adjusted from non-secure state. Signed-off-by: Fabian Aggeler Signed-off-by: Greg Bellows Reviewed-by: Peter Maydell --- v10 -> v11 - Moved cpsr_write() uncached_cpsr updated to before the mode setting. v8 -> v9 - Move cpsr_write mask filtering above mode switch. - Replace conditional checks removed in v8. v7 -> v8 - Fixed incorrect use of env->uncached_cpsr A/I/F to use env->daif instead. - Removed incorrect statement about SPSR to CPSR copies being affected by SCR.AW/FW. - Fix typo in comment. - Simpified cpsr_write logic v3 -> v4 - Fixed up conditions for ignoring CPSR.A/F updates by isolating to v7 and checking for the existence of EL3 and non-existence of EL2. --- target-arm/helper.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/target-arm/helper.c b/target-arm/helper.c index 1148273..d555fe4 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -3644,6 +3644,8 @@ uint32_t cpsr_read(CPUARMState *env) void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) { + uint32_t changed_daif; + if (mask & CPSR_NZCV) { env->ZF = (~val) & CPSR_Z; env->NF = val; @@ -3666,6 +3668,58 @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) env->GE = (val >> 16) & 0xf; } + /* In a V7 implementation that includes the security extensions but does + * not include Virtualization Extensions the SCR.FW and SCR.AW bits control + * whether non-secure software is allowed to change the CPSR_F and CPSR_A + * bits respectively. + * + * In a V8 implementation, it is permitted for privileged software to + * change the CPSR A/F bits regardless of the SCR.AW/FW bits. + */ + if (!arm_feature(env, ARM_FEATURE_V8) && + arm_feature(env, ARM_FEATURE_EL3) && + !arm_feature(env, ARM_FEATURE_EL2) && + !arm_is_secure(env)) { + + changed_daif = (env->daif ^ val) & mask; + + if (changed_daif & CPSR_A) { + /* Check to see if we are allowed to change the masking of async + * abort exceptions from a non-secure state. + */ + if (!(env->cp15.scr_el3 & SCR_AW)) { + qemu_log_mask(LOG_GUEST_ERROR, + "Ignoring attempt to switch CPSR_A flag from " + "non-secure world with SCR.AW bit clear\n"); + mask &= ~CPSR_A; + } + } + + if (changed_daif & CPSR_F) { + /* Check to see if we are allowed to change the masking of FIQ + * exceptions from a non-secure state. + */ + if (!(env->cp15.scr_el3 & SCR_FW)) { + qemu_log_mask(LOG_GUEST_ERROR, + "Ignoring attempt to switch CPSR_F flag from " + "non-secure world with SCR.FW bit clear\n"); + mask &= ~CPSR_F; + } + + /* Check whether non-maskable FIQ (NMFI) support is enabled. + * If this bit is set software is not allowed to mask + * FIQs, but is allowed to set CPSR_F to 0. + */ + if ((A32_BANKED_CURRENT_REG_GET(env, sctlr) & SCTLR_NMFI) && + (val & CPSR_F)) { + qemu_log_mask(LOG_GUEST_ERROR, + "Ignoring attempt to enable CPSR_F flag " + "(non-maskable FIQ [NMFI] support enabled)\n"); + mask &= ~CPSR_F; + } + } + } + env->daif &= ~(CPSR_AIF & mask); env->daif |= val & CPSR_AIF & mask;