1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2021 Facebook */
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_tracing.h>
12 char _license[] SEC("license") = "GPL";
17 __uint(type, BPF_MAP_TYPE_TASK_STORAGE);
18 __uint(map_flags, BPF_F_NO_PREALLOC);
24 __uint(type, BPF_MAP_TYPE_TASK_STORAGE);
25 __uint(map_flags, BPF_F_NO_PREALLOC);
30 SEC("fentry/bpf_local_storage_update")
31 int BPF_PROG(on_update)
33 struct task_struct *task = bpf_get_current_task_btf();
36 if (!test_pid || task->pid != test_pid)
39 ptr = bpf_task_storage_get(&map_a, task, 0,
40 BPF_LOCAL_STORAGE_GET_F_CREATE);
41 /* ptr will not be NULL when it is called from
42 * the bpf_task_storage_get(&map_b,...F_CREATE) in
43 * the BPF_PROG(on_enter) below. It is because
44 * the value can be found in map_a and the kernel
45 * does not need to acquire any spin_lock.
51 err = bpf_task_storage_delete(&map_a, task);
56 /* This will still fail because map_b is empty and
57 * this BPF_PROG(on_update) has failed to acquire
58 * the percpu busy lock => meaning potential
59 * deadlock is detected and it will fail to create
62 ptr = bpf_task_storage_get(&map_b, task, 0,
63 BPF_LOCAL_STORAGE_GET_F_CREATE);
70 SEC("tp_btf/sys_enter")
71 int BPF_PROG(on_enter, struct pt_regs *regs, long id)
73 struct task_struct *task;
76 task = bpf_get_current_task_btf();
77 if (!test_pid || task->pid != test_pid)
80 ptr = bpf_task_storage_get(&map_a, task, 0,
81 BPF_LOCAL_STORAGE_GET_F_CREATE);
85 ptr = bpf_task_storage_get(&map_b, task, 0,
86 BPF_LOCAL_STORAGE_GET_F_CREATE);