From nobody Thu Apr 9 14:59:31 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 56313156C6A for ; Tue, 3 Mar 2026 06:10:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772518205; cv=none; b=P57i47wjab2t4THzpK3ER+jg0M5AseOfgXaZVMuTrwu3izPn9HtvgB5ryBhaXCYY5YHBthPBgxVDjjiMeWdhoMs+s/1qHIHB8HcbxriT90LfOJz/xfWFY85jCb7LXLkM8iovf+FrHnDLZkrmbkOMCRB23lzFHUzaLdlwiecNBmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772518205; c=relaxed/simple; bh=bv2Jz4U2DpMjAUfifYxKw27bsTlEORVTMJigqU5sadg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=jGPe69ZvuC62zxn2mABUV8yLt90xwn8R+PIvc6FTB87HwBih0/DDqmva5Zb/CsXjPgManshTXmM1bUHW1yBnh4KQ5msszFiLElui0+XSKVcFzLdAsOTVFLILRaduqfoFuJyMJy+u7FMeto+8iB2cm2CTzR8QoxVxGGCTicPIJ3c= 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=LIr5SOWS; arc=none smtp.client-ip=209.85.210.171 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="LIr5SOWS" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-8272c559597so5207374b3a.1 for ; Mon, 02 Mar 2026 22:10:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772518203; x=1773123003; 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=P6esbafM8AfMQhSMQFEvnisdVNGuHu/hvV9/NaeusRQ=; b=LIr5SOWSfpvrPLvklRLdlzfawx4xNJ5WupECBbHzkZvgFBnl4V1vJm9IfUd9pD7WEr gtH0MV+r4NyomS39434MAk4UlBYrlB+U/7G6MHkQ6w3c7zCCWUhn/nvutkqS1VTh5+Z3 jcEG9X/lKKbIH7SRkobDB2CP49qiloSbnz6DdV4KmFcokOFOO1H66iYjeDNNWO+mAxvV bPvKxU7gP/F13oiFkjgeXxXiEyNKf98gTNqUwyN/XH/LGmKm9rpkFseY9vPZbcYwxMKq ZZz5UxjB/wiTI6eqd2qpfJ5Wq3Q1geGQ+F7hGdJ+zkOXQeRTZQUhAH60GBQgatgl3NPJ 40rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772518203; x=1773123003; 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=P6esbafM8AfMQhSMQFEvnisdVNGuHu/hvV9/NaeusRQ=; b=md1Oq6C+E+dkg5ZMtD119NQDoGxzHmE/DlYq/R5NJdNWpBuSdbZAnrcTXuN3UxGIba O8V6ImqXgE1H9WDj8SioGdHKwvN5hkF9vbvmbl8q32+Wi4NtS+ihujUVXO0gAymxi3KG rMuRG/1OYMjG7Suw+Y4tg+81N+WfVSn706jV9aorzXCgnFk/jVGW/8Hf0jrm7V3eN3L8 MeYXtEc55NWuJ8wcvpfpcm8Ls39l+QDPS7RdIeVGNiVO3tPvSbOciDbrA/LVZn6jBmiS WVS8sAEK/dcmwnQRWZfHFhUSYkwjBzXsawVlpJCrd6DEWS3gmWTwAFKq7fi2j3sKyZRU jJDQ== X-Gm-Message-State: AOJu0Yz7Kk7Qo81SR8uwAgmpJyprngiHizyg/qkhB8cXB/ATLCl1thqg K4E6YZlGOhmIR9l0Yyazia+gvFJGW2k2wDY9suJ7rFVDn2emxcHgSYTEtU/zz/Lw X-Gm-Gg: ATEYQzyniAHLHToSGReQZgtaeMqxLeQBKp+XtkP0BUWZ2frZNGCqrj1BccP55vCBQOc uN/76bYhcbqM+qPnPJRifRE/4f3xvUB+pDrBrP15DhGXGwQkhFWgnT9+UBF73AjiqY1uNqkBHcx ey66VHpw0lGPa+YenCTfxtZKyq4I7rpUiR/Opjj5j6sXAMV0M3TJUIwqQ7XdmgZe0TxlPLciLd+ mZhiXmBXPxm6Zo/X1B5EDFQYbveuBiB3JhBs/vEI5xudCP5yRBLrU1UwClVFZ3I3stpXZzDiifL N4zm1R3zlQa26aj+MPWzLxGTp7FM61FV2Y5AzZqCHFo/9aZg/LPscHFFExQffjfbVVyS2zhQduj cCHBFQKIup1ONHe3m/ZZYs+SgH6aomLA4kX4t0f/VXAH0ANj/MpyxAvGiKzTXrCynOogVrR4Suo roJs2xCo82ciU9qMEpG5y6AWk2ZRaWngj5pxRhq0sZ7Rey2T6W+DFhLnFW+jPguWpAb6d0QC8KL AI= X-Received: by 2002:a05:6a00:4fc5:b0:81f:eb35:69ef with SMTP id d2e1a72fcca58-8274d9f43c9mr15590469b3a.40.1772518203462; Mon, 02 Mar 2026 22:10:03 -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-82739ff350asm14116621b3a.35.2026.03.02.22.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 22:10:03 -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 plain reads of scx_watchdog_timeout Date: Tue, 3 Mar 2026 14:09:58 +0800 Message-ID: <20260303060958.120517-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_watchdog_timeout is written with WRITE_ONCE() in scx_enable(): WRITE_ONCE(scx_watchdog_timeout, timeout); However, three read-side accesses use plain reads without the matching READ_ONCE(): /* check_rq_for_timeouts() - L2824 */ last_runnable + scx_watchdog_timeout /* scx_watchdog_workfn() - L2852 */ scx_watchdog_timeout / 2 /* scx_enable() - L5179 */ scx_watchdog_timeout / 2 The KCSAN documentation requires that if one accessor uses WRITE_ONCE() to annotate lock-free access, all other accesses must also use the appropriate accessor. Plain reads alongside WRITE_ONCE() leave the pair incomplete and can trigger KCSAN warnings. Note that scx_tick() already uses the correct READ_ONCE() annotation: last_check + READ_ONCE(scx_watchdog_timeout) Fix the three remaining plain reads to match, making all accesses to scx_watchdog_timeout consistently annotated and KCSAN-clean. Signed-off-by: zhidao su --- kernel/sched/ext.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 147b31a7b3cf..b9247c9f0430 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -2821,7 +2821,7 @@ static bool check_rq_for_timeouts(struct rq *rq) unsigned long last_runnable =3D p->scx.runnable_at; =20 if (unlikely(time_after(jiffies, - last_runnable + scx_watchdog_timeout))) { + last_runnable + READ_ONCE(scx_watchdog_timeout)))) { u32 dur_ms =3D jiffies_to_msecs(jiffies - last_runnable); =20 scx_exit(sch, SCX_EXIT_ERROR_STALL, 0, @@ -2849,7 +2849,7 @@ static void scx_watchdog_workfn(struct work_struct *w= ork) cond_resched(); } queue_delayed_work(system_unbound_wq, to_delayed_work(work), - scx_watchdog_timeout / 2); + READ_ONCE(scx_watchdog_timeout) / 2); } =20 void scx_tick(struct rq *rq) @@ -5176,7 +5176,7 @@ static int scx_enable(struct sched_ext_ops *ops, stru= ct bpf_link *link) WRITE_ONCE(scx_watchdog_timeout, timeout); WRITE_ONCE(scx_watchdog_timestamp, jiffies); queue_delayed_work(system_unbound_wq, &scx_watchdog_work, - scx_watchdog_timeout / 2); + READ_ONCE(scx_watchdog_timeout) / 2); =20 /* * Once __scx_enabled is set, %current can be switched to SCX anytime. --=20 2.43.0