Skip to content

Commit 06be843

Browse files
committed
feat: add_counter ignored
1 parent 60ea0c0 commit 06be843

4 files changed

Lines changed: 52 additions & 4 deletions

File tree

include/linux/bpf_ir.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,8 @@ void bpr_ir_cg_to_cssa(struct bpf_ir_env *env, struct ir_function *fun,
12371237
int bpf_ir_init_opts(struct bpf_ir_env *env, const char *pass_opt,
12381238
const char *global_opt);
12391239

1240+
bool bpf_ir_builtin_pass_enabled(struct bpf_ir_env *env, const char *pass_name);
1241+
12401242
void bpf_ir_free_opts(struct bpf_ir_env *env);
12411243

12421244
/* Kern Utils End */

kernel/bpf/ir/kern_utils.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ static int apply_pass_opt(struct bpf_ir_env *env, const char *opt)
8787

8888
static int apply_global_opt(struct bpf_ir_env *env, const char *opt)
8989
{
90-
PRINT_DBG("global opt: %s\n", opt);
9190
if (strcmp(opt, "force") == 0) {
9291
env->opts.force = true;
9392
} else if (strcmp(opt, "enable_coalesce") == 0) {
@@ -128,6 +127,18 @@ static int apply_global_opt(struct bpf_ir_env *env, const char *opt)
128127
return 0;
129128
}
130129

130+
// Check if a builtin pass is enabled (by cfg)
131+
bool bpf_ir_builtin_pass_enabled(struct bpf_ir_env *env, const char *pass_name)
132+
{
133+
for (size_t i = 0; i < env->opts.builtin_pass_cfg_num; ++i) {
134+
if (strcmp(env->opts.builtin_pass_cfg[i].name, pass_name) ==
135+
0) {
136+
return env->opts.builtin_pass_cfg[i].enable_cfg;
137+
}
138+
}
139+
return false;
140+
}
141+
131142
/* Initialize pass configuration for kernel component
132143
*
133144
* @param env: bpf_ir_env, must be already initialized

kernel/bpf/ir_kern.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,24 @@ bool bpf_ir_canfix(struct bpf_ir_env *env)
2828
int err = env->verifier_err;
2929

3030
for (size_t i = 0; i < env->opts.custom_pass_num; ++i) {
31-
if (env->opts.custom_passes[i].check_apply && env->opts.custom_passes[i].check_apply(err)) {
31+
if (env->opts.custom_passes[i].check_apply &&
32+
env->opts.custom_passes[i].check_apply(err)) {
3233
return true;
3334
}
3435
}
3536
return false;
3637
}
3738

39+
// Enable all builtin passes specified by enable_cfg
40+
static void enable_builtin(struct bpf_ir_env *env)
41+
{
42+
for (size_t i = 0; i < env->opts.builtin_pass_cfg_num; ++i) {
43+
if (env->opts.builtin_pass_cfg[i].enable_cfg) {
44+
env->opts.builtin_pass_cfg[i].enable = true;
45+
}
46+
}
47+
}
48+
3849
int bpf_ir_kern_run(struct bpf_prog **prog_ptr, union bpf_attr *attr,
3950
bpfptr_t uattr, u32 uattr_size, const char *pass_opt,
4051
const char *global_opt)
@@ -81,7 +92,29 @@ int bpf_ir_kern_run(struct bpf_prog **prog_ptr, union bpf_attr *attr,
8192
goto clean_op;
8293
}
8394

84-
// Call the verifier
95+
// Remove line info, otherwise the verifier will complain about that they cannot find those lines
96+
// (Also you could remove debug flag when compile ebpf programs)
97+
// printk("LINEINFO %u, %u", attr->line_info_cnt,
98+
// attr->line_info_rec_size);
99+
attr->line_info_cnt = 0;
100+
101+
// Iteration
102+
103+
u32 iter = 0;
104+
105+
while (true) {
106+
iter++;
107+
if (iter >= env->opts.max_iteration) {
108+
err = -ELOOP;
109+
break;
110+
}
111+
}
112+
113+
if (err) {
114+
goto clean_op;
115+
}
116+
117+
// Run built-in passes
85118

86119
/*
87120
err = bpf_check(prog_ptr, attr, uattr, uattr_size, env);

kernel/bpf/verifier.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17961,8 +17961,10 @@ static int do_check(struct bpf_verifier_env *env)
1796117961

1796217962
insn = &insns[env->insn_idx];
1796317963
class = BPF_CLASS(insn->code);
17964+
++env->insn_processed;
1796417965

17965-
if (++env->insn_processed > BPF_COMPLEXITY_LIMIT_INSNS) {
17966+
if (env->insn_processed > BPF_COMPLEXITY_LIMIT_INSNS &&
17967+
!bpf_ir_builtin_pass_enabled(env->ir_env, "add_counter")) {
1796617968
verbose_err(
1796717969
363, env,
1796817970
"BPF program is too large. Processed %d insn\n",

0 commit comments

Comments
 (0)