From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 887CECFB43F for ; Mon, 7 Oct 2024 13:23:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 054746B00D3; Mon, 7 Oct 2024 09:23:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 003FA6B00D4; Mon, 7 Oct 2024 09:23:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0CA86B00D5; Mon, 7 Oct 2024 09:23:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C24D66B00D3 for ; Mon, 7 Oct 2024 09:23:10 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 43F354033F for ; Mon, 7 Oct 2024 13:23:10 +0000 (UTC) X-FDA: 82646872140.25.0D315E3 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by imf27.hostedemail.com (Postfix) with ESMTP id 52CAA4000D for ; Mon, 7 Oct 2024 13:23:08 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=AyWYXTwJ; dmarc=pass (policy=none) header.from=efficios.com; spf=pass (imf27.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728307290; a=rsa-sha256; cv=none; b=oKWifq/X9CwRi+gMr36xqGe7z+rIg/l2WaCMub1k/uS9PlwSXtZPzEt+gH4rnPcjG6zbY1 NbsmVArkfKNYeoUnqZbqWupW8x/KkmIE7UCTCBxqbb0vvFR1VrtAH5+jYH6xc8sxoH7zq4 AAMG88LATThAnR1h+ImuP1J5bBWnsPc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=AyWYXTwJ; dmarc=pass (policy=none) header.from=efficios.com; spf=pass (imf27.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728307290; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=y+BX1ttH7OG3Qlh6iDsFAH/MboKkAXVupghHGLu/m50=; b=CaLRsXntmkM2MFEhlD4NG/PoqzbpG2uJUjIca8HSsRQz2mMdL0c4TcW2Wzz+s/4x3x3kta Iq3n3pH0SMS5vK8QFAqcgkYT5Lw8egQp/xBIXFWdCaQaYIyTRCkMQy/S8xS4ToEsPtsP3s yL0mlxOsyBaHGhqv1XBh+RXPRKOxIcA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1728307387; bh=sRmBF0SeDxIe13YKtx2EtfkkIJUtFxsFcv9CqtdHrWc=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=AyWYXTwJOIFfM7YA1yH4qyX7HNVcKXqEM4mCxsjzbyARw0JbSu6tFCQQ0Sb+4dlqy jRZPbEZYqmCHCjthBX20tX0mRy5Ep4EtS/oSxnpF5mFsqJAa0Nr3N1cfyV15Kt97HY 03gWmio+WUfLakdU6X5Faq04FaFQurydsCXRm96/eynaKzgyDrCQpkB49u8SF37r4Z d0G4N8+u9zBPCTVTTe1QSMYn5JPmledg4ZDThF3pQU2+pym6uXP5Tz9crKGDB4A+3v GqeaJsozz8mnEVjNf6Xa/wGYiPTtoFlSmw6/yhhxd8E2jjW3Il7cDFDXp/ccGZBH4E xyjyfI+YHyiqQ== Received: from [172.16.0.134] (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4XMfwV3qDnz2kt; Mon, 7 Oct 2024 09:23:06 -0400 (EDT) Message-ID: Date: Mon, 7 Oct 2024 09:21:09 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency To: David Laight , 'Jonas Oberhauser' , 'Alan Stern' Cc: Linus Torvalds , "linux-kernel@vger.kernel.org" , Greg Kroah-Hartman , Sebastian Andrzej Siewior , "Paul E. McKenney" , Will Deacon , Peter Zijlstra , Boqun Feng , John Stultz , Neeraj Upadhyay , Frederic Weisbecker , Joel Fernandes , Josh Triplett , Uladzislau Rezki , Steven Rostedt , Lai Jiangshan , Zqiang , Ingo Molnar , Waiman Long , Mark Rutland , Thomas Gleixner , Vlastimil Babka , "maged.michael@gmail.com" , Mateusz Guzik , Gary Guo , "rcu@vger.kernel.org" , "linux-mm@kvack.org" , "lkmm@lists.linux.dev" References: <02c63e79-ec8c-4d6a-9fcf-75f0e67ea242@rowland.harvard.edu> <9539c551-5c91-42db-8ac1-cff1d6d7c293@huaweicloud.com> <2cdda043-1ad9-40cf-a157-0c16a0ffb046@rowland.harvard.edu> <5d7d8a59-57f5-4125-95bb-fda9c193b9cf@huaweicloud.com> <82e97ad5-17ad-418d-8791-22297acc7af4@rowland.harvard.edu> <2b1caba3-48fa-43b9-bd44-cf60b9a141d7@rowland.harvard.edu> <22638e2fe1274eb0834fa3e43b44184e@AcuMS.aculab.com> <68dc00b3-1ca1-42bc-8f1e-78ace10e4d64@rowland.harvard.edu> <6ae2461a-e509-4c4d-8959-ae17eb214419@huaweicloud.com> <43788527053542e78001820857445e4d@AcuMS.aculab.com> From: Mathieu Desnoyers Content-Language: en-US In-Reply-To: <43788527053542e78001820857445e4d@AcuMS.aculab.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 52CAA4000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: i84jumft6oyiczmj8mtdapx884f58i7t X-HE-Tag: 1728307388-206642 X-HE-Meta: U2FsdGVkX19FTA0PmM+tPJ8C/9sqgdZedeW5Nc2ceJBcxX+/KEc2QOxtRSZg9WVCepSizojQzYCMcSzDNXm/SXFUZ55szGeMa7BwKPD+EfopktfGkpQkBQggdAVRZuAfqk0aAE5eYiMjXpeApBrnqH6j5bNs0vskQbiCyKM5DnxqWYIRgAPQIl4FLCQMe2qlDQB39t6ad9rLnQdN4ixGlR7z5zmgr+SOLXvLCL4idxfjX2/T+ixaNkwkBlZ5XGT89NnHN9AbZ6EDkxfGXF6QwQm4G9Eid9g3XTkNXT03EBmZ7s3nRNfqIeJCL6hI8dFLVnJDfHuONwSMkUvX3BN3izpPt24AX6ghP8TzcXkt9CDtjTDtzeEs3XJQPA8Ejlghy6IcB3+ASS4yszpLxP3uXWjL4nfrC+uZqyQIc+sflh4JKesctu54rDnwu2g6lihQ5pGZdi8SfIee1g2orkYNPgkvRFfx+VLhTTm+ly3oFCuaMGLillyiMCrYst7OlLGCDZbvWBGyfbwX5IW6b2ghBt01OXFCH3G9fXuU9RB15D4BlBau1TXHxdHxwpLbZ/C0s1zGLk5vlvp0fDN6fVz3KppKtF4qg481gukjiFdI4ot2lSzsJ5Fpai4WEhugGdrw40m1IDT/36h32m2nkZroYvJugTsN+l18NXx+NhLAy5wZnNzIYAbPgKW7mxdqeuGJT7XhOzH0d078RKXPw3FfreZVJJ3c4zgDAfRUGGhuem5lDdgds96xz8f0BbBFSvjaDqFxKvvsTF9fz4t2P6JBtL28UmkYM2TTbV3pHNAk67E4SosI21GAHgNQg2RxBrh2cnwndyEeyD6XC6Bju4wM0lD/NoNOMGUyh2DcDmuA1VjnxTh+N99a3QoUjJ8IbivF3qre9U1OvO3lrHdVtDOVo6ppwJmoLgchlnl2nJSzaibPPNqmiqkxd2axAqeAtgdnCIYUgphCBb5LvQeKafl fbEyko8B /V9y5mgt44mysYdKxO+Xm1kbwqZIF1mXZP9DLacmPtw9IITexJcCB2pzmV8QGLbNXJaZfESALYIChpXj6/osV3MCbaRC72Tq1V8EFEKwf/4w7z7HDcssslsd1LVpYL5bD2v/1CTe+W+kITdA3tJbCpVXFbxLp65GzDyvQqpNTQ9+mziLmEAli+IhTDoKBGoi8EefFu+Q2RlK6FachAaH/HdZZoLw+5p/wc8Qm+kLxI+2GMqEe7m7yssvMP5dellf+/WWjC+Cm/A8cj8ocVOYsQDay6uJCR4TViXFHMcxIlNr1YsScC4JE9F0ZvjqKh4fBa6EpGT4ghDMe2UF1+7ruvzn1XJE4TFMbUss80pVZx7kCGyXoL85Eiq8ulUw++mNn2nwIJGJTGYMKAqCtUBXbrkdXvUDjU2MTc4zfjeHIXuMFyiHb5BuPIjbe+OfvesvDg9KI7Lw/QeItOzFlCcnbTR4y5mpz0pBHLXTL9IfYx3i1ntSgnm7Wjr3qjYGAeAmQ3kFeUxllVgPolck= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 2024-10-07 15:18, David Laight wrote: > From: Jonas Oberhauser >> Sent: 07 October 2024 12:55 >> >> Am 10/3/2024 um 3:23 PM schrieb Mathieu Desnoyers: >>> What _does_ work however are the following two approaches: >>> >>> 1) Perform the equality check on the original variables, creating >>> new versions (with OPTIMIZER_HIDE_VAR) of both variables for the >>> rest of their use, therefore making sure the pointer dereference >>> are not derived from versions of the variables which were compared >>> with another pointer. (as suggested by Boqun) >> >> This should not be guaranteed to work, because right after the >> comparison the compiler can do b=a, then it doesn't matter how much you >> hide afterwards. >> >> However it might work if you escape the addresses of a and b first, in >> which case the compiler will not do b=a anymore, but it might force the >> compiler to put a and b on the stack, which has some performance impact. > > Nope, as pointed out last week, the compiler can move the 'a == b' > check to before the OPTIMISER_HID_VAR() and then use the same register > for both of them. Yes. > >>> 2) Perform the equality check on the versions resulting of hiding >>> both variables, making sure those versions of the variables are >>> not dereferenced afterwards. (as suggested by Linus) > > That (and other things) could usefully use: > #define OPTIMISER_HIDE_VALUE(x) \ > ({ __auto_type _x = x; OPTIMISER_HIDE_VAR(_x); _x; }) > You'll almost certainly end up with a register-register move > even if 'x' isn't used afterwards. Yes. > > The calling could just become: > if (a == OPTIMISER_HIDE_VALUE(b) ... > since it is likely that you only care about one of the pointers. > (Actually isn't hiding one of them always enough?) Linus asked that we hide both inputs, otherwise it's really asking for trouble in terms of API misuse. Thanks, Mathieu > > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales) -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com