Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

liveupdate: synchronize lazy initialization of FLB private state

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.

Link: https://lore.kernel.org/20260327033335.696621-3-pasha.tatashin@soleen.com
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Cc: David Matlack <dmatlack@google.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Samiullah Khawaja <skhawaja@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Pasha Tatashin and committed by
Andrew Morton
38fb71ac 277f4e5e

+6 -1
+6 -1
kernel/liveupdate/luo_flb.c
··· 89 89 static struct luo_flb_private *luo_flb_get_private(struct liveupdate_flb *flb) 90 90 { 91 91 struct luo_flb_private *private = &ACCESS_PRIVATE(flb, private); 92 + static DEFINE_SPINLOCK(luo_flb_init_lock); 92 93 94 + if (smp_load_acquire(&private->initialized)) 95 + return private; 96 + 97 + guard(spinlock)(&luo_flb_init_lock); 93 98 if (!private->initialized) { 94 99 mutex_init(&private->incoming.lock); 95 100 mutex_init(&private->outgoing.lock); 96 101 INIT_LIST_HEAD(&private->list); 97 102 private->users = 0; 98 - private->initialized = true; 103 + smp_store_release(&private->initialized, true); 99 104 } 100 105 101 106 return private;