From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id aIEWAttnBWYLgBkAWB0awg (envelope-from ) for ; Thu, 28 Mar 2024 08:51:39 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=1nnf5jWk; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=1nnf5jWk; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E89421E0C0; Thu, 28 Mar 2024 08:51:38 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id BECA31E030 for ; Thu, 28 Mar 2024 08:51:36 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 471263858D28 for ; Thu, 28 Mar 2024 12:51:36 +0000 (GMT) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2060.outbound.protection.outlook.com [40.107.20.60]) by sourceware.org (Postfix) with ESMTPS id CC0B13858D20 for ; Thu, 28 Mar 2024 12:51:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CC0B13858D20 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 CC0B13858D20 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.20.60 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1711630273; cv=pass; b=jXEf2A8vCfW7Sq44iZ/v3MKyab1gtCOxUUoRwRA8hhqH2PvbvkTkdh8Flli+os74xtH3rRqAVDSF3DRdCdovxOFXWrMKcTvWSwGnwwVi/Cls25Pu+tSPc9XBrCQ0g7lqcbhKT/cUXK5uH2pP27M7IgWo6mJFoA4w3a4McAoRl+I= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1711630273; c=relaxed/simple; bh=/vOeOAMJEZos1cy7IV8kRfbfV0iCHHQ2xTUEy/zrDxM=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=QTLMb8y+g12GQspEnkh7iGwSGPo8dUhUj8zd4z1m6MJyZ3ayJHPE56z61vBHiGf2M2Oa62I+ggN0+joYknpT1MdoNPux+go0y4IBwj+XG2AIQXRbdinmJZK9VSpBJw2OhhkE1qGHpLAoFDM2DST7ZGIZ/7K8+B9G/6O8t2y0krw= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=RgbKvPNggJtVUF4077s0n1Cph1sDbisZPwJSeYMhLQkyVY46ZCgmRe5IxPbFz+3qK2oqMK5xVZS7ouqZ0GagSN+UNAJoTUAhxyiBQcaazbutGYt/QVeJkWqnCdv92S+ZGRIAVoPM3bCJx79iSrl/2B9DJr8pV7j+A0kTJDa/OuOWOV4x5ruZZnaKmGk74poKcMfKq4Kx49v65h2lMeSXxV3sugEPde+TNahjixHhUhKheRBcJ+db/aZWxIpSk+7oBg/51rq2o2Ild9qZiZqc3lw1As69TCufvjanHZiDGAsPRn8xL+V2HqOMHG0wbpslkN0gVkYKUA1EjvDFgS3i0g== 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=FN4hBEC1hJcoF4wTE3ZdExd0oZEWoUbO0AwM8/xFo5Q=; b=O5wd26beMtLn6qomsWDKPVfv40ZfDjCUWW/ZapJI+cfLtBVGvGEr8kR5IBWYoISkFzkePWj+2pDziZGCzOJ4O9JrWz1MYYVRNzKyxoABDjOWoCEiHmHagGP8Inm9cSQ9DuREkyEK9VOlQDfTVqCQnrlY1GRFkLAGQK5vudZhyyBebruydZOPHzbTtsKV+drG1x1wMJ20Y0gQHp+ujtrqDjLUiXlLxvNIN0KqJm7QwazIFIsMenKD2PjAcjkq8E5ThmrZD3e44qItJhD3X6UwxEOSdkOn5CUoL5k6x28FRTQvKlcr+QkikcF412+L3MxHOAyV88ZG0JKDd7I6rCYT4A== 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=FN4hBEC1hJcoF4wTE3ZdExd0oZEWoUbO0AwM8/xFo5Q=; b=1nnf5jWkUXF+Z7RE1RUpjWuKKwAV/6iS5/3XDwh+xykXz31I2/HdBsFlCt5pULo6zNG3tyHq4UABBwcyYCmYxSZ2e+dkFkr8haz3dUvd9p3W3OVwMmKiaN1Ca4/C/flPkgGWXYq3cbzbowr6zSbnXo4iC2QA2Ws+Eb2iImxRvGY= Received: from AM6P193CA0141.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::46) by AS2PR08MB9023.eurprd08.prod.outlook.com (2603:10a6:20b:5ff::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Thu, 28 Mar 2024 12:51:00 +0000 Received: from AM1PEPF000252DD.eurprd07.prod.outlook.com (2603:10a6:209:85:cafe::4) by AM6P193CA0141.outlook.office365.com (2603:10a6:209:85::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Thu, 28 Mar 2024 12:51:00 +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 AM1PEPF000252DD.mail.protection.outlook.com (10.167.16.55) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.10 via Frontend Transport; Thu, 28 Mar 2024 12:51:00 +0000 Received: ("Tessian outbound 1b0f2681ce6f:v300"); Thu, 28 Mar 2024 12:51:00 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 4365ec58f3274ffb X-CR-MTA-TID: 64aa7808 Received: from 1a8fcb66c71d.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 4CA09047-A3B8-4C38-B981-6956EEFB466E.1; Thu, 28 Mar 2024 12:50:52 +0000 Received: from EUR03-AM7-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 1a8fcb66c71d.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 28 Mar 2024 12:50:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XYltmiBnB6uKpL5MWTSFzqdxt6nG7PgtueNX42HYWfOGzNtiHtnHVKPTtvOK6lClaH4hrYrlKz5HNHbusJ0NIyxSzVXD+D4X69tVfrLIOri40kci5RUlH1fGTpw/l+rxutKMuyyz+QI/ENaRebfZKLpe2quXSYJNaVPJfulX4v97XxNfWTHkd5PAQqzgNjSZ54oUWzI+qxCaA3UKq5kMGaCCgTcWDPPqi4vJpezdy4+oca1pSIDlPESFMcWj4s68y+J7Fld29IxK3oGYWKLEYjLsbiD2XGrpdcHWTTmDCw93Xv9eAfyzAg0yZlQOSU+k74PtO3JbFmO+9y60WAxdzA== 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=FN4hBEC1hJcoF4wTE3ZdExd0oZEWoUbO0AwM8/xFo5Q=; b=QyEeoFesv/+PLiZ6RSjD3aOWnaL1FuC58uRYh5DOqbJNbOKL/Mbwa6JGFTbqSOdwYsyqYcLSqW6kKZ7SV+L0e/IoBA3zYyqXTHVn9oZT8hv5CGTIV0ckLNb7EEJ3XNsQl0t84Qv66ISEa3k3/OP1rcoOZMv4lApkg142i7YU2kzkWfe9Yytw7JbXQEzN92TKoEpWScugIcxJOj+ZBU0KyRRV8DxxXIbZ9DJG+xHa3V9yc2wzHdZl41Zwec2VJsyobL5fqBq1yxCt7CwBkDB1wV+SGGFsIH27Hci395bUXwoXGWKmRCuW/sf5iMrg0dv1tBSC9HrJ7RyOCQbn6OZlNA== 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=FN4hBEC1hJcoF4wTE3ZdExd0oZEWoUbO0AwM8/xFo5Q=; b=1nnf5jWkUXF+Z7RE1RUpjWuKKwAV/6iS5/3XDwh+xykXz31I2/HdBsFlCt5pULo6zNG3tyHq4UABBwcyYCmYxSZ2e+dkFkr8haz3dUvd9p3W3OVwMmKiaN1Ca4/C/flPkgGWXYq3cbzbowr6zSbnXo4iC2QA2Ws+Eb2iImxRvGY= 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 DBBPR08MB10650.eurprd08.prod.outlook.com (2603:10a6:10:52d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.30; Thu, 28 Mar 2024 12:50:50 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::363f:3fc8:fc36:58ed]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::363f:3fc8:fc36:58ed%5]) with mapi id 15.20.7409.031; Thu, 28 Mar 2024 12:50:50 +0000 Message-ID: <3e6ee87e-5b3a-4487-8e25-794419bebf26@arm.com> Date: Thu, 28 Mar 2024 12:50:48 +0000 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/3] LAM: Enable tagged pointer support for watchpoints. Content-Language: en-US To: "Schimpe, Christina" , gdb-patches@sourceware.org References: <20240327074739.2969623-1-christina.schimpe@intel.com> <20240327074739.2969623-3-christina.schimpe@intel.com> From: Luis Machado In-Reply-To: <20240327074739.2969623-3-christina.schimpe@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P265CA0261.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:37c::14) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|DBBPR08MB10650:EE_|AM1PEPF000252DD:EE_|AS2PR08MB9023:EE_ X-MS-Office365-Filtering-Correlation-Id: 62256697-6324-4a02-5271-08dc4f25b844 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: MAaK8x61f2F7YUZ9sRXynt7K7rqtYL1DzpomUIyXOaMMQg+Z7V8P+y/TtEv5jGKeIzH7ByyicCeg4zhqP9H6a2Um7ns9yZvT9XTQ+SHC9lqBdL+S6XXm5xNGJQfujOz8uiWiGFSv5X7YjFhp0Wv7yuiVWx1VCWxu6hWKAr6tOGpNwTrzTpfMU6i2Es72uWm1v7C/haXat0GuiTdlliA4odyeIVVKf9f6/xs5onz5JwpPl5efJwuTSeJp1vQ+6DimtwlrQGZEiPlUcMO0MruMLnDL2Ny9tQ9qLUrS1yRvRmU4HRkD/+FXsN+7GeQzLvL5iEvbrrCsYZFIkOkSJDpaK9Juc/bCVRKs9dgUS3HJzxYq0bZWHX8NRrUXVz5YMe65HzHhjEJPkgUT+uDsA6twvsdVr61UiqRq8lu56TYSWYM1IKRzDrOFTXL1uFie7nhIGVPQ1U3BFzoFVgdl1L045tZEOjd7LWMk43S8jq0Xk4fRmJbtmJ8vDqsMArmRt+T7R2I+Qc1tJfoRziaT93S26x9uCaWgR2bQF7f66lRaGEgdZiKB9OCEJBVHT77HDqsRhofNc6EjTD7TpaaUliccHeZc0n/Usm8LjtqISa+qTNA= 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)(366007)(1800799015)(376005); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB10650 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: AM1PEPF000252DD.eurprd07.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: c383fc82-1b99-44ce-3209-08dc4f25b248 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1S5aweEtaxTUNjBgD5sOBlW86YGNuINnyv2LCVTRSr6EzAUvI8sazVm7ZhEjnq8lFHE8sbS+EjYhrC0QyNY3Qd8zKN2kaIgIhQ5fuy3ZX9UWH0/nRorQNncBUho4MxqTOPJpDo8L+7qMYPC1U+gREdypfvtMIWN77TJ/DDwmb6QslD/FPrN6/5n4utYEX+YQ1Be/vDOjkLdj9bb4pW7hiTTLW3SDwfiLn+tgJnLZlMd9YOAE3epEVI0Njjm21krG/dTkVCwyrdMHeRzlWzs8cdv9ZSDEglm0AhPhJPSOUox17/aVZ20FwmFFun9FHP0FEABQPina8PjyvTr0FeYOwVjapYWbwPw2p4n94B+F+VVy2qJMfdgsR0xRSHyXj7mnRJjEZ16fMQmwrNkT5qrFhIZp4tZ9KdPDAlui41RwvacLpzZ9YrtQz4DEAM80w4vlskF528pUG7FNfIwe4BQ1Xkd1NEHahx04pMDRVmt25hmR5TDTvN0GvfAg8fhzj9vR5cQ7mHYH1unW7wYIeH5RdkoB7r3PMfRi7/Y7l0zrRUM7xqDIlVNsv1/hOJ0YETq0V0Gpqa3ZsJlqgh8yBGk8p1VV4FBMX7RHbHtquJT0sp55RXv7VWROWo3Ze66K/rAjlj40sCx2ays5l9XpuyXWGsW6rlHF33h+7iATxZe11mMPsXvifIpbDbc0L5+OjJ1AhrXswRuMkwN2TOaEfjeoqw== 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)(1800799015)(376005)(82310400014)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2024 12:51:00.3012 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 62256697-6324-4a02-5271-08dc4f25b844 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: AM1PEPF000252DD.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB9023 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, KAM_SHORT, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org On 3/27/24 07:47, Schimpe, Christina wrote: > From: Christina Schimpe > > The Intel (R) linear address masking (LAM) feature modifies the checking > applied to 64-bit linear addresses. With this so-called "modified > canonicality check" the processor masks the metadata bits in a pointer > before using it as a linear address. LAM supports two different modes that > differ regarding which pointer bits are masked and can be used for > metadata: LAM 48 resulting in a LAM width of 15 and LAM 57 resulting in a > LAM width of 6. > > This patch adjusts watchpoint addresses based on the currently enabled > LAM mode using the untag mask provided in the /proc//status file. > As LAM can be enabled at runtime or as the configuration may change > when entering an enclave, GDB checks enablement state each time a watchpoint > is updated. > > In contrast to the patch implemented for ARM's Top Byte Ignore "Clear > non-significant bits of address on memory access", it is not necessary to > adjust addresses before they are passed to the target layer cache, as > for LAM tagged pointers are supported by the system call to read memory. > Additionally, LAM applies only to addresses used for data accesses. > Thus, it is sufficient to mask addresses used for watchpoints. > > The following examples are based on a LAM57 enabled program. > Before this patch tagged pointers were not supported for watchpoints: > ~~~ > (gdb) print pi_tagged > $2 = (int *) 0x10007ffffffffe004 > (gdb) watch *pi_tagged > Hardware watchpoint 2: *pi_tagged > (gdb) c > Continuing. > Couldn't write debug register: Invalid argument. > ~~~~ > > Once LAM 48 or LAM 57 is enabled for the current program, GDB can now > specify watchpoints for tagged addresses with LAM width 15 or 6, > respectively. > --- > gdb/NEWS | 2 + > gdb/amd64-linux-tdep.c | 67 ++++++++++++++++++++++++++++ > gdb/testsuite/gdb.arch/amd64-lam.c | 49 ++++++++++++++++++++ > gdb/testsuite/gdb.arch/amd64-lam.exp | 45 +++++++++++++++++++ > gdb/testsuite/lib/gdb.exp | 62 +++++++++++++++++++++++++ > 5 files changed, 225 insertions(+) > create mode 100755 gdb/testsuite/gdb.arch/amd64-lam.c > create mode 100644 gdb/testsuite/gdb.arch/amd64-lam.exp > > diff --git a/gdb/NEWS b/gdb/NEWS > index feb3a37393a..295f2147def 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -3,6 +3,8 @@ > > *** Changes since GDB 14 > > +* GDB now supports watchpoints for tagged data pointers on amd64. > + > * The MPX commands "show/set mpx bound" have been deprecated, as Intel > listed MPX as removed in 2019. > > diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c > index 9d560ac4fbf..94c62277623 100644 > --- a/gdb/amd64-linux-tdep.c > +++ b/gdb/amd64-linux-tdep.c > @@ -41,6 +41,7 @@ > #include "arch/amd64.h" > #include "target-descriptions.h" > #include "expop.h" > +#include "inferior.h" > > /* The syscall's XML filename for i386. */ > #define XML_SYSCALL_FILENAME_AMD64 "syscalls/amd64-linux.xml" > @@ -48,6 +49,10 @@ > #include "record-full.h" > #include "linux-record.h" > > +#include > + > +#define DEFAULT_TAG_MASK 0xffffffffffffffffULL > + > /* Mapping between the general-purpose registers in `struct user' > format and GDB's register cache layout. */ > > @@ -1794,6 +1799,65 @@ amd64_dtrace_parse_probe_argument (struct gdbarch *gdbarch, > } > } > > +/* Extract the untagging mask based on the currently active linear address > + masking (LAM) mode, which is stored in the /proc//status file. > + If we cannot extract the untag mask (for example, if we don't have > + execution), we assume address tagging is not enabled and return the > + DEFAULT_TAG_MASK. */ > + > +static CORE_ADDR > +amd64_linux_lam_untag_mask () > +{ > + if (!target_has_execution ()) > + return DEFAULT_TAG_MASK; > + > + inferior *inf = current_inferior (); > + if (inf->fake_pid_p) > + return DEFAULT_TAG_MASK; > + > + /* Construct status file name and read the file's content. */ > + std::string filename = string_printf ("/proc/%d/status", inf->pid); > + gdb::unique_xmalloc_ptr status_file > + = target_fileio_read_stralloc (nullptr, filename.c_str ()); > + > + if (status_file == nullptr) > + return DEFAULT_TAG_MASK; > + > + /* Parse the status file line-by-line and look for the untag mask. */ > + std::istringstream strm_status_file (status_file.get ()); > + std::string line; > + const std::string untag_mask_str ("untag_mask:\t"); > + while (std::getline (strm_status_file, line)) > + { > + const size_t found = line.find (untag_mask_str); > + if (found != std::string::npos) > + { > + const size_t tag_length = untag_mask_str.length(); > + return std::strtoul (&line[found + tag_length], nullptr, 0); > + } > + } > + > + return DEFAULT_TAG_MASK; > +} > + > +/* Adjust watchpoint address based on the tagging mode which is currently > + enabled. For now, linear address masking (LAM) is the only feature > + which allows to store metadata in pointer values for amd64. Thus, we > + adjust the watchpoint address based on the currently active LAM mode > + using the untag mask provided by the linux kernel. Check each time for > + a new mask, as LAM is enabled at runtime. Also, the LAM configuration > + may change when entering an enclave. No untagging will be applied if > + this function is called while we don't have execution. */ > + > +static CORE_ADDR > +amd64_linux_remove_non_addr_bits_wpt (gdbarch *gdbarch, CORE_ADDR addr) > +{ > + /* Clear insignificant bits of a target address using the untag mask. > + The untag mask preserves the topmost bit, which distinguishes user space > + from kernel space address. */ > + return (addr & amd64_linux_lam_untag_mask ()); > +} > + > static void > amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch, > int num_disp_step_buffers) > @@ -1848,6 +1912,9 @@ amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch, > > set_gdbarch_get_siginfo_type (gdbarch, x86_linux_get_siginfo_type); > set_gdbarch_report_signal_info (gdbarch, i386_linux_report_signal_info); > + > + set_gdbarch_remove_non_addr_bits_wpt (gdbarch, > + amd64_linux_remove_non_addr_bits_wpt); > } > > static void > diff --git a/gdb/testsuite/gdb.arch/amd64-lam.c b/gdb/testsuite/gdb.arch/amd64-lam.c > new file mode 100755 > index 00000000000..28786389a9a > --- /dev/null > +++ b/gdb/testsuite/gdb.arch/amd64-lam.c > @@ -0,0 +1,49 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2023 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +#define _GNU_SOURCE > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +int > +main (int argc, char **argv) > +{ > + int i; > + int* pi = &i; > + int* pi_tagged; > + > + /* Enable LAM 57. */ > + errno = 0; > + syscall (SYS_arch_prctl, ARCH_ENABLE_TAGGED_ADDR, 6); > + assert_perror (errno); > + > + /* Add tagging at bit 61. */ > + pi_tagged = (int *) ((uintptr_t) pi | (1LL << 60)); > + > + i = 0; /* Breakpoint here. */ > + *pi = 1; > + *pi_tagged = 2; > + *pi = 3; > + *pi_tagged = 4; > + > + return 0; > +} > diff --git a/gdb/testsuite/gdb.arch/amd64-lam.exp b/gdb/testsuite/gdb.arch/amd64-lam.exp > new file mode 100644 > index 00000000000..8274c3adf97 > --- /dev/null > +++ b/gdb/testsuite/gdb.arch/amd64-lam.exp > @@ -0,0 +1,45 @@ > +# Copyright 2023 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Test Linear Address Masking (LAM) support. > + > +require allow_lam_tests > + > +standard_testfile amd64-lam.c > + > +# Test LAM 57. > +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { > + return -1 > +} > + > +if { ![runto_main] } { > + return -1 > +} > + > +gdb_breakpoint [gdb_get_line_number "Breakpoint here"] > +gdb_continue_to_breakpoint "Breakpoint here" > + > +# Test hw watchpoint for tagged and untagged address with hit on untagged > +# and tagged adress. > +foreach symbol {"pi" "pi_tagged"} { > + gdb_test "watch *${symbol}" > + gdb_test "continue" \ > + "Continuing\\..*Hardware watchpoint \[0-9\]+.*" \ > + "run until watchpoint on ${symbol}" > + gdb_test "continue" \ > + "Continuing\\..*Hardware watchpoint \[0-9\]+.*" \ > + "run until watchpoint on ${symbol}, 2nd hit" > + delete_breakpoints > +} > diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp > index d48ea37c0cc..c7d15f82da1 100644 > --- a/gdb/testsuite/lib/gdb.exp > +++ b/gdb/testsuite/lib/gdb.exp > @@ -9285,6 +9285,68 @@ gdb_caching_proc allow_ctf_tests {} { > > return $can_ctf > } > +# Run a test on the target to see if it supports LAM 57. Return 1 if so, > +# 0 if it does not. Based on the arch_prctl() handle ARCH_ENABLE_TAGGED_ADDR > +# to enable LAM which fails if the hardware or the OS does not support LAM. > + > +gdb_caching_proc allow_lam_tests {} { > + global gdb_prompt inferior_exited_re > + > + set me "allow_lam_tests" > + if { ![istarget "x86_64-*-*"] } { > + verbose "$me: target does not support LAM, returning 1" 2 > + return 0 > + } > + > + # Compile a test program. > + set src { > + #define _GNU_SOURCE > + #include > + #include > + #include > + #include > + > + int configure_lam () > + { > + errno = 0; > + syscall (SYS_arch_prctl, ARCH_ENABLE_TAGGED_ADDR, 6); > + assert_perror (errno); > + return errno; > + } > + > + int > + main () { return configure_lam (); } > + } > + > + if {![gdb_simple_compile $me $src executable ""]} { > + return 0 > + } > + # No error message, compilation succeeded so now run it via gdb. > + > + set allow_lam_tests 0 > + clean_restart $obj > + gdb_run_cmd > + gdb_expect { > + -re ".*$inferior_exited_re with code.*${gdb_prompt} $" { > + verbose -log "$me: LAM support not detected." > + } > + -re ".*Program received signal SIGABRT, Aborted.*${gdb_prompt} $" { > + verbose -log "$me: LAM support not detected." > + } > + -re ".*$inferior_exited_re normally.*${gdb_prompt} $" { > + verbose -log "$me: LAM support detected." > + set allow_lam_tests 1 > + } > + default { > + warning "\n$me: default case taken." > + } > + } > + gdb_exit > + remote_file build delete $obj > + > + verbose "$me: returning $allow_lam_tests" 2 > + return $allow_lam_tests > +} > > # Return 1 if compiler supports -gstatement-frontiers. Otherwise, > # return 0. I'll leave the amd64-specific bits for the responsible maintainers. But I noticed the copyright year is wrong (2023 -> 2024).