From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>,
Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf <bpf@vger.kernel.org>, Jiri Olsa <jolsa@redhat.com>,
Jakub Kicinski <kuba@kernel.org>
Subject: Re: [PATCH RFC] bpf: update current instruction on patching
Date: Mon, 07 Sep 2020 18:14:07 +0200 [thread overview]
Message-ID: <7510248caa08a521150b3089e12ded4312eaf14b.camel@linux.ibm.com> (raw)
In-Reply-To: <CANoWswkX9xrG48HHO19Q67ogmNcOArpe4iZwWU4_S08A7H+_Cg@mail.gmail.com>
On Thu, 2020-09-03 at 19:13 +0300, Yauheni Kaliuta wrote:
> On Thu, Sep 3, 2020 at 6:10 PM Daniel Borkmann <daniel@iogearbox.net>
> 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().
>
> The code is
> Disassembly of section classifier/test:
>
> 0000000000000000 test_cls:
> 0: 85 01 00 00 ff ff ff ff call -1
> 0000000000000000: R_BPF_64_32 f7
> 1: 95 00 00 00 00 00 00 00 exit
> 0000000000000000 f1:
> 0: 61 01 00 00 00 00 00 00 r0 = *(u32 *)(r1 + 0)
> 1: 95 00 00 00 00 00 00 00 exit
> [...]
> 00000000000000a8 f7:
> 21: 85 01 00 00 ff ff ff ff call -1
> 00000000000000a8: R_BPF_64_32 f6
> 22: 95 00 00 00 00 00 00 00 exit
>
> Before the patching the bytecode is:
>
> 00000000: 85 01 00 00 00 00 00 16 95 00 00 00 00 00 00 00
> 00000010: 61 01 00 00 00 00 00 00 95 00 00 00 00 00 00 00
> [...]
>
> It becomes
>
>
> 00000000: 85 01 00 00 00 00 00 2b bc 00 00 00 00 00 00 01
> 00000010: 95 00 00 00 00 00 00 00 61 01 00 80 00 00 00 00
>
> at the end, the 2b offset is incorrect.
>
> With that zext patching the code "85 01 00 00 00 00 00 16" is
> replaced
> with "85 01 00 00 00 00 00 16 bc 00 00 00 00 00 00 01", 0x16 is not
> changed, but the real offset has changed.
>
> > 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?
>
> I have not investigated why on s390 it is zext'ed, but on x86 not,
> it's related to the size of the register when it returns 32bit value.
> There may be a bug there as well.
>
> I did think a bit more on your words, making the zext patching code
> specially check jumps and adjust the offset in the patchlet looks
> more
> correct. But duplicates the existing code. I should spend more time
> on
> that.
I guess copying the existing insn into the patchlet was introduced
because there is nothing like bpf_insert_insns()? I.e. we can replace
an existing insn with a patchlet, but cannot append anything to it.
Would introducing such function solve this problem?
next prev parent reply other threads:[~2020-09-07 16: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 [this message]
2020-09-08 11:31 ` Yauheni Kaliuta
2020-09-04 15:17 ` Ilya Leoshkevich
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=7510248caa08a521150b3089e12ded4312eaf14b.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