From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2047.outbound.protection.outlook.com [40.107.22.47]) by sourceware.org (Postfix) with ESMTPS id 77F3D3959CB4 for ; Tue, 6 Dec 2022 09:51:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 77F3D3959CB4 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fdSllIzaB5Atl1dqFmy6/UHFd07Dt++9lVZrX/3JAOg=; b=9eXMaVE/Pf1MlNqSuEKO53GGiRYAA0jH8rW6X/Nv1eqLUxyGNLPQnKBtWueaADvqxDMzFF7qyv9xD1RgY6DVqnBr2nouakjeBGw7c3rG51fzlwdmiJhYBJjMC2qEIsGkUwBZI1S5D6wdKhvtLSwvq0/jiBDtHeI6wSLxSPQrZAE= Received: from AS9PR06CA0636.eurprd06.prod.outlook.com (2603:10a6:20b:46f::12) by AS2PR08MB8502.eurprd08.prod.outlook.com (2603:10a6:20b:55d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.13; Tue, 6 Dec 2022 09:50:51 +0000 Received: from VI1EUR03FT023.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:46f:cafe::6f) by AS9PR06CA0636.outlook.office365.com (2603:10a6:20b:46f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Tue, 6 Dec 2022 09:50:51 +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 VI1EUR03FT023.mail.protection.outlook.com (100.127.144.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.14 via Frontend Transport; Tue, 6 Dec 2022 09:50:50 +0000 Received: ("Tessian outbound 2ff13c8f2c05:v130"); Tue, 06 Dec 2022 09:50:50 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 5a83956306bbeabb X-CR-MTA-TID: 64aa7808 Received: from 43eccd9469ac.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 7177E35A-7EA4-4515-9E9B-46846F07D750.1; Tue, 06 Dec 2022 09:50:43 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 43eccd9469ac.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 06 Dec 2022 09:50:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aGKU7oAvGWxQrB0Reobjiqg3gscza7faKR7eMhSGMVqE1LD9Lp60Kysp2KsRLtlcgEpnQ1b/6fe2Z/1u1NWwl84Ww7jXtipt/NoGZ9GbsN5YVlZ/cXWOhANN59Z6uxS/v7M/gelPQg1zpUjK0LLrWCiWtGOl9v2nZ4MMJHBQAi5UxRDALkqRwHQb4mmMHXnt5U4U8dcLb8m8fRVyNGUEZ/a/a0CyMx85Wm8IgRe5yviIR6jyI0NZ/hlgYDHetIueyGHeh+vcfgteZ0h73eaRkdoddlZ2xdqfO2XjXKjvN6HchRZBA0VwtXdOSq8PEP+I9+dmG6Pq0yzdHBARDSGA/A== 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=fdSllIzaB5Atl1dqFmy6/UHFd07Dt++9lVZrX/3JAOg=; b=MPE7vcGw+CVW2Tu+ZAcbn5AYKdT1JyCgQAV6XWCoAaILTmDcyxBzrw0uCAbdzBo6r9/XZ7Zh1YUaaaxqNVtnpZ1CN3aDd5xUn/ZbyAIsf6VI9VD9W76S740l+C9U5obHDtOK59KWDnwtdQiGr5GftiwzT21UoTNKkIjAlzzSW9PBxryZVg6vaHZnLczlqGyKuGUfIjDx+e+eV0/dhrHUxnk2iwWSLqVkoo8/jPpnP7swsD2pHZ50qV84OPErjLy3bSjK9DMzMppdaAGsSTUcFiZ+Wdfkx/VckmvKAR9BxvgF5hySQoYx6jrpVSIBySHd8j+KndjtPgam9dI47mHDuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fdSllIzaB5Atl1dqFmy6/UHFd07Dt++9lVZrX/3JAOg=; b=9eXMaVE/Pf1MlNqSuEKO53GGiRYAA0jH8rW6X/Nv1eqLUxyGNLPQnKBtWueaADvqxDMzFF7qyv9xD1RgY6DVqnBr2nouakjeBGw7c3rG51fzlwdmiJhYBJjMC2qEIsGkUwBZI1S5D6wdKhvtLSwvq0/jiBDtHeI6wSLxSPQrZAE= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) by DBAPR08MB5797.eurprd08.prod.outlook.com (2603:10a6:10:1a1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Tue, 6 Dec 2022 09:50:41 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::fe5c:b195:a2ad:b19c]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::fe5c:b195:a2ad:b19c%4]) with mapi id 15.20.5880.014; Tue, 6 Dec 2022 09:50:40 +0000 Message-ID: <66882b66-df2e-ba99-5466-53ce2b4af2af@arm.com> Date: Tue, 6 Dec 2022 09:50:39 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH] [AArch64] Add TPIDR2 register support for Linux Content-Language: en-US To: Simon Marchi , gdb-patches@sourceware.org References: <20220923134648.114930-1-luis.machado@arm.com> <41c544e4-1832-d4c4-9ea4-b0d034ac67d2@simark.ca> From: Luis Machado In-Reply-To: <41c544e4-1832-d4c4-9ea4-b0d034ac67d2@simark.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P123CA0002.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:a6::14) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|DBAPR08MB5797:EE_|VI1EUR03FT023:EE_|AS2PR08MB8502:EE_ X-MS-Office365-Filtering-Correlation-Id: 28e9f5a1-ef07-4fba-10a6-08dad76f5bf9 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: WkpGBB5EFOTL0Nxq19QvqcoKzkQICK2v2PElJlWNUNPxv3NinzPquVXpESqySvl9ooNeNMZtAfSxBXb/rCoKmb5EHyv8WLiKAPnCRBaz4pNxe3S11sCIXQZ0ErEByrAYBcjCDRM9tayygCB8UzUneQc/gCtUA6zUE1IdCS/zoLRRbJO5rYIm/FkEZtMzbi8fiV9Hk+/m6Ew2wvjWf9vs6w6jN/1bJPbPrWyunVIWGKZAJxva93k1SHGbwBJgSBNifyssfAtSHWuo/+LbAMQYr9uEQkHwchoy7Fc4VUfTw3RR+Bxj/plA/A23OsgxN7tO/slJBX76SG+l/iyPNkSyET+FEOa0rvqQcyqU31jH7j+tsSdRnq0suelu5xjotoywM6X4jNhHyFnl4p4Vrs/0YVDDD0WuvDUrS49QMnmn/BMoEFwyeeUt4o9oaagGffoTqtnHtox2sCf4Ro4+vId/cmnYQ3/Z2e1POmwXCEral3FPD6A11TcOGBqzwmWEp1mJtwS6RQfpN1WAvvunOKOCBhKkCC5ng4V+kPd1bBjMLVeHznKrU8f65je9hz27cripbhAqp+lOBAKJF5pCCFjD2HSmOk6CFBlj6HEB3ws5eosXUmuGX3x/PSDGeAbnO4rgyUP2fDMQgcQkAcroSFs66BgQOS4JJfakp2ZmsGHbv2OgGWfgZ/FfkiyMbt/mwNgdnaoZ6vYnpTqcOBRz0i0bYDHo34JEjcCt0e9CZCkeAjc= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR08MB3919.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(39860400002)(136003)(346002)(366004)(451199015)(41300700001)(38100700002)(2616005)(186003)(2906002)(83380400001)(5660300002)(36756003)(8936002)(44832011)(478600001)(6486002)(53546011)(66476007)(6506007)(31686004)(6512007)(66946007)(86362001)(26005)(31696002)(66556008)(8676002)(316002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR08MB5797 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VI1EUR03FT023.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 3a627d62-863a-44f6-f1e0-08dad76f5507 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3b7f2X2/+Ds338q27PQKbWZ136r7GnXzsKkrwG81sHA8d0zWTrALEFQQl83r4+mgl+fc2x/dfvVkza4rouY8luDuKywNbNAvA888h9WDHnJjjitl4EDXzuzaq99d6WOlH8bY4ieCcslMQ1t+abzL4PY7/KWOk4YgXslSHFSaYp8SusSXoXNE+8K2oaABZqeHQkO37+2bXW31BYJXgm+hOmH8L4GMzl52dtjN6jSoeCdUWJ0K2hDzMYqVim+urvdnltG/NpSZIrkV2FTf3w04FT4uoeTgQtpNR1Gjpm5EDOjVUfIiPT7o2hDtXbNStPI4KAjOolVBKYNBSBCeNIjnK4ob+G99V5b19pI6TERoOY63WL3kkFPil2w2oJL6ktZSMnZBgslMJonKysULL2cPF10TttfhTnOSZ6VvLyCoCTeWOSZ74+W2qIzqaG9hrP8d5St9/0xf/V4qClIBePfUK2h+K9MMChrGXbb7mKacwNCfTMHtL2xwcphAKNu2FOp3zQJcYIjGSjgePBPHzmMlPTJQyOege7K9163ebMeVovnKrz1iYraG/EZXQ67Tm/gWuZQ5w4XvpoETLAFho/7zYeWzkfCDSsOVkoaKE7xEO/j4q/RLz1I1/Sqii9oKentEziz+cvpQX4U2oYaPRXbapLJm2wNZJxj4JCoJGcjVb0BY4R12YS7pbxQX4UbzOFsY7pFjRVWtUHO1he5ucuh3C3sPK6Rfz9xYKKVuTte4QrQ= 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:(13230022)(4636009)(346002)(376002)(136003)(396003)(39860400002)(451199015)(46966006)(36840700001)(40470700004)(82310400005)(44832011)(70586007)(70206006)(8676002)(83380400001)(36756003)(86362001)(40480700001)(31696002)(186003)(6506007)(336012)(2616005)(41300700001)(53546011)(8936002)(47076005)(5660300002)(31686004)(40460700003)(36860700001)(478600001)(6486002)(2906002)(6512007)(82740400003)(81166007)(26005)(316002)(356005)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2022 09:50:50.9643 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 28e9f5a1-ef07-4fba-10a6-08dad76f5bf9 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: VI1EUR03FT023.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB8502 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_NONE,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,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 List-Id: Hi Simon, Thanks for the review. On 12/5/22 20:36, Simon Marchi wrote: >> diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c >> index eda79ec6d35..03eec37a6c4 100644 >> --- a/gdb/aarch64-linux-nat.c >> +++ b/gdb/aarch64-linux-nat.c >> @@ -442,19 +442,19 @@ fetch_tlsregs_from_thread (struct regcache *regcache) >> = gdbarch_tdep (regcache->arch ()); >> int regno = tdep->tls_regnum; >> >> - gdb_assert (regno != -1); >> + gdb_assert (regno != -1 && tdep->tls_register_count > 0); > Check just one thing per gdb_assert. Fixed. > >> @@ -786,7 +790,16 @@ aarch64_linux_core_read_description (struct gdbarch *gdbarch, >> features.vq = aarch64_linux_core_read_vq (gdbarch, abfd); >> features.pauth = hwcap & AARCH64_HWCAP_PACA; >> features.mte = hwcap2 & HWCAP2_MTE; >> - features.tls = tls != nullptr; >> + >> + /* Handle the TLS section. */ >> + asection *tls = bfd_get_section_by_name (abfd, ".reg-aarch-tls"); >> + if (tls != nullptr) >> + { >> + size_t size = bfd_section_size (tls); >> + /* Convert the size to the number of actual registers, by >> + dividing by 8. */ >> + features.tls = size >> 3; > > Why not write it as `size / 8`? Or, `size / AARCH64_TLS_REGISTER_SIZE`? > Fixed. >> @@ -3544,13 +3555,26 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) >> /* Add the TLS register. */ >> if (feature_tls != nullptr) >> { >> - tls_regnum = num_regs; >> - /* Validate the descriptor provides the mandatory TLS register >> - and allocate its number. */ >> - valid_p = tdesc_numbered_register (feature_tls, tdesc_data.get (), >> - tls_regnum, "tpidr"); >> + const char *tls_register_names[2] = { "tpidr", "tpidr2" }; >> + first_tls_regnum = num_regs; >> + >> + /* Look for the TLS registers. */ >> + for (i = 0; i < ARRAY_SIZE (tls_register_names); i++) >> + { >> + valid_p >> + = tdesc_numbered_register (feature_tls, tdesc_data.get (), >> + first_tls_regnum + tls_register_count, >> + tls_register_names[i]); >> + if (valid_p) >> + tls_register_count++; >> + } >> + valid_p = true; > > It would seem better to just use a different variable inside the loop, > if you don't want it to affect valid_p. If valid_p is false before > entering the loop, you still set it to true afterwards, is that what you > want? > > It seems to me like you would want the lookup of tpidr to affect > valid_p, as it would be invalid to have the tls feature without tpidr, > but the lookup of tpidr2 to not affect valid_p. > Yes, indeed. I've switched this to using a different bool for the tpidr2 check. >> diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h >> index d8513023c37..8166df0ada8 100644 >> --- a/gdb/aarch64-tdep.h >> +++ b/gdb/aarch64-tdep.h >> @@ -111,8 +111,9 @@ struct aarch64_gdbarch_tdep : gdbarch_tdep_base >> return mte_reg_base != -1; >> } >> >> - /* TLS register. This is -1 if the TLS register is not available. */ >> + /* TLS registers. This is -1 if the TLS registers are not available. */ >> int tls_regnum = 0; >> + int tls_register_count = 0; > > Perhaps rename tls_regnum to tls_regnum_base, since it not longer > represents just one register. > Yeah. I deferred renaming this to avoid having more churn in the patch. Done now. >> diff --git a/gdb/nat/aarch64-linux.c b/gdb/nat/aarch64-linux.c >> index 421d1ecb53c..017c30948a9 100644 >> --- a/gdb/nat/aarch64-linux.c >> +++ b/gdb/nat/aarch64-linux.c >> @@ -250,3 +250,20 @@ aarch64_ps_get_thread_area (struct ps_prochandle *ph, >> >> return PS_OK; >> } >> + >> +/* See nat/aarch64-linux.h */ > > Dot and double space. > >> + >> +int >> +aarch64_tls_register_count (int tid) >> +{ >> + uint64_t tls_regs[2]; >> + struct iovec iovec; >> + iovec.iov_base = tls_regs; >> + iovec.iov_len = sizeof (tls_regs); >> + >> + if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_TLS, &iovec) != 0) >> + return 1; >> + >> + /* TPIDR2 is available. */ >> + return 2; > > Can you explain what is happening here? How does checking for success > reading NT_ARM_TLS telly ou that TPIDR2 exists? If you attempt a read of two registers - sizeof (tls_regs) - and it fails, it means the Linux Kernel doesn't support TPIDR2. Otherwise, it does. I'll add a comment making this a bit more clear. > > Simon > I'll send an updated version.