netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiong Wang <jiong.wang@netronome.com>
To: Jakub Kicinski <jakub.kicinski@netronome.com>
Cc: Jiong Wang <jiong.wang@netronome.com>,
	ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org,
	oss-drivers@netronome.com
Subject: Re: [PATH bpf-next 11/13] bpf: verifier support JMP32
Date: Tue, 08 Jan 2019 15:23:15 +0000	[thread overview]
Message-ID: <874lajp40s.fsf@netronome.com> (raw)
In-Reply-To: <20181219155406.36d1bcb5@cakuba.netronome.com>


Jakub Kicinski writes:

> On Wed, 19 Dec 2018 17:44:18 -0500, Jiong Wang wrote:
>> Verifier is doing some runtime optimizations based on the extra info
>> conditional jump instruction could offer, especially when the comparison
>> is between constant and register for which case the value range of the
>> register could be improved.
>> 
>>   is_branch_taken/reg_set_min_max/reg_set_min_max_inv
>> 
>> are the three functions that needs updating.
>> 
>> There are some other conditional jump related optimizations but they
>> are with pointer types comparison which JMP32 won't be generated for.
>> 
>> Signed-off-by: Jiong Wang <jiong.wang@netronome.com>
>> ---
>>  kernel/bpf/verifier.c | 178 ++++++++++++++++++++++++++++++++++++++------------
>>  1 file changed, 137 insertions(+), 41 deletions(-)
>> 
>> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
>> index e0e77ff..3123c91 100644
>> --- a/kernel/bpf/verifier.c
>> +++ b/kernel/bpf/verifier.c
>> @@ -3919,7 +3919,7 @@ static int is_branch_taken(struct bpf_reg_state *reg, u64 val, u8 opcode)
>>   */
>>  static void reg_set_min_max(struct bpf_reg_state *true_reg,
>>  			    struct bpf_reg_state *false_reg, u64 val,
>> -			    u8 opcode)
>> +			    u8 opcode, bool is_jmp32)
>>  {
>>  	/* If the dst_reg is a pointer, we can't learn anything about its
>>  	 * variable offset from the compare (unless src_reg were a pointer into
>> @@ -3935,45 +3935,69 @@ static void reg_set_min_max(struct bpf_reg_state *true_reg,
>>  		/* If this is false then we know nothing Jon Snow, but if it is
>>  		 * true then we know for sure.
>>  		 */
>> -		__mark_reg_known(true_reg, val);
>> +		if (is_jmp32)
>> +			true_reg->var_off = tnum_or(true_reg->var_off,
>> +						    tnum_const(val));
>
> These tnum updates look strange, if the jump is 32bit we know the
> bottom bits.  So:
>
> 	tnum.m &= GENMASK(63, 32);
> 	tnum.v = upper_32_bits(tnum.v) | lower_32_bits(val);

Ack.

By the way, I also fixed range deduction for some other operations which
eventually fixed the only regression on bpf_flow.o mentioned in the cover
letter. Now the processed insn number looks in general a consistent win
against either alu32 or default.

Processed insn number
===
LLVM code-gen option   default  alu32  alu32/jmp32  change Vs.  change Vs.
                                                    alu32       default
bpf_lb-DLB_L3.o:       1579     1281   1295         +1.09%      -17.99%
bpf_lb-DLB_L4.o:       2045     1663   1556         -6.43%      -23.91%
bpf_lb-DUNKNOWN.o:     606      513    501          -2.34%      -17.33%
bpf_lxc.o:             85381    103218 84236        -18.39%     -1.34%
bpf_netdev.o:          5246     5809   5200         -10.48%     -0.08%
bpf_overlay.o:         2443     2705   2456         -9.02%      -0.53%

Will included all fixes in v2.

Regards,
Jiong

  reply	other threads:[~2019-01-08 15:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-19 22:44 [PATH bpf-next 00/13] bpf: propose new jmp32 instructions Jiong Wang
2018-12-19 22:44 ` [PATH bpf-next 01/13] bpf: encoding description and macros for JMP32 Jiong Wang
2018-12-19 22:44 ` [PATH bpf-next 02/13] bpf: interpreter support " Jiong Wang
2018-12-19 22:44 ` [PATH bpf-next 03/13] bpf: JIT blinds support JMP32 Jiong Wang
2018-12-19 22:44 ` [PATH bpf-next 04/13] x86_64: bpf: implement jitting of JMP32 Jiong Wang
2018-12-19 22:44 ` [PATH bpf-next 05/13] x32: " Jiong Wang
2018-12-19 22:44 ` [PATH bpf-next 06/13] arm64: " Jiong Wang
2018-12-19 22:44 ` [PATH bpf-next 07/13] arm: " Jiong Wang
2018-12-19 22:44 ` [PATH bpf-next 08/13] ppc: " Jiong Wang
2018-12-19 22:44 ` [PATH bpf-next 09/13] s390: " Jiong Wang
2018-12-20  6:47   ` Martin Schwidefsky
2018-12-19 22:44 ` [PATH bpf-next 10/13] nfp: " Jiong Wang
2018-12-19 22:44 ` [PATH bpf-next 11/13] bpf: verifier support JMP32 Jiong Wang
2018-12-19 23:54   ` Jakub Kicinski
2019-01-08 15:23     ` Jiong Wang [this message]
2018-12-19 22:44 ` [PATH bpf-next 12/13] bpf: unit tests for JMP32 Jiong Wang
2018-12-19 22:44 ` [PATH bpf-next 13/13] selftests: bpf: makefile support sub-register code-gen test mode Jiong Wang
2018-12-20  3:08 ` [PATH bpf-next 00/13] bpf: propose new jmp32 instructions Alexei Starovoitov

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=874lajp40s.fsf@netronome.com \
    --to=jiong.wang@netronome.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jakub.kicinski@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;
as well as URLs for NNTP newsgroup(s).