From: Andrea Righi <arighi@nvidia.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
Josh Don <joshdon@google.com>,
Vineeth Pillai <vineethrp@google.com>,
Balbir Singh <balbirs@nvidia.com>,
Shameer Kolothum <skolothumtho@nvidia.com>,
Himadri Chhaya-Shailesh <himadrics@protonmail.com>,
NchangRoy <royfru44@gmail.com>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/5] bpf: Add an arena flag to retain allocated pages
Date: Sun, 11 Oct 2026 00:45:56 +0200 [thread overview]
Message-ID: <20261010224902.1232178-2-arighi@nvidia.com> (raw)
In-Reply-To: <20261010224902.1232178-1-arighi@nvidia.com>
Add BPF_F_ARENA_NO_FREE to retain arena pages until the map is
destroyed.
Make BPF page-free operations no-ops in both sleepable and non-sleepable
programs when the flag is set. Programs can manage reusable objects
within the retained pages without releasing their backing memory.
This provides a page-retention policy independently of how userspace
accesses the arena. It also supplies stable backing for external
consumers that must not lose pages while they are still using them.
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
include/uapi/linux/bpf.h | 3 +++
kernel/bpf/arena.c | 9 ++++++---
tools/include/uapi/linux/bpf.h | 3 +++
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index e0ed44b1bbcb7..75101d602bd32 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1500,6 +1500,9 @@ enum {
/* Enable BPF ringbuf overwrite mode */
BPF_F_RB_OVERWRITE = (1U << 19),
+
+ /* Keep arena pages allocated until the map is destroyed. */
+ BPF_F_ARENA_NO_FREE = (1U << 20),
};
/* Flags for BPF_PROG_QUERY. */
diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
index 0ff707707da04..343e84139ec29 100644
--- a/kernel/bpf/arena.c
+++ b/kernel/bpf/arena.c
@@ -283,7 +283,8 @@ static struct bpf_map *arena_map_alloc(union bpf_attr *attr)
/* BPF_F_MMAPABLE must be set */
!(attr->map_flags & BPF_F_MMAPABLE) ||
/* No unsupported flags present */
- (attr->map_flags & ~(BPF_F_SEGV_ON_FAULT | BPF_F_MMAPABLE | BPF_F_NO_USER_CONV)))
+ (attr->map_flags & ~(BPF_F_SEGV_ON_FAULT | BPF_F_MMAPABLE |
+ BPF_F_NO_USER_CONV | BPF_F_ARENA_NO_FREE)))
return ERR_PTR(-EINVAL);
if (attr->map_extra & ~PAGE_MASK)
@@ -1134,7 +1135,8 @@ __bpf_kfunc void bpf_arena_free_pages(void *p__map, void *ptr__ign, u32 page_cnt
struct bpf_map *map = p__map;
struct bpf_arena *arena = container_of(map, struct bpf_arena, map);
- if (map->map_type != BPF_MAP_TYPE_ARENA || !page_cnt || !ptr__ign)
+ if (map->map_type != BPF_MAP_TYPE_ARENA || !page_cnt || !ptr__ign ||
+ (map->map_flags & BPF_F_ARENA_NO_FREE))
return;
arena_free_pages(arena, (long)ptr__ign, page_cnt, true);
}
@@ -1144,7 +1146,8 @@ void bpf_arena_free_pages_non_sleepable(void *p__map, void *ptr__ign, u32 page_c
struct bpf_map *map = p__map;
struct bpf_arena *arena = container_of(map, struct bpf_arena, map);
- if (map->map_type != BPF_MAP_TYPE_ARENA || !page_cnt || !ptr__ign)
+ if (map->map_type != BPF_MAP_TYPE_ARENA || !page_cnt || !ptr__ign ||
+ (map->map_flags & BPF_F_ARENA_NO_FREE))
return;
arena_free_pages(arena, (long)ptr__ign, page_cnt, false);
}
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index e0ed44b1bbcb7..75101d602bd32 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1500,6 +1500,9 @@ enum {
/* Enable BPF ringbuf overwrite mode */
BPF_F_RB_OVERWRITE = (1U << 19),
+
+ /* Keep arena pages allocated until the map is destroyed. */
+ BPF_F_ARENA_NO_FREE = (1U << 20),
};
/* Flags for BPF_PROG_QUERY. */
--
2.56.0
next prev parent reply other threads:[~2026-10-10 22:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 22:45 [PATCH bpf-next 0/5] bpf: Expose pinned arenas as sized bpffs files Andrea Righi
2026-10-10 22:45 ` Andrea Righi [this message]
2026-10-10 22:45 ` [PATCH 2/5] " Andrea Righi
2026-10-10 23:40 ` bot+bpf-ci
2026-10-10 22:45 ` [PATCH 3/5] docs/bpf: Document pinned arena file mappings Andrea Righi
2026-10-10 23:19 ` bot+bpf-ci
2026-10-10 22:45 ` [PATCH 4/5] selftests/bpf: Test " Andrea Righi
2026-10-10 23:40 ` bot+bpf-ci
2026-10-10 22:46 ` [PATCH 5/5] selftests/bpf: Test two-way arena access with two guests Andrea Righi
2026-10-10 23:40 ` bot+bpf-ci
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=20261010224902.1232178-2-arighi@nvidia.com \
--to=arighi@nvidia.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=balbirs@nvidia.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=himadrics@protonmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=joshdon@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=royfru44@gmail.com \
--cc=skolothumtho@nvidia.com \
--cc=song@kernel.org \
--cc=vineethrp@google.com \
--cc=yonghong.song@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
all inboxes | Powered by JetHome®