bpf: Remove migrate_{disable|enable} from bpf_cgrp_storage_lock helpers

Three callers of bpf_cgrp_storage_lock() are ->map_lookup_elem,
->map_update_elem, ->map_delete_elem from bpf syscall. BPF syscall for
these three operations of cgrp storage has already disabled migration.

Two call sites of bpf_cgrp_storage_trylock() are bpf_cgrp_storage_get(),
and bpf_cgrp_storage_delete() helpers. The running contexts of these
helpers have already disabled migration.

Therefore, it is safe to remove migrate_disable() for these callers.
However, bpf_cgrp_storage_free() also invokes bpf_cgrp_storage_lock()
and its running context doesn't disable migration. Therefore, also add
the missed migrate_{disabled|enable} in bpf_cgrp_storage_free().

Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20250108010728.207536-5-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Hou Tao 2025-01-08 09:07:16 +08:00 committed by Alexei Starovoitov
parent 53f2ba0b1c
commit 25dc65f75b

View File

@ -15,22 +15,20 @@ static DEFINE_PER_CPU(int, bpf_cgrp_storage_busy);
static void bpf_cgrp_storage_lock(void) static void bpf_cgrp_storage_lock(void)
{ {
migrate_disable(); cant_migrate();
this_cpu_inc(bpf_cgrp_storage_busy); this_cpu_inc(bpf_cgrp_storage_busy);
} }
static void bpf_cgrp_storage_unlock(void) static void bpf_cgrp_storage_unlock(void)
{ {
this_cpu_dec(bpf_cgrp_storage_busy); this_cpu_dec(bpf_cgrp_storage_busy);
migrate_enable();
} }
static bool bpf_cgrp_storage_trylock(void) static bool bpf_cgrp_storage_trylock(void)
{ {
migrate_disable(); cant_migrate();
if (unlikely(this_cpu_inc_return(bpf_cgrp_storage_busy) != 1)) { if (unlikely(this_cpu_inc_return(bpf_cgrp_storage_busy) != 1)) {
this_cpu_dec(bpf_cgrp_storage_busy); this_cpu_dec(bpf_cgrp_storage_busy);
migrate_enable();
return false; return false;
} }
return true; return true;
@ -47,17 +45,18 @@ void bpf_cgrp_storage_free(struct cgroup *cgroup)
{ {
struct bpf_local_storage *local_storage; struct bpf_local_storage *local_storage;
migrate_disable();
rcu_read_lock(); rcu_read_lock();
local_storage = rcu_dereference(cgroup->bpf_cgrp_storage); local_storage = rcu_dereference(cgroup->bpf_cgrp_storage);
if (!local_storage) { if (!local_storage)
rcu_read_unlock(); goto out;
return;
}
bpf_cgrp_storage_lock(); bpf_cgrp_storage_lock();
bpf_local_storage_destroy(local_storage); bpf_local_storage_destroy(local_storage);
bpf_cgrp_storage_unlock(); bpf_cgrp_storage_unlock();
out:
rcu_read_unlock(); rcu_read_unlock();
migrate_enable();
} }
static struct bpf_local_storage_data * static struct bpf_local_storage_data *