Skip to content

Commit 090d7f2

Browse files
Hou TaoAlexei Starovoitov
authored andcommitted
bpf: Disable migration in bpf_selem_free_rcu
bpf_selem_free_rcu() 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_selem_free_rcu(). 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 dfccfc4 commit 090d7f2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

kernel/bpf/bpf_local_storage.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ static void bpf_selem_free_rcu(struct rcu_head *rcu)
217217
selem = container_of(rcu, struct bpf_local_storage_elem, rcu);
218218
/* The bpf_local_storage_map_free will wait for rcu_barrier */
219219
smap = rcu_dereference_check(SDATA(selem)->smap, 1);
220+
221+
migrate_disable();
220222
bpf_obj_free_fields(smap->map.record, SDATA(selem)->data);
223+
migrate_enable();
221224
bpf_mem_cache_raw_free(selem);
222225
}
223226

0 commit comments

Comments
 (0)