[PATCH bpf-next v2 1/3] bpf: reuse local storage map link and unlink helpers

From: Mahe Tardy

Date: Mon Nov 30 2026 - 15:14:38 EST


Route map-side insertions and removals through the existing _nolock
helpers. The following commit will use the bpf map elem counters helpers
from the _nolock functions to estimate the memory usage more accurately.

Signed-off-by: Mahe Tardy <mahe.tardy@xxxxxxxxx>
---
kernel/bpf/bpf_local_storage.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
index b12fcec47ffa..e470447d6218 100644
--- a/kernel/bpf/bpf_local_storage.c
+++ b/kernel/bpf/bpf_local_storage.c
@@ -240,6 +240,11 @@ void bpf_selem_link_storage_nolock(struct bpf_local_storage *local_storage,
hlist_add_head_rcu(&selem->snode, &local_storage->list);
}

+static void bpf_selem_unlink_map_nolock(struct bpf_local_storage_elem *selem)
+{
+ hlist_del_init_rcu(&selem->map_node);
+}
+
/* Must be called with the owning local_storage->lock held. */
static int bpf_selem_unlink_map(struct bpf_local_storage_elem *selem)
{
@@ -258,15 +263,16 @@ static int bpf_selem_unlink_map(struct bpf_local_storage_elem *selem)
if (err)
return err;

- hlist_del_init_rcu(&selem->map_node);
+ bpf_selem_unlink_map_nolock(selem);
raw_res_spin_unlock(&b->lock);

return 0;
}

-static void bpf_selem_unlink_map_nolock(struct bpf_local_storage_elem *selem)
+static void bpf_selem_link_map_nolock(struct bpf_local_storage_map_bucket *b,
+ struct bpf_local_storage_elem *selem)
{
- hlist_del_init_rcu(&selem->map_node);
+ hlist_add_head_rcu(&selem->map_node, &b->list);
}

int bpf_selem_link_map(struct bpf_local_storage_map *smap,
@@ -283,18 +289,12 @@ int bpf_selem_link_map(struct bpf_local_storage_map *smap,
if (err)
return err;

- hlist_add_head_rcu(&selem->map_node, &b->list);
+ bpf_selem_link_map_nolock(b, selem);
raw_res_spin_unlock_irqrestore(&b->lock, flags);

return 0;
}

-static void bpf_selem_link_map_nolock(struct bpf_local_storage_map_bucket *b,
- struct bpf_local_storage_elem *selem)
-{
- hlist_add_head_rcu(&selem->map_node, &b->list);
-}
-
/*
* Unlink an selem from map and local storage with lock held.
* This is the common path used by local storages to delete an selem.
@@ -377,7 +377,7 @@ static void bpf_selem_unlink_nofail(struct bpf_local_storage_elem *selem,
* is sleepable: see below.
*/
if (likely(selem_linked_to_map(selem))) {
- hlist_del_init_rcu(&selem->map_node);
+ bpf_selem_unlink_map_nolock(selem);
if (sleepable_users)
keep_fields = true;
else
--
2.43.0