From nobody Fri Oct 3 20:29:12 2025 Received: from mta-65-227.siemens.flowmailer.net (mta-65-227.siemens.flowmailer.net [185.136.65.227]) (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 2BAE0199FAB for ; Tue, 26 Aug 2025 10:27:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.136.65.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756204068; cv=none; b=ei5MmYcFfb01IvQFHP77TLUMoyIYrU/ZKPSICUoZdCJpezi55//xwqWxq9M+2c6ZVDlBTHGoIvUlO6UWUPCmSaLKFRpp5v5+qScyvE5jUb1unwLJNHF/UdlbTYgJM+D2NlPhP50K8QfK1+KnSB1IL1fJWF5MQIIa0+j2leUXIng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756204068; c=relaxed/simple; bh=IesqIGnB9Ffo5uqYC6nyaFAQHscROhBN/53NzNHTVys=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dOvJhPyT467r5fvCTnR7Ftx/8JX98cWGyql0uNPF1jqHkBzCr1mTzc+Tk1G+Ik4sIVNg5qx5B2rILyRMQw/FNBXNSPWDf1a6Kstaff1zJE07ciWatUjzTLhnQTa7ccCE9gepM19BjYRHLFe9iflC7xcHYUerI2QWg/yf+z/yyXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=siemens.com; spf=pass smtp.mailfrom=rts-flowmailer.siemens.com; dkim=pass (2048-bit key) header.d=siemens.com header.i=alexander.sverdlin@siemens.com header.b=P22KnrD7; arc=none smtp.client-ip=185.136.65.227 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=siemens.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rts-flowmailer.siemens.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=siemens.com header.i=alexander.sverdlin@siemens.com header.b="P22KnrD7" Received: by mta-65-227.siemens.flowmailer.net with ESMTPSA id 20250826102741e6a38a615d000207dc for ; Tue, 26 Aug 2025 12:27:41 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm2; d=siemens.com; i=alexander.sverdlin@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc; bh=I/4BVzGU//6o8w11JEpBafkAVNTi3A37k7IOe6GBXws=; b=P22KnrD7K2eLtlFSFdKekh9i2IMMpIplqPFKWTX0OT22i4CJXQfd39EDkaV/yDKtBnd1gU 6Hb2/hcwDuZMwCNB3QhypM/bfUjEflgvTwsaXuixrAvsbdh0k58WhsUNOM4I5TcxXOCsPENM xXNnVzVKs7SQcNJuHn3p/TOtA+orgZsqWcW3EN4B3c7cvHrs15t37emEt3BWWQty0HCj2gD0 1bBFpG22jKbS8oOb/yAdUmX5y8Sk+Qn6dKH7f2M6lWFbp8ysYY/CCMcMObPY8qtykaWGVmOK UN0fT89QKpi32/J0JwfIZA6Md325NSqB8oN88tvcuYqQNWVPC6PC37BQ==; From: "A. Sverdlin" To: Marco Elver , linux-kernel@vger.kernel.org Cc: Alexander Sverdlin , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , "Paul E . McKenney" , stable@vger.kernel.org, Adrian Freihofer Subject: [PATCH RESEND] locking/spinlock/debug: Fix data-race in do_raw_write_lock Date: Tue, 26 Aug 2025 12:27:27 +0200 Message-ID: <20250826102731.52507-1-alexander.sverdlin@siemens.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-456497:519-21489:flowmailer Content-Type: text/plain; charset="utf-8" From: Alexander Sverdlin 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. Cc: stable@vger.kernel.org Fixes: 1a365e822372 ("locking/spinlock/debug: Fix various data races") Reported-by: Adrian Freihofer Acked-by: Waiman Long Signed-off-by: Alexander Sverdlin Reviewed-by: Paul E. McKenney --- There are still some inconsistencies remaining IMO: - lock->magic is sometimes accessed with READ_ONCE() even though it's only being plain-written; - debug_spin_unlock() and debug_write_unlock() both do WRITE_ONCE() on lock->owner and lock->owner_cpu, but examine them with plain read accesses. kernel/locking/spinlock_debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/locking/spinlock_debug.c b/kernel/locking/spinlock_debu= g.c index 87b03d2e41dbb..2338b3adfb55f 100644 --- 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 !=3D RWLOCK_MAGIC, lock, "bad magic"); - RWLOCK_BUG_ON(lock->owner =3D=3D current, lock, "recursion"); - RWLOCK_BUG_ON(lock->owner_cpu =3D=3D raw_smp_processor_id(), + RWLOCK_BUG_ON(READ_ONCE(lock->owner) =3D=3D current, lock, "recursion"); + RWLOCK_BUG_ON(READ_ONCE(lock->owner_cpu) =3D=3D raw_smp_processor_id(), lock, "cpu recursion"); } =20 --=20 2.47.1