From patchwork Wed Mar 22 20:25:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 13184656 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86CE7C6FD1F for ; Wed, 22 Mar 2023 20:28:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pf52P-0001eW-8w; Wed, 22 Mar 2023 16:26:25 -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 1pf52N-0001e9-LK; Wed, 22 Mar 2023 16:26:23 -0400 Received: from mail-bn7nam10on20707.outbound.protection.outlook.com ([2a01:111:f400:7e8a::707] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pf52L-0004xk-Su; Wed, 22 Mar 2023 16:26:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UV6YNmlVnSZTYQzAxpIZmcIxip1C/tv1qbIv6cQ3vJ0JwMmMySaAFSaybUVleNx7ygPTQe/goh69ioraXqS//LCSmTSVjIVmgi5d/RLdItW2S19MjCn7lVAirjb5TJpSPoBcD0C9FEtUq9CCV/+4HaAUGdQ9OYxnLTzvHPSHvhWseoEu83rezTF5OMrhMSK1lzag754v9Mg0F+xlu4qY7rhJr5AJfljQ+lkh2OY4dxqZg/WicDu3HSH1yiouTdSDLVNMzkWoi+eZZWi4tmmfYWTDoOa7+dtr8Caz5rJe/zXvXNEz9rPSi7XA4eE7waYetQKB4DMo12sI7g6la0VR5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Z+VGBZAF/st+ysD7A6pDdoonFVJM2RxzmwLO71SPFcg=; b=JZkvaxR2GJxMMxEd+T7WkWz4l0ZLOEAiG9Et+CmW44SILcZFYMZZrLhQwDakLCHx8P/fmDAnY4mw2BqmrXg8buU9xMmLtVOVfyfwQ2nwYwjQFgD3nF1KSWXxySl4IKXWttT2yKnk+rTHoMuEXxuBccvIQ9qWYCgnS+c3Z5i+vc9tdRxkNaLRGO3wazuBsGjo65mCIPzWn17CLG3M7f78cg74tN+XUlCk69vYsra76J/hu4e828juIve33ShjqorCzDVnzRcRsEnaWjvrNJ9F39rswtYOguudLTpB6UifUi0dcR9HB2eRBI7AIdghk/7hMrdyhvTzU5iN5lHDU97Ryg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z+VGBZAF/st+ysD7A6pDdoonFVJM2RxzmwLO71SPFcg=; b=hbCMTMBOFPbOugDeah/a587q2NENcYmkBPepXHcay1Qyfo/2oH8tJaz+OrSPPmVcZnU0a8EmNAhTrGww0ygMrTeU5k0teKVHjuhlg3z5sUVIYsoaNWa+gDw3Ow7SN73vWm4ihrTX0NgBjMLC1Bo21whOr+c5sDrNAgY2oPr3QXc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from CH0PR01MB7124.prod.exchangelabs.com (2603:10b6:610:f3::20) by SA1PR01MB7342.prod.exchangelabs.com (2603:10b6:806:1f5::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.8; Wed, 22 Mar 2023 20:26:18 +0000 Received: from CH0PR01MB7124.prod.exchangelabs.com ([fe80::cf62:d511:8228:b39c]) by CH0PR01MB7124.prod.exchangelabs.com ([fe80::cf62:d511:8228:b39c%8]) with mapi id 15.20.6222.010; Wed, 22 Mar 2023 20:26:18 +0000 From: Aaron Lindsay To: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Richard Henderson , Vincent Dehors , =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell Cc: Aaron Lindsay Subject: [PATCH v3 5/8] target/arm: Implement v8.3 Pauth2 Date: Wed, 22 Mar 2023 16:25:38 -0400 Message-Id: <20230322202541.1404058-6-aaron@os.amperecomputing.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230322202541.1404058-1-aaron@os.amperecomputing.com> References: <20230322202541.1404058-1-aaron@os.amperecomputing.com> X-ClientProxiedBy: CH2PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:59::18) To CH0PR01MB7124.prod.exchangelabs.com (2603:10b6:610:f3::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH0PR01MB7124:EE_|SA1PR01MB7342:EE_ X-MS-Office365-Filtering-Correlation-Id: fe1eeee7-dd28-4942-4ad8-08db2b13b127 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IW5BuifnD8dSu1WzJPYWhrli7MsybAEsNPHRGZ/QR70pAgQIKOfha2eq3u9Xy74Er8K3SWToALHon6AZDR62EIQbPVCHmT3/dv+k+dydk7ax5IJEPhUhw+45KAgD0Gr+guInnYx1CcOF1oU7MrNZfz0coD8JsPBT7vI3QkgRhB3BrYmiKLyNS7P5+ZeSMQreqBi01vzDrGRToK/7wKDb70VF1wQy0WFBSq93otzC+1KbcLEZToAO2y9Od+5r11KUnrJ5gH9jM+rShqXpRhwK3FN3FJrAxNnoqXVqSMzVDazhqkLofHoFecBFUrghLedq8zozSfp9QYKwVn0OEg5fyLrqk85dwP57IeceFcnB3kQOdnh+PJYbMGgsIHueQVuUTetwxd78uOxYJ0pnpXVIjDC3mdpshdTy2YlZzKAkS/hiYYCavZeynkDwfBd2/uTLmf+qYdelGs9XCINK0KPbrDKnMYLz/IKkWwqj4HPYlOb4hsJWzQeYEAcycW4C6WlftCgLJNh5U7rtS4gxRrgjrUXdf0hPZfQZotGGKZJflBBfTacSinvEsinN4f4SsJpmeRZF4aq8KKqztfEbzNwC9mmwQNWxgDRuOvj4h73rX4SPbjO6BRaXPg2SO4yVs/C7iJTiJBl7tCJRNVAHJLSKIQvB9OTUXv1V/2BLbwQqjbGlRDhcyPS2tYRi8wlQgvqze9eIbu/YNF4WOdSDBe8hKw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH0PR01MB7124.prod.exchangelabs.com; PTR:; CAT:NONE; SFS:(13230025)(4636009)(346002)(136003)(366004)(396003)(376002)(39850400004)(451199018)(83380400001)(38350700002)(6486002)(186003)(6506007)(86362001)(26005)(6512007)(2616005)(1076003)(38100700002)(6666004)(107886003)(5660300002)(4326008)(52116002)(66476007)(41300700001)(110136005)(66946007)(478600001)(8936002)(2906002)(8676002)(316002)(66556008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wAVK6ztMuMJnJnsOyls2H8jSdTIl2onp2KPR9yuAm/eAIGIYI3BnOS+pP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1EA1syG/HbNu+SNzZh29psfpx/C00fhOq0/DmrqKz5twpCnMO8Tyt5AhOsqtv2nZxSDr9zEG3l8Klsf25pjFciKaykzwXggCeNCcZFrb8TsTzb4ip4Y+kHU8kx5yqI6VSBV/NBGK2djC9/n5aXu1Xg7GwVz9IwiJhDfSeL5ph6b5pDJtyO0LlnN/498BDo2/MfbXi7GcatkUq5MBVuqLkvJpVxNPb/EELhA6AEwn1Tw+ro978BuxPF0QEI4EuvJJFG4RLHKwolLvtFJPYsaY5kq/aui8YA9Gxfmudp6q67n7gYOEsttLLbF2dKIwZmJ7GfNmpxEACnWIFAUmpFo1dpnqvJOiQfBeebScaaU3utBeqjxmX42fbtARESt2h587o4lgnL48bT+nL8QE7mc9pxpWwwtMlq6m4CX4Jv3l3f4sNk5vyWjB2UxJaTzbwWceY7Pxa7LWSJ/hvmHK7lMSSemlN58LQ2r3jmY93zCnn9UT8hgydIgHC0FA7l2JbSd+ZeM6tZqoc= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe1eeee7-dd28-4942-4ad8-08db2b13b127 X-MS-Exchange-CrossTenant-AuthSource: CH0PR01MB7124.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2023 20:26:18.1253 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VKwAykNz216kzicW40a882szWyLoDRsmcNoJAidGClP+6xoHQc6wAzDrvw7ABhXB4zGepipLYfhHvr9nPO8CTgqxQUlDyfufmnEnNJ1hC7Uc/CcX/sXhvSLdDWojXMvG X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR01MB7342 Received-SPF: pass client-ip=2a01:111:f400:7e8a::707; envelope-from=aaron@os.amperecomputing.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_HELO_PASS=-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Aaron Lindsay Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson --- target/arm/tcg/pauth_helper.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/target/arm/tcg/pauth_helper.c b/target/arm/tcg/pauth_helper.c index 7682f139ef..1148a21ce6 100644 --- a/target/arm/tcg/pauth_helper.c +++ b/target/arm/tcg/pauth_helper.c @@ -352,7 +352,9 @@ static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modifier, */ test = sextract64(ptr, bot_bit, top_bit - bot_bit); if (test != 0 && test != -1) { - if (cpu_isar_feature(aa64_pauth_epac, cpu)) { + if (cpu_isar_feature(aa64_pauth2, cpu)) { + /* No action required */ + } else if (cpu_isar_feature(aa64_pauth_epac, cpu)) { pac = 0; } else { /* @@ -367,6 +369,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 (cpu_isar_feature(aa64_pauth2, cpu)) { + pac ^= ptr; + } if (param.tbi) { ptr &= ~MAKE_64BIT_MASK(bot_bit, 55 - bot_bit + 1); pac &= MAKE_64BIT_MASK(bot_bit, 54 - bot_bit + 1); @@ -409,26 +414,34 @@ uint64_t pauth_ptr_mask(CPUARMState *env, uint64_t ptr, bool data) static uint64_t pauth_auth(CPUARMState *env, uint64_t ptr, uint64_t modifier, ARMPACKey *key, bool data, int keynumber) { + ARMCPU *cpu = env_archcpu(env); ARMMMUIdx mmu_idx = arm_stage1_mmu_idx(env); ARMVAParameters param = aa64_va_parameters(env, ptr, mmu_idx, data); int bot_bit, top_bit; - uint64_t pac, orig_ptr, test; + uint64_t pac, orig_ptr, test, result; orig_ptr = pauth_original_ptr(ptr, param); pac = pauth_computepac(env, orig_ptr, modifier, *key); bot_bit = 64 - param.tsz; top_bit = 64 - 8 * param.tbi; - test = (pac ^ ptr) & ~MAKE_64BIT_MASK(55, 1); - if (unlikely(extract64(test, bot_bit, top_bit - bot_bit))) { - int error_code = (keynumber << 1) | (keynumber ^ 1); - if (param.tbi) { - return deposit64(orig_ptr, 53, 2, error_code); - } else { - return deposit64(orig_ptr, 61, 2, error_code); + if (cpu_isar_feature(aa64_pauth2, cpu)) { + uint64_t xor_mask = MAKE_64BIT_MASK(bot_bit, top_bit - bot_bit + 1) & + ~MAKE_64BIT_MASK(55, 1); + result = ptr ^ (pac & xor_mask); + } else { + test = (pac ^ ptr) & ~MAKE_64BIT_MASK(55, 1); + if (unlikely(extract64(test, bot_bit, top_bit - bot_bit))) { + int error_code = (keynumber << 1) | (keynumber ^ 1); + if (param.tbi) { + return deposit64(orig_ptr, 53, 2, error_code); + } else { + return deposit64(orig_ptr, 61, 2, error_code); + } } + result = orig_ptr; } - return orig_ptr; + return result; } static uint64_t pauth_strip(CPUARMState *env, uint64_t ptr, bool data)