From nobody Thu Apr 9 14:15:10 2026 Received: from m16.mail.126.com (m16.mail.126.com [117.135.210.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7757254B1F; Mon, 9 Mar 2026 02:30:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773023403; cv=none; b=TVLSLFcOTRglW9TRN+nAbupTaHr7ANIVMssAvMG4Vix0JUKqywV6UCLmumuSEfZn/AG4fAscpcClruwtEHgzHqkjAZSfGL5Lchx7kf+LfmrxsTwQ820IieL2nQK5Dv6AItopbUvirx1REdjH7X+yCn/BkBKSugNxIlIgQfYmiwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773023403; c=relaxed/simple; bh=/1tjs1txaxspQo84xrzGcDbG3nJgdeSmSFC0uzTi9Vw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Id9w0turX4R8Z7CXFw6leHzI2ydgrQ4CRzjtV1wLcxbQTtuefE8vU3AJsba2yNdAsLs1VogqwVo8KmAtkoWHM4ZJeOY2KUgyoOAkweWe9RYROcEeLtsooKTY4dt3k4Oec7Veju5iWn7Z1CJo8VrrGOU7rHMi48wfjdkjIojzRAo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com; spf=pass smtp.mailfrom=126.com; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b=aNpYkuvE; arc=none smtp.client-ip=117.135.210.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=126.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b="aNpYkuvE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=UZ gWiBAvLd+YXyCRU//RkZvAYeiAPrFvirUav+rFLbE=; b=aNpYkuvEHaACccuNnT Xs8dhqd+mR645XcJ7cW1eMnxKOT4Ag1mK5R6fUlAW//zb3YRHPfPajKDdByhnIQK EWZAt2HJ8fDuTY8yiJIBH6GcZUy4LWyc8l635ZyddtLPApkmj6AIRj0m1412RVx4 qzjxB1D0tJgyTzgcV20n/KaAE= Received: from localhost.localdomain (unknown []) by gzsmtp1 (Coremail) with SMTP id PCkvCgDHb_5qMK5pKd7+BA--.65315S4; Mon, 09 Mar 2026 10:29:00 +0800 (CST) From: Zhao Mengmeng To: tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com, nathan@kernel.org, nick.desaulniers+lkml@gmail.com, morbo@google.com, justinstitt@google.com, emil@etsalapatis.com Cc: sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev, zhaomengmeng@kylinos.cn Subject: [PATCH v2 2/2] tools/sched_ext: scx_sdt: Fix BPF verifier rejection on older LLVMs Date: Mon, 9 Mar 2026 10:28:47 +0800 Message-ID: <20260309022847.106150-3-zhaomzhao@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260309022847.106150-1-zhaomzhao@126.com> References: <20260309022847.106150-1-zhaomzhao@126.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 X-CM-TRANSID: PCkvCgDHb_5qMK5pKd7+BA--.65315S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxKw45WFW7Jw1xXF1UuFyDJrb_yoW7XFW7pF WUJFyDXF1Utrn3Arn7t3ZYyrs3CanrXr1UWayrKrn7Z3sI9wnrX34Ikw1Fvr4qyrWSyay3 ZFZrC3Z2qF15JrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jYT5QUUUUU= X-CM-SenderInfo: 52kd0zp2kd0qqrswhudrp/xtbBqwwtpGmuMGw5qwAA3n Content-Type: text/plain; charset="utf-8" From: Zhao Mengmeng Under Clang 17/18, when running scx_sdt scheduler, it fails with: libbpf: prog 'sdt_init_task': BPF program load failed: -EACCES libbpf: prog 'sdt_init_task': -- BEGIN PROG LOAD LOG -- ... ; desc =3D desc_find_empty(alloc->root, &idx); @ scx_sdt.bpf.c:479 43: (79) r8 =3D *(u64 *)(r6 +32) ; frame1: R6=3Dmap_value(map=3Dscx_= sdt.bss,ks=3D4,vs=3D200,off=3D120) R8=3Dscalar() ; for (level =3D zero; level < SDT_TASK_LEVELS && can_loop; level++) { @ sc= x_sdt.bpf.c:407 44: (e5) may_goto pc+51 ; idx |=3D pos; @ scx_sdt.bpf.c:418 96: (bf) r7 =3D r2 ; frame1: R2=3D0 R7=3D0 97: (bf) r1 =3D r10 ; frame1: R1=3Dfp0 R10=3Dfp0 ; @ scx_sdt.bpf.c:0 98: (07) r1 +=3D -56 ; frame1: R1=3Dfp-56 ; bpf_for(u, 0, SDT_TASK_LEVELS) { @ scx_sdt.bpf.c:447 99: (b4) w2 =3D 0 ; frame1: R2=3D0 100: (b4) w3 =3D 3 ; frame1: R3=3D3 101: (85) call bpf_iter_num_new#82234 ; frame1: R0=3Dscalar() fp-56= =3Diter_num(ref_id=3D2,state=3Dactive,depth=3D0) 102: (18) r9 =3D 0x1ffffffffffffff8 ; frame1: R9=3D0x1ffffffffffffff8 104: (bf) r1 =3D r10 ; frame1: R1=3Dfp0 R10=3Dfp0 ; @ scx_sdt.bpf.c:0 105: (07) r1 +=3D -56 ; frame1: R1=3Dfp-56 ; bpf_for(u, 0, SDT_TASK_LEVELS) { @ scx_sdt.bpf.c:447 106: (85) call bpf_iter_num_next#82235 ; frame1: R0=3D0 fp-56=3Diter= _num(ref_id=3D2,state=3Ddrained,depth=3D0) 107: (15) if r0 =3D=3D 0x0 goto pc+29 ; frame1: R0=3D0 ; if (tmp->nr_free > 0) @ scx_sdt.bpf.c:456 137: (bf) r1 =3D r10 ; frame1: R1=3Dfp0 R10=3Dfp0 ; bpf_for(u, 0, SDT_TASK_LEVELS) { @ scx_sdt.bpf.c:447 138: (07) r1 +=3D -56 ; frame1: R1=3Dfp-56 139: (85) call bpf_iter_num_destroy#82232 ; frame1: 140: (b7) r9 =3D 0 ; frame1: R9=3D0 ; if (unlikely(desc =3D=3D NULL)) { @ scx_sdt.bpf.c:480 141: (15) if r8 =3D=3D 0x0 goto pc+15 ; frame1: R8=3Dscalar(umin=3D1) ; chunk =3D desc->chunk; @ scx_sdt.bpf.c:485 142: (79) r4 =3D *(u64 *)(r8 +72) R8 invalid mem access 'scalar' The reason is these older compilers lacks native support for __BPF_FEATURE_ADDR_SPACE_CAST, __arena macro is defined as empty. Fix it by adding cast_kern when dereferencing variables with __arena tag. Signed-off-by: Zhao Mengmeng --- tools/sched_ext/scx_sdt.bpf.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/sched_ext/scx_sdt.bpf.c b/tools/sched_ext/scx_sdt.bpf.c index 31b09958e8d5..caacc55bd7a5 100644 --- a/tools/sched_ext/scx_sdt.bpf.c +++ b/tools/sched_ext/scx_sdt.bpf.c @@ -148,6 +148,7 @@ static sdt_desc_t *scx_alloc_chunk(void) =20 out =3D desc; =20 + cast_kern(desc); desc->nr_free =3D SDT_TASK_ENTS_PER_CHUNK; desc->chunk =3D chunk; =20 @@ -244,6 +245,7 @@ int mark_nodes_avail(sdt_desc_t *lv_desc[SDT_TASK_LEVEL= S], __u64 lv_pos[SDT_TASK /* Only propagate upwards if we are the parent's only free chunk. */ desc =3D lv_desc[level]; =20 + cast_kern(desc); ret =3D set_idx_state(desc, lv_pos[level], false); if (unlikely(ret !=3D 0)) return ret; @@ -298,20 +300,26 @@ int scx_alloc_free_idx(struct scx_allocator *alloc, _= _u64 idx) if (level =3D=3D SDT_TASK_LEVELS - 1) break; =20 + cast_kern(desc); chunk =3D desc->chunk; =20 + cast_kern(chunk); desc_children =3D (sdt_desc_t * __arena *)chunk->descs; + cast_kern(desc_children); desc =3D desc_children[pos]; =20 if (unlikely(!desc)) return -EINVAL; } =20 + cast_kern(desc); chunk =3D desc->chunk; =20 pos =3D idx & mask; + cast_kern(chunk); data =3D chunk->data[pos]; if (likely(data)) { + cast_kern(data); *data =3D (struct sdt_data) { .tid.genn =3D data->tid.genn + 1, }; @@ -378,6 +386,7 @@ __u64 chunk_find_empty(sdt_desc_t __arg_arena *desc) __u64 freeslots; __u64 i; =20 + cast_kern(desc); for (i =3D 0; i < SDT_TASK_CHUNK_BITMAP_U64S; i++) { freeslots =3D ~desc->allocated[i]; if (freeslots =3D=3D (__u64)0) @@ -426,9 +435,12 @@ static sdt_desc_t * desc_find_empty(sdt_desc_t *desc, = __u64 *idxp) break; =20 /* Allocate an internal node if necessary. */ + cast_kern(desc); chunk =3D desc->chunk; + cast_kern(chunk); desc_children =3D (sdt_desc_t * __arena *)chunk->descs; =20 + cast_kern(desc_children); desc =3D desc_children[pos]; if (!desc) { desc =3D scx_alloc_chunk(); @@ -448,6 +460,7 @@ static sdt_desc_t * desc_find_empty(sdt_desc_t *desc, _= _u64 *idxp) level =3D SDT_TASK_LEVELS - 1 - u; tmp =3D lv_desc[level]; =20 + cast_kern(tmp); ret =3D set_idx_state(tmp, lv_pos[level], true); if (ret !=3D 0) break; @@ -482,10 +495,12 @@ void __arena *scx_alloc(struct scx_allocator *alloc) return NULL; } =20 + cast_kern(desc); chunk =3D desc->chunk; =20 /* Populate the leaf node if necessary. */ pos =3D idx & (SDT_TASK_ENTS_PER_CHUNK - 1); + cast_kern(chunk); data =3D chunk->data[pos]; if (!data) { data =3D scx_alloc_from_pool(&alloc->pool); @@ -503,10 +518,12 @@ void __arena *scx_alloc(struct scx_allocator *alloc) alloc_stats.alloc_ops +=3D 1; alloc_stats.active_allocs +=3D 1; =20 + cast_kern(data); data->tid.idx =3D idx; =20 bpf_spin_unlock(&alloc_lock); =20 + cast_user(data); return data; } =20 @@ -544,9 +561,10 @@ void __arena *scx_task_alloc(struct task_struct *p) if (unlikely(!data)) return NULL; =20 + mval->data =3D data; + cast_kern(data); mval->tid =3D data->tid; mval->tptr =3D (__u64) p; - mval->data =3D data; =20 return (void __arena *)data->payload; } --=20 2.43.0