From patchwork Tue Aug 22 04:25:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 715671 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp69359wrp; Mon, 21 Aug 2023 21:26:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpKdX4YlKS+vTBHYoORtgzclg1qQSW9m63bdNxwM+RT1HoQtMlA8RzBTLxyohIBiCx3hOr X-Received: by 2002:ac8:5fd3:0:b0:3fb:42cb:aa9 with SMTP id k19-20020ac85fd3000000b003fb42cb0aa9mr12039036qta.45.1692678417028; Mon, 21 Aug 2023 21:26:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692678417; cv=none; d=google.com; s=arc-20160816; b=N/82qgD1eN3woRPaWjw8VcoOPams7WB82zZXri4VhDtY6huVseNVqR/SfjL26j/KHT SLR9FXHo5e3O/QRr+nxugyHIeT+zoM8MRkAcxNZpmgXnkGyGtZQCMHxTLVic4LAEDR02 LMyreiQmvhHEiRKv8xtummYuKG+QXtjpDR9AgCzDakOx7knO4sC3Q+nA9NSmIQkUfdyh xYJJdGlqZZb8MKvdhw7eazxnnBxOXptGq1k6VOUFxEAqkHIil2sDRDYySPZR5CeyW+AG TN6P4aI5QgXHe8wK/FtdGlILdP1pD+ayDYqqxlfvQgwZ0KrmbEkn+Oo6zCkegOpYU9MZ BK7A== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Tz0aWUu/vHl+1ntPEUMfK/rYoMDJR4BjrdL+Cy/mdVs=; fh=lg8/ckKb61gDlKZ2NmTq/Hk94gXqE66TCPFK/Ovz1LA=; b=c6Ob98ICJE3UBNDUUcQ49gJtA2SAZFmnBZJwEAZjYi4Q0KefhBXcLWO9ZvV4QHDymO JZFSZrcUCLnnjj91JcxMCFzBiLRKZVsZ5SiFZsgsgNColw/ZOs2cIE7LbfIP7rFWZsE/ Li1nZ/+NcW5HS1XgwMVQHDbtaB22IaENllsVXChkAT6NpfcvolHNrMVS69Th3LYrIAYk kbCZg2FNHDiIhe7L1Qp06W6rEX8dktRcp+kbm7PgkAB0yCcAiZpMOR5uz1yoPCHOPqft DZB0QLlIWYCJC21hcdETDVPozwt1MXZAGqdhCDKtaA4IGeYuf+PdqjQF4G05GIjRx86x cbSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gsTvcKb7; 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=pass (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 g12-20020ac87d0c000000b004109d20c07dsi1735247qtb.499.2023.08.21.21.26.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Aug 2023 21:26:57 -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=pass header.i=@linaro.org header.s=google header.b=gsTvcKb7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYIxe-0006PI-KJ; Tue, 22 Aug 2023 00:25:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYIxd-0006N0-8G for qemu-devel@nongnu.org; Tue, 22 Aug 2023 00:25:45 -0400 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYIxX-0007XX-Bz for qemu-devel@nongnu.org; Tue, 22 Aug 2023 00:25:44 -0400 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3a8506f5b73so1707731b6e.0 for ; Mon, 21 Aug 2023 21:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692678338; x=1693283138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Tz0aWUu/vHl+1ntPEUMfK/rYoMDJR4BjrdL+Cy/mdVs=; b=gsTvcKb7tj6IyaLYI0joiqIh8GG+BQZN5WTHB6Mjb6N+Uboh8scCxj6UkhQenyUlMS cKdB4kaopQCLoWtgZLp7GityYwmhbTrvyUwd5y+cMJUi4ud//1p3bJF1HwFDDd11CT46 sQZOzWh9t977dJTz6trxXn9tQNcK12MJ0udJ+J6d8WemrG/qGUkLYnXasg3VUKhTsFTn hnmFIzeBg1tgVMoyL+X/EJv7C7XlNIuOchArmlLoD4bgu3fYBsSBSI0s+UqdU0+ogG2l DbjbOUZc954EmqlsZbps1PgNvS6F0AXVM2g9Vr8VQ54EUzDWxS7tNqpDY+MW0KVHyiQF GjPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692678338; x=1693283138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Tz0aWUu/vHl+1ntPEUMfK/rYoMDJR4BjrdL+Cy/mdVs=; b=P5XuRTv4mHmr76lNL0nlbdypGC65jTHgIlyUa35wem8zCw1b5512FDLf6SJYpaHl1m T/JRoCdVMIi+qTyI6kbLDnUPlF2DX+zD3x+GbIwVztNbhQ8kmhE3y6AfMg7gGzs67QlH lee24snDocWntUYqfYxIZU5AobgCv6jWQ//Z+Szf5go3xWa1S1+uu/hTow3JsGIy4KR5 Kko+Nuwfbs/kZCq3Q0W1KOclx6j+HWZYvpUBcvTPowKd1K7rzUA3xBczCTgY6xDKx9pF 8wp+O5RyJ2hJ9HD4554YsDmtEU225AzZo/K6rj9Gt21BEbQekGUhAmFE0JG3ts74gjUO R2KA== X-Gm-Message-State: AOJu0YyK/s2UstjiUvOPEyKdi/vQNTiyracKwXu9y5niZf2jtl2lHw37 5TwW76mrLkp5iJkz3PnA0YAAm948/s7n0Fv0SrY= X-Received: by 2002:a05:6808:1b0b:b0:3a8:5904:1aa8 with SMTP id bx11-20020a0568081b0b00b003a859041aa8mr6570206oib.52.1692678337949; Mon, 21 Aug 2023 21:25:37 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:2c08:e710:4459:46f1]) by smtp.gmail.com with ESMTPSA id m14-20020aa7900e000000b0068a3f861b24sm3364908pfo.195.2023.08.21.21.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Aug 2023 21:25:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Aaron Lindsay , Peter Maydell Subject: [PATCH v4 7/9] target/arm: Implement FEAT_Pauth2 Date: Mon, 21 Aug 2023 21:25:28 -0700 Message-Id: <20230822042530.1026751-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230822042530.1026751-1-richard.henderson@linaro.org> References: <20230822042530.1026751-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22d; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 From: Aaron Lindsay Signed-off-by: Aaron Lindsay Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson Message-Id: <20230609172324.982888-6-aaron@os.amperecomputing.com> Signed-off-by: Richard Henderson --- docs/system/arm/emulation.rst | 1 + target/arm/tcg/cpu64.c | 2 +- target/arm/tcg/pauth_helper.c | 21 +++++++++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst index 4866a73ca0..54234ac090 100644 --- a/docs/system/arm/emulation.rst +++ b/docs/system/arm/emulation.rst @@ -63,6 +63,7 @@ the following architecture extensions: - FEAT_PAN2 (AT S1E1R and AT S1E1W instruction variants affected by PSTATE.PAN) - FEAT_PAN3 (Support for SCTLR_ELx.EPAN) - FEAT_PAuth (Pointer authentication) +- FEAT_PAuth2 (Enhacements to pointer authentication) - FEAT_PMULL (PMULL, PMULL2 instructions) - FEAT_PMUv3p1 (PMU Extensions v3.1) - FEAT_PMUv3p4 (PMU Extensions v3.4) diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c index 85bf94ee40..d3be14137e 100644 --- a/target/arm/tcg/cpu64.c +++ b/target/arm/tcg/cpu64.c @@ -758,7 +758,7 @@ void aarch64_max_tcg_initfn(Object *obj) t = cpu->isar.id_aa64isar1; t = FIELD_DP64(t, ID_AA64ISAR1, DPB, 2); /* FEAT_DPB2 */ - t = FIELD_DP64(t, ID_AA64ISAR1, APA, PauthFeat_EPAC); + t = FIELD_DP64(t, ID_AA64ISAR1, APA, PauthFeat_2); t = FIELD_DP64(t, ID_AA64ISAR1, API, 1); t = FIELD_DP64(t, ID_AA64ISAR1, JSCVT, 1); /* FEAT_JSCVT */ t = FIELD_DP64(t, ID_AA64ISAR1, FCMA, 1); /* FEAT_FCMA */ diff --git a/target/arm/tcg/pauth_helper.c b/target/arm/tcg/pauth_helper.c index 63e1009ea7..b6aeb90548 100644 --- a/target/arm/tcg/pauth_helper.c +++ b/target/arm/tcg/pauth_helper.c @@ -353,7 +353,9 @@ static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modifier, */ test = sextract64(ptr, bot_bit, top_bit - bot_bit); if (test != 0 && test != -1) { - if (pauth_feature == PauthFeat_EPAC) { + if (pauth_feature >= PauthFeat_2) { + /* No action required */ + } else if (pauth_feature == PauthFeat_EPAC) { pac = 0; } else { /* @@ -368,6 +370,9 @@ static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modifier, * Preserve the determination between upper and lower at bit 55, * and insert pointer authentication code. */ + if (pauth_feature >= PauthFeat_2) { + pac ^= ptr; + } if (param.tbi) { ptr &= ~MAKE_64BIT_MASK(bot_bit, 55 - bot_bit + 1); pac &= MAKE_64BIT_MASK(bot_bit, 54 - bot_bit + 1); @@ -394,18 +399,26 @@ static uint64_t pauth_original_ptr(uint64_t ptr, ARMVAParameters param) static uint64_t pauth_auth(CPUARMState *env, uint64_t ptr, uint64_t modifier, ARMPACKey *key, bool data, int keynumber) { + ARMCPU *cpu = env_archcpu(env); ARMMMUIdx mmu_idx = arm_stage1_mmu_idx(env); ARMVAParameters param = aa64_va_parameters(env, ptr, mmu_idx, data, false); + ARMPauthFeature pauth_feature = cpu_isar_feature(pauth_feature, cpu); int bot_bit, top_bit; - uint64_t pac, orig_ptr, test; + uint64_t pac, orig_ptr, cmp_mask; orig_ptr = pauth_original_ptr(ptr, param); pac = pauth_computepac(env, orig_ptr, modifier, *key); bot_bit = 64 - param.tsz; top_bit = 64 - 8 * param.tbi; - test = (pac ^ ptr) & ~MAKE_64BIT_MASK(55, 1); - if (unlikely(extract64(test, bot_bit, top_bit - bot_bit))) { + cmp_mask = MAKE_64BIT_MASK(bot_bit, top_bit - bot_bit); + cmp_mask &= ~MAKE_64BIT_MASK(55, 1); + + if (pauth_feature >= PauthFeat_2) { + return ptr ^ (pac & cmp_mask); + } + + if ((pac ^ ptr) & cmp_mask) { int error_code = (keynumber << 1) | (keynumber ^ 1); if (param.tbi) { return deposit64(orig_ptr, 53, 2, error_code);