Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-07 Thread Jonas Oberhauser
Am 10/7/2024 um 3:18 PM schrieb David Laight: 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 (wit

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-07 Thread Mathieu Desnoyers
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 OPTIMI

RE: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-07 Thread David Laight
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 va

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-07 Thread Jonas Oberhauser
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

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-03 Thread Mathieu Desnoyers
On 2024-10-03 19:07, David Laight wrote: ... 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 derefer

RE: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-03 Thread David Laight
... > 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 versio

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-03 Thread Mathieu Desnoyers
On 2024-10-03 03:50, 'Alan Stern' wrote: On Wed, Oct 02, 2024 at 03:24:45PM +, David Laight wrote: I think I know what you are trying to do, and you just fail. Whether something can work is another matter, but that code can't ever work. Inside if (a == b) the compiler will always use the sa

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-02 Thread 'Alan Stern'
On Wed, Oct 02, 2024 at 03:24:45PM +, David Laight wrote: > I think I know what you are trying to do, and you just fail. > Whether something can work is another matter, but that code > can't ever work. > > Inside if (a == b) the compiler will always use the same register > for references to a

RE: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-02 Thread David Laight
From: 'Alan Stern' > Sent: 02 October 2024 15:15 > > On Wed, Oct 02, 2024 at 08:13:15AM +, David Laight wrote: > > From: 'Alan Stern' > > > Sent: 01 October 2024 23:57 > > > > > > On Tue, Oct 01, 2024 at 05:11:05PM +, David Laight wrote: > > > > From: Alan Stern > > > > > Sent: 30 Septembe

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-02 Thread 'Alan Stern'
On Wed, Oct 02, 2024 at 08:13:15AM +, David Laight wrote: > From: 'Alan Stern' > > Sent: 01 October 2024 23:57 > > > > On Tue, Oct 01, 2024 at 05:11:05PM +, David Laight wrote: > > > From: Alan Stern > > > > Sent: 30 September 2024 19:53 > > > > > > > > On Mon, Sep 30, 2024 at 07:05:06PM +

RE: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-02 Thread David Laight
From: 'Alan Stern' > Sent: 01 October 2024 23:57 > > On Tue, Oct 01, 2024 at 05:11:05PM +, David Laight wrote: > > From: Alan Stern > > > Sent: 30 September 2024 19:53 > > > > > > On Mon, Sep 30, 2024 at 07:05:06PM +0200, Jonas Oberhauser wrote: > > > > > > > > > > > > Am 9/30/2024 um 6:43 PM

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-01 Thread 'Alan Stern'
On Tue, Oct 01, 2024 at 05:11:05PM +, David Laight wrote: > From: Alan Stern > > Sent: 30 September 2024 19:53 > > > > On Mon, Sep 30, 2024 at 07:05:06PM +0200, Jonas Oberhauser wrote: > > > > > > > > > Am 9/30/2024 um 6:43 PM schrieb Alan Stern: > > > > On Mon, Sep 30, 2024 at 01:26:53PM +020

RE: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-10-01 Thread David Laight
From: Alan Stern > Sent: 30 September 2024 19:53 > > On Mon, Sep 30, 2024 at 07:05:06PM +0200, Jonas Oberhauser wrote: > > > > > > Am 9/30/2024 um 6:43 PM schrieb Alan Stern: > > > On Mon, Sep 30, 2024 at 01:26:53PM +0200, Jonas Oberhauser wrote: > > > > > > > > > > > > Am 9/28/2024 um 4:49 PM sch

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Alan Stern
On Mon, Sep 30, 2024 at 07:05:06PM +0200, Jonas Oberhauser wrote: > > > Am 9/30/2024 um 6:43 PM schrieb Alan Stern: > > On Mon, Sep 30, 2024 at 01:26:53PM +0200, Jonas Oberhauser wrote: > > > > > > > > > Am 9/28/2024 um 4:49 PM schrieb Alan Stern: > > > > > > I should also point out that it is

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Jonas Oberhauser
Am 9/30/2024 um 6:43 PM schrieb Alan Stern: On Mon, Sep 30, 2024 at 01:26:53PM +0200, Jonas Oberhauser wrote: Am 9/28/2024 um 4:49 PM schrieb Alan Stern: On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoyers wrote: Compiler CSE and SSA GVN optimizations can cause the address depende

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Alan Stern
On Mon, Sep 30, 2024 at 01:26:53PM +0200, Jonas Oberhauser wrote: > > > Am 9/28/2024 um 4:49 PM schrieb Alan Stern: > > On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoyers wrote: > > > Compiler CSE and SSA GVN optimizations can cause the address dependency > > > of addresses returned by r

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Paul E. McKenney
On Mon, Sep 30, 2024 at 02:06:12PM +0200, Jonas Oberhauser wrote: > > > Am 9/30/2024 um 1:04 PM schrieb Paul E. McKenney: > > On Mon, Sep 30, 2024 at 11:42:11AM +0200, Jonas Oberhauser wrote: > > > > > > > > > I also currently don't see any major difference between the constant and > > > regist

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Jonas Oberhauser
Am 9/30/2024 um 1:04 PM schrieb Paul E. McKenney: On Mon, Sep 30, 2024 at 11:42:11AM +0200, Jonas Oberhauser wrote: I also currently don't see any major difference between the constant and register case. The point is that the address is known before loading into b, and hence the compiler +

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Jonas Oberhauser
Am 9/28/2024 um 4:49 PM schrieb Alan Stern: On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoyers wrote: Compiler CSE and SSA GVN optimizations can cause the address dependency of addresses returned by rcu_dereference to be lost when comparing those pointers with either constants or pre

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Paul E. McKenney
On Mon, Sep 30, 2024 at 11:42:11AM +0200, Jonas Oberhauser wrote: > > > Am 9/28/2024 um 11:15 PM schrieb Alan Stern: > > On Sat, Sep 28, 2024 at 11:55:22AM -0400, Mathieu Desnoyers wrote: > > > On 2024-09-28 17:49, Alan Stern wrote: > > > > Isn't it true that on strongly ordered CPUs, a compiler

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Alan Huang
On Sep 30, 2024, at 17:33, Jonas Oberhauser wrote: > > > > Am 9/30/2024 um 11:27 AM schrieb Alan Huang: >> 2024年9月30日 17:15,Alan Huang 写道: >>> >>> 2024年9月30日 16:57,Jonas Oberhauser 写道: Am 9/29/2024 um 12:26 AM schrieb Alan Huang: > 2024年9月28日 23:55,Mathieu Desnoye

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Jonas Oberhauser
Am 9/28/2024 um 11:15 PM schrieb Alan Stern: On Sat, Sep 28, 2024 at 11:55:22AM -0400, Mathieu Desnoyers wrote: On 2024-09-28 17:49, Alan Stern wrote: Isn't it true that on strongly ordered CPUs, a compiler barrier is sufficient to prevent the rcu_dereference() problem? So the whole idea be

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Jonas Oberhauser
Am 9/30/2024 um 11:27 AM schrieb Alan Huang: 2024年9月30日 17:15,Alan Huang 写道: 2024年9月30日 16:57,Jonas Oberhauser 写道: Am 9/29/2024 um 12:26 AM schrieb Alan Huang: 2024年9月28日 23:55,Mathieu Desnoyers wrote: The motivation for introducing ptr_eq() is indeed because the compiler barrier i

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Alan Huang
2024年9月30日 17:15,Alan Huang 写道: > > 2024年9月30日 16:57,Jonas Oberhauser 写道: >> >> >> >> Am 9/29/2024 um 12:26 AM schrieb Alan Huang: >>> 2024年9月28日 23:55,Mathieu Desnoyers wrote: On 2024-09-28 17:49, Alan Stern wrote: > On Sat, Sep 28, 2024 at 11:32:18AM -0400, Mathieu Desnoyers

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Alan Huang
2024年9月30日 16:57,Jonas Oberhauser 写道: > > > > Am 9/29/2024 um 12:26 AM schrieb Alan Huang: >> 2024年9月28日 23:55,Mathieu Desnoyers wrote: >>> >>> On 2024-09-28 17:49, Alan Stern wrote: On Sat, Sep 28, 2024 at 11:32:18AM -0400, Mathieu Desnoyers wrote: > On 2024-09-28 16:49, Alan Stern

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-30 Thread Jonas Oberhauser
Am 9/29/2024 um 12:26 AM schrieb Alan Huang: 2024年9月28日 23:55,Mathieu Desnoyers wrote: On 2024-09-28 17:49, Alan Stern wrote: On Sat, Sep 28, 2024 at 11:32:18AM -0400, Mathieu Desnoyers wrote: On 2024-09-28 16:49, Alan Stern wrote: On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoy

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-29 Thread Mathieu Desnoyers
On 2024-09-29 01:24, Gary Guo wrote: Cc: Nikita Popov Cc: l...@lists.linux.dev On Sat, 28 Sep 2024 09:51:27 -0400 Mathieu Desnoyers wrote: Compiler CSE and SSA GVN optimizations can cause the address dependency of addresses returned by rcu_dereference to be lost when comparing those pointers

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-28 Thread Alan Huang
2024年9月29日 07:55,Boqun Feng wrote: > > > > On Sun, Sep 29, 2024, at 6:26 AM, Alan Huang wrote: >> 2024年9月28日 23:55,Mathieu Desnoyers wrote: >>> >>> On 2024-09-28 17:49, Alan Stern wrote: On Sat, Sep 28, 2024 at 11:32:18AM -0400, Mathieu Desnoyers wrote: > On 2024-09-28 16:49, Alan St

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-28 Thread Boqun Feng
On Sun, Sep 29, 2024, at 6:26 AM, Alan Huang wrote: > 2024年9月28日 23:55,Mathieu Desnoyers wrote: >> >> On 2024-09-28 17:49, Alan Stern wrote: >>> On Sat, Sep 28, 2024 at 11:32:18AM -0400, Mathieu Desnoyers wrote: On 2024-09-28 16:49, Alan Stern wrote: > On Sat, Sep 28, 2024 at 09:51:27

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-28 Thread Gary Guo
Cc: Nikita Popov Cc: l...@lists.linux.dev On Sat, 28 Sep 2024 09:51:27 -0400 Mathieu Desnoyers wrote: > Compiler CSE and SSA GVN optimizations can cause the address dependency > of addresses returned by rcu_dereference to be lost when comparing those > pointers with either constants or previous

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-28 Thread Alan Huang
2024年9月28日 23:55,Mathieu Desnoyers wrote: > > On 2024-09-28 17:49, Alan Stern wrote: >> On Sat, Sep 28, 2024 at 11:32:18AM -0400, Mathieu Desnoyers wrote: >>> On 2024-09-28 16:49, Alan Stern wrote: On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoyers wrote: > equality, which does

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-28 Thread Alan Stern
On Sat, Sep 28, 2024 at 11:55:22AM -0400, Mathieu Desnoyers wrote: > On 2024-09-28 17:49, Alan Stern wrote: > > On Sat, Sep 28, 2024 at 11:32:18AM -0400, Mathieu Desnoyers wrote: > > > On 2024-09-28 16:49, Alan Stern wrote: > > > > On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoyers wrote:

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-28 Thread Mathieu Desnoyers
On 2024-09-28 17:49, Alan Stern wrote: On Sat, Sep 28, 2024 at 11:32:18AM -0400, Mathieu Desnoyers wrote: On 2024-09-28 16:49, Alan Stern wrote: On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoyers wrote: equality, which does not preserve address dependencies and allows the following mi

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-28 Thread Alan Stern
On Sat, Sep 28, 2024 at 11:32:18AM -0400, Mathieu Desnoyers wrote: > On 2024-09-28 16:49, Alan Stern wrote: > > On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoyers wrote: > > > equality, which does not preserve address dependencies and allows the > > > following misordering speculations: >

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-28 Thread Mathieu Desnoyers
On 2024-09-28 16:49, Alan Stern wrote: On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoyers wrote: Compiler CSE and SSA GVN optimizations can cause the address dependency of addresses returned by rcu_dereference to be lost when comparing those pointers with either constants or previously

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-28 Thread Mathieu Desnoyers
On 2024-09-28 16:49, Alan Stern wrote: On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoyers wrote: [...] +/* + * Compare two addresses while preserving the address dependencies for + * later use of the address. It should be used when comparing an address + * returned by rcu_dereference()

Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-28 Thread Alan Stern
On Sat, Sep 28, 2024 at 09:51:27AM -0400, Mathieu Desnoyers wrote: > Compiler CSE and SSA GVN optimizations can cause the address dependency > of addresses returned by rcu_dereference to be lost when comparing those > pointers with either constants or previously loaded pointers. > > Introduce ptr_

[PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address dependency

2024-09-28 Thread Mathieu Desnoyers
Compiler CSE and SSA GVN optimizations can cause the address dependency of addresses returned by rcu_dereference to be lost when comparing those pointers with either constants or previously loaded pointers. Introduce ptr_eq() to compare two addresses while preserving the address dependencies for l