Re: [PATCH] locking/local_lock, mm: Replace localtry_ helpers with local_trylock_t type
From: Vlastimil Babka
Date: Wed Apr 02 2025 - 05:06:08 EST
On 4/2/25 09:30, Sebastian Andrzej Siewior wrote:
> On 2025-03-31 17:51:34 [-0700], Alexei Starovoitov wrote:
>> From: Alexei Starovoitov <ast@xxxxxxxxxx>
>>
>> Partially revert commit 0aaddfb06882 ("locking/local_lock: Introduce localtry_lock_t").
>> Remove localtry_*() helpers, since localtry_lock() name might
>> be misinterpreted as "try lock".
>
> So we back to what you suggested initially. I was more a fan of
> explicitly naming things but if this is misleading so be it. So
>
> Acked-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
>
> While at it, could you look at the hunk below and check if it worth it?
> The struct duplication and hoping that the first part remains the same,
> is hoping. This still relies that the first part remains the same but…
I've updated your fixups to v2
https://lore.kernel.org/all/20250401205245.70838-1-alexei.starovoitov@xxxxxxxxx/
and to support runtime local_trylock_init(), and it's at the end of my e-mail
But I also thought we could go all the way with removing casting in
that way and stop relying on the same layout implicitly.
So I rewrote this:
#define __local_lock_acquire(lock) \
do { \
local_trylock_t *tl; \
local_lock_t *l; \
\
_Generic((lock), \
local_lock_t *: ({ \
l = this_cpu_ptr(lock); \
}), \
local_trylock_t *: ({ \
tl = this_cpu_ptr(lock); \
l = &tl->llock; \
lockdep_assert(tl->acquired == 0); \
WRITE_ONCE(tl->acquired, 1); \
}), \
default:(void)0); \
local_lock_acquire(l); \
} while (0)
But I'm getting weird errors:
./include/linux/local_lock_internal.h:107:36: error: assignment to ‘local_trylock_t *’ from incompatible pointer type ‘local_lock_t *’ [-Wincompatible-pointer-types]
107 | tl = this_cpu_ptr(lock); \
coming from the guard expansions. I don't understand why it goes to the
_Generic() "branch" of local_trylock_t * with a local_lock_t *.
----8<----