Skip to content

Commit e259427

Browse files
committed
nettrace: disable BPF program when necessary if btf_modules not supported
Signed-off-by: Menglong Dong <imagedong@tencent.com>
1 parent 911670b commit e259427

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

shared/bpf_utils.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,28 @@ exist:;
114114
return 0;
115115
}
116116

117-
int btf_get_arg_count(char *name)
117+
static struct btf *local_btf;
118+
const struct btf_type *btf_get_type(char *name)
118119
{
119-
struct btf *local_btf = btf__load_vmlinux_btf();
120120
const struct btf_type *t;
121121
int id;
122122

123123
if (!local_btf)
124-
return -ENOTSUP;
124+
local_btf= btf__load_vmlinux_btf();
125125

126126
id = btf__find_by_name(local_btf, name);
127127
if (id < 0)
128-
return -ENOENT;
128+
return NULL;
129129

130130
t = btf__type_by_id(local_btf, id);
131+
return t;
132+
}
133+
134+
int btf_get_arg_count(char *name)
135+
{
136+
const struct btf_type *t;
137+
138+
t = btf_get_type(name);
131139
if (!t)
132140
return -ENOENT;
133141

shared/bpf_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static inline int perf_output(int fd, perf_buffer_sample_fn fn)
6363
}
6464

6565
int compat_bpf_attach_kprobe(int fd, char *name, bool ret);
66+
const struct btf_type *btf_get_type(char *name);
6667
int btf_get_arg_count(char *name);
6768

6869
#endif

src/trace_tracing.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,15 @@ static void tracing_load_rules()
101101

102102
static void tracing_check_args()
103103
{
104-
bool support_feat_args_ext;
104+
bool support_feat_args_ext, support_btf_modules;
105105
trace_t *trace;
106106

107107
support_feat_args_ext = tracing_support_feat_args_ext();
108108
if (!support_feat_args_ext)
109109
pr_warn("tracing kernel function with 6+ arguments is not"
110-
"supportd by your kernel, following function is "
111-
"skipped:\n");
110+
"supportd by your kernel, following functions "
111+
"are skipped:\n");
112+
112113
trace_for_each(trace) {
113114
if (trace_is_invalid(trace) || !trace_is_enable(trace) ||
114115
!trace_is_func(trace))
@@ -119,6 +120,23 @@ static void tracing_check_args()
119120
trace_set_invalid(trace);
120121
}
121122
}
123+
124+
support_btf_modules = kernel_has_config("DEBUG_INFO_BTF_MODULES");
125+
if (!support_btf_modules)
126+
pr_warn("CONFIG_DEBUG_INFO_BTF_MODULES is not supported "
127+
"by your kernel, following functions are "
128+
"skipped:\n");
129+
130+
trace_for_each(trace) {
131+
if (trace_is_invalid(trace) || !trace_is_enable(trace) ||
132+
!trace_is_func(trace))
133+
continue;
134+
135+
if (!support_btf_modules && !btf_get_type(trace->name)) {
136+
pr_warn("\t%s\n", trace->name);
137+
trace_set_invalid(trace);
138+
}
139+
}
122140
}
123141

124142
static int tracing_trace_load()

0 commit comments

Comments
 (0)