Skip to content

Commit c2a1d26

Browse files
zy84338719hao022
authored andcommitted
fix: revert cpu_runqlat_tracing to use task->state CO-RE check
task_struct___7_0 with preserve_access_index causes CO-RE relocation failure on older kernels (ubuntu20.04/kernel 5.15). The original bpf_core_field_exists(task->state) approach with task_struct___5_14 fallback works correctly on all kernel versions (4.18+). Fixes: bad CO-RE relocation: invalid func unknown#195896080 Signed-off-by: zhangyi <zy84338719@gmail.com>
1 parent 85e6aed commit c2a1d26

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

bpf/cpu_runqlat_tracing.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <bpf/bpf_tracing.h>
66

77
#include "bpf_common.h"
8-
#include "bpf_compat_7_0.h"
98

109
// defaultly, we use task_group address as key to operate map.
1110
#define TG_ADDR_KEY
@@ -124,14 +123,11 @@ long get_task_state(struct task_struct *task)
124123
if (task == NULL)
125124
return -1;
126125

127-
{
128-
struct task_struct___7_0 *task7 = (struct task_struct___7_0 *)task;
129-
if (bpf_core_field_exists(task7->__state)) {
130-
state = BPF_CORE_READ(task7, __state);
131-
} else {
132-
struct task_struct___5_14 *task_new = (struct task_struct___5_14 *)task;
133-
state = (long)BPF_CORE_READ(task_new, __state);
134-
}
126+
if (bpf_core_field_exists(task->state))
127+
state = BPF_CORE_READ(task, state);
128+
else {
129+
struct task_struct___5_14 *task_new = (struct task_struct___5_14 *)task;
130+
state = (long)BPF_CORE_READ(task_new, __state);
135131
}
136132

137133
return state;

0 commit comments

Comments
 (0)