From patchwork Fri Jun 30 13:48:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 71915 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB7D83882AED for ; Fri, 30 Jun 2023 13:50:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB7D83882AED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688133003; bh=zyVI21hROLrQFPxcXLHoSKx2fmf3tneSGap8gHkv+Yc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=DjqSDbOhizsiMUc28jX0UKdeD/Y4sqz9OQt/5C8iyN8GBuCzXJ1dLIfTHYl8FiBlG SP80+aljmVflRXf3eKBhGFCEtUzG+i9g2EMMZej5BWAlpPp6VzWVRSBcXQhAf/kknT PlYijaEa+4tYGTRf553RjVqEucdnvgsEvYEpR4KU= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2089.outbound.protection.outlook.com [40.107.105.89]) by sourceware.org (Postfix) with ESMTPS id 9E2253836EA4 for ; Fri, 30 Jun 2023 13:49:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E2253836EA4 Received: from DU2PR04CA0200.eurprd04.prod.outlook.com (2603:10a6:10:28d::25) by AM9PR08MB6260.eurprd08.prod.outlook.com (2603:10a6:20b:283::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.19; Fri, 30 Jun 2023 13:49:03 +0000 Received: from DBAEUR03FT033.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:28d:cafe::ec) by DU2PR04CA0200.outlook.office365.com (2603:10a6:10:28d::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.22 via Frontend Transport; Fri, 30 Jun 2023 13:49:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT033.mail.protection.outlook.com (100.127.142.251) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.22 via Frontend Transport; Fri, 30 Jun 2023 13:49:03 +0000 Received: ("Tessian outbound d6c4ee3ba1eb:v142"); Fri, 30 Jun 2023 13:49:03 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c6ecc9e74c3ffbca X-CR-MTA-TID: 64aa7808 Received: from a41d7a73a78f.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 8DCEACC5-353A-48D5-A910-0413B5D86218.1; Fri, 30 Jun 2023 13:48:56 +0000 Received: from EUR02-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a41d7a73a78f.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 30 Jun 2023 13:48:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BU1pAklcY0V6ecK9cvK8Z8L8VTCSUkKzPsIe/ODrz+eXI/Lwb9iAvZLB4ul7bhBZXESofor9RiK3NvQbr61OiEpLGwihIRcMYj6APcBamgI7wYWVE1a3o6P9yN8f7k8ttw/7ASMiLaGLcMlOm7I6C5L49IiPC0tq0Tapf01OZWiZQOXkQHrZxHOFeqGNmMap7ri3FnGjfva+voxXaeNwNVkKWEzNT5hJvD7szlCfx3qi7a0TR714VLuVPfhgtYU1MuZFz/TEM2dXns3KfeebKhjhPZjHb/wi6lw59GSuKGFfyPoTcawhQlZt8xepZQ+uBu5eKH1vcIX2eq6yKoFVuw== 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=zyVI21hROLrQFPxcXLHoSKx2fmf3tneSGap8gHkv+Yc=; b=W3FqE8ouZD9n6v5WVMmfnOsrN1/I+cBdZE0Wv2oC8LJYJZgBU/nnPAL+SzEh6psI8IMNu9u9fUNaNUJJ8kD9WD1r0ZZL7oRNyt4rXWd80AVMEtBLgNroLS9PGbnptLu84mZnN4nIqRJmpFCknUgZA+NtNxnFTCF1VPwMD8gkH40Y3TY+IwgCENpEiTXTFxveWK2e1fuV5WGuV63WwMd9QklLfOC8jT3ep6IW3w//Xa7Imbt8vq2AvSmbDPGjqR1lUdTWHDDiapxHfVhGtq8K/3Jnrswig19db3uM5QPxJAM4y6gYZFOuJgYCW1qFNresOh3CaH0aoihZqo5DBsCQSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from DB6PR0301CA0090.eurprd03.prod.outlook.com (2603:10a6:6:30::37) by GV2PR08MB8512.eurprd08.prod.outlook.com (2603:10a6:150:c2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.19; Fri, 30 Jun 2023 13:48:53 +0000 Received: from DBAEUR03FT029.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:30:cafe::e8) by DB6PR0301CA0090.outlook.office365.com (2603:10a6:6:30::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.22 via Frontend Transport; Fri, 30 Jun 2023 13:48:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT029.mail.protection.outlook.com (100.127.142.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6544.22 via Frontend Transport; Fri, 30 Jun 2023 13:48:53 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 30 Jun 2023 13:48:53 +0000 Received: from e129171.arm.com (10.57.27.17) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 30 Jun 2023 13:48:53 +0000 To: Subject: [PATCH 2/6] [gdbserver/aarch64] sme2: Enable SME2 support in gdbserver Date: Fri, 30 Jun 2023 14:48:40 +0100 Message-ID: <20230630134844.1238445-3-luis.machado@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230630134844.1238445-1-luis.machado@arm.com> References: <20230630134844.1238445-1-luis.machado@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DBAEUR03FT029:EE_|GV2PR08MB8512:EE_|DBAEUR03FT033:EE_|AM9PR08MB6260:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f15b1c8-e319-4e7c-9f82-08db7970c401 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 0kXFwXWZFr84jCk9Mh59/VRHkfqxtCOabaTo3P5pJ0b33BhY9+oz3mQHpa/aYlOAaNVwfB+p8H1UGK+OGW9Z04H02KR/vk6aGfVJDJ7Kv1JZ6/Lbc7kMgFmZa0S0Qn+ipk3X41aJphCZvXNOlKU9EowU7BJj57GEPcZSdZj2VIEhkfvsDnSWYPdYkYDEhOfZOM6U0hyB8cVQwU5T0fFGZoke3AxNq1kDgRl46KAR2/lXVT4Ar7l3Jst9/m85PI7USwUPfJTWo3Z44dNKaQxPvcxVa/worn73Ld6Hd0dNwgmo/FCxG9h2Y29IusmSLROdzR7o4hAvdZevszNTkSzjuFl4ve9X/vl7PE10/H6UjsuqNEyqbfUY2YNJc0EmeLxZTzetOTRA8cnugL4naunuOKzwC6FQ9i1lBHke9nC4QnmRhJY4/s+6PWcGIo5tVP5Meww6u0OZJ3u+bRJj80qU+UpuzmP2BZYlVOEyVjFU/vWpWizg+glheR96ZNXRRfNhdCwOHSzirQ4uBbVelxOLX8lPIQuU3YiVAq7C9F9h9ugcMlc1WKrTQ6Z7nIM9BoMhoEtr9SgQRAHktzALBcSWTIXI/9G41y3gT/t3J3RpR7m74Ng3bMp/4rg+YXfyetdw0EBcOLQdfGHGzGEgFn2JmEsJR310rUim02HasIReKj2dmdjaPBYvEUMHLmVbb03+mpCjL//miSC8rhyH8j4GEj3Bgp1ULYBfDMrShx1A7H+5NInctcU/FQW73nIqUHN+WCk8njNg2vS1Ur0ELL14QA== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230028)(4636009)(376002)(396003)(136003)(346002)(39860400002)(451199021)(40470700004)(36840700001)(46966006)(40460700003)(41300700001)(316002)(47076005)(83380400001)(82310400005)(86362001)(336012)(36860700001)(426003)(186003)(26005)(1076003)(44832011)(2616005)(2906002)(82740400003)(356005)(81166007)(40480700001)(5660300002)(36756003)(8676002)(8936002)(70586007)(7696005)(478600001)(6916009)(70206006)(6666004)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB8512 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 4ba9d1ce-ef1e-4630-a417-08db7970be2b X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g+jhd9yiWZzpukS8KdrXQAPooFTu0pJ/4JhbQuqQg70izNAO6GYoaPaF41+9EG97kyVGjJACUVhxcnd3omKsUtZ20l1x8tmoPNdmyslmhaqd/o+auISEZXpBN02WDRyCp7joLqBPOzfcdVDqlUSQhGxtODXI58K8c4ApEdjdS5HfUJpe8F0EZykUDFkMDUmvo/m4OfmxiGh+KE/85XVw5vFSfkQHlQqfxIyvdWwvOfMJJd9nsPryXoslRKqe1HGhe5Z/jBJRcsRNXdU++qaeMBDNQEqpnoMJEQeg3NlO56kYvOG4hQAdfXmeZBTRkMsLGQbk4aUyQC7XTjpjcSIw2SyAwW2ac1gHcud+EjViX7N9QnL/Mo6w1tucTYaX86z0zzaaND77yCOV70+lF0vmMYiqDb4jlkv++RG284HxjUFbQgMRq46CpgxS2/WiHg5c89hHPsivIAb08QlCGJz7U/+XTwyNyh7Dws8YRogw9w2IR0Vutp8Lb/eLCl9Z0i//jkKAV9bH2boqWKn6tmJGLmhY6zHBOac7jVTtjXZYEEtzrO83XTBSvPc6yvV+Ei/buJXOJxkOp+3N+b9he5OqeaZf8JwCAUKJk83XOujOrjV10CKVWIJRVKYaFVb3jHaRdSuvORBPQFKcECVDVKZ3aMpzmWRMThM0iqI03Rsrc4oXDZFOYwrPvg1+o7ogUwViS/FduEq3TctthSZb6UOfoQwVHpQezQC6Zn4Y9f00S99mLR7AjoMLIVruC7OIzeJl X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230028)(4636009)(396003)(376002)(136003)(346002)(39860400002)(451199021)(46966006)(40470700004)(36840700001)(316002)(40460700003)(41300700001)(83380400001)(426003)(82310400005)(36860700001)(86362001)(186003)(44832011)(26005)(2616005)(1076003)(336012)(2906002)(82740400003)(81166007)(40480700001)(47076005)(5660300002)(36756003)(8676002)(8936002)(6666004)(7696005)(6916009)(478600001)(70586007)(70206006); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2023 13:49:03.4639 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1f15b1c8-e319-4e7c-9f82-08db7970c401 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6260 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Luis Machado via Gdb-patches From: Luis Machado Reply-To: Luis Machado Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This patch teaches gdbserver about the SME2 and the ZT0 register. Since most of the code used by gdbserver for SME2 is shared with gdb, this is a rather small patch that reuses most of the code put in place for native AArch64 Linux. Validated under Fast Models. --- gdbserver/linux-aarch64-low.cc | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index 95688480c3d..783053e359b 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -811,6 +811,52 @@ aarch64_za_regs_copy_from_regcache (struct regcache *regcache, void *buf) memcpy (buf, za_state.data (), za_state.size ()); } +/* Wrapper for aarch64_zt_regs_copy_to_reg_buf, to help copying NT_ARM_ZT + state from the thread (BUF) to the register cache. */ + +static void +aarch64_zt_regs_copy_to_regcache (struct regcache *regcache, + ATTRIBUTE_UNUSED const void *buf) +{ + /* BUF is unused here since we collect the data straight from a ptrace + request, therefore bypassing gdbserver's own call to ptrace. */ + int tid = lwpid_of (current_thread); + + gdb::optional zt_regnum + = find_regno_no_throw (regcache->tdesc, "zt0"); + + gdb_assert (zt_regnum.has_value ()); + + /* Update the register cache. aarch64_zt_regs_copy_to_reg_buf handles + fetching the NT_ARM_ZT state from thread TID. */ + aarch64_zt_regs_copy_to_reg_buf (tid, regcache, *zt_regnum); +} + +/* Wrapper for aarch64_zt_regs_copy_from_reg_buf, to help copying NT_ARM_ZT + state from the register cache to the thread (BUF). */ + +static void +aarch64_zt_regs_copy_from_regcache (struct regcache *regcache, void *buf) +{ + int tid = lwpid_of (current_thread); + + gdb::optional zt_regnum + = find_regno_no_throw (regcache->tdesc, "za"); + + gdb_assert (zt_regnum.has_value ()); + + /* Update the thread NT_ARM_ZT state. aarch64_zt_regs_copy_from_reg_buf + handles writing the ZT state back to thread TID. */ + aarch64_zt_regs_copy_from_reg_buf (tid, regcache, *zt_regnum); + + /* We need to return the expected data in BUF, so copy whatever the kernel + already has to BUF. */ + + /* Obtain a dump of NT_ARM_ZT from ptrace. */ + gdb::byte_vector zt_state = aarch64_fetch_zt_regset (tid); + memcpy (buf, zt_state.data (), zt_state.size ()); +} + /* Array containing all the possible register sets for AArch64/Linux. During architecture setup, these will be checked against the HWCAP/HWCAP2 bits for validity and enabled/disabled accordingly. @@ -838,6 +884,11 @@ static struct regset_info aarch64_regsets[] = 0, EXTENDED_REGS, aarch64_za_regs_copy_from_regcache, aarch64_za_regs_copy_to_regcache }, + /* Scalable Matrix Extension 2 (SME2) ZT registers. */ + { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_ARM_ZT, + 0, EXTENDED_REGS, + aarch64_zt_regs_copy_from_regcache, aarch64_zt_regs_copy_to_regcache + }, /* PAC registers. */ { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_ARM_PAC_MASK, 0, OPTIONAL_REGS, @@ -909,6 +960,10 @@ aarch64_adjust_register_sets (const struct aarch64_features &features) if (features.svq > 0) regset->size = ZA_PT_SIZE (features.svq); break; + case NT_ARM_ZT: + if (features.sme2) + regset->size = 64; + break; default: gdb_assert_not_reached ("Unknown register set found."); } @@ -947,6 +1002,14 @@ aarch64_target::low_arch_setup () if (linux_get_hwcap2 (pid, 8) & HWCAP2_SME) features.svq = aarch64_za_get_svq (tid); + /* Scalable Matrix Extension 2 feature check. */ + CORE_ADDR hwcap2 = linux_get_hwcap2 (pid, 8); + if ((hwcap2 & HWCAP2_SME2) || (hwcap2 & HWCAP2_SME2P1)) + { + /* Make sure ptrace supports NT_ARM_ZT. */ + features.sme2 = supports_zt_registers (tid); + } + current_process ()->tdesc = aarch64_linux_read_description (features); /* Adjust the register sets we should use for this particular set of