diff options
Diffstat (limited to 'kernel/bpf/helpers.c')
| -rw-r--r-- | kernel/bpf/helpers.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 9e3414d85459..bd7f5988ed9c 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c | |||
| @@ -11,6 +11,8 @@ | |||
| 11 | */ | 11 | */ |
| 12 | #include <linux/bpf.h> | 12 | #include <linux/bpf.h> |
| 13 | #include <linux/rcupdate.h> | 13 | #include <linux/rcupdate.h> |
| 14 | #include <linux/random.h> | ||
| 15 | #include <linux/smp.h> | ||
| 14 | 16 | ||
| 15 | /* If kernel subsystem is allowing eBPF programs to call this function, | 17 | /* If kernel subsystem is allowing eBPF programs to call this function, |
| 16 | * inside its own verifier_ops->get_func_proto() callback it should return | 18 | * inside its own verifier_ops->get_func_proto() callback it should return |
| @@ -41,7 +43,7 @@ static u64 bpf_map_lookup_elem(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) | |||
| 41 | return (unsigned long) value; | 43 | return (unsigned long) value; |
| 42 | } | 44 | } |
| 43 | 45 | ||
| 44 | struct bpf_func_proto bpf_map_lookup_elem_proto = { | 46 | const struct bpf_func_proto bpf_map_lookup_elem_proto = { |
| 45 | .func = bpf_map_lookup_elem, | 47 | .func = bpf_map_lookup_elem, |
| 46 | .gpl_only = false, | 48 | .gpl_only = false, |
| 47 | .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, | 49 | .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, |
| @@ -60,7 +62,7 @@ static u64 bpf_map_update_elem(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) | |||
| 60 | return map->ops->map_update_elem(map, key, value, r4); | 62 | return map->ops->map_update_elem(map, key, value, r4); |
| 61 | } | 63 | } |
| 62 | 64 | ||
| 63 | struct bpf_func_proto bpf_map_update_elem_proto = { | 65 | const struct bpf_func_proto bpf_map_update_elem_proto = { |
| 64 | .func = bpf_map_update_elem, | 66 | .func = bpf_map_update_elem, |
| 65 | .gpl_only = false, | 67 | .gpl_only = false, |
| 66 | .ret_type = RET_INTEGER, | 68 | .ret_type = RET_INTEGER, |
| @@ -80,10 +82,32 @@ static u64 bpf_map_delete_elem(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) | |||
| 80 | return map->ops->map_delete_elem(map, key); | 82 | return map->ops->map_delete_elem(map, key); |
| 81 | } | 83 | } |
| 82 | 84 | ||
| 83 | struct bpf_func_proto bpf_map_delete_elem_proto = { | 85 | const struct bpf_func_proto bpf_map_delete_elem_proto = { |
| 84 | .func = bpf_map_delete_elem, | 86 | .func = bpf_map_delete_elem, |
| 85 | .gpl_only = false, | 87 | .gpl_only = false, |
| 86 | .ret_type = RET_INTEGER, | 88 | .ret_type = RET_INTEGER, |
| 87 | .arg1_type = ARG_CONST_MAP_PTR, | 89 | .arg1_type = ARG_CONST_MAP_PTR, |
| 88 | .arg2_type = ARG_PTR_TO_MAP_KEY, | 90 | .arg2_type = ARG_PTR_TO_MAP_KEY, |
| 89 | }; | 91 | }; |
| 92 | |||
| 93 | static u64 bpf_get_prandom_u32(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) | ||
| 94 | { | ||
| 95 | return prandom_u32(); | ||
| 96 | } | ||
| 97 | |||
| 98 | const struct bpf_func_proto bpf_get_prandom_u32_proto = { | ||
| 99 | .func = bpf_get_prandom_u32, | ||
| 100 | .gpl_only = false, | ||
| 101 | .ret_type = RET_INTEGER, | ||
| 102 | }; | ||
| 103 | |||
| 104 | static u64 bpf_get_smp_processor_id(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) | ||
| 105 | { | ||
| 106 | return raw_smp_processor_id(); | ||
| 107 | } | ||
| 108 | |||
| 109 | const struct bpf_func_proto bpf_get_smp_processor_id_proto = { | ||
| 110 | .func = bpf_get_smp_processor_id, | ||
| 111 | .gpl_only = false, | ||
| 112 | .ret_type = RET_INTEGER, | ||
| 113 | }; | ||
