From: Andrea Righi <arighi@nvidia.com>
To: luoliang@kylinos.cn
Cc: Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>,
Changwoo Min <changwoo@igalia.com>,
sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org
Subject: Re: [PATCH] tools/sched_ext: use btf_vlen() helper in compat.h
Date: Tue, 30 Jun 2026 07:13:51 +0200 [thread overview]
Message-ID: <akNQjzejJOdtDYnQ@gpd4> (raw)
In-Reply-To: <20260630031246.2618216-1-luoliang@kylinos.cn>
Hi,
On Tue, Jun 30, 2026 at 11:12:46AM +0800, luoliang@kylinos.cn wrote:
> From: luoliang <luoliang@kylinos.cn>
>
> __COMPAT_read_enum() and __COMPAT_struct_has_field() open-code the
> vlen lookup via the raw BTF_INFO_VLEN(t->info) UAPI macro, whose
> result type is __u32 (t->info is __u32 and 0xffff is promoted to
> unsigned). Comparing it against the int loop counter triggers
> -Wsign-compare in every example scheduler that includes compat.h.
>
> libbpf already exposes btf_vlen() for exactly this purpose; it
> returns __u16, the natural width of the vlen field, and the usual
> integer promotions turn the 'int < __u16' comparison into a plain
> 'int < int' so the warning goes away without any cast. This matches
> the pattern already used in-kernel (e.g. kernel/bpf/inode.c) and in
> tools/bpf/bpftool. Replace the three open-coded lookups with
> btf_vlen(t). No functional change.
btf_vlen() currently returns __u32, not __u16. This changed in commit
cacd6729c092 ("libbpf: Adjust btf_vlen() to return a __u32"), because BTF vlen
was expanded to 24 bits. We should update the description to match this. And i
should be changed to __u32 for consistency.
With these changes:
Reviewed-by: Andrea Righi <arighi@nvidia.com>
Thanks,
-Andrea
>
> Signed-off-by: Liang Luo <luoliang@kylinos.cn>
> ---
> tools/sched_ext/include/scx/compat.h | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/sched_ext/include/scx/compat.h b/tools/sched_ext/include/scx/compat.h
> index 039854c490d5..df5ca1ce20f6 100644
> --- a/tools/sched_ext/include/scx/compat.h
> +++ b/tools/sched_ext/include/scx/compat.h
> @@ -42,7 +42,7 @@ static inline bool __COMPAT_read_enum(const char *type, const char *name, u64 *v
> if (btf_is_enum(t)) {
> struct btf_enum *e = btf_enum(t);
>
> - for (i = 0; i < BTF_INFO_VLEN(t->info); i++) {
> + for (i = 0; i < btf_vlen(t); i++) {
> n = btf__name_by_offset(__COMPAT_vmlinux_btf, e[i].name_off);
> SCX_BUG_ON(!n, "btf__name_by_offset()");
> if (!strcmp(n, name)) {
> @@ -53,7 +53,7 @@ static inline bool __COMPAT_read_enum(const char *type, const char *name, u64 *v
> } else if (btf_is_enum64(t)) {
> struct btf_enum64 *e = btf_enum64(t);
>
> - for (i = 0; i < BTF_INFO_VLEN(t->info); i++) {
> + for (i = 0; i < btf_vlen(t); i++) {
> n = btf__name_by_offset(__COMPAT_vmlinux_btf, e[i].name_off);
> SCX_BUG_ON(!n, "btf__name_by_offset()");
> if (!strcmp(n, name)) {
> @@ -97,7 +97,7 @@ static inline bool __COMPAT_struct_has_field(const char *type, const char *field
>
> m = btf_members(t);
>
> - for (i = 0; i < BTF_INFO_VLEN(t->info); i++) {
> + for (i = 0; i < btf_vlen(t); i++) {
> n = btf__name_by_offset(__COMPAT_vmlinux_btf, m[i].name_off);
> SCX_BUG_ON(!n, "btf__name_by_offset()");
> if (!strcmp(n, field))
> --
> 2.43.0
>
next prev parent reply other threads:[~2026-06-30 5:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 3:12 [PATCH] tools/sched_ext: use btf_vlen() helper in compat.h luoliang
2026-06-30 5:13 ` Andrea Righi [this message]
2026-06-30 8:15 ` luoliang
2026-06-30 8:17 ` [PATCH v2] " luoliang
2026-06-30 8:27 ` Andrea Righi
2026-06-30 14:24 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=akNQjzejJOdtDYnQ@gpd4 \
--to=arighi@nvidia.com \
--cc=bpf@vger.kernel.org \
--cc=changwoo@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luoliang@kylinos.cn \
--cc=sched-ext@lists.linux.dev \
--cc=tj@kernel.org \
--cc=void@manifault.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox