From: Hari Bathini <hbathini@linux.ibm.com>
To: 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, christophe.leroy@csgroup.eu,
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 1/6] powerpc64/bpf: Move tail_call_cnt to bottom of stack frame
Date: Sat, 17 Jan 2026 16:29:26 +0530 [thread overview]
Message-ID: <05f17f8b-4cbb-4d17-81f3-ada2ac12ce6b@linux.ibm.com> (raw)
In-Reply-To: <3e1c5930518113f349625cfa80ce82f5@imap.linux.ibm.com>
On 17/01/26 4:11 pm, adubey wrote:
> On 2026-01-17 15:41, Hari Bathini wrote:
>> On 14/01/26 5:14 pm, adubey@linux.ibm.com wrote:
>>> From: Abhishek Dubey <adubey@linux.ibm.com>
>>>
>>> In the conventional stack frame, the position of tail_call_cnt
>>> is after the NVR save area (BPF_PPC_STACK_SAVE). Whereas, the
>>> offset of tail_call_cnt in the trampoline frame is after the
>>> stack alignment padding. BPF JIT logic could become complex
>>> when dealing with frame-sensitive offset calculation of
>>> tail_call_cnt. Having the same offset in both frames is the
>>> desired objective.
>>>
>>> The trampoline frame does not have a BPF_PPC_STACK_SAVE area.
>>> Introducing it leads to under-utilization of extra memory meant
>>> only for the offset alignment of tail_call_cnt.
>>> Another challenge is the variable alignment padding sitting at
>>> the bottom of the trampoline frame, which requires additional
>>> handling to compute tail_call_cnt offset.
>>>
>>> This patch addresses the above issues by moving tail_call_cnt
>>> to the bottom of the stack frame at offset 0 for both types
>>> of frames. This saves additional bytes required by BPF_PPC_STACK_SAVE
>>> in trampoline frame, and a common offset computation for
>>> tail_call_cnt serves both frames.
>>>
>>> The changes in this patch are required by the third patch in the
>>> series, where the 'reference to tail_call_info' of the main frame
>>> is copied into the trampoline frame from the previous frame.
>>>
>>> Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com>
>>> ---
>>> arch/powerpc/net/bpf_jit.h | 4 ++++
>>> arch/powerpc/net/bpf_jit_comp64.c | 31 ++++++++++++++++++++-----------
>>> 2 files changed, 24 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h
>>> index 8334cd667bba..45d419c0ee73 100644
>>> --- a/arch/powerpc/net/bpf_jit.h
>>> +++ b/arch/powerpc/net/bpf_jit.h
>>> @@ -72,6 +72,10 @@
>>> } } while (0)
>>> #ifdef CONFIG_PPC64
>>> +
>>> +/* for tailcall counter */
>>> +#define BPF_PPC_TAILCALL 8
>>> +
>>> /* If dummy pass (!image), account for maximum possible
>>> instructions */
>>> #define PPC_LI64(d, i) do { \
>>> if (!image) \
>>> diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/
>>> bpf_jit_comp64.c
>>> index 1fe37128c876..39061cd742c1 100644
>>> --- a/arch/powerpc/net/bpf_jit_comp64.c
>>> +++ b/arch/powerpc/net/bpf_jit_comp64.c
>>> @@ -20,13 +20,15 @@
>>> #include "bpf_jit.h"
>>> /*
>>> - * Stack layout:
>>> + * Stack layout 1:
>>> + * Layout when setting up our own stack frame.
>>> + * Note: r1 at bottom, component offsets positive wrt r1.
>>> * Ensure the top half (upto local_tmp_var) stays consistent
>>> * with our redzone usage.
>>> *
>>> * [ prev sp ] <-------------
>>> - * [ nv gpr save area ] 6*8 |
>>> * [ tail_call_cnt ] 8 |
>>> + * [ nv gpr save area ] 6*8 |
>>> * [ local_tmp_var ] 24 |
>>> * fp (r31) --> [ ebpf stack space ] upto 512 |
>>> * [ frame header ] 32/112 |
>>> @@ -36,10 +38,12 @@
>>> /* for gpr non volatile registers BPG_REG_6 to 10 */
>>> #define BPF_PPC_STACK_SAVE (6*8)
>>> /* for bpf JIT code internal usage */
>>> -#define BPF_PPC_STACK_LOCALS 32
>>> +#define BPF_PPC_STACK_LOCALS 24
>>> /* stack frame excluding BPF stack, ensure this is quadword aligned */
>>> #define BPF_PPC_STACKFRAME (STACK_FRAME_MIN_SIZE + \
>>> - BPF_PPC_STACK_LOCALS + BPF_PPC_STACK_SAVE)
>>> + BPF_PPC_STACK_LOCALS + \
>>> + BPF_PPC_STACK_SAVE + \
>>> + BPF_PPC_TAILCALL)
>>> /* BPF register usage */
>>> #define TMP_REG_1 (MAX_BPF_JIT_REG + 0)
>>> @@ -87,27 +91,32 @@ static inline bool bpf_has_stack_frame(struct
>>> codegen_context *ctx)
>>> }
>>>
>>
>>> /*
>>> + * Stack layout 2:
>>> * When not setting up our own stackframe, the redzone (288 bytes)
>>> usage is:
>>> + * Note: r1 from prev frame. Component offset negative wrt r1.
>>> *
>>> * [ prev sp ] <-------------
>>> * [ ... ] |
>>> * sp (r1) ---> [ stack pointer ] --------------
>>> - * [ nv gpr save area ] 6*8
>>> * [ tail_call_cnt ] 8
>>> + * [ nv gpr save area ] 6*8
>>> * [ local_tmp_var ] 24
>>> * [ unused red zone ] 224
>>> */
>>
>> Calling it stack layout 1 & 2 is inappropriate. The stack layout
>> is essentially the same. It just goes to show things with reference
>> to r1 when stack is setup explicitly vs when redzone is being used...
> Agree. I am using it as labels to refer in comment. Any better suggestions?
I think the comments could refer to has stack frame vs Redzone case..
- Hari
next prev parent reply other threads:[~2026-01-17 11:01 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 [this message]
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
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=05f17f8b-4cbb-4d17-81f3-ada2ac12ce6b@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=christophe.leroy@csgroup.eu \
--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