netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann via iovisor-dev <iovisor-dev-9jONkmmOlFHEE9lA1F8Ukti2O/JbrIOy@public.gmane.org>
To: Edward Cree <ecree-s/n/eUQHGBpZroRs9YW3xA@public.gmane.org>,
	davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org,
	Alexei Starovoitov
	<alexei.starovoitov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Alexei Starovoitov <ast-b10kYP2dOMg@public.gmane.org>
Cc: netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	iovisor-dev
	<iovisor-dev-9jONkmmOlFHEE9lA1F8Ukti2O/JbrIOy@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v2 net-next] bpf/verifier: track liveness for pruning
Date: Tue, 15 Aug 2017 18:33:46 +0200	[thread overview]
Message-ID: <5993226A.9010704@iogearbox.net> (raw)
In-Reply-To: <3c245ef4-3161-0e5a-3708-6b9b47db01cd-s/n/eUQHGBpZroRs9YW3xA@public.gmane.org>

On 08/15/2017 03:53 PM, Edward Cree wrote:
> State of a register doesn't matter if it wasn't read in reaching an exit;
>   a write screens off all reads downstream of it from all explored_states
>   upstream of it.
> This allows us to prune many more branches; here are some processed insn
>   counts for some Cilium programs:
> Program                  before  after
> bpf_lb_opt_-DLB_L3.o       6515   3361
> bpf_lb_opt_-DLB_L4.o       8976   5176
> bpf_lb_opt_-DUNKNOWN.o     2960   1137
> bpf_lxc_opt_-DDROP_ALL.o  95412  48537
> bpf_lxc_opt_-DUNKNOWN.o  141706  78718
> bpf_netdev.o              24251  17995
> bpf_overlay.o             10999   9385
>
> The runtime is also improved; here are 'time' results in ms:
> Program                  before  after
> bpf_lb_opt_-DLB_L3.o         24      6
> bpf_lb_opt_-DLB_L4.o         26     11
> bpf_lb_opt_-DUNKNOWN.o       11      2
> bpf_lxc_opt_-DDROP_ALL.o   1288    139
> bpf_lxc_opt_-DUNKNOWN.o    1768    234
> bpf_netdev.o                 62     31
> bpf_overlay.o                15     13
>
> Signed-off-by: Edward Cree <ecree-s/n/eUQHGBpZroRs9YW3xA@public.gmane.org>
[...]
> @@ -1639,10 +1675,13 @@ static int check_call(struct bpf_verifier_env *env, int func_id, int insn_idx)
>   	}
>
>   	/* reset caller saved regs */
> -	for (i = 0; i < CALLER_SAVED_REGS; i++)
> +	for (i = 0; i < CALLER_SAVED_REGS; i++) {
>   		mark_reg_not_init(regs, caller_saved[i]);
> +		check_reg_arg(env, i, DST_OP_NO_MARK);

Ah, I oversaw that earlier, this needs to be: s/i/caller_saved[i]/

> +	}
>
>   	/* update return register */
> +	check_reg_arg(env, BPF_REG_0, DST_OP_NO_MARK);

We could leave this for clarity, but ...

>   	if (fn->ret_type == RET_INTEGER) {
>   		/* sets type to SCALAR_VALUE */
>   		mark_reg_unknown(regs, BPF_REG_0);
[...]
>
>   	/* reset caller saved regs to unreadable */
> -	for (i = 0; i < CALLER_SAVED_REGS; i++)
> +	for (i = 0; i < CALLER_SAVED_REGS; i++) {
>   		mark_reg_not_init(regs, caller_saved[i]);
> +		check_reg_arg(env, i, DST_OP_NO_MARK);

caller_saved[i]

> +	}
>
>   	/* mark destination R0 register as readable, since it contains
> -	 * the value fetched from the packet
> +	 * the value fetched from the packet.
> +	 * Already marked as written above.

... then it should be here as well. Other option is to leave out
both BPF_REG_0 since covered by caller_saved[] already.

>   	 */
>   	mark_reg_unknown(regs, BPF_REG_0);
>   	return 0;
> @@ -3194,7 +3236,11 @@ static bool regsafe(struct bpf_reg_state *rold,
>   		    struct bpf_reg_state *rcur,
>   		    bool varlen_map_access, struct idpair *idmap)
>   {
> -	if (memcmp(rold, rcur, sizeof(*rold)) == 0)
> +	if (!(rold->live & REG_LIVE_READ))
> +		/* explored state didn't use this */
> +		return true;

  parent reply	other threads:[~2017-08-15 16:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-15 13:53 [PATCH v2 net-next] bpf/verifier: track liveness for pruning Edward Cree
     [not found] ` <3c245ef4-3161-0e5a-3708-6b9b47db01cd-s/n/eUQHGBpZroRs9YW3xA@public.gmane.org>
2017-08-15 16:33   ` Daniel Borkmann via iovisor-dev [this message]
     [not found]     ` <5993226A.9010704-FeC+5ew28dpmcu3hnIyYJQ@public.gmane.org>
2017-08-15 18:06       ` Edward Cree via iovisor-dev

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=5993226A.9010704@iogearbox.net \
    --to=iovisor-dev-9jonkmmolfhee9la1f8ukti2o/jbrioy@public.gmane.org \
    --cc=alexei.starovoitov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=ast-b10kYP2dOMg@public.gmane.org \
    --cc=daniel-FeC+5ew28dpmcu3hnIyYJQ@public.gmane.org \
    --cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
    --cc=ecree-s/n/eUQHGBpZroRs9YW3xA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /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;
as well as URLs for NNTP newsgroup(s).