History

bpf: remove global variables

Move three global variables protected by bpf_verifier_lock into 'struct bpf_verifier_env' to allow parallel verification.

Alexei Starovoitov committed 7 years ago

Commit 7df737e1 parent 3b880242 files · +18 −12Browse files

Unified · Split

2 files
  1. include/linux/bpf_verifier.h +5 −0
  2. kernel/bpf/verifier.c +13 −12
include/linux/bpf_verifier.h+5−0
@@ -295,6 +295,11 @@ struct bpf_verifier_env { · 294 unmodified lines
295295 const struct bpf_line_info *prev_linfo;
296296 struct bpf_verifier_log log;
297297 struct bpf_subprog_info subprog_info[BPF_MAX_SUBPROGS + 1];
298+ struct {
299+ int *insn_state;
300+ int *insn_stack;
301+ int cur_stack;
302+ } cfg;
298303 u32 subprog_cnt;
299304 /* number of instructions analyzed by the verifier */
300305 u32 insn_processed;
kernel/bpf/verifier.c+13−12
@@ -5369,10 +5369,6 @@ enum { · 5368 unmodified lines
53695369
53705370 #define STATE_LIST_MARK ((struct bpf_verifier_state_list *) -1L)
53715371
5372−static int *insn_stack; /* stack of insns to process */
5373−static int cur_stack; /* current stack index */
5374−static int *insn_state;
5375−
53765372 /* t, w, e - match pseudo-code above:
53775373 * t - index of current instruction
53785374 * w - next instruction
@@ -5380,6 +5376,9 @@ static int *insn_state; · 1 unmodified line
53805376 */
53815377 static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)
53825378 {
5379+ int *insn_stack = env->cfg.insn_stack;
5380+ int *insn_state = env->cfg.insn_state;
5381+
53835382 if (e == FALLTHROUGH && insn_state[t] >= (DISCOVERED | FALLTHROUGH))
53845383 return 0;
53855384
@@ -5400,9 +5399,9 @@ static int push_insn(int t, int w, int e, struct bpf_verifier_env *env) · 14 unmodified lines
54005399 /* tree-edge */
54015400 insn_state[t] = DISCOVERED | e;
54025401 insn_state[w] = DISCOVERED;
5403− if (cur_stack >= env->prog->len)
5402+ if (env->cfg.cur_stack >= env->prog->len)
54045403 return -E2BIG;
5405− insn_stack[cur_stack++] = w;
5404+ insn_stack[env->cfg.cur_stack++] = w;
54065405 return 1;
54075406 } else if ((insn_state[w] & 0xF0) == DISCOVERED) {
54085407 verbose_linfo(env, t, "%d: ", t);
@@ -5426,14 +5425,15 @@ static int check_cfg(struct bpf_verifier_env *env) · 17 unmodified lines
54265425 {
54275426 struct bpf_insn *insns = env->prog->insnsi;
54285427 int insn_cnt = env->prog->len;
5428+ int *insn_stack, *insn_state;
54295429 int ret = 0;
54305430 int i, t;
54315431
5432− insn_state = kvcalloc(insn_cnt, sizeof(int), GFP_KERNEL);
5432+ insn_state = env->cfg.insn_state = kvcalloc(insn_cnt, sizeof(int), GFP_KERNEL);
54335433 if (!insn_state)
54345434 return -ENOMEM;
54355435
5436− insn_stack = kvcalloc(insn_cnt, sizeof(int), GFP_KERNEL);
5436+ insn_stack = env->cfg.insn_stack = kvcalloc(insn_cnt, sizeof(int), GFP_KERNEL);
54375437 if (!insn_stack) {
54385438 kvfree(insn_state);
54395439 return -ENOMEM;
@@ -5441,12 +5441,12 @@ static int check_cfg(struct bpf_verifier_env *env) · 1 unmodified line
54415441
54425442 insn_state[0] = DISCOVERED; /* mark 1st insn as discovered */
54435443 insn_stack[0] = 0; /* 0 is the first instruction */
5444− cur_stack = 1;
5444+ env->cfg.cur_stack = 1;
54455445
54465446 peek_stack:
5447− if (cur_stack == 0)
5447+ if (env->cfg.cur_stack == 0)
54485448 goto check_state;
5449− t = insn_stack[cur_stack - 1];
5449+ t = insn_stack[env->cfg.cur_stack - 1];
54505450
54515451 if (BPF_CLASS(insns[t].code) == BPF_JMP ||
54525452 BPF_CLASS(insns[t].code) == BPF_JMP32) {
@@ -5515,7 +5515,7 @@ peek_stack: · 62 unmodified lines
55155515
55165516 mark_explored:
55175517 insn_state[t] = EXPLORED;
5518− if (cur_stack-- <= 0) {
5518+ if (env->cfg.cur_stack-- <= 0) {
55195519 verbose(env, "pop stack internal bug\n");
55205520 ret = -EFAULT;
55215521 goto err_free;
@@ -5535,6 +5535,7 @@ check_state: · 13 unmodified lines
55355535 err_free:
55365536 kvfree(insn_state);
55375537 kvfree(insn_stack);
5538+ env->cfg.insn_state = env->cfg.insn_stack = NULL;
55385539 return ret;
55395540 }
55405541

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t