Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bpf: Convert bpf_selem_link_map to failable

To prepare for changing bpf_local_storage_map_bucket::lock to rqspinlock,
convert bpf_selem_link_map() to failable. It still always succeeds and
returns 0 until the change happens. No functional change.

Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Amery Hung <ameryhung@gmail.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20260205222916.1788211-4-ameryhung@gmail.com

authored by

Amery Hung and committed by
Martin KaFai Lau
fd103ffc 1b7e0cae

+16 -7
+3 -3
include/linux/bpf_local_storage.h
··· 178 178 179 179 void bpf_selem_unlink(struct bpf_local_storage_elem *selem, bool reuse_now); 180 180 181 - void bpf_selem_link_map(struct bpf_local_storage_map *smap, 182 - struct bpf_local_storage *local_storage, 183 - struct bpf_local_storage_elem *selem); 181 + int bpf_selem_link_map(struct bpf_local_storage_map *smap, 182 + struct bpf_local_storage *local_storage, 183 + struct bpf_local_storage_elem *selem); 184 184 185 185 struct bpf_local_storage_elem * 186 186 bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner, void *value,
+5 -3
kernel/bpf/bpf_local_storage.c
··· 365 365 hlist_del_init_rcu(&selem->map_node); 366 366 } 367 367 368 - void bpf_selem_link_map(struct bpf_local_storage_map *smap, 369 - struct bpf_local_storage *local_storage, 370 - struct bpf_local_storage_elem *selem) 368 + int bpf_selem_link_map(struct bpf_local_storage_map *smap, 369 + struct bpf_local_storage *local_storage, 370 + struct bpf_local_storage_elem *selem) 371 371 { 372 372 struct bpf_local_storage_map_bucket *b; 373 373 unsigned long flags; ··· 376 376 raw_spin_lock_irqsave(&b->lock, flags); 377 377 hlist_add_head_rcu(&selem->map_node, &b->list); 378 378 raw_spin_unlock_irqrestore(&b->lock, flags); 379 + 380 + return 0; 379 381 } 380 382 381 383 static void bpf_selem_link_map_nolock(struct bpf_local_storage_map_bucket *b,
+8 -1
net/core/bpf_sk_storage.c
··· 191 191 } 192 192 193 193 if (new_sk_storage) { 194 - bpf_selem_link_map(smap, new_sk_storage, copy_selem); 194 + ret = bpf_selem_link_map(smap, new_sk_storage, copy_selem); 195 + if (ret) { 196 + bpf_selem_free(copy_selem, true); 197 + atomic_sub(smap->elem_size, 198 + &newsk->sk_omem_alloc); 199 + bpf_map_put(map); 200 + goto out; 201 + } 195 202 bpf_selem_link_storage_nolock(new_sk_storage, copy_selem); 196 203 } else { 197 204 ret = bpf_local_storage_alloc(newsk, smap, copy_selem, GFP_ATOMIC);