From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-22.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E01BCC43219 for ; Thu, 9 Sep 2021 07:57:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C808E60F5B for ; Thu, 9 Sep 2021 07:57:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230147AbhIIH6w (ORCPT ); Thu, 9 Sep 2021 03:58:52 -0400 Received: from www62.your-server.de ([213.133.104.62]:59298 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbhIIH6r (ORCPT ); Thu, 9 Sep 2021 03:58:47 -0400 Received: from sslproxy01.your-server.de ([78.46.139.224]) by www62.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1mOEvf-0001T3-P1; Thu, 09 Sep 2021 09:57:03 +0200 Received: from [85.5.47.65] (helo=linux.home) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mOEvf-000H3n-3x; Thu, 09 Sep 2021 09:57:03 +0200 Subject: Re: [PATCH bpf-next] bpf: Change value of MAX_TAIL_CALL_CNT from 32 to 33 To: Andrii Nakryiko , Tiezhu Yang Cc: Shubham Bansal , Russell King , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Zi Shen Lim , Catalin Marinas , Will Deacon , Paul Burton , Thomas Bogendoerfer , naveen.n.rao@linux.ibm.com, Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Luke Nelson , Xi Wang , Paul Walmsley , Palmer Dabbelt , Albert Ou , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , "David S. Miller" , Johan Almbladh , Paul Chaignon , Networking , bpf , linux-arm-kernel , open list , linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org References: <1631158350-3661-1-git-send-email-yangtiezhu@loongson.cn> From: Daniel Borkmann Message-ID: Date: Thu, 9 Sep 2021 09:57:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.103.2/26288/Wed Sep 8 10:22:21 2021) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/9/21 7:50 AM, Andrii Nakryiko wrote: > On Wed, Sep 8, 2021 at 8:33 PM Tiezhu Yang wrote: >> >> In the current code, the actual max tail call count is 33 which is greater >> than MAX_TAIL_CALL_CNT (defined as 32), the actual limit is not consistent >> with the meaning of MAX_TAIL_CALL_CNT, there is some confusion and need to >> spend some time to think the reason at the first glance. > > think *about* the reason > >> We can see the historical evolution from commit 04fd61ab36ec ("bpf: allow >> bpf programs to tail-call other bpf programs") and commit f9dabe016b63 >> ("bpf: Undo off-by-one in interpreter tail call count limit"). >> >> In order to avoid changing existing behavior, the actual limit is 33 now, >> this is resonable. > > typo: reasonable > >> After commit 874be05f525e ("bpf, tests: Add tail call test suite"), we can >> see there exists failed testcase. >> >> On all archs when CONFIG_BPF_JIT_ALWAYS_ON is not set: >> # echo 0 > /proc/sys/net/core/bpf_jit_enable >> # modprobe test_bpf >> # dmesg | grep -w FAIL >> Tail call error path, max count reached jited:0 ret 34 != 33 FAIL >> >> On some archs: >> # echo 1 > /proc/sys/net/core/bpf_jit_enable >> # modprobe test_bpf >> # dmesg | grep -w FAIL >> Tail call error path, max count reached jited:1 ret 34 != 33 FAIL >> >> So it is necessary to change the value of MAX_TAIL_CALL_CNT from 32 to 33, >> then do some small changes of the related code. >> >> With this patch, it does not change the current limit, MAX_TAIL_CALL_CNT >> can reflect the actual max tail call count, and the above failed testcase >> can be fixed. >> >> Signed-off-by: Tiezhu Yang >> --- > > This change breaks selftests ([0]), please fix them at the same time > as you are changing the kernel behavior: The below selftests shouldn't have to change given there is no change in behavior intended (MAX_TAIL_CALL_CNT is bumped to 33 but counter inc'ed prior to the comparison). It just means that /all/ JITs must be changed and in particular properly _tested_. > test_tailcall_2:PASS:tailcall 128 nsec > test_tailcall_2:PASS:tailcall 128 nsec > test_tailcall_2:FAIL:tailcall err 0 errno 2 retval 4 > #135/2 tailcalls/tailcall_2:FAIL > test_tailcall_3:PASS:tailcall 128 nsec > test_tailcall_3:FAIL:tailcall count err 0 errno 2 count 34 > test_tailcall_3:PASS:tailcall 128 nsec > #135/3 tailcalls/tailcall_3:FAIL > #135/4 tailcalls/tailcall_4:OK > #135/5 tailcalls/tailcall_5:OK > #135/6 tailcalls/tailcall_bpf2bpf_1:OK > test_tailcall_bpf2bpf_2:PASS:tailcall 128 nsec > test_tailcall_bpf2bpf_2:FAIL:tailcall count err 0 errno 2 count 34 > test_tailcall_bpf2bpf_2:PASS:tailcall 128 nsec > #135/7 tailcalls/tailcall_bpf2bpf_2:FAIL > #135/8 tailcalls/tailcall_bpf2bpf_3:OK > test_tailcall_bpf2bpf_4:PASS:tailcall 54 nsec > test_tailcall_bpf2bpf_4:FAIL:tailcall count err 0 errno 2 count 32 > #135/9 tailcalls/tailcall_bpf2bpf_4:FAIL > test_tailcall_bpf2bpf_4:PASS:tailcall 54 nsec > test_tailcall_bpf2bpf_4:FAIL:tailcall count err 0 errno 2 count 32 > #135/10 tailcalls/tailcall_bpf2bpf_5:FAIL > #135 tailcalls:FAIL > > [0] https://github.com/kernel-patches/bpf/pull/1747/checks?check_run_id=3552002906 > >> arch/arm/net/bpf_jit_32.c | 11 ++++++----- >> arch/arm64/net/bpf_jit_comp.c | 7 ++++--- >> arch/mips/net/ebpf_jit.c | 4 ++-- >> arch/powerpc/net/bpf_jit_comp32.c | 4 ++-- >> arch/powerpc/net/bpf_jit_comp64.c | 12 ++++++------ >> arch/riscv/net/bpf_jit_comp32.c | 4 ++-- >> arch/riscv/net/bpf_jit_comp64.c | 4 ++-- >> arch/sparc/net/bpf_jit_comp_64.c | 8 ++++---- >> include/linux/bpf.h | 2 +- >> kernel/bpf/core.c | 4 ++-- >> 10 files changed, 31 insertions(+), 29 deletions(-) >> > > [...] >