From nobody Fri Oct 2 09:22:05 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 41B2E3AB498; Mon, 3 Aug 2026 08:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785744598; cv=none; b=t/uvdNm2r5GA53nEJCxNl0K8W5b9gfGOZBIRW+YLp5vpVCwnw2CXbvGalbnGolz6vaxPqSZG3iNR88AijcYqAY5Tvky+Dko2I2ldeca3jLyD3p2/QUzjXYUCge0fPRNr2306RL33pK9cy/xZvgi5iVTCarJBFhBm3gHPQnVxMAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785744598; c=relaxed/simple; bh=P6GdP+DetwWRo2QX+im0cRwA6TbnhOUrvN66t4dGOD4=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=u5I0y7jMM58zYP75i8u52zKsVSlE7+GkX6DWqjylBHqy/3g2U3xhW1msOBaeJyVDpfwGOAHz63dLEPAHB4o5ths7QWBUEInEDzJ5wzQAhT6yGDKQcpETmHC/ZFtuTmlvzffl9NkPb+EdHgu9w5OXXgfMxcc6G5z8VU2NEmidqwc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Hktth1vK; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=E+NqYbG/; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Hktth1vK"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="E+NqYbG/" Date: Mon, 03 Aug 2026 08:09:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1785744590; h=from:from:sender:sender:reply-to: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=zrCcobgqKcN3WPYBCsa5ZUf7s7B72JYkx/yDQFB4/mc=; b=Hktth1vKM0EzVDof1EnSIhLgouFi3aFLCbP42qnusk0uhrsSxLdIT060Y/ioQ+Xl7ysdXW Yz+fYbdK76cXu7kFv+/dPqEpf2hu82LPTXg2FJCoMDImy7f1dSGuzpdJnfWMCxK5R7aYoe MB7xu0NHxnjUBiHWs5XLwxAFEqXHkG8Uaid/CV00vFpb6WCSG2Od5SmMwYvKr3MHSet91G qM67PhmYf5vm89g+HqOTKW4GquDFJvjg9PJHFyuP3KHo1rMp0uBi9St3c5mnvFqx1669Pu c8V/js1inl9eUq4HPmU71CJQjociTrGo1q7EOZlrDnhXhj/xOW2ePypDK9PpsA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1785744590; h=from:from:sender:sender:reply-to: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=zrCcobgqKcN3WPYBCsa5ZUf7s7B72JYkx/yDQFB4/mc=; b=E+NqYbG/wM9I2BKpE14jjoLKXM+mRBD68IkXAGrjzHGsEV78wN4QqCjBqLPpuTrjL8tXLo irjRVT2YTb3Pu2AA== From: "tip-bot2 for Sun Shaojie" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/percpu-rwsem: Annotate intentional data race in readers_active_check() Cc: Sun Shaojie , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260623104132.505117-1-sunshaojie@kylinos.cn> References: <20260623104132.505117-1-sunshaojie@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178574458879.1210945.13436761488087536694.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the locking/core branch of tip: Commit-ID: c9c8578ad58e66a64ca887731e2b6ebf9d71174b Gitweb: https://git.kernel.org/tip/c9c8578ad58e66a64ca887731e2b6ebf9= d71174b Author: Sun Shaojie AuthorDate: Tue, 23 Jun 2026 18:41:32 +08:00 Committer: Peter Zijlstra CommitterDate: Fri, 31 Jul 2026 10:32:25 +02:00 locking/percpu-rwsem: Annotate intentional data race in readers_active_chec= k() KCSAN reports a data race between readers_active_check() and a concurrently executing reader: 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 readers_active_check() calls per_cpu_sum(*sem->read_count), which iterates over all CPUs and reads each CPU's per-CPU read_count variable. Concurrently, a reader on a remote CPU is modifying its own CPU's read_count via this_cpu_inc() / this_cpu_dec() as it enters and exits the critical section. These are plain reads and writes to the same per-CPU storage, hence KCSAN flags a data race. This race is benign. readers_active_check() is called from the percpu_down_write() wait loop (rcuwait_wait_event) after sem->block is already set. At this point: - New readers must immediately back out (they see block set, decrement their counter, and wake the writer), so counters can only decrease. - If the sum catches a reader's increment before its decrement, readers_active_check() sees a non-zero sum and returns false. The writer merely iterates the wait loop again -- a harmless retry. - A false zero (observing sum =3D=3D 0 while a reader is still active) cannot happen: per_cpu_sum() reads each CPU's counter, and each per-CPU int read is atomic on all architectures, so an active reader's counter is always seen as non-zero. Annotate the read with data_race() to suppress the KCSAN warning and document the intentional nature of this unlocked access. Signed-off-by: Sun Shaojie Signed-off-by: Peter Zijlstra (Intel) Link: https://patch.msgid.link/20260623104132.505117-1-sunshaojie@kylinos.cn --- 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 f7e152c..6c78961 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) !=3D 0) + if (data_race(per_cpu_sum(*sem->read_count)) !=3D 0) return false; =20 /*