From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>
Cc: Hao Luo <haoluo@google.com>,
Daniel Borkmann <daniel@iogearbox.net>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Stanislav Fomichev <sdf@google.com>,
Jiri Olsa <jolsa@kernel.org>, KP Singh <kpsingh@kernel.org>,
Yonghong Song <yhs@fb.com>,
"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Subject: Re: [PATCH v1 06/10] powerpc/bpf: Perform complete extra passes to update addresses
Date: Tue, 31 Jan 2023 09:52:16 +0000 [thread overview]
Message-ID: <d53644df-7f02-00fb-f022-58ce2436a245@csgroup.eu> (raw)
In-Reply-To: <1673339740.lyeaje9o3l.naveen@linux.ibm.com>
Le 10/01/2023 à 09:44, Naveen N. Rao a écrit :
> Christophe Leroy wrote:
>>
>>
>> Le 13/12/2022 à 11:23, Naveen N. Rao a écrit :
>>> Christophe Leroy wrote:
>>>> BPF core calls the jit compiler again for an extra pass in order
>>>> to properly set subprog addresses.
>>>>
>>>> Unlike other architectures, powerpc only updates the addresses
>>>> during that extra pass. It means that holes must have been left
>>>> in the code in order to enable the maximum possible instruction
>>>> size.
>>>>
>>>> In order avoid waste of space, and waste of CPU time on powerpc
>>>> processors on which the NOP instruction is not 0-cycle, perform
>>>> two real additional passes.
>>>>
>>>> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
>>>> ---
>>>> arch/powerpc/net/bpf_jit_comp.c | 85 ---------------------------------
>>>> 1 file changed, 85 deletions(-)
>>>>
>>>> diff --git a/arch/powerpc/net/bpf_jit_comp.c
>>>> b/arch/powerpc/net/bpf_jit_comp.c
>>>> index 43e634126514..8833bf23f5aa 100644
>>>> --- a/arch/powerpc/net/bpf_jit_comp.c
>>>> +++ b/arch/powerpc/net/bpf_jit_comp.c
>>>> @@ -23,74 +23,6 @@ static void bpf_jit_fill_ill_insns(void *area,
>>>> unsigned int size)
>>>> memset32(area, BREAKPOINT_INSTRUCTION, size / 4);
>>>> }
>>>>
>>>> -/* Fix updated addresses (for subprog calls, ldimm64, et al) during
>>>> extra pass */
>>>> -static int bpf_jit_fixup_addresses(struct bpf_prog *fp, u32 *image,
>>>> - struct codegen_context *ctx, u32 *addrs)
>>>> -{
>>>> - const struct bpf_insn *insn = fp->insnsi;
>>>> - bool func_addr_fixed;
>>>> - u64 func_addr;
>>>> - u32 tmp_idx;
>>>> - int i, j, ret;
>>>> -
>>>> - for (i = 0; i < fp->len; i++) {
>>>> - /*
>>>> - * During the extra pass, only the branch target addresses for
>>>> - * the subprog calls need to be fixed. All other instructions
>>>> - * can left untouched.
>>>> - *
>>>> - * The JITed image length does not change because we already
>>>> - * ensure that the JITed instruction sequence for these calls
>>>> - * are of fixed length by padding them with NOPs.
>>>> - */
>>>> - if (insn[i].code == (BPF_JMP | BPF_CALL) &&
>>>> - insn[i].src_reg == BPF_PSEUDO_CALL) {
>>>> - ret = bpf_jit_get_func_addr(fp, &insn[i], true,
>>>> - &func_addr,
>>>> - &func_addr_fixed);
>>>
>>> I don't see you updating calls to bpf_jit_get_func_addr() in
>>> bpf_jit_build_body() to set extra_pass to true. Afaics, that's
>>> required to get the correct address to be branched to for subprogs.
>>>
>>
>> I don't understand what you mean.
>
> I am referring to the third parameter we pass to bpf_jit_get_func_addr().
>
> In bpf_jit_build_body(), we do:
>
> case BPF_JMP | BPF_CALL:
> ctx->seen |= SEEN_FUNC;
>
> ret = bpf_jit_get_func_addr(fp, &insn[i], false,
> &func_addr, &func_addr_fixed);
>
>
> The third parameter (extra_pass) to bpf_jit_get_func_addr() is set to
> false. In bpf_jit_get_func_addr(), we have:
>
> *func_addr_fixed = insn->src_reg != BPF_PSEUDO_CALL;
> if (!*func_addr_fixed) {
> /* Place-holder address till the last pass has collected
> * all addresses for JITed subprograms in which case we
> * can pick them up from prog->aux.
> */
> if (!extra_pass)
> addr = NULL;
>
> Before this patch series, in bpf_jit_fixup_addresses(), we were calling
> bpf_jit_get_func_addr() with the third parameter set to true.
Ah right, I see.
I will send out v2 shortly.
Thanks
Christophe
next prev parent reply other threads:[~2023-01-31 9:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-01 7:56 [PATCH v1 01/10] powerpc/bpf/32: Fix Oops on tail call tests Christophe Leroy
2022-12-01 7:56 ` [PATCH v1 02/10] powerpc: Remove __kernel_text_address() in show_instructions() Christophe Leroy
2022-12-01 7:56 ` [PATCH v1 03/10] powerpc/bpf/32: No need to zeroise r4 when not doing tail call Christophe Leroy
2022-12-01 7:56 ` [PATCH v1 04/10] powerpc/bpf/32: Only set a stack frame when necessary Christophe Leroy
2022-12-01 7:56 ` [PATCH v1 05/10] powerpc/bpf/32: BPF prog is never called with more than one arg Christophe Leroy
2022-12-01 7:56 ` [PATCH v1 06/10] powerpc/bpf: Perform complete extra passes to update addresses Christophe Leroy
2022-12-13 10:23 ` Naveen N. Rao
2022-12-19 19:06 ` Christophe Leroy
2023-01-10 8:44 ` Naveen N. Rao
2023-01-31 9:52 ` Christophe Leroy [this message]
2022-12-01 7:56 ` [PATCH v1 07/10] powerpc/bpf: Only pad length-variable code at initial pass Christophe Leroy
2022-12-01 7:56 ` [PATCH v1 08/10] powerpc/bpf/32: Optimise some particular const operations Christophe Leroy
2022-12-01 7:56 ` [PATCH v1 09/10] powerpc/bpf/32: introduce a second source register for ALU operations Christophe Leroy
2022-12-01 7:56 ` [PATCH v1 10/10] powerpc/bpf/32: perform three operands " Christophe Leroy
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=d53644df-7f02-00fb-f022-58ce2436a245@csgroup.eu \
--to=christophe.leroy@csgroup.eu \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=martin.lau@linux.dev \
--cc=mpe@ellerman.id.au \
--cc=naveen.n.rao@linux.vnet.ibm.com \
--cc=npiggin@gmail.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yhs@fb.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: 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;
as well as URLs for NNTP newsgroup(s).