From nobody Tue May 14 14:23:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1693351784; cv=none; d=zohomail.com; s=zohoarc; b=LVlhpvN0F5A2S1k3OFahkM51Ni0bD3iwlwwMi9an0GU/xU1wBiTUNBp0BtepxsObsgrCHymW7kX+0YdkgHVF6jTC513l8uPnMf83MHOYNW8Neg/1nFMzMDTDQ6HdNPOC+8a6QKAw8o/WcnSCCnTudgFvf2JoT5UA7iqz/uXu0Jg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693351784; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GOQxCV2ZeNNpKDkyg+BAXzxnOS5aPcNG/SXJ9WibMEs=; b=FO0cdzpsn7K2lXrEIvUEv463NBhD6n1zydMwlQU07xtSAA/1/knt+JMUDaPlIhijo8U3+jVES3TXOnCKGXoPd8s9jduFRItFmltl+ZsS8VJBgBxCgN0zyyvz5LJGfSyFtFVE7P0ecKGd8cE9DNG90AxnB9G6OkB9Uch4k2nJVv4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693351784221338.79101963329686; Tue, 29 Aug 2023 16:29:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb83n-0003Mt-2L; Tue, 29 Aug 2023 19:23:47 -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 1qb83k-00035T-K3 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:44 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb83f-0001Ls-Gx for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:44 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-68a4bcf8a97so3226329b3a.1 for ; Tue, 29 Aug 2023 16:23:39 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id t9-20020a170902e84900b001b9dadf8bd2sm9829970plg.190.2023.08.29.16.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 16:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693351418; x=1693956218; darn=nongnu.org; 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=GOQxCV2ZeNNpKDkyg+BAXzxnOS5aPcNG/SXJ9WibMEs=; b=y4WCu8KIwponZSD6lMaiZw81ljVaXROBXBJD26OHL/SracIS+zrYw/7UBFygAL4TtD iHDv1f8aJKepPLzBmbWRzDPy5gcgwTTt3Xo3PCfKLGnPpLTVhUpMD21kSbLqenHpAFxb rvVe7HcNAl9eyFZbKH7qj2NYtfvEB8Jh4lUil0+gH+JNBVIBSTaX+AAZAvycQwfFN/E2 DXiPXu0BbeuuZLpq+m0RwXwnzcyGpf9eNHzZlhy8gfd2Mm2Oh3XW/wDcPpimOJpppW2N 9OCyomXY437Ohk/hQO/aAs2tPn+fhkyJdd4vwtC0NbIsTiiurR9rtOieBKH8YEdMzwYm fzcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693351418; x=1693956218; 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=GOQxCV2ZeNNpKDkyg+BAXzxnOS5aPcNG/SXJ9WibMEs=; b=HTq49fy692DVRqxUZCoXb8CSnAjg13heKZC7QlHbL7MG5B10tGMVJ8cDQIbEMcsGby SrDGVYEs9lmTRsKrKC76Y1QHxnmQL0kqxJ/ANb03E/oQpP3QjMQLy/Puw+9o67HMDNr2 8O87ptpzwQ0veEuZSarPtLiK0n40s3RHdS2KHzAsFIk0yYelzdbfbQ0780egEN0IEB8C W/VT9Arc0H7AdExwek3NPpYSDe5+FDe+GwNb9H9HewtKYevmyiKUs9FOWhJg5ZEr/Tzg 3g+Ujtl+lwds7ZkMQ+RRxKmZXJznEeiqBx1AJGGz00hKG85adau7bfVzq9gXxdrf2VO+ Da/w== X-Gm-Message-State: AOJu0YyIXuj3SePwIfAr/7BjAPnLvi8QhkTNAKx6QVqiH6lwhoLJRVcy +d8BkMkgABoVQeDOFNah8GqyHULjje925Vujibo= X-Google-Smtp-Source: AGHT+IEraxh0BSW/LBYOXbzF+cEkOKlWrhXo68qK+XIJL8ZVxg1xvYAm9MuQ+lCXMN4PRuu8wMqPcw== X-Received: by 2002:a05:6a20:3954:b0:137:e595:830f with SMTP id r20-20020a056a20395400b00137e595830fmr876263pzg.57.1693351418016; Tue, 29 Aug 2023 16:23:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: aaron@os.amperecomputing.com, qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v5 01/12] tests/tcg/aarch64: Adjust pauth tests for FEAT_FPAC Date: Tue, 29 Aug 2023 16:23:24 -0700 Message-Id: <20230829232335.965414-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829232335.965414-1-richard.henderson@linaro.org> References: <20230829232335.965414-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1693351785226100003 Content-Type: text/plain; charset="utf-8" With FEAT_FPAC, AUT* instructions that fail authentication do not produce an error value but instead fault. For pauth-2, install a signal handler and verify it gets called. For pauth-4 and pauth-5, we are explicitly testing the error value, so there's nothing to test with FEAT_FPAC, so exit early. Adjust the makefile to use -cpu neoverse-v1, which has FEAT_EPAC but not FEAT_FPAC. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- tests/tcg/aarch64/pauth.h | 23 +++++++++++++ tests/tcg/aarch64/pauth-2.c | 54 ++++++++++++++++++++++++++----- tests/tcg/aarch64/pauth-4.c | 18 ++++++++--- tests/tcg/aarch64/pauth-5.c | 10 ++++++ tests/tcg/aarch64/Makefile.target | 6 +++- 5 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 tests/tcg/aarch64/pauth.h diff --git a/tests/tcg/aarch64/pauth.h b/tests/tcg/aarch64/pauth.h new file mode 100644 index 0000000000..543b234437 --- /dev/null +++ b/tests/tcg/aarch64/pauth.h @@ -0,0 +1,23 @@ +/* + * Helper for pauth test case + * + * Copyright (c) 2023 Linaro Ltd + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include + +static int get_pac_feature(void) +{ + unsigned long isar1, isar2; + + assert(getauxval(AT_HWCAP) & HWCAP_CPUID); + + asm("mrs %0, id_aa64isar1_el1" : "=3Dr"(isar1)); + asm("mrs %0, S3_0_C0_C6_2" : "=3Dr"(isar2)); /* id_aa64isar2_el1 */ + + return ((isar1 >> 4) & 0xf) /* APA */ + | ((isar1 >> 8) & 0xf) /* API */ + | ((isar2 >> 12) & 0xf); /* APA3 */ +} diff --git a/tests/tcg/aarch64/pauth-2.c b/tests/tcg/aarch64/pauth-2.c index 978652ede3..89ffdbf1df 100644 --- a/tests/tcg/aarch64/pauth-2.c +++ b/tests/tcg/aarch64/pauth-2.c @@ -1,5 +1,22 @@ #include +#include +#include #include +#include "pauth.h" + + +static void sigill(int sig, siginfo_t *info, void *vuc) +{ + ucontext_t *uc =3D vuc; + uint64_t test; + + /* There is only one insn below that is allowed to fault. */ + asm volatile("adr %0, auth2_insn" : "=3Dr"(test)); + assert(test =3D=3D uc->uc_mcontext.pc); + exit(0); +} + +static int pac_feature; =20 void do_test(uint64_t value) { @@ -27,31 +44,52 @@ void do_test(uint64_t value) * An invalid salt usually fails authorization, but again there * is a chance of choosing another salt that works. * Iterate until we find another salt which does fail. + * + * With FEAT_FPAC, this will SIGILL instead of producing a result. */ for (salt2 =3D salt1 + 1; ; salt2++) { - asm volatile("autda %0, %2" : "=3Dr"(decode) : "0"(encode), "r"(sa= lt2)); + asm volatile("auth2_insn: autda %0, %2" + : "=3Dr"(decode) : "0"(encode), "r"(salt2)); if (decode !=3D value) { break; } } =20 + assert(pac_feature < 4); /* No FEAT_FPAC */ + /* The VA bits, bit 55, and the TBI bits, should be unchanged. */ assert(((decode ^ value) & 0xff80ffffffffffffull) =3D=3D 0); =20 /* - * Bits [54:53] are an error indicator based on the key used; - * the DA key above is keynumber 0, so error =3D=3D 0b01. Otherwise - * bit 55 of the original is sign-extended into the rest of the auth. + * Without FEAT_Pauth2, bits [54:53] are an error indicator based on + * the key used; the DA key above is keynumber 0, so error =3D=3D 0b01. + * Otherwise, bit 55 of the original is sign-extended into the rest + * of the auth. */ - if ((value >> 55) & 1) { - assert(((decode >> 48) & 0xff) =3D=3D 0b10111111); - } else { - assert(((decode >> 48) & 0xff) =3D=3D 0b00100000); + if (pac_feature < 3) { + if ((value >> 55) & 1) { + assert(((decode >> 48) & 0xff) =3D=3D 0b10111111); + } else { + assert(((decode >> 48) & 0xff) =3D=3D 0b00100000); + } } } =20 int main() { + static const struct sigaction sa =3D { + .sa_sigaction =3D sigill, + .sa_flags =3D SA_SIGINFO + }; + + pac_feature =3D get_pac_feature(); + assert(pac_feature !=3D 0); + + if (pac_feature >=3D 4) { + /* FEAT_FPAC */ + sigaction(SIGILL, &sa, NULL); + } + do_test(0); do_test(0xda004acedeadbeefull); return 0; diff --git a/tests/tcg/aarch64/pauth-4.c b/tests/tcg/aarch64/pauth-4.c index 24a639e36c..b254f413af 100644 --- a/tests/tcg/aarch64/pauth-4.c +++ b/tests/tcg/aarch64/pauth-4.c @@ -2,14 +2,24 @@ #include #include #include +#include "pauth.h" =20 #define TESTS 1000 =20 int main() { + char base[TESTS]; int i, count =3D 0; float perc; - void *base =3D malloc(TESTS); + int pac_feature =3D get_pac_feature(); + + /* + * Exit if no PAuth or FEAT_FPAC, which will SIGILL on AUTIA failure + * rather than return an error for us to check below. + */ + if (pac_feature =3D=3D 0 || pac_feature >=3D 4) { + return 0; + } =20 for (i =3D 0; i < TESTS; i++) { uintptr_t in, x, y; @@ -17,7 +27,7 @@ int main() in =3D i + (uintptr_t) base; =20 asm("mov %0, %[in]\n\t" - "pacia %0, sp\n\t" /* sigill if pauth not supported */ + "pacia %0, sp\n\t" "eor %0, %0, #4\n\t" /* corrupt single bit */ "mov %1, %0\n\t" "autia %1, sp\n\t" /* validate corrupted pointer */ @@ -36,10 +46,10 @@ int main() if (x !=3D y) { count++; } - } + perc =3D (float) count / (float) TESTS; - printf("Checks Passed: %0.2f%%", perc * 100.0); + printf("Checks Passed: %0.2f%%\n", perc * 100.0); assert(perc > 0.95); return 0; } diff --git a/tests/tcg/aarch64/pauth-5.c b/tests/tcg/aarch64/pauth-5.c index 67c257918b..ed8d5a926b 100644 --- a/tests/tcg/aarch64/pauth-5.c +++ b/tests/tcg/aarch64/pauth-5.c @@ -1,4 +1,5 @@ #include +#include "pauth.h" =20 static int x; =20 @@ -6,6 +7,15 @@ int main() { int *p0 =3D &x, *p1, *p2, *p3; unsigned long salt =3D 0; + int pac_feature =3D get_pac_feature(); + + /* + * Exit if no PAuth or FEAT_FPAC, which will SIGILL on AUTDA failure + * rather than return an error for us to check below. + */ + if (pac_feature =3D=3D 0 || pac_feature >=3D 4) { + return 0; + } =20 /* * With TBI enabled and a 48-bit VA, there are 7 bits of auth, and so diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile= .target index 681dfa077c..1ee6309920 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -42,7 +42,11 @@ endif ifneq ($(CROSS_CC_HAS_ARMV8_3),) AARCH64_TESTS +=3D pauth-1 pauth-2 pauth-4 pauth-5 pauth-%: CFLAGS +=3D -march=3Darmv8.3-a -run-pauth-%: QEMU_OPTS +=3D -cpu max +run-pauth-1: QEMU_OPTS +=3D -cpu max +run-pauth-2: QEMU_OPTS +=3D -cpu max +# Choose a cpu with FEAT_Pauth but without FEAT_FPAC for pauth-[45]. +run-pauth-4: QEMU_OPTS +=3D -cpu neoverse-v1 +run-pauth-5: QEMU_OPTS +=3D -cpu neoverse-v1 endif =20 # BTI Tests --=20 2.34.1 From nobody Tue May 14 14:23:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1693351437; cv=none; d=zohomail.com; s=zohoarc; b=hluDMM4IdfD3qPPMdVuw9hZuIqeHdvUr4m6vUaGoVjh9N04VUGg5yXNf+yrF0/PU7INwji01qo7eFOlwakrOuo4d/+4lx5DsddODvzJOROQIzlp+z8ZJR8s+TwwLue2c5YQ8nhS4zflG6iyRh/BNUU3QHsDdOv2/e8Dowji5n5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693351437; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KJs9VdlYYhcs1M3WHRYBXtRa+lFbPejqKMvTmE5WpOE=; b=LGvXRjMw+qU/+1l83ZUPvhm+nT16TAe8JQUaxSep00BsJgaU3cI8xrpJQcyDArDYWR8N3ByLwcDjqD+KWyGH80eNMkINgieXEv01/dxVdltW7n3l4J/hmSwRq8LNJ/d35U+sC+nVOacA1aQ2EARCIYMN++kaCBPIs0vTO3EMU7E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693351437212984.3432409612836; Tue, 29 Aug 2023 16:23:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb83m-0003LL-U0; Tue, 29 Aug 2023 19:23: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 1qb83l-0003A1-0u for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:45 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb83g-0001M4-RP for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:44 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68a56401b9aso3641426b3a.1 for ; Tue, 29 Aug 2023 16:23:40 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id t9-20020a170902e84900b001b9dadf8bd2sm9829970plg.190.2023.08.29.16.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 16:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693351419; x=1693956219; darn=nongnu.org; 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=KJs9VdlYYhcs1M3WHRYBXtRa+lFbPejqKMvTmE5WpOE=; b=TQfY7WDBlbIvrNCsrBydTFY9cUvHxviWv8/O0IA/CJ2EJTh35GRfAJStIV0CLxkUKR lRFMaqu3V3dnnmpZBVDVYW1uwVJ/icTiW5YX8PJeSN0qioTnLE0MX/A43BzGR+7ABLXM tmxqb7iL7QXEDNjKhZ1/HeF6oGVil3iHitOyNbpBUs/aziWMFhKMg/SNOgVhPyo/U5fQ kIFaUoqQNndUy1ooYSSraAbM4UDnWKXQCDGXAcJuE89LKvvXFkIbNri5g2pVIMx3bJ4A JI3vdjYuBwxiWtQwg5iAuqjaFf6+tHFgZhfSV4fIdVSRQQQ5y7YWujtuEhr3rrfNeaJC zR0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693351419; x=1693956219; 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=KJs9VdlYYhcs1M3WHRYBXtRa+lFbPejqKMvTmE5WpOE=; b=JSJBlolmB7E5snoNMoEUJz6MG5AoNntvd4Lvl0MZNUA3RsU5bWEoVvBLlgzc8JKeAY CstC5uXDDXWNr2WBfp4DOtKVuG7TJr8gO08vWVdbLtwc662YOQjo2G8zIa7kqFAF8h/i TA9R6ow7Z0viZCFA9G76ZK/nuzcUQjgGVr80ojHAHgWnIXZAFQYkTAqD+89d0g7OKLbI 08o1kYN80CYyQBPQadxQOdBGGwOPoDS431nhjTc1ufugp+JzvVD/VGDE9Khaw4SSVTUK xeRO7BZ4c5KdVnsCAe8D1WaTdiJx1CCoaknEcqSsItgEXgaCyryO2DREqwfTOI//ZaDg C/Dw== X-Gm-Message-State: AOJu0Yzbve5vviIrFM5z834EE8UdWPDzPcHCjpXuY9lBfI3H95+FxQXY CM0xCEEhYQYH9RIXsr9DQ/ZbvCXnDF07ez6UHXo= X-Google-Smtp-Source: AGHT+IEK9iEz4JBxRJXEUvuaFVcrAj6l4IKTy77vsTCkl/CuOMUGadl4hKS1QszR8uHIWuPeGznwwg== X-Received: by 2002:a05:6a20:d422:b0:13d:2f80:cf1c with SMTP id il34-20020a056a20d42200b0013d2f80cf1cmr747623pzb.17.1693351419039; Tue, 29 Aug 2023 16:23:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: aaron@os.amperecomputing.com, qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell Subject: [PATCH v5 02/12] target/arm: Add ID_AA64ISAR2_EL1 Date: Tue, 29 Aug 2023 16:23:25 -0700 Message-Id: <20230829232335.965414-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829232335.965414-1-richard.henderson@linaro.org> References: <20230829232335.965414-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1693351439107100001 From: Aaron Lindsay Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Signed-off-by: Aaron Lindsay [PMM: drop the HVF part of the patch and just comment that we need to do something when the register appears in that API] Signed-off-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 1 + target/arm/helper.c | 4 ++-- target/arm/hvf/hvf.c | 1 + target/arm/kvm64.c | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index cdf8600b96..4a5a5e9eb8 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1033,6 +1033,7 @@ struct ArchCPU { uint32_t dbgdevid1; uint64_t id_aa64isar0; uint64_t id_aa64isar1; + uint64_t id_aa64isar2; uint64_t id_aa64pfr0; uint64_t id_aa64pfr1; uint64_t id_aa64mmfr0; diff --git a/target/arm/helper.c b/target/arm/helper.c index 85291d5b8e..b5be68be58 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -8439,11 +8439,11 @@ void register_cp_regs_for_features(ARMCPU *cpu) .access =3D PL1_R, .type =3D ARM_CP_CONST, .accessfn =3D access_aa64_tid3, .resetvalue =3D cpu->isar.id_aa64isar1 }, - { .name =3D "ID_AA64ISAR2_EL1_RESERVED", .state =3D ARM_CP_STA= TE_AA64, + { .name =3D "ID_AA64ISAR2_EL1", .state =3D ARM_CP_STATE_AA64, .opc0 =3D 3, .opc1 =3D 0, .crn =3D 0, .crm =3D 6, .opc2 =3D = 2, .access =3D PL1_R, .type =3D ARM_CP_CONST, .accessfn =3D access_aa64_tid3, - .resetvalue =3D 0 }, + .resetvalue =3D cpu->isar.id_aa64isar2 }, { .name =3D "ID_AA64ISAR3_EL1_RESERVED", .state =3D ARM_CP_STA= TE_AA64, .opc0 =3D 3, .opc1 =3D 0, .crn =3D 0, .crm =3D 6, .opc2 =3D = 3, .access =3D PL1_R, .type =3D ARM_CP_CONST, diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c index 486f90be1d..546c0e817f 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -847,6 +847,7 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFea= tures *ahcf) { HV_SYS_REG_ID_AA64DFR1_EL1, &host_isar.id_aa64dfr1 }, { HV_SYS_REG_ID_AA64ISAR0_EL1, &host_isar.id_aa64isar0 }, { HV_SYS_REG_ID_AA64ISAR1_EL1, &host_isar.id_aa64isar1 }, + /* Add ID_AA64ISAR2_EL1 here when HVF supports it */ { HV_SYS_REG_ID_AA64MMFR0_EL1, &host_isar.id_aa64mmfr0 }, { HV_SYS_REG_ID_AA64MMFR1_EL1, &host_isar.id_aa64mmfr1 }, { HV_SYS_REG_ID_AA64MMFR2_EL1, &host_isar.id_aa64mmfr2 }, diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index 4d904a1d11..ac440c33f9 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -304,6 +304,8 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *= ahcf) ARM64_SYS_REG(3, 0, 0, 6, 0)); err |=3D read_sys_reg64(fdarray[2], &ahcf->isar.id_aa64isar1, ARM64_SYS_REG(3, 0, 0, 6, 1)); + err |=3D read_sys_reg64(fdarray[2], &ahcf->isar.id_aa64isar2, + ARM64_SYS_REG(3, 0, 0, 6, 2)); err |=3D read_sys_reg64(fdarray[2], &ahcf->isar.id_aa64mmfr0, ARM64_SYS_REG(3, 0, 0, 7, 0)); err |=3D read_sys_reg64(fdarray[2], &ahcf->isar.id_aa64mmfr1, --=20 2.34.1 From nobody Tue May 14 14:23:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1693351564; cv=none; d=zohomail.com; s=zohoarc; b=UAhasj5FnfHiAEm2SDe0SvUt5mnGmIsnBk5DHXzsIGSEiP7UjSepJn5vG+oZRcbLyyNfsHY853eDc/mtVlZibUmC8O9Mj2Nfo4JXSUH4nHX1gYPty4ojNGx11F04SNbN7i8HAGzm+ifrK8jqvsHCU6YCochVQUonSv/nPRE2agU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693351564; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Hb9dMZIAxrLN24ygvHA9pXLZxd+STyR5WIcVAOZOt3k=; b=dCqbZJY/4hMj82+ZxqzT/0AAgLpKVWdRRcOgOyc3hXB2aHAHbj8ybZkW4F1yAUWystLHDd1KeexnGnPPGHLEJkexI6ePeI5O1tqU9GJGgACujvePeKUGBurScAA5FgbdCRVfvkWOQ2bpjux+Eh45Mf+mrKJd3mxTavtaT5rxYKM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693351564729198.59901521045265; Tue, 29 Aug 2023 16:26:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb83p-0003iF-Jb; Tue, 29 Aug 2023 19:23:49 -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 1qb83m-0003KV-Ft for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:46 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb83h-0001MD-Px for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:46 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bdbf10333bso39077355ad.1 for ; Tue, 29 Aug 2023 16:23:41 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id t9-20020a170902e84900b001b9dadf8bd2sm9829970plg.190.2023.08.29.16.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 16:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693351420; x=1693956220; darn=nongnu.org; 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=Hb9dMZIAxrLN24ygvHA9pXLZxd+STyR5WIcVAOZOt3k=; b=NJ2aySW5dDJ8u3pIIxwpMHZXyjcXe5FJhvqBhqZd2tUFfoq5FXmiJTYewJ+cLK50Yy X5WtkkTCtxxy2H0BCqXwwYyGFq8IHzU+GPvJ9z75YILeferAPoAbqvTR/0yh9ddPHKwC +DVvgUVX9L175qwh9JCoNxoUs4a/vHMs+nh+ItNEalpuaVblDq38tLTrdE77wwWlLlUa +eTLzSp3LFuDQslhmjH2j62ASCtUzhssMJybrN398W8yzTa1ZHNIZQ+2gO6ZbCblL1WK v6xlSBwhyO2G8JRENGRocICvGOvjmlU4wryqdN7wdR2LXtigGyQ/nrQdplQmR97eLct/ g31w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693351420; x=1693956220; 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=Hb9dMZIAxrLN24ygvHA9pXLZxd+STyR5WIcVAOZOt3k=; b=fYJqyWdb+MSgYxo4pCpZ2mFIFmAtdOPk9MOMFU54GPXVrr5k8ID5FKiec0eng78wRF mid2JYfpjKZ/1JaQR2nZTguz4hiqX4dOIIj16+cmjIhx1fA//r+V4/RDnen03+pzeU0y EQwfrpcFCN/IPARd80gGpeicUi6q4VWWelWRmsxtFTE0VdE+BmcInv4fTjmWsfPxndjO 56dH5udEZzzgIjMiNeXqMZO6JYYB85AC0zZOkgPY+oymrP3TFC/gWyNrgy8LmO7dc5fZ Po595KJIEv3I4q4nGeJTo+HFGdG7jIM3ohCUsmFeG9wED4/m91uJFegR0hxC1/bTZOAX S54w== X-Gm-Message-State: AOJu0YxJ0M0z9DVDGsEZDGww92YLBQhBNYCOlqSplRfHoTjpDGs8mbZW rcgs/RK5X2bie57YFsoLJ7W8fh7ZWz5C/j33veM= X-Google-Smtp-Source: AGHT+IGdyWMQ0SsHRPpDFNdO0X/FPoZCq6JFmGQhs48NQXPwSSqX0K5l31vasxnb5DayMz4vMykKGQ== X-Received: by 2002:a17:902:684c:b0:1c0:9abb:4873 with SMTP id f12-20020a170902684c00b001c09abb4873mr503273pln.64.1693351420134; Tue, 29 Aug 2023 16:23:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: aaron@os.amperecomputing.com, qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v5 03/12] target/arm: Add feature detection for FEAT_Pauth2 and extensions Date: Tue, 29 Aug 2023 16:23:26 -0700 Message-Id: <20230829232335.965414-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829232335.965414-1-richard.henderson@linaro.org> References: <20230829232335.965414-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1693351566430100003 Content-Type: text/plain; charset="utf-8" From: Aaron Lindsay Rename isar_feature_aa64_pauth_arch to isar_feature_aa64_pauth_qarma5 to distinguish the other architectural algorithm qarma3. Add ARMPauthFeature and isar_feature_pauth_feature to cover the other pauth conditions. Reviewed-by: Peter Maydell Signed-off-by: Aaron Lindsay Message-Id: <20230609172324.982888-3-aaron@os.amperecomputing.com> [rth: Add ARMPauthFeature and eliminate most other predicates] Signed-off-by: Richard Henderson --- target/arm/cpu.h | 47 +++++++++++++++++++++++++++++------ target/arm/tcg/pauth_helper.c | 2 +- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 4a5a5e9eb8..0e2545d631 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3801,28 +3801,59 @@ static inline bool isar_feature_aa64_fcma(const ARM= ISARegisters *id) return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, FCMA) !=3D 0; } =20 +/* + * These are the values from APA/API/APA3. + * In general these must be compared '>=3D', per the normal Arm ARM + * treatment of fields in ID registers. + */ +typedef enum { + PauthFeat_None =3D 0, + PauthFeat_1 =3D 1, + PauthFeat_EPAC =3D 2, + PauthFeat_2 =3D 3, + PauthFeat_FPAC =3D 4, + PauthFeat_FPACCOMBINED =3D 5, +} ARMPauthFeature; + +static inline ARMPauthFeature +isar_feature_pauth_feature(const ARMISARegisters *id) +{ + /* + * Architecturally, only one of {APA,API,APA3} may be active (non-zero) + * and the other two must be zero. Thus we may avoid conditionals. + */ + return (FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, APA) | + FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, API) | + FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, APA3)); +} + static inline bool isar_feature_aa64_pauth(const ARMISARegisters *id) { /* * Return true if any form of pauth is enabled, as this * predicate controls migration of the 128-bit keys. */ - return (id->id_aa64isar1 & - (FIELD_DP64(0, ID_AA64ISAR1, APA, 0xf) | - FIELD_DP64(0, ID_AA64ISAR1, API, 0xf) | - FIELD_DP64(0, ID_AA64ISAR1, GPA, 0xf) | - FIELD_DP64(0, ID_AA64ISAR1, GPI, 0xf))) !=3D 0; + return isar_feature_pauth_feature(id) !=3D PauthFeat_None; } =20 -static inline bool isar_feature_aa64_pauth_arch(const ARMISARegisters *id) +static inline bool isar_feature_aa64_pauth_qarma5(const ARMISARegisters *i= d) { /* - * Return true if pauth is enabled with the architected QARMA algorith= m. - * QEMU will always set APA+GPA to the same value. + * Return true if pauth is enabled with the architected QARMA5 algorit= hm. + * QEMU will always enable or disable both APA and GPA. */ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, APA) !=3D 0; } =20 +static inline bool isar_feature_aa64_pauth_qarma3(const ARMISARegisters *i= d) +{ + /* + * Return true if pauth is enabled with the architected QARMA3 algorit= hm. + * QEMU will always enable or disable both APA3 and GPA3. + */ + return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, APA3) !=3D 0; +} + static inline bool isar_feature_aa64_tlbirange(const ARMISARegisters *id) { return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TLB) =3D=3D 2; diff --git a/target/arm/tcg/pauth_helper.c b/target/arm/tcg/pauth_helper.c index 62af569341..6271a84ec9 100644 --- a/target/arm/tcg/pauth_helper.c +++ b/target/arm/tcg/pauth_helper.c @@ -282,7 +282,7 @@ static uint64_t pauth_computepac_impdef(uint64_t data, = uint64_t modifier, static uint64_t pauth_computepac(CPUARMState *env, uint64_t data, uint64_t modifier, ARMPACKey key) { - if (cpu_isar_feature(aa64_pauth_arch, env_archcpu(env))) { + if (cpu_isar_feature(aa64_pauth_qarma5, env_archcpu(env))) { return pauth_computepac_architected(data, modifier, key); } else { return pauth_computepac_impdef(data, modifier, key); --=20 2.34.1 From nobody Tue May 14 14:23:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1693351550; cv=none; d=zohomail.com; s=zohoarc; b=LNG5cM2gihXUrFZYep0fsqv2VoJRRUndi9acbj+HV9xE9G9es2SJiwfdhA6SzADrhBu3g3i65OwK1GHAMHTD+IzIwHr4+T6yFLXQGwmvU21udlNdUBRHWXy0LNX2uT8tGgqdLgPi90q6iNSeICSmR18VNtrV0alpytsaEtIsNaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693351550; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=L7JWHxmJ23NmS8KMDWOHbcj7S88Z02RWmeeJJ7xEGx8=; b=AinOJdKNRHV6HZB8TWmz3QrkK+KWIuIrHGtCVVPMW8fqjzyFRp++CRGwJh1z+Nc0LZhGxtD3Gs+Bg6oMhztAmGFfs1v8O2YuDxdhU9UKkDqnOlExK6H4QJTMoefBgYQVlyru/rBgo87qNJOiRhUj8YFOGK6Am9tIqSolYb+J1M8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16933515501527.711021237595332; Tue, 29 Aug 2023 16:25:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb83p-0003kr-Sp; Tue, 29 Aug 2023 19:23:49 -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 1qb83m-0003MD-Sh for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:46 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb83i-0001MM-FD for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:46 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1bdf4752c3cso30682825ad.2 for ; Tue, 29 Aug 2023 16:23:41 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id t9-20020a170902e84900b001b9dadf8bd2sm9829970plg.190.2023.08.29.16.23.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 16:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693351421; x=1693956221; darn=nongnu.org; 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=L7JWHxmJ23NmS8KMDWOHbcj7S88Z02RWmeeJJ7xEGx8=; b=pmWZkM8YjkFeQ15aBt9RyaK0iaT1IBjp6PR8AZw0TqOcU+2Gqm6MEeykm1YK/Ax7X7 1d7v+fSfgb5kYns4ifz4Tly5RiIcF/fvRlUTb4gARerIiSRNaUI6Nj3dEc+/OEhDjfPz +1UsUwq4RD3Z8245YwUsD43aBkp2jqlncxde3YXP/tP5u65sCAJyn3cpEQicPcwC9iJ4 CxWWkiJjVjcb1CvrDgQxyZDhZQ4TGdQL65vjEzlk/xn8PgjtxareVmZV5rQcbMWLdRXS pW0e+BpoeiUX9pHcauZowWcMMTWwj2qCptlXYrZMayOIkoaFWv+z+uuQOQ+5dWWYLhWZ 9dvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693351421; x=1693956221; 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=L7JWHxmJ23NmS8KMDWOHbcj7S88Z02RWmeeJJ7xEGx8=; b=Yz9KNtbzF5TlPRpPRleGXbyHta+Mvi3908VbcivEKVs6xURKAdhVKb6Sk+cv3Zm8Yq iWZ+gKs2Ja9VFc3sAuRHvQ2PF5tzavDXcwUZQmvTmIgMYUL9N7mZylk179zDLzq5ZTlM uFt+lFiKxkNs7dPnEJMiRs9FbrpEHlAMLw/dEz8zBDhLYW4Xnfe5jKrcw2lM/NJBEwae lhmPtiQjKGigKZgBiMzWrfmNn9yjSiFxm4sBOboppji2sglJOVoHHhi3xIbI5MiKjHTn K8n9hA5/nmgFDRV0WzuTVsNTUpRmJhpv+rf+sKpHKBQeGk8GwvH44mSnEFO5HRxiorqK l/Qw== X-Gm-Message-State: AOJu0YwczkHJE5vaHTR+a+ehUXLOJtE+a6fwckNzcOG6R2dOpmp3HoeQ 5ay4Fb7C7G76vdD0y2qIZ1sVeTTo+XiRWcOeZhg= X-Google-Smtp-Source: AGHT+IFofvSYxHpXEuACd3CtDGUUTxwiploomMPI03V14ZZXmlq+xeQKXOsEkEfL35aT9/7G/dGYOQ== X-Received: by 2002:a17:903:4283:b0:1bf:78d:5cd9 with SMTP id ju3-20020a170903428300b001bf078d5cd9mr388453plb.67.1693351420955; Tue, 29 Aug 2023 16:23:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: aaron@os.amperecomputing.com, qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v5 04/12] target/arm: Don't change pauth features when changing algorithm Date: Tue, 29 Aug 2023 16:23:27 -0700 Message-Id: <20230829232335.965414-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829232335.965414-1-richard.henderson@linaro.org> References: <20230829232335.965414-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1693351551042100001 Content-Type: text/plain; charset="utf-8" We have cpu properties to adjust the pauth algorithm for the purpose of speed of emulation. Retain the set of pauth features supported by the cpu even as the algorithm changes. This already affects the neoverse-v1 cpu, which has FEAT_EPAC. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu64.c | 70 +++++++++++++++++++++++++++--------------- target/arm/tcg/cpu64.c | 2 ++ 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 96158093cc..fd584a31da 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -473,37 +473,57 @@ void aarch64_add_sme_properties(Object *obj) =20 void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp) { - int arch_val =3D 0, impdef_val =3D 0; - uint64_t t; + ARMPauthFeature features =3D cpu_isar_feature(pauth_feature, cpu); + uint64_t isar1; =20 - /* Exit early if PAuth is enabled, and fall through to disable it */ - if ((kvm_enabled() || hvf_enabled()) && cpu->prop_pauth) { - if (!cpu_isar_feature(aa64_pauth, cpu)) { - error_setg(errp, "'pauth' feature not supported by %s on this = host", - kvm_enabled() ? "KVM" : "hvf"); + /* + * These properties enable or disable Pauth as a whole, or change + * the pauth algorithm, but do not change the set of features that + * are present. We have saved a copy of those features above and + * will now place it into the field that chooses the algorithm. + * + * Begin by disabling all fields. + */ + isar1 =3D cpu->isar.id_aa64isar1; + isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, APA, 0); + isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, GPA, 0); + isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, API, 0); + isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, GPI, 0); + + if (kvm_enabled() || hvf_enabled()) { + /* + * Exit early if PAuth is enabled and fall through to disable it. + * The algorithm selection properties are not present. + */ + if (cpu->prop_pauth) { + if (features =3D=3D 0) { + error_setg(errp, "'pauth' feature not supported by " + "%s on this host", current_accel_name()); + } + return; + } + } else { + /* Pauth properties are only present when the model supports it. */ + if (features =3D=3D 0) { + assert(!cpu->prop_pauth); + return; } =20 - return; - } - - /* TODO: Handle HaveEnhancedPAC, HaveEnhancedPAC2, HaveFPAC. */ - if (cpu->prop_pauth) { - if (cpu->prop_pauth_impdef) { - impdef_val =3D 1; - } else { - arch_val =3D 1; + if (cpu->prop_pauth) { + if (cpu->prop_pauth_impdef) { + isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, API, features); + isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, GPI, 1); + } else { + isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, APA, features); + isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, GPA, 1); + } + } else if (cpu->prop_pauth_impdef) { + error_setg(errp, "cannot enable pauth-impdef without pauth"); + error_append_hint(errp, "Add pauth=3Don to the CPU property li= st.\n"); } - } else if (cpu->prop_pauth_impdef) { - error_setg(errp, "cannot enable pauth-impdef without pauth"); - error_append_hint(errp, "Add pauth=3Don to the CPU property list.\= n"); } =20 - t =3D cpu->isar.id_aa64isar1; - t =3D FIELD_DP64(t, ID_AA64ISAR1, APA, arch_val); - t =3D FIELD_DP64(t, ID_AA64ISAR1, GPA, arch_val); - t =3D FIELD_DP64(t, ID_AA64ISAR1, API, impdef_val); - t =3D FIELD_DP64(t, ID_AA64ISAR1, GPI, impdef_val); - cpu->isar.id_aa64isar1 =3D t; + cpu->isar.id_aa64isar1 =3D isar1; } =20 static Property arm_cpu_pauth_property =3D diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c index 8019f00bc3..fec6a4875d 100644 --- a/target/arm/tcg/cpu64.c +++ b/target/arm/tcg/cpu64.c @@ -758,6 +758,8 @@ void aarch64_max_tcg_initfn(Object *obj) =20 t =3D cpu->isar.id_aa64isar1; t =3D FIELD_DP64(t, ID_AA64ISAR1, DPB, 2); /* FEAT_DPB2 */ + t =3D FIELD_DP64(t, ID_AA64ISAR1, APA, PauthFeat_1); + t =3D FIELD_DP64(t, ID_AA64ISAR1, API, 1); t =3D FIELD_DP64(t, ID_AA64ISAR1, JSCVT, 1); /* FEAT_JSCVT */ t =3D FIELD_DP64(t, ID_AA64ISAR1, FCMA, 1); /* FEAT_FCMA */ t =3D FIELD_DP64(t, ID_AA64ISAR1, LRCPC, 2); /* FEAT_LRCPC2 */ --=20 2.34.1 From nobody Tue May 14 14:23:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1693351544; cv=none; d=zohomail.com; s=zohoarc; b=jx/OfdCV/milOzZ7oPdBqtzquS5cJeQIyi5nsUxu6okzZxd+evyhKoY7vpmTdJ2p4D7llvVFBGbBRslvvSzSeUgtP2ThYQMxaTLStENNcMiNL/Sq2k/YvOdCL8OCKbyoYHRkLcFEqAQmT0gYWcEhJltbJq2UUpGjfweVXSZctVM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693351544; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=J5PvsEisUhmViwuTX1kAnQipV1YYI3hKBjw90v7ICj0=; b=QDTRf55RrFBdwomSRhHDjJ6fLLpLT1/dY1E53es8ARqWyFyIO9Onu8qYF+cI3kKKLhFPtDayCGG4/tLL3V9knhzRHj8PxWsylaQhvmGPIpFt+7/r+rSyYHaRFmmhc07KovGp8eOgPFbhbLp1o/66rqGBhWsB+Hl1F/iDLdqIaHk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693351544643424.50015948523503; Tue, 29 Aug 2023 16:25:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb83q-0003oG-M8; Tue, 29 Aug 2023 19:23:50 -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 1qb83o-0003dp-T2 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:48 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb83j-0001Mh-55 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:48 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1bf57366ccdso2210695ad.1 for ; Tue, 29 Aug 2023 16:23:42 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id t9-20020a170902e84900b001b9dadf8bd2sm9829970plg.190.2023.08.29.16.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 16:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693351422; x=1693956222; darn=nongnu.org; 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=J5PvsEisUhmViwuTX1kAnQipV1YYI3hKBjw90v7ICj0=; b=gJw5cozjVpEviyGyfZfGykTLkXQfc2HTUmdKH1diieOEI3dRQ9JM8PwKBwTeZTDPvY GbS0G54VgiGzae2CM0U8T+oCc+QiPk7k3ZxWeetvOs7VTsMxuODu5KLF+zSruRAKhhlI XnczB5BZRhULibelN2nBdNsdgO9a9R+5Bqx/Vjsp75TC1iS/7L0CQ5sMjGsekn/XRIbY StpOC9u2R57dYiBC0r/SbXbzQHTWZUyVA0xXvuxoyu1u4UPe9b2CBUwJia8hcaDpbvG1 gP2uaLfYyzU262UW68EoCthc+dPKV+gn5sY0DPgy2nPHUT2NoyGNiuKOnReuSF38C2lo tVRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693351422; x=1693956222; 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=J5PvsEisUhmViwuTX1kAnQipV1YYI3hKBjw90v7ICj0=; b=fX+WXdpk+FlWIKJK3mZVKTFiEEtsDf7Z0LpKW7zqhJvIzrwMaUC+L70bpUAVhS3thh k3i4t3BIJ9u23zY44enKqvVBh48gSMU343w3dFPDHV5dbV8BjavLC8R3+6YxwCzxbxe7 1IIMovFYOYiNecZGmTfIt9u1+BhZHTdkjQnAIH+GtboLgSYxRFlSfrdJSEKNCB8nASGF Taeubj88nZqWpd+8Bx7/tFtUoJnkXgoK9VNR8vybyRjMGHX/F/Ea/BNrEha79UZwU1/a qMis554HbPjJDgDUNySHulzfh9H5JUGlvttrh964I5JBeOgU5NGL5s0S70pnf1skSzSR 8dnw== X-Gm-Message-State: AOJu0YziK9mtI2knA6IMVJWQNqaq8gRPopjgmyQxA5qYXyOXEihW23x+ Y855hIejr6LyAu2Pr+yAENPYs2t8xBKHTQhq+HE= X-Google-Smtp-Source: AGHT+IGUzOFo23vXQ+e0PPbFxHHLQySUiAA3VACsN3wkHdQ4Wj+jD6BlGRg9cJoQ8yUnlZfHbIkX2g== X-Received: by 2002:a17:902:c950:b0:1bd:e258:a256 with SMTP id i16-20020a170902c95000b001bde258a256mr1020157pla.32.1693351421791; Tue, 29 Aug 2023 16:23:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: aaron@os.amperecomputing.com, qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v5 05/12] target/arm: Implement FEAT_PACQARMA3 Date: Tue, 29 Aug 2023 16:23:28 -0700 Message-Id: <20230829232335.965414-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829232335.965414-1-richard.henderson@linaro.org> References: <20230829232335.965414-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1693351545089100001 Content-Type: text/plain; charset="utf-8" Implement the QARMA3 cryptographic algorithm for PAC calculation. Implement a cpu feature to select the algorithm and document it. Signed-off-by: Aaron Lindsay Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson Message-Id: <20230609172324.982888-4-aaron@os.amperecomputing.com> [rth: Merge cpu feature addition from another patch.] Signed-off-by: Richard Henderson --- docs/system/arm/cpu-features.rst | 21 ++++++++----- docs/system/arm/emulation.rst | 3 ++ target/arm/cpu.h | 1 + target/arm/arm-qmp-cmds.c | 2 +- target/arm/cpu64.c | 24 ++++++++++++-- target/arm/tcg/pauth_helper.c | 54 ++++++++++++++++++++++++++------ tests/qtest/arm-cpu-features.c | 12 ++++++- 7 files changed, 94 insertions(+), 23 deletions(-) diff --git a/docs/system/arm/cpu-features.rst b/docs/system/arm/cpu-feature= s.rst index 6bb88a40c7..a5fb929243 100644 --- a/docs/system/arm/cpu-features.rst +++ b/docs/system/arm/cpu-features.rst @@ -210,15 +210,20 @@ TCG VCPU Features TCG VCPU features are CPU features that are specific to TCG. Below is the list of TCG VCPU features and their descriptions. =20 -``pauth-impdef`` - When ``FEAT_Pauth`` is enabled, either the *impdef* (Implementation - Defined) algorithm is enabled or the *architected* QARMA algorithm - is enabled. By default the impdef algorithm is disabled, and QARMA - is enabled. +``pauth`` + Enable or disable ``FEAT_Pauth`` entirely. =20 - The architected QARMA algorithm has good cryptographic properties, - but can be quite slow to emulate. The impdef algorithm used by QEMU - is non-cryptographic but significantly faster. +``pauth-impdef`` + When ``pauth`` is enabled, select the QEMU implementation defined algori= thm. + +``pauth-qarma3`` + When ``pauth`` is enabled, select the architected QARMA3 algorithm. + +Without either ``pauth-impdef`` or ``pauth-qarma3`` enabled, +the architected QARMA5 algorithm is used. The architected QARMA5 +and QARMA3 algorithms have good cryptographic properties, but can +be quite slow to emulate. The impdef algorithm used by QEMU is +non-cryptographic but significantly faster. =20 SVE CPU Properties =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst index bdafc68819..06af20d10f 100644 --- a/docs/system/arm/emulation.rst +++ b/docs/system/arm/emulation.rst @@ -55,6 +55,9 @@ the following architecture extensions: - FEAT_MTE (Memory Tagging Extension) - FEAT_MTE2 (Memory Tagging Extension) - FEAT_MTE3 (MTE Asymmetric Fault Handling) +- FEAT_PACIMP (Pointer authentication - IMPLEMENTATION DEFINED algorithm) +- FEAT_PACQARMA3 (Pointer authentication - QARMA3 algorithm) +- FEAT_PACQARMA5 (Pointer authentication - QARMA5 algorithm) - FEAT_PAN (Privileged access never) - FEAT_PAN2 (AT S1E1R and AT S1E1W instruction variants affected by PSTATE= .PAN) - FEAT_PAN3 (Support for SCTLR_ELx.EPAN) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 0e2545d631..cfca42293a 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1072,6 +1072,7 @@ struct ArchCPU { */ bool prop_pauth; bool prop_pauth_impdef; + bool prop_pauth_qarma3; bool prop_lpa2; =20 /* DCZ blocksize, in log_2(words), ie low 4 bits of DCZID_EL0 */ diff --git a/target/arm/arm-qmp-cmds.c b/target/arm/arm-qmp-cmds.c index c8fa524002..b53d5efe13 100644 --- a/target/arm/arm-qmp-cmds.c +++ b/target/arm/arm-qmp-cmds.c @@ -95,7 +95,7 @@ static const char *cpu_model_advertised_features[] =3D { "sve640", "sve768", "sve896", "sve1024", "sve1152", "sve1280", "sve1408", "sve1536", "sve1664", "sve1792", "sve1920", "sve2048", "kvm-no-adjvtime", "kvm-steal-time", - "pauth", "pauth-impdef", + "pauth", "pauth-impdef", "pauth-qarma3", NULL }; =20 diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index fd584a31da..f3d87e001f 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -474,7 +474,7 @@ void aarch64_add_sme_properties(Object *obj) void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp) { ARMPauthFeature features =3D cpu_isar_feature(pauth_feature, cpu); - uint64_t isar1; + uint64_t isar1, isar2; =20 /* * These properties enable or disable Pauth as a whole, or change @@ -490,6 +490,10 @@ void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp) isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, API, 0); isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, GPI, 0); =20 + isar2 =3D cpu->isar.id_aa64isar2; + isar2 =3D FIELD_DP64(isar2, ID_AA64ISAR2, APA3, 0); + isar2 =3D FIELD_DP64(isar2, ID_AA64ISAR2, GPA3, 0); + if (kvm_enabled() || hvf_enabled()) { /* * Exit early if PAuth is enabled and fall through to disable it. @@ -510,26 +514,39 @@ void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp) } =20 if (cpu->prop_pauth) { + if (cpu->prop_pauth_impdef && cpu->prop_pauth_qarma3) { + error_setg(errp, + "cannot enable both pauth-impdef and pauth-qarm= a3"); + return; + } + if (cpu->prop_pauth_impdef) { isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, API, features); isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, GPI, 1); + } else if (cpu->prop_pauth_qarma3) { + isar2 =3D FIELD_DP64(isar2, ID_AA64ISAR2, APA3, features); + isar2 =3D FIELD_DP64(isar2, ID_AA64ISAR2, GPA3, 1); } else { isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, APA, features); isar1 =3D FIELD_DP64(isar1, ID_AA64ISAR1, GPA, 1); } - } else if (cpu->prop_pauth_impdef) { - error_setg(errp, "cannot enable pauth-impdef without pauth"); + } else if (cpu->prop_pauth_impdef || cpu->prop_pauth_qarma3) { + error_setg(errp, "cannot enable pauth-impdef or " + "pauth-qarma3 without pauth"); error_append_hint(errp, "Add pauth=3Don to the CPU property li= st.\n"); } } =20 cpu->isar.id_aa64isar1 =3D isar1; + cpu->isar.id_aa64isar2 =3D isar2; } =20 static Property arm_cpu_pauth_property =3D DEFINE_PROP_BOOL("pauth", ARMCPU, prop_pauth, true); static Property arm_cpu_pauth_impdef_property =3D DEFINE_PROP_BOOL("pauth-impdef", ARMCPU, prop_pauth_impdef, false); +static Property arm_cpu_pauth_qarma3_property =3D + DEFINE_PROP_BOOL("pauth-qarma3", ARMCPU, prop_pauth_qarma3, false); =20 void aarch64_add_pauth_properties(Object *obj) { @@ -549,6 +566,7 @@ void aarch64_add_pauth_properties(Object *obj) cpu->prop_pauth =3D cpu_isar_feature(aa64_pauth, cpu); } else { qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_impdef_proper= ty); + qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_qarma3_proper= ty); } } =20 diff --git a/target/arm/tcg/pauth_helper.c b/target/arm/tcg/pauth_helper.c index 6271a84ec9..bb03409ee5 100644 --- a/target/arm/tcg/pauth_helper.c +++ b/target/arm/tcg/pauth_helper.c @@ -96,6 +96,21 @@ static uint64_t pac_sub(uint64_t i) return o; } =20 +static uint64_t pac_sub1(uint64_t i) +{ + static const uint8_t sub1[16] =3D { + 0xa, 0xd, 0xe, 0x6, 0xf, 0x7, 0x3, 0x5, + 0x9, 0x8, 0x0, 0xc, 0xb, 0x1, 0x2, 0x4, + }; + uint64_t o =3D 0; + int b; + + for (b =3D 0; b < 64; b +=3D 4) { + o |=3D (uint64_t)sub1[(i >> b) & 0xf] << b; + } + return o; +} + static uint64_t pac_inv_sub(uint64_t i) { static const uint8_t inv_sub[16] =3D { @@ -209,7 +224,7 @@ static uint64_t tweak_inv_shuffle(uint64_t i) } =20 static uint64_t pauth_computepac_architected(uint64_t data, uint64_t modif= ier, - ARMPACKey key) + ARMPACKey key, bool isqarma3) { static const uint64_t RC[5] =3D { 0x0000000000000000ull, @@ -219,6 +234,7 @@ static uint64_t pauth_computepac_architected(uint64_t d= ata, uint64_t modifier, 0x452821E638D01377ull, }; const uint64_t alpha =3D 0xC0AC29B7C97C50DDull; + int iterations =3D isqarma3 ? 2 : 4; /* * Note that in the ARM pseudocode, key0 contains bits <127:64> * and key1 contains bits <63:0> of the 128-bit key. @@ -231,7 +247,7 @@ static uint64_t pauth_computepac_architected(uint64_t d= ata, uint64_t modifier, runningmod =3D modifier; workingval =3D data ^ key0; =20 - for (i =3D 0; i <=3D 4; ++i) { + for (i =3D 0; i <=3D iterations; ++i) { roundkey =3D key1 ^ runningmod; workingval ^=3D roundkey; workingval ^=3D RC[i]; @@ -239,32 +255,48 @@ static uint64_t pauth_computepac_architected(uint64_t= data, uint64_t modifier, workingval =3D pac_cell_shuffle(workingval); workingval =3D pac_mult(workingval); } - workingval =3D pac_sub(workingval); + if (isqarma3) { + workingval =3D pac_sub1(workingval); + } else { + workingval =3D pac_sub(workingval); + } runningmod =3D tweak_shuffle(runningmod); } roundkey =3D modk0 ^ runningmod; workingval ^=3D roundkey; workingval =3D pac_cell_shuffle(workingval); workingval =3D pac_mult(workingval); - workingval =3D pac_sub(workingval); + if (isqarma3) { + workingval =3D pac_sub1(workingval); + } else { + workingval =3D pac_sub(workingval); + } workingval =3D pac_cell_shuffle(workingval); workingval =3D pac_mult(workingval); workingval ^=3D key1; workingval =3D pac_cell_inv_shuffle(workingval); - workingval =3D pac_inv_sub(workingval); + if (isqarma3) { + workingval =3D pac_sub1(workingval); + } else { + workingval =3D pac_inv_sub(workingval); + } workingval =3D pac_mult(workingval); workingval =3D pac_cell_inv_shuffle(workingval); workingval ^=3D key0; workingval ^=3D runningmod; - for (i =3D 0; i <=3D 4; ++i) { - workingval =3D pac_inv_sub(workingval); - if (i < 4) { + for (i =3D 0; i <=3D iterations; ++i) { + if (isqarma3) { + workingval =3D pac_sub1(workingval); + } else { + workingval =3D pac_inv_sub(workingval); + } + if (i < iterations) { workingval =3D pac_mult(workingval); workingval =3D pac_cell_inv_shuffle(workingval); } runningmod =3D tweak_inv_shuffle(runningmod); roundkey =3D key1 ^ runningmod; - workingval ^=3D RC[4 - i]; + workingval ^=3D RC[iterations - i]; workingval ^=3D roundkey; workingval ^=3D alpha; } @@ -283,7 +315,9 @@ static uint64_t pauth_computepac(CPUARMState *env, uint= 64_t data, uint64_t modifier, ARMPACKey key) { if (cpu_isar_feature(aa64_pauth_qarma5, env_archcpu(env))) { - return pauth_computepac_architected(data, modifier, key); + return pauth_computepac_architected(data, modifier, key, false); + } else if (cpu_isar_feature(aa64_pauth_qarma3, env_archcpu(env))) { + return pauth_computepac_architected(data, modifier, key, true); } else { return pauth_computepac_impdef(data, modifier, key); } diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c index 3fc33fc24d..a8a4c668ad 100644 --- a/tests/qtest/arm-cpu-features.c +++ b/tests/qtest/arm-cpu-features.c @@ -417,12 +417,22 @@ static void pauth_tests_default(QTestState *qts, cons= t char *cpu_type) { assert_has_feature_enabled(qts, cpu_type, "pauth"); assert_has_feature_disabled(qts, cpu_type, "pauth-impdef"); + assert_has_feature_disabled(qts, cpu_type, "pauth-qarma3"); assert_set_feature(qts, cpu_type, "pauth", false); assert_set_feature(qts, cpu_type, "pauth", true); assert_set_feature(qts, cpu_type, "pauth-impdef", true); assert_set_feature(qts, cpu_type, "pauth-impdef", false); - assert_error(qts, cpu_type, "cannot enable pauth-impdef without pauth", + assert_set_feature(qts, cpu_type, "pauth-qarma3", true); + assert_set_feature(qts, cpu_type, "pauth-qarma3", false); + assert_error(qts, cpu_type, + "cannot enable pauth-impdef or pauth-qarma3 without pauth= ", "{ 'pauth': false, 'pauth-impdef': true }"); + assert_error(qts, cpu_type, + "cannot enable pauth-impdef or pauth-qarma3 without pauth= ", + "{ 'pauth': false, 'pauth-qarma3': true }"); + assert_error(qts, cpu_type, + "cannot enable both pauth-impdef and pauth-qarma3", + "{ 'pauth': true, 'pauth-impdef': true, 'pauth-qarma3': t= rue }"); } =20 static void test_query_cpu_model_expansion(const void *data) --=20 2.34.1 From nobody Tue May 14 14:23:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1693351808; cv=none; d=zohomail.com; s=zohoarc; b=FCWu+sRu6uNccsfdmdCfQKAFFFZkRRVwWWyqXGyO4XPDHpuEalL9asE3R/K9DISx5D+b3pByQ/4nYYYmr6X2tIbdE2NSr5fq5brwzJvPeuaTiyopjz13ZSGYTWCpbKMInSGSbsf6BImtf1rz70dHv806eWpqXzhbypsjwYqrkPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693351808; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dSHDOqmpvVqWZn7zJjJYDufm+wpdwBxF2KdyWkAtGiQ=; b=NdGt5fBHkb8fXQ55o7W5W9l1ZUxu7R/Opr+qdWIzjVUHAtgmiGdCJozgayLX1tdkB731OdjkmEvSsCgA0LjsxahJPJyrAb7UdYSeynZN8QIOX0i2xMWPLFyzH1oCJ03a5UUlPHO2vhpStJCneocVTCemXp2lAtVBl0m7BgSBYEA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693351808555354.5740212679584; Tue, 29 Aug 2023 16:30:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb83r-0003vm-VX; Tue, 29 Aug 2023 19:23:52 -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 1qb83p-0003fi-3t for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:49 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb83k-0001N1-9A for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:48 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-68bed286169so4261470b3a.1 for ; Tue, 29 Aug 2023 16:23:43 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id t9-20020a170902e84900b001b9dadf8bd2sm9829970plg.190.2023.08.29.16.23.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 16:23:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693351423; x=1693956223; darn=nongnu.org; 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=dSHDOqmpvVqWZn7zJjJYDufm+wpdwBxF2KdyWkAtGiQ=; b=RBXDMiCAbVEWOh24jzMgBq9SwBVpcHnOk3/ikUpgslogFgev87rbJIm9UFqTo99h+1 xI/c5F72Riu/P1YyUly9Vzy5UkBORtDJ3bp6J8I+1yNXvA/o3NnZb4KRLeIRk/UphrbX hW8zThsIEkc6sc7aDqZutKsJqxklxuA6SYQ8JQf/arAmCVrJX+vqql911fc9ankbDXbK 8zdktD6Tu9TqgbdmreLutguBDRk3MkIRvANfuXrx0ujcr36LqqgyvvqBJXgTgqLNUnyQ Upn2d4l51zR3aGhgD3fpPanjaCVMAC6SPsIY8O9IyCGlnYZogNQVicPLVmH1E2diqFrD aUxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693351423; x=1693956223; 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=dSHDOqmpvVqWZn7zJjJYDufm+wpdwBxF2KdyWkAtGiQ=; b=dikAqFaou1mgclySXlrATd0xmurlIUTedLix+h0lKssUOviXfCY7NG9yL/jcSNrwJ8 XvWHvFy4J68DR9VRC2Lntew/hzLJgyEs5IZiFKpwWQaUgYVc+zHX47X3suezLpPtGJQZ 0m++OT5B7jjrIJlgzbeVxx3ZhRw4OmSAd8wi4CIW/OHDLYKiz1Bb2ab0C886qyDfudvz TxKiqtWf7ypVZc1mLa2UuxtZVGRHljH6bXadjdTfj23esjrhsmw/BeSff/K3dGoeh/dK 6sz6HujeHBcFws7ul5Y2WVSZeDtibrrq49YHyAPM8c9xXJ+QfPWkg23sNzW+E65iwX8g Ejkg== X-Gm-Message-State: AOJu0YwBbuegMJuLqfC0Hvxru5+pqab9xClPw4FOVJMXplhpP11vfn7I Gjd0+hZp/7ds5L2h1KfkIsVnXggCIdWcXPEbGq8= X-Google-Smtp-Source: AGHT+IHO50E7tTBjS/eaarB7jCSxrsGpZlg4wQs/Z+sNtjmWIpeLSCNl0WBOd0g98vYXQlrmTM2mPw== X-Received: by 2002:a05:6a20:4c84:b0:148:d5d9:aaa9 with SMTP id fq4-20020a056a204c8400b00148d5d9aaa9mr554519pzb.33.1693351422849; Tue, 29 Aug 2023 16:23:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: aaron@os.amperecomputing.com, qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v5 06/12] target/arm: Implement FEAT_EPAC Date: Tue, 29 Aug 2023 16:23:29 -0700 Message-Id: <20230829232335.965414-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829232335.965414-1-richard.henderson@linaro.org> References: <20230829232335.965414-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1693351809354100005 Content-Type: text/plain; charset="utf-8" From: Aaron Lindsay Signed-off-by: Aaron Lindsay Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson Message-Id: <20230609172324.982888-5-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 | 16 +++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst index 06af20d10f..4866a73ca0 100644 --- a/docs/system/arm/emulation.rst +++ b/docs/system/arm/emulation.rst @@ -27,6 +27,7 @@ the following architecture extensions: - FEAT_DotProd (Advanced SIMD dot product instructions) - FEAT_DoubleFault (Double Fault Extension) - FEAT_E0PD (Preventing EL0 access to halves of address maps) +- FEAT_EPAC (Enhanced pointer authentication) - FEAT_ETS (Enhanced Translation Synchronization) - FEAT_EVT (Enhanced Virtualization Traps) - FEAT_FCMA (Floating-point complex number instructions) diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c index fec6a4875d..85bf94ee40 100644 --- a/target/arm/tcg/cpu64.c +++ b/target/arm/tcg/cpu64.c @@ -758,7 +758,7 @@ void aarch64_max_tcg_initfn(Object *obj) =20 t =3D cpu->isar.id_aa64isar1; t =3D FIELD_DP64(t, ID_AA64ISAR1, DPB, 2); /* FEAT_DPB2 */ - t =3D FIELD_DP64(t, ID_AA64ISAR1, APA, PauthFeat_1); + t =3D FIELD_DP64(t, ID_AA64ISAR1, APA, PauthFeat_EPAC); t =3D FIELD_DP64(t, ID_AA64ISAR1, API, 1); t =3D FIELD_DP64(t, ID_AA64ISAR1, JSCVT, 1); /* FEAT_JSCVT */ t =3D 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 bb03409ee5..63e1009ea7 100644 --- a/target/arm/tcg/pauth_helper.c +++ b/target/arm/tcg/pauth_helper.c @@ -326,8 +326,10 @@ static uint64_t pauth_computepac(CPUARMState *env, uin= t64_t data, static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modi= fier, ARMPACKey *key, bool data) { + ARMCPU *cpu =3D env_archcpu(env); ARMMMUIdx mmu_idx =3D arm_stage1_mmu_idx(env); ARMVAParameters param =3D aa64_va_parameters(env, ptr, mmu_idx, data, = false); + ARMPauthFeature pauth_feature =3D cpu_isar_feature(pauth_feature, cpu); uint64_t pac, ext_ptr, ext, test; int bot_bit, top_bit; =20 @@ -351,11 +353,15 @@ static uint64_t pauth_addpac(CPUARMState *env, uint64= _t ptr, uint64_t modifier, */ test =3D sextract64(ptr, bot_bit, top_bit - bot_bit); if (test !=3D 0 && test !=3D -1) { - /* - * Note that our top_bit is one greater than the pseudocode's - * version, hence "- 2" here. - */ - pac ^=3D MAKE_64BIT_MASK(top_bit - 2, 1); + if (pauth_feature =3D=3D PauthFeat_EPAC) { + pac =3D 0; + } else { + /* + * Note that our top_bit is one greater than the pseudocode's + * version, hence "- 2" here. + */ + pac ^=3D MAKE_64BIT_MASK(top_bit - 2, 1); + } } =20 /* --=20 2.34.1 From nobody Tue May 14 14:23:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1693351741; cv=none; d=zohomail.com; s=zohoarc; b=V7G+zPl7MaLMnDL+schZH5Rzo72uaAJumfLOUIwS8tT0b+NUQXx/rWva9TRHGTFcd2Mdo2Ee49uAlU51nUDnHH7WZXmJkCEcNeygqz8R1Yvpvv46OKUmMqTqnuUNZaFA0ciJozUINDIy+afG2Jh2U9tw/pUlW0ECEuoktBhdvsQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693351741; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Tz0aWUu/vHl+1ntPEUMfK/rYoMDJR4BjrdL+Cy/mdVs=; b=hhS6QlgJ6E1Z4tw5LtuPNQeXHb3tStdiIMfRu/5m+xiTKZ31QIfxz1hHSCer4z/dAgW9YXGHk3RTiv/V3ltrXCgGhgZPySs7M/9/9BK5CRn5NKQZyx7Atzm/b0GiL5HmL3vscMZIWMGjGqNMnfleNq0x7KQ8+F8qb51CxzBATkQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693351741652133.44429216425317; Tue, 29 Aug 2023 16:29:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb83r-0003x1-VK; Tue, 29 Aug 2023 19:23:52 -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 1qb83q-0003ly-4n for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:50 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb83l-0001NL-3W for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:49 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1c1e3a4a06fso17052885ad.3 for ; Tue, 29 Aug 2023 16:23:44 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id t9-20020a170902e84900b001b9dadf8bd2sm9829970plg.190.2023.08.29.16.23.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 16:23:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693351423; x=1693956223; darn=nongnu.org; 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=m6n/TpIpbBGNBQuAUKMsHJ23fngCD5iKz2R34+H/gyI8U3PL6yS67MHbC4P/Yy42zf hfuEfuV+o8Y+ekBQLOndgbb6i4puKzsRv9gD8iAcoSF5n1fm6bXr7VN8EO6XJY84UEFW PBMbpty6vScIR284vl7AkzGz4NdxbK/sQTXtAkvDrTgECzBzbjBbL5UkoaiJmgvxoaRn mEl1E2avZwPBgwqwq8HWExlcYhDC3vZ4YRlWMKFF0mM00R9hG4mT/YO0HrTxQguQ10AN bGHCJvFOstoq3cRdQvmoTWS+NDT6JU9Hya7JYofzMxgheSouT2Qdv0eWz2yl24yQqUti NQCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693351423; x=1693956223; 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=hQOXQgP2nAQJJBDKGwr0ELVr5Tb914pVLaA0v8nYzUzDUgQLWsPt2tQe9Pu7yvlUQA X9h/aFxNh6iIcm7v9y/qBuKNhf4U38i46OO0is/ZgdRNktShPFxhvUaHm3yq9CFig+C6 z+sM1Pxu/NukrZqAR0qKNQ13zMe3SY8meRnnEy1HHwn9I6sM4TENWDp3ii6y2cUZDfwL p/L1Euz1U/y4J+VnFaiUeERKBOh+VRQJlqRWlj2iztpHXgMqvs24s1Wlj1TaKa524Xdr JSWYKlzEV4LhZfEoFKkEdv5z5WLfrfVdAagTukMrweCibmj0UrQZp8FtNw9PEMFDqZK+ 1u1Q== X-Gm-Message-State: AOJu0Yy3+xc0Uo4v+Z9S7+83PTPAEV3Ehly8d5mU1tLuOmJKhFGaFVWP 5bz7hKZlOuDKufXMNRjUMP7tdKWDyNnDR4uZXRo= X-Google-Smtp-Source: AGHT+IHq1sgHi+ieZCXn8DM5++QiXiy25GX9ppO0+JVZ0SP/6MgAz9CzUa/uY908bbakJZIJnheQ7A== X-Received: by 2002:a17:903:11d1:b0:1b8:78e:7c1 with SMTP id q17-20020a17090311d100b001b8078e07c1mr585119plh.51.1693351423715; Tue, 29 Aug 2023 16:23:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: aaron@os.amperecomputing.com, qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v5 07/12] target/arm: Implement FEAT_Pauth2 Date: Tue, 29 Aug 2023 16:23:30 -0700 Message-Id: <20230829232335.965414-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829232335.965414-1-richard.henderson@linaro.org> References: <20230829232335.965414-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1693351742262100001 Content-Type: text/plain; charset="utf-8" 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) =20 t =3D cpu->isar.id_aa64isar1; t =3D FIELD_DP64(t, ID_AA64ISAR1, DPB, 2); /* FEAT_DPB2 */ - t =3D FIELD_DP64(t, ID_AA64ISAR1, APA, PauthFeat_EPAC); + t =3D FIELD_DP64(t, ID_AA64ISAR1, APA, PauthFeat_2); t =3D FIELD_DP64(t, ID_AA64ISAR1, API, 1); t =3D FIELD_DP64(t, ID_AA64ISAR1, JSCVT, 1); /* FEAT_JSCVT */ t =3D 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 =3D sextract64(ptr, bot_bit, top_bit - bot_bit); if (test !=3D 0 && test !=3D -1) { - if (pauth_feature =3D=3D PauthFeat_EPAC) { + if (pauth_feature >=3D PauthFeat_2) { + /* No action required */ + } else if (pauth_feature =3D=3D PauthFeat_EPAC) { pac =3D 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 >=3D PauthFeat_2) { + pac ^=3D ptr; + } if (param.tbi) { ptr &=3D ~MAKE_64BIT_MASK(bot_bit, 55 - bot_bit + 1); pac &=3D MAKE_64BIT_MASK(bot_bit, 54 - bot_bit + 1); @@ -394,18 +399,26 @@ static uint64_t pauth_original_ptr(uint64_t ptr, ARMV= AParameters param) static uint64_t pauth_auth(CPUARMState *env, uint64_t ptr, uint64_t modifi= er, ARMPACKey *key, bool data, int keynumber) { + ARMCPU *cpu =3D env_archcpu(env); ARMMMUIdx mmu_idx =3D arm_stage1_mmu_idx(env); ARMVAParameters param =3D aa64_va_parameters(env, ptr, mmu_idx, data, = false); + ARMPauthFeature pauth_feature =3D cpu_isar_feature(pauth_feature, cpu); int bot_bit, top_bit; - uint64_t pac, orig_ptr, test; + uint64_t pac, orig_ptr, cmp_mask; =20 orig_ptr =3D pauth_original_ptr(ptr, param); pac =3D pauth_computepac(env, orig_ptr, modifier, *key); bot_bit =3D 64 - param.tsz; top_bit =3D 64 - 8 * param.tbi; =20 - test =3D (pac ^ ptr) & ~MAKE_64BIT_MASK(55, 1); - if (unlikely(extract64(test, bot_bit, top_bit - bot_bit))) { + cmp_mask =3D MAKE_64BIT_MASK(bot_bit, top_bit - bot_bit); + cmp_mask &=3D ~MAKE_64BIT_MASK(55, 1); + + if (pauth_feature >=3D PauthFeat_2) { + return ptr ^ (pac & cmp_mask); + } + + if ((pac ^ ptr) & cmp_mask) { int error_code =3D (keynumber << 1) | (keynumber ^ 1); if (param.tbi) { return deposit64(orig_ptr, 53, 2, error_code); --=20 2.34.1 From nobody Tue May 14 14:23:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1693351655; cv=none; d=zohomail.com; s=zohoarc; b=LGo9Z8HY37pWTmW+WULl1BShKdQkdOZ7F3R6kaPZn1zC5Ql83yOXEXLsNoK/RjXQJ9V2qz8SKA/e3d2/a66fF+6VyuTQ9qBOsWJklFlRwnniF/esNi1/8EsPo2Js/zqz8KIe36E9LGvlXNR0+FTiI/KLYNrxj4wkEkKrpGFrGwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693351655; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GBMbwJtbWJINLG/Bi+3dEW8o9qtvntfSHtdu/TS63ec=; b=dcv49bae8ndK2rGB/EAHPdzyrO2W2F9fbmpE+qPWl8HX4QSQ87uMBJ3VkGian/qwJHpo8TWw49jYU7ZcQHwEqHRFgpywNMT7LC4Di7WnmGtT3J3AA5CMc3LxUUS/lA5fmT1QkT9ApVGV8NybzXFbV2jpYwqUMB5OxssKjMQxH+Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693351655428342.46383778222173; Tue, 29 Aug 2023 16:27:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb83u-0004Ki-V4; Tue, 29 Aug 2023 19:23:54 -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 1qb83r-0003s5-Cl for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:51 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb83l-0001Np-Rz for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:51 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1c09673b006so26288145ad.1 for ; Tue, 29 Aug 2023 16:23:45 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id t9-20020a170902e84900b001b9dadf8bd2sm9829970plg.190.2023.08.29.16.23.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 16:23:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693351424; x=1693956224; darn=nongnu.org; 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=GBMbwJtbWJINLG/Bi+3dEW8o9qtvntfSHtdu/TS63ec=; b=L5REHIAGXj+TQFb1hHVUlwUVL0b+XHMvPHQSsRTfgHOqYyzKflogOgn3oay9iMgJxA f3Pf2uUU6N4aqRFp2qi1xP+LnSWMGR4YNuiZ2vCX8xcFHQkb8P/SNI/Wr+BQTrM1EGR6 vNu6slT09bxQ16Ot3SVCTUu0ktFtLxpuqKvuUIeEXz3Ud4IV6EfFgzL+tEqqiQvgxUEI pXvi09vx6pzqfKtd0KBKchFtozWL2k+E+bkyZPx5UcGye2EnzK58go2LSHfmH6+fUB3E wBoJ9jLYsbAtWNTMyVFWRN0hlLaKSPNmGDjRrVn/RT310je2EEnO3mzrXkJey9DBy2S7 tsDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693351424; x=1693956224; 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=GBMbwJtbWJINLG/Bi+3dEW8o9qtvntfSHtdu/TS63ec=; b=PXh4dEoMWH3MSS1XQ/Z31bjTvFpI/WdtL7M5tZqWaWRlCwdGVj4QWlhfhg9zeqlVHT IWzFL5JKnoCqq9EH6Zg9aBh/oY7U7v8ZtODldtsYWHsDs1B+GthzarcMbl8vVlFoznq0 iwJdzrirmiCIZnqw6xkX1WFAs50iZQ5FXhdabacBTjzrA4ttsRmsegCkIMnkVO9ql51q ZAWKHSGnNJQRcsrdMIWzogWiGMfufVLM/TKTW4p1+lLT8hrFfbMYf/mZJcDVOJ93WbCN lNTIa/0ks3hqq367to2BP3xWsjNnsVxKi4TmReydTzBTRqog6N50Ffktq5/TYO8xJlX6 fHVQ== X-Gm-Message-State: AOJu0YzSY3S7R8L6P8OEVwGSpDuwLEhcuEooFeZt+wYyAAJR9TK+F7lm QFhn6RcM2wJRqzdrObFqDr+9C/HB5Z//NhAoBP0= X-Google-Smtp-Source: AGHT+IEV5NFdxM4cHLoXR22TbD8RN5twczHuD4OrWOlmMbtYwnYG6euQyR3zAZRPoDmBMI4ythxe0Q== X-Received: by 2002:a17:902:d48e:b0:1b8:6cae:4400 with SMTP id c14-20020a170902d48e00b001b86cae4400mr635988plg.37.1693351424504; Tue, 29 Aug 2023 16:23:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: aaron@os.amperecomputing.com, qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 08/12] targer/arm: Inform helpers whether a PAC instruction is 'combined' Date: Tue, 29 Aug 2023 16:23:31 -0700 Message-Id: <20230829232335.965414-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829232335.965414-1-richard.henderson@linaro.org> References: <20230829232335.965414-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1693351656846100003 From: Aaron Lindsay An instruction is a 'combined' Pointer Authentication instruction if it does something in addition to PAC -- for instance, branching to or loading an address from the authenticated pointer. Knowing whether a PAC operation is 'combined' is needed to implement FEAT_FPACCOMBINE. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Aaron Lindsay Reviewed-by: Richard Henderson Message-Id: <20230609172324.982888-7-aaron@os.amperecomputing.com> Signed-off-by: Richard Henderson --- target/arm/tcg/helper-a64.h | 4 ++ target/arm/tcg/pauth_helper.c | 71 +++++++++++++++++++++++++++------- target/arm/tcg/translate-a64.c | 12 +++--- 3 files changed, 68 insertions(+), 19 deletions(-) diff --git a/target/arm/tcg/helper-a64.h b/target/arm/tcg/helper-a64.h index 3d5957c11f..57cfd68569 100644 --- a/target/arm/tcg/helper-a64.h +++ b/target/arm/tcg/helper-a64.h @@ -90,9 +90,13 @@ 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(autia_combined, 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(autib_combined, 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(autda_combined, TCG_CALL_NO_WG, i64, env, i64, i64) DEF_HELPER_FLAGS_3(autdb, TCG_CALL_NO_WG, i64, env, i64, i64) +DEF_HELPER_FLAGS_3(autdb_combined, 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) =20 diff --git a/target/arm/tcg/pauth_helper.c b/target/arm/tcg/pauth_helper.c index b6aeb90548..c05c5b30ff 100644 --- a/target/arm/tcg/pauth_helper.c +++ b/target/arm/tcg/pauth_helper.c @@ -397,7 +397,8 @@ static uint64_t pauth_original_ptr(uint64_t ptr, ARMVAP= arameters param) } =20 static uint64_t pauth_auth(CPUARMState *env, uint64_t ptr, uint64_t modifi= er, - ARMPACKey *key, bool data, int keynumber) + ARMPACKey *key, bool data, int keynumber, + uintptr_t ra, bool is_combined) { ARMCPU *cpu =3D env_archcpu(env); ARMMMUIdx mmu_idx =3D arm_stage1_mmu_idx(env); @@ -519,44 +520,88 @@ uint64_t HELPER(pacga)(CPUARMState *env, uint64_t x, = uint64_t y) return pac & 0xffffffff00000000ull; } =20 -uint64_t HELPER(autia)(CPUARMState *env, uint64_t x, uint64_t y) +static uint64_t pauth_autia(CPUARMState *env, uint64_t x, uint64_t y, + uintptr_t ra, bool is_combined) { int el =3D 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->keys.apia, false, 0); + pauth_check_trap(env, el, ra); + return pauth_auth(env, x, y, &env->keys.apia, false, 0, ra, is_combine= d); } =20 -uint64_t HELPER(autib)(CPUARMState *env, uint64_t x, uint64_t y) +uint64_t HELPER(autia)(CPUARMState *env, uint64_t x, uint64_t y) +{ + return pauth_autia(env, x, y, GETPC(), false); +} + +uint64_t HELPER(autia_combined)(CPUARMState *env, uint64_t x, uint64_t y) +{ + return pauth_autia(env, x, y, GETPC(), true); +} + +static uint64_t pauth_autib(CPUARMState *env, uint64_t x, uint64_t y, + uintptr_t ra, bool is_combined) { int el =3D 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->keys.apib, false, 1); + pauth_check_trap(env, el, ra); + return pauth_auth(env, x, y, &env->keys.apib, false, 1, ra, is_combine= d); } =20 -uint64_t HELPER(autda)(CPUARMState *env, uint64_t x, uint64_t y) +uint64_t HELPER(autib)(CPUARMState *env, uint64_t x, uint64_t y) +{ + return pauth_autib(env, x, y, GETPC(), false); +} + +uint64_t HELPER(autib_combined)(CPUARMState *env, uint64_t x, uint64_t y) +{ + return pauth_autib(env, x, y, GETPC(), true); +} + +static uint64_t pauth_autda(CPUARMState *env, uint64_t x, uint64_t y, + uintptr_t ra, bool is_combined) { int el =3D 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->keys.apda, true, 0); + pauth_check_trap(env, el, ra); + return pauth_auth(env, x, y, &env->keys.apda, true, 0, ra, is_combined= ); } =20 -uint64_t HELPER(autdb)(CPUARMState *env, uint64_t x, uint64_t y) +uint64_t HELPER(autda)(CPUARMState *env, uint64_t x, uint64_t y) +{ + return pauth_autda(env, x, y, GETPC(), false); +} + +uint64_t HELPER(autda_combined)(CPUARMState *env, uint64_t x, uint64_t y) +{ + return pauth_autda(env, x, y, GETPC(), true); +} + +static uint64_t pauth_autdb(CPUARMState *env, uint64_t x, uint64_t y, + uintptr_t ra, bool is_combined) { int el =3D 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->keys.apdb, true, 1); + pauth_check_trap(env, el, ra); + return pauth_auth(env, x, y, &env->keys.apdb, true, 1, ra, is_combined= ); +} + +uint64_t HELPER(autdb)(CPUARMState *env, uint64_t x, uint64_t y) +{ + return pauth_autdb(env, x, y, GETPC(), false); +} + +uint64_t HELPER(autdb_combined)(CPUARMState *env, uint64_t x, uint64_t y) +{ + return pauth_autdb(env, x, y, GETPC(), true); } =20 uint64_t HELPER(xpaci)(CPUARMState *env, uint64_t a) diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c index da686cc953..eab3beef06 100644 --- a/target/arm/tcg/translate-a64.c +++ b/target/arm/tcg/translate-a64.c @@ -1530,9 +1530,9 @@ static TCGv_i64 auth_branch_target(DisasContext *s, T= CGv_i64 dst, =20 truedst =3D tcg_temp_new_i64(); if (use_key_a) { - gen_helper_autia(truedst, cpu_env, dst, modifier); + gen_helper_autia_combined(truedst, cpu_env, dst, modifier); } else { - gen_helper_autib(truedst, cpu_env, dst, modifier); + gen_helper_autib_combined(truedst, cpu_env, dst, modifier); } return truedst; } @@ -3352,11 +3352,11 @@ static bool trans_LDRA(DisasContext *s, arg_LDRA *a) =20 if (s->pauth_active) { if (!a->m) { - gen_helper_autda(dirty_addr, cpu_env, dirty_addr, - tcg_constant_i64(0)); + gen_helper_autda_combined(dirty_addr, cpu_env, dirty_addr, + tcg_constant_i64(0)); } else { - gen_helper_autdb(dirty_addr, cpu_env, dirty_addr, - tcg_constant_i64(0)); + gen_helper_autdb_combined(dirty_addr, cpu_env, dirty_addr, + tcg_constant_i64(0)); } } =20 --=20 2.34.1 From nobody Tue May 14 14:23:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1693351683; cv=none; d=zohomail.com; s=zohoarc; b=Gi+yYIoygW9UfbAzJJV/+Oak6Y7MQKJOaJUyDw2FmQBboqPJr1tqteaZcM58tde5B4524e+/9GPgCDL2BWXFifq+FvQMpuBfqQEZEc5xcYOGMjnlfS9XuTbv5rr7sJflfSq53iNOxkazaTzw0Hf68KHYHCh4TmscJ8ntoqZdKlg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693351683; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QYRPHwHql4RJiTHPJiRJM3r+k6GdWisA6scz9yo7XuE=; b=LS12g8iLMZeedVyMDKtnI1sc3X1+PGQB1TFWPFKqjAbN5N1id4csQgIz6iBoG8fysG+rH4imQ7+UK9YKUHflPwlC4a0CDjFrdokcn3wdir8MLZo6Q5tadF7wdQ+MclJYm0q608Ht6Vela2FHF83SSiL8t6R5S6UH58Fx726dFJs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693351683532850.3638223415535; Tue, 29 Aug 2023 16:28:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb83w-0004Vp-DJ; Tue, 29 Aug 2023 19:23:56 -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 1qb83s-00041L-AP for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:52 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb83m-0001O2-L4 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:52 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1bdbf10333bso39077755ad.1 for ; Tue, 29 Aug 2023 16:23:46 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id t9-20020a170902e84900b001b9dadf8bd2sm9829970plg.190.2023.08.29.16.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 16:23:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693351425; x=1693956225; darn=nongnu.org; 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=QYRPHwHql4RJiTHPJiRJM3r+k6GdWisA6scz9yo7XuE=; b=SV0bHeYucokZw3B7Y7d0cL91KpJdUemBbUecIWfQ/b3vN7ZexlMYE5Rw+nfJMR6Uw7 ze4iolneTbSf09B/56mjy5TGv0+wlm6mDyUwJAG6L6geFrpoU0xl/dpM+kTOGpTATwQJ bpE0ZDavVs3tXvXoRPQnKHfX7rUZgQkadzoTjRMCZbWPAXXunN7Ee2h53Ve09BZ6xXkH sIFCUXMqWBrc1PtQOMhqyj7VXX0IstYtwI/zFFJ1X+zLpLHzu34DGGT4yKORu/wam5AK KXBZoNRhHd2JGcQUEhEbIxyddnyIWS7CJCNVYB9C0R1op6/39QvapLAjQoxboeHB13zH XT/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693351425; x=1693956225; 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=QYRPHwHql4RJiTHPJiRJM3r+k6GdWisA6scz9yo7XuE=; b=ddoLAZ5aY3ZA4eupwjUt6Xiqgl6MS5ydCogHF2oJLAKo7rs6fEMQhMVMTwdGhStGNW MJJjMSWWPhMIlYFXnz4bQni4+kdYXeMmF0gp2RrdqlNe+bc/0eEnAsud5d92Ivxd6IrL YlNvmqUQTABElkwMB0UAjXuCO7OC8RC8IEWDimIIQWER2NHy7eUQZJv6F4XZ2MO/lKf1 XULn8zzuED6YMBQCBpE7d4wGimJ+wO54xXL2W1TiZc6d92fRLNJ1ADQVNR4H1kNs+vwn J2ADLZhScJKc+WqdkozgevBYDmrWbWSmpA1sSc8WvzJ9ZN0Qo2Jn7XZCkRGS4S5KG3lD /25Q== X-Gm-Message-State: AOJu0Yx6cJDi80/ickpefexNBymfWw0CPNM/mEgU1SUqHVLc+v/pqGAn w3/cNgsQzo6OtNUaLYjVtFzJQNKIhxOzjgyJRFU= X-Google-Smtp-Source: AGHT+IHDP1ZtVriSwSv3vFBLEjvx5MVC3/uBgc3GszGNEHvqhlv692SqeR07Sv+1Lg0kp9Ob+ImNcA== X-Received: by 2002:a17:902:8e89:b0:1c0:b7f4:5b86 with SMTP id bg9-20020a1709028e8900b001c0b7f45b86mr552309plb.65.1693351425350; Tue, 29 Aug 2023 16:23:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: aaron@os.amperecomputing.com, qemu-arm@nongnu.org Subject: [PATCH v5 09/12] target/arm: Implement FEAT_FPAC and FEAT_FPACCOMBINE Date: Tue, 29 Aug 2023 16:23:32 -0700 Message-Id: <20230829232335.965414-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829232335.965414-1-richard.henderson@linaro.org> References: <20230829232335.965414-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1693351684472100002 Content-Type: text/plain; charset="utf-8" From: Aaron Lindsay Signed-off-by: Aaron Lindsay Reviewed-by: Richard Henderson Message-Id: <20230609172324.982888-8-aaron@os.amperecomputing.com> [rth: Simplify fpac comparison, reusing cmp_mask] Signed-off-by: Richard Henderson --- docs/system/arm/emulation.rst | 2 ++ target/arm/syndrome.h | 7 +++++++ target/arm/tcg/cpu64.c | 2 +- target/arm/tcg/pauth_helper.c | 18 +++++++++++++++++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst index 54234ac090..8be04edbcc 100644 --- a/docs/system/arm/emulation.rst +++ b/docs/system/arm/emulation.rst @@ -34,6 +34,8 @@ the following architecture extensions: - FEAT_FGT (Fine-Grained Traps) - FEAT_FHM (Floating-point half-precision multiplication instructions) - FEAT_FP16 (Half-precision floating-point data processing) +- FEAT_FPAC (Faulting on AUT* instructions) +- FEAT_FPACCOMBINE (Faulting on combined pointer authentication instructio= ns) - FEAT_FRINTTS (Floating-point to integer instructions) - FEAT_FlagM (Flag manipulation instructions v2) - FEAT_FlagM2 (Enhancements to flag manipulation instructions) diff --git a/target/arm/syndrome.h b/target/arm/syndrome.h index 62254d0e51..8a6b8f8162 100644 --- a/target/arm/syndrome.h +++ b/target/arm/syndrome.h @@ -49,6 +49,7 @@ enum arm_exception_class { EC_SYSTEMREGISTERTRAP =3D 0x18, EC_SVEACCESSTRAP =3D 0x19, EC_ERETTRAP =3D 0x1a, + EC_PACFAIL =3D 0x1c, EC_SMETRAP =3D 0x1d, EC_GPC =3D 0x1e, EC_INSNABORT =3D 0x20, @@ -232,6 +233,12 @@ static inline uint32_t syn_smetrap(SMEExceptionType et= ype, bool is_16bit) | (is_16bit ? 0 : ARM_EL_IL) | etype; } =20 +static inline uint32_t syn_pacfail(bool data, int keynumber) +{ + int error_code =3D (data << 1) | keynumber; + return (EC_PACFAIL << ARM_EL_EC_SHIFT) | ARM_EL_IL | error_code; +} + static inline uint32_t syn_pactrap(void) { return EC_PACTRAP << ARM_EL_EC_SHIFT; diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c index d3be14137e..7734058bb1 100644 --- a/target/arm/tcg/cpu64.c +++ b/target/arm/tcg/cpu64.c @@ -758,7 +758,7 @@ void aarch64_max_tcg_initfn(Object *obj) =20 t =3D cpu->isar.id_aa64isar1; t =3D FIELD_DP64(t, ID_AA64ISAR1, DPB, 2); /* FEAT_DPB2 */ - t =3D FIELD_DP64(t, ID_AA64ISAR1, APA, PauthFeat_2); + t =3D FIELD_DP64(t, ID_AA64ISAR1, APA, PauthFeat_FPACCOMBINED); t =3D FIELD_DP64(t, ID_AA64ISAR1, API, 1); t =3D FIELD_DP64(t, ID_AA64ISAR1, JSCVT, 1); /* FEAT_JSCVT */ t =3D 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 c05c5b30ff..4da2962ad5 100644 --- a/target/arm/tcg/pauth_helper.c +++ b/target/arm/tcg/pauth_helper.c @@ -396,6 +396,14 @@ static uint64_t pauth_original_ptr(uint64_t ptr, ARMVA= Parameters param) } } =20 +static G_NORETURN +void pauth_fail_exception(CPUARMState *env, bool data, + int keynumber, uintptr_t ra) +{ + raise_exception_ra(env, EXCP_UDEF, syn_pacfail(data, keynumber), + exception_target_el(env), ra); +} + static uint64_t pauth_auth(CPUARMState *env, uint64_t ptr, uint64_t modifi= er, ARMPACKey *key, bool data, int keynumber, uintptr_t ra, bool is_combined) @@ -416,7 +424,15 @@ static uint64_t pauth_auth(CPUARMState *env, uint64_t = ptr, uint64_t modifier, cmp_mask &=3D ~MAKE_64BIT_MASK(55, 1); =20 if (pauth_feature >=3D PauthFeat_2) { - return ptr ^ (pac & cmp_mask); + ARMPauthFeature fault_feature =3D + is_combined ? PauthFeat_FPACCOMBINED : PauthFeat_FPAC; + uint64_t result =3D ptr ^ (pac & cmp_mask); + + if (pauth_feature >=3D fault_feature + && ((result ^ sextract64(result, 55, 1)) & cmp_mask)) { + pauth_fail_exception(env, data, keynumber, ra); + } + return result; } =20 if ((pac ^ ptr) & cmp_mask) { --=20 2.34.1 From nobody Tue May 14 14:23:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1693351465; cv=none; d=zohomail.com; s=zohoarc; b=FnsyiDS4W3maRZ8IMHLKhY54S6MT3F73ZGl93d513eJrVLMFVwyCMuLJJVFwhRBOndfNiUdcC2CTM8AEieqywugZuB3K+SD/5P9WYALkaJT1zG/GSSoWOhw37xCur9V4ZtcTxbAVECC9JMm5dhRTwQpQVNsJbmON9AfG+EMXGXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693351465; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fonDp/wXRvCIKOTr9zFpwn6DY7PZ+KvY5INrQDOWD5c=; b=jbZsD8gBfMiNRH94F7so+KefgSLkctvpWX3dxwy0RFgMtMDSM8C7gu++4DmnlvjNFHtKcHluwfJdhifIeILzi4TIpgpl1C7LxM8pcbBTEMzqPGsGYXU//E7nHVzKPK3tazkb/uYvgOo0ZLEjqVoGuWPn80RcetllLfT6cxJS1nU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169335146507253.90458853808457; Tue, 29 Aug 2023 16:24:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb83z-0004p6-NN; Tue, 29 Aug 2023 19:23:59 -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 1qb83t-0004AS-Ix for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:53 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb83n-0001OU-K5 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:53 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-68a402c1fcdso3466475b3a.1 for ; Tue, 29 Aug 2023 16:23:47 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id t9-20020a170902e84900b001b9dadf8bd2sm9829970plg.190.2023.08.29.16.23.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 16:23:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693351426; x=1693956226; darn=nongnu.org; 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=fonDp/wXRvCIKOTr9zFpwn6DY7PZ+KvY5INrQDOWD5c=; b=kcwbcAEZ5WahBfHQjzYIpa0UrmbF2krCmwTtOJZyFfrbRcPT/2XUESjI7jNrgnY3m5 nu4NrJEMCwVKpCH/UcXPKbmDSgNMJkPFv4ebWiqzGys1n1mXXZO3BdshyTxfs+GRDvN1 Jomu9DtDwm7tCKGDcad84a5OqOLu5cqQZEBVPTScdF6j2ePjbAU2Mw6By1057VfV/ubX oyKziDgadVrkoDhhqmeeYFv/rpH6g3wEju4jayGV3W/Bm4lRmLVocOX9JqCylq6VTG/s hgMTeCcBiyOzulwFK07oRMRIbvVLoZwNNfDqWCPtzZoIFSU8w+rboaQWLbPMbykOFl30 d90Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693351426; x=1693956226; 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=fonDp/wXRvCIKOTr9zFpwn6DY7PZ+KvY5INrQDOWD5c=; b=Y51zJzRgbigzfAGWgJTzmJcxkeE2uW4QFRqPZo8/UDDNKG1N54liw+dP7Pe3NRc8wZ hsnt2pjoEUdOv394yuZWBU/3JVa3oNOK3L6fKP/G7JrsNhcPzXT5jK5Y3kGMXHr8VqYQ mPJNwFcsJiWGUlEpnMHsWPETIuozsLMTjilYT2UPKEv6tS6xx50PXujnkMMlMF/afNGW SGYk8sFo35SVeNY7wPKxrN1oZgS8nXe3Sqhh9zNwO/vfV9IgvEq7DqGxYcdvT71QuDgu /ja6oTnqxeso3cfv7ATC/nlCm1rLVGOWtVh95Q+FhJ0sEhzJf14vQ2AJSNrrWrBV51Tm 9iIg== X-Gm-Message-State: AOJu0YzY3IOj15gYa8B83Qm7mZYW2rLztJpLR02ltu6PeS4N+nvzMZga VpTwa+Dc7zOy9gii4fyG00Tgxgd3jiN4uvK/mkk= X-Google-Smtp-Source: AGHT+IGtOjRaCycAsK7bsLepLgcpWbmxoPY8GCx+0YYGew8NeTeKITM6Gxin7fLwm7YC1ROy0unCnA== X-Received: by 2002:a05:6a20:6a1a:b0:133:e3e3:dc07 with SMTP id p26-20020a056a206a1a00b00133e3e3dc07mr893323pzk.49.1693351426151; Tue, 29 Aug 2023 16:23:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: aaron@os.amperecomputing.com, qemu-arm@nongnu.org Subject: [PATCH v5 10/12] linux-user/aarch64: Add ESR signal frame for SIGSEGV, SIGBUS Date: Tue, 29 Aug 2023 16:23:33 -0700 Message-Id: <20230829232335.965414-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829232335.965414-1-richard.henderson@linaro.org> References: <20230829232335.965414-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1693351467234100003 Content-Type: text/plain; charset="utf-8" These are all synchronous exceptions for which the kernel passes on ESR to the user signal handler. Signed-off-by: Richard Henderson --- linux-user/aarch64/signal.c | 52 ++++++++++++++++++++++++++++++++++++- target/arm/tcg/tlb_helper.c | 8 +++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c index b265cfd470..40a476c33e 100644 --- a/linux-user/aarch64/signal.c +++ b/linux-user/aarch64/signal.c @@ -21,6 +21,7 @@ #include "user-internals.h" #include "signal-common.h" #include "linux-user/trace.h" +#include "target/arm/syndrome.h" =20 struct target_sigcontext { uint64_t fault_address; @@ -64,6 +65,13 @@ struct target_fpsimd_context { uint64_t vregs[32 * 2]; /* really uint128_t vregs[32] */ }; =20 +#define TARGET_ESR_MAGIC 0x45535201 + +struct target_esr_context { + struct target_aarch64_ctx head; + uint64_t esr; +}; + #define TARGET_EXTRA_MAGIC 0x45585401 =20 struct target_extra_context { @@ -191,6 +199,14 @@ static void target_setup_end_record(struct target_aarc= h64_ctx *end) __put_user(0, &end->size); } =20 +static void target_setup_esr_record(struct target_esr_context *esr, + CPUARMState *env) +{ + __put_user(TARGET_ESR_MAGIC, &esr->head.magic); + __put_user(sizeof(struct target_esr_context), &esr->head.size); + __put_user(env->exception.syndrome, &esr->esr); +} + static void target_setup_sve_record(struct target_sve_context *sve, CPUARMState *env, int size) { @@ -443,6 +459,10 @@ static int target_restore_sigframe(CPUARMState *env, fpsimd =3D (struct target_fpsimd_context *)ctx; break; =20 + case TARGET_ESR_MAGIC: + /* ignore */ + break; + case TARGET_SVE_MAGIC: if (sve || size < sizeof(struct target_sve_context)) { goto err; @@ -558,6 +578,27 @@ static int alloc_sigframe_space(int this_size, target_= sigframe_layout *l) return this_loc; } =20 +static bool need_save_esr(target_siginfo_t *info, CPUARMState *env) +{ + int sig =3D info->si_signo; + int type =3D info->si_code >> 16; + + if (type !=3D QEMU_SI_FAULT) { + return false; + } + + /* + * See arch/arm64/mm/fault.c, for invocations of set_thread_esr. + * We populate ESR in arm_cpu_record_sigsegv or arm_cpu_record_sigbus, + * called via cpu_loop_exit_{sigsegv,sigbus}. + */ + if (sig =3D=3D TARGET_SIGSEGV || sig =3D=3D TARGET_SIGBUS) { + return true; + } + + return false; +} + static void target_setup_frame(int usig, struct target_sigaction *ka, target_siginfo_t *info, target_sigset_t *se= t, CPUARMState *env) @@ -567,7 +608,7 @@ static void target_setup_frame(int usig, struct target_= sigaction *ka, .total_size =3D offsetof(struct target_rt_sigframe, uc.tuc_mcontext.__reserved), }; - int fpsimd_ofs, fr_ofs, sve_ofs =3D 0, za_ofs =3D 0; + int fpsimd_ofs, fr_ofs, esr_ofs =3D 0, sve_ofs =3D 0, za_ofs =3D 0; int sve_size =3D 0, za_size =3D 0; struct target_rt_sigframe *frame; struct target_rt_frame_record *fr; @@ -577,6 +618,12 @@ static void target_setup_frame(int usig, struct target= _sigaction *ka, fpsimd_ofs =3D alloc_sigframe_space(sizeof(struct target_fpsimd_contex= t), &layout); =20 + /* ESR state needs saving only for certain signals. */ + if (need_save_esr(info, env)) { + esr_ofs =3D alloc_sigframe_space(sizeof(struct target_esr_context), + &layout); + } + /* SVE state needs saving only if it exists. */ if (cpu_isar_feature(aa64_sve, env_archcpu(env)) || cpu_isar_feature(aa64_sme, env_archcpu(env))) { @@ -637,6 +684,9 @@ static void target_setup_frame(int usig, struct target_= sigaction *ka, layout.extra_size); target_setup_end_record((void *)frame + layout.extra_end_ofs); } + if (esr_ofs) { + target_setup_esr_record((void *)frame + esr_ofs, env); + } if (sve_ofs) { target_setup_sve_record((void *)frame + sve_ofs, env, sve_size); } diff --git a/target/arm/tcg/tlb_helper.c b/target/arm/tcg/tlb_helper.c index b22b2a4c6e..27bf30e9e2 100644 --- a/target/arm/tcg/tlb_helper.c +++ b/target/arm/tcg/tlb_helper.c @@ -354,7 +354,13 @@ void arm_cpu_record_sigsegv(CPUState *cs, vaddr addr, { ARMMMUFaultInfo fi =3D { .type =3D maperr ? ARMFault_Translation : ARMFault_Permission, - .level =3D 3, + /* + * In arch/arm64/mm/fault.c, set_thread_esr, for kernel-space + * addresses (i.e. TTBR1) the kernel cleans the ESR value to + * always report level 0. Since we're manufacturing a level + * here, we might as well pick 0 always. + */ + .level =3D 0, }; ARMCPU *cpu =3D ARM_CPU(cs); =20 --=20 2.34.1 From nobody Tue May 14 14:23:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1693351746; cv=none; d=zohomail.com; s=zohoarc; b=N9rdkrukUaEOvmpnlb2TbCJnk7oM/xwSEYMS1G7FhtXtMYpF+69dHpdQh5KsK1EQu9E7C4qADsVhi6kp/GKKZyx6cnUT9UHrWtabiNGRS5DtV0yK+RDhGtZrkPG/dKrhzOCL/KCKxLI5b/vnLv9kW+ITm1jk/9SQ8LusPoXrCgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693351746; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1kQdNiCM9Zqst6RWSQxeqs+p1o22wGyR4sXs05ml1eo=; b=UaXbSOBji9Qg23XoECzTuWCuNSbT3bdABBBQlJfw9MZN13/r4C3DzLrzAP7glZBNICv9pMS3CLmbu7Quj4w+/xwSRlmanJktJFiGhP5GfQedufRNpqpwuEZexA230SMv+m4GIU9hqBhQRIY5bJZISj0UgJFoUu1sxqAbe8m0c5c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693351746800754.6955963711455; Tue, 29 Aug 2023 16:29:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb83x-0004dj-Et; Tue, 29 Aug 2023 19:23:57 -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 1qb83t-0004A3-F0 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:53 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb83o-0001Om-C9 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:53 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-68a42d06d02so3481421b3a.0 for ; Tue, 29 Aug 2023 16:23:47 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id t9-20020a170902e84900b001b9dadf8bd2sm9829970plg.190.2023.08.29.16.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 16:23:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693351427; x=1693956227; darn=nongnu.org; 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=1kQdNiCM9Zqst6RWSQxeqs+p1o22wGyR4sXs05ml1eo=; b=M1zBRhaFJLKf4SKXp8KDIBr9Mw2/K1tBixAa0tOmVz4poIzyXwIM+23+EfA7xlrpBY 59VC1SEr62ngm4Rv9qrCdGA7W1yimBvRWrAUygQZU/JoFkWdV/EWeme1Go5q+buQ45in NnZau6GedSO61cWYed8LrjJLzujjqJ3aboXVWDXeB7G+u56qUb6OfBVGOjOd7WH59Bbz 1NSNMl4EzIm3MbMOFfsN/9f2PCYbIf68nqg13bxKKoOyQrlqdhL6YD+thn2+pvExpIwp ov+TeuXd5DEvQfuZ+ZkkHsEvklMOMFxHDaBB2+RCatgswSHfIZ+IIE0q7trlBJYgZnpK VudA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693351427; x=1693956227; 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=1kQdNiCM9Zqst6RWSQxeqs+p1o22wGyR4sXs05ml1eo=; b=e9UZ1isCiUa7eDMVx0r5IrILbr17IIihZuq6tAgwFIZ+YuWkbzwEDfAo9pOL9Kz4pC REsoC8xbWPjHcLrHuAhPwIyBa4mK3ds4OHj3oldrLw7FUVfAXDEvv6e+3h1Zh+p4gZSE J6pHIUougkbIuI/CZp8gkHcYWPzti0b2TkCo7yaNCIu+R4ZUSSZjrOOxCXG5fZ/K0Z6Q a+7dX6rRqyxlH73ttEx2DZRjJaj9fTF7Ekd/jL72imflI0DccILwYBmCeSzbBeGH+QMB 47PnOBJY0h5hb5ZjAKATvKkOpcpybLiZ2xtZRtOAsCvvvnjd6XjKeRcNsFRm9/Su0GWO eDUA== X-Gm-Message-State: AOJu0YwIKpn7cap8BAB9ufBWWVNJ32XyAX27zB680SF4aTFzzhcyQ+sq +IKLFVGWkLq9PLgl5IxllUYvOSW9ce8tH2Gqqmc= X-Google-Smtp-Source: AGHT+IGUQj3CwRk5PbS9IohWNK7e9cweW68RLWPA2NJPYlotAmZGotRsslxyCAj2Bj0hpyDPZ0kkeg== X-Received: by 2002:a05:6a20:138b:b0:14e:3ac2:e10d with SMTP id hn11-20020a056a20138b00b0014e3ac2e10dmr627463pzc.47.1693351426989; Tue, 29 Aug 2023 16:23:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: aaron@os.amperecomputing.com, qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v5 11/12] linux-user/aarch64: Fix normal SIGILL si_code Date: Tue, 29 Aug 2023 16:23:34 -0700 Message-Id: <20230829232335.965414-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829232335.965414-1-richard.henderson@linaro.org> References: <20230829232335.965414-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1693351748802100011 Content-Type: text/plain; charset="utf-8" Most illegal instructions use ILL_ILLOPC. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/aarch64/cpu_loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 2e2f7cf218..22c9789326 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -110,7 +110,7 @@ void cpu_loop(CPUARMState *env) /* just indicate that signals should be handled asap */ break; case EXCP_UDEF: - force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->pc); + force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc); break; case EXCP_PREFETCH_ABORT: case EXCP_DATA_ABORT: --=20 2.34.1 From nobody Tue May 14 14:23:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1693351730; cv=none; d=zohomail.com; s=zohoarc; b=nbdfvuXT7L1UZ67VOyalckFIq0oO5Y1r6nWYjtp/mqQpLVn8WESin+p0JiSoWuE4XDYXe/ErQdBvs22ppM8n0UaE+vaGqBp0nCywBEzthJ3l88BhvP9R78iMr0SmeqmQfMnnxE4pOrRRv4LCa393A2IhjCZREkKu2bVDBX5y5N4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693351730; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rbgZWuFBEAnasVpd2Kly8rMi99QBufRW3Lhak1ajaXE=; b=D7LrI0a/4IizqCyo87XN6fHBOwIAPiWzAqgqMKs8qn1FaJMcoMAFo5hoYxb4LyunShq9Vk6j6eecloKcId2pNkYreujFDGtJud4CjoFqjP3nJA3dwTtUF30whvnqh7Z3UL3+Z1CGiAHGNsikkr15RPIQ6+YOVrgQLakPpUZqBgk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693351730744386.8605583254463; Tue, 29 Aug 2023 16:28:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb83x-0004fo-SL; Tue, 29 Aug 2023 19:23:57 -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 1qb83u-0004Hj-GO for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:54 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb83p-0001Ow-74 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 19:23:54 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1bf3a2f4528so39093565ad.2 for ; Tue, 29 Aug 2023 16:23:48 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id t9-20020a170902e84900b001b9dadf8bd2sm9829970plg.190.2023.08.29.16.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 16:23:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693351428; x=1693956228; darn=nongnu.org; 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=rbgZWuFBEAnasVpd2Kly8rMi99QBufRW3Lhak1ajaXE=; b=gHhryrUmHCuN0NKKsuWxIXwBWnIbVCONpe3nOOHM8gQznbPGp014AapaSS23ttzKQ9 5pw1nWuWyJxh21YrOaMkp+fG0i4++tcQwnuM3RPJg86STOn7zU2d+2hkeHTqQn6B/R9B ZJhOLJWGnFCIE1iSpYU25Zu2HmFM4bev3PxnU93DRLkG0Q1jN1n+OhwXNn0j8PSc4K/w BrV+4rEjkdzEclt9Y4Rk7DLXbG+lx1rOFWBeuYR1dirXn0+v9v4AG4DdmEs/A+17miCM jnEvi6mH0EzSjFfK/Me/GndgH4GTLkmwCHvG+gu9BgeNp/qD/cVujsks3Os/y3baApeE lFnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693351428; x=1693956228; 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=rbgZWuFBEAnasVpd2Kly8rMi99QBufRW3Lhak1ajaXE=; b=c7Edbjc+YOfPEgrJs1mcEYaXrXGP7x8HlMPlYQrjc458HH5NC1bat/F2JWDPB5389o SvQ7Qrhm9eDFJLMRBEXdEk+aL16u2thILRX2FgYsWBA6Pm/w5TkZDupu+itS0I6TG3tI zmjIcX9fRWNAO8zpmT/lsGzot+ylZh2T5Q1k4d4nvPGx2yinMFgwYplS8YqarOzYTo7j xPQm8r1TONi6YjmxZko+9o5BEXyOaCBGs9R/hla5stSg5/saT04LYyElwI5eeoOvDoOt obPcuU5/kcBdOURfEEc8cF9bDleYBRUBCKV7DnwevHGwYk1wO2BA3HOqPs2hdn1c9dCu oapA== X-Gm-Message-State: AOJu0YxSIQnk1ytyoC2GSpONbC1WWzJawGa6jqLJlKvtmSj3Gwd4GGFm yu3R0FMJLTbyYgfi2p6920zrjrxMhjHOWwi094Y= X-Google-Smtp-Source: AGHT+IGH6gBlsrRcr1fsbilOUeBolS4SQ0d/3WIPph5nPIWdzXbvVDjPkQ9DgNYL4cepcxTTdu2J+A== X-Received: by 2002:a17:902:e5cc:b0:1c0:d89e:904a with SMTP id u12-20020a170902e5cc00b001c0d89e904amr610179plf.29.1693351427816; Tue, 29 Aug 2023 16:23:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: aaron@os.amperecomputing.com, qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v5 12/12] linux-user/aarch64: Add ESR signal frame for PACFAIL Date: Tue, 29 Aug 2023 16:23:35 -0700 Message-Id: <20230829232335.965414-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829232335.965414-1-richard.henderson@linaro.org> References: <20230829232335.965414-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1693351732218100003 Content-Type: text/plain; charset="utf-8" The PACFAIL fault uses ILL_ILLOPN and includes ESR. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/aarch64/cpu_loop.c | 7 ++++++- linux-user/aarch64/signal.c | 6 ++++++ tests/tcg/aarch64/pauth-2.c | 25 ++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 22c9789326..5af17e8724 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -110,7 +110,12 @@ void cpu_loop(CPUARMState *env) /* just indicate that signals should be handled asap */ break; case EXCP_UDEF: - force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc); + /* See kernel's do_el0_fpac, and our need_save_esr(). */ + if (syn_get_ec(env->exception.syndrome) =3D=3D EC_PACFAIL) { + force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->pc); + } else { + force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc); + } break; case EXCP_PREFETCH_ABORT: case EXCP_DATA_ABORT: diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c index 40a476c33e..375b8350f6 100644 --- a/linux-user/aarch64/signal.c +++ b/linux-user/aarch64/signal.c @@ -582,6 +582,7 @@ static bool need_save_esr(target_siginfo_t *info, CPUAR= MState *env) { int sig =3D info->si_signo; int type =3D info->si_code >> 16; + int code =3D info->si_code & 0xffff; =20 if (type !=3D QEMU_SI_FAULT) { return false; @@ -596,6 +597,11 @@ static bool need_save_esr(target_siginfo_t *info, CPUA= RMState *env) return true; } =20 + /* See arch/arm64/kernel/traps.c, do_el0_fpac, and our cpu_loop(). */ + if (sig =3D=3D TARGET_SIGILL && code =3D=3D TARGET_ILL_ILLOPN) { + return true; + } + return false; } =20 diff --git a/tests/tcg/aarch64/pauth-2.c b/tests/tcg/aarch64/pauth-2.c index 89ffdbf1df..aaf7c4a19f 100644 --- a/tests/tcg/aarch64/pauth-2.c +++ b/tests/tcg/aarch64/pauth-2.c @@ -5,14 +5,37 @@ #include "pauth.h" =20 =20 +static inline struct _aarch64_ctx *first_ctx(ucontext_t *uc) +{ + return (struct _aarch64_ctx *)&uc->uc_mcontext.__reserved; +} + +static inline struct _aarch64_ctx *next_ctx(struct _aarch64_ctx *hdr) +{ + return (struct _aarch64_ctx *)((char *)hdr + hdr->size); +} + static void sigill(int sig, siginfo_t *info, void *vuc) { ucontext_t *uc =3D vuc; - uint64_t test; + struct _aarch64_ctx *hdr; + struct esr_context *ec; + uint64_t test, esr; =20 /* There is only one insn below that is allowed to fault. */ asm volatile("adr %0, auth2_insn" : "=3Dr"(test)); assert(test =3D=3D uc->uc_mcontext.pc); + + /* Find the esr_context. */ + for (hdr =3D first_ctx(uc); hdr->magic !=3D ESR_MAGIC; hdr =3D next_ct= x(hdr)) { + assert(hdr->magic !=3D 0); + } + + ec =3D (struct esr_context *)hdr; + esr =3D ec->esr; + + assert((esr >> 26) =3D=3D 0x1c); /* EC_PACFAIL */ + assert((esr & 3) =3D=3D 2); /* AUTDA: data=3D1 key=3D0 */ exit(0); } =20 --=20 2.34.1