Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Paul Chaignon <paul.chaignon@gmail.com>
To: Johan Almbladh <johan.almbladh@anyfinetworks.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Alexei Starovoitov <ast@kernel.org>,
	andrii@kernel.org
Cc: Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	john.fastabend@gmail.com, kpsingh@kernel.org,
	Linux Kernel Network Developers <netdev@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>,
	illusionist.neo@gmail.com, zlim.lnx@gmail.com,
	Paul Burton <paulburton@kernel.org>,
	naveen.n.rao@linux.ibm.com, sandipan@linux.ibm.com,
	luke.r.nels@gmail.com, bjorn@kernel.org, iii@linux.ibm.com,
	hca@linux.ibm.com, gor@linux.ibm.com,
	"David S. Miller" <davem@davemloft.net>,
	udknight@gmail.com
Subject: Re: [PATCH bpf-next 0/7] Fix MAX_TAIL_CALL_CNT handling in eBPF JITs
Date: Thu, 12 Aug 2021 18:36:59 +0200	[thread overview]
Message-ID: <CAO5pjwTWrC0_dzTbTHFPSqDwA56aVH+4KFGVqdq8=ASs0MqZGQ@mail.gmail.com> (raw)
In-Reply-To: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com>

On Mon, Aug 09, 2021 at 11:34:30AM +0200, Johan Almbladh wrote:
> A new test of tail call count limiting revealed that the interpreter
> did in fact allow up to MAX_TAIL_CALL_CNT + 1 tail calls, whereas the
> x86 JITs stopped at the intended MAX_TAIL_CALL_CNT. The interpreter was
> fixed in commit b61a28cf11d61f512172e673b8f8c4a6c789b425 ("bpf: Fix
> off-by-one in tail call count limiting"). This patch set fixes all
> arch-specific JITs except for RISC-V.

I'm a bit surprised by this because I had previously tested the tail
call limit of several JIT compilers and found it to be 33 (i.e.,
allowing chains of up to 34 programs). I've just extended a test program
I had to validate this again on the x86-64 JIT and found a limit of 33
tail calls again [1].

Also note we had previously changed the RISC-V and MIPS JITs to allow up
to 33 tail calls [2, 3], for consistency with other JITs and with the
interpreter. We had decided to increase these two to 33 rather than
decrease the other JITs to 32 for backward compatibility, though that
probably doesn't matter much as I'd expect few people to actually use 33
tail calls :-)

1 - https://github.com/pchaigno/tail-call-bench/commit/ae7887482985b4b1745c9b2ef7ff9ae506c82886
2 - 96bc4432 ("bpf, riscv: Limit to 33 tail calls")
3 - e49e6f6d ("bpf, mips: Limit to 33 tail calls")

>
> For each of the affected JITs, the incorrect behaviour was verified
> by running the test_bpf test suite in QEMU. After the fixes, the JITs
> pass the tail call count limiting test.

If you are referring to test_tailcall_3 and its associated BPF program
tailcall3, then as far as I can tell, it checks that 33 tail calls are
allowed. The counter is incremented before each tail call except the
first one. The last tail call is rejected because we reach the limit, so
a counter value of 33 (as checked in the test code) means we've
successfully executed 33 tail calls.

--
Paul

>
> I have not been able to test the RISC-V JITs due to the lack of a
> working toolchain and QEMU setup. It is likely that the RISC-V JITs
> have the off-by-one behaviour too. I have not verfied any of the NIC JITs.
>
> Link: https://lore.kernel.org/bpf/20210728164741.350370-1-johan.almbladh@anyfinetworks.com/
>
> Johan Almbladh (7):
>   arm: bpf: Fix off-by-one in tail call count limiting
>   arm64: bpf: Fix off-by-one in tail call count limiting
>   powerpc: bpf: Fix off-by-one in tail call count limiting
>   s390: bpf: Fix off-by-one in tail call count limiting
>   sparc: bpf: Fix off-by-one in tail call count limiting
>   mips: bpf: Fix off-by-one in tail call count limiting
>   x86: bpf: Fix comments on tail call count limiting
>
>  arch/arm/net/bpf_jit_32.c         | 6 +++---
>  arch/arm64/net/bpf_jit_comp.c     | 4 ++--
>  arch/mips/net/ebpf_jit.c          | 4 ++--
>  arch/powerpc/net/bpf_jit_comp32.c | 4 ++--
>  arch/powerpc/net/bpf_jit_comp64.c | 4 ++--
>  arch/s390/net/bpf_jit_comp.c      | 6 +++---
>  arch/sparc/net/bpf_jit_comp_64.c  | 2 +-
>  arch/x86/net/bpf_jit_comp32.c     | 6 +++---
>  8 files changed, 18 insertions(+), 18 deletions(-)
>
> --
> 2.25.1
>

  parent reply	other threads:[~2021-08-12 16:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-09  9:34 [PATCH bpf-next 0/7] Fix MAX_TAIL_CALL_CNT handling in eBPF JITs Johan Almbladh
2021-08-09  9:34 ` [PATCH bpf-next 1/7] arm: bpf: Fix off-by-one in tail call count limiting Johan Almbladh
2021-08-09  9:34 ` [PATCH bpf-next 2/7] arm64: " Johan Almbladh
2021-08-09  9:34 ` [PATCH bpf-next 3/7] powerpc: " Johan Almbladh
2021-08-09  9:34 ` [PATCH bpf-next 4/7] s390: " Johan Almbladh
2021-08-09 12:24   ` Ilya Leoshkevich
2021-08-09 21:09     ` Johan Almbladh
2021-08-09  9:34 ` [PATCH bpf-next 5/7] sparc: " Johan Almbladh
2021-08-09  9:34 ` [PATCH bpf-next 6/7] mips: " Johan Almbladh
2021-08-09  9:34 ` [PATCH bpf-next 7/7] x86: bpf: Fix comments on " Johan Almbladh
2021-08-09 15:41   ` Daniel Borkmann
2021-08-09 18:02     ` Johan Almbladh
2021-08-12 16:36 ` Paul Chaignon [this message]
2021-08-16  7:17   ` [PATCH bpf-next 0/7] Fix MAX_TAIL_CALL_CNT handling in eBPF JITs 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='CAO5pjwTWrC0_dzTbTHFPSqDwA56aVH+4KFGVqdq8=ASs0MqZGQ@mail.gmail.com' \
    --to=paul.chaignon@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    --cc=illusionist.neo@gmail.com \
    --cc=johan.almbladh@anyfinetworks.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=luke.r.nels@gmail.com \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=paulburton@kernel.org \
    --cc=sandipan@linux.ibm.com \
    --cc=songliubraving@fb.com \
    --cc=udknight@gmail.com \
    --cc=yhs@fb.com \
    --cc=zlim.lnx@gmail.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).