From: Xu Kuohai <xukuohai@huawei.com>
To: Pu Lehui <pulehui@huaweicloud.com>, <bpf@vger.kernel.org>,
<linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Cc: "Björn Töpel" <bjorn@kernel.org>,
"Luke Nelson" <luke.r.nels@gmail.com>,
"Xi Wang" <xi.wang@gmail.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Song Liu" <song@kernel.org>, "Yonghong Song" <yhs@fb.com>,
"John Fastabend" <john.fastabend@gmail.com>,
"KP Singh" <kpsingh@kernel.org>,
"Stanislav Fomichev" <sdf@google.com>,
"Hao Luo" <haoluo@google.com>, "Jiri Olsa" <jolsa@kernel.org>,
"Paul Walmsley" <paul.walmsley@sifive.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Pu Lehui" <pulehui@huawei.com>
Subject: Re: [RFC PATCH RESEND bpf-next 1/4] bpf: Rollback to text_poke when arch not supported ftrace direct call
Date: Tue, 20 Dec 2022 10:32:31 +0800 [thread overview]
Message-ID: <a2bf7ed9-4977-608c-d5a5-8ee6a520cf52@huawei.com> (raw)
In-Reply-To: <20221220021319.1655871-2-pulehui@huaweicloud.com>
On 12/20/2022 10:13 AM, Pu Lehui wrote:
> From: Pu Lehui <pulehui@huawei.com>
>
> The current bpf trampoline attach to kernel functions via ftrace direct
> call API, while text_poke is applied for bpf2bpf attach and tail call
> optimization. For architectures that do not support ftrace direct call,
> text_poke is still able to attach bpf trampoline to kernel functions.
> Let's relax it by rollback to text_poke when architecture not supported.
>
> Signed-off-by: Pu Lehui <pulehui@huawei.com>
> ---
> kernel/bpf/trampoline.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> index d6395215b849..386197a7952c 100644
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c
> @@ -228,15 +228,11 @@ static int modify_fentry(struct bpf_trampoline *tr, void *old_addr, void *new_ad
> static int register_fentry(struct bpf_trampoline *tr, void *new_addr)
> {
> void *ip = tr->func.addr;
> - unsigned long faddr;
> int ret;
>
> - faddr = ftrace_location((unsigned long)ip);
> - if (faddr) {
> - if (!tr->fops)
> - return -ENOTSUPP;
> + if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS) &&
> + !!ftrace_location((unsigned long)ip))
> tr->func.ftrace_managed = true;
> - }
>
After this patch, a kernel function with true trace_location will be patched
by bpf when CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS is disabled, which means
that a kernel function may be patched by both bpf and ftrace in a mutually
unaware way. This will cause ftrace and bpf_arch_text_poke to fail in a
somewhat random way if the function to be patched was already patched
by the other.
> if (bpf_trampoline_module_get(tr))
> return -ENOENT;
next prev parent reply other threads:[~2022-12-20 2:32 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-20 2:13 [RFC PATCH RESEND bpf-next 0/4] Support bpf trampoline for RV64 Pu Lehui
2022-12-20 2:13 ` [RFC PATCH RESEND bpf-next 1/4] bpf: Rollback to text_poke when arch not supported ftrace direct call Pu Lehui
2022-12-20 2:32 ` Xu Kuohai [this message]
2022-12-21 2:36 ` Pu Lehui
2023-01-03 12:05 ` Björn Töpel
2023-01-06 2:35 ` Pu Lehui
2022-12-20 2:13 ` [RFC PATCH RESEND bpf-next 2/4] riscv, bpf: Factor out emit_call for kernel and bpf context Pu Lehui
2022-12-20 2:13 ` [RFC PATCH RESEND bpf-next 3/4] riscv, bpf: Add bpf_arch_text_poke support for RV64 Pu Lehui
2022-12-20 3:00 ` Xu Kuohai
2022-12-22 3:01 ` Pu Lehui
2023-01-03 18:12 ` Björn Töpel
2023-01-06 1:57 ` Pu Lehui
2023-01-06 3:59 ` Pu Lehui
2022-12-20 2:13 ` [RFC PATCH RESEND bpf-next 4/4] riscv, bpf: Add bpf trampoline " Pu Lehui
2023-01-03 19:16 ` Björn Töpel
2023-01-06 1:36 ` Pu Lehui
2022-12-22 13:00 ` [RFC PATCH RESEND bpf-next 0/4] Support bpf trampoline " Björn Töpel
2022-12-24 6:22 ` Pu Lehui
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=a2bf7ed9-4977-608c-d5a5-8ee6a520cf52@huawei.com \
--to=xukuohai@huawei.com \
--cc=andrii@kernel.org \
--cc=aou@eecs.berkeley.edu \
--cc=ast@kernel.org \
--cc=bjorn@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=linux-riscv@lists.infradead.org \
--cc=luke.r.nels@gmail.com \
--cc=martin.lau@linux.dev \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=pulehui@huawei.com \
--cc=pulehui@huaweicloud.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=xi.wang@gmail.com \
--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
all inboxes | Powered by JetHome®