From: Emil Tsalapatis <emil@etsalapatis.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com,
memxor@gmail.com, daniel@iogearbox.net,
Emil Tsalapatis <emil@etsalapatis.com>
Subject: [PATCH bpf-next v1 3/4] bpf: Add sleepable local storage
Date: Tue, 24 Nov 2026 06:03:56 +0000 [thread overview]
Message-ID: <20261124060357.11700-4-emil@etsalapatis.com> (raw)
In-Reply-To: <20261124060357.11700-1-emil@etsalapatis.com>
Sleepable BPF programs still create local storage with kmalloc_maylock.
Use the program aux metadata from the expanded helper to allocate
storage with a sleepable call when available.
Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
---
include/linux/bpf.h | 5 +++++
kernel/bpf/bpf_local_storage.c | 6 +++++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 5565a735ae7ce..52eee026d0685 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2094,6 +2094,11 @@ static inline bool bpf_prog_runs_sleepable(const struct bpf_prog *prog)
return prog->sleepable || prog->aux->sleepable_async_cb;
}
+static inline bool bpf_prog_can_sleep(const struct bpf_prog *prog)
+{
+ return prog->sleepable && preemptible() && !rcu_preempt_depth();
+}
+
struct bpf_array_aux {
/* Programs with direct jumps into programs part of this array. */
struct list_head poke_progs;
diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
index 28eaee5c66ce8..74dfebf180970 100644
--- a/kernel/bpf/bpf_local_storage.c
+++ b/kernel/bpf/bpf_local_storage.c
@@ -69,6 +69,10 @@ static bool selem_linked_to_map(const struct bpf_local_storage_elem *selem)
static void *bpf_local_storage_alloc_mem(struct bpf_local_storage_map *smap,
size_t size, bool sleepable)
{
+ if (sleepable)
+ return bpf_map_kzalloc(&smap->map, size,
+ GFP_KERNEL | __GFP_RETRY_MAYFAIL);
+
return bpf_map_kmalloc_maylock(&smap->map, size, __GFP_ZERO);
}
@@ -598,7 +602,7 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap,
{
struct bpf_local_storage_data *old_sdata = NULL;
struct bpf_local_storage_elem *alloc_selem, *selem = NULL;
- bool sleepable = false;
+ bool sleepable = aux && bpf_prog_can_sleep(aux->prog);
struct bpf_local_storage *local_storage;
struct bpf_local_storage_map_bucket *b;
HLIST_HEAD(old_selem_free_list);
--
2.52.1
next prev parent reply other threads:[~2026-11-24 6:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 6:03 [PATCH bpf-next v1 0/4] bpf: Use kmalloc for local storage if possible Emil Tsalapatis
2026-11-24 6:03 ` [PATCH bpf-next v1 1/4] bpf: Add call for selecting kmalloc or kmalloc_nolock at call time Emil Tsalapatis
2026-11-24 6:21 ` sashiko-bot
2026-11-24 6:03 ` [PATCH bpf-next v1 2/4] bpf: Plumb local storage context Emil Tsalapatis
2026-11-24 6:17 ` sashiko-bot
2026-11-24 6:03 ` Emil Tsalapatis [this message]
2026-11-24 6:03 ` [PATCH bpf-next v1 4/4] selftests/bpf: Test kmalloc variant selection for task storage Emil Tsalapatis
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=20261124060357.11700-4-emil@etsalapatis.com \
--to=emil@etsalapatis.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=memxor@gmail.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