[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANn89iLi4CQZhAw7DKVauk0+cC+nBjoVuHgAan=cOsCP07Jh=w@mail.gmail.com>
Date: Sat, 6 Sep 2025 07:34:19 -0700
From: Eric Dumazet <edumazet@...gle.com>
To: Qi Xi <xiqi2@...wei.com>
Cc: bobo.shaobowang@...wei.com, xiexiuqi@...wei.com, arnd@...db.de,
masahiroy@...nel.org, kuba@...nel.org, linux-arch@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] once: fix race by moving DO_ONCE to separate section
On Sat, Sep 6, 2025 at 6:58 AM Qi Xi <xiqi2@...wei.com> wrote:
>
> The commit c2c60ea37e5b ("once: use __section(".data.once")") moved
> DO_ONCE's ___done variable to .data.once section, which conflicts with
> WARN_ONCE series macros that also use the same section.
>
> This creates a race condition when clear_warn_once is used:
>
> Thread 1 (DO_ONCE) Thread 2 (DO_ONCE)
> __do_once_start
> read ___done (false)
> acquire once_lock
> execute func
> __do_once_done
> write ___done (true) __do_once_start
> release once_lock // Thread 3 clear_warn_once reset ___done
> read ___done (false)
> acquire once_lock
> execute func
> schedule once_work __do_once_done
> once_deferred: OK write ___done (true)
> static_branch_disable release once_lock
> schedule once_work
> once_deferred:
> BUG_ON(!static_key_enabled)
Should we use this section as well in include/linux/once_lite.h ?
Or add a comment there explaining that there is a difference
between the two variants, I am not sure this was explicitly mentioned
in the past.
Powered by blists - more mailing lists