From patchwork Tue Jan 8 22:31:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 155038 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp49200jaa; Tue, 8 Jan 2019 14:57:21 -0800 (PST) X-Google-Smtp-Source: ALg8bN5nzuGLjaYayayWlbug3twOEFrDfL7sFFaWXReNk7iCroJiJB1nGNfkOEbkOZusSucEL9i/ X-Received: by 2002:adf:eb45:: with SMTP id u5mr2705998wrn.102.1546988241779; Tue, 08 Jan 2019 14:57:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546988241; cv=none; d=google.com; s=arc-20160816; b=jDNe7z0649Tg6MYiFmmmCW1Ls3UjpQoNHz9iqcjZVYYor1hli4okc0Up4SJHe5SWIi Sv+XNH1VMK52z7MEOchpMTERda3bytglP/hFA3JhDLjatv1fbM3JROnQtn1Hr0uy0VoF rter8ScR8nhqDQiMb4YbQL1q3F5RJvFF5JHQnL/0pQmrh9tfBV68GM/DTN7tOXSHH+Sj VPBFkLypWYNj4G9XqSDD58dc23bpGYgkmn+I3gtav23rTfa/GzFIWzVvI7bvOdz/HtI+ zsvi1HqWcl/UPiXD29fk/aTL3SLUcWu2C4wqCmWPFBFYd0j5NUr1u6t+yN8QATWdLCDx fd2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=SsMK15voUNz/4OMQjnv/6CxVykvnZyFEz9xWDCHBxbE=; b=VaAOhtoOGZwsAG5SEsCFToyyKNhKEXcuernYA29KJ47S0B3MinFrsvuMPHY6lJ7GaS 0v17CY/f8voQ+lth3MMPI8XC6DV4wvSIMCXgV9pRODSDQDJk/o3jjWZ2qT1rngyg/Yo9 Bxh9JYAbQRsiybro8RfU0wbvkEOob4mLK3s0mRLmGuKK39wZw2o5iGknMExZGqYjHznX ywpMwe+XHAt4W7xF/ZNWAPEuBqUtP5f3a5avvgJTEaOgVjx7M65LRZ1b6CVlMI2gaqQ5 1HHcuX4H6LbJ/f2J5BS/aw4ZIEUVJRvGbIzAFi3ItFQ/Ebv1kCNe8GLH6it4NbtgvEWw BnXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RFtKkgTF; 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 g1si7550827wmg.78.2019.01.08.14.57.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 08 Jan 2019 14:57:21 -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=RFtKkgTF; 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]:46222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gh0JE-0007zj-KP for patch@linaro.org; Tue, 08 Jan 2019 17:57:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggzvf-0000rS-JJ for qemu-devel@nongnu.org; Tue, 08 Jan 2019 17:33:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ggzve-0005UP-I0 for qemu-devel@nongnu.org; Tue, 08 Jan 2019 17:32:59 -0500 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:44814) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ggzve-0005Og-BJ for qemu-devel@nongnu.org; Tue, 08 Jan 2019 17:32:58 -0500 Received: by mail-pg1-x543.google.com with SMTP id t13so2346827pgr.11 for ; Tue, 08 Jan 2019 14:32:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SsMK15voUNz/4OMQjnv/6CxVykvnZyFEz9xWDCHBxbE=; b=RFtKkgTFjr71uo+I4TXeaiIYlJwXNkaJwrXFyoVxmgjqY8ENZRQWkLv47bB08jBgPp uSES5q5NH+nFc9xe8VsTJR30eXdriThyVY8awbUMKaEbhvKi3DYrsINCdsTqHWicMHQO NQ5TeT+CofqKSLBNMqnIQW7Txdi7r9LSqgojU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SsMK15voUNz/4OMQjnv/6CxVykvnZyFEz9xWDCHBxbE=; b=OeniCEeSWc8iZeLojj4zrQT4BsfZON0z9PVc3sSZTuQU5wns4en77nCqtVNNYnnVx6 41P4TL/FusAQaVZ9HbgrBd26taDn3G3ZS7AyPsWJtBPWbUIyhigFmBg0LWVY7FCmiCDO BK7g1WOBVJL3ks/BBeg1rzevZTO7bE2lm0WmQ5D00XKXGGBsQQEAe63BTJoN6uJWm6Hj 1FrkiwfoTEtQQZhFs6AUPIix8I31g6T0vb4lwL9bjbD4l7E/yrxjSL1czojUhWZL8gxV FV1OMkH5SbtuCgG3SD0cjEIhsuIVbox3yjdY5cH1gRcLnRh1sKM5OA50umaawqfDVzFz MIWA== X-Gm-Message-State: AJcUukd6VkOsOVuJ+XdY83V//ZHuAxc0ZvOEL5KhbvAhZXFvagUXyplE CXwe5SBIwkumyQ1jwRVL2AcS/Dnj93o= X-Received: by 2002:a63:2d46:: with SMTP id t67mr3217956pgt.140.1546986774304; Tue, 08 Jan 2019 14:32:54 -0800 (PST) Received: from cloudburst.lan (2001-44b8-2176-c800-8cc6-2630-7d99-5ef1.static.ipv6.internode.on.net. [2001:44b8:2176:c800:8cc6:2630:7d99:5ef1]) by smtp.gmail.com with ESMTPSA id w128sm100686177pfw.79.2019.01.08.14.32.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Jan 2019 14:32:53 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 9 Jan 2019 08:31:28 +1000 Message-Id: <20190108223129.5570-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190108223129.5570-1-richard.henderson@linaro.org> References: <20190108223129.5570-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 Subject: [Qemu-devel] [PATCH v3 30/31] 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: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- target/arm/cpu.c | 3 +++ target/arm/cpu64.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) -- 2.17.2 Reviewed-by: Peter Maydell diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 4c4e9e169e..14bc24a35a 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 1974f1aeb7..d0de0d5dcf 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;