From: Hari Bathini <hbathini@linux.ibm.com>
To: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
adubey <adubey@imap.linux.ibm.com>
Cc: adubey@linux.ibm.com, bpf@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, sachinpb@linux.ibm.com,
venkat88@linux.ibm.com, andrii@kernel.org, eddyz87@gmail.com,
mykolal@fb.com, ast@kernel.org, daniel@iogearbox.net,
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, naveen@kernel.org,
maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
memxor@gmail.com, iii@linux.ibm.com, shuah@kernel.org
Subject: Re: [PATCH v2 2/6] powerpc64/bpf: Support tailcalls with subprogs
Date: Fri, 16 Jan 2026 19:29:02 +0530 [thread overview]
Message-ID: <051521cf-5dd2-4831-ab4c-b0db32436ba9@linux.ibm.com> (raw)
In-Reply-To: <ea66ddc5-984f-4873-993d-9de1140d7e6e@kernel.org>
On 16/01/26 1:19 pm, Christophe Leroy (CS GROUP) wrote:
>
>
> Le 16/01/2026 à 05:50, Hari Bathini a écrit :
>
> Not received this mail that Hari is reponding to.
That is weird.
>>
>>
>> On 14/01/26 6:33 pm, adubey wrote:
>>> On 2026-01-14 17:57, Christophe Leroy (CS GROUP) wrote:
>>>> Le 14/01/2026 à 12:44, adubey@linux.ibm.com a écrit :
>>>>> From: Abhishek Dubey <adubey@linux.ibm.com>
>>>>>
>>>>> Enabling tailcalls with subprog combinations by referencing
>>>>> method. The actual tailcall count is always maintained in the
>>>>> tail_call_info variable present in the frame of main function
>>>>> (also called entry function). The tail_call_info variables in
>>>>> the frames of all other subprog contains reference to the
>>>>> tail_call_info present in frame of main function.
>>>>>
>>>>> Dynamic resolution interprets the tail_call_info either as
>>>>> value or reference depending on the context of active frame
>>>>> while tailcall is invoked.
>>>>>
>>>>> Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com>
>>>>> ---
>>>>> arch/powerpc/net/bpf_jit.h | 12 +++++-
>>>>> arch/powerpc/net/bpf_jit_comp.c | 10 ++++-
>>>>> arch/powerpc/net/bpf_jit_comp64.c | 68 ++++++++++++++++++++++
>>>>> +--------
>>>>> 3 files changed, 70 insertions(+), 20 deletions(-)
>>>>>
>>>>> diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h
>>>>> index 45d419c0ee73..5d735bc5e6bd 100644
>>>>> --- a/arch/powerpc/net/bpf_jit.h
>>>>> +++ b/arch/powerpc/net/bpf_jit.h
>>>>> @@ -51,6 +51,12 @@
>>>>> EMIT(PPC_INST_BRANCH_COND | (((cond) & 0x3ff) << 16) |
>>>>> (offset & 0xfffc)); \
>>>>> } while (0)
>>>>> +/* Same as PPC_BCC_SHORT, except valid dest is known prior to
>>>>> call. */
>>>>> +#define PPC_COND_BRANCH(cond, dest) \
>>>>> + do { \
>>>>> + long offset = (long)(dest) - CTX_NIA(ctx); \
>>>>> + EMIT(PPC_INST_BRANCH_COND | (((cond) & 0x3ff) << 16) |
>>>>> (offset & 0xfffc)); \
>>>>> + } while (0)
>>>>
>>>> I don't like the idea of duplicating PPC_BCC_SHORT() to just kick the
>>>> verification out. Now we will have two macros doing the exact same
>>>> thing with one handling failure case and one ignoring failure case.
>>>> There is a big risk that one day or another someone will use the wrong
>>>> macro.
>>>>
>>>> Could you change bpf_jit_build_prologue() to return an int add use
>>>> PPC_BCC_SHORT() instead of that new PPC_COND_BRANCH() ?
>>> I implemented exactly same change in bpf_jit_build_prologue(). But,
>>> during internal review, @HariBathini suggested
>>> to have separate macro with a caution note.
>>>
>>> @Hari please suggest here!
>>
>> Not just about the change of return type but the check seems like an
>> overkill for cases where the offset is known and within branch range.
>> How about using BUILD_BUG_ON() to avoid unecessary checks and
>> return type change for places where the branch offset is known
>> and is a constant?
>
> When offset is a constant known at build time, checks are eliminated by
> gcc at build, see exemple below from disasembly of bpf_jit_comp32.o,
> there are no checks.
>
> PPC_BCC_SHORT(COND_GT, (ctx->idx + 4) *
> 4);
> 36d8: 3c 80 41 81 lis r4,16769
> EMIT(PPC_RAW_CMPLW(src_reg, _R0));
> 36dc: 81 3f 00 04 lwz r9,4(r31)
> PPC_BCC_SHORT(COND_GT, (ctx->idx + 4) *
> 4);
> 36e0: 60 84 00 10 ori r4,r4,16
> EMIT(PPC_RAW_CMPLW(src_reg, _R0));
> 36e4: 39 29 00 01 addi r9,r9,1
> PPC_BCC_SHORT(COND_GT, (ctx->idx + 4) *
> 4);
> 36e8: 55 23 10 3a slwi r3,r9,2
> EMIT(PPC_RAW_CMPLW(src_reg, _R0));
> 36ec: 91 3f 00 04 stw r9,4(r31)
> PPC_BCC_SHORT(COND_GT, (ctx->idx + 4) *
> 4);
> 36f0: 7c 97 19 2e stwx r4,r23,r3
> EMIT(PPC_RAW_LI(dst_reg, 0));
> 36f4: 55 49 a9 94 rlwinm r9,r10,21,6,10
> PPC_BCC_SHORT(COND_GT, (ctx->idx + 4) *
> 4);
> 36f8: 80 9f 00 04 lwz r4,4(r31)
> EMIT(PPC_RAW_LI(dst_reg, 0));
> 36fc: 65 29 38 00 oris r9,r9,14336
> PPC_BCC_SHORT(COND_GT, (ctx->idx + 4) *
> 4);
> 3700: 38 84 00 01 addi r4,r4,1
> EMIT(PPC_RAW_LI(dst_reg, 0));
> 3704: 54 83 10 3a slwi r3,r4,2
> PPC_BCC_SHORT(COND_GT, (ctx->idx + 4) *
> 4);
> 3708: 90 9f 00 04 stw r4,4(r31)
> EMIT(PPC_RAW_LI(dst_reg, 0));
> 370c: 7d 37 19 2e stwx r9,r23,r3
>
Interesting. I do see is_offset_in_cond_branch_range() in action with
constant offsets too, on ppc64 compile at least. fwiw, I had this
optimized version in mind for constant offset:
#define PPC_BCC_CONST_SHORT(cond, offset)
\
do {
\
BUILD_BUG_ON(offset < -0x8000 || offset > 0x7fff ||
(offset & 0x3)); \
EMIT(PPC_INST_BRANCH_COND | (((cond) & 0x3ff) << 16) |
(offset & 0xfffc)); \
} while (0)
With that, something like:
PPC_BCC_SHORT(COND_NE, (ctx->idx + 3) * 4);
becomes
PPC_BCC_CONST_SHORT(COND_NE, 12);
- Hari
next prev parent reply other threads:[~2026-01-16 14:00 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-14 11:44 [PATCH v2 0/6] powerpc64/bpf: Support tailcalls with subprogs & BPF exceptions adubey
2026-01-14 11:44 ` [PATCH v2 1/6] powerpc64/bpf: Move tail_call_cnt to bottom of stack frame adubey
2026-01-14 12:25 ` bot+bpf-ci
2026-01-15 8:29 ` Christophe Leroy (CS GROUP)
2026-01-17 10:11 ` Hari Bathini
[not found] ` <3e1c5930518113f349625cfa80ce82f5@imap.linux.ibm.com>
2026-01-17 10:59 ` Hari Bathini
2026-01-14 11:44 ` [PATCH v2 2/6] powerpc64/bpf: Support tailcalls with subprogs adubey
2026-01-14 12:27 ` Christophe Leroy (CS GROUP)
[not found] ` <2d242f4476b61373da236d24272b0ec3@imap.linux.ibm.com>
2026-01-16 4:50 ` Hari Bathini
2026-01-16 7:49 ` Christophe Leroy (CS GROUP)
2026-01-16 13:59 ` Hari Bathini [this message]
2026-01-17 10:23 ` Hari Bathini
2026-01-14 11:44 ` [PATCH v2 3/6] powerpc64/bpf: Tailcall handling with trampolines adubey
2026-01-14 12:25 ` bot+bpf-ci
2026-01-14 19:39 ` kernel test robot
2026-01-17 10:39 ` Hari Bathini
2026-01-17 10:41 ` Hari Bathini
2026-01-14 11:44 ` [PATCH v2 4/6] powerpc64/bpf: Add arch_bpf_stack_walk() for BPF JIT adubey
2026-01-14 12:37 ` Christophe Leroy (CS GROUP)
[not found] ` <bec1dfbacced0198fa76bc59e73811c6@imap.linux.ibm.com>
2026-01-16 5:38 ` Hari Bathini
2026-01-14 11:44 ` [PATCH v2 5/6] powerpc64/bpf: Support exceptions adubey
2026-01-16 6:27 ` Hari Bathini
[not found] ` <77a6a07add66189fbc9b68a410911e3c@imap.linux.ibm.com>
[not found] ` <cf1aea1601d03d42b3afde367c29d26b@imap.linux.ibm.com>
2026-01-16 7:48 ` Hari Bathini
2026-01-14 11:44 ` [PATCH v2 6/6] powerpc64/bpf: Additional NVR handling for bpf_throw adubey
2026-01-14 12:35 ` bot+bpf-ci
2026-01-17 10:51 ` Hari Bathini
2026-01-14 12:28 ` [PATCH v2 0/6] powerpc64/bpf: Support tailcalls with subprogs & BPF exceptions Christophe Leroy (CS GROUP)
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=051521cf-5dd2-4831-ab4c-b0db32436ba9@linux.ibm.com \
--to=hbathini@linux.ibm.com \
--cc=adubey@imap.linux.ibm.com \
--cc=adubey@linux.ibm.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chleroy@kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=iii@linux.ibm.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mpe@ellerman.id.au \
--cc=mykolal@fb.com \
--cc=naveen@kernel.org \
--cc=npiggin@gmail.com \
--cc=sachinpb@linux.ibm.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=venkat88@linux.ibm.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox