Re: [PATCH v3 next 5/5] Avoid writing to node->next in the osq_lock() fast path
From: Linus Torvalds
Date: Fri Mar 06 2026 - 19:06:48 EST
On Fri, 6 Mar 2026 at 14:52, <david.laight.linux@xxxxxxxxx> wrote:
>
> From: David Laight <david.laight.linux@xxxxxxxxx>
>
> When osq_lock() returns false or osq_unlock() returns static
> analysis shows that node->next should always be NULL.
This explanation makes me nervous.
*What* static analysis? It's very unclear. And the "should be NULL"
doesn't make me get the warm and fuzzies.
For example, osq_unlock() does do
node = this_cpu_ptr(&osq_node);
next = xchg(&node->next, NULL);
so it's clearly NULL after that. But it's not obvious this will be
reached, because osq_unlock() does that
/*
* Fast path for the uncontended case.
*/
if (atomic_try_cmpxchg_release(&lock->tail, &curr, OSQ_UNLOCKED_VAL))
return;
before it actually gets to this point.
And yes, I'm very willing to believe that if we hit that fast-path,
node->next (which is "curr->next" in that path) is indeed NULL, but I
think this commit message really needs to spell it all out.
No "should be NULL", in other words. I want a rock-solid "node->next
is always NULL because XYZ" explanation, not a wishy-washy "static
analysis says" without spelling it out.
Linus