From patchwork Thu Jun 13 12:13:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 166618 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp701584ilk; Thu, 13 Jun 2019 05:33:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxgWpN6r8vf+ksZezfiEXi9YuXkM8kRCbWx0RVLSaB+qNeywzosGquENTP707MO3CHrJyJV X-Received: by 2002:a0c:879d:: with SMTP id 29mr3275528qvj.91.1560429215832; Thu, 13 Jun 2019 05:33:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560429215; cv=none; d=google.com; s=arc-20160816; b=NGm6m2Yc/9PqVpolNZaypai+N28+5koLrsrUoTt7dLvXzgNjOItQlLa1thrL7aqMNr 8R2apWeC1BmWpnuwjSisLY12ZnQY2FbtIA0nM8IwcNrQcpzr2eFLfS38/bDonitYEFgB DJUwGfUqYODQ0kXgV9TC9d6mNYU870lyCbD+0u5TVUgjgQ/9OFPzXjYRvfxFRbiviSVW 0MmXaSrIFW28sKCE7sYPzvXq1AJtE7OHAcrVpD+kSOUVqvLUE5PwaOPxW5FuDMGCiQj1 wh8pb71LbkI2dxRV6XAFJmXiWXY6ccm+lOzTpQUHI3q7sdLC2ZXCXQBerON8ES/iPSaU GuwQ== 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=FgrJRA7j7aTJ3DWKdfLXQg9RBsbyTXhKrH5Enhs39X4=; b=x3aG4+o42TGtMmCVFrf9c8bYzKDWC3xb1/250gFn5FgcmZcGze7P23jgNYmqFz9p8x qbiPuKN+ewcdJW7Ktt1+miSmPuJfkwhkARvlH+vpK2GG3IzPpTL4NKnbtmK8s/NROTrF /3XH7HHZwjVMAkYK+pTBAxdrazWbdhwW7RBsGxQowVIdlv6h5jgvM+UNtgEliCTWqOaa w/bk5agmji7OSjpFPKMKcMxCL2D21BP4+gPpFynhC67l7undgd+enPIMsQtS3+iC82Si 8DJeLgof4hGgl98IiEqpoByqoBqe6bey0Sf5Z2A+7CMD6OIsTxeqLUpKVSUpz3sevoQq FjfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mo6vMRnX; 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 v124si1559958qkc.264.2019.06.13.05.33.35 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jun 2019 05:33:35 -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=mo6vMRnX; 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]:39420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbOv8-0001Pr-WB for patch@linaro.org; Thu, 13 Jun 2019 08:33:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58775) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbOcx-0007tk-HY for qemu-devel@nongnu.org; Thu, 13 Jun 2019 08:14:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbOcu-0003wy-B0 for qemu-devel@nongnu.org; Thu, 13 Jun 2019 08:14:47 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:39408) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hbOcr-0003tS-DB for qemu-devel@nongnu.org; Thu, 13 Jun 2019 08:14:41 -0400 Received: by mail-wr1-x443.google.com with SMTP id x4so17872241wrt.6 for ; Thu, 13 Jun 2019 05:14:40 -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=FgrJRA7j7aTJ3DWKdfLXQg9RBsbyTXhKrH5Enhs39X4=; b=mo6vMRnX3ZrwUK7W+GWxyPfZUPDHrhoAbLvdB199iH+Xt2Q+QkRNiGo9aZ1ifX/SQW 3Nw/Yxb7lVSchyLOW7nI6RIhRE3RWy6rmOtdR3SDS6Uz7xUKOobBg+IhY/2ALLBoMSFy 5vScqnSoOf9ndo639W6Yved1gARN5PANXXd73KrcanxIYOWajgS35AVZM6s1tVcKC+jk B5nKS5PSBwE1TneM4TBaQwzxORX+3BE8Xl/xKqf0xVxicjbMIpAr8+J2LiLE9WJzVMoi WtTe6xfKZKss6icO3EX8Mn2DvAWd0Ze9GFibtr/k4cR/AxCxLMRukO4IVBY5kAw9WDqY P6mg== 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=FgrJRA7j7aTJ3DWKdfLXQg9RBsbyTXhKrH5Enhs39X4=; b=oVy1e6Wmvftw9Ch8QulPJnV31CkehUezGEzydDUa2OUJlK/+kfGUxMbyJT8MBj6QZE q82mATgehoFIZvBDb3cnA7XLeXW0KD0C3twbFUXDUErvqULZw0Pb/isRhUd85nF7InBM m7el1vAyVbfRPXlioqAXOQVnL/KMYARE3XwcIkIXytnbc1dTR8oIJvL2OaF7x+pV9OmF day+7pAF7CLemw9T5DXJ+OrxidRIYc4/8NcLo8lhgeLbFE81FrvIlG4hX//UZ5ctwJEB CozsqLV6VNtXE3NUjM3MZ6sqmWmZIgPWvj6+qEBlkKFwzhTFIxj6DTYN/SCF5jBSNwyK WUXg== X-Gm-Message-State: APjAAAX7TrvxiP10b0Uf6/Ay0RGJ/40WRM3ijCXv890wSoGuzct8Jucf PgLaiNe8lW6Ug1j7Ym/s+Jmk+Al0UMlJ5g== X-Received: by 2002:adf:e8d0:: with SMTP id k16mr46597951wrn.31.1560428079139; Thu, 13 Jun 2019 05:14:39 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id y6sm2010576wrp.12.2019.06.13.05.14.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2019 05:14:38 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 13 Jun 2019 13:13:48 +0100 Message-Id: <20190613121433.5246-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190613121433.5246-1-peter.maydell@linaro.org> References: <20190613121433.5246-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::443 Subject: [Qemu-devel] [PULL 03/48] target/arm: Implement NSACR gating of floating point 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The NSACR register allows secure code to configure the FPU to be inaccessible to non-secure code. If the NSACR.CP10 bit is set then: * NS accesses to the FPU trap as UNDEF (ie to NS EL1 or EL2) * CPACR.{CP10,CP11} behave as if RAZ/WI * HCPTR.{TCP11,TCP10} behave as if RAO/WI Note that we do not implement the NSACR.NSASEDIS bit which gates only access to Advanced SIMD, in the same way that we don't implement the equivalent CPACR.ASEDIS and HCPTR.TASE. Reviewed-by: Richard Henderson Signed-off-by: Peter Maydell Message-id: 20190510110357.18825-1-peter.maydell@linaro.org --- target/arm/helper.c | 75 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/target/arm/helper.c b/target/arm/helper.c index 188fb1950ef..df4276f5f6c 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -930,9 +930,36 @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri, } value &= mask; } + + /* + * For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10 + * is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00. + */ + if (arm_feature(env, ARM_FEATURE_EL3) && !arm_el_is_aa64(env, 3) && + !arm_is_secure(env) && !extract32(env->cp15.nsacr, 10, 1)) { + value &= ~(0xf << 20); + value |= env->cp15.cpacr_el1 & (0xf << 20); + } + env->cp15.cpacr_el1 = value; } +static uint64_t cpacr_read(CPUARMState *env, const ARMCPRegInfo *ri) +{ + /* + * For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10 + * is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00. + */ + uint64_t value = env->cp15.cpacr_el1; + + if (arm_feature(env, ARM_FEATURE_EL3) && !arm_el_is_aa64(env, 3) && + !arm_is_secure(env) && !extract32(env->cp15.nsacr, 10, 1)) { + value &= ~(0xf << 20); + } + return value; +} + + static void cpacr_reset(CPUARMState *env, const ARMCPRegInfo *ri) { /* Call cpacr_write() so that we reset with the correct RAO bits set @@ -998,7 +1025,7 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { { .name = "CPACR", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .crn = 1, .crm = 0, .opc1 = 0, .opc2 = 2, .accessfn = cpacr_access, .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.cpacr_el1), - .resetfn = cpacr_reset, .writefn = cpacr_write }, + .resetfn = cpacr_reset, .writefn = cpacr_write, .readfn = cpacr_read }, REGINFO_SENTINEL }; @@ -4683,6 +4710,36 @@ uint64_t arm_hcr_el2_eff(CPUARMState *env) return ret; } +static void cptr_el2_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + /* + * For A-profile AArch32 EL3, if NSACR.CP10 + * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1. + */ + if (arm_feature(env, ARM_FEATURE_EL3) && !arm_el_is_aa64(env, 3) && + !arm_is_secure(env) && !extract32(env->cp15.nsacr, 10, 1)) { + value &= ~(0x3 << 10); + value |= env->cp15.cptr_el[2] & (0x3 << 10); + } + env->cp15.cptr_el[2] = value; +} + +static uint64_t cptr_el2_read(CPUARMState *env, const ARMCPRegInfo *ri) +{ + /* + * For A-profile AArch32 EL3, if NSACR.CP10 + * is 0 then HCPTR.{TCP11,TCP10} ignore writes and read as 1. + */ + uint64_t value = env->cp15.cptr_el[2]; + + if (arm_feature(env, ARM_FEATURE_EL3) && !arm_el_is_aa64(env, 3) && + !arm_is_secure(env) && !extract32(env->cp15.nsacr, 10, 1)) { + value |= 0x3 << 10; + } + return value; +} + static const ARMCPRegInfo el2_cp_reginfo[] = { { .name = "HCR_EL2", .state = ARM_CP_STATE_AA64, .type = ARM_CP_IO, @@ -4730,7 +4787,8 @@ static const ARMCPRegInfo el2_cp_reginfo[] = { { .name = "CPTR_EL2", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 2, .access = PL2_RW, .accessfn = cptr_access, .resetvalue = 0, - .fieldoffset = offsetof(CPUARMState, cp15.cptr_el[2]) }, + .fieldoffset = offsetof(CPUARMState, cp15.cptr_el[2]), + .readfn = cptr_el2_read, .writefn = cptr_el2_write }, { .name = "MAIR_EL2", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 4, .crn = 10, .crm = 2, .opc2 = 0, .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.mair_el[2]), @@ -13587,6 +13645,19 @@ int fp_exception_el(CPUARMState *env, int cur_el) break; } + /* + * The NSACR allows A-profile AArch32 EL3 and M-profile secure mode + * to control non-secure access to the FPU. It doesn't have any + * effect if EL3 is AArch64 or if EL3 doesn't exist at all. + */ + if ((arm_feature(env, ARM_FEATURE_EL3) && !arm_el_is_aa64(env, 3) && + cur_el <= 2 && !arm_is_secure_below_el3(env))) { + if (!extract32(env->cp15.nsacr, 10, 1)) { + /* FP insns act as UNDEF */ + return cur_el == 2 ? 2 : 1; + } + } + /* For the CPTR registers we don't need to guard with an ARM_FEATURE * check because zero bits in the registers mean "don't trap". */