From nobody Thu Apr 9 14:08:11 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2C3C330662 for ; Sat, 7 Mar 2026 23:32:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772926332; cv=none; b=TEFjKICcSsc8vGastjj2CrbFB+ihR/JeNUQICAe8jWRosCk4MZrNcc7TLsvzRrK9FZZvxPU4FlUFEkD2bV6Xi17SY9D6M0mK2OKHdZS+9AvDxCpP8tIIzMRGrIWLOwIN7D2LsoVVYjcmtIBtpXUmmIVT4KpC44lTWufqKuxjrJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772926332; c=relaxed/simple; bh=qh4kdq/f2MjHwUOPIHZhTw8pKND709GvA8446cH6DGY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=buNFqhjpcEqvLpsu/2lqsQy0kFSiCZR/dKSH0of2MFlHmYB5AegC62jDkbQdL3TlexSUhEG1gShg2YsFtC/ipIlrHMV+szDUegiVADb5ISMBMKq3O4qKI1dFu3Wg7BqM0hI9HO+1Ri8Eu8vqedDx6B7/ush/WBtru7Z4V+ro25g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c4735RSt; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c4735RSt" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-4327790c4e9so8012550f8f.2 for ; Sat, 07 Mar 2026 15:32:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772926328; x=1773531128; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=KVsyG0c5+JO67r/aSVvJQUFRXdBlNPJ8cINS7o0jxdg=; b=c4735RStIyMsnHpR6Eky+hdJjs45vUP3DrAYt3tLK+hWU/X777gdYWGcPsHlcrL6ZB XRLrKt8LNIO41bwtPILHVc9bZScQ1xuVyZ/8M2nIFnx2JF0Il+HfgAkM4BSuJQYda3O8 rM8zikXXE69Ec1pyOaYyyNM9YjSbfQQ1CFxvJxFnqyxlsIPgt9x8nFuNKWHPXimgnH/d CGH/1JC/Tn2cTGT1CgGpgyjQMQo3PDgyhToAN21/wj8H3SmX/6cEUFCGpDe6EroEhKaO 3qwW2bJQCGP0so1FUXCoffXmlcZWEiCSuE+DWYLmnzi+9zWFBVjqhQyKQI/VdjO1SnGo pdCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772926328; x=1773531128; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=KVsyG0c5+JO67r/aSVvJQUFRXdBlNPJ8cINS7o0jxdg=; b=uFY9nJjnNB3AXTVjazvaxO7QO6DcbqFppN2OsAqf555aB2uXzlGGqVcsaxY7JTlDoW de2bywIH0wRV58NiK3arR9/zQk9QWirxIVLDY7jkgllJ0gttIGcdrn7mmfUtLBJ3Jzw9 6ioOedndd3sagk0gDlvX8uKHG+DqJyC2DeGdfy9gyzldo0ALUJUWflNM4+3X67HKzHcL gsnZpQbglqaPnxsqWFQMmQj9M05ZFBqp3NZ59B7DClWrkKvFxolMb7z28b1keq1qMoQY rKwgAEnPAThiYo5RWdX5fuMCefrbiO9ozbkf9i6naR/voc4/zdTNKSSa8g6aXLvhneyh WdFQ== X-Gm-Message-State: AOJu0Yz8ROiflGCuFiSJotOQv5zfgxCqoCNehklMDvo5140oBmqwlQJb iPvuLVI27nL2N4dEbWV350UK0Q/a9h2j7Uq94pE5DpgA9jpmfu+DRP7q X-Gm-Gg: ATEYQzxcFgfc5SLQmQUUAzJBBBDqSe6iCTiBD2MqlKIXSAyM3IGrVn1GhCKCK881ui6 39eIhnLbdNIeRebqPQvfeLF2N8KL99tvXyM6hMi0Y/pnZPuOOFl5WEDxkic8fv92QHtE35tlbUT z2/vquDqIlWeKlskXvMvfxcjodgl/pKmk39q6YUgFCW005U2jHvMC99p1rlndTPHFr1TEox2B+u eQCm/t8gp2mT3QU1rYeXqqM8QgyjkNTjGLEpkmpd3wFKVLVDkc58IwKs5OyTwHYkpUlRO7flIOg w5irwdNCfDHhJiD0kqCh18YBIxPedIu3XjCqaOAmoRIxJAnEXQq3e+rpHjl8kHnPuakYY5gtkkK akkjXsDKbqIF3IZ36E+4DAW9ihEDf24RBY5xt/PcTz/nqqPbyH9CGYP249loI+tKzwI376mAg25 mPwShAwH2h5KZn+o3FGKw68/OiqgWwvYgTbNn2tS93ZdgQHPxgyduKsrN6BalGwTqVehwh7yNwV 4Tv2YKxXGhQ8Jrm5+tI X-Received: by 2002:a05:600c:c16d:b0:477:afc5:fb02 with SMTP id 5b1f17b1804b1-485269581camr123673635e9.21.1772926327561; Sat, 07 Mar 2026 15:32:07 -0800 (PST) Received: from rozandragon.chello.ie (188-141-5-72.dynamic.upc.ie. [188.141.5.72]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4852767d8e4sm133789835e9.2.2026.03.07.15.32.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Mar 2026 15:32:07 -0800 (PST) From: David Carlier To: Tejun Heo , David Vernet , Andrea Righi Cc: linux-kernel@vger.kernel.org, David Carlier Subject: [PATCH] sched_ext: Use READ_ONCE() for the read side of dsq->seq update Date: Sat, 7 Mar 2026 23:32:04 +0000 Message-ID: <20260307233204.30749-1-devnexen@gmail.com> X-Mailer: git-send-email 2.51.0 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 Content-Type: text/plain; charset="utf-8" Commit 7a8464555d2e ("sched_ext: Use WRITE_ONCE() for the write side of dsq->seq update") annotated the plain write of dsq->seq in dispatch_enqueue(), but left the read side unannotated: WRITE_ONCE(dsq->seq, dsq->seq + 1); ^^^^^^^^ plain read p->scx.dsq_seq =3D dsq->seq; ^^^^^^^^ plain read bpf_iter_scx_dsq_new() reads dsq->seq via READ_ONCE() without holding any lock, making dsq->seq a lock-free concurrently accessed variable. 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. The plain reads on the right-hand side of WRITE_ONCE() and the subsequent assignment leave the annotation incomplete. Compute the new sequence number into a local variable using READ_ONCE(), store it with WRITE_ONCE(), and assign the local to p->scx.dsq_seq. This completes the annotation started by commit 7a8464555d2e and is consistent with the dsq->nr fix in commit 9adfcef334bf ("sched_ext: Use READ_ONCE() for the read side of dsq->nr update"). Signed-off-by: David Carlier --- kernel/sched/ext.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 174e3650d7fe..3fb8365ff563 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -1017,6 +1017,7 @@ static void local_dsq_post_enq(struct scx_dispatch_q = *dsq, struct task_struct *p static void dispatch_enqueue(struct scx_sched *sch, struct scx_dispatch_q = *dsq, struct task_struct *p, u64 enq_flags) { + u32 nseq; bool is_local =3D dsq->id =3D=3D SCX_DSQ_LOCAL; =20 WARN_ON_ONCE(p->scx.dsq || !list_empty(&p->scx.dsq_list.node)); @@ -1103,8 +1104,9 @@ static void dispatch_enqueue(struct scx_sched *sch, s= truct scx_dispatch_q *dsq, } =20 /* seq records the order tasks are queued, used by BPF DSQ iterator */ - WRITE_ONCE(dsq->seq, dsq->seq + 1); - p->scx.dsq_seq =3D dsq->seq; + nseq =3D READ_ONCE(dsq->seq) + 1; + WRITE_ONCE(dsq->seq, nseq); + p->scx.dsq_seq =3D nseq; =20 dsq_mod_nr(dsq, 1); p->scx.dsq =3D dsq; --=20 2.51.0