From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: "Pu Lehui" <pulehui@huaweicloud.com>, "Björn Töpel" <bjorn@kernel.org>
Cc: "Daniel Borkmann" <daniel@iogearbox.net>, <bot+bpf-ci@kernel.org>,
<bpf@vger.kernel.org>, <linux-riscv@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <ast@kernel.org>,
<andrii@kernel.org>, <eddyz87@gmail.com>, <martin.lau@linux.dev>,
<song@kernel.org>, <yonghong.song@linux.dev>,
<john.fastabend@gmail.com>, <kpsingh@kernel.org>,
<sdf@fomichev.me>, <haoluo@google.com>, <jolsa@kernel.org>,
<puranjay@kernel.org>, <pjw@kernel.org>, <palmer@dabbelt.com>,
<alex@ghiti.fr>, <pulehui@huawei.com>, <martin.lau@kernel.org>,
<clm@meta.com>, <ihor.solodrai@linux.dev>
Subject: Re: [PATCH bpf-next v6 6/7] riscv, bpf: Mixing bpf2bpf and tailcalls
Date: Mon, 20 Jul 2026 16:24:44 +0200 [thread overview]
Message-ID: <DK3GTYQ5UOMO.CVL471XPD0AT@gmail.com> (raw)
In-Reply-To: <dd20e3ea-4b3a-45d1-99f4-79e99e51e7fb@huaweicloud.com>
On Fri Jul 17, 2026 at 9:37 AM CEST, Pu Lehui wrote:
>
>
> On 2026/7/10 17:43, Daniel Borkmann wrote:
>> On 7/10/26 2:53 AM, Pu Lehui wrote:
>>> On 2026/7/10 3:51, Björn Töpel wrote:
>>>> On Thu, 9 Jul 2026 at 17:09, Pu Lehui <pulehui@huaweicloud.com> wrote:
>>>>> On 2026/7/9 19:37, Björn Töpel wrote:
>>>>>> Sorry for the delay here -- the bot had me thinking a bit.
>>>>>>
>>>>>> On Wed, 8 Jul 2026 at 10:54, Pu Lehui <pulehui@huaweicloud.com> wrote:
>>>>>> ...
>>>>>>
>>>>>>>> This assumes a fixed number of instructions before the tailcall
>>>>>>>> entry
>>>>>>>> point. When is_subprog is true, the rv_addi() instruction is not
>>>>>>>> emitted,
>>>>>>>> which means the tailcall entry point moves forward by 4 bytes
>>>>>>>> relative to
>>>>>>>> where RV_TAILCALL_OFFSET expects it to be.
>>>>>>>>
>>>>>>>> The tailcall entry is used in emit_bpf_tail_call() when
>>>>>>>> calculating the
>>>>>>>> jump target for the tail call. If RV_TAILCALL_OFFSET doesn't
>>>>>>>> account for
>>>>>>>> the conditional emission, could this cause the wrong entry point
>>>>>>>> to be
>>>>>>>> used when tail calling into subprograms?
>>>>>>>
>>>>>>> This is not an issue, subprog can not be the tailcall callee.
>>>>>>
>>>>>> Say, that we have an entry function that does bpf_for_each_map_array()
>>>>>> into a callback cb(). cb() is a subprogram, so no init of TCC. Now,
>>>>>> cb() calls another subprogram that does a tailcall.
>>>>>>
>>>>>> The callback to cb() is coming from the kernel, so a6 could have been
>>>>>> clobbered, no? We're entering a subprogram coming from the C ABI. Now,
>>>>>> if the callback calls a subprog that's tail-call reachable, the TCC
>>>>>> can be garbage?
>>>>>
>>>>> Sashiko reported the same issue yesterday. I verified that the verifier
>>>>> rejects cases where a tail call is invoked within a callback;
>>>>> specifically, while the callback's return value range is [0, 1], the
>>>>> simulation of the exit path in `check_helper_call` (handling the tail
>>>>> call helper) marks R0 as UNKNOWN, causing the verifier to reject
>>>>> it—so I
>>>>> didn't investigate further. However, I just verified that the verifier
>>>>> *does* accept the scenario where a callback calls a subprogram, and
>>>>> that
>>>>> subprogram subsequently calls a tail call. I believe this scenario
>>>>> ought
>>>>> to be rejected; perhaps some changes are needed in the verifier,
>>>>> otherwise tail calls on other architectures (like x86) would also be
>>>>> susceptible to infinite loop issues.
>>>>
>>>> Thanks for trying it out!
>>>>
>>>> Ok, so seems like we need a verifier fix pre-landing?
>
> Hi Björn,
>
> Just a quick note that the verifier fix we discussed has now landed in
> bpf-next [0]. Looking forward to your feedback on v6 whenever you get a
> chance. :)
Yep, if there are no more concerns, it would make sense to pull this in.
Björn, what do you think?
> [...]
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: "Pu Lehui" <pulehui@huaweicloud.com>, "Björn Töpel" <bjorn@kernel.org>
Cc: "Daniel Borkmann" <daniel@iogearbox.net>, <bot+bpf-ci@kernel.org>,
<bpf@vger.kernel.org>, <linux-riscv@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <ast@kernel.org>,
<andrii@kernel.org>, <eddyz87@gmail.com>, <martin.lau@linux.dev>,
<song@kernel.org>, <yonghong.song@linux.dev>,
<john.fastabend@gmail.com>, <kpsingh@kernel.org>,
<sdf@fomichev.me>, <haoluo@google.com>, <jolsa@kernel.org>,
<puranjay@kernel.org>, <pjw@kernel.org>, <palmer@dabbelt.com>,
<alex@ghiti.fr>, <pulehui@huawei.com>, <martin.lau@kernel.org>,
<clm@meta.com>, <ihor.solodrai@linux.dev>
Subject: Re: [PATCH bpf-next v6 6/7] riscv, bpf: Mixing bpf2bpf and tailcalls
Date: Mon, 20 Jul 2026 16:24:44 +0200 [thread overview]
Message-ID: <DK3GTYQ5UOMO.CVL471XPD0AT@gmail.com> (raw)
In-Reply-To: <dd20e3ea-4b3a-45d1-99f4-79e99e51e7fb@huaweicloud.com>
On Fri Jul 17, 2026 at 9:37 AM CEST, Pu Lehui wrote:
>
>
> On 2026/7/10 17:43, Daniel Borkmann wrote:
>> On 7/10/26 2:53 AM, Pu Lehui wrote:
>>> On 2026/7/10 3:51, Björn Töpel wrote:
>>>> On Thu, 9 Jul 2026 at 17:09, Pu Lehui <pulehui@huaweicloud.com> wrote:
>>>>> On 2026/7/9 19:37, Björn Töpel wrote:
>>>>>> Sorry for the delay here -- the bot had me thinking a bit.
>>>>>>
>>>>>> On Wed, 8 Jul 2026 at 10:54, Pu Lehui <pulehui@huaweicloud.com> wrote:
>>>>>> ...
>>>>>>
>>>>>>>> This assumes a fixed number of instructions before the tailcall
>>>>>>>> entry
>>>>>>>> point. When is_subprog is true, the rv_addi() instruction is not
>>>>>>>> emitted,
>>>>>>>> which means the tailcall entry point moves forward by 4 bytes
>>>>>>>> relative to
>>>>>>>> where RV_TAILCALL_OFFSET expects it to be.
>>>>>>>>
>>>>>>>> The tailcall entry is used in emit_bpf_tail_call() when
>>>>>>>> calculating the
>>>>>>>> jump target for the tail call. If RV_TAILCALL_OFFSET doesn't
>>>>>>>> account for
>>>>>>>> the conditional emission, could this cause the wrong entry point
>>>>>>>> to be
>>>>>>>> used when tail calling into subprograms?
>>>>>>>
>>>>>>> This is not an issue, subprog can not be the tailcall callee.
>>>>>>
>>>>>> Say, that we have an entry function that does bpf_for_each_map_array()
>>>>>> into a callback cb(). cb() is a subprogram, so no init of TCC. Now,
>>>>>> cb() calls another subprogram that does a tailcall.
>>>>>>
>>>>>> The callback to cb() is coming from the kernel, so a6 could have been
>>>>>> clobbered, no? We're entering a subprogram coming from the C ABI. Now,
>>>>>> if the callback calls a subprog that's tail-call reachable, the TCC
>>>>>> can be garbage?
>>>>>
>>>>> Sashiko reported the same issue yesterday. I verified that the verifier
>>>>> rejects cases where a tail call is invoked within a callback;
>>>>> specifically, while the callback's return value range is [0, 1], the
>>>>> simulation of the exit path in `check_helper_call` (handling the tail
>>>>> call helper) marks R0 as UNKNOWN, causing the verifier to reject
>>>>> it—so I
>>>>> didn't investigate further. However, I just verified that the verifier
>>>>> *does* accept the scenario where a callback calls a subprogram, and
>>>>> that
>>>>> subprogram subsequently calls a tail call. I believe this scenario
>>>>> ought
>>>>> to be rejected; perhaps some changes are needed in the verifier,
>>>>> otherwise tail calls on other architectures (like x86) would also be
>>>>> susceptible to infinite loop issues.
>>>>
>>>> Thanks for trying it out!
>>>>
>>>> Ok, so seems like we need a verifier fix pre-landing?
>
> Hi Björn,
>
> Just a quick note that the verifier fix we discussed has now landed in
> bpf-next [0]. Looking forward to your feedback on v6 whenever you get a
> chance. :)
Yep, if there are no more concerns, it would make sense to pull this in.
Björn, what do you think?
> [...]
next prev parent reply other threads:[~2026-07-20 14:25 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 6:44 [PATCH bpf-next v6 0/7] Mixing bpf2bpf and tailcalls for RV64 Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 6:44 ` [PATCH bpf-next v6 1/7] bpf: Extract the is_struct_ops_tramp helper Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 6:44 ` [PATCH bpf-next v6 2/7] riscv, bpf: Fix memory leak in bpf_jit_free Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 6:54 ` sashiko-bot
2026-07-08 8:51 ` Pu Lehui
2026-07-09 8:46 ` Daniel Borkmann
2026-07-08 6:44 ` [PATCH bpf-next v6 3/7] riscv, bpf: Using kvzalloc_objs to allocate cache buffer Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 6:44 ` [PATCH bpf-next v6 4/7] riscv, bpf: Fix kernel stack corruption in tailcall with CFI Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 6:44 ` [PATCH bpf-next v6 5/7] riscv, bpf: Add RV_TAILCALL_OFFSET macro to format tailcall offset Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 6:44 ` [PATCH bpf-next v6 6/7] riscv, bpf: Mixing bpf2bpf and tailcalls Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-08 7:07 ` sashiko-bot
2026-07-08 8:48 ` Pu Lehui
2026-07-08 7:35 ` bot+bpf-ci
2026-07-08 7:35 ` bot+bpf-ci
2026-07-08 8:54 ` Pu Lehui
2026-07-08 8:54 ` Pu Lehui
2026-07-09 11:37 ` Björn Töpel
2026-07-09 11:37 ` Björn Töpel
2026-07-09 15:09 ` Pu Lehui
2026-07-09 15:09 ` Pu Lehui
2026-07-09 19:51 ` Björn Töpel
2026-07-09 19:51 ` Björn Töpel
2026-07-10 0:53 ` Pu Lehui
2026-07-10 0:53 ` Pu Lehui
2026-07-10 9:43 ` Daniel Borkmann
2026-07-10 9:43 ` Daniel Borkmann
2026-07-17 7:37 ` Pu Lehui
2026-07-17 7:37 ` Pu Lehui
2026-07-20 14:24 ` Kumar Kartikeya Dwivedi [this message]
2026-07-20 14:24 ` Kumar Kartikeya Dwivedi
2026-07-21 18:12 ` Björn Töpel
2026-07-21 18:12 ` Björn Töpel
2026-07-08 6:44 ` [PATCH bpf-next v6 7/7] selftests/bpf: Remove tailcalls tests from DENYLIST.riscv64 Pu Lehui
2026-07-08 6:44 ` Pu Lehui
2026-07-21 18:30 ` [PATCH bpf-next v6 0/7] Mixing bpf2bpf and tailcalls for RV64 patchwork-bot+netdevbpf
2026-07-21 18:30 ` patchwork-bot+netdevbpf
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=DK3GTYQ5UOMO.CVL471XPD0AT@gmail.com \
--to=memxor@gmail.com \
--cc=alex@ghiti.fr \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=pulehui@huawei.com \
--cc=pulehui@huaweicloud.com \
--cc=puranjay@kernel.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.