From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on2079.outbound.protection.outlook.com [40.107.15.79]) by sourceware.org (Postfix) with ESMTPS id 255143858D35 for ; Tue, 16 Apr 2024 18:04:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 255143858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 255143858D35 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.15.79 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1713290670; cv=pass; b=IZ88kv5bCHTCWGzzxPFRTvMkHWzKy00u3zTvtcXZLId+U8uW6ANmIWUdGdEVRJo7uaKUwd7naCipj3D8cIBY6lx3JHCB+XobO4PGe2+PgY8OBVRK1EuCykJa5I9Cmw1aU+5aESziwORFvRNoHCIlHQlbFBaDjMI79d4SvLldmEI= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1713290670; c=relaxed/simple; bh=ozQ8W+CcP/5fNK4h3KY58YjGEVo3m7wA1EQ9n7S3vZ4=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=KxI+ij3xOUU/dB0stjilYdh2emFvQw+wLJLw3bcbiFqwxmuSlG+weWlWovqHmvCPOuErSx9G46As4GYiTQRSTNq/S+O5LT1f9gplOXVnuGOxVJ+LkgUoVgkLuh2vXBADr5Kljmn95WQRU3OEaSHIJkNM7EPuSvj2+SoE7dahiXY= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=ax+djoF/URPeqq9Nj1CY35zFXGMv2l4WLU0f2klaEcTLBYc6i8GBctkUk2jRcvYvhR30nsTx53TV5T47u8EB+MdwTX71p6ucFvos49G8GOnebJw5hU1Asi1GRT6AIwJ3p3ANsgxawGz6eTIm5oRcypNVJFHuM0MK2Bilv/YFMod1GQywvMILFweYjQ62E5U42SUtci0mPF4sqCxkGPpIbjymUANYvXyKWhS+MP/1kcjGO4LkRR6bfyZ7Xnv67shNqYMY6ZGWKqZHnQ6n3B2YDhgLHRgOx9iS1S//eWkNrz+Ax+9hWDpqiZ17HLTfAyJnHKjZ887+jQEh+2fRYJdvIA== ARC-Message-Signature: i=2; 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=7AvRTIZeMTuIgMfJEdN+U/+2oppNBaWEIEkXT3vFI00=; b=BZX/8LLoK3PsSA7juiJsfeMZML/PSE5h5WmHIxwGK3vF6F4zxRXwyjbCCqQLDuP5NPHwAgG43hFjwkKQ1JFkKSA+ZUdmBs4mjIk8FVR1X7OV4Hvu6slW4LGMk3BhB1DpJgmhkWjp2ULMpwVi0VscXHTziw+ZKFRUoAVk4HkOLL7sccDRK9MKkerHVWp6JzZRi3TvHuEw36xjD7CU9yezwcpWxaPR4+eNajln5n3IiFjavBNtL77/V/tUvNh2+zlBGze6KaqjKDmYzWM0/wlrF8nXkaIWIatd2U6v2OGuP05jbQR7swb6hcBVTVOjWNqU7B23llvulNUyySA25UQGwQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=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=7AvRTIZeMTuIgMfJEdN+U/+2oppNBaWEIEkXT3vFI00=; b=FE04W71t2NlQrv1MFQ2cdAhrLOwzAavnXKkcB/NzGZ4ywhbw8ClFvyc6QgURWb2E/wGFUnwqA0CX7XdliQs3xzNgwOJqAL3Dwgw3nBXFjBZ3qx2iueHagb1kYvgjgtyRE7fsebRhEWcrTX/9AoOLw3g0UyXb/wOoCvsbDhfMXE8= Received: from AS9PR04CA0074.eurprd04.prod.outlook.com (2603:10a6:20b:48b::8) by AS8PR08MB7918.eurprd08.prod.outlook.com (2603:10a6:20b:539::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Tue, 16 Apr 2024 18:04:16 +0000 Received: from AMS1EPF0000003F.eurprd04.prod.outlook.com (2603:10a6:20b:48b:cafe::45) by AS9PR04CA0074.outlook.office365.com (2603:10a6:20b:48b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.20 via Frontend Transport; Tue, 16 Apr 2024 18:04:16 +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 AMS1EPF0000003F.mail.protection.outlook.com (10.167.16.36) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Tue, 16 Apr 2024 18:04:16 +0000 Received: ("Tessian outbound 9fd7e4b543e6:v313"); Tue, 16 Apr 2024 18:04:15 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3d9ee429d0e090c6 X-CR-MTA-TID: 64aa7808 Received: from f61906f07eb2.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9952ECD2-A468-4287-9817-68E3193D50C7.1; Tue, 16 Apr 2024 18:04:09 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f61906f07eb2.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 16 Apr 2024 18:04:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ht8L35PsO9/m1ZyJvkzRhI1tY2BMy7VTvu9y+RylIHiK5s2byYiPrOsDBZb1gKRsh55CIKopQ+GhiN8IpGTJ8uZr0nQnPOugDG32k3sLMxkXXdL2dIHEn5E9kE7ej968OsDh1CsP172q1zxf68Q+584ZjpVVF9bzzI22E4B/gLRs1wtGUrTYtZASLC4qkMDiHw6YRCiNbc3ihDaKlKLnjfRGewDSGXOaQ7ZHIEeg6Qdi7Xfy2BbaBY9EdMfG0h2dWb3dY0w/szxcgt7lOpAAek26qEPpzYQftPvAUugO9oNsgbtJy/ft15X3xIKOaGsb0Tfuf9VBPlN5mAlHSbrCgw== 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=7AvRTIZeMTuIgMfJEdN+U/+2oppNBaWEIEkXT3vFI00=; b=XrPI4neGGuQ4amSnU4LInIU53H9m+tWOKHM9qnAR5I80TDe+y5/82nbY1OjPfe1TCqKKCsDxzr1h7bwdNNz0aTJKqxfZ5RFSZfmtiYae9h4FH7qZEuKBMY0Tcg58aghaOmi/LZf0L3cxOJlEd/1NF5ynj59a4afjyPncx6t/467eyWhObaQAPXTgMS24eN+RhjATCtQTQKjSYL4YJ96DP9MFKsdga6znQWd/V2+dmZ0OvFpGG+eH3LMyBebw9MsSAggWl4RCDg74SA8LdiPgVncXwRkBZ38ZAtnsj7yfJe4ibqmTaq2H1pM+0XnBFXOsRRCg/LS+mXSOpBngdhWxfg== 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=7AvRTIZeMTuIgMfJEdN+U/+2oppNBaWEIEkXT3vFI00=; b=FE04W71t2NlQrv1MFQ2cdAhrLOwzAavnXKkcB/NzGZ4ywhbw8ClFvyc6QgURWb2E/wGFUnwqA0CX7XdliQs3xzNgwOJqAL3Dwgw3nBXFjBZ3qx2iueHagb1kYvgjgtyRE7fsebRhEWcrTX/9AoOLw3g0UyXb/wOoCvsbDhfMXE8= 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 DU5PR08MB10678.eurprd08.prod.outlook.com (2603:10a6:10:528::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.55; Tue, 16 Apr 2024 18:04:06 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::77d4:d040:b19d:6472]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::77d4:d040:b19d:6472%4]) with mapi id 15.20.7452.049; Tue, 16 Apr 2024 18:04:06 +0000 Message-ID: <790c7439-341f-4ae3-87d4-b63f2a4a33a3@arm.com> Date: Tue, 16 Apr 2024 19:04:04 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 6/8] gdb: Add qIsAddressTagged packet Content-Language: en-US To: Gustavo Romero , gdb-patches@sourceware.org Cc: thiago.bauermann@linaro.org, eliz@gnu.org, tom@tromey.com References: <20240416140728.198163-1-gustavo.romero@linaro.org> <20240416140728.198163-7-gustavo.romero@linaro.org> From: Luis Machado In-Reply-To: <20240416140728.198163-7-gustavo.romero@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P265CA0338.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:d::14) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|DU5PR08MB10678:EE_|AMS1EPF0000003F:EE_|AS8PR08MB7918:EE_ X-MS-Office365-Filtering-Correlation-Id: 2394413a-ad7d-43d4-d40c-08dc5e3fa14d 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: 9qmn4bFr1QhKVhVeC/bisVyRyrcSCARNGV2nqn3oUcd+SlB+a+tkjr9ekFbZZA8HigpcYpPfH8IP6zReki4oYJyJLaX0x7oVSAaQY5onV2JpvWg65kSX8+wcY9I6gyTqp8zeNAr5iiW4ZOSd3T9eba7SHm0xU01+6gzbpJwJ9c/mZA1J+YY5PjCdIChz3QlHTcO71tt2RwRzRyIbBY2U4R1XwmpFVAaj/toAU3nBKwuKm5yGWg6OEF/yEA2oZHUxu+IzUhOe2NhqExKj2II77KB7viQxtFM/bqJ9iPSXFn///wzGw//FiLnFnJnBQ5FXPhZFof+qy9Oh8y25VieeLuZ5GSi3PN+GoTZIV/ENCfCHiJULXNrUmqHHo2HPQ+vMbV7L/XP1s5kXUVvpb1DsbOsDzbGdEnW76ZNWteSbPQhUM8Y2ydlxexlgye/xkBmlgWlVKQ3XFMUr3z25BB9TeLuy/Opa8rU0ednn1jDxa0CMr22baz41c5OvtH0SCsEcX4uVf/LohL08tpTLYtRZXFuo8fhf+dShF+KFmxHYd8BjoDTLcSXYGBgiHUs5u2moPA0CHWOedAV6v1mErqLNTIBkswet/ZirpC9S5A8DTmKLURZ8lcpjlNVtgpxux90vinSHSbsgfyUp7jout+y3Hq3sMkQJzvZiVghZIRew+n4= 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:(13230031)(376005)(366007)(1800799015);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU5PR08MB10678 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: AMS1EPF0000003F.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 96b9ccda-58e6-46f8-5e5b-08dc5e3f9b50 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VCyKkGQnCnuTmSU1jwoKrDwkHNdcGT16YZFHcLQSzT2WPCmrPlb+gr7dfilMCW23aKrhQgn/r7s9zTnJrpfbDyxFx5gIE1pJL57miBXu3HcP8Veupdjh41+jpRjsJzQdFiGA+pppcqbDi0REcX7D1lEMZl3kHqmClBBOVPEAkJk2S64Hz4NQCDZi5yosn6jAU1bvTtM7fqGhBpi6NKmuH5EKnFdd+OWqsHM1vnNwHd16finy0aUscG5HmVrP4ZA6l/3j9e1APRIbinLB6fAP5g4DTy8G0VuXkrNRrbFk95g9PvkD1US0VmMRbaDxubB1S21g0SFpVZo4K4p0w8ZVYbYRrbR83KMLIf0ZZFZKAN+f8xt1zA8JnYWgqxw9ZVTMqOyfqmOHO74pG+thblpNvvHBgkzIxpBICmmiylgEP/3GhBZPlQJM9WfCWEYWgJv7rN8CfprNLg5GCC+iDNjkj/mhldGVqQEmc5Iv3b3taaxQuDfEDUID+OB6ubo1asn3bFhWrHn5N+vqyaGnAtEKo7Vicau+JYSZtMTKdk765MJ+aUcgeKJr7777nHOdlPpWM8j+hzj+8nQ+spNj3mr+j6Jd0b0BkuqwLU4s85vfVge9c5v0lo71/WoLAS9aFKjfxNN8TiPUSnY1JyI3heND46bo3bboqa6vE5AeHg2Avlz2Hm3fxXVcYoI624XR8GVGtFpk0Tc0xQSb9wUwg6PyfZae5SI9X7L4NLNwLM08wwiH2v7fDtVT14dunkNTpwp3 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:(13230031)(82310400014)(36860700004)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Apr 2024 18:04:16.1482 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2394413a-ad7d-43d4-d40c-08dc5e3fa14d 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: AMS1EPF0000003F.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB7918 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_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: Close, by I still have a few comments below. On 4/16/24 15:07, Gustavo Romero wrote: > This commit adds a new packet, qIsAddressTagged, allowing GDB remote > targets to use it to query the stub if a given address is tagged. > > Currently, the memory tagging address check is done via a read query, > where the contents of /proc//smaps is read and the flags are > inspected for memory tagging-related flags that indicate the address is > in a memory tagged region. > > This is not ideal, for example, for QEMU stub and other cases, such as > on bare-metal, where there is no notion of an OS file like 'smaps.' > Hence, the introduction of qIsAddressTagged packet allows checking > if an address is tagged in an agnostic way. > > The is_address_tagged target hook in remote.c attempts to use the > qIsAddressTagged packet first for checking if an address is tagged and > if the stub does not support such a packet (reply is empty) it falls > back to using the current mechanism that reads the contents of > /proc//smaps via vFile requests. > > Signed-off-by: Gustavo Romero > --- > gdb/remote.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 49 insertions(+) > > diff --git a/gdb/remote.c b/gdb/remote.c > index 9717db55e27..63799ac5e3f 100644 > --- a/gdb/remote.c > +++ b/gdb/remote.c > @@ -15534,6 +15534,40 @@ create_store_memtags_request (gdb::char_vector &packet, CORE_ADDR address, > strcpy (packet.data (), request.c_str ()); > } > > +static void > +create_is_address_tagged_request (gdbarch *gdbarch, gdb::char_vector &packet, > + CORE_ADDR address) > +{ > + int addr_size; > + std::string request; > + > + addr_size = gdbarch_addr_bit (gdbarch) / 8; > + request = string_printf ("qIsAddressTagged:%s", phex_nz (address, addr_size)); > + > + if (packet.size () < request.length () + 1) > + error (_("Contents too big for packet qIsAddressTagged.")); > + > + strcpy (packet.data (), request.c_str ()); > +} > + > +static bool > +check_is_address_tagged_reply (gdb::char_vector &packet, bool *tagged) Instead of passing TAGGED as pointer, make it a reference. It is safer. > +{ > + if (packet_check_result (packet).status () != PACKET_OK) This function signature is incorrect and leads to a build error. This function has two arguments. Also, this check will return false if the packet yields an error and if the packet is not supported. We need to be able to distinguish between unsupported and error here, right? > + return false; > + > + gdb_byte reply; > + /* Convert only 2 hex digits, i.e. 1 byte in hex format. */ > + hex2bin (packet.data (), &reply, 1); > + > + if (reply == 0x00 || reply == 0x01) { > + *tagged = !!reply; Passing tagged as reference just use tagged instead of *tagged here. > + return true; > + } > + > + return false; > +} > + > /* Implement the "fetch_memtags" target_ops method. */ > > bool > @@ -15580,6 +15614,21 @@ remote_target::store_memtags (CORE_ADDR address, size_t len, > bool > remote_target::is_address_tagged (gdbarch *gdbarch, CORE_ADDR address) > { > + struct remote_state *rs = get_remote_state (); > + bool is_addr_tagged; > + Before sending the packet, we need to check if the packet is supported. Generally gdb will send it the first time around, but if the packet isn't supported gdb shouldn't keep sending these packets if the stub is gonna reply empty again. See remote_target::remote_query_attached for an example of how we deal with this. First you need to have a new enum PACKET_qIsAddressTagged, so we can register if the packet is supported or not at runtime. Then at the start of the function: if (m_features.packet_support (PACKET_qIsAddressTagged) != PACKET_DISABLE) { /* Use the qIsTaggedAddress packet. */ } else { /* Use the fallback smaps method. */ } That way gdb only sends the qIsTaggedAddress packet once. If it works, then gdb keeps using it. Otherwise it always uses the fallback. > + /* Firstly, attempt to check the address using the qIsAddressTagged > + packet. */ > + create_is_address_tagged_request (gdbarch, rs->buf, address); > + > + putpkt (rs->buf); > + getpkt (&rs->buf); > + > + if (check_is_address_tagged_reply (rs->buf, &is_addr_tagged)) We should pass is_addr_tagged by reference instead. > + return is_addr_tagged;> + > + /* Fallback to arch-specific method of checking whether an address is tagged > + if qIsAddressTagged fails. */ > return gdbarch_tagged_address_p (gdbarch, address); > } >