Netdev Archive on lore.kernel.org help / color / mirror / Atom feed
From: Johan Almbladh <johan.almbladh@anyfinetworks.com> To: Daniel Borkmann <daniel@iogearbox.net> Cc: Alexei Starovoitov <ast@kernel.org>, 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>, illusionist.neo@gmail.com, zlim.lnx@gmail.com, Paul Burton <paulburton@kernel.org>, naveen.n.rao@linux.ibm.com, sandipan@linux.ibm.com, Luke Nelson <luke.r.nels@gmail.com>, bjorn@kernel.org, iii@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, davem@davemloft.net, udknight@gmail.com Subject: Re: [PATCH bpf-next 7/7] x86: bpf: Fix comments on tail call count limiting Date: Mon, 9 Aug 2021 20:02:33 +0200 [thread overview] Message-ID: <CAM1=_QRs3p+u3+QeJXdv8y=dP6NVKYLhozJeR0U6pOY4cqOUCg@mail.gmail.com> (raw) In-Reply-To: <bab35321-9142-c51d-7244-438fc5a0efb9@iogearbox.net> On Mon, Aug 9, 2021 at 5:42 PM Daniel Borkmann <daniel@iogearbox.net> wrote: > > On 8/9/21 11:34 AM, Johan Almbladh wrote: > > Before, the comments in the 32-bit eBPF JIT claimed that up to > > MAX_TAIL_CALL_CNT + 1 tail calls were allowed, when in fact the > > implementation was using the correct limit of MAX_TAIL_CALL_CNT. > > Now, the comments are in line with what the code actually does. > > > > Signed-off-by: Johan Almbladh <johan.almbladh@anyfinetworks.com> > > --- > > arch/x86/net/bpf_jit_comp32.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/arch/x86/net/bpf_jit_comp32.c b/arch/x86/net/bpf_jit_comp32.c > > index 3bfda5f502cb..8db9ab11abda 100644 > > --- a/arch/x86/net/bpf_jit_comp32.c > > +++ b/arch/x86/net/bpf_jit_comp32.c > > @@ -1272,7 +1272,7 @@ static void emit_epilogue(u8 **pprog, u32 stack_depth) > > * ... bpf_tail_call(void *ctx, struct bpf_array *array, u64 index) ... > > * if (index >= array->map.max_entries) > > * goto out; > > - * if (++tail_call_cnt > MAX_TAIL_CALL_CNT) > > + * if (tail_call_cnt++ >= MAX_TAIL_CALL_CNT) > > * goto out; > > * prog = array->ptrs[index]; > > * if (prog == NULL) > > @@ -1307,7 +1307,7 @@ static void emit_bpf_tail_call(u8 **pprog) > > EMIT2(IA32_JBE, jmp_label(jmp_label1, 2)); > > > > /* > > - * if (tail_call_cnt > MAX_TAIL_CALL_CNT) > > + * if (tail_call_cnt >= MAX_TAIL_CALL_CNT) > > * goto out; > > */ > > lo = (u32)MAX_TAIL_CALL_CNT; > > @@ -1321,7 +1321,7 @@ static void emit_bpf_tail_call(u8 **pprog) > > /* cmp ecx,lo */ > > EMIT3(0x83, add_1reg(0xF8, IA32_ECX), lo); > > > > - /* ja out */ > > + /* jae out */ > > EMIT2(IA32_JAE, jmp_label(jmp_label1, 2)); > > You have me confused here ... b61a28cf11d6 ("bpf: Fix off-by-one in tail call count > limiting") from bpf-next says '[interpreter is now] in line with the behavior of the > x86 JITs'. From the latter I assumed you implicitly refer to x86-64. Which one did you > test specifically wrt the prior statement? I tested both the 64-bit and the 32-bit JITs with QEMU. Both passed, meaning that the tail call recursion stopped after 32 tail calls. However, the comments in the code indicated that it would allow one more call, and also said JA when it actually emitted JAE. This patch merely fixes the comments in the 32-bit JIT to match the code. > It looks like x86-64 vs x86-32 differ: > > [...] > EMIT2_off32(0x8B, 0x85, tcc_off); /* mov eax, dword ptr [rbp - tcc_off] */ > EMIT3(0x83, 0xF8, MAX_TAIL_CALL_CNT); /* cmp eax, MAX_TAIL_CALL_CNT */ > EMIT2(X86_JA, OFFSET2); /* ja out */ > EMIT3(0x83, 0xC0, 0x01); /* add eax, 1 */ > EMIT2_off32(0x89, 0x85, tcc_off); /* mov dword ptr [rbp - tcc_off], eax */ > [...] > > So it's ja vs jae ... unless I need more coffee? ;) Yes, the x86-64 JIT is different. It also pass the test, but I do find the code and comments a bit confusing too. Since it pass the test, and the top-level comment correctly states the stop condition as ++tail_call_cnt > MAX_TAIL_CALL_CNT, I left it at that. On a side note, I see that the x86-64 JIT also has a direct tail call code path which the other JITs don't seem to have. The tail call test only checks the indirect tail call code path. > > > /* add eax,0x1 */ > > >
next prev parent reply other threads:[~2021-08-09 18:02 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 [this message] 2021-08-12 16:36 ` [PATCH bpf-next 0/7] Fix MAX_TAIL_CALL_CNT handling in eBPF JITs Paul Chaignon 2021-08-16 7:17 ` 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=_QRs3p+u3+QeJXdv8y=dP6NVKYLhozJeR0U6pOY4cqOUCg@mail.gmail.com' \ --to=johan.almbladh@anyfinetworks.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=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: linkBe 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).