From: Waiman Long <longman@redhat.com>
To: Haakon Bugge <haakon.bugge@oracle.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Davidlohr Bueso <dave@stgolabs.net>,
David Laight <david.laight.linux@gmail.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Yafang Shao <laoar.shao@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH] locking/osq_lock: Ensure proper locking semantics for osq_lock/osq_unlock()
Date: Mon, 14 Sep 2026 21:09:39 -0400 [thread overview]
Message-ID: <8acd1e8f-a8f8-47f0-9ede-27f164c0687f@redhat.com> (raw)
In-Reply-To: <B7EAC6BE-D491-428E-8943-CE2F6DF390C6@oracle.com>
On 9/14/26 6:30 AM, Haakon Bugge wrote:
> [$Subject fixed]
>
>> On 10 Sep 2026, at 16:19, Waiman Long <longman@redhat.com> wrote:
>>
>> The osq_lock is special in the sense that lock transfer from one CPU to
>> the next can happen either over the common optimistic_spin_queue.tail
>> value with uncontended lock or over a lock waiter's own percpu
>> optimistic_spin_node.locked flag when the lock is contended.
>>
>> To ensure proper lock synchronization, we need to provide
>> the acquire/release semantics for the osq_lock/osq_unlock()
>> functions in both cases. This is currently the case for the
>> common optimistic_spin_queue.tail value, but not for the percpu
>> optimistic_spin_node.locked flag as the proper barriers are missing in
>> some places. Fix that by adding the needed barriers in those places.
>>
>> Note that the two percpu optimistic_spin_node.locked setting in
>> osq_unlock() are proceeded by a full barrier xchg() call, but the
>
> s/proceeded/preceded/
>
>> contended cachelines are different. This should probably work in most
>> cases except in some exotic architectures where the barrier semantics
>> may be cacheline specific.
>
> As of today, doesn't atomic_xchg() provide full memory barrier?
> From the doc: "RMW operations that have a return value are fully
> ordered". I assume this applies to both the intra- and inter-
> cacheline cases.
Yes, you are right. That is why I decide to keep the WRITE_ONCE() in v2/v3.
Cheers,
Longman
prev parent reply other threads:[~2026-09-15 1:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 14:19 Waiman Long
2026-09-14 8:10 ` [PATCH] p " Haakon Bugge
2026-09-14 9:53 ` [PATCH] locking/osq_lock: Ensure proper locking semantics " David Laight
2026-09-14 20:22 ` Waiman Long
2026-09-14 11:22 ` Peter Zijlstra
2026-09-15 2:30 ` Waiman Long
2026-09-15 5:19 ` Peter Zijlstra
2026-09-15 8:36 ` David Laight
2026-09-15 8:26 ` Peter Zijlstra
2026-09-17 17:01 ` Haakon Bugge
[not found] ` <B7EAC6BE-D491-428E-8943-CE2F6DF390C6@oracle.com>
2026-09-15 1:09 ` Waiman Long [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8acd1e8f-a8f8-47f0-9ede-27f164c0687f@redhat.com \
--to=longman@redhat.com \
--cc=boqun@kernel.org \
--cc=dave@stgolabs.net \
--cc=david.laight.linux@gmail.com \
--cc=haakon.bugge@oracle.com \
--cc=laoar.shao@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=torvalds@linux-foundation.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®