BPF List
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>, bpf <bpf@vger.kernel.org>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Subject: Re: [PATCH RFC bpf-next 5/5] bpf: Do not include the original insn in zext patchlet
Date: Fri, 11 Sep 2020 14:58:45 +0200	[thread overview]
Message-ID: <2b84f5c397ca43c5883f6e10c6e3a232b511d893.camel@linux.ibm.com> (raw)
In-Reply-To: <CAADnVQ+2RPKcftZw8d+B1UwB35cpBhpF5u3OocNh90D9pETPwg@mail.gmail.com>

On Thu, 2020-09-10 at 17:25 -0700, Alexei Starovoitov wrote:
> On Wed, Sep 9, 2020 at 4:37 PM Ilya Leoshkevich <iii@linux.ibm.com>
> wrote:
> > If the original insn is a jump, then it is not subjected to branch
> > adjustment, which is incorrect. As discovered by Yauheni in
> 
> I think the problem is elsewhere.
> Something is wrong with zext logic.
> the branch insn should not have been marked as zext_dst.
> and in the line:
> zext_patch[0] = insn;
> this 'insn' should never be a branch.
> See insn_no_def().

Would it make sense to add a WARN_ON(insn_no_def(&insn)) there?


I believe the root cause is triggered by clear_caller_saved_regs().

This is our prog:

[     0]: BPF_JMP | BPF_CALL | BPF_K, BPF_REG_0, BPF_REG_1, 0x0, 0x1
[     1]: BPF_JMP | BPF_EXIT | BPF_K, BPF_REG_0, BPF_REG_0, 0x0, 0x0
[     2]: BPF_JMP | BPF_CALL | BPF_K, BPF_REG_0, BPF_REG_1, 0x0, 0x1
[     3]: BPF_JMP | BPF_EXIT | BPF_K, BPF_REG_0, BPF_REG_0, 0x0, 0x0
...

and env->insn_idx is 2. clear_caller_saved_regs() calls

	check_reg_arg(env, caller_saved[i], DST_OP_NO_MARK);

for register 0, and then inside check_reg_arg() we come to

	reg->subreg_def = rw64 ? DEF_NOT_SUBREG : env->insn_idx + 1;

where rw64 is false, because insn 2 is a BPF_PSEUDO_CALL. Having
non-zero subreg_def causes mark_insn_zext() to set zext_dst later on.

Maybe mark_reg_unknown() can do something to prevent this? My knee-jerk
reaction would be to set subreg_def to 0 there, but I'm not sure
whether this would be correct.


  parent reply	other threads:[~2020-09-11 17:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-09 23:34 [PATCH RFC bpf-next 0/5] Do not include the original insn in zext patchlet Ilya Leoshkevich
2020-09-09 23:34 ` [PATCH RFC bpf-next 1/5] bpf: Make bpf_patch_insn_single() accept variable number of old insns Ilya Leoshkevich
2020-09-09 23:34 ` [PATCH RFC bpf-next 2/5] bpf: Make adjust_insn_aux_data() " Ilya Leoshkevich
2020-09-09 23:34 ` [PATCH RFC bpf-next 3/5] bpf: Make adjust_subprog_starts() " Ilya Leoshkevich
2020-09-09 23:34 ` [PATCH RFC bpf-next 4/5] bpf: Make bpf_patch_insn_data() " Ilya Leoshkevich
2020-09-09 23:34 ` [PATCH RFC bpf-next 5/5] bpf: Do not include the original insn in zext patchlet Ilya Leoshkevich
2020-09-10  6:59   ` Yauheni Kaliuta
2020-09-10  9:18     ` Ilya Leoshkevich
2020-09-11  0:25   ` Alexei Starovoitov
2020-09-11  6:33     ` Yauheni Kaliuta
2020-09-11 12:58     ` Ilya Leoshkevich [this message]
2020-09-29 20:03       ` Ilya Leoshkevich

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=2b84f5c397ca43c5883f6e10c6e3a232b511d893.camel@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=yauheni.kaliuta@redhat.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