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 v2] tools/sched_ext: use btf_vlen() helper in compat.h
Date: Tue, 30 Jun 2026 10:27:15 +0200 [thread overview]
Message-ID: <akN947xV8nxj6g_x@gpd4> (raw)
In-Reply-To: <20260630081720.3081733-1-luoliang@kylinos.cn>
On Tue, Jun 30, 2026 at 04:17:20PM +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. libbpf
> exposes btf_vlen() for exactly this purpose; use it in the three
> call sites, matching the pattern in kernel/bpf/inode.c and
> tools/bpf/bpftool.
>
> btf_vlen() returns __u32 (since commit cacd6729c0923, "libbpf:
> Adjust btf_vlen() to return a __u32", which expanded the BTF vlen
> field from 16 to 24 bits). Declare the loop counters as __u32 to
> match the return type, keeping the comparison as a plain
> '__u32 < __u32' and silencing the -Wsign-compare warnings.
>
> No functional change.
>
> Suggested-by: Andrea Righi <arighi@nvidia.com>
> Signed-off-by: Liang Luo <luoliang@kylinos.cn>
Looks good.
Reviewed-by: Andrea Righi <arighi@nvidia.com>
Thanks!
-Andrea
>
> ---
>
> Changes in v2:
> - Correct the commit message: btf_vlen() returns __u32 (not __u16)
> on mainline since cacd6729c0923. The v1 description was accurate
> only on a v7.1 baseline. (Thanks to Sashiko AI review and Andrea
> Righi for catching this.)
> - Declare the loop counters as __u32 to match btf_vlen()'s return
> type, as suggested by Andrea Righi. This properly silences
> -Wsign-compare on mainline.
> ---
> tools/sched_ext/include/scx/compat.h | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/tools/sched_ext/include/scx/compat.h b/tools/sched_ext/include/scx/compat.h
> index 602f07061ee3..23d9ef3e4c9d 100644
> --- a/tools/sched_ext/include/scx/compat.h
> +++ b/tools/sched_ext/include/scx/compat.h
> @@ -28,7 +28,7 @@ static inline bool __COMPAT_read_enum(const char *type, const char *name, u64 *v
> const struct btf_type *t;
> const char *n;
> s32 tid;
> - int i;
> + __u32 i;
>
> __COMPAT_load_vmlinux_btf();
>
> @@ -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)) {
> @@ -85,7 +85,7 @@ static inline bool __COMPAT_struct_has_field(const char *type, const char *field
> const struct btf_member *m;
> const char *n;
> s32 tid;
> - int i;
> + __u32 i;
>
> __COMPAT_load_vmlinux_btf();
> tid = btf__find_by_name_kind(__COMPAT_vmlinux_btf, type, BTF_KIND_STRUCT);
> @@ -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 8:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 3:12 [PATCH] " luoliang
2026-06-30 5:13 ` Andrea Righi
2026-06-30 8:15 ` luoliang
2026-06-30 8:17 ` [PATCH v2] " luoliang
2026-06-30 8:27 ` Andrea Righi [this message]
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=akN947xV8nxj6g_x@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
all inboxes | Powered by JetHome®