From nobody Thu Apr 9 23:24:22 2026 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 E4D091339A4 for ; Thu, 5 Mar 2026 04:06:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772683600; cv=none; b=HSb2DX2aJZ+9torK5Z0PxH4iC6wMEXS9ThUi6qxaIfqhvORMCO0zKqhjkesDH7sIWuoOzoXq1bRtqbId/ReTo9IajDS+Lp3id3DHfA361gH2T+92NPTi1uYtT+EPeJwOXlwXiZiKlupDWd/1rokAMUFc0YX1Ma4Q4zOI0a1uVwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772683600; c=relaxed/simple; bh=K3I1WO/XZ12LOjA7uCESl0KE5zvtyoQ+YxgsfnqqN+8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=CMFkKwXm+UtIf8FM4TugdRQoHWRkLlgv9gtgqMUI1AE1iY9PtrWfSNI036GkCZjvVuxJJO8mlZ1cB2mSxZzFdD9ayPcrbePjDRe8JRvAG2RBzOLCz+x+Thp97ml1K5w9QjUlhyC7+LuEEcdmhBFFa35xGOpM8chiuRTaaemeIeY= 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=VppPAbOc; arc=none smtp.client-ip=209.85.215.178 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="VppPAbOc" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-c70ea5e9e9dso2774852a12.1 for ; Wed, 04 Mar 2026 20:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772683599; x=1773288399; 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=8OQSjVBPYaZXq4l1ZMR/y6g/ReN7WoQx6dDK07M5fRA=; b=VppPAbOcK8pAF2H21mjqAL/a8fiM5Z6Z+0pWUY0ygMfwp+9PsElSiXx16/CsV+Z6KS y2PxWBxe7h84Pr95kveNdjcleXWyW2b+h3wRc0DlP07P7Pg1JcHuNDdWx/RJnSkCGWob Vf4QgWNjifu4SSt4xgOddt14hJbbniu7vR2g3fG/ANE+GbeRCItX2tlRDWUaHkDfNZEs WYewrplfDXof66NFf2wt3Ly3RQOl3L++i9GBchYZPoTboVJu5dNYfINDdMW4Tg6Iusfx 2d37azy1NrbI0hSCDrSxVLs/ejcbVePFLdMXfpMGvD0CzwIef/nhdU+BZrBugeCFnvwK HTYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772683599; x=1773288399; 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=8OQSjVBPYaZXq4l1ZMR/y6g/ReN7WoQx6dDK07M5fRA=; b=r0gCnwu6qo1+FgAMXaedeAdKM7QsBupoR2zGKrIe1HiFVLXPJDykzIk/5iEBXFlKi7 pjOpP5EbnwidZgs3UlXmP9DfNNxhVBbF2fykXo4APuAzHxZWlLWH90PVQzQzzc5pQTs9 +e7pgleRGPTAWI+b0wnQqRwaiv+HZAvvM5fvzUlXM7sJ60m9jpgSDsEy8RemNuUe+3Cw ZHRN3NcxuNWsMhtpeZFk2luTYbiy8F+GkA0FdLVJQ+ez7TTBy7w0GUgvseMZTSxdnkI+ 6+woN3md8TD5MmKsxG+JiP6Rpjhcujy/1VIyGtt7jlQ6hDyJVz/dLbKJmvu7+3Hl/f3y ENDg== X-Gm-Message-State: AOJu0Ywjcve7kCnLLgjRiZNMCtrWWBMZZk8WMQoT+gJzCyzG7qu7nYic tE1xqp4BJQiXRiUSgkBPNeGhXjHtErba1+/1rfPGW6thwgmBtAZo7lFtNHY8Bo4h X-Gm-Gg: ATEYQzzQhRYl/ePUff1CnwD+EcIDHkATKAAWEDrk7/R7YOdHduTaj/+q275A+eCXjvY VrWea8QjF1g2XWdBJh7eI6AQl5/9WGLPEdah475CM19FNVsnHgFRIHSnEux5hy470R6hsGEiBAB H9kasH7/coKGJ5W/5WMSnN17eBX9SmE7JJuvybIFKeWwtkqmqeqEw4wtjrpatAJhpaEl471ACIX bo8QkdaKi6qyaIQOGP5zWrGnT/y7V/LH67yUKEIejgR3yVTguLcfQlohKntLcMQUJfNR+5eIgOm zC35ClBZd78I2cSVZ4+z+AViElqnePScQlkn2ZRaW9E7xS23ms8P5FAOjrhuPzPBPlTjMTgTSlj WnwwWqIPqKQ7OQLXwEMUjLSDgWf03vCYUWMI4nVczOFgeAQxodeLLwqKMJEsmZ6oGDLBcuZimeO Jfb1rNj+uIgEkfa/vEs38Mi9GG3nT8WSCK+f98wyp3qWKaiIZuinAC7KWDD1iy73RJV0gSByHlR s8= X-Received: by 2002:a17:903:b83:b0:2ae:62c8:7738 with SMTP id d9443c01a7336-2ae6aa0e414mr41503165ad.22.1772683599049; Wed, 04 Mar 2026 20:06:39 -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 d9443c01a7336-2ae4cd40e4dsm113204455ad.92.2026.03.04.20.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2026 20:06:38 -0800 (PST) From: zhidao su X-Google-Original-From: zhidao su To: linux-kernel@vger.kernel.org, sched-ext@lists.linux.dev Cc: tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com, zhidao su Subject: [PATCH] sched_ext: Use READ_ONCE() for lock-free reads of module param variables Date: Thu, 5 Mar 2026 12:06:33 +0800 Message-ID: <20260305040633.1274357-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" bypass_lb_cpu() reads scx_bypass_lb_intv_us and scx_slice_bypass_us without holding any lock, in timer callback context where module parameter writes via sysfs can happen concurrently: min_delta_us =3D scx_bypass_lb_intv_us / SCX_BYPASS_LB_MIN_DELTA_DIV; ^^^^^^^^^^^^^^^^^^^^ plain read -- KCSAN data race if (delta < DIV_ROUND_UP(min_delta_us, scx_slice_bypass_us)) ^^^^^^^^^^^^^^^^^ plain read -- KCSAN data race scx_bypass_lb_intv_us already uses READ_ONCE() in scx_bypass_lb_timerfn() and scx_bypass() for its other lock-free read sites, leaving bypass_lb_cpu() inconsistent. scx_slice_bypass_us has the same lock-free access pattern in the same function. Fix both plain reads by using READ_ONCE() to complete the concurrent access annotation and make the code KCSAN-clean: min_delta_us =3D READ_ONCE(scx_bypass_lb_intv_us) / SCX_BYPASS_LB_MIN_D= ELTA_DIV; if (delta < DIV_ROUND_UP(min_delta_us, READ_ONCE(scx_slice_bypass_us))) Signed-off-by: zhidao su --- 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 1c3170846c84..9a1471ad5ae7 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -4004,8 +4004,8 @@ static u32 bypass_lb_cpu(struct scx_sched *sch, struc= t rq *rq, * consider offloading iff the total queued duration is over the * threshold. */ - min_delta_us =3D scx_bypass_lb_intv_us / SCX_BYPASS_LB_MIN_DELTA_DIV; - if (delta < DIV_ROUND_UP(min_delta_us, scx_slice_bypass_us)) + min_delta_us =3D READ_ONCE(scx_bypass_lb_intv_us) / SCX_BYPASS_LB_MIN_DEL= TA_DIV; + if (delta < DIV_ROUND_UP(min_delta_us, READ_ONCE(scx_slice_bypass_us))) return 0; =20 raw_spin_rq_lock_irq(rq); --=20 2.43.0