From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10066.outbound.protection.outlook.com [40.107.1.66]) by sourceware.org (Postfix) with ESMTPS id 384133858CDA for ; Fri, 19 Aug 2022 09:53:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 384133858CDA ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=TaNu+xAJujvNp8vMWqgkmKjPzKK/q0DuNwOqt+f5L4n8h/i+4isWmwrmPj0HUHO6N4opzHLXTkInT9zgwqF9pDfOwFc3wzxQ9L5XiQ917mxIITsRnCUbpGwxvJsyMy+77Alte+ByzSOWqGbBUPD4gsyxgHpGDO4r+uhOlqPKTcMC1h7c5ly9RLbczTQns+1q8MMgZb/lwqHgDaZ1hanbbuKbpeNw7IEt+40SSOuhXdVBl1IPkbweeTSoLahubuh+Av8sUCVExwoC9LQX7IdIIPCfatX9XDoy5NZU/Q/7GCSP/BCY4ymqSO3e8z3af0K2D6ZA37JRsObl+XRZixcU+Q== 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=KVwTJKLJHMTv3Dxrg8ifg1I0OlMz+85/CHIkwq/YEBI=; b=ROCKOK3W+NDmeZNriq+YA+29rPaIIBGvAwq7Uw/Rka8lGbND63v9oZ17ohk0YDq6YswEx6LipX4gI1H8ny7svvlUSRbZrhLYIJ1zVK2kSFFzJ1VSxyWXmg/R7Xj61rcWryrRZEXx8kGYVJs1lDDOrMAwZyQbR8J2VfR8jSGq8UqXShccYDdD2kaAuiEVheu3nIH6SNsqkWBDIeBLTO4kkdwq6JDzYsLI8ipQh/rymwwLMp75/V+cCJ9CNbIgiywsrjmX4qjyqiJ8QYsCZM80218x8EYE+z2beYTmXXcYxtqDkm4KBPga6QexjTxHg0jiOQezqBAoV/d/yTfVVYJNHA== 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]) Received: from AS9PR06CA0216.eurprd06.prod.outlook.com (2603:10a6:20b:45e::30) by DBBPR08MB6124.eurprd08.prod.outlook.com (2603:10a6:10:202::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.16; Fri, 19 Aug 2022 09:53:07 +0000 Received: from VE1EUR03FT060.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45e:cafe::d) by AS9PR06CA0216.outlook.office365.com (2603:10a6:20b:45e::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.19 via Frontend Transport; Fri, 19 Aug 2022 09:53:06 +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 VE1EUR03FT060.mail.protection.outlook.com (10.152.19.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.15 via Frontend Transport; Fri, 19 Aug 2022 09:53:06 +0000 Received: ("Tessian outbound cc6a8ab50b6b:v123"); Fri, 19 Aug 2022 09:53:05 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 93646b13d19b2f46 X-CR-MTA-TID: 64aa7808 Received: from 0d1870bba350.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A8B25DF7-9595-45C6-8B70-A3A625CC298E.1; Fri, 19 Aug 2022 09:52:59 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 0d1870bba350.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 19 Aug 2022 09:52:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hysbSdRPhoSVTD0m29abF6zMgdudYa+7xrbC/GxpypECmZ0ZKgzhXq9wNYBk6VWYAC17aLafpiJneT2JE9yRiTxfT0Dd/W58ErDDb9oygrmIm5qCVm6ttXD9v/k1VEUrpoqTD++8JPXaaBvu/qLFb/nDdJxwROdGUSCQF2PMQMxjqHssk2CHDTI1oU2c9DzgeMKYiRzVS1T5Efcm7g/YGmUQAjzNBEf0Oa7yahv5q1uXmihcA0OA67wxro378RKs4cPA9BzSctCw4GNlK8E+hhS7+Ge9tbJcbMuiE3F+T859PKXWsQbx+ZvKVo0l+aGv+zyh8EULDOGUoBJOGQDYww== 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=KVwTJKLJHMTv3Dxrg8ifg1I0OlMz+85/CHIkwq/YEBI=; b=FDrh5Dbbxc7p6wsVEY2azcaO1vH5MKG+vTa9uATXDFrzRAn+lYtHSPyq2vJA5IzKgzWxIvnIyEUb1qVpaUTYDF01d8ys5PMVsmP45BuK7paNrZe4HuUxY3P4/mYqqLnTKHsE03jyLYWPSGr3Ozu2fi7eBQtOQNaC7ZMemod9vBuQ2ghT3Ny/VJCUWUxkphuD4geKz7DbYN7tF10e0/kmr6gbSnP76gdh5IU6mq8HB1+SibdPeg3BkjYaRJWi0ybBMKQKnZdx+0yt88o8JAtTeebFUY5JeuzQgN4BGOQSkAVGvScUkdZb3ehZTs3mA462IALQDBoffV5qYIjaAFAURA== 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 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 DBBPR08MB4855.eurprd08.prod.outlook.com (2603:10a6:10:da::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Fri, 19 Aug 2022 09:52:56 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::cc64:9170:b12d:de8]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::cc64:9170:b12d:de8%4]) with mapi id 15.20.5504.028; Fri, 19 Aug 2022 09:52:55 +0000 Message-ID: Date: Fri, 19 Aug 2022 10:52:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH,v2] [aarch64] Fix removal of non-address bits for PAuth Content-Language: en-US To: Thiago Jung Bauermann Cc: lsix@lancelotsix.com, gdb-patches@sourceware.org References: <20220705140037.135012-1-luis.machado@arm.com> <20220711115534.23810-1-luis.machado@arm.com> <87o7wh2jy2.fsf@linaro.org> From: Luis Machado In-Reply-To: <87o7wh2jy2.fsf@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: LO4P123CA0296.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:196::13) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: b4ed1d21-2592-4abd-8744-08da81c89d6f X-MS-TrafficTypeDiagnostic: DBBPR08MB4855:EE_|VE1EUR03FT060:EE_|DBBPR08MB6124:EE_ 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: cCGhEtilnbIl6YsD3yhCfGdK89lq1sKunQqS2Q/6PKs5xWJohgphB0ddcl55SjucqcfeEVls5OxaGy4WO4N3Sby7fXRqcloVHNpw5Eh7pBeYXA2ynSXoKbpFepDeXM6OmtN2yRxYkJNP0kWlaBMlZv53YzJpewKuue7YI6ELfx7Hl3VIl2LJZ54MfzMAcmpyFmhqbqkVrZcqSLK6gNDz+MxZj3PMlSxU9cjRkwfx9yW8JRzlMGhuWz8+0W8opagv50T1eCFxA3a+XsH0YNkEPXka4wT7jFNXLDQNb2nZ2FOHQpoyW/vEN5mYD+yy8lrqLwWftZ0+LSdpB6AHJ0TeNjxfcM/XB3NpJGIhCRnKP+JWNmNZ+rGW/Vd7LQx8Yq1qvykfFzF25BWYPnv0LDcM1xldVk7iNXnXlRVgoxrHfwfMYF/MQN+wA2rTAxivJV4Z8akacYEnZY01BIzB1ELPAn1EeSXWNyAGzWjqQC1CVqXqA2x05uWpXOjn/61cIo2Iem3QVypZX9d7q8WKkFbQaj6EyT/YP3Y6bMyFp+5eJfv20KUhPMFdupQnJEnuEoFBzs3N47IxpnGUoRrErHNmjmcApIZJcPttVUI5h1tHlgiwWXhSNKdFNdW6Tu4i3IwXc2TNNQy2LZ+cJ0OKG89sZYdFyT9w9G70wbBt+18GqhBijdSHmx4IzZUsk5pFTj5H01Rii04+tXYhK32XB7WQVRxRck1S/emfUixWOqab2vxPIH8KK8jLsiWAAaVzQ9G5iIA0y79h23FPK2kMiqjPVdH+0M0p7M75aK5eMgGVVf0= 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:(13230016)(4636009)(366004)(396003)(39860400002)(376002)(136003)(346002)(6512007)(186003)(2616005)(83380400001)(5660300002)(4326008)(44832011)(8676002)(53546011)(41300700001)(31686004)(36756003)(6486002)(478600001)(6506007)(26005)(6666004)(31696002)(86362001)(66946007)(8936002)(66556008)(2906002)(66476007)(316002)(6916009)(38100700002)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4855 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: VE1EUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 77b6b607-9b3d-434d-b304-08da81c896b9 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FvvDiBzrdt3sHW7dbiNO1mlA65sb+cEous6jDBs8PuJx/aNzlDbc0zF0Uxdog4QcyaPpQK58D3C3oaf41jrN2q5CQKryGqRvhV+ENKHgozgp/ARfzqzOR8+d8wN/+I4FU2jtu1kjTIscVBpVBCrUlry5hPoN+osFTXUDxj0h0xyk/3UlGODDqccTDhqA0nMoZ2R4bsPoY8aPaVMFdK/bV9Si4q63PHJsLlpqG+LVWD0+aNVyG1AhHCOJgaeZ7SY5UV2EC4mEOw5fd2pokMdmIOlbZLO0G+WXIAEsFs/VdS6RkwYkOFHz3w4MNdY16aOgrUaW2sMGOu4hFxxLvx6jepeMoQj7+9AkyzmcjpIVGK9ts2NAViBcDIqxiinP+VXVYaWQvKbjrWZMpvuvOgIEAtn6+7fSvWreLHgWko0qF8X+cOnbiqU+udpBkxmYyARfbG2yqBLpk3C3se+rITlRYU8OtYo9yyBmFzVqONkiqOhWS/c2Mhx1O2i/YrF5Y5suGLfSHPsIRS8hGkSSDkJfGhCLwxqGVvi2WlXkum3Alz+XU2zoBiIlJPc8eTxfibQoB/PgKC/RkzqDyyjTcp9skDjG2b3bgWDM94jmE2R9P5WeYJzUoCp7jXdK7wST/89uhpx653sy9mmhbVYDFFjGDVs8Gr3pL73KIp7ycGEk9lFKwaqlPM4PegBwqAPBMoF5GQ9LYwBEeKRqWVohth70k4dvCuTXp7+50wrPCCcevQ1mnRK45h/9IkfVU2WlCYq6Rv1z2cczJ3CxUSdjg3FkzFjQSY3DohpO2KUaTKn5K/Vo2n2WOxSk0u2JKivuX8I/ 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:(13230016)(4636009)(346002)(376002)(136003)(39860400002)(396003)(46966006)(40470700004)(36840700001)(26005)(53546011)(2616005)(186003)(6506007)(44832011)(6666004)(82310400005)(336012)(47076005)(41300700001)(36756003)(6486002)(31686004)(478600001)(6512007)(86362001)(81166007)(36860700001)(31696002)(83380400001)(40460700003)(356005)(82740400003)(70586007)(2906002)(40480700001)(5660300002)(6862004)(70206006)(4326008)(8676002)(8936002)(316002)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2022 09:53:06.0027 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b4ed1d21-2592-4abd-8744-08da81c89d6f 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: VE1EUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB6124 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, 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-List-Received-Date: Fri, 19 Aug 2022 09:53:16 -0000 On 8/19/22 00:47, Thiago Jung Bauermann wrote: > > Hello Luis, > > The patch looks great to me, FWIW. > I have just a few small comments. > > Luis Machado via Gdb-patches writes: > >> While at it, make GDB and GDBServer share some more code for aarch64 > > Nice! > >> +/* AArch64 implementation of the remove_non_address_bits gdbarch hook. Remove >> + non address bits from a pointer value. */ >> + >> +static CORE_ADDR >> +aarch64_remove_non_address_bits (struct gdbarch *gdbarch, CORE_ADDR pointer) >> +{ >> + aarch64_gdbarch_tdep *tdep >> + = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch); >> + >> + /* By default, we assume TBI and discard the top 8 bits plus the VA range >> + select bit (55). */ >> + CORE_ADDR mask = (((CORE_ADDR) 1) << (64 - 9)) - 1; >> + mask = ~mask; > > One suggestion is to put the above in gdb/arch/aarch64.h as: > > /* By default, we assume TBI and discard the top 8 bits plus the VA range > select bit (55). */ > #define AARCH64_TOP_BITS_MASK (~((((CORE_ADDR) 1) << (64 - 9)) - 1)) > > and then use it here and in gdbserver's version of this function so that > there's a little bit more code shared between them. > That makes sense, but I wonder if it will fit gdb/arch/aarch64.h. The VA bit is a generic ISA thing, but the TBI is OS-specific I think. Maybe a gdb/arch/aarch64-pauth.h header that gets shared between gdb and gdbserver then? >> + >> + if (tdep->has_pauth ()) >> + { >> + /* Fetch the PAC masks. These masks are per-process, so we can just >> + fetch data from whatever thread we have at the moment. >> + >> + Also, we have both a code mask and a data mask. For now they are the >> + same, but this may change in the future. */ >> + struct regcache *regs = get_current_regcache (); >> + CORE_ADDR cmask, dmask; >> + >> + if (regs->cooked_read (tdep->pauth_reg_base, &dmask) != REG_VALID) >> + dmask = mask; >> + >> + if (regs->cooked_read (tdep->pauth_reg_base + 1, &cmask) != REG_VALID) >> + cmask = mask; >> + >> + if (dmask != cmask) >> + { >> + /* Warn if the masks are different. */ >> + warning (_("C mask and D mask differ")); > > This warning is a bit hard to read if one isn't familiar enough with > PAuth. Perhaps something like “Pointer authentication masks for code and > data differ”? > > Same comment applies to the warning message in the gdbserver version of > this function. > You're right. Let me adjust those. >> diff --git a/gdb/gdbarch-components.py b/gdb/gdbarch-components.py >> index fc10e8600ba..c6836b63c50 100644 >> --- a/gdb/gdbarch-components.py >> +++ b/gdb/gdbarch-components.py >> @@ -1116,15 +1116,21 @@ possible it should be in TARGET_READ_PC instead). >> invalid=False, >> ) >> >> -Value( >> +Method( >> comment=""" >> -On some machines, not all bits of an address word are significant. >> -For example, on AArch64, the top bits of an address known as the "tag" >> -are ignored by the kernel, the hardware, etc. and can be regarded as >> -additional data associated with the address. >> +On some architectures, not all bits of a pointer are significant. >> +On AArch64, for example, the top bits of a pointer may carry a "tag", which >> +can be ignored by the kernel and the hardware. The "tag" can be regarded as >> +additional data associated with the pointer, but it is not part of the address. >> + >> +Given a pointer for the architecture, this hook removes all the >> +non-significant bits and sign-extends things as needed. It is used mostly >> +for data pointers, as opposed to code pointers. > > Is the last sentence just FYI or does it imply some consequence for the > GDB user or even GDB itself? > More a FYI really. This was documented somewhere in the code, and I wanted to bring it to the manual. I'll clarify it.