Lines Matching +full:revision +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0
11 struct bpf_link *link = ERR_PTR(-EINVAL); in bpf_mprog_link()
12 bool id = flags & BPF_F_ID; in bpf_mprog_link() local
14 if (id) in bpf_mprog_link()
20 if (type && link->prog->type != type) { in bpf_mprog_link()
22 return -EINVAL; in bpf_mprog_link()
25 tuple->link = link; in bpf_mprog_link()
26 tuple->prog = link->prog; in bpf_mprog_link()
34 struct bpf_prog *prog = ERR_PTR(-EINVAL); in bpf_mprog_prog()
35 bool id = flags & BPF_F_ID; in bpf_mprog_prog() local
37 if (id) in bpf_mprog_prog()
43 if (type && prog->type != type) { in bpf_mprog_prog()
45 return -EINVAL; in bpf_mprog_prog()
48 tuple->link = NULL; in bpf_mprog_prog()
49 tuple->prog = prog; in bpf_mprog_prog()
58 bool id = flags & BPF_F_ID; in bpf_mprog_tuple_relative() local
67 if (!id && !id_or_fd) in bpf_mprog_tuple_relative()
74 if (tuple->link) in bpf_mprog_tuple_put()
75 bpf_link_put(tuple->link); in bpf_mprog_tuple_put()
76 else if (tuple->prog) in bpf_mprog_tuple_put()
77 bpf_prog_put(tuple->prog); in bpf_mprog_tuple_put()
82 * case of front idx is -1, in case of back idx is bpf_mprog_total(entry).
91 * before P1 would have old idx -1 and new idx 0.
93 * +--+--+--+ +--+--+--+--+ +--+--+--+--+
95 * +--+--+--+ +--+--+--+--+ +--+--+--+--+
104 * +--+--+--+ +--+--+--+--+ +--+--+--+--+
106 * +--+--+--+ +--+--+--+--+ +--+--+--+--+
117 oprog = READ_ONCE(fp->prog); in bpf_mprog_replace()
119 if (!ntuple->link) { in bpf_mprog_replace()
120 WARN_ON_ONCE(cp->link); in bpf_mprog_replace()
160 if (idx == -1) in bpf_mprog_delete()
163 idx = total - 1; in bpf_mprog_delete()
187 if (tuple->prog == READ_ONCE(fp->prog)) in bpf_mprog_pos_exact()
188 return tuple->link == cp->link ? i : -EBUSY; in bpf_mprog_pos_exact()
190 return -ENOENT; in bpf_mprog_pos_exact()
202 if (tuple->prog == READ_ONCE(fp->prog) && in bpf_mprog_pos_before()
203 (!tuple->link || tuple->link == cp->link)) in bpf_mprog_pos_before()
204 return i - 1; in bpf_mprog_pos_before()
206 return tuple->prog ? -ENOENT : -1; in bpf_mprog_pos_before()
218 if (tuple->prog == READ_ONCE(fp->prog) && in bpf_mprog_pos_after()
219 (!tuple->link || tuple->link == cp->link)) in bpf_mprog_pos_after()
222 return tuple->prog ? -ENOENT : bpf_mprog_total(entry); in bpf_mprog_pos_after()
229 u32 flags, u32 id_or_fd, u64 revision) in bpf_mprog_attach() argument
238 int ret, idx = -ERANGE, tidx; in bpf_mprog_attach()
240 if (revision && revision != bpf_mprog_revision(entry)) in bpf_mprog_attach()
241 return -ESTALE; in bpf_mprog_attach()
243 return -EEXIST; in bpf_mprog_attach()
246 prog_new->type); in bpf_mprog_attach()
257 ret = -ERANGE; in bpf_mprog_attach()
262 if (tidx < -1 || (idx >= -1 && tidx != idx)) { in bpf_mprog_attach()
263 ret = tidx < -1 ? tidx : -ERANGE; in bpf_mprog_attach()
270 if (tidx < -1 || (idx >= -1 && tidx != idx)) { in bpf_mprog_attach()
271 ret = tidx < 0 ? tidx : -ERANGE; in bpf_mprog_attach()
276 if (idx < -1) { in bpf_mprog_attach()
278 ret = -EINVAL; in bpf_mprog_attach()
285 ret = -ERANGE; in bpf_mprog_attach()
306 if (idx == -1) in bpf_mprog_fetch()
309 idx = total - 1; in bpf_mprog_fetch()
311 prog = READ_ONCE(fp->prog); in bpf_mprog_fetch()
312 link = cp->link; in bpf_mprog_fetch()
319 if (link && !tuple->link) in bpf_mprog_fetch()
320 return -EBUSY; in bpf_mprog_fetch()
321 WARN_ON_ONCE(tuple->prog && tuple->prog != prog); in bpf_mprog_fetch()
322 WARN_ON_ONCE(tuple->link && tuple->link != link); in bpf_mprog_fetch()
323 tuple->prog = prog; in bpf_mprog_fetch()
324 tuple->link = link; in bpf_mprog_fetch()
331 u32 flags, u32 id_or_fd, u64 revision) in bpf_mprog_detach() argument
337 int ret, idx = -ERANGE, tidx; in bpf_mprog_detach()
340 return -EINVAL; in bpf_mprog_detach()
341 if (revision && revision != bpf_mprog_revision(entry)) in bpf_mprog_detach()
342 return -ESTALE; in bpf_mprog_detach()
344 return -ENOENT; in bpf_mprog_detach()
346 prog ? prog->type : in bpf_mprog_detach()
360 if (tidx < -1 || (idx >= -1 && tidx != idx)) { in bpf_mprog_detach()
361 ret = tidx < -1 ? tidx : -ERANGE; in bpf_mprog_detach()
368 if (tidx < -1 || (idx >= -1 && tidx != idx)) { in bpf_mprog_detach()
369 ret = tidx < 0 ? tidx : -ERANGE; in bpf_mprog_detach()
374 if (idx < -1) { in bpf_mprog_detach()
376 ret = -EINVAL; in bpf_mprog_detach()
383 ret = -ERANGE; in bpf_mprog_detach()
404 u32 id, count = 0; in bpf_mprog_query() local
405 u64 revision = 1; in bpf_mprog_query() local
408 if (attr->query.query_flags || attr->query.attach_flags) in bpf_mprog_query()
409 return -EINVAL; in bpf_mprog_query()
411 revision = bpf_mprog_revision(entry); in bpf_mprog_query()
414 if (copy_to_user(&uattr->query.attach_flags, &flags, sizeof(flags))) in bpf_mprog_query()
415 return -EFAULT; in bpf_mprog_query()
416 if (copy_to_user(&uattr->query.revision, &revision, sizeof(revision))) in bpf_mprog_query()
417 return -EFAULT; in bpf_mprog_query()
418 if (copy_to_user(&uattr->query.count, &count, sizeof(count))) in bpf_mprog_query()
419 return -EFAULT; in bpf_mprog_query()
420 uprog_id = u64_to_user_ptr(attr->query.prog_ids); in bpf_mprog_query()
421 uprog_flags = u64_to_user_ptr(attr->query.prog_attach_flags); in bpf_mprog_query()
422 ulink_id = u64_to_user_ptr(attr->query.link_ids); in bpf_mprog_query()
423 ulink_flags = u64_to_user_ptr(attr->query.link_attach_flags); in bpf_mprog_query()
424 if (attr->query.count == 0 || !uprog_id || !count) in bpf_mprog_query()
426 if (attr->query.count < count) { in bpf_mprog_query()
427 count = attr->query.count; in bpf_mprog_query()
428 ret = -ENOSPC; in bpf_mprog_query()
432 prog = READ_ONCE(fp->prog); in bpf_mprog_query()
435 id = prog->aux->id; in bpf_mprog_query()
436 if (copy_to_user(uprog_id + i, &id, sizeof(id))) in bpf_mprog_query()
437 return -EFAULT; in bpf_mprog_query()
440 return -EFAULT; in bpf_mprog_query()
441 id = cp->link ? cp->link->id : 0; in bpf_mprog_query()
443 copy_to_user(ulink_id + i, &id, sizeof(id))) in bpf_mprog_query()
444 return -EFAULT; in bpf_mprog_query()
447 return -EFAULT; in bpf_mprog_query()