bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Leon Hwang" <leon.hwang@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v11 05/10] libbpf: Add support for global percpu data
Date: Thu, 06 Aug 2026 16:57:54 +0000	[thread overview]
Message-ID: <20260806165754.B77971F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806163125.11172-6-leon.hwang@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Dead code in percpu global data feature check
--

--- Patch [5]: [PATCH bpf-next v11 05/10] libbpf: Add support for global percpu data ---
commit ee97f8a8e25b5e9337024df3dd6f3a1aae4f6cdc
Author: Leon Hwang <leon.hwang@linux.dev>

libbpf: Add support for global percpu data

This commit adds support for global percpu data in libbpf by introducing a 
new ".percpu" section. It updates the lightweight skeleton loader to use 
BPF_F_ALL_CPUS when updating the percpu_array map and marks the mmaped data 
as read-only after population.

> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 514e4e9daa825..9f79a8e850fdb 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c

[ ... ]

> @@ -5293,18 +5326,26 @@ static int
>  bpf_object__populate_internal_map(struct bpf_object *obj, struct bpf_map *map)
>  {
>  	enum libbpf_map_type map_type = map->libbpf_type;
> +	bool is_percpu = map_type == LIBBPF_MAP_PERCPU;
> +	const __u64 update_flags = is_percpu ? BPF_F_ALL_CPUS : 0;
>  	int err, zero = 0;
>  	size_t mmap_sz;
>  
> +	if (is_percpu && !obj->gen_loader && !kernel_supports(obj, FEAT_PERCPU_DATA)) {
> +		pr_warn("map '%s': kernel does not support percpu data.\n",
> +			bpf_map__name(map));
> +		return -EOPNOTSUPP;
> +	}
> +

[Severity: Low]
Is this check reachable? 

Looking at bpf_object__create_maps(), if the kernel does not support
FEAT_PERCPU_DATA, map->autocreate is set to false and the map processing
loop continues early:

bpf_object__create_maps() {
    ...
    if (bpf_map__is_internal(map) && bpf_map__type(map) == BPF_MAP_TYPE_PERCPU_ARRAY &&
        !kernel_supports(obj, FEAT_PERCPU_DATA))
        map->autocreate = false;

    if (!map->autocreate) {
        pr_debug("map '%s': skipped auto-creating...\n", map->name);
        continue;
    }
    ...
}

Since bpf_object__populate_internal_map() is called later in this same
loop (after the continue), wouldn't the !kernel_supports() condition
already be filtered out, making this warning dead code?

>  	if (obj->gen_loader) {
>  		bpf_gen__map_update_elem(obj->gen_loader, map - obj->maps,
> -					 map->mmaped, map->def.value_size);
> +					 map->mmaped, map->def.value_size, update_flags);
>  		if (map_type == LIBBPF_MAP_RODATA || map_type == LIBBPF_MAP_KCONFIG)
>  			bpf_gen__map_freeze(obj->gen_loader, map - obj->maps);
>  		return 0;
>  	}
>  
> -	err = bpf_map_update_elem(map->fd, &zero, map->mmaped, 0);
> +	err = bpf_map_update_elem(map->fd, &zero, map->mmaped, update_flags);
>  	if (err) {
>  		err = -errno;
>  		pr_warn("map '%s': failed to set initial contents: %s\n",

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260806163125.11172-1-leon.hwang@linux.dev?part=5

  reply	other threads:[~2026-08-06 16:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 16:31 [PATCH bpf-next v11 00/10] bpf: Introduce global percpu data Leon Hwang
2026-08-06 16:31 ` [PATCH bpf-next v11 01/10] bpf: Drop duplicate blank lines in kernel/bpf/ Leon Hwang
2026-08-06 16:31 ` [PATCH bpf-next v11 02/10] bpf: Factor out check_map_mem_read helper in verifier Leon Hwang
2026-08-06 16:31 ` [PATCH bpf-next v11 03/10] bpf: Introduce global percpu data Leon Hwang
2026-08-06 16:31 ` [PATCH bpf-next v11 04/10] libbpf: Probe percpu data feature Leon Hwang
2026-08-06 17:05   ` sashiko-bot
2026-08-07  2:26     ` Leon Hwang
2026-08-06 16:31 ` [PATCH bpf-next v11 05/10] libbpf: Add support for global percpu data Leon Hwang
2026-08-06 16:57   ` sashiko-bot [this message]
2026-08-07  2:36     ` Leon Hwang
2026-08-06 16:31 ` [PATCH bpf-next v11 06/10] bpftool: Generate skeleton " Leon Hwang
2026-08-06 16:31 ` [PATCH bpf-next v11 07/10] selftests/bpf: Add tests to verify " Leon Hwang
2026-08-06 16:31 ` [PATCH bpf-next v11 08/10] selftests/bpf: Test direct reading/writing read-only percpu_array map Leon Hwang
2026-08-06 16:31 ` [PATCH bpf-next v11 09/10] selftests/bpf: Test verifier log for global percpu data Leon Hwang
2026-08-06 16:31 ` [PATCH bpf-next v11 10/10] selftests/bpf: Verify bpf_iter " Leon Hwang

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=20260806165754.B77971F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=leon.hwang@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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;
as well as URLs for NNTP newsgroup(s).