Re: [PATCH v3 02/10] liveupdate: Synchronize lazy initialization of FLB private state

From: Pratyush Yadav

Date: Tue Mar 31 2026 - 06:45:53 EST


On Fri, Mar 27 2026, Pasha Tatashin wrote:

> The luo_flb_get_private() function, which is responsible for lazily
> initializing the private state of FLB objects, can be called
> concurrently from multiple threads. This creates a data
> race on the 'initialized' flag and can lead to multiple executions of
> mutex_init() and INIT_LIST_HEAD() on the same memory.
>
> Introduce a static spinlock (luo_flb_init_lock) local to the function
> to synchronize the initialization path. Use smp_load_acquire() and
> smp_store_release() for memory ordering between the fast path and the
> slow path.
>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@xxxxxxxxxx>

Reviewed-by: Pratyush Yadav <pratyush@xxxxxxxxxx>

But... wouldn't it be a whole lot simpler if we introduce a
DEFINE_LUO_FLB() and get rid of luo_flb_get_private() entirely:

#define DEFINE_LUO_FLB(_name, _ops, _compatible) \
struct liveupdate_flb _name = { \
.ops = _ops, \
.compatible = _compatible, \
.private = { \
.list = LIST_HEAD_INIT(_name.private.list), \
.list = LIST_HEAD_INIT(_name.private.list), \
/ ...
}, \
}

I can't get sparse to work so not sure if I need some special syntax to
initialize stuff in .private, but I reckon we can get something working.

[...]

--
Regards,
Pratyush Yadav