From patchwork Wed Feb 22 19:35:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lindsay X-Patchwork-Id: 13149529 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 66F13C636D6 for ; Wed, 22 Feb 2023 19:36:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUuuW-0007J2-Ab; Wed, 22 Feb 2023 14:36:16 -0500 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 1pUuuU-0007HV-8T; Wed, 22 Feb 2023 14:36:14 -0500 Received: from mail-dm6nam11on2071e.outbound.protection.outlook.com ([2a01:111:f400:7eaa::71e] helo=NAM11-DM6-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 1pUuuS-0005XN-5S; Wed, 22 Feb 2023 14:36:14 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jKXHCNSs1koRxOG1FAqiAAg9Kdan2XlQYE7LRl6VgplCy5JptAfQvvm08X1QQhymDLZpLBvRO5DukXhN6WuhWHZhcMC2PyhU15gk53Xdv8L+BYTayhfF+w02YVtYQFYWLjjBYFiULIpLfiLbY0oCuzpaSAeK0EVttPrOHhcsOdbPN8mqSV9OjvQaCm2ZaxvvqVeAHgel5wRiT7Y5g9ouL0ZaAkgoqaVQdDzRKTEHJy2/8GuPK4281e4dz6esuRRrIXgIqxkwBol8wMRKyAKvXJZ1T5DPstldcHyUSe1T9ZbO4GCUjmYZ+yV+0bzKESENKZcYDrS5wtsBfOau8BlT/Q== 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=VWBVNPCkegKSNV2fM0LBfJwOxfxCLzKu2b4eQ4z0jVs=; b=oRn/dYxjG9y5le0wQ9Zl9ut54TGQ+6tQlZM+O5E7O0iFAkPssdUraEA54mo6JD/MajaGU1bdm1PNGCN4JdtDsVNES4tSk75T2pkxFz+fp4Y9J4rbrBJphrf7GCxh//66byiURl7YzRaFe45apZARabRpBwcVVz/vn/kL1fCLwHrvCKrgfcclWBpqSKRXSY/GwtBrCA75QvJCf/xp9nDsyBYqIJ/ZEaSl+FyeQoGXrLOIBiWQ2e9pIq9LekwEUo/ifvDD8SrCVmd4qMkbIArZ/rf3xLUAe42gZQdrrgFVmFB1yhNbSIOJe1VC9O++5+TRdTPmUQmFa2g7/C0FdmCW+g== 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=VWBVNPCkegKSNV2fM0LBfJwOxfxCLzKu2b4eQ4z0jVs=; b=CKq2/HymDWlKDUIuw3Wg8BY0kzW46fP7IqbaUAfUpBarkuj2y2Qady+Mmq5zKCZ/+RDloT2GMktY8+kqgfiOJYsajv1Q7EcRaOJB6L+8ef/kNM4MMZSx68AUSZLEyTJgCu5xlKUx92O4HGFqicWzFieWYYIy08zFl1QR6hZlXxY= 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 DM6PR01MB3849.prod.exchangelabs.com (2603:10b6:5:91::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.20; Wed, 22 Feb 2023 19:36:08 +0000 Received: from CH0PR01MB7124.prod.exchangelabs.com ([fe80::c6ce:a93c:6bfa:2ec8]) by CH0PR01MB7124.prod.exchangelabs.com ([fe80::c6ce:a93c:6bfa:2ec8%9]) with mapi id 15.20.6134.019; Wed, 22 Feb 2023 19:36:08 +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 v2 4/7] target/arm: Implement v8.3 Pauth2 Date: Wed, 22 Feb 2023 14:35:41 -0500 Message-Id: <20230222193544.3392713-5-aaron@os.amperecomputing.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230222193544.3392713-1-aaron@os.amperecomputing.com> References: <20230222193544.3392713-1-aaron@os.amperecomputing.com> X-ClientProxiedBy: CH2PR08CA0016.namprd08.prod.outlook.com (2603:10b6:610:5a::26) To CH0PR01MB7124.prod.exchangelabs.com (2603:10b6:610:f3::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH0PR01MB7124:EE_|DM6PR01MB3849:EE_ X-MS-Office365-Filtering-Correlation-Id: 085f6f5b-2524-4c84-7c57-08db150c0b7f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AE84fRWQAhzmrdRruOMZSf6zIINMwv4kMgPUoM861Hw9yX83y91rq+Kfftc6l3Qx3+JBsgps+4gjPGBBWZtkCMenxqdFehgmN/3RhPn2wRKIhC4PBXMkLo9cpwXsvoH4xcS2fpnM1DdCKt6aPD6tbgswir7wLL9OV/W0kk04UFM7/Tjs0NW0gRgPXjhxg6G3CO5aUjFqHrc6/526PlMfx/39W/UW+ElJcQmei5KwxdtINfSKDGoGx0QC2y5jEZ1u0JdYIpRY5ztXjTWvL/3v+V7L0IJUs1U9x6aXk+/sUJQTvx5rNysk6vl7L0FEbeJu+v9GFDBqRLU7guhvfvlPdaI2sp+z1iSoc7ty+xDIpjl2TUPHsbYPi29R7D7VcJ0q6KmTXbFwghF5vjVbxgk8+Kt2c1bE1B92E1F7CUXRZLCZIX/SLxKYYzWg0AmQPu+eFdlZpZfWKPUF0PuF45Ulu2lCR2S4c4CZYIQH3AcWgbJoOTmlMtW+y3RBn7DYIYMZLLzLyOi6yDh55SWUaTFTGwxMPF3L7nP14+J4xJy0EQhcNo75pzC6iL6pw9OW8KE02k+E10r2TFLjtHjoe+sEzRXjkaE0eJnQl+YvNoGcAUHzw+SrXNfkMH8DKhXWCbl1cLExyEsnLIEqinthbaMk4YxQU+VcWX4bqB05+cKqSYd6yr1VoHe1jwKmTdATmQ/m18O7nfOVMwgYaBoTpaKzLA== 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)(366004)(136003)(346002)(39850400004)(396003)(376002)(451199018)(478600001)(26005)(6486002)(1076003)(107886003)(6512007)(6666004)(6506007)(110136005)(41300700001)(86362001)(66946007)(4326008)(66556008)(66476007)(8676002)(38350700002)(52116002)(316002)(2616005)(8936002)(38100700002)(5660300002)(2906002)(83380400001)(186003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QT07olbXNk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N5hAXSnRjg1ri0aXIfia7q5mvc/Lt0mDWdseGceuKfdRRGxCp1DZQE0p5sEPKcu9XrRSAL1jNiZgBSCVUBm6gkpsY31+qWgVhVOchILWJBE6RcOOOyu7zP6+YAwwB1on2VBcXYYTjQJkU/HucX1V4/47GdjSEAv9ncoRHtoe9RkDxOf7mv8nSNF0xm8WVEWhiLwrN5xtPKLSlNYtPGIxFjcOHAQCfErhyQG/UcvXAZlPTZuQmcvZjOUvQpnoOYE150qk4YQhMurMxS5tIs581L4b1xrpjHiWcb7q20ENe9ApB5Vc13rspznIb1u/Bg/oGlqkCSB7vj+5J9P6kNXAkmWftZMD1DZmwDcIermvtpgZ8PTd5ehTvhq4RhC4wdz+vw/ZfCJdr256FuAfL/3npJ+dk7a6Wu5t/D0ffo8wXcormt9QmK9km75Fm8DkwKyEfb6xZgMhWnuMScYzPvD5dJcKbnCKfBODxUm4C1TNK9YZfOqaUPvuCkjo3ljxXtbP3Yy6NuA2Ij4AgGqDA3kVVtmqCgsKpWHce3S5BJRJJIK+vo= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 085f6f5b-2524-4c84-7c57-08db150c0b7f X-MS-Exchange-CrossTenant-AuthSource: CH0PR01MB7124.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Feb 2023 19:36:08.1314 (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: ijVVQvakhusVPeQ3I8+ZFK4/ZiTz55Qd71vcnxLWlcAIun+a9j7j+VyOmbZFVK+WccmMGIoHdEcYfn5Y/sHBmJ4WfpiuhuFvyDdb/JUlaLQaKv27yWsyBiJUNWJbcrY7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB3849 Received-SPF: pass client-ip=2a01:111:f400:7eaa::71e; envelope-from=aaron@os.amperecomputing.com; helo=NAM11-DM6-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/pauth_helper.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c index a83956652f..c4ee040da7 100644 --- a/target/arm/pauth_helper.c +++ b/target/arm/pauth_helper.c @@ -347,7 +347,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, env_archcpu(env))) { + if (cpu_isar_feature(aa64_pauth2, env_archcpu(env))) { + /* No action required */ + } else if (cpu_isar_feature(aa64_pauth_epac, env_archcpu(env))) { pac = 0; } else { /* @@ -362,6 +364,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, env_archcpu(env))) { + 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); @@ -389,23 +394,30 @@ static uint64_t pauth_auth(CPUARMState *env, uint64_t ptr, uint64_t modifier, 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, env_archcpu(env))) { + uint64_t xor_mask = MAKE_64BIT_MASK(bot_bit, top_bit - bot_bit + 1) & + ~MAKE_64BIT_MASK(55, 1); + result = ((ptr ^ pac) & xor_mask) | (ptr & ~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)