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 378B5423A9B; Tue, 31 Mar 2026 16:59:04 +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=1774976344; cv=none; b=pO2Ul2ZAgGbmpYC5BM5fsEQFAju41vFmvJYTbjyV05pmuluGtsclzcW1SUihVnqblHg7tnAir95uMzrlurxpZlj1KGEKmNU53yDuP3BpX1805NCTwklOAvfQSK880WYZAaPyfX/RiJcnDsaMTfBnYDgvcPTK7ubx51WmzSiksdk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774976344; c=relaxed/simple; bh=lVpEoRfoDuLpgTsD8uUhyNAjvfC2/mspilJtezqoWTE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gtGygVHhSzZ3qkk1IfC/uSBq1TApDgk+28HIb+Mle98eELa24C2axuqOLHd86UKsi70237xgLohd/SM1yxdKlyY7cKTEdTIQeaDagD6oqbbDqAwHbmWjwSUBaXMnh0IYFZEDsOPjr9nbHGNtlpca+C8crxxY2f/DTsBDQ1Ty5Cg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NLQKHzTp; 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="NLQKHzTp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7A22C19424; Tue, 31 Mar 2026 16:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774976344; bh=lVpEoRfoDuLpgTsD8uUhyNAjvfC2/mspilJtezqoWTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NLQKHzTpmQ3+v3mzbLKGk+tASZAfPWCnq6YT7eeLWKs96Io2uVacG/zu8t+wOswdB p7U8/6XSeR7Xa+lkzZTo+dq3hKMK92/AGo16aMeiLvW3EzwNh9DiCGI4+rjsb+VqsJ 5mSeyH+V2U+UQXBpl5kCt4wHvl0IWpvzGgInonEw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, zhidao su , Tejun Heo , Sasha Levin Subject: [PATCH 6.18 055/309] sched_ext: Use WRITE_ONCE() for the write side of dsq->seq update Date: Tue, 31 Mar 2026 18:19:18 +0200 Message-ID: <20260331161755.512104407@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260331161753.468533260@linuxfoundation.org> References: <20260331161753.468533260@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: zhidao su [ Upstream commit 7a8464555d2e5f038758bb19e72ab4710b79e9cd ] bpf_iter_scx_dsq_new() reads dsq->seq via READ_ONCE() without holding any lock, making dsq->seq a lock-free concurrently accessed variable. However, dispatch_enqueue(), the sole writer of dsq->seq, uses a plain increment without the matching WRITE_ONCE() on the write side: dsq->seq++; ^^^^^^^^^^^ plain write -- KCSAN data race The KCSAN documentation requires that if one accessor uses READ_ONCE() or WRITE_ONCE() on a variable to annotate lock-free access, all other accesses must also use the appropriate accessor. A plain write leaves the pair incomplete and will trigger KCSAN warnings. Fix by using WRITE_ONCE() for the write side of the update: WRITE_ONCE(dsq->seq, dsq->seq + 1); This is consistent with bpf_iter_scx_dsq_new() and makes the concurrent access annotation complete and KCSAN-clean. Signed-off-by: zhidao su Signed-off-by: Tejun Heo Signed-off-by: Sasha Levin --- kernel/sched/ext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 4e3f06c19ab46..bf4bea3595cd0 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -1019,7 +1019,7 @@ static void dispatch_enqueue(struct scx_sched *sch, struct scx_dispatch_q *dsq, } /* seq records the order tasks are queued, used by BPF DSQ iterator */ - dsq->seq++; + WRITE_ONCE(dsq->seq, dsq->seq + 1); p->scx.dsq_seq = dsq->seq; dsq_mod_nr(dsq, 1); -- 2.51.0