From nobody Sun Feb 8 18:32:48 2026 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.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 D2FBD2882A8 for ; Tue, 3 Feb 2026 03:20:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770088853; cv=none; b=uFhBrUyJyfX7BpxKrghpzJXTmVA96igiWmZsWg7iV0b8or5yoPHzE27Rbgca39p2XTKIBh1Gpifu05nXJcBHzYwQC5zlRKat9SNwKwspfduGMX+/Rt740TgPk6RkdLud3pn9bXfzI84O8mcbSUuqLiBRXiJKMVKGSr+LWnxRG7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770088853; c=relaxed/simple; bh=JXk8IyqhrHpFxXsAl8dGtNFL2Lakm80UhdvwCm2rA4o=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FIV8VuWZ86YEEpkfhgnniALZflVTbJMXp2ELJmrWBrMc6cD4pIa3ejZZi4htaB4+1n2QYZPyAbUyTPEzgs0IWxFqZH5n08qG8//IS8gD2+QFYP+hjGFGXcS9rITIPIdY9cU9hKgRYsoULZRgwzjbYyDc7y4vd2RfY3MouD08+io= 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=V6GCKH90; arc=none smtp.client-ip=209.85.215.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="V6GCKH90" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-c61342a69b9so2012862a12.0 for ; Mon, 02 Feb 2026 19:20:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770088851; x=1770693651; 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=Fba9wK0ddQLmfW7kwqc71u405B8id7PXxdc3NF0N80Q=; b=V6GCKH90nhv0lMUbGsVE4roYnVkz/PQL9b2xzXEeHbthVnMLJOFheTlAJrQ2B0ydp8 rDf9bv8HpR/v1ZgVJYtehM1hnaDOMrTipQDM1rZN8tPEQwA8Th5IhlQ3G5dqjU43/XsV DP5L3loIUKQsFBxUM+U4+jnURuNDyZQdONJ1EzDaDvwlQkn/drTv/H+ejfNlv6PmDEN7 Fo03beWYUuO7rhm8gneMkFNrralYezyjgbAFQa0vvJdsNB63PBjqsqDn2L7TfBGCzKCb obKjGRprNvHakyQNybEVtSUWvovKMYRNZq/Xb3uipcJw9OIwHPqxnOKLxIOuj5NGEUj/ G5wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770088851; x=1770693651; 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=Fba9wK0ddQLmfW7kwqc71u405B8id7PXxdc3NF0N80Q=; b=h6hTSDOmozu0MTsl4+xNHLFpCeUi/0A+H9DkswgCKvmZ3+QG5Pn4553xK8mHbFsVgV KAVjdnuDAJ0xK1CGADXqpzOAaN5X+zbHLIoV3REJPsY/4i1DLoZRcwN9SUeR3FcWDRqh h80rwIEauStaLlY8qjB1uZZ/mRlehJ2k68OHhr/j6JIA4CB6k9SKTEMA+43QxgfM7tgE KePL5oyp6Le5f/R9G1i1topWQLRIjUESWUMSm9ckpY+2sHzY76Qan5aAUpOLUkSgRT6x vL5zhf8CL7Z7//RTT46U0snbrl+eWlTGnUD7e6OUKHGmR3TjU27g17my2rJFdxB6ZNUs DYSA== X-Forwarded-Encrypted: i=1; AJvYcCWzy180xaq5dVxHZMNxphWrcWJORVQArU7ee+NvnLmu/IuzuG49lWecddv5kygdrvwPnWU46HSVqJJ9tXo=@vger.kernel.org X-Gm-Message-State: AOJu0YyWW+gqN87lb+spbhT3DeRdMf2flmloGSZlxBa+gr7LOmq/CdvU KqByzft8Av07XK+PupmJdhoUoBtDY+hRAIjrDLh5el4ZrpaH3T27qQ6z X-Gm-Gg: AZuq6aK/Df2pqKK9Er2/rwV7LI+0EaH8WU9OfV5n6+PHmK5d+oMOyOz1T9MPMbsx/oo ioklnqpblx1xGb+fOk20lhbE5pcde4uoIA/YeO2ALrKIoURbx6jmYoG2dPDzGOV5tZyycOLxBkL LZxibM+NNj/Omdsq9xbnTvEW4vsyEUMaiEem0+yQWXdk7m2h0XWT28oOl03twl/KlcfACWrILuW QbAO0sH/A2R80bfotZFBKTMZezfTFquv4Hjjn4iLYI3oZ/D6WNOpw9l+CNPy4mQubLIUEHr0cDF /Tt3sTPGR8vnhcEnL/r3RwNc1KzzTV1aQxBNzFKqzfXF6Pja5nXC5XU130oIKXHy9Z5YfvpB4it CZx/R3JPSwVc8JVWt2H6k5cMOs/R4J8oV3g7lWx2ombvz35E4SAn9vlVFFNnUgCOdCMuXpDwIm6 TwqiU/H8rGPSMonJTAqAsZaIpyJqHJmT78TmsIz4tWVt5j1FdkxSoQuBnMCKngMw== X-Received: by 2002:a17:902:c952:b0:295:9cb5:ae07 with SMTP id d9443c01a7336-2a8d8038ea5mr137502935ad.38.1770088851078; Mon, 02 Feb 2026 19:20:51 -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-2a88b6e4189sm153967435ad.83.2026.02.02.19.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Feb 2026 19:20:50 -0800 (PST) From: zhidao su X-Google-Original-From: zhidao su To: tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com Cc: sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, suzhidao@xiaomi.com Subject: [PATCH] tools/sched_ext: Improve BPF verifier arena detection workaround Date: Tue, 3 Feb 2026 11:19:54 +0800 Message-ID: <20260203031954.915681-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" Replace the BPF verifier workaround in scx_sdt scheduler with a more elegant solution that: 1. Uses volatile cast instead of bpf_printk to generate LD.IMM instruction without producing unnecessary output 2. Adds conditional compilation based on __BPF_FEATURE_ADDR_SPACE_CAST to eliminate the workaround entirely on modern toolchains 3. Updates documentation to reflect broader compatibility concerns This eliminates the side effects of the previous hack while maintaining compatibility across different kernel/BPF toolchain versions. Signed-off-by: zhidao su --- tools/sched_ext/scx_sdt.bpf.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tools/sched_ext/scx_sdt.bpf.c b/tools/sched_ext/scx_sdt.bpf.c index 31b09958e8d5..88ac3043a643 100644 --- a/tools/sched_ext/scx_sdt.bpf.c +++ b/tools/sched_ext/scx_sdt.bpf.c @@ -64,15 +64,15 @@ DEFINE_SDT_STAT(select_busy_cpu); static __u64 zero =3D 0; =20 /* - * XXX Hack to get the verifier to find the arena for sdt_exit_task. - * As of 6.12-rc5, The verifier associates arenas with programs by - * checking LD.IMM instruction operands for an arena and populating - * the program state with the first instance it finds. This requires - * accessing our global arena variable, but scx methods do not necessarily - * do so while still using pointers from that arena. Insert a bpf_printk - * statement that triggers at most once to generate an LD.IMM instruction - * to access the arena and help the verifier. + * Helper to ensure BPF verifier can track arena usage. + * On older toolchains, the verifier may not automatically detect arena us= age + * through indirect references, so we provide an explicit reference. */ +#if defined(__BPF_FEATURE_ADDR_SPACE_CAST) +/* Modern toolchains don't need the workaround */ +#define scx_arena_subprog_init() do { } while (0) +#else +/* Older toolchains need explicit arena reference for verifier */ static volatile bool scx_arena_verify_once; =20 __hidden void scx_arena_subprog_init(void) @@ -80,9 +80,15 @@ __hidden void scx_arena_subprog_init(void) if (scx_arena_verify_once) return; =20 - bpf_printk("%s: arena pointer %p", __func__, &arena); + /* + * Generate LD.IMM instruction to help BPF verifier track arena usage. + * The volatile cast ensures the compiler doesn't optimize away the refer= ence. + */ + (void)*(volatile void **)&arena; + scx_arena_verify_once =3D true; } +#endif =20 =20 private(LOCK) struct bpf_spin_lock alloc_lock; --=20 2.43.0