From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Hari Bathini <hbathini@linux.ibm.com>,
linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Cc: Song Liu <songliubraving@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
"Naveen N. Rao" <naveen.n.rao@linux.ibm.com>
Subject: Re: [PATCH v3 2/5] powerpc/bpf: implement bpf_arch_text_invalidate for bpf_prog_pack
Date: Fri, 25 Aug 2023 15:33:18 +0000 [thread overview]
Message-ID: <7df92b0b-d260-addf-fc78-27690d72310f@csgroup.eu> (raw)
In-Reply-To: <20230825151810.164418-3-hbathini@linux.ibm.com>
Le 25/08/2023 à 17:18, Hari Bathini a écrit :
> Implement bpf_arch_text_invalidate and use it to fill unused part of
> the bpf_prog_pack with trap instructions when a BPF program is freed.
>
> Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
> ---
> arch/powerpc/net/bpf_jit_comp.c | 22 +++++++++++++++++++---
> 1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
> index 170ebf8ac0f2..7cd4cf53d61c 100644
> --- a/arch/powerpc/net/bpf_jit_comp.c
> +++ b/arch/powerpc/net/bpf_jit_comp.c
> @@ -30,7 +30,7 @@ static void bpf_jit_fill_ill_insns(void *area, unsigned int size)
> * Patch 'len' bytes of instructions from opcode to addr, one instruction
> * at a time. Returns addr on success. ERR_PTR(-EINVAL), otherwise.
> */
> -static void *bpf_patch_instructions(void *addr, void *opcode, size_t len)
> +static void *bpf_patch_instructions(void *addr, void *opcode, size_t len, bool fill_insn)
It's a pitty that you have to modify in patch 2 a function you have
added in patch 1 of the same series. Can't you have it right from the
begining ?
> {
> while (len > 0) {
> ppc_inst_t insn = ppc_inst_read(opcode);
> @@ -41,7 +41,8 @@ static void *bpf_patch_instructions(void *addr, void *opcode, size_t len)
>
> len -= ilen;
> addr = addr + ilen;
> - opcode = opcode + ilen;
> + if (!fill_insn)
> + opcode = opcode + ilen;
> }
>
> return addr;
> @@ -307,7 +308,22 @@ void *bpf_arch_text_copy(void *dst, void *src, size_t len)
> return ERR_PTR(-EINVAL);
>
> mutex_lock(&text_mutex);
> - ret = bpf_patch_instructions(dst, src, len);
> + ret = bpf_patch_instructions(dst, src, len, false);
> + mutex_unlock(&text_mutex);
> +
> + return ret;
> +}
> +
> +int bpf_arch_text_invalidate(void *dst, size_t len)
> +{
> + u32 insn = BREAKPOINT_INSTRUCTION;
> + int ret;
> +
> + if (WARN_ON_ONCE(core_kernel_text((unsigned long)dst)))
> + return -EINVAL;
> +
> + mutex_lock(&text_mutex);
> + ret = IS_ERR(bpf_patch_instructions(dst, &insn, len, true));
Why IS_ERR ?
As far as I understand from the weak definition in kernel/bpf/core.c,
this function is supposed to return an error, not a bool.
> mutex_unlock(&text_mutex);
>
> return ret;
next prev parent reply other threads:[~2023-08-25 15:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-25 15:18 [PATCH 0/5] powerpc/bpf: use BPF prog pack allocator Hari Bathini
2023-08-25 15:18 ` [PATCH v3 1/5] powerpc/bpf: implement bpf_arch_text_copy Hari Bathini
2023-08-25 15:29 ` Christophe Leroy
2023-08-25 15:18 ` [PATCH v3 2/5] powerpc/bpf: implement bpf_arch_text_invalidate for bpf_prog_pack Hari Bathini
2023-08-25 15:33 ` Christophe Leroy [this message]
2023-08-25 17:37 ` Hari Bathini
2023-08-25 15:18 ` [PATCH v3 3/5] powerpc/bpf: use bpf_jit_binary_pack_[alloc|finalize|free] Hari Bathini
2023-08-25 15:18 ` [PATCH v3 4/5] powerpc/code-patching: introduce patch_instructions() Hari Bathini
2023-08-25 15:18 ` [PATCH v3 5/5] powerpc/bpf: use patch_instructions() Hari Bathini
2023-08-25 15:46 ` Christophe Leroy
2023-08-25 17:43 ` Hari Bathini
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=7df92b0b-d260-addf-fc78-27690d72310f@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=hbathini@linux.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=naveen.n.rao@linux.ibm.com \
--cc=songliubraving@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).