Re: [PATCH] locking/percpu-rwsem: Annotate intentional data race in readers_active_check()
From: Peter Zijlstra
Date: Tue Jun 23 2026 - 05:47:53 EST
On Tue, Jun 23, 2026 at 05:34:45PM +0800, Sun Shaojie wrote:
> KCSAN reports a data race in readers_active_check():
>
> BUG: KCSAN: data-race in readers_active_check / percpu_down_write
>
> race at unknown origin, with read to 0xffff9f3eb5bf5f30 of 4 bytes
> by task 1271 on cpu 14:
> readers_active_check+0x...
> percpu_down_write+0x152/0x1f0
>
> value changed: 0xfffffff9 -> 0xfffffff8
>
> This is a benign race. Annotate it with data_race() to suppress the
> KCSAN warning.
I'm not even sure I can tell what actual access is seemed problematic
from this report, let alone tell your reasoning for why it is benign.
And while I think the patch is ok (with my vague memories of the code at
hand), this changelog is entirely insufficient.
> Signed-off-by: Sun Shaojie <sunshaojie@xxxxxxxxxx>
> ---
> kernel/locking/percpu-rwsem.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c
> index f7e152c40d6d..6c78961fe753 100644
> --- a/kernel/locking/percpu-rwsem.c
> +++ b/kernel/locking/percpu-rwsem.c
> @@ -211,7 +211,7 @@ EXPORT_SYMBOL_GPL(percpu_is_read_locked);
> */
> static bool readers_active_check(struct percpu_rw_semaphore *sem)
> {
> - if (per_cpu_sum(*sem->read_count) != 0)
> + if (data_race(per_cpu_sum(*sem->read_count)) != 0)
> return false;
>
> /*
> --
> 2.25.1
>