From: sashiko-bot@kernel.org
To: "Siddharth Nayyar" <sidnayyar@google.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH RFC bpf-next 3/7] libbpf: Support BPF_MAP_TYPE_STRUCT_OPS in bpf_gen__map_create()
Date: Fri, 06 Nov 2026 20:33:02 +0000 [thread overview]
Message-ID: <sashiko-outbox-202213@kernel.org> (raw)
In-Reply-To: <20261106-lskel-struct-ops-v1-3-a4486ffc79cb@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] libbpf: double byte-swap of BPF_F_VTYPE_BTF_OBJ_FD in
bpf_gen__map_create()
--
commit 504179d2d83634dc1591a224d0263ff3b4a9b9cf
Author: Siddharth Nayyar <sidnayyar@google.com>
libbpf: Support BPF_MAP_TYPE_STRUCT_OPS in bpf_gen__map_create()
This commit adds support for BPF_MAP_TYPE_STRUCT_OPS maps in
bpf_gen__map_create() when generating a BPF light skeleton, including
handling kernel module BTF object FDs.
> diff --git a/tools/lib/bpf/gen_loader.c b/tools/lib/bpf/gen_loader.c
> index 09713c39f71ec..6027a2762c352 100644
> --- a/tools/lib/bpf/gen_loader.c
> +++ b/tools/lib/bpf/gen_loader.c
[ ... ]
> @@ -543,6 +543,27 @@ void bpf_gen__map_create(struct bpf_gen *gen,
> stack_off(inner_map_fd));
> close_inner_map_fd = true;
> break;
> + case BPF_MAP_TYPE_STRUCT_OPS:
> + move_blob2blob(gen, attr_field(map_create_attr, value_size), 4,
> + value_size);
> + emit2(gen, BPF_LD_IMM64_RAW_FULL(BPF_REG_1, BPF_PSEUDO_MAP_IDX_VALUE,
> + 0, 0, 0, map_attr->btf_vmlinux_value_type_id));
> + emit(gen, BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, 0));
> + emit2(gen, BPF_LD_IMM64_RAW_FULL(BPF_REG_1, BPF_PSEUDO_MAP_IDX_VALUE,
> + 0, 0, 0, map_create_attr));
> + emit(gen, BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0,
> + offsetof(union bpf_attr, btf_vmlinux_value_type_id)));
> + emit(gen, BPF_ALU64_IMM(BPF_RSH, BPF_REG_0, 32));
> + emit(gen, BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 4));
> + emit(gen, BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0,
> + offsetof(union bpf_attr, value_type_btf_obj_fd)));
> + emit(gen, BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
> + offsetof(union bpf_attr, map_flags)));
> + emit(gen, BPF_ALU32_IMM(BPF_OR, BPF_REG_0,
> + tgt_endian(BPF_F_VTYPE_BTF_OBJ_FD)));
> + emit(gen, BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0,
> + offsetof(union bpf_attr, map_flags)));
> + break;
[Severity: Medium]
Does wrapping BPF_F_VTYPE_BTF_OBJ_FD in tgt_endian() double-swap the
instruction immediate when generating a cross-endian light skeleton?
Unlike data blob fields, emitted BPF instructions are built in host byte
order and later byte-swapped in bpf_gen__finish() via bpf_insn_bswap()
when gen->swapped_endian is set:
tools/lib/bpf/gen_loader.c:bpf_gen__finish() {
...
if (gen->swapped_endian) {
struct bpf_insn *insn = (struct bpf_insn *)opts->insns;
int insn_cnt = opts->insns_sz / sizeof(struct bpf_insn);
for (i = 0; i < insn_cnt; i++)
bpf_insn_bswap(insn++);
}
...
}
Pre-swapping the immediate here causes bpf_insn_bswap() to swap insn->imm
back to the wrong byte order, setting 0x00800000 instead of
BPF_F_VTYPE_BTF_OBJ_FD (0x00008000) in attr.map_flags on the target and
causing BPF_MAP_CREATE for kernel module struct_ops maps to fail with
-EINVAL. Passing BPF_F_VTYPE_BTF_OBJ_FD directly without tgt_endian()
avoids the double swap.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261106-lskel-struct-ops-v1-0-a4486ffc79cb@google.com?part=3
next prev parent reply other threads:[~2026-11-06 20:33 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 20:19 [PATCH RFC bpf-next 0/7] bpf: Support struct_ops in light skeletons Siddharth Nayyar
2026-11-06 20:19 ` [PATCH RFC bpf-next 1/7] bpf: Add bpf_btf_get_struct_member_info() helper Siddharth Nayyar
2026-11-06 20:37 ` sashiko-bot
2026-11-06 20:56 ` bot+bpf-ci
2026-11-06 20:19 ` [PATCH RFC bpf-next 2/7] libbpf: Implement bpf_gen__init_kern_struct_ops() for light skeletons Siddharth Nayyar
2026-11-06 20:53 ` sashiko-bot
2026-11-06 20:56 ` bot+bpf-ci
2026-11-06 20:19 ` [PATCH RFC bpf-next 3/7] libbpf: Support BPF_MAP_TYPE_STRUCT_OPS in bpf_gen__map_create() Siddharth Nayyar
2026-11-06 20:33 ` sashiko-bot [this message]
2026-11-06 20:56 ` bot+bpf-ci
2026-11-06 20:19 ` [PATCH RFC bpf-next 4/7] libbpf: Support BPF_PROG_TYPE_STRUCT_OPS in bpf_gen__prog_load() Siddharth Nayyar
2026-11-06 20:56 ` bot+bpf-ci
2026-11-06 20:19 ` [PATCH RFC bpf-next 5/7] libbpf: Implement bpf_gen__struct_ops_update_elem() for light skeletons Siddharth Nayyar
2026-11-06 20:39 ` sashiko-bot
2026-11-06 20:56 ` bot+bpf-ci
2026-11-06 20:19 ` [PATCH RFC bpf-next 6/7] bpftool: Generate attach and detach for struct_ops in " Siddharth Nayyar
2026-11-06 20:19 ` [PATCH RFC bpf-next 7/7] selftests/bpf: Add light skeleton struct_ops tests Siddharth Nayyar
2026-11-09 19:46 ` [PATCH RFC bpf-next 0/7] bpf: Support struct_ops in light skeletons Ihor Solodrai
2026-11-09 21:39 ` Alexei Starovoitov
2026-11-10 13:08 ` Anton Protopopov
2026-11-10 13:12 ` Anton Protopopov
2026-11-11 7:35 ` Sid Nayyar
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=sashiko-outbox-202213@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sidnayyar@google.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