lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <AF8BEE57-2F7A-4BD5-B062-F4C268E8494B@gmail.com>
Date: Mon, 30 Sep 2024 18:12:31 +0800
From: Alan Huang <mmpgouride@...il.com>
To: Jonas Oberhauser <jonas.oberhauser@...weicloud.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
 Alan Stern <stern@...land.harvard.edu>,
 Linus Torvalds <torvalds@...ux-foundation.org>,
 LKML <linux-kernel@...r.kernel.org>,
 Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
 Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
 "Paul E. McKenney" <paulmck@...nel.org>,
 Will Deacon <will@...nel.org>,
 Peter Zijlstra <peterz@...radead.org>,
 Boqun Feng <boqun.feng@...il.com>,
 John Stultz <jstultz@...gle.com>,
 Neeraj upadhyay <Neeraj.Upadhyay@....com>,
 Frederic Weisbecker <frederic@...nel.org>,
 Joel Fernandes <joel@...lfernandes.org>,
 Josh Triplett <josh@...htriplett.org>,
 "Uladzislau Rezki (Sony)" <urezki@...il.com>,
 Steven Rostedt <rostedt@...dmis.org>,
 Lai Jiangshan <jiangshanlai@...il.com>,
 Zqiang <qiang.zhang1211@...il.com>,
 Ingo Molnar <mingo@...hat.com>,
 Waiman Long <longman@...hat.com>,
 Mark Rutland <mark.rutland@....com>,
 Thomas Gleixner <tglx@...utronix.de>,
 Vlastimil Babka <vbabka@...e.cz>,
 maged.michael@...il.com,
 Mateusz Guzik <mjguzik@...il.com>,
 Gary Guo <gary@...yguo.net>,
 RCU <rcu@...r.kernel.org>,
 linux-mm@...ck.org,
 lkmm@...ts.linux.dev
Subject: Re: [PATCH 1/2] compiler.h: Introduce ptr_eq() to preserve address
 dependency

On Sep 30, 2024, at 17:33, Jonas Oberhauser <jonas.oberhauser@...weicloud.com> wrote:
> 
> 
> 
> Am 9/30/2024 um 11:27 AM schrieb Alan Huang:
>> 2024年9月30日 17:15,Alan Huang <mmpgouride@...il.com> 写道:
>>> 
>>> 2024年9月30日 16:57,Jonas Oberhauser <jonas.oberhauser@...weicloud.com> 写道:
>>>> 
>>>> 
>>>> 
>>>> Am 9/29/2024 um 12:26 AM schrieb Alan Huang:
>>>>> 2024年9月28日 23:55,Mathieu Desnoyers <mathieu.desnoyers@...icios.com> wrote:
>>>>>> 
>>>>>> The motivation for introducing ptr_eq() is indeed because the
>>>>>> compiler barrier is not sufficient to prevent the compiler from
>>>>>> using one pointer instead of the other.
>>>>> barrier_data(&b) prevents that.
>>>> 
>>>> I don't think one barrier_data can garantuee preventing this, because right after doing the comparison, the compiler still could do b=a.
>>>> 
>>>> In that case you would be guaranteed to use the value in b, but that value is not the value loaded into b originally but rather the value loaded into a, and hence your address dependency goes to the wrong load still.
>>> 
>>> After barrier_data(&b), *b will be loaded from memory, you mean even if *b is loaded from memory, the address dependency goes to the wrong load still?
>> Sorry, *b should b.
> 
> That's exactly what I meant to say. In my understanding, it can happen like this:
> 
> a = READ_ONCE(*p);
> ...
> b = READ_ONCE(*p);
> if (a == b) {
>   b = a; // inserted by compiler
> 
>   barrier_data(&b);
> 
>   foo(*b); // compiler definitely use the current value in b
> }
> 
> 
> 
> In the end, the address dependency is from the first load, and the CPU can speculatively (with register renaming, forwarding etc) execute
> 
> a = READ_ONCE(*p);
> b2 = a; // speculatively
> tmp = load *b2 // speculatively
> b1 = READ_ONCE(*p);
> if (a == b1) { // confirmed
>   foo(tmp);
> }

I get it now, thanks for the explanation.

> 
> 
> best wishes,
>  jonas
> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ