[PATCH bpf-next 05/16] libbpf: Add the arena percpu chunk attribute to map creation options

From: Xu Kuohai

Date: Tue Oct 20 2026 - 10:17:24 EST


From: Xu Kuohai <xukuohai@xxxxxxxxxx>

Add the percpu chunk offset and size information to the map creation
attribute, and set the values when creating an arena map.

Signed-off-by: Xu Kuohai <xukuohai@xxxxxxxxxx>
---
tools/include/uapi/linux/bpf.h | 4 ++++
tools/lib/bpf/bpf.c | 4 +++-
tools/lib/bpf/bpf.h | 4 ++++
tools/lib/bpf/libbpf.c | 6 ++++++
4 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 6f70db7515dd..246f52361372 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1615,6 +1615,10 @@ union bpf_attr {
__aligned_u64 excl_prog_hash;
/* Size of the passed 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 { /* anonymous struct used by BPF_MAP_*_ELEM and BPF_MAP_FREEZE commands */
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index b49822d212ae..3d5fd7e23898 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -210,7 +210,7 @@ int bpf_map_create(enum bpf_map_type map_type,
__u32 max_entries,
const struct bpf_map_create_opts *opts)
{
- const size_t attr_sz = offsetofend(union bpf_attr, excl_prog_hash_size);
+ const size_t attr_sz = offsetofend(union bpf_attr, arena_percpu_chunk_sz);
const size_t attr_common_sz = sizeof(struct bpf_common_attr);
struct bpf_common_attr attr_common;
struct bpf_log_opts *log_opts;
@@ -246,6 +246,8 @@ int bpf_map_create(enum bpf_map_type map_type,
attr.map_token_fd = OPTS_GET(opts, token_fd, 0);
attr.excl_prog_hash = ptr_to_u64(OPTS_GET(opts, excl_prog_hash, NULL));
attr.excl_prog_hash_size = OPTS_GET(opts, excl_prog_hash_size, 0);
+ 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))
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 826d9cc9ab65..15a544488eb5 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;
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 3d18ba483f6e..0b0c9d72b353 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -5816,6 +5816,12 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b
create_attr.map_flags = def->map_flags;
create_attr.numa_node = map->numa_node;
create_attr.map_extra = map->map_extra;
+
+ if (obj->arena_percpu.present && map == &obj->maps[obj->arena_map_idx]) {
+ create_attr.arena_percpu_chunk_off = obj->arena_percpu.offset;
+ create_attr.arena_percpu_chunk_sz = obj->arena_percpu.chunk_sz;
+ }
+
create_attr.token_fd = obj->token_fd;
if (obj->token_fd)
create_attr.map_flags |= BPF_F_TOKEN_FD;
--
2.47.3