Skip to content

Commit 4725477

Browse files
anakryikoborkmann
authored andcommitted
selftest/bpf: Fix profiler test using CO-RE relocation for enums
Instead of hard-coding invalid pids_cgrp_id, use Kconfig to detect the presence of that enum value and CO-RE to capture its actual value in the hosts's kernel. Fixes: 03d4d13 ("selftests/bpf: Add profiler test") Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Tested-by: Song Liu <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 435ccfa commit 4725477

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tools/testing/selftests/bpf/progs/profiler.inc.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ static ino_t get_inode_from_kernfs(struct kernfs_node* node)
243243
}
244244
}
245245

246-
int pids_cgrp_id = 1;
246+
extern bool CONFIG_CGROUP_PIDS __kconfig __weak;
247+
enum cgroup_subsys_id___local {
248+
pids_cgrp_id___local = 123, /* value doesn't matter */
249+
};
247250

248251
static INLINE void* populate_cgroup_info(struct cgroup_data_t* cgroup_data,
249252
struct task_struct* task,
@@ -253,7 +256,9 @@ static INLINE void* populate_cgroup_info(struct cgroup_data_t* cgroup_data,
253256
BPF_CORE_READ(task, nsproxy, cgroup_ns, root_cset, dfl_cgrp, kn);
254257
struct kernfs_node* proc_kernfs = BPF_CORE_READ(task, cgroups, dfl_cgrp, kn);
255258

256-
if (ENABLE_CGROUP_V1_RESOLVER) {
259+
if (ENABLE_CGROUP_V1_RESOLVER && CONFIG_CGROUP_PIDS) {
260+
int cgrp_id = bpf_core_enum_value(enum cgroup_subsys_id___local,
261+
pids_cgrp_id___local);
257262
#ifdef UNROLL
258263
#pragma unroll
259264
#endif
@@ -262,7 +267,7 @@ static INLINE void* populate_cgroup_info(struct cgroup_data_t* cgroup_data,
262267
BPF_CORE_READ(task, cgroups, subsys[i]);
263268
if (subsys != NULL) {
264269
int subsys_id = BPF_CORE_READ(subsys, ss, id);
265-
if (subsys_id == pids_cgrp_id) {
270+
if (subsys_id == cgrp_id) {
266271
proc_kernfs = BPF_CORE_READ(subsys, cgroup, kn);
267272
root_kernfs = BPF_CORE_READ(subsys, ss, root, kf_root, kn);
268273
break;

0 commit comments

Comments
 (0)