Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or |
| 4 | * modify it under the terms of version 2 of the GNU General Public |
| 5 | * License as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, but |
| 8 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10 | * General Public License for more details. |
| 11 | */ |
| 12 | #include <linux/bpf.h> |
| 13 | #include <linux/rcupdate.h> |
Daniel Borkmann | 03e69b5 | 2015-03-14 02:27:16 +0100 | [diff] [blame] | 14 | #include <linux/random.h> |
Daniel Borkmann | c04167c | 2015-03-14 02:27:17 +0100 | [diff] [blame] | 15 | #include <linux/smp.h> |
Daniel Borkmann | 2d0e30c | 2016-10-21 12:46:33 +0200 | [diff] [blame] | 16 | #include <linux/topology.h> |
Daniel Borkmann | 17ca8cb | 2015-05-29 23:23:06 +0200 | [diff] [blame] | 17 | #include <linux/ktime.h> |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 18 | #include <linux/sched.h> |
| 19 | #include <linux/uidgid.h> |
Daniel Borkmann | f3694e0 | 2016-09-09 02:45:31 +0200 | [diff] [blame] | 20 | #include <linux/filter.h> |
Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 21 | |
| 22 | /* If kernel subsystem is allowing eBPF programs to call this function, |
| 23 | * inside its own verifier_ops->get_func_proto() callback it should return |
| 24 | * bpf_map_lookup_elem_proto, so that verifier can properly check the arguments |
| 25 | * |
| 26 | * Different map implementations will rely on rcu in map methods |
| 27 | * 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. |
| 30 | */ |
Daniel Borkmann | f3694e0 | 2016-09-09 02:45:31 +0200 | [diff] [blame] | 31 | BPF_CALL_2(bpf_map_lookup_elem, struct bpf_map *, map, void *, key) |
Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 32 | { |
Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 33 | WARN_ON_ONCE(!rcu_read_lock_held()); |
Daniel Borkmann | f3694e0 | 2016-09-09 02:45:31 +0200 | [diff] [blame] | 34 | return (unsigned long) map->ops->map_lookup_elem(map, key); |
Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 35 | } |
| 36 | |
Daniel Borkmann | a2c83ff | 2015-03-01 12:31:42 +0100 | [diff] [blame] | 37 | const struct bpf_func_proto bpf_map_lookup_elem_proto = { |
Daniel Borkmann | 3324b58 | 2015-05-29 23:23:07 +0200 | [diff] [blame] | 38 | .func = bpf_map_lookup_elem, |
| 39 | .gpl_only = false, |
Daniel Borkmann | 36bbef5 | 2016-09-20 00:26:13 +0200 | [diff] [blame] | 40 | .pkt_access = true, |
Daniel Borkmann | 3324b58 | 2015-05-29 23:23:07 +0200 | [diff] [blame] | 41 | .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, |
| 42 | .arg1_type = ARG_CONST_MAP_PTR, |
| 43 | .arg2_type = ARG_PTR_TO_MAP_KEY, |
Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 44 | }; |
| 45 | |
Daniel Borkmann | f3694e0 | 2016-09-09 02:45:31 +0200 | [diff] [blame] | 46 | BPF_CALL_4(bpf_map_update_elem, struct bpf_map *, map, void *, key, |
| 47 | void *, value, u64, flags) |
Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 48 | { |
Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 49 | WARN_ON_ONCE(!rcu_read_lock_held()); |
Daniel Borkmann | f3694e0 | 2016-09-09 02:45:31 +0200 | [diff] [blame] | 50 | return map->ops->map_update_elem(map, key, value, flags); |
Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Daniel Borkmann | a2c83ff | 2015-03-01 12:31:42 +0100 | [diff] [blame] | 53 | const struct bpf_func_proto bpf_map_update_elem_proto = { |
Daniel Borkmann | 3324b58 | 2015-05-29 23:23:07 +0200 | [diff] [blame] | 54 | .func = bpf_map_update_elem, |
| 55 | .gpl_only = false, |
Daniel Borkmann | 36bbef5 | 2016-09-20 00:26:13 +0200 | [diff] [blame] | 56 | .pkt_access = true, |
Daniel Borkmann | 3324b58 | 2015-05-29 23:23:07 +0200 | [diff] [blame] | 57 | .ret_type = RET_INTEGER, |
| 58 | .arg1_type = ARG_CONST_MAP_PTR, |
| 59 | .arg2_type = ARG_PTR_TO_MAP_KEY, |
| 60 | .arg3_type = ARG_PTR_TO_MAP_VALUE, |
| 61 | .arg4_type = ARG_ANYTHING, |
Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
Daniel Borkmann | f3694e0 | 2016-09-09 02:45:31 +0200 | [diff] [blame] | 64 | BPF_CALL_2(bpf_map_delete_elem, struct bpf_map *, map, void *, key) |
Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 65 | { |
Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 66 | WARN_ON_ONCE(!rcu_read_lock_held()); |
Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 67 | return map->ops->map_delete_elem(map, key); |
| 68 | } |
| 69 | |
Daniel Borkmann | a2c83ff | 2015-03-01 12:31:42 +0100 | [diff] [blame] | 70 | const struct bpf_func_proto bpf_map_delete_elem_proto = { |
Daniel Borkmann | 3324b58 | 2015-05-29 23:23:07 +0200 | [diff] [blame] | 71 | .func = bpf_map_delete_elem, |
| 72 | .gpl_only = false, |
Daniel Borkmann | 36bbef5 | 2016-09-20 00:26:13 +0200 | [diff] [blame] | 73 | .pkt_access = true, |
Daniel Borkmann | 3324b58 | 2015-05-29 23:23:07 +0200 | [diff] [blame] | 74 | .ret_type = RET_INTEGER, |
| 75 | .arg1_type = ARG_CONST_MAP_PTR, |
| 76 | .arg2_type = ARG_PTR_TO_MAP_KEY, |
Alexei Starovoitov | d0003ec | 2014-11-13 17:36:49 -0800 | [diff] [blame] | 77 | }; |
Daniel Borkmann | 03e69b5 | 2015-03-14 02:27:16 +0100 | [diff] [blame] | 78 | |
Mauricio Vasquez B | f1a2e44 | 2018-10-18 15:16:25 +0200 | [diff] [blame] | 79 | BPF_CALL_3(bpf_map_push_elem, struct bpf_map *, map, void *, value, u64, flags) |
| 80 | { |
| 81 | return map->ops->map_push_elem(map, value, flags); |
| 82 | } |
| 83 | |
| 84 | const struct bpf_func_proto bpf_map_push_elem_proto = { |
| 85 | .func = bpf_map_push_elem, |
| 86 | .gpl_only = false, |
| 87 | .pkt_access = true, |
| 88 | .ret_type = RET_INTEGER, |
| 89 | .arg1_type = ARG_CONST_MAP_PTR, |
| 90 | .arg2_type = ARG_PTR_TO_MAP_VALUE, |
| 91 | .arg3_type = ARG_ANYTHING, |
| 92 | }; |
| 93 | |
| 94 | BPF_CALL_2(bpf_map_pop_elem, struct bpf_map *, map, void *, value) |
| 95 | { |
| 96 | return map->ops->map_pop_elem(map, value); |
| 97 | } |
| 98 | |
| 99 | const struct bpf_func_proto bpf_map_pop_elem_proto = { |
| 100 | .func = bpf_map_pop_elem, |
| 101 | .gpl_only = false, |
Mauricio Vasquez B | f1a2e44 | 2018-10-18 15:16:25 +0200 | [diff] [blame] | 102 | .ret_type = RET_INTEGER, |
| 103 | .arg1_type = ARG_CONST_MAP_PTR, |
| 104 | .arg2_type = ARG_PTR_TO_UNINIT_MAP_VALUE, |
| 105 | }; |
| 106 | |
| 107 | BPF_CALL_2(bpf_map_peek_elem, struct bpf_map *, map, void *, value) |
| 108 | { |
| 109 | return map->ops->map_peek_elem(map, value); |
| 110 | } |
| 111 | |
| 112 | const struct bpf_func_proto bpf_map_peek_elem_proto = { |
| 113 | .func = bpf_map_pop_elem, |
| 114 | .gpl_only = false, |
Mauricio Vasquez B | f1a2e44 | 2018-10-18 15:16:25 +0200 | [diff] [blame] | 115 | .ret_type = RET_INTEGER, |
| 116 | .arg1_type = ARG_CONST_MAP_PTR, |
| 117 | .arg2_type = ARG_PTR_TO_UNINIT_MAP_VALUE, |
| 118 | }; |
| 119 | |
Daniel Borkmann | 03e69b5 | 2015-03-14 02:27:16 +0100 | [diff] [blame] | 120 | const struct bpf_func_proto bpf_get_prandom_u32_proto = { |
Daniel Borkmann | 3ad0040 | 2015-10-08 01:20:39 +0200 | [diff] [blame] | 121 | .func = bpf_user_rnd_u32, |
Daniel Borkmann | 03e69b5 | 2015-03-14 02:27:16 +0100 | [diff] [blame] | 122 | .gpl_only = false, |
| 123 | .ret_type = RET_INTEGER, |
| 124 | }; |
Daniel Borkmann | c04167c | 2015-03-14 02:27:17 +0100 | [diff] [blame] | 125 | |
Daniel Borkmann | f3694e0 | 2016-09-09 02:45:31 +0200 | [diff] [blame] | 126 | BPF_CALL_0(bpf_get_smp_processor_id) |
Daniel Borkmann | c04167c | 2015-03-14 02:27:17 +0100 | [diff] [blame] | 127 | { |
Daniel Borkmann | 80b48c4 | 2016-06-28 12:18:26 +0200 | [diff] [blame] | 128 | return smp_processor_id(); |
Daniel Borkmann | c04167c | 2015-03-14 02:27:17 +0100 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | const struct bpf_func_proto bpf_get_smp_processor_id_proto = { |
| 132 | .func = bpf_get_smp_processor_id, |
| 133 | .gpl_only = false, |
| 134 | .ret_type = RET_INTEGER, |
| 135 | }; |
Daniel Borkmann | 17ca8cb | 2015-05-29 23:23:06 +0200 | [diff] [blame] | 136 | |
Daniel Borkmann | 2d0e30c | 2016-10-21 12:46:33 +0200 | [diff] [blame] | 137 | BPF_CALL_0(bpf_get_numa_node_id) |
| 138 | { |
| 139 | return numa_node_id(); |
| 140 | } |
| 141 | |
| 142 | const struct bpf_func_proto bpf_get_numa_node_id_proto = { |
| 143 | .func = bpf_get_numa_node_id, |
| 144 | .gpl_only = false, |
| 145 | .ret_type = RET_INTEGER, |
| 146 | }; |
| 147 | |
Daniel Borkmann | f3694e0 | 2016-09-09 02:45:31 +0200 | [diff] [blame] | 148 | BPF_CALL_0(bpf_ktime_get_ns) |
Daniel Borkmann | 17ca8cb | 2015-05-29 23:23:06 +0200 | [diff] [blame] | 149 | { |
| 150 | /* NMI safe access to clock monotonic */ |
| 151 | return ktime_get_mono_fast_ns(); |
| 152 | } |
| 153 | |
| 154 | const struct bpf_func_proto bpf_ktime_get_ns_proto = { |
| 155 | .func = bpf_ktime_get_ns, |
| 156 | .gpl_only = true, |
| 157 | .ret_type = RET_INTEGER, |
| 158 | }; |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 159 | |
Daniel Borkmann | f3694e0 | 2016-09-09 02:45:31 +0200 | [diff] [blame] | 160 | BPF_CALL_0(bpf_get_current_pid_tgid) |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 161 | { |
| 162 | struct task_struct *task = current; |
| 163 | |
Daniel Borkmann | 6088b58 | 2016-09-09 02:45:28 +0200 | [diff] [blame] | 164 | if (unlikely(!task)) |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 165 | return -EINVAL; |
| 166 | |
| 167 | return (u64) task->tgid << 32 | task->pid; |
| 168 | } |
| 169 | |
| 170 | const struct bpf_func_proto bpf_get_current_pid_tgid_proto = { |
| 171 | .func = bpf_get_current_pid_tgid, |
| 172 | .gpl_only = false, |
| 173 | .ret_type = RET_INTEGER, |
| 174 | }; |
| 175 | |
Daniel Borkmann | f3694e0 | 2016-09-09 02:45:31 +0200 | [diff] [blame] | 176 | BPF_CALL_0(bpf_get_current_uid_gid) |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 177 | { |
| 178 | struct task_struct *task = current; |
| 179 | kuid_t uid; |
| 180 | kgid_t gid; |
| 181 | |
Daniel Borkmann | 6088b58 | 2016-09-09 02:45:28 +0200 | [diff] [blame] | 182 | if (unlikely(!task)) |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 183 | return -EINVAL; |
| 184 | |
| 185 | current_uid_gid(&uid, &gid); |
| 186 | return (u64) from_kgid(&init_user_ns, gid) << 32 | |
Daniel Borkmann | 6088b58 | 2016-09-09 02:45:28 +0200 | [diff] [blame] | 187 | from_kuid(&init_user_ns, uid); |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | const struct bpf_func_proto bpf_get_current_uid_gid_proto = { |
| 191 | .func = bpf_get_current_uid_gid, |
| 192 | .gpl_only = false, |
| 193 | .ret_type = RET_INTEGER, |
| 194 | }; |
| 195 | |
Daniel Borkmann | f3694e0 | 2016-09-09 02:45:31 +0200 | [diff] [blame] | 196 | BPF_CALL_2(bpf_get_current_comm, char *, buf, u32, size) |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 197 | { |
| 198 | struct task_struct *task = current; |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 199 | |
Daniel Borkmann | 074f528e | 2016-04-13 00:10:52 +0200 | [diff] [blame] | 200 | if (unlikely(!task)) |
| 201 | goto err_clear; |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 202 | |
Daniel Borkmann | 074f528e | 2016-04-13 00:10:52 +0200 | [diff] [blame] | 203 | strncpy(buf, task->comm, size); |
| 204 | |
| 205 | /* Verifier guarantees that size > 0. For task->comm exceeding |
| 206 | * size, guarantee that buf is %NUL-terminated. Unconditionally |
| 207 | * done here to save the size test. |
| 208 | */ |
| 209 | buf[size - 1] = 0; |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 210 | return 0; |
Daniel Borkmann | 074f528e | 2016-04-13 00:10:52 +0200 | [diff] [blame] | 211 | err_clear: |
| 212 | memset(buf, 0, size); |
| 213 | return -EINVAL; |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | const struct bpf_func_proto bpf_get_current_comm_proto = { |
| 217 | .func = bpf_get_current_comm, |
| 218 | .gpl_only = false, |
| 219 | .ret_type = RET_INTEGER, |
Alexei Starovoitov | 39f19ebb | 2017-01-09 10:19:50 -0800 | [diff] [blame] | 220 | .arg1_type = ARG_PTR_TO_UNINIT_MEM, |
| 221 | .arg2_type = ARG_CONST_SIZE, |
Alexei Starovoitov | ffeedaf | 2015-06-12 19:39:12 -0700 | [diff] [blame] | 222 | }; |
Yonghong Song | bf6fa2c8 | 2018-06-03 15:59:41 -0700 | [diff] [blame] | 223 | |
Alexei Starovoitov | d83525c | 2019-01-31 15:40:04 -0800 | [diff] [blame^] | 224 | #if defined(CONFIG_QUEUED_SPINLOCKS) || defined(CONFIG_BPF_ARCH_SPINLOCK) |
| 225 | |
| 226 | static inline void __bpf_spin_lock(struct bpf_spin_lock *lock) |
| 227 | { |
| 228 | arch_spinlock_t *l = (void *)lock; |
| 229 | union { |
| 230 | __u32 val; |
| 231 | arch_spinlock_t lock; |
| 232 | } u = { .lock = __ARCH_SPIN_LOCK_UNLOCKED }; |
| 233 | |
| 234 | compiletime_assert(u.val == 0, "__ARCH_SPIN_LOCK_UNLOCKED not 0"); |
| 235 | BUILD_BUG_ON(sizeof(*l) != sizeof(__u32)); |
| 236 | BUILD_BUG_ON(sizeof(*lock) != sizeof(__u32)); |
| 237 | arch_spin_lock(l); |
| 238 | } |
| 239 | |
| 240 | static inline void __bpf_spin_unlock(struct bpf_spin_lock *lock) |
| 241 | { |
| 242 | arch_spinlock_t *l = (void *)lock; |
| 243 | |
| 244 | arch_spin_unlock(l); |
| 245 | } |
| 246 | |
| 247 | #else |
| 248 | |
| 249 | static inline void __bpf_spin_lock(struct bpf_spin_lock *lock) |
| 250 | { |
| 251 | atomic_t *l = (void *)lock; |
| 252 | |
| 253 | BUILD_BUG_ON(sizeof(*l) != sizeof(*lock)); |
| 254 | do { |
| 255 | atomic_cond_read_relaxed(l, !VAL); |
| 256 | } while (atomic_xchg(l, 1)); |
| 257 | } |
| 258 | |
| 259 | static inline void __bpf_spin_unlock(struct bpf_spin_lock *lock) |
| 260 | { |
| 261 | atomic_t *l = (void *)lock; |
| 262 | |
| 263 | atomic_set_release(l, 0); |
| 264 | } |
| 265 | |
| 266 | #endif |
| 267 | |
| 268 | static DEFINE_PER_CPU(unsigned long, irqsave_flags); |
| 269 | |
| 270 | notrace BPF_CALL_1(bpf_spin_lock, struct bpf_spin_lock *, lock) |
| 271 | { |
| 272 | unsigned long flags; |
| 273 | |
| 274 | local_irq_save(flags); |
| 275 | __bpf_spin_lock(lock); |
| 276 | __this_cpu_write(irqsave_flags, flags); |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | const struct bpf_func_proto bpf_spin_lock_proto = { |
| 281 | .func = bpf_spin_lock, |
| 282 | .gpl_only = false, |
| 283 | .ret_type = RET_VOID, |
| 284 | .arg1_type = ARG_PTR_TO_SPIN_LOCK, |
| 285 | }; |
| 286 | |
| 287 | notrace BPF_CALL_1(bpf_spin_unlock, struct bpf_spin_lock *, lock) |
| 288 | { |
| 289 | unsigned long flags; |
| 290 | |
| 291 | flags = __this_cpu_read(irqsave_flags); |
| 292 | __bpf_spin_unlock(lock); |
| 293 | local_irq_restore(flags); |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | const struct bpf_func_proto bpf_spin_unlock_proto = { |
| 298 | .func = bpf_spin_unlock, |
| 299 | .gpl_only = false, |
| 300 | .ret_type = RET_VOID, |
| 301 | .arg1_type = ARG_PTR_TO_SPIN_LOCK, |
| 302 | }; |
| 303 | |
Yonghong Song | bf6fa2c8 | 2018-06-03 15:59:41 -0700 | [diff] [blame] | 304 | #ifdef CONFIG_CGROUPS |
| 305 | BPF_CALL_0(bpf_get_current_cgroup_id) |
| 306 | { |
| 307 | struct cgroup *cgrp = task_dfl_cgroup(current); |
| 308 | |
| 309 | return cgrp->kn->id.id; |
| 310 | } |
| 311 | |
| 312 | const struct bpf_func_proto bpf_get_current_cgroup_id_proto = { |
| 313 | .func = bpf_get_current_cgroup_id, |
| 314 | .gpl_only = false, |
| 315 | .ret_type = RET_INTEGER, |
| 316 | }; |
Roman Gushchin | cd33943 | 2018-08-02 14:27:24 -0700 | [diff] [blame] | 317 | |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 318 | #ifdef CONFIG_CGROUP_BPF |
Roman Gushchin | f294b37 | 2018-09-28 14:45:40 +0000 | [diff] [blame] | 319 | DECLARE_PER_CPU(struct bpf_cgroup_storage*, |
| 320 | bpf_cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]); |
Roman Gushchin | cd33943 | 2018-08-02 14:27:24 -0700 | [diff] [blame] | 321 | |
| 322 | BPF_CALL_2(bpf_get_local_storage, struct bpf_map *, map, u64, flags) |
| 323 | { |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 324 | /* flags argument is not used now, |
| 325 | * but provides an ability to extend the API. |
| 326 | * verifier checks that its value is correct. |
Roman Gushchin | cd33943 | 2018-08-02 14:27:24 -0700 | [diff] [blame] | 327 | */ |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 328 | enum bpf_cgroup_storage_type stype = cgroup_storage_type(map); |
Roman Gushchin | f294b37 | 2018-09-28 14:45:40 +0000 | [diff] [blame] | 329 | struct bpf_cgroup_storage *storage; |
Roman Gushchin | b741f16 | 2018-09-28 14:45:43 +0000 | [diff] [blame] | 330 | void *ptr; |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 331 | |
Roman Gushchin | f294b37 | 2018-09-28 14:45:40 +0000 | [diff] [blame] | 332 | storage = this_cpu_read(bpf_cgroup_storage[stype]); |
| 333 | |
Roman Gushchin | b741f16 | 2018-09-28 14:45:43 +0000 | [diff] [blame] | 334 | if (stype == BPF_CGROUP_STORAGE_SHARED) |
| 335 | ptr = &READ_ONCE(storage->buf)->data[0]; |
| 336 | else |
| 337 | ptr = this_cpu_ptr(storage->percpu_buf); |
| 338 | |
| 339 | return (unsigned long)ptr; |
Roman Gushchin | cd33943 | 2018-08-02 14:27:24 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | const struct bpf_func_proto bpf_get_local_storage_proto = { |
| 343 | .func = bpf_get_local_storage, |
| 344 | .gpl_only = false, |
| 345 | .ret_type = RET_PTR_TO_MAP_VALUE, |
| 346 | .arg1_type = ARG_CONST_MAP_PTR, |
| 347 | .arg2_type = ARG_ANYTHING, |
| 348 | }; |
Yonghong Song | bf6fa2c8 | 2018-06-03 15:59:41 -0700 | [diff] [blame] | 349 | #endif |
Roman Gushchin | 8bad74f | 2018-09-28 14:45:36 +0000 | [diff] [blame] | 350 | #endif |