From nobody Thu Apr 9 18:41:34 2026 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 632E23ACA52 for ; Fri, 6 Mar 2026 14:17:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772806646; cv=none; b=h24Sd81yCxDusY46EI+pCr82eJGrdS1SGcrDClQlXMNRYVS8nX83F4/p5uGJnEopo6t2e5d/0rwzMrQBRlB+H3iCZROqGW1ymI7mEYUjgkWLKo7AzJGBxwlQajFhMm9KgOojd9QQh48sIU1JtZHQohfpMsRJ0yDpqypvdfqPBqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772806646; c=relaxed/simple; bh=uzRhG2waj9YPKA+eQoa5kyWaQhKsS1FA6irUTeRvHuQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nfuSBs3FIrxbv/xKIqbRYs2AFrhYGfQeEdsJbfG2DujyS/UAlUf7EAYQCUwuwVXEBHtkJJnWew9nvlJev8sdCp0yjHdp649XJz1pPzCeherv+f7dYsq9bCbtILzJnC0SHn1ujjGsK/1livl3UAGnycU+vSnGxtPhGaJ/dZWWd4o= 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=OTOC2O1i; arc=none smtp.client-ip=209.85.210.169 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="OTOC2O1i" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-829abaaa92bso139806b3a.1 for ; Fri, 06 Mar 2026 06:17:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772806645; x=1773411445; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=b15QORKSDrTLJTIKvMf1+ueicTFAHfVm0j93qNup2Mg=; b=OTOC2O1iuiilbC29hOTgA4S1zaTI1q8bCG1CZltfzIlB/sdr74Xg640RuPvE8utki8 fvuS/0mrTCmjqy52T0wzhux8eKz6mgB4deAZa1GlJ7msaKO+Qy5o9wcU8/xUDVliOuOx C9aVIZR0XdNZOU4AedOuJRiu6nEkC/iTUXAsag4NMocUkqips3k3KbzK2V+feEzb/dIw KqfuxbERg8vDvNqQt81hKEXr2t4JGYkoptIgIONVeKa4OBDJqbhZtwPkrjbGoxNYygcT 5VNlLvPDaBwpZUkYHZGK3fOie0dg3RSmvb0k6ivR0APLHmWcWn+9Alr+7QNygRdxIw7n G55w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772806645; x=1773411445; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=b15QORKSDrTLJTIKvMf1+ueicTFAHfVm0j93qNup2Mg=; b=HqYJHT/9GREmSpKtTX03AEY9WHUjGXMlYLT9EpE2AyVTHhTw1wgLM9WuKtCa+fdnzN N3R4MJlAGDjRFlEoG3aSuHGjK0IrK8dEIRZsPHW3lw1rdRa5aZ9WfFcIdPOm4ZwESX9U 2TUf6CD6skLF1bnQJg6/dfsoliak2NuWNF24uxYdpRNWF5svCqd5rt3FwCLecJb88bvk ZPL9wvSrA4JqpZ40YNBfyL1xLgBrEXgk7bGf0EceOCnTohGeQdzhRr47MVVjtOpVqA4s nD5mJw7TDuo7DkQ/+ah0O+9S6WmdZYh6huRDDxMCvU1eG6aUpdEYaUzAoc2jPFv6CRSX qjmw== X-Gm-Message-State: AOJu0YyM83itDIQPfARTWZ4+4rsqPc0wvy+ANz45mIWP2NrrsTF1rtT/ +ti8R92kus/OYVcrJrevV8FwWzzD7efGYuJiCD7syv2hp3CMDwZXVjUa X-Gm-Gg: ATEYQzxSvrEsOGVNg++gtrhvyqKr3uqVPgEEmwZgFXbI54scOvq2j5D25BIinqSJxhc GqVEkVn4pC+OrQGqJCs7B5m7Q+hda0nlcKL4C04V3RpYH5tcOtKm/8yyNm9qcafL/OgQ9zUTudf mHo6P2LvSdcxnGgq/LnNBdpji81TdKqwH/o/tYuQC6Y0HMBxPuRWxE7SUVqeeTLnsjceEmr7LiO ZepjIt+JxxelrJvU4qcYfzzsUob2DJz2ep1cL1mD5RTPtqG2yrY/UJl7mgxzNMXbnRTGI8kxe7X YjPArh0ERjFPs392lLI0VY/vL+eXQKsg9SCkkTeIXN+2U4N5P0xHaHTqg8WpNH48xkVsSzJRiNw Y3/wTjhmQXWGR2XYvoAsnSIHKnT/I6Rpgh7o95WWaUCUppa3Zpz2nzVhogNtLb0j08v06sbATAt J44467030qzV06wZG3BtgTyuW5yzkbC8DyO9/F4qhktUPDUV5h8ZyxBFb4OVRPcSf8qwmLVU0D7 Fc= X-Received: by 2002:a05:6a00:4505:b0:827:4343:4c1 with SMTP id d2e1a72fcca58-829a2e39d41mr2103832b3a.29.1772806644725; Fri, 06 Mar 2026 06:17:24 -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 d2e1a72fcca58-829a4866763sm1920504b3a.38.2026.03.06.06.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2026 06:17:24 -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 v2] sched_ext: Use WRITE_ONCE() for the write side of scx_enable helper pointer Date: Fri, 6 Mar 2026 22:17:18 +0800 Message-ID: <20260306141718.2721073-1-suzhidao@xiaomi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260306105901.2543743-1-suzhidao@xiaomi.com> References: <20260306105901.2543743-1-suzhidao@xiaomi.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 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. Fixes: b06ccbabe250 ("sched_ext: Fix starvation of scx_enable() under fair-= class saturation") Signed-off-by: zhidao su --- v2: Add missing Fixes: tag (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