All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xu Kuohai" <xukuohai@huaweicloud.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 13/16] bpftool: Emit the arena percpu datasec into skeleton
Date: Tue, 20 Oct 2026 14:01:41 +0000	[thread overview]
Message-ID: <sashiko-outbox-179076@kernel.org> (raw)
In-Reply-To: <a579251a284c3dd4954c305a04346acef4ec4113.1792503001.git.xukuohai@huawei.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] bpftool: NULL pointer dereference in do_skeleton() when BTF is absent
- [Low] bpftool: missing pointer cast in do_skeleton() breaks C++ skeleton build
--

commit 104a6169dc8cb31cbaeca548b8c48657b09d1a96
Author: Xu Kuohai <xukuohai@huawei.com>

bpftool: Emit the arena percpu datasec into skeleton

This commit updates bpftool skeleton generation to emit a separate
arena_percpu data section struct when .arena.percpu variables are present
and initializes obj->arena_percpu to cpu 0's per-cpu arena base in the
generated load function.

> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> index ee680f7c21160..8a321ec1155a1 100644
> --- a/tools/bpf/bpftool/gen.c
> +++ b/tools/bpf/bpftool/gen.c

[ ... ]

> @@ -1511,11 +1523,58 @@ static int do_skeleton(int argc, char **argv)
>  			return %1$s__open_opts(NULL);			    \n\
>  		}							    \n\
>  									    \n\
> -		static inline int					    \n\
> -		%1$s__load(struct %1$s *obj)				    \n\
> -		{							    \n\
> -			return bpf_object__load_skeleton(obj->skeleton);    \n\
> -		}							    \n\
> +		",
> +		obj_name
> +	);
> +
> +	/* The per-cpu arena data has no mmaped slot in the map skeleton.
> +	 * Point obj->arena_percpu at cpu 0's chunk once the object is
> +	 * loaded.
> +	 */
> +	{
> +		char arena_map_ident[256] = "";
> +		bool have_percpu_arena = false;
> +
> +		bpf_object__for_each_map(map, obj) {
> +			if (bpf_map__type(map) != BPF_MAP_TYPE_ARENA)
> +				continue;
> +			if (find_type_for_map(bpf_object__btf(obj), "arena_percpu") &&
> +			    get_map_ident(map, arena_map_ident, sizeof(arena_map_ident))) {

[Severity: Medium]
Can this dereference a NULL btf pointer when generating a skeleton for an
object with an arena map but no BTF information?

Earlier in do_skeleton(), codegen_datasecs() is guarded by checking if btf
is non-NULL:

    if (btf) {
        err = codegen_datasecs(obj, obj_name);
        if (err)
            goto out;
    }

Here, bpf_object__btf(obj) is passed directly to find_type_for_map()
without checking if btf is NULL:

    do_skeleton()
      find_type_for_map(bpf_object__btf(obj), "arena_percpu")
        btf__type_cnt(btf)
          return btf->start_id + btf->nr_types;

Should this check that btf is non-NULL before calling find_type_for_map()?

> +				have_percpu_arena = true;
> +				break;
> +			}
> +		}
> +
> +		if (have_percpu_arena) {
> +			codegen("\
> +				\n\
> +				static inline int \n\
> +				%1$s__load(struct %1$s *obj) \n\
> +				{ \n\
> +					int err; \n\
> +					 \n\
> +					err = bpf_object__load_skeleton(obj->skeleton); \n\
> +					if (err) \n\
> +						return err; \n\
> +					obj->arena_percpu = \n\
> +						bpf_map__arena_percpu_base(obj->maps.%2$s); \n\

[Severity: Low]
Will this assignment fail to compile when the generated skeleton header is
included in C++ code?

bpf_map__arena_percpu_base() returns void *, while obj->arena_percpu is a
typed struct pointer (struct <obj_name>__arena_percpu *). In C++, implicit
conversion from void * to a typed pointer is not permitted.

Elsewhere in tools/bpf/bpftool/gen.c, such as in gen_st_ops_shadow_init(),
void * returns are cast using __typeof__:

    obj->struct_ops.%1$s = (__typeof__(obj->struct_ops.%1$s))
        bpf_map__initial_value(obj->maps.%1$s, NULL);

Should obj->arena_percpu also use a (__typeof__(obj->arena_percpu)) cast
here?

> +					return 0; \n\
> +				} \n\
> +				", obj_name, arena_map_ident);

[ ... ]

>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1792503001.git.xukuohai@huawei.com?part=13

  reply	other threads:[~2026-10-20 14:01 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 13:22 [PATCH bpf-next 00/16] Add percpu variable support for bpf arena Xu Kuohai
2026-10-20 13:22 ` [PATCH bpf-next 01/16] libbpf: Collect arena percpu data section Xu Kuohai
2026-10-20 14:17   ` bot+bpf-ci
2026-10-20 13:22 ` [PATCH bpf-next 02/16] libbpf: Create arena percpu chunk from the arena percpu ELF section Xu Kuohai
2026-10-20 14:17   ` bot+bpf-ci
2026-10-20 13:22 ` [PATCH bpf-next 03/16] libbpf: Place the percpu chunks in the bpf arena Xu Kuohai
2026-10-20 13:22 ` [PATCH bpf-next 04/16] libbpf: Copy the percpu chunks into " Xu Kuohai
2026-10-20 14:17   ` bot+bpf-ci
2026-10-20 13:22 ` [PATCH bpf-next 05/16] libbpf: Add the arena percpu chunk attribute to map creation options Xu Kuohai
2026-10-20 14:04   ` sashiko-bot
2026-10-20 14:17   ` bot+bpf-ci
2026-10-20 13:22 ` [PATCH bpf-next 06/16] libbpf: Relocate arena percpu access instructions Xu Kuohai
2026-10-20 14:29   ` bot+bpf-ci
2026-10-20 13:22 ` [PATCH bpf-next 07/16] libbpf: Add arena percpu feature probe Xu Kuohai
2026-10-20 14:17   ` bot+bpf-ci
2026-10-20 13:22 ` [PATCH bpf-next 08/16] bpf: Extend syscall to accept arena percpu information Xu Kuohai
2026-10-20 14:17   ` bot+bpf-ci
2026-10-20 13:22 ` [PATCH bpf-next 09/16] bpf: Teach verifier about arena percpu instructions Xu Kuohai
2026-10-20 14:16   ` sashiko-bot
2026-10-20 14:29   ` bot+bpf-ci
2026-10-20 13:22 ` [PATCH bpf-next 10/16] bpf, x86: Add support for arena percpu Xu Kuohai
2026-10-20 14:12   ` sashiko-bot
2026-10-20 13:22 ` [PATCH bpf-next 11/16] bpf, arm64: " Xu Kuohai
2026-10-20 14:17   ` bot+bpf-ci
2026-10-20 14:31   ` sashiko-bot
2026-10-20 13:22 ` [PATCH bpf-next 12/16] libbpf: Introduce arena percpu helpers for user space Xu Kuohai
2026-10-20 14:00   ` sashiko-bot
2026-10-20 14:17   ` bot+bpf-ci
2026-10-20 13:22 ` [PATCH bpf-next 13/16] bpftool: Emit the arena percpu datasec into skeleton Xu Kuohai
2026-10-20 14:01   ` sashiko-bot [this message]
2026-10-20 13:22 ` [PATCH bpf-next 14/16] selftests/bpf: Add test for arena percpu-only object Xu Kuohai
2026-10-20 14:12   ` sashiko-bot
2026-10-20 14:17   ` bot+bpf-ci
2026-10-20 13:23 ` [PATCH bpf-next 15/16] selftests/bpf: Add test for mixed arena percpu object Xu Kuohai
2026-10-20 13:57   ` sashiko-bot
2026-10-20 13:23 ` [PATCH bpf-next 16/16] selftests/bpf: Add test for arena percpu bounds Xu Kuohai
2026-10-20 14:17   ` bot+bpf-ci
2026-10-20 14:47 ` [PATCH bpf-next 00/16] Add percpu variable support for bpf arena Alexei Starovoitov

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-179076@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xukuohai@huaweicloud.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.