Skip to content

Commit 9e6c958

Browse files
Hou TaoAlexei Starovoitov
authored andcommitted
bpf: Remove migrate_{disable|enable} from bpf_task_storage_lock helpers
Three callers of bpf_task_storage_lock() are ->map_lookup_elem, ->map_update_elem, ->map_delete_elem from bpf syscall. BPF syscall for these three operations of task storage has already disabled migration. Another two callers are bpf_task_storage_get() and bpf_task_storage_delete() helpers which will be used by BPF program. Two callers of bpf_task_storage_trylock() are bpf_task_storage_get() and bpf_task_storage_delete() helpers. The running contexts of these helpers have already disabled migration. Therefore, it is safe to remove migrate_{disable|enable} from task storage lock helpers for these call sites. However, bpf_task_storage_free() also invokes bpf_task_storage_lock() and its running context doesn't disable migration, therefore, add the missed migrate_{disable|enable} in bpf_task_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 25dc65f commit 9e6c958

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

kernel/bpf/bpf_task_storage.c

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

2525
static void bpf_task_storage_lock(void)
2626
{
27-
migrate_disable();
27+
cant_migrate();
2828
this_cpu_inc(bpf_task_storage_busy);
2929
}
3030

3131
static void bpf_task_storage_unlock(void)
3232
{
3333
this_cpu_dec(bpf_task_storage_busy);
34-
migrate_enable();
3534
}
3635

3736
static bool bpf_task_storage_trylock(void)
3837
{
39-
migrate_disable();
38+
cant_migrate();
4039
if (unlikely(this_cpu_inc_return(bpf_task_storage_busy) != 1)) {
4140
this_cpu_dec(bpf_task_storage_busy);
42-
migrate_enable();
4341
return false;
4442
}
4543
return true;
@@ -72,18 +70,19 @@ void bpf_task_storage_free(struct task_struct *task)
7270
{
7371
struct bpf_local_storage *local_storage;
7472

73+
migrate_disable();
7574
rcu_read_lock();
7675

7776
local_storage = rcu_dereference(task->bpf_storage);
78-
if (!local_storage) {
79-
rcu_read_unlock();
80-
return;
81-
}
77+
if (!local_storage)
78+
goto out;
8279

8380
bpf_task_storage_lock();
8481
bpf_local_storage_destroy(local_storage);
8582
bpf_task_storage_unlock();
83+
out:
8684
rcu_read_unlock();
85+
migrate_enable();
8786
}
8887

8988
static void *bpf_pid_task_storage_lookup_elem(struct bpf_map *map, void *key)

0 commit comments

Comments
 (0)