mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Jiayi Li <lijiayi@kylinos.cn>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Boqun Feng <boqun@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] locking/osq_lock: annotate a data race in osq_wait_next
Date: Wed, 10 Jun 2026 22:21:50 -0400	[thread overview]
Message-ID: <12a7731e-e7c7-40a1-a121-dab66c0a3563@redhat.com> (raw)
In-Reply-To: <20260611020857.1576964-1-lijiayi@kylinos.cn>

On 6/10/26 10:08 PM, Jiayi Li wrote:
> KCSAN reported a data race in osq_unlock():
>
>    BUG: KCSAN: data-race in osq_unlock+0xa6/0x120
>
>    race at unknown origin, with read to 0xffff8e2c799b7600 of 8 bytes
>    by task 6598 on cpu 11:
>      osq_unlock+0xa6/0x120
>      generic_osq_unlock+0xe/0x20
>      rwsem_down_write_slowpath+0x78a/0xd50
>      down_write+0xef/0x100
>      vma_link_file+0x4c/0xb0
>      mmap_region+0x865/0x12a0
>      do_mmap+0x5b5/0x8d0
>
>    value changed: 0x0000000000000000 -> 0xffff8e2c796b7600
>    Reported by Kernel Concurrency Sanitizer on:
>    CPU: 11 PID: 6598 Comm: modprobe Not tainted 6.6.103+ #588
>
> static inline struct optimistic_spin_node *
> osq_wait_next(struct optimistic_spin_queue *lock,
>                struct optimistic_spin_node *node,
>                struct optimistic_spin_node *prev)
> {
>          struct optimistic_spin_node *next = NULL;
>          int curr = encode_cpu(smp_processor_id());
>          int old;
>
>          old = prev ? prev->cpu : OSQ_UNLOCKED_VAL;
>
>          for (;;) {
>
>                  ......
>
>                  if (node->next) {      <--------------------------
>                          next = xchg(&node->next, NULL);
>                          if (next)
>                                  break;
>                  }
>
>                  cpu_relax();
>          }
>
>          return next;
> }
>
> The read in osq_wait_next() only tests if node->next is non-NULL before
> using xchg() to fetch and clear the actual successor. Even if the load
> observes a transient value, the code is still working correctly. Thus,
> mark it as an intentional data race using the data_race() macro.
>
> Signed-off-by: Jiayi Li <lijiayi@kylinos.cn>
> ---
>   kernel/locking/osq_lock.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c
> index b4233dc2c2b0..ab87d06405f9 100644
> --- a/kernel/locking/osq_lock.c
> +++ b/kernel/locking/osq_lock.c
> @@ -78,7 +78,7 @@ osq_wait_next(struct optimistic_spin_queue *lock,
>   		 * wait for either @lock to point to us, through its Step-B, or
>   		 * wait for a new @node->next from its Step-C.
>   		 */
> -		if (node->next) {
> +		if (data_race(node->next)) { /* xchg() validates the value. */
>   			struct optimistic_spin_node *next;
>   
>   			next = xchg(&node->next, NULL);
Acked-by: Waiman Long <longman@redhat.com>


      reply	other threads:[~2026-06-11  2:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-11  2:08 Jiayi Li
2026-06-11  2:21 ` Waiman Long [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12a7731e-e7c7-40a1-a121-dab66c0a3563@redhat.com \
    --to=longman@redhat.com \
    --cc=boqun@kernel.org \
    --cc=lijiayi@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®