aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2018-06-03 21:22:42 -0400
committerAlexei Starovoitov <ast@kernel.org>2018-06-03 21:22:42 -0400
commit432bdb581e410ad3cea8f04e9323397f17501e3e (patch)
tree74151563ca1a780f930b7537846123d165af5829
parentea9916ea3ed98d0a1f67f5cbe8ed8ae28e37f8c8 (diff)
parentf269099a7e7a0c6732c4a817d0e99e92216414d9 (diff)
Merge branch 'bpf_get_current_cgroup_id'
Yonghong Song says: ==================== bpf has been used extensively for tracing. For example, bcc contains an almost full set of bpf-based tools to trace kernel and user functions/events. Most tracing tools are currently either filtered based on pid or system-wide. Containers have been used quite extensively in industry and cgroup is often used together to provide resource isolation and protection. Several processes may run inside the same container. It is often desirable to get container-level tracing results as well, e.g. syscall count, function count, I/O activity, etc. This patch implements a new helper, bpf_get_current_cgroup_id(), which will return cgroup id based on the cgroup within which the current task is running. Patch #1 implements the new helper in the kernel. Patch #2 syncs the uapi bpf.h header and helper between tools and kernel. Patch #3 shows how to get the same cgroup id in user space, so a filter or policy could be configgured in the bpf program based on current task cgroup. Changelog: v1 -> v2: . rebase to resolve merge conflict with latest bpf-next. ==================== Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r--include/linux/bpf.h1
-rw-r--r--include/uapi/linux/bpf.h8
-rw-r--r--kernel/bpf/core.c1
-rw-r--r--kernel/bpf/helpers.c15
-rw-r--r--kernel/trace/bpf_trace.c2
-rw-r--r--tools/include/uapi/linux/bpf.h8
-rw-r--r--tools/testing/selftests/bpf/.gitignore1
-rw-r--r--tools/testing/selftests/bpf/Makefile6
-rw-r--r--tools/testing/selftests/bpf/bpf_helpers.h2
-rw-r--r--tools/testing/selftests/bpf/cgroup_helpers.c57
-rw-r--r--tools/testing/selftests/bpf/cgroup_helpers.h1
-rw-r--r--tools/testing/selftests/bpf/get_cgroup_id_kern.c28
-rw-r--r--tools/testing/selftests/bpf/get_cgroup_id_user.c141
13 files changed, 267 insertions, 4 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index bbe297436e5d..995c3b1e59bf 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -746,6 +746,7 @@ extern const struct bpf_func_proto bpf_get_stackid_proto;
746extern const struct bpf_func_proto bpf_get_stack_proto; 746extern const struct bpf_func_proto bpf_get_stack_proto;
747extern const struct bpf_func_proto bpf_sock_map_update_proto; 747extern const struct bpf_func_proto bpf_sock_map_update_proto;
748extern const struct bpf_func_proto bpf_sock_hash_update_proto; 748extern const struct bpf_func_proto bpf_sock_hash_update_proto;
749extern const struct bpf_func_proto bpf_get_current_cgroup_id_proto;
749 750
750/* Shared helpers among cBPF and eBPF. */ 751/* Shared helpers among cBPF and eBPF. */
751void bpf_user_rnd_init_once(void); 752void bpf_user_rnd_init_once(void);
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index f0b6608b1f1c..18712b0dbfe7 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -2070,6 +2070,11 @@ union bpf_attr {
2070 * **CONFIG_SOCK_CGROUP_DATA** configuration option. 2070 * **CONFIG_SOCK_CGROUP_DATA** configuration option.
2071 * Return 2071 * Return
2072 * The id is returned or 0 in case the id could not be retrieved. 2072 * The id is returned or 0 in case the id could not be retrieved.
2073 *
2074 * u64 bpf_get_current_cgroup_id(void)
2075 * Return
2076 * A 64-bit integer containing the current cgroup id based
2077 * on the cgroup within which the current task is running.
2073 */ 2078 */
2074#define __BPF_FUNC_MAPPER(FN) \ 2079#define __BPF_FUNC_MAPPER(FN) \
2075 FN(unspec), \ 2080 FN(unspec), \
@@ -2151,7 +2156,8 @@ union bpf_attr {
2151 FN(lwt_seg6_action), \ 2156 FN(lwt_seg6_action), \
2152 FN(rc_repeat), \ 2157 FN(rc_repeat), \
2153 FN(rc_keydown), \ 2158 FN(rc_keydown), \
2154 FN(skb_cgroup_id), 2159 FN(skb_cgroup_id), \
2160 FN(get_current_cgroup_id),
2155 2161
2156/* integer value in 'imm' field of BPF_CALL instruction selects which helper 2162/* integer value in 'imm' field of BPF_CALL instruction selects which helper
2157 * function eBPF program intends to call 2163 * function eBPF program intends to call
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 527587de8a67..9f1493705f40 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1765,6 +1765,7 @@ const struct bpf_func_proto bpf_get_current_uid_gid_proto __weak;
1765const struct bpf_func_proto bpf_get_current_comm_proto __weak; 1765const struct bpf_func_proto bpf_get_current_comm_proto __weak;
1766const struct bpf_func_proto bpf_sock_map_update_proto __weak; 1766const struct bpf_func_proto bpf_sock_map_update_proto __weak;
1767const struct bpf_func_proto bpf_sock_hash_update_proto __weak; 1767const struct bpf_func_proto bpf_sock_hash_update_proto __weak;
1768const struct bpf_func_proto bpf_get_current_cgroup_id_proto __weak;
1768 1769
1769const struct bpf_func_proto * __weak bpf_get_trace_printk_proto(void) 1770const struct bpf_func_proto * __weak bpf_get_trace_printk_proto(void)
1770{ 1771{
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index 3d24e238221e..73065e2d23c2 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -179,3 +179,18 @@ const struct bpf_func_proto bpf_get_current_comm_proto = {
179 .arg1_type = ARG_PTR_TO_UNINIT_MEM, 179 .arg1_type = ARG_PTR_TO_UNINIT_MEM,
180 .arg2_type = ARG_CONST_SIZE, 180 .arg2_type = ARG_CONST_SIZE,
181}; 181};
182
183#ifdef CONFIG_CGROUPS
184BPF_CALL_0(bpf_get_current_cgroup_id)
185{
186 struct cgroup *cgrp = task_dfl_cgroup(current);
187
188 return cgrp->kn->id.id;
189}
190
191const struct bpf_func_proto bpf_get_current_cgroup_id_proto = {
192 .func = bpf_get_current_cgroup_id,
193 .gpl_only = false,
194 .ret_type = RET_INTEGER,
195};
196#endif
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 752992ce3513..e2ab5b7f29d2 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -564,6 +564,8 @@ tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
564 return &bpf_get_prandom_u32_proto; 564 return &bpf_get_prandom_u32_proto;
565 case BPF_FUNC_probe_read_str: 565 case BPF_FUNC_probe_read_str:
566 return &bpf_probe_read_str_proto; 566 return &bpf_probe_read_str_proto;
567 case BPF_FUNC_get_current_cgroup_id:
568 return &bpf_get_current_cgroup_id_proto;
567 default: 569 default:
568 return NULL; 570 return NULL;
569 } 571 }
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index f0b6608b1f1c..18712b0dbfe7 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -2070,6 +2070,11 @@ union bpf_attr {
2070 * **CONFIG_SOCK_CGROUP_DATA** configuration option. 2070 * **CONFIG_SOCK_CGROUP_DATA** configuration option.
2071 * Return 2071 * Return
2072 * The id is returned or 0 in case the id could not be retrieved. 2072 * The id is returned or 0 in case the id could not be retrieved.
2073 *
2074 * u64 bpf_get_current_cgroup_id(void)
2075 * Return
2076 * A 64-bit integer containing the current cgroup id based
2077 * on the cgroup within which the current task is running.
2073 */ 2078 */
2074#define __BPF_FUNC_MAPPER(FN) \ 2079#define __BPF_FUNC_MAPPER(FN) \
2075 FN(unspec), \ 2080 FN(unspec), \
@@ -2151,7 +2156,8 @@ union bpf_attr {
2151 FN(lwt_seg6_action), \ 2156 FN(lwt_seg6_action), \
2152 FN(rc_repeat), \ 2157 FN(rc_repeat), \
2153 FN(rc_keydown), \ 2158 FN(rc_keydown), \
2154 FN(skb_cgroup_id), 2159 FN(skb_cgroup_id), \
2160 FN(get_current_cgroup_id),
2155 2161
2156/* integer value in 'imm' field of BPF_CALL instruction selects which helper 2162/* integer value in 'imm' field of BPF_CALL instruction selects which helper
2157 * function eBPF program intends to call 2163 * function eBPF program intends to call
diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore
index 6ea835982464..49938d72cf63 100644
--- a/tools/testing/selftests/bpf/.gitignore
+++ b/tools/testing/selftests/bpf/.gitignore
@@ -18,3 +18,4 @@ urandom_read
18test_btf 18test_btf
19test_sockmap 19test_sockmap
20test_lirc_mode2_user 20test_lirc_mode2_user
21get_cgroup_id_user
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 553d1816b77a..607ed8729c06 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -24,7 +24,7 @@ urandom_read: urandom_read.c
24# Order correspond to 'make run_tests' order 24# Order correspond to 'make run_tests' order
25TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ 25TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
26 test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \ 26 test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \
27 test_sock test_btf test_sockmap test_lirc_mode2_user 27 test_sock test_btf test_sockmap test_lirc_mode2_user get_cgroup_id_user
28 28
29TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \ 29TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \
30 test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \ 30 test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \
@@ -34,7 +34,8 @@ TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test
34 sockmap_tcp_msg_prog.o connect4_prog.o connect6_prog.o test_adjust_tail.o \ 34 sockmap_tcp_msg_prog.o connect4_prog.o connect6_prog.o test_adjust_tail.o \
35 test_btf_haskv.o test_btf_nokv.o test_sockmap_kern.o test_tunnel_kern.o \ 35 test_btf_haskv.o test_btf_nokv.o test_sockmap_kern.o test_tunnel_kern.o \
36 test_get_stack_rawtp.o test_sockmap_kern.o test_sockhash_kern.o \ 36 test_get_stack_rawtp.o test_sockmap_kern.o test_sockhash_kern.o \
37 test_lwt_seg6local.o sendmsg4_prog.o sendmsg6_prog.o test_lirc_mode2_kern.o 37 test_lwt_seg6local.o sendmsg4_prog.o sendmsg6_prog.o test_lirc_mode2_kern.o \
38 get_cgroup_id_kern.o
38 39
39# Order correspond to 'make run_tests' order 40# Order correspond to 'make run_tests' order
40TEST_PROGS := test_kmod.sh \ 41TEST_PROGS := test_kmod.sh \
@@ -63,6 +64,7 @@ $(OUTPUT)/test_sock: cgroup_helpers.c
63$(OUTPUT)/test_sock_addr: cgroup_helpers.c 64$(OUTPUT)/test_sock_addr: cgroup_helpers.c
64$(OUTPUT)/test_sockmap: cgroup_helpers.c 65$(OUTPUT)/test_sockmap: cgroup_helpers.c
65$(OUTPUT)/test_progs: trace_helpers.c 66$(OUTPUT)/test_progs: trace_helpers.c
67$(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c
66 68
67.PHONY: force 69.PHONY: force
68 70
diff --git a/tools/testing/selftests/bpf/bpf_helpers.h b/tools/testing/selftests/bpf/bpf_helpers.h
index a66a9d91acf4..f2f28b6c8915 100644
--- a/tools/testing/selftests/bpf/bpf_helpers.h
+++ b/tools/testing/selftests/bpf/bpf_helpers.h
@@ -131,6 +131,8 @@ static int (*bpf_rc_repeat)(void *ctx) =
131static int (*bpf_rc_keydown)(void *ctx, unsigned int protocol, 131static int (*bpf_rc_keydown)(void *ctx, unsigned int protocol,
132 unsigned long long scancode, unsigned int toggle) = 132 unsigned long long scancode, unsigned int toggle) =
133 (void *) BPF_FUNC_rc_keydown; 133 (void *) BPF_FUNC_rc_keydown;
134static unsigned long long (*bpf_get_current_cgroup_id)(void) =
135 (void *) BPF_FUNC_get_current_cgroup_id;
134 136
135/* llvm builtin functions that eBPF C program may use to 137/* llvm builtin functions that eBPF C program may use to
136 * emit BPF_LD_ABS and BPF_LD_IND instructions 138 * emit BPF_LD_ABS and BPF_LD_IND instructions
diff --git a/tools/testing/selftests/bpf/cgroup_helpers.c b/tools/testing/selftests/bpf/cgroup_helpers.c
index f3bca3ade0f3..c87b4e052ce9 100644
--- a/tools/testing/selftests/bpf/cgroup_helpers.c
+++ b/tools/testing/selftests/bpf/cgroup_helpers.c
@@ -6,6 +6,7 @@
6#include <sys/types.h> 6#include <sys/types.h>
7#include <linux/limits.h> 7#include <linux/limits.h>
8#include <stdio.h> 8#include <stdio.h>
9#include <stdlib.h>
9#include <linux/sched.h> 10#include <linux/sched.h>
10#include <fcntl.h> 11#include <fcntl.h>
11#include <unistd.h> 12#include <unistd.h>
@@ -176,3 +177,59 @@ int create_and_get_cgroup(char *path)
176 177
177 return fd; 178 return fd;
178} 179}
180
181/**
182 * get_cgroup_id() - Get cgroup id for a particular cgroup path
183 * @path: The cgroup path, relative to the workdir, to join
184 *
185 * On success, it returns the cgroup id. On failure it returns 0,
186 * which is an invalid cgroup id.
187 * If there is a failure, it prints the error to stderr.
188 */
189unsigned long long get_cgroup_id(char *path)
190{
191 int dirfd, err, flags, mount_id, fhsize;
192 union {
193 unsigned long long cgid;
194 unsigned char raw_bytes[8];
195 } id;
196 char cgroup_workdir[PATH_MAX + 1];
197 struct file_handle *fhp, *fhp2;
198 unsigned long long ret = 0;
199
200 format_cgroup_path(cgroup_workdir, path);
201
202 dirfd = AT_FDCWD;
203 flags = 0;
204 fhsize = sizeof(*fhp);
205 fhp = calloc(1, fhsize);
206 if (!fhp) {
207 log_err("calloc");
208 return 0;
209 }
210 err = name_to_handle_at(dirfd, cgroup_workdir, fhp, &mount_id, flags);
211 if (err >= 0 || fhp->handle_bytes != 8) {
212 log_err("name_to_handle_at");
213 goto free_mem;
214 }
215
216 fhsize = sizeof(struct file_handle) + fhp->handle_bytes;
217 fhp2 = realloc(fhp, fhsize);
218 if (!fhp2) {
219 log_err("realloc");
220 goto free_mem;
221 }
222 err = name_to_handle_at(dirfd, cgroup_workdir, fhp2, &mount_id, flags);
223 fhp = fhp2;
224 if (err < 0) {
225 log_err("name_to_handle_at");
226 goto free_mem;
227 }
228
229 memcpy(id.raw_bytes, fhp->f_handle, 8);
230 ret = id.cgid;
231
232free_mem:
233 free(fhp);
234 return ret;
235}
diff --git a/tools/testing/selftests/bpf/cgroup_helpers.h b/tools/testing/selftests/bpf/cgroup_helpers.h
index 06485e0002b3..20a4a5dcd469 100644
--- a/tools/testing/selftests/bpf/cgroup_helpers.h
+++ b/tools/testing/selftests/bpf/cgroup_helpers.h
@@ -13,5 +13,6 @@ int create_and_get_cgroup(char *path);
13int join_cgroup(char *path); 13int join_cgroup(char *path);
14int setup_cgroup_environment(void); 14int setup_cgroup_environment(void);
15void cleanup_cgroup_environment(void); 15void cleanup_cgroup_environment(void);
16unsigned long long get_cgroup_id(char *path);
16 17
17#endif 18#endif
diff --git a/tools/testing/selftests/bpf/get_cgroup_id_kern.c b/tools/testing/selftests/bpf/get_cgroup_id_kern.c
new file mode 100644
index 000000000000..2cf8cb23f209
--- /dev/null
+++ b/tools/testing/selftests/bpf/get_cgroup_id_kern.c
@@ -0,0 +1,28 @@
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (c) 2018 Facebook
3
4#include <linux/bpf.h>
5#include "bpf_helpers.h"
6
7struct bpf_map_def SEC("maps") cg_ids = {
8 .type = BPF_MAP_TYPE_ARRAY,
9 .key_size = sizeof(__u32),
10 .value_size = sizeof(__u64),
11 .max_entries = 1,
12};
13
14SEC("tracepoint/syscalls/sys_enter_nanosleep")
15int trace(void *ctx)
16{
17 __u32 key = 0;
18 __u64 *val;
19
20 val = bpf_map_lookup_elem(&cg_ids, &key);
21 if (val)
22 *val = bpf_get_current_cgroup_id();
23
24 return 0;
25}
26
27char _license[] SEC("license") = "GPL";
28__u32 _version SEC("version") = 1; /* ignored by tracepoints, required by libbpf.a */
diff --git a/tools/testing/selftests/bpf/get_cgroup_id_user.c b/tools/testing/selftests/bpf/get_cgroup_id_user.c
new file mode 100644
index 000000000000..ea19a42e5894
--- /dev/null
+++ b/tools/testing/selftests/bpf/get_cgroup_id_user.c
@@ -0,0 +1,141 @@
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (c) 2018 Facebook
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <errno.h>
8#include <fcntl.h>
9#include <syscall.h>
10#include <unistd.h>
11#include <linux/perf_event.h>
12#include <sys/ioctl.h>
13#include <sys/time.h>
14#include <sys/types.h>
15#include <sys/stat.h>
16
17#include <linux/bpf.h>
18#include <bpf/bpf.h>
19#include <bpf/libbpf.h>
20
21#include "cgroup_helpers.h"
22#include "bpf_rlimit.h"
23
24#define CHECK(condition, tag, format...) ({ \
25 int __ret = !!(condition); \
26 if (__ret) { \
27 printf("%s:FAIL:%s ", __func__, tag); \
28 printf(format); \
29 } else { \
30 printf("%s:PASS:%s\n", __func__, tag); \
31 } \
32 __ret; \
33})
34
35static int bpf_find_map(const char *test, struct bpf_object *obj,
36 const char *name)
37{
38 struct bpf_map *map;
39
40 map = bpf_object__find_map_by_name(obj, name);
41 if (!map)
42 return -1;
43 return bpf_map__fd(map);
44}
45
46#define TEST_CGROUP "/test-bpf-get-cgroup-id/"
47
48int main(int argc, char **argv)
49{
50 const char *probe_name = "syscalls/sys_enter_nanosleep";
51 const char *file = "get_cgroup_id_kern.o";
52 int err, bytes, efd, prog_fd, pmu_fd;
53 struct perf_event_attr attr = {};
54 int cgroup_fd, cgidmap_fd;
55 struct bpf_object *obj;
56 __u64 kcgid = 0, ucgid;
57 int exit_code = 1;
58 char buf[256];
59 __u32 key = 0;
60
61 err = setup_cgroup_environment();
62 if (CHECK(err, "setup_cgroup_environment", "err %d errno %d\n", err,
63 errno))
64 return 1;
65
66 cgroup_fd = create_and_get_cgroup(TEST_CGROUP);
67 if (CHECK(cgroup_fd < 0, "create_and_get_cgroup", "err %d errno %d\n",
68 cgroup_fd, errno))
69 goto cleanup_cgroup_env;
70
71 err = join_cgroup(TEST_CGROUP);
72 if (CHECK(err, "join_cgroup", "err %d errno %d\n", err, errno))
73 goto cleanup_cgroup_env;
74
75 err = bpf_prog_load(file, BPF_PROG_TYPE_TRACEPOINT, &obj, &prog_fd);
76 if (CHECK(err, "bpf_prog_load", "err %d errno %d\n", err, errno))
77 goto cleanup_cgroup_env;
78
79 cgidmap_fd = bpf_find_map(__func__, obj, "cg_ids");
80 if (CHECK(cgidmap_fd < 0, "bpf_find_map", "err %d errno %d\n",
81 cgidmap_fd, errno))
82 goto close_prog;
83
84 snprintf(buf, sizeof(buf),
85 "/sys/kernel/debug/tracing/events/%s/id", probe_name);
86 efd = open(buf, O_RDONLY, 0);
87 if (CHECK(efd < 0, "open", "err %d errno %d\n", efd, errno))
88 goto close_prog;
89 bytes = read(efd, buf, sizeof(buf));
90 close(efd);
91 if (CHECK(bytes <= 0 || bytes >= sizeof(buf), "read",
92 "bytes %d errno %d\n", bytes, errno))
93 goto close_prog;
94
95 attr.config = strtol(buf, NULL, 0);
96 attr.type = PERF_TYPE_TRACEPOINT;
97 attr.sample_type = PERF_SAMPLE_RAW;
98 attr.sample_period = 1;
99 attr.wakeup_events = 1;
100
101 /* attach to this pid so the all bpf invocations will be in the
102 * cgroup associated with this pid.
103 */
104 pmu_fd = syscall(__NR_perf_event_open, &attr, getpid(), -1, -1, 0);
105 if (CHECK(pmu_fd < 0, "perf_event_open", "err %d errno %d\n", pmu_fd,
106 errno))
107 goto close_prog;
108
109 err = ioctl(pmu_fd, PERF_EVENT_IOC_ENABLE, 0);
110 if (CHECK(err, "perf_event_ioc_enable", "err %d errno %d\n", err,
111 errno))
112 goto close_pmu;
113
114 err = ioctl(pmu_fd, PERF_EVENT_IOC_SET_BPF, prog_fd);
115 if (CHECK(err, "perf_event_ioc_set_bpf", "err %d errno %d\n", err,
116 errno))
117 goto close_pmu;
118
119 /* trigger some syscalls */
120 sleep(1);
121
122 err = bpf_map_lookup_elem(cgidmap_fd, &key, &kcgid);
123 if (CHECK(err, "bpf_map_lookup_elem", "err %d errno %d\n", err, errno))
124 goto close_pmu;
125
126 ucgid = get_cgroup_id(TEST_CGROUP);
127 if (CHECK(kcgid != ucgid, "compare_cgroup_id",
128 "kern cgid %llx user cgid %llx", kcgid, ucgid))
129 goto close_pmu;
130
131 exit_code = 0;
132 printf("%s:PASS\n", argv[0]);
133
134close_pmu:
135 close(pmu_fd);
136close_prog:
137 bpf_object__close(obj);
138cleanup_cgroup_env:
139 cleanup_cgroup_environment();
140 return exit_code;
141}