Commit fd103ffc authored by Amery Hung's avatar Amery Hung Committed by Martin KaFai Lau
Browse files

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: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarAmery Hung <ameryhung@gmail.com>
Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20260205222916.1788211-4-ameryhung@gmail.com
parent 1b7e0cae
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -178,7 +178,7 @@ void bpf_selem_link_storage_nolock(struct bpf_local_storage *local_storage,

void bpf_selem_unlink(struct bpf_local_storage_elem *selem, bool reuse_now);

void bpf_selem_link_map(struct bpf_local_storage_map *smap,
int bpf_selem_link_map(struct bpf_local_storage_map *smap,
		       struct bpf_local_storage *local_storage,
		       struct bpf_local_storage_elem *selem);

+5 −3
Original line number Diff line number Diff line
@@ -365,7 +365,7 @@ static void bpf_selem_unlink_map_nolock(struct bpf_local_storage_elem *selem)
	hlist_del_init_rcu(&selem->map_node);
}

void bpf_selem_link_map(struct bpf_local_storage_map *smap,
int bpf_selem_link_map(struct bpf_local_storage_map *smap,
		       struct bpf_local_storage *local_storage,
		       struct bpf_local_storage_elem *selem)
{
@@ -376,6 +376,8 @@ void bpf_selem_link_map(struct bpf_local_storage_map *smap,
	raw_spin_lock_irqsave(&b->lock, flags);
	hlist_add_head_rcu(&selem->map_node, &b->list);
	raw_spin_unlock_irqrestore(&b->lock, flags);

	return 0;
}

static void bpf_selem_link_map_nolock(struct bpf_local_storage_map_bucket *b,
+8 −1
Original line number Diff line number Diff line
@@ -191,7 +191,14 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk)
		}

		if (new_sk_storage) {
			bpf_selem_link_map(smap, new_sk_storage, copy_selem);
			ret = bpf_selem_link_map(smap, new_sk_storage, copy_selem);
			if (ret) {
				bpf_selem_free(copy_selem, true);
				atomic_sub(smap->elem_size,
					   &newsk->sk_omem_alloc);
				bpf_map_put(map);
				goto out;
			}
			bpf_selem_link_storage_nolock(new_sk_storage, copy_selem);
		} else {
			ret = bpf_local_storage_alloc(newsk, smap, copy_selem, GFP_ATOMIC);