From nobody Thu Apr 9 17:23:00 2026 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 A333F1B4257 for ; Fri, 6 Mar 2026 10:59:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772794748; cv=none; b=Y5BrHy2rXT5eLaWAR3dVQrFbdNLld06IuIwQlmMi3w7m5pQDEtTKrRwaibwOCHvg/EQNfmdMAfYxafRXWfbjb0683/0bVLoV5ce7sJEqacpBq9DE7Dh4v422TLdXP8QDRO2cO2TbpXVg8Yy6hRPyvTBWYNj5HYKpaFWTvX0eHjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772794748; c=relaxed/simple; bh=U9vfN3aOervp6BiVrSrKKN/8sXJHVbme9yQU946P68M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=V87diFccocAw8f4F9QLQZ16aG5d+/TeOqN8wOsha1RLVL2dpK/QBxTcFrwlWiodBrj3OJJ7WHPJoF0PPuVl3By5O4IcZvv60XhrG+sk6mycEMsFDG0ASkXqLV99GkZCLZughVbaDbbMqapnTxZV1TfJcVa+iiQA6/eRGhRcQDMQ= 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=StGU2F4T; arc=none smtp.client-ip=209.85.216.53 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="StGU2F4T" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-358e3cc5e7eso4200565a91.0 for ; Fri, 06 Mar 2026 02:59:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772794747; x=1773399547; 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=VJX1Q5TDY8tDQM4DxMBMHAJp5Yfs+Kh2ac0xcWiEGwA=; b=StGU2F4TRhK40t/8zTTRGqtmJV/iSDlseB84sDnDzi6ca4B0nk88DbKvpfm510F4VW IQQXwuQ+pFowYl0S2791v3KxqdCzAUIl+kgTAAzAw8rndBeU8TdXKhBnFLvjol7Kseu2 VI5Txhz4dJsdMg3QEYRNpo4DoJCgoeLyqWvuLyWeuXh8a4fxAE3D1ixFQA+C3BkECSn6 85ehPuKXqiJFzv3s6d7tTVAP9xVDeEhZhB+1D9bAbIcabzMpI4bT6FddpjlpGzVrQ9Y9 3ffjiSGk5eEyVOMOl/5d3wuO/s1w66XUrGPAEp+L2LsS3hZKsLa5lLua549ZIWVW7FSk rwZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772794747; x=1773399547; 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=VJX1Q5TDY8tDQM4DxMBMHAJp5Yfs+Kh2ac0xcWiEGwA=; b=OBEvg8MvFuas2iJU3XK5bjxxpcGc6Om1b3of06Q/48aksm1ncuo41ShJcRa4eTfwRC 7e2zLxWsJfgJLN+HZibEfF/zXkDWa5HzY4wbjv5fyI4vModtGd3LZ0AI/tBwIqbBDLI6 KRXxEanY+vxyLeOEwK3B/1Ul1R2EHSPSzm3poTA+XopozfuXjXPQuKAdIpc8UkJQ5xye Qka/zs9wNLxlFwvlqiYxn+cXtF6wsbJfucv13fBhHhOjoGdyEj0V7cEWkOk2gxsIkdyb 7OSczH4sWUi4xVTqaWJcBnui/R8DF/FU/X49uE7mZKO8we1q9NAdbC9YTRIPSdsldFr8 nOEA== X-Gm-Message-State: AOJu0YzUNJMkBy5QpwSfriBBMCFOrOs0+jt+a4cMnuw90n1NXhGQgBDG DkLTP+KkgHoOcPkfdLhdMWyBOmB29rDrywWdr96wKStpheX1gXPR4fs2 X-Gm-Gg: ATEYQzzfsbObKX9ioztq/cjYZi1PN3X5a1Z151ThM5PNCPUmhICq7M/4CLuGebU2HQX +63sfhsgy7Bv9rKcW0vcu5HbxJ5bOlvMPHaqoO8cicteihQTguiIX7Kg8lUnBjmW9gxE1RTIFfJ Ncg3k61aKOYfFTlKM8ctcbYaNF4Pfpmh8JBfXHOCR7AWmGAKaRAb0d9KHe9uT9g2fi+QAPAaVp1 lFsMBJuasRPFbXlg5fT6B0RRF04X3gmjSOuFd1yjViExVKJLNF43TW58yYetvhww2gTmrXVDDol DXAKf+DqAbN5lzaeOi4jAwXMKlxUCNes4EAipcQveRdNk7EJrkt4UGk0Oo7ZruAJpbbSlDcOg9W gYPJgkVOi/mQc5vJOD3ZwFMyBibMhpnK1303cMPpMzT5ULhjZvepkvLtQbirz55j23BJiLgelHT Oq2T/F04y5dGrO7s3hNizHwHpSuK250qZFw4WF0wE7b1TRWvXIi97LZNWyjU+Mk2yLrrmwIHHIg 4w= X-Received: by 2002:a05:6a21:7747:b0:398:5f2d:5ae3 with SMTP id adf61e73a8af0-3985f2d6222mr862516637.66.1772794746915; Fri, 06 Mar 2026 02:59:06 -0800 (PST) Received: from mi-HP-ProDesk-680-G6-PCI-Microtower-PC.mioffice.cn ([43.224.245.226]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c739dfbf4fesm1427037a12.0.2026.03.06.02.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2026 02:59:06 -0800 (PST) From: zhidao su X-Google-Original-From: zhidao su To: sched-ext@lists.linux.dev Cc: linux-kernel@vger.kernel.org, tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com, peterz@infradead.org, mingo@redhat.com, zhidao su Subject: [PATCH] sched_ext: Use WRITE_ONCE() for the write side of scx_enable helper pointer Date: Fri, 6 Mar 2026 18:59:01 +0800 Message-ID: <20260306105901.2543743-1-suzhidao@xiaomi.com> X-Mailer: git-send-email 2.43.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" scx_enable() uses double-checked locking to lazily initialize a static kthread_worker pointer: if (!READ_ONCE(helper)) { mutex_lock(&helper_mutex); if (!helper) { helper =3D kthread_run_worker(0, "scx_enable_helper"); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ plain write -- KCSAN data race The outer READ_ONCE() annotates the lockless fast-path read, but the write side uses a plain assignment without the matching WRITE_ONCE(). 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. The error path also has the same issue: helper =3D NULL; ^^^^^^^^^^ plain write -- KCSAN data race Fix both plain writes by using WRITE_ONCE() to complete the concurrent access annotation and make the code KCSAN-clean. Signed-off-by: zhidao su Acked-by: Andrea Righi --- kernel/sched/ext.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 9a1471ad5ae7..c4ccd685259f 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -5355,9 +5355,9 @@ static int scx_enable(struct sched_ext_ops *ops, stru= ct bpf_link *link) if (!READ_ONCE(helper)) { mutex_lock(&helper_mutex); if (!helper) { - helper =3D kthread_run_worker(0, "scx_enable_helper"); + WRITE_ONCE(helper, kthread_run_worker(0, "scx_enable_helper")); if (IS_ERR_OR_NULL(helper)) { - helper =3D NULL; + WRITE_ONCE(helper, NULL); mutex_unlock(&helper_mutex); return -ENOMEM; } --=20 2.43.0