From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0C062DB78C for ; Thu, 11 Jun 2026 02:21:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781144521; cv=none; b=ArjyvzwYOWL9l2ZzNN60NEvQuZUjMm+anHluo56CZFE5y/hLhCPDUPlhii18HBpddVlMq2HIYbRQDUSqYkzBQaywhXTllgUDlCLR9Tidlexaxe7fjNXA58QJ7PAkpO3iSzn3b5ilE5TALI++n4f68d9ckBSN18grMlYpLCNQCyo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781144521; c=relaxed/simple; bh=yZrzNUS5gRQJE6caK1LOQm2jsuK/qOsCwJahGTe+X+o=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=tAB7PUeQ4HOzQkLTvwOWcZqm3PC/Lmte8lArL0L3ONSIfRHvKVHpo8f2IOMbzgH/24DxVELz/KgG7/oJ3Zw93XEvs5hBgCRMEcvWiJcPCmgWHVCmiySZ0Exh1vy6OzCBWis7hW5erZavhAwN0nQHqwl0oipElr7w5OV36EmdE6Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ALOUma3S; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ALOUma3S" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781144519; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dda/zf/tm+2seO6NoTre8V3EVFAc5zYHpAhPIkoO/80=; b=ALOUma3SANRNRANPEB9caIUbzUW3rV0p1TnTcixjiZUkmIUXWm5RHDymFRa5HDl+QX1Zwa msR3mWtj+Xrqu//w6PM6GfPHCn22Bh+m14a2w/fq53WlCbxOHSK/KdToSihiovUyFq6RnT cZ+xnZLfr1qo2RGAvZhoxFGNDduZ394= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-OW-RJyJ9OWiGd4VG_0snUQ-1; Wed, 10 Jun 2026 22:21:54 -0400 X-MC-Unique: OW-RJyJ9OWiGd4VG_0snUQ-1 X-Mimecast-MFC-AGG-ID: OW-RJyJ9OWiGd4VG_0snUQ_1781144513 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DEB69180AC49; Thu, 11 Jun 2026 02:21:52 +0000 (UTC) Received: from [10.22.81.61] (unknown [10.22.81.61]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E58653008B35; Thu, 11 Jun 2026 02:21:51 +0000 (UTC) Message-ID: <12a7731e-e7c7-40a1-a121-dab66c0a3563@redhat.com> Date: Wed, 10 Jun 2026 22:21:50 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] locking/osq_lock: annotate a data race in osq_wait_next To: Jiayi Li , Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng Cc: linux-kernel@vger.kernel.org References: <20260611020857.1576964-1-lijiayi@kylinos.cn> Content-Language: en-US From: Waiman Long In-Reply-To: <20260611020857.1576964-1-lijiayi@kylinos.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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 > --- > 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