BPF List
 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 05/16] libbpf: Add the arena percpu chunk attribute to map creation options
Date: Tue, 20 Oct 2026 14:04:23 +0000	[thread overview]
Message-ID: <sashiko-outbox-179079@kernel.org> (raw)
In-Reply-To: <e596c9878df94ac93c172d93106c8ebd2dac4bb7.1792503001.git.xukuohai@huawei.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] libbpf: ABI break in struct bpf_map_create_opts from field insertion
--

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

libbpf: Add the arena percpu chunk attribute to map creation options

This commit adds arena_percpu_chunk_off and arena_percpu_chunk_sz to
union bpf_attr and struct bpf_map_create_opts, and populates them when
creating an arena map.

> diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
> index 826d9cc9ab65d..15a544488eb59 100644
> --- a/tools/lib/bpf/bpf.h
> +++ b/tools/lib/bpf/bpf.h
> @@ -70,6 +70,10 @@ struct bpf_map_create_opts {
>  	const void *excl_prog_hash;
>  	__u32 excl_prog_hash_size;
>  
> +	/* offset and size of an arena percpu chunk */
> +	__u32 arena_percpu_chunk_off;
> +	__u32 arena_percpu_chunk_sz;
> +
>  	struct bpf_log_opts *log_opts;
>  
>  	size_t :0;

[Severity: High]
Does inserting arena_percpu_chunk_off and arena_percpu_chunk_sz before
log_opts break binary compatibility for struct bpf_map_create_opts?

struct bpf_map_create_opts is a size-versioned LIBBPF_OPTS structure
validated and accessed through OPTS_VALID() and OPTS_GET() in
bpf_map_create():

tools/lib/bpf/bpf.c:bpf_map_create() {
	...
	if (!OPTS_VALID(opts, bpf_map_create_opts))
		return libbpf_err(-EINVAL);
	...
	attr.arena_percpu_chunk_off = OPTS_GET(opts, arena_percpu_chunk_off, 0);
	attr.arena_percpu_chunk_sz = OPTS_GET(opts, arena_percpu_chunk_sz, 0);

	log_opts = OPTS_GET(opts, log_opts, NULL);
	if (!OPTS_VALID(log_opts, bpf_log_opts))
		return libbpf_err(-EINVAL);
}

Prior to this change, log_opts was the last field in struct
bpf_map_create_opts (at byte offset 72 on 64-bit platforms, with
sizeof(struct bpf_map_create_opts) == 80) and
bpf_map_create_opts__last_field was defined as log_opts:

tools/lib/bpf/bpf.h:
	struct bpf_log_opts *log_opts;

	size_t :0;
};
#define bpf_map_create_opts__last_field log_opts

Placing arena_percpu_chunk_off (offset 68) and arena_percpu_chunk_sz
(offset 72) ahead of log_opts shifts log_opts to offset 80 (with
sizeof(struct bpf_map_create_opts) == 88).

If an existing binary compiled against the previous struct
bpf_map_create_opts layout (opts->sz == 80, log_opts at offset 72) calls
the updated bpf_map_create(), OPTS_GET(opts, arena_percpu_chunk_sz, 0)
will read the lower 32 bits of the caller's log_opts pointer into
attr.arena_percpu_chunk_sz, while OPTS_GET(opts, log_opts, NULL) will see
opts->sz < offsetofend(struct bpf_map_create_opts, log_opts) and silently
drop log_opts.

Conversely, if a binary compiled against the new header sets
arena_percpu_chunk_sz and runs against an older libbpf.so, the older
bpf_map_create() will read the 32-bit arena_percpu_chunk_sz value at
offset 72 as a non-NULL struct bpf_log_opts *log_opts pointer and
dereference it in OPTS_VALID(log_opts, bpf_log_opts).

Should arena_percpu_chunk_off and arena_percpu_chunk_sz be appended after
log_opts, with bpf_map_create_opts__last_field updated to
arena_percpu_chunk_sz?

[ ... ]

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

  reply	other threads:[~2026-10-20 14:04 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 [this message]
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
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-179079@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox