From patchwork Fri Dec 14 05:23:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 153748 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1674344ljp; Thu, 13 Dec 2018 21:30:21 -0800 (PST) X-Google-Smtp-Source: AFSGD/WQ9+1XRVp2690DWuILQqGtVMNKnIZ1VWM0NzNnZzJbh5e4VY4Bgo/ZOxeZpt8XJsAGl8vH X-Received: by 2002:ac8:231a:: with SMTP id a26mr1558756qta.40.1544765421379; Thu, 13 Dec 2018 21:30:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544765421; cv=none; d=google.com; s=arc-20160816; b=qBWd8iFVhcCJVuz1+NyCQnKbe5dpq+khruvTERuAggceqYYPQPArVCwDVThax5wH2Q JHEYos3zgzopieFCFRViMdMTbvv36jxIOV57D4qmnO8rBs19oklAxVOx30cpgdpSC/n0 yQSborkd3gZo0G/Ahxbse+DK3/Jj+RtZORP4lAMEpTH0qeY3xTMcm/K6+ijUXR+J/PO+ GNSVrgsm2KOLn1av0HwN4GnEuoCTkmoNatviPqWGSfflBf9hfJ/8gy8hcsyE2os55kXo 3YnpT/jvViQUucD2vq9SgepRxGarHSdgAVuuwrAMEqxbdEJu0m9/iIDfJDgeC35DYaSO v4+A== 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=ldSi+/GZ75tY2sMXo663Bnf5UGnKGhgycBn6Q0lPKBw=; b=BUZHwqVuZ4bYpBaCs9TGZXuWuYYKEA6ju1yF6oSzdimQJ3cCPi7G6g3dSQhNHt7XPE /B+IXGcE+O7vC1rWnoP/xhPJuGDPfPlg818jymKhxNCIMe9AR2Z3P07i81/Cmsl+ap6V 6sjjMFAM2tyVvQj9mAD4M1Rykd3NKku5WU78CLYWamdrAgc7gID6WZ6Qp1iTtYFXI94j eLFkDj1mjtUecj5A3gJ/ZbZujCDH2zXmkVVRY9+JpTCn0O3RlMNdnYO2Kfcmf4OVWLtS 7c9O1hY1K7hUqL3g7b/+VBXi5N9HSBto9npnx7cczkt+rak8WnpWibxx9Iq/oufl+i2y QaMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=iymr0tPh; 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 q31si1888597qtj.66.2018.12.13.21.30.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 13 Dec 2018 21:30:21 -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; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=iymr0tPh; 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]:59452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXg3I-0000Rz-Dh for patch@linaro.org; Fri, 14 Dec 2018 00:30:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXfxX-0004P2-Nt for qemu-devel@nongnu.org; Fri, 14 Dec 2018 00:24:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXfxW-0005LM-Cb for qemu-devel@nongnu.org; Fri, 14 Dec 2018 00:24:23 -0500 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]:45304) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gXfxT-0005K2-Fq for qemu-devel@nongnu.org; Fri, 14 Dec 2018 00:24:21 -0500 Received: by mail-oi1-x236.google.com with SMTP id y1so3607062oie.12 for ; Thu, 13 Dec 2018 21:24:18 -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=ldSi+/GZ75tY2sMXo663Bnf5UGnKGhgycBn6Q0lPKBw=; b=iymr0tPhyrBNK3XVG5phfM0TR6DHKqwC0IQBp48dP0Xuoau2Of2HiD2Qv6Iv9xA8Gf qMRYnbi1ORkebyAMPyOkO4H4fBqdsVt+4dQKV4zRcSj6VKxuNvA9dbChzw1b6jVhNKtA YV20SCC6GFNl//RJx/et/oEt1Vm9h5mM74iQE= 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=ldSi+/GZ75tY2sMXo663Bnf5UGnKGhgycBn6Q0lPKBw=; b=jG+V2Qjfd4jDX668pw+LMcwjlMj2bBuTQADIl9P6FYywsHhraFJK/DxKI/YX+RgopX oon4E/Bd6Z2SjXuMk9u/kREeAoRPSy3dgLT6vK/QcveCtP6LhNePU6cWGRcit6pF2RcL wm/p2QdAGa/gXSloIKrM/+j6N41qDsukr75JApfeQt4vRde/LEOLaKPqW7e5Z3RglHce DNJL2vMMaduWojiHf1Y95rSz8blW61DcHzzM36ewVgfavedyWwBGGVWpnLj8l0BMgOAO lADoG/KtOyDd1L4pH/DH+aXC38+n5jDme7cFtRyPl5lu3SAAgs5s1dDULu3xYLPgELu0 h7bg== X-Gm-Message-State: AA+aEWaaZe3rr1JLMGmY7Vnt8EHDUbYP3Dx4l5WItsJVEUbYqhfGchRY 1j85Bia1d+2fttvh5Y7nyaSuMuuWcggkrg== X-Received: by 2002:aca:195:: with SMTP id 143mr928711oib.322.1544765057842; Thu, 13 Dec 2018 21:24:17 -0800 (PST) Received: from cloudburst.twiddle.net ([187.217.227.243]) by smtp.gmail.com with ESMTPSA id r1sm1845379oti.44.2018.12.13.21.24.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Dec 2018 21:24:17 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 13 Dec 2018 23:23:47 -0600 Message-Id: <20181214052410.11863-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181214052410.11863-1-richard.henderson@linaro.org> References: <20181214052410.11863-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::236 Subject: [Qemu-devel] [PATCH v2 04/27] target/arm: Add PAuth helpers 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" The cryptographic internals are stubbed out for now, but the enable and trap bits are checked. Signed-off-by: Richard Henderson ---- v2: Remove trap from xpac* helpers; these are now side-effect free. Use struct ARMPACKey. --- target/arm/helper-a64.h | 12 +++ target/arm/internals.h | 6 ++ target/arm/helper-a64.c | 166 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+) -- 2.17.2 diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h index 9d3a907049..28aa0af69d 100644 --- a/target/arm/helper-a64.h +++ b/target/arm/helper-a64.h @@ -85,3 +85,15 @@ DEF_HELPER_2(advsimd_rinth, f16, f16, ptr) DEF_HELPER_2(advsimd_f16tosinth, i32, f16, ptr) DEF_HELPER_2(advsimd_f16touinth, i32, f16, ptr) DEF_HELPER_2(sqrt_f16, f16, f16, ptr) + +DEF_HELPER_FLAGS_3(pacia, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(pacib, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(pacda, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(pacdb, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(pacga, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(autia, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(autib, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(autda, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(autdb, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_2(xpaci, TCG_CALL_NO_RWG_SE, i64, env, i64) +DEF_HELPER_FLAGS_2(xpacd, TCG_CALL_NO_RWG_SE, i64, env, i64) diff --git a/target/arm/internals.h b/target/arm/internals.h index 78e026d6e9..6bc0daf560 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -259,6 +259,7 @@ enum arm_exception_class { EC_CP14DTTRAP = 0x06, EC_ADVSIMDFPACCESSTRAP = 0x07, EC_FPIDTRAP = 0x08, + EC_PACTRAP = 0x09, EC_CP14RRTTRAP = 0x0c, EC_ILLEGALSTATE = 0x0e, EC_AA32_SVC = 0x11, @@ -426,6 +427,11 @@ static inline uint32_t syn_sve_access_trap(void) return EC_SVEACCESSTRAP << ARM_EL_EC_SHIFT; } +static inline uint32_t syn_pactrap(void) +{ + return EC_PACTRAP << ARM_EL_EC_SHIFT; +} + static inline uint32_t syn_insn_abort(int same_el, int ea, int s1ptw, int fsc) { return (EC_INSNABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c index 61799d20e1..bb64700e10 100644 --- a/target/arm/helper-a64.c +++ b/target/arm/helper-a64.c @@ -898,4 +898,170 @@ uint32_t HELPER(sqrt_f16)(uint32_t a, void *fpstp) return float16_sqrt(a, s); } +/* + * Helpers for ARMv8.3-PAuth. + */ +static uint64_t pauth_computepac(uint64_t data, uint64_t modifier, + ARMPACKey key) +{ + g_assert_not_reached(); /* FIXME */ +} + +static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modifier, + ARMPACKey *key, bool data) +{ + g_assert_not_reached(); /* FIXME */ +} + +static uint64_t pauth_auth(CPUARMState *env, uint64_t ptr, uint64_t modifier, + ARMPACKey *key, bool data, int keynumber) +{ + g_assert_not_reached(); /* FIXME */ +} + +static uint64_t pauth_strip(CPUARMState *env, uint64_t ptr, bool data) +{ + g_assert_not_reached(); /* FIXME */ +} + +static void QEMU_NORETURN pauth_trap(CPUARMState *env, int target_el, + uintptr_t ra) +{ + CPUState *cs = ENV_GET_CPU(env); + + cs->exception_index = EXCP_UDEF; + env->exception.syndrome = syn_pactrap(); + env->exception.target_el = target_el; + cpu_loop_exit_restore(cs, ra); +} + +static void pauth_check_trap(CPUARMState *env, int el, uintptr_t ra) +{ + if (el < 2 && arm_feature(env, ARM_FEATURE_EL2)) { + uint64_t hcr = arm_hcr_el2_eff(env); + bool trap = !(hcr & HCR_API); + /* FIXME: ARMv8.1-VHE: trap only applies to EL1&0 regime. */ + /* FIXME: ARMv8.3-NV: HCR_NV trap takes precedence for ERETA[AB]. */ + if (trap) { + pauth_trap(env, 2, ra); + } + } + if (el < 3 && arm_feature(env, ARM_FEATURE_EL3)) { + if (!(env->cp15.scr_el3 & SCR_API)) { + pauth_trap(env, 3, ra); + } + } +} + +static bool pauth_key_enabled(CPUARMState *env, int el, uint32_t bit) +{ + uint32_t sctlr; + if (el == 0) { + /* FIXME: ARMv8.1-VHE S2 translation regime. */ + sctlr = env->cp15.sctlr_el[1]; + } else { + sctlr = env->cp15.sctlr_el[el]; + } + return (sctlr & bit) != 0; +} + +uint64_t HELPER(pacia)(CPUARMState *env, uint64_t x, uint64_t y) +{ + int el = arm_current_el(env); + if (!pauth_key_enabled(env, el, SCTLR_EnIA)) { + return x; + } + pauth_check_trap(env, el, GETPC()); + return pauth_addpac(env, x, y, &env->apia_key, false); +} + +uint64_t HELPER(pacib)(CPUARMState *env, uint64_t x, uint64_t y) +{ + int el = arm_current_el(env); + if (!pauth_key_enabled(env, el, SCTLR_EnIB)) { + return x; + } + pauth_check_trap(env, el, GETPC()); + return pauth_addpac(env, x, y, &env->apib_key, false); +} + +uint64_t HELPER(pacda)(CPUARMState *env, uint64_t x, uint64_t y) +{ + int el = arm_current_el(env); + if (!pauth_key_enabled(env, el, SCTLR_EnDA)) { + return x; + } + pauth_check_trap(env, el, GETPC()); + return pauth_addpac(env, x, y, &env->apda_key, true); +} + +uint64_t HELPER(pacdb)(CPUARMState *env, uint64_t x, uint64_t y) +{ + int el = arm_current_el(env); + if (!pauth_key_enabled(env, el, SCTLR_EnDB)) { + return x; + } + pauth_check_trap(env, el, GETPC()); + return pauth_addpac(env, x, y, &env->apdb_key, true); +} + +uint64_t HELPER(pacga)(CPUARMState *env, uint64_t x, uint64_t y) +{ + uint64_t pac; + + pauth_check_trap(env, arm_current_el(env), GETPC()); + pac = pauth_computepac(x, y, env->apga_key); + + return pac & 0xffffffff00000000ull; +} + +uint64_t HELPER(autia)(CPUARMState *env, uint64_t x, uint64_t y) +{ + int el = arm_current_el(env); + if (!pauth_key_enabled(env, el, SCTLR_EnIA)) { + return x; + } + pauth_check_trap(env, el, GETPC()); + return pauth_auth(env, x, y, &env->apia_key, false, 0); +} + +uint64_t HELPER(autib)(CPUARMState *env, uint64_t x, uint64_t y) +{ + int el = arm_current_el(env); + if (!pauth_key_enabled(env, el, SCTLR_EnIB)) { + return x; + } + pauth_check_trap(env, el, GETPC()); + return pauth_auth(env, x, y, &env->apib_key, false, 1); +} + +uint64_t HELPER(autda)(CPUARMState *env, uint64_t x, uint64_t y) +{ + int el = arm_current_el(env); + if (!pauth_key_enabled(env, el, SCTLR_EnDA)) { + return x; + } + pauth_check_trap(env, el, GETPC()); + return pauth_auth(env, x, y, &env->apda_key, true, 0); +} + +uint64_t HELPER(autdb)(CPUARMState *env, uint64_t x, uint64_t y) +{ + int el = arm_current_el(env); + if (!pauth_key_enabled(env, el, SCTLR_EnDB)) { + return x; + } + pauth_check_trap(env, el, GETPC()); + return pauth_auth(env, x, y, &env->apdb_key, true, 1); +} + +uint64_t HELPER(xpaci)(CPUARMState *env, uint64_t a) +{ + return pauth_strip(env, a, false); +} + +uint64_t HELPER(xpacd)(CPUARMState *env, uint64_t a) +{ + return pauth_strip(env, a, true); +}