]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Disable migration in bpf_selem_free_rcu
authorHou Tao <houtao1@huawei.com>
Wed, 8 Jan 2025 01:07:21 +0000 (09:07 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 9 Jan 2025 02:06:36 +0000 (18:06 -0800)
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 <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20250108010728.207536-10-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/bpf_local_storage.c

index e94820f6b0cd38b351a769aefcd7af8089183d4f..615a3034baeb512096d96194ccff22b6fd58269b 100644 (file)
@@ -217,7 +217,10 @@ static void bpf_selem_free_rcu(struct rcu_head *rcu)
        selem = container_of(rcu, struct bpf_local_storage_elem, rcu);
        /* The bpf_local_storage_map_free will wait for rcu_barrier */
        smap = rcu_dereference_check(SDATA(selem)->smap, 1);
+
+       migrate_disable();
        bpf_obj_free_fields(smap->map.record, SDATA(selem)->data);
+       migrate_enable();
        bpf_mem_cache_raw_free(selem);
 }