summaryrefslogtreecommitdiffstats
path: root/kernel/bpf/verifier.c
diff options
context:
space:
mode:
authorJiong Wang <jiong.wang@netronome.com>2019-04-12 23:59:36 +0200
committerAlexei Starovoitov <ast@kernel.org>2019-04-13 02:06:33 +0200
commit55e7f3b5ac94a8c9f2e35961a45e9aa526a9e41d (patch)
treee9cd98b8ca3044e8783ac98db6525b651e4a5192 /kernel/bpf/verifier.c
parentbpf: refactor propagate_liveness to eliminate code redundance (diff)
downloadlinux-55e7f3b5ac94a8c9f2e35961a45e9aa526a9e41d.tar.xz
linux-55e7f3b5ac94a8c9f2e35961a45e9aa526a9e41d.zip
bpf: factor out reg and stack slot propagation into "propagate_liveness_reg"
After code refactor in previous patches, the propagation logic inside the for loop in "propagate_liveness" becomes clear that they are good enough to be factored out into a common function "propagate_liveness_reg". Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Jiong Wang <jiong.wang@netronome.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to '')
-rw-r--r--kernel/bpf/verifier.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 6fd36a8ba1a0..3fdb301c4f8c 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -6221,6 +6221,22 @@ static bool states_equal(struct bpf_verifier_env *env,
return true;
}
+static int propagate_liveness_reg(struct bpf_verifier_env *env,
+ struct bpf_reg_state *reg,
+ struct bpf_reg_state *parent_reg)
+{
+ int err;
+
+ if (parent_reg->live & REG_LIVE_READ || !(reg->live & REG_LIVE_READ))
+ return 0;
+
+ err = mark_reg_read(env, reg, parent_reg);
+ if (err)
+ return err;
+
+ return 0;
+}
+
/* A write screens off any subsequent reads; but write marks come from the
* straight-line code between a state and its parent. When we arrive at an
* equivalent state (jump target or such) we didn't arrive by the straight-line
@@ -6250,11 +6266,8 @@ static int propagate_liveness(struct bpf_verifier_env *env,
state_reg = state->regs;
/* We don't need to worry about FP liveness, it's read-only */
for (i = frame < vstate->curframe ? BPF_REG_6 : 0; i < BPF_REG_FP; i++) {
- if (parent_reg[i].live & REG_LIVE_READ)
- continue;
- if (!(state_reg[i].live & REG_LIVE_READ))
- continue;
- err = mark_reg_read(env, &state_reg[i], &parent_reg[i]);
+ err = propagate_liveness_reg(env, &state_reg[i],
+ &parent_reg[i]);
if (err)
return err;
}
@@ -6264,11 +6277,8 @@ static int propagate_liveness(struct bpf_verifier_env *env,
i < parent->allocated_stack / BPF_REG_SIZE; i++) {
parent_reg = &parent->stack[i].spilled_ptr;
state_reg = &state->stack[i].spilled_ptr;
- if (parent_reg->live & REG_LIVE_READ)
- continue;
- if (!(state_reg->live & REG_LIVE_READ))
- continue;
- err = mark_reg_read(env, state_reg, parent_reg);
+ err = propagate_liveness_reg(env, state_reg,
+ parent_reg);
if (err)
return err;
}