From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 573AE1DD0EF; Wed, 10 Dec 2025 07:31:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765351896; cv=none; b=qFcpijoK7PDlNviIMgmYBVmIkN5EDpyhOHgutr+iJfObzDkb3RaPmxK2/fN2JyG0aqmxd8DBtv59A85AScNNzNpGydsT/JV8wL9aSify7+BMm/RMvdwAYZkS5XQakZ92P+yCU9mQ1lx03el8RHVXnYX4s3xZe7jBLBjvqyfM7cI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765351896; c=relaxed/simple; bh=UobY8J9ysCSh4UMR0svHhPkKtuvR7otwji7HK/MVUz0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OL6WPMOH3hyQn1KyNGMCzB4iEChp4Q0t6axDvoHS8Ju9pTSlj4W3JKA9gSrtiM2F+CcZoS5nVl5wyaInO+uE+4IlhLda4CckMMLD+dtfh2t7qr7EgW/XLuYeIl4Pb28pQSfj1IiAYN+CpM87beefYWzmFLHIne/KacaNxI0weT0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=scy3P1+E; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="scy3P1+E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE1B6C116B1; Wed, 10 Dec 2025 07:31:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1765351896; bh=UobY8J9ysCSh4UMR0svHhPkKtuvR7otwji7HK/MVUz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=scy3P1+ENVKBvBuSpcva4PfiAJQ4qr3Ce5hy4eADtEtWOUCDcbt2p3difn+GGUA8K qCtGJM8Mj5/2oOYpiSUDbv2YDFNZyrfcYqmK/cmxDIXo34A9Mgi0wd9ayCGf/gxiaA NCClY35KHQEwkthgzWKGhbI53uUKypOukAO54lUo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Adrian Freihofer , Alexander Sverdlin , Boqun Feng , "Peter Zijlstra (Intel)" , "Paul E. McKenney" , Waiman Long Subject: [PATCH 6.12 09/49] locking/spinlock/debug: Fix data-race in do_raw_write_lock Date: Wed, 10 Dec 2025 16:29:39 +0900 Message-ID: <20251210072948.356454895@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251210072948.125620687@linuxfoundation.org> References: <20251210072948.125620687@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexander Sverdlin commit c14ecb555c3ee80eeb030a4e46d00e679537f03a upstream. KCSAN reports: BUG: KCSAN: data-race in do_raw_write_lock / do_raw_write_lock write (marked) to 0xffff800009cf504c of 4 bytes by task 1102 on cpu 1: do_raw_write_lock+0x120/0x204 _raw_write_lock_irq do_exit call_usermodehelper_exec_async ret_from_fork read to 0xffff800009cf504c of 4 bytes by task 1103 on cpu 0: do_raw_write_lock+0x88/0x204 _raw_write_lock_irq do_exit call_usermodehelper_exec_async ret_from_fork value changed: 0xffffffff -> 0x00000001 Reported by Kernel Concurrency Sanitizer on: CPU: 0 PID: 1103 Comm: kworker/u4:1 6.1.111 Commit 1a365e822372 ("locking/spinlock/debug: Fix various data races") has adressed most of these races, but seems to be not consistent/not complete. >>From do_raw_write_lock() only debug_write_lock_after() part has been converted to WRITE_ONCE(), but not debug_write_lock_before() part. Do it now. Fixes: 1a365e822372 ("locking/spinlock/debug: Fix various data races") Reported-by: Adrian Freihofer Signed-off-by: Alexander Sverdlin Signed-off-by: Boqun Feng Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Paul E. McKenney Acked-by: Waiman Long Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- kernel/locking/spinlock_debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/kernel/locking/spinlock_debug.c +++ b/kernel/locking/spinlock_debug.c @@ -184,8 +184,8 @@ void do_raw_read_unlock(rwlock_t *lock) static inline void debug_write_lock_before(rwlock_t *lock) { RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic"); - RWLOCK_BUG_ON(lock->owner == current, lock, "recursion"); - RWLOCK_BUG_ON(lock->owner_cpu == raw_smp_processor_id(), + RWLOCK_BUG_ON(READ_ONCE(lock->owner) == current, lock, "recursion"); + RWLOCK_BUG_ON(READ_ONCE(lock->owner_cpu) == raw_smp_processor_id(), lock, "cpu recursion"); }