Skip to content

Commit 25dc65f

Browse files
Hou TaoAlexei Starovoitov
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 53f2ba0 commit 25dc65f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

kernel/bpf/bpf_cgrp_storage.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@ static DEFINE_PER_CPU(int, bpf_cgrp_storage_busy);
1515

1616
static void bpf_cgrp_storage_lock(void)
1717
{
18-
migrate_disable();
18+
cant_migrate();
1919
this_cpu_inc(bpf_cgrp_storage_busy);
2020
}
2121

2222
static void bpf_cgrp_storage_unlock(void)
2323
{
2424
this_cpu_dec(bpf_cgrp_storage_busy);
25-
migrate_enable();
2625
}
2726

2827
static bool bpf_cgrp_storage_trylock(void)
2928
{
30-
migrate_disable();
29+
cant_migrate();
3130
if (unlikely(this_cpu_inc_return(bpf_cgrp_storage_busy) != 1)) {
3231
this_cpu_dec(bpf_cgrp_storage_busy);
33-
migrate_enable();
3432
return false;
3533
}
3634
return true;
@@ -47,17 +45,18 @@ void bpf_cgrp_storage_free(struct cgroup *cgroup)
4745
{
4846
struct bpf_local_storage *local_storage;
4947

48+
migrate_disable();
5049
rcu_read_lock();
5150
local_storage = rcu_dereference(cgroup->bpf_cgrp_storage);
52-
if (!local_storage) {
53-
rcu_read_unlock();
54-
return;
55-
}
51+
if (!local_storage)
52+
goto out;
5653

5754
bpf_cgrp_storage_lock();
5855
bpf_local_storage_destroy(local_storage);
5956
bpf_cgrp_storage_unlock();
57+
out:
6058
rcu_read_unlock();
59+
migrate_enable();
6160
}
6261

6362
static struct bpf_local_storage_data *

0 commit comments

Comments
 (0)