Skip to content

Commit e319cdc

Browse files
Hou TaoAlexei Starovoitov
authored andcommitted
bpf: Disable migration when destroying inode storage
When destroying inode storage, it invokes bpf_local_storage_destroy() to remove all storage elements saved in the inode 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_inode_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 9e6c958 commit e319cdc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

kernel/bpf/bpf_inode_storage.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,17 @@ void bpf_inode_storage_free(struct inode *inode)
6262
if (!bsb)
6363
return;
6464

65+
migrate_disable();
6566
rcu_read_lock();
6667

6768
local_storage = rcu_dereference(bsb->storage);
68-
if (!local_storage) {
69-
rcu_read_unlock();
70-
return;
71-
}
69+
if (!local_storage)
70+
goto out;
7271

7372
bpf_local_storage_destroy(local_storage);
73+
out:
7474
rcu_read_unlock();
75+
migrate_enable();
7576
}
7677

7778
static void *bpf_fd_inode_storage_lookup_elem(struct bpf_map *map, void *key)

0 commit comments

Comments
 (0)