BPF List
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Daniel Borkmann <daniel@iogearbox.net>,
	Yauheni Kaliuta <yauheni.kaliuta@redhat.com>,
	bpf@vger.kernel.org
Cc: jolsa@redhat.com, Jakub Kicinski <kuba@kernel.org>
Subject: Re: [PATCH RFC] bpf: update current instruction on patching
Date: Fri, 04 Sep 2020 17:17:49 +0200	[thread overview]
Message-ID: <a38c5d977acb6c036bfeddfc6784a0fe58c29b80.camel@linux.ibm.com> (raw)
In-Reply-To: <1ac6aef1-b38c-06c7-6e0d-b8459207d7d9@iogearbox.net>

On Thu, 2020-09-03 at 17:10 +0200, Daniel Borkmann wrote:
> On 9/3/20 4:05 PM, Yauheni Kaliuta wrote:
> > On code patching it may require to update branch destinations if
> > the
> > code size changed. bpf_adj_delta_to_imm/off increments offset only
> > if the patched area is after the branch instruction. But it's
> > possible, that the patched area itself is a branch instruction and
> > requires destination update.
> 
> Could you provide a concrete example and walk us through? I'm
> probably
> missing something but if the patchlet contains a branch instruction,
> then
> it should be 'self-contained'. In the sense that the patchlet is a
> 'black
> box' that replaces 1 insns with n insns but there is no awareness
> what's
> inside these insns and hence no fixup for that inside
> bpf_patch_insn_data().
> So, if we take an existing branch insns from the code, move it into
> the
> patchlet and extend beginning or end, then it feels more like a bug
> to the
> one that called bpf_patch_insn_data(), aka zext code here. Bit
> puzzled why
> this is only seen now, my impression was that Ilya was running s390x
> the
> BPF selftests quite recently?
> 
> > The problem was triggered by bpf selftest
> > 
> > test_progs -t global_funcs
> > 
> > on s390, where the very first "call" instruction is patched from
> > verifier.c:opt_subreg_zext_lo32_rnd_hi32() with zext_patch.
> > 
> > The patch includes current instruction to the condition check.
> > 
> > Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
> > ---
> >   kernel/bpf/core.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> > index ed0b3578867c..b0a9a22491a5 100644
> > --- a/kernel/bpf/core.c
> > +++ b/kernel/bpf/core.c
> > @@ -340,7 +340,7 @@ static int bpf_adj_delta_to_imm(struct bpf_insn
> > *insn, u32 pos, s32 end_old,
> >   	s32 delta = end_new - end_old;
> >   	s64 imm = insn->imm;
> >   
> > -	if (curr < pos && curr + imm + 1 >= end_old)
> > +	if (curr <= pos && curr + imm + 1 >= end_old)
> >   		imm += delta;
> >   	else if (curr >= end_new && curr + imm + 1 < end_new)
> >   		imm -= delta;
> > @@ -358,7 +358,7 @@ static int bpf_adj_delta_to_off(struct bpf_insn
> > *insn, u32 pos, s32 end_old,
> >   	s32 delta = end_new - end_old;
> >   	s32 off = insn->off;
> >   
> > -	if (curr < pos && curr + off + 1 >= end_old)
> > +	if (curr <= pos && curr + off + 1 >= end_old)
> >   		off += delta;
> >   	else if (curr >= end_new && curr + off + 1 < end_new)
> >   		off -= delta;
> > 

Hi!

Last time I ran selftests against bpf-next ~1 month ago, and I don't
remember seeing any test_progs failures. Now I tried it again, and I
see the same problem as Yauheni. So this must be relatively new - I'll
try to bisect the commit that caused this.

Best regards,
Ilya


  parent reply	other threads:[~2020-09-04 15:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03 14:05 [PATCH RFC] bpf: update current instruction on patching Yauheni Kaliuta
2020-09-03 15:05 ` Yauheni Kaliuta
2020-09-03 15:10 ` Daniel Borkmann
2020-09-03 16:13   ` Yauheni Kaliuta
2020-09-03 18:12     ` Yauheni Kaliuta
2020-09-07 16:14     ` Ilya Leoshkevich
2020-09-08 11:31       ` Yauheni Kaliuta
2020-09-04 15:17   ` Ilya Leoshkevich [this message]
2020-09-04 17:40     ` 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=a38c5d977acb6c036bfeddfc6784a0fe58c29b80.camel@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jolsa@redhat.com \
    --cc=kuba@kernel.org \
    --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