4
4
#include <linux/bpf.h>
5
5
#include <linux/btf.h>
6
6
#include <linux/rcupdate.h>
7
+ #include <linux/rcupdate_trace.h>
7
8
#include <linux/random.h>
8
9
#include <linux/smp.h>
9
10
#include <linux/topology.h>
25
26
*
26
27
* Different map implementations will rely on rcu in map methods
27
28
* lookup/update/delete, therefore eBPF programs must run under rcu lock
28
- * if program is allowed to access maps, so check rcu_read_lock_held in
29
- * all three functions.
29
+ * if program is allowed to access maps, so check rcu_read_lock_held() or
30
+ * rcu_read_lock_trace_held() in all three functions.
30
31
*/
31
32
BPF_CALL_2 (bpf_map_lookup_elem , struct bpf_map * , map , void * , key )
32
33
{
33
- WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_bh_held ());
34
+ WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () &&
35
+ !rcu_read_lock_bh_held ());
34
36
return (unsigned long ) map -> ops -> map_lookup_elem (map , key );
35
37
}
36
38
@@ -46,7 +48,8 @@ const struct bpf_func_proto bpf_map_lookup_elem_proto = {
46
48
BPF_CALL_4 (bpf_map_update_elem , struct bpf_map * , map , void * , key ,
47
49
void * , value , u64 , flags )
48
50
{
49
- WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_bh_held ());
51
+ WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () &&
52
+ !rcu_read_lock_bh_held ());
50
53
return map -> ops -> map_update_elem (map , key , value , flags );
51
54
}
52
55
@@ -63,7 +66,8 @@ const struct bpf_func_proto bpf_map_update_elem_proto = {
63
66
64
67
BPF_CALL_2 (bpf_map_delete_elem , struct bpf_map * , map , void * , key )
65
68
{
66
- WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_bh_held ());
69
+ WARN_ON_ONCE (!rcu_read_lock_held () && !rcu_read_lock_trace_held () &&
70
+ !rcu_read_lock_bh_held ());
67
71
return map -> ops -> map_delete_elem (map , key );
68
72
}
69
73
0 commit comments