Skip to content

Commit 7d1032d

Browse files
Hou TaoAlexei Starovoitov
authored andcommitted
bpf: Disable migration when destroying sock storage
When destroying sock storage, it invokes bpf_local_storage_destroy() to remove all storage elements saved in the sock storage. The destroy procedure will call bpf_selem_free() to free the element, and bpf_selem_free() calls bpf_obj_free_fields() to free the special fields in map value (e.g., kptr). Since kptrs may be allocated from bpf memory allocator, migrate_{disable|enable} pairs are necessary for the freeing of these kptrs. To simplify reasoning about when migrate_disable() is needed for the freeing of these dynamically-allocated kptrs, let the caller to guarantee migration is disabled before invoking bpf_obj_free_fields(). Therefore, the patch adds migrate_{disable|enable} pair in bpf_sock_storage_free(). The migrate_{disable|enable} pairs in the underlying implementation of bpf_obj_free_fields() will be removed by The following patch. Signed-off-by: Hou Tao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent e319cdc commit 7d1032d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

net/core/bpf_sk_storage.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ void bpf_sk_storage_free(struct sock *sk)
5050
{
5151
struct bpf_local_storage *sk_storage;
5252

53+
migrate_disable();
5354
rcu_read_lock();
5455
sk_storage = rcu_dereference(sk->sk_bpf_storage);
55-
if (!sk_storage) {
56-
rcu_read_unlock();
57-
return;
58-
}
56+
if (!sk_storage)
57+
goto out;
5958

6059
bpf_local_storage_destroy(sk_storage);
60+
out:
6161
rcu_read_unlock();
62+
migrate_enable();
6263
}
6364

6465
static void bpf_sk_storage_map_free(struct bpf_map *map)

0 commit comments

Comments
 (0)