From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Jiong Wang <jiong.wang@netronome.com>
Cc: daniel@iogearbox.net, bpf@vger.kernel.org,
netdev@vger.kernel.org, oss-drivers@netronome.com
Subject: Re: [PATCH/RFC bpf-next 02/16] bpf: refactor propagate_live implementation
Date: Wed, 27 Mar 2019 09:35:05 -0700 [thread overview]
Message-ID: <20190327163504.7ueecpetrwohkbmd@ast-mbp> (raw)
In-Reply-To: <1553623539-15474-3-git-send-email-jiong.wang@netronome.com>
On Tue, Mar 26, 2019 at 06:05:25PM +0000, Jiong Wang wrote:
> Some code inside current implementation of "propagate_liveness" is a little
> bit verbose.
>
> This patch refactor them so the code looks more simple and more clear.
>
> The redundant usage of "vparent->frame[vstate->curframe]" is removed as we
> are here. It is safe to do this because "state_equal" has guaranteed that
> vstate->curframe must be equal with vparent->curframe.
>
> Signed-off-by: Jiong Wang <jiong.wang@netronome.com>
> ---
> kernel/bpf/verifier.c | 44 ++++++++++++++++++++++++++++++--------------
> 1 file changed, 30 insertions(+), 14 deletions(-)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 6cc8c38..245bb3c 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -6050,6 +6050,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, u8 flag)
> +{
> + int err;
> +
> + if (parent_reg->live & flag || !(reg->live & flag))
> + return 0;
> +
> + err = mark_reg_read(env, reg, parent_reg);
> + if (err)
> + return err;
> +
> + return 1;
> +}
what is the difference between 1 and 0 ? it doesn't seem to be used.
> +
> /* 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
> @@ -6061,8 +6077,9 @@ static int propagate_liveness(struct bpf_verifier_env *env,
> const struct bpf_verifier_state *vstate,
> struct bpf_verifier_state *vparent)
> {
> - int i, frame, err = 0;
> + struct bpf_reg_state *regs, *parent_regs;
> struct bpf_func_state *state, *parent;
> + int i, frame, err = 0;
>
> if (vparent->curframe != vstate->curframe) {
> WARN(1, "propagate_live: parent frame %d current frame %d\n",
> @@ -6071,16 +6088,13 @@ static int propagate_liveness(struct bpf_verifier_env *env,
> }
> /* Propagate read liveness of registers... */
> BUILD_BUG_ON(BPF_REG_FP + 1 != MAX_BPF_REG);
> + parent_regs = vparent->frame[vparent->curframe]->regs;
> + regs = vstate->frame[vstate->curframe]->regs;
may be do:
frame = vstate->curframe;
if (vparent->curframe != frame) { WARN...
parent_regs = vparent->frame[frame]->regs;
regs = vstate->frame[frame]->regs;
?
> /* We don't need to worry about FP liveness because it's read-only */
> for (i = 0; i < BPF_REG_FP; i++) {
> - if (vparent->frame[vparent->curframe]->regs[i].live & REG_LIVE_READ)
> - continue;
> - if (vstate->frame[vstate->curframe]->regs[i].live & REG_LIVE_READ) {
> - err = mark_reg_read(env, &vstate->frame[vstate->curframe]->regs[i],
> - &vparent->frame[vstate->curframe]->regs[i]);
> - if (err)
> - return err;
> - }
> + err = propagate_liveness_reg(env, ®s[i], &parent_regs[i]);
> + if (err < 0)
> + return err;
> }
>
> /* ... and stack slots */
> @@ -6089,11 +6103,13 @@ static int propagate_liveness(struct bpf_verifier_env *env,
> parent = vparent->frame[frame];
> for (i = 0; i < state->allocated_stack / BPF_REG_SIZE &&
> i < parent->allocated_stack / BPF_REG_SIZE; i++) {
> - if (parent->stack[i].spilled_ptr.live & REG_LIVE_READ)
> - continue;
> - if (state->stack[i].spilled_ptr.live & REG_LIVE_READ)
> - mark_reg_read(env, &state->stack[i].spilled_ptr,
> - &parent->stack[i].spilled_ptr);
> + struct bpf_reg_state *parent_reg, *reg;
> +
> + parent_reg = &parent->stack[i].spilled_ptr;
> + reg = &state->stack[i].spilled_ptr;
> + err = propagate_liveness_reg(env, reg, parent_reg);
> + if (err < 0)
> + return err;
> }
> }
> return err;
> --
> 2.7.4
>
next prev parent reply other threads:[~2019-03-27 16:35 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-26 18:05 [PATCH/RFC bpf-next 00/16] bpf: eliminate zero extensions for sub-register writes Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 01/16] bpf: turn "enum bpf_reg_liveness" into bit representation Jiong Wang
2019-03-27 15:44 ` Alexei Starovoitov
2019-03-26 18:05 ` [PATCH/RFC bpf-next 02/16] bpf: refactor propagate_live implementation Jiong Wang
2019-03-26 18:26 ` Jann Horn
2019-03-26 19:45 ` Jiong Wang
2019-03-27 16:35 ` Alexei Starovoitov [this message]
2019-03-27 16:44 ` Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 03/16] bpf: split read liveness into REG_LIVE_READ64 and REG_LIVE_READ32 Jiong Wang
2019-03-26 20:21 ` Jann Horn
2019-03-26 20:50 ` Jiong Wang
2019-03-27 16:38 ` Alexei Starovoitov
2019-03-26 18:05 ` [PATCH/RFC bpf-next 04/16] bpf: mark sub-register writes that really need zero extension to high bits Jiong Wang
2019-03-26 18:44 ` Edward Cree
2019-03-26 19:47 ` Jiong Wang
2019-04-05 20:44 ` Jiong Wang
2019-04-06 3:41 ` Alexei Starovoitov
2019-04-06 6:56 ` Jiong Wang
2019-04-07 2:51 ` Alexei Starovoitov
2019-03-27 16:50 ` Alexei Starovoitov
2019-03-27 17:06 ` Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 05/16] bpf: reduce false alarm by refining "enum bpf_arg_type" Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 06/16] bpf: new sysctl "bpf_jit_32bit_opt" Jiong Wang
2019-03-27 17:00 ` Alexei Starovoitov
2019-03-27 17:06 ` Jiong Wang
2019-03-27 17:17 ` Alexei Starovoitov
2019-03-27 17:18 ` Jiong Wang
2019-03-27 17:45 ` Alexei Starovoitov
2019-03-27 19:13 ` Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 07/16] bpf: insert explicit zero extension instructions when bpf_jit_32bit_opt is true Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 08/16] arm: bpf: eliminate zero extension code-gen Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 09/16] powerpc: " Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 10/16] s390: " Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 11/16] sparc: " Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 12/16] x32: " Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 13/16] riscv: " Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 14/16] nfp: " Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 15/16] selftests: bpf: new field "xlated_insns" for insn scan test after verification Jiong Wang
2019-03-26 18:05 ` [PATCH/RFC bpf-next 16/16] selftests: bpf: unit testcases for zero extension insertion pass Jiong Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190327163504.7ueecpetrwohkbmd@ast-mbp \
--to=alexei.starovoitov@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jiong.wang@netronome.com \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@netronome.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox