From patchwork Fri Jan 18 14:57:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 155976 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3383659jaa; Fri, 18 Jan 2019 07:27:33 -0800 (PST) X-Google-Smtp-Source: ALg8bN7b97MHLesmhz+nKjWvDwyW2qrmrLgTglVbBPHR5Y+SwXinaC9MJtsPdUn+DNMaXhP4zHXH X-Received: by 2002:a1c:7eca:: with SMTP id z193mr17071565wmc.140.1547825253170; Fri, 18 Jan 2019 07:27:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547825253; cv=none; d=google.com; s=arc-20160816; b=qS9kw7+OHsl4hveFVUbrDW3aA479xgayi3tq4DhDCxinWew52D/h8v74HLXwFxz967 s2v0A7Jd99N58wIc1hCTYrA1t9AkwQK4XXa2162QKBOeeOfEG1pzw+d/VOWWs4PkYNDj 7k3EDt90tEYXUbHUBDbeFSJAcxQvKOTfVf6exBknGQb4xZEACzQ1bpv99XGRtUHdH0Gs b1gvJ40P8LuPbfnBf/O7HwCp+fwwwj45x66CTFY1wjw+Ye4zigqCqOXKAgs4xgDJcSkU DTk+XU3zoPkkQ6v4+IjDU7vc8MyI0RCcBBtnJX9AR3E4IUCNFGdioOL9XSe96xbJYKeb 29Lg== 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=Q/iKc1b7Ptvw05FtPrBH1F4iiqkzdyUjBpBBa90oCZo=; b=mggxcCYvdmcs819/gbCSDrirbWolkvV/qH3w3mkGQCdp9SFl+KWKEAQMSwhIDkJjjk I0Joh5uPnMEdArDhsK5r0n8tZUqpMcTveMdOxqK/XDe4+Vtf7jHI6GnmJndeJsuwnamE SDjRWl7/ePlWMyilwNW6Bz2L4A3NCFESJUEa8en0357M6QaXA2OABhsrxZVGhzI2CPAb Oite32kdhWvUEcsL1cEN9HMNGrpVRlwu/rtf46nboHVTD/K1vZNvtXV48uXhlxuMTv+D EnckhnoXdp8WZOOcVsUpLX7aq0g88X09C945jmRXvfhrWsexz3skOU+Zhxfr6scChL3B lHHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=J8AJmB3m; 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 r5si56773069wrs.80.2019.01.18.07.27.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 18 Jan 2019 07:27:33 -0800 (PST) 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=J8AJmB3m; 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]:41430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkW3P-0000uV-Vz for patch@linaro.org; Fri, 18 Jan 2019 10:27:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkVbc-0002tw-Bu for qemu-devel@nongnu.org; Fri, 18 Jan 2019 09:58:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkVbb-0007Wn-AN for qemu-devel@nongnu.org; Fri, 18 Jan 2019 09:58:48 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:46684) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gkVbb-0007WL-4B for qemu-devel@nongnu.org; Fri, 18 Jan 2019 09:58:47 -0500 Received: by mail-wr1-x42d.google.com with SMTP id l9so15349398wrt.13 for ; Fri, 18 Jan 2019 06:58:47 -0800 (PST) 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=Q/iKc1b7Ptvw05FtPrBH1F4iiqkzdyUjBpBBa90oCZo=; b=J8AJmB3mLhXJDXzGm9r8BAHhcBTQW0DgIu9gq7GgdzezGH/lP1g/8Kp6X6Lw++PqpD X0xnZwF+OKfSp2PLA2ZTiWCahIEZln/S2REvCzkX9lyVPQPsDsxdpWVSN8YjMjhOinxC h7gpj2HVmtIAy5IRWB5E7CE4Ee+OB6K7JFtpo= 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=Q/iKc1b7Ptvw05FtPrBH1F4iiqkzdyUjBpBBa90oCZo=; b=awnjncJivO2lppz69bikTo9h2dohw0od2ZxIZPGbTMAblsctmDedVS4VcZ6b6V609r xXvZwbIZCKPwFOl8MTK5fQNFTr8+W3pMBgenaAIPgFon+BGSQIfqiWX3tHR0Txpk4l8A pYV/yt8kx+BYP9WJLr1PZ+tgLqbWMD1i/u5TzYfbCYcjZGsJeffL54Vqd8mSOYLgR+9l DHjIwxgfTryExzui90KjjchDcnf4XOMz0mZnTUS5mcKMQaljMDJGQBnVBcuUvTeXybPW +j0VbmrTkGdVdNmV4CSfNQ5KGUL0EcemO8T9hWgL7xW6ozwUEy24UL/fl3erDze7Weve SvhA== X-Gm-Message-State: AJcUukfC09FVYpMjWbvvF08C2T3Zg3UT25k2IYdTXF4TMHg+5CF/W0hC uqoKreQPcZp5C81Rzf3rOGFvA3fnC1WGEw== X-Received: by 2002:a5d:47d1:: with SMTP id l17mr16600155wrs.319.1547823525960; Fri, 18 Jan 2019 06:58:45 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id e27sm92094561wra.67.2019.01.18.06.58.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Jan 2019 06:58:45 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 18 Jan 2019 14:57:50 +0000 Message-Id: <20190118145805.6852-35-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190118145805.6852-1-peter.maydell@linaro.org> References: <20190118145805.6852-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::42d Subject: [Qemu-devel] [PULL 34/49] target/arm: Enable PAuth for user-only 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" From: Richard Henderson Add 4 attributes that controls the EL1 enable bits, as we may not always want to turn on pointer authentication with -cpu max. However, by default they are enabled. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Message-id: 20190108223129.5570-31-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/cpu.c | 3 +++ target/arm/cpu64.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) -- 2.20.1 diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 4c4e9e169ed..14bc24a35ae 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -162,6 +162,9 @@ static void arm_cpu_reset(CPUState *s) env->pstate = PSTATE_MODE_EL0t; /* Userspace expects access to DC ZVA, CTL_EL0 and the cache ops */ env->cp15.sctlr_el[1] |= SCTLR_UCT | SCTLR_UCI | SCTLR_DZE; + /* Enable all PAC instructions */ + env->cp15.hcr_el2 |= HCR_API; + env->cp15.scr_el3 |= SCR_API; /* and to the FP/Neon instructions */ env->cp15.cpacr_el1 = deposit64(env->cp15.cpacr_el1, 20, 2, 3); /* and to the SVE instructions */ diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 1974f1aeb74..d0de0d5dcfa 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -285,6 +285,38 @@ static void cpu_max_set_sve_vq(Object *obj, Visitor *v, const char *name, error_propagate(errp, err); } +#ifdef CONFIG_USER_ONLY +static void cpu_max_get_packey(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + ARMCPU *cpu = ARM_CPU(obj); + const uint64_t *bit = opaque; + bool enabled = (cpu->env.cp15.sctlr_el[1] & *bit) != 0; + + visit_type_bool(v, name, &enabled, errp); +} + +static void cpu_max_set_packey(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + ARMCPU *cpu = ARM_CPU(obj); + Error *err = NULL; + const uint64_t *bit = opaque; + bool enabled; + + visit_type_bool(v, name, &enabled, errp); + + if (!err) { + if (enabled) { + cpu->env.cp15.sctlr_el[1] |= *bit; + } else { + cpu->env.cp15.sctlr_el[1] &= ~*bit; + } + } + error_propagate(errp, err); +} +#endif + /* -cpu max: if KVM is enabled, like -cpu host (best possible with this host); * otherwise, a CPU with as many features enabled as our emulation supports. * The version of '-cpu max' for qemu-system-arm is defined in cpu.c; @@ -360,6 +392,34 @@ static void aarch64_max_initfn(Object *obj) */ cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */ cpu->dcz_blocksize = 7; /* 512 bytes */ + + /* + * Note that Linux will enable enable all of the keys at once. + * But doing it this way will allow experimentation beyond that. + */ + { + static const uint64_t apia_bit = SCTLR_EnIA; + static const uint64_t apib_bit = SCTLR_EnIB; + static const uint64_t apda_bit = SCTLR_EnDA; + static const uint64_t apdb_bit = SCTLR_EnDB; + + object_property_add(obj, "apia", "bool", cpu_max_get_packey, + cpu_max_set_packey, NULL, + (void *)&apia_bit, &error_fatal); + object_property_add(obj, "apib", "bool", cpu_max_get_packey, + cpu_max_set_packey, NULL, + (void *)&apib_bit, &error_fatal); + object_property_add(obj, "apda", "bool", cpu_max_get_packey, + cpu_max_set_packey, NULL, + (void *)&apda_bit, &error_fatal); + object_property_add(obj, "apdb", "bool", cpu_max_get_packey, + cpu_max_set_packey, NULL, + (void *)&apdb_bit, &error_fatal); + + /* Enable all PAC keys by default. */ + cpu->env.cp15.sctlr_el[1] |= SCTLR_EnIA | SCTLR_EnIB; + cpu->env.cp15.sctlr_el[1] |= SCTLR_EnDA | SCTLR_EnDB; + } #endif cpu->sve_max_vq = ARM_MAX_VQ;