[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c2e5b1ee-eeee-4614-9b42-d6bbf7a67162@huaweicloud.com>
Date: Mon, 30 Sep 2024 11:33:26 +0200
From: Jonas Oberhauser <jonas.oberhauser@...weicloud.com>
To: Alan Huang <mmpgouride@...il.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
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);
}
best wishes,
jonas
Powered by blists - more mailing lists