~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/cgrp_kfunc_common.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
  3 
  4 #ifndef _CGRP_KFUNC_COMMON_H
  5 #define _CGRP_KFUNC_COMMON_H
  6 
  7 #include <errno.h>
  8 #include <vmlinux.h>
  9 #include <bpf/bpf_helpers.h>
 10 #include <bpf/bpf_tracing.h>
 11 
 12 struct __cgrps_kfunc_map_value {
 13         struct cgroup __kptr * cgrp;
 14 };
 15 
 16 struct {
 17         __uint(type, BPF_MAP_TYPE_HASH);
 18         __type(key, int);
 19         __type(value, struct __cgrps_kfunc_map_value);
 20         __uint(max_entries, 1);
 21 } __cgrps_kfunc_map SEC(".maps");
 22 
 23 struct cgroup *bpf_cgroup_acquire(struct cgroup *p) __ksym;
 24 void bpf_cgroup_release(struct cgroup *p) __ksym;
 25 struct cgroup *bpf_cgroup_ancestor(struct cgroup *cgrp, int level) __ksym;
 26 struct cgroup *bpf_cgroup_from_id(u64 cgid) __ksym;
 27 void bpf_rcu_read_lock(void) __ksym;
 28 void bpf_rcu_read_unlock(void) __ksym;
 29 
 30 static inline struct __cgrps_kfunc_map_value *cgrps_kfunc_map_value_lookup(struct cgroup *cgrp)
 31 {
 32         s32 id;
 33         long status;
 34 
 35         status = bpf_probe_read_kernel(&id, sizeof(id), &cgrp->self.id);
 36         if (status)
 37                 return NULL;
 38 
 39         return bpf_map_lookup_elem(&__cgrps_kfunc_map, &id);
 40 }
 41 
 42 static inline int cgrps_kfunc_map_insert(struct cgroup *cgrp)
 43 {
 44         struct __cgrps_kfunc_map_value local, *v;
 45         long status;
 46         struct cgroup *acquired, *old;
 47         s32 id;
 48 
 49         status = bpf_probe_read_kernel(&id, sizeof(id), &cgrp->self.id);
 50         if (status)
 51                 return status;
 52 
 53         local.cgrp = NULL;
 54         status = bpf_map_update_elem(&__cgrps_kfunc_map, &id, &local, BPF_NOEXIST);
 55         if (status)
 56                 return status;
 57 
 58         v = bpf_map_lookup_elem(&__cgrps_kfunc_map, &id);
 59         if (!v) {
 60                 bpf_map_delete_elem(&__cgrps_kfunc_map, &id);
 61                 return -ENOENT;
 62         }
 63 
 64         acquired = bpf_cgroup_acquire(cgrp);
 65         if (!acquired) {
 66                 bpf_map_delete_elem(&__cgrps_kfunc_map, &id);
 67                 return -ENOENT;
 68         }
 69 
 70         old = bpf_kptr_xchg(&v->cgrp, acquired);
 71         if (old) {
 72                 bpf_cgroup_release(old);
 73                 return -EEXIST;
 74         }
 75 
 76         return 0;
 77 }
 78 
 79 #endif /* _CGRP_KFUNC_COMMON_H */
 80 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php