Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Johan Almbladh <johan.almbladh@anyfinetworks.com>
To: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next v2 13/13] bpf/tests: Add tail call limit test with external function call
Date: Wed, 8 Sep 2021 12:53:23 +0200	[thread overview]
Message-ID: <CAM1=_QTC077YiaJ_7x=ooq2HyKhYFEPt_C04y1uo4tNEyGioFA@mail.gmail.com> (raw)
In-Reply-To: <fe04c10b5991a5fb0656fe272c137a73ec7d2472.camel@linux.ibm.com>

On Wed, Sep 8, 2021 at 12:10 PM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>
> On Wed, 2021-09-08 at 00:23 +0200, Johan Almbladh wrote:
> > This patch adds a tail call limit test where the program also emits
> > a BPF_CALL to an external function prior to the tail call. Mainly
> > testing that JITed programs preserve its internal register state, for
> > example tail call count, across such external calls.
> >
> > Signed-off-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
> > ---
> >  lib/test_bpf.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++---
> >  1 file changed, 48 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/test_bpf.c b/lib/test_bpf.c
> > index 7475abfd2186..6e45b4da9841 100644
> > --- a/lib/test_bpf.c
> > +++ b/lib/test_bpf.c
> > @@ -12259,6 +12259,20 @@ static struct tail_call_test tail_call_tests[]
> > = {
> >                 },
> >                 .result = MAX_TAIL_CALL_CNT + 1,
> >         },
> > +       {
> > +               "Tail call count preserved across function calls",
> > +               .insns = {
> > +                       BPF_ALU64_IMM(BPF_ADD, R1, 1),
> > +                       BPF_STX_MEM(BPF_DW, R10, R1, -8),
> > +                       BPF_CALL_REL(0),
> > +                       BPF_LDX_MEM(BPF_DW, R1, R10, -8),
> > +                       BPF_ALU32_REG(BPF_MOV, R0, R1),
> > +                       TAIL_CALL(0),
> > +                       BPF_EXIT_INSN(),
> > +               },
> > +               .stack_depth = 8,
> > +               .result = MAX_TAIL_CALL_CNT + 1,
> > +       },
> >         {
> >                 "Tail call error path, NULL target",
> >                 .insns = {
>
> There seems to be a problem with BPF_CALL_REL(0) on s390, since it
> assumes that test_bpf_func and __bpf_call_base are within +-2G of
> each other, which is not (yet) the case.

The idea with this test is to mess up a JITed program's internal state
if it does not properly save/restore those regs. I would like to keep
the test in some form, but I do see the problem here.

Another option could perhaps be to skip this test at runtime if the
computed offset is outside +-2G. If the offset is greater than that it
does not fit into the 32-bit BPF immediate field, and must therefore
be skipped. This would work for other archs too.

Yet another solution would be call one or several bpf helpers instead.
As I understand it, they should always be located within this range,
otherwise they would not be callable from a BPF program. The reason I
did not do this was because I found helpers that don't require any
context to be too simple. Ideally one would want to call something
that uses pretty much all available caller-saved CPU registers. I
figured snprintf would be complex/nasty enough for this purpose.

>
> I can't think of a good fix, so how about something like this?
>
> --- a/lib/test_bpf.c
> +++ b/lib/test_bpf.c
> @@ -12257,6 +12257,7 @@ static struct tail_call_test tail_call_tests[]
> = {
>                 },
>                 .result = MAX_TAIL_CALL_CNT + 1,
>         },
> +#ifndef __s390__
>         {
>                 "Tail call count preserved across function calls",
>                 .insns = {
> @@ -12271,6 +12272,7 @@ static struct tail_call_test tail_call_tests[]
> = {
>                 .stack_depth = 8,
>                 .result = MAX_TAIL_CALL_CNT + 1,
>         },
> +#endif
>         {
>                 "Tail call error path, NULL target",
>                 .insns = {
>
> [...]
>

  reply	other threads:[~2021-09-08 10:53 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-07 22:23 [PATCH bpf-next v2 00/13] bpf/tests: Extend JIT test suite coverage Johan Almbladh
2021-09-07 22:23 ` [PATCH bpf-next v2 01/13] bpf/tests: Allow different number of runs per test case Johan Almbladh
2021-09-07 22:23 ` [PATCH bpf-next v2 02/13] bpf/tests: Reduce memory footprint of test suite Johan Almbladh
2021-09-07 22:23 ` [PATCH bpf-next v2 03/13] bpf/tests: Add exhaustive tests of ALU shift values Johan Almbladh
2021-09-07 22:23 ` [PATCH bpf-next v2 04/13] bpf/tests: Add exhaustive tests of ALU operand magnitudes Johan Almbladh
2021-09-07 22:23 ` [PATCH bpf-next v2 05/13] bpf/tests: Add exhaustive tests of JMP " Johan Almbladh
2021-09-07 22:23 ` [PATCH bpf-next v2 06/13] bpf/tests: Add staggered JMP and JMP32 tests Johan Almbladh
2021-09-07 22:23 ` [PATCH bpf-next v2 07/13] bpf/tests: Add exhaustive test of LD_IMM64 immediate magnitudes Johan Almbladh
2021-09-07 22:23 ` [PATCH bpf-next v2 08/13] bpf/tests: Add test case flag for verifier zero-extension Johan Almbladh
2021-09-07 22:23 ` [PATCH bpf-next v2 09/13] bpf/tests: Add JMP tests with small offsets Johan Almbladh
2021-09-07 22:23 ` [PATCH bpf-next v2 10/13] bpf/tests: Add JMP tests with degenerate conditional Johan Almbladh
2021-09-07 22:23 ` [PATCH bpf-next v2 11/13] bpf/tests: Expand branch conversion JIT test Johan Almbladh
2021-09-07 22:23 ` [PATCH bpf-next v2 12/13] bpf/tests: Add more BPF_END byte order conversion tests Johan Almbladh
2021-09-07 22:23 ` [PATCH bpf-next v2 13/13] bpf/tests: Add tail call limit test with external function call Johan Almbladh
2021-09-08 10:10   ` Ilya Leoshkevich
2021-09-08 10:53     ` Johan Almbladh [this message]
2021-09-08 11:46       ` Daniel Borkmann
2021-09-08 11:59         ` Johan Almbladh

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='CAM1=_QTC077YiaJ_7x=ooq2HyKhYFEPt_C04y1uo4tNEyGioFA@mail.gmail.com' \
    --to=johan.almbladh@anyfinetworks.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=iii@linux.ibm.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.com \
    --subject='Re: [PATCH bpf-next v2 13/13] bpf/tests: Add tail call limit test with external function call' \
    /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

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).