On 2024-10-06 19:52:49 [+0000], David Laight wrote: > From: Mathieu Desnoyers > > Sent: 04 October 2024 19:28 > > > > Refer to ptr_eq() in the rcu_dereference() documentation. > > > > ptr_eq() is a mechanism that preserves address dependencies when > > comparing pointers, and should be favored when comparing a pointer > > obtained from rcu_dereference() against another pointer. > > Why does this ever really matter for rcu? > > The check just ensure that any speculative load uses > a specific one of the pointers when they are different. > This can only matter if you care about the side effects > of the speculative load. > > But rcu is all about (things like) lockless list following. > So you need to wait until it is impossible for another > execution context to have a reference to some memory > before actually completely invalidating it (ie kfree()). Not always. Non-RCU could would have locking with a barrier to ensure a reload. RCU would not have the barrier. Assuming the pointer, points to a struct, the compiler could load an element from the first pointer and keeping it after it ensured the pointer are equal. However based on the logic, the content could have changed and the compiler would not load the new value but keep the previous one. > David Sebastian