Re: [PATCH] buffer: Annotate the remote buffer LRU occupancy check

From: Jan Kara

Date: Wed Nov 11 2026 - 09:28:28 EST


On Wed 11-11-26 16:41:12, Zhu Jun wrote:
> has_bh_in_lru() reads another CPU's buffer LRU while that CPU may install
> or invalidate entries. The local BH LRU lock does not serialize this
> remote occupancy check, which KCSAN reports as a data race.
>
> The check only decides whether to send a drain IPI and never dereferences
> the sampled pointer. Mark it as an intentional race and use READ_ONCE()
> to keep the test to a single load.
>
> Fixes: 42be35d0390b ("fs: only send IPI to invalidate LRU BH when needed")
> Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
...
> for (i = 0; i < BH_LRU_SIZE; i++) {
> - if (b->bhs[i])
> + /* Only test occupancy; the remote CPU owns the references. */
> + if (data_race(READ_ONCE(b->bhs[i])))

No need for the comment. Also combining READ_ONCE() and data_race() is
really silly. Just use data_race().

Honza

> return true;
> }
>
> --
> 2.51.0
>
>
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR