From: "Björn Töpel" <bjorn@kernel.org>
To: Palmer Dabbelt <palmer@rivosinc.com>
Cc: suagrfillet@gmail.com, Paul Walmsley <paul.walmsley@sifive.com>,
aou@eecs.berkeley.edu, rostedt@goodmis.org, mhiramat@kernel.org,
Mark Rutland <mark.rutland@arm.com>,
guoren@kernel.org, suagrfillet@gmail.com,
Bjorn Topel <bjorn@rivosinc.com>,
jszhang@kernel.org, Conor Dooley <conor.dooley@microchip.com>,
pulehui@huawei.com, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
songshuaishuai@tinylab.org, bpf@vger.kernel.org
Subject: Re: [PATCH V11 0/5] riscv: Optimize function trace
Date: Wed, 23 Aug 2023 22:20:29 +0200 [thread overview]
Message-ID: <87zg2hse7m.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <mhng-a2c88f43-3cf7-4caa-8e4a-b0fc9d7e4628@palmer-ri-x1c9a>
Palmer Dabbelt <palmer@rivosinc.com> writes:
> On Wed, 12 Jul 2023 11:11:08 PDT (-0700), bjorn@kernel.org wrote:
>> Song Shuai <suagrfillet@gmail.com> writes:
>>
>> [...]
>>
>>> Add WITH_DIRECT_CALLS support [3] (patch 3, 4)
>>> ==============================================
>>
>> We've had some offlist discussions, so here's some input for a wider
>> audience! Most importantly, this is for Palmer, so that this series is
>> not merged until a proper BPF trampoline fix is in place.
>>
>> Note that what's currently usable from BPF trampoline *works*. It's
>> when this series is added that it breaks.
>>
>> TL;DR This series adds DYNAMIC_FTRACE_WITH_DIRECT_CALLS, which enables
>> fentry/fexit BPF trampoline support. Unfortunately the
>> fexit/BPF_TRAMP_F_SKIP_FRAME parts of the RV BPF trampoline breaks
>> with this addition, and need to be addressed *prior* merging this
>> series. An easy way to reproduce, is just calling any of the kselftest
>> tests that uses fexit patching.
>>
>> The issue is around the nop seld, and how a call is done; The nop sled
>> (patchable-function-entry) size changed from 16B to 8B in commit
>> 6724a76cff85 ("riscv: ftrace: Reduce the detour code size to half"), but
>> BPF code still uses the old 16B. So it'll work for BPF programs, but not
>> for regular kernel functions.
>>
>> An example:
>>
>> | ffffffff80fa4150 <bpf_fentry_test1>:
>> | ffffffff80fa4150: 0001 nop
>> | ffffffff80fa4152: 0001 nop
>> | ffffffff80fa4154: 0001 nop
>> | ffffffff80fa4156: 0001 nop
>> | ffffffff80fa4158: 1141 add sp,sp,-16
>> | ffffffff80fa415a: e422 sd s0,8(sp)
>> | ffffffff80fa415c: 0800 add s0,sp,16
>> | ffffffff80fa415e: 6422 ld s0,8(sp)
>> | ffffffff80fa4160: 2505 addw a0,a0,1
>> | ffffffff80fa4162: 0141 add sp,sp,16
>> | ffffffff80fa4164: 8082 ret
>>
>> is patched to:
>>
>> | ffffffff80fa4150: f70c0297 auipc t0,-150208512
>> | ffffffff80fa4154: eb0282e7 jalr t0,t0,-336
>>
>> The return address to bpf_fentry_test1 is stored in t0 at BPF
>> trampoline entry. Return to the *parent* is in ra. The trampline has
>> to deal with this.
>>
>> For BPF_TRAMP_F_SKIP_FRAME/CALL_ORIG, the BPF trampoline will skip too
>> many bytes, and not correctly handle parent calls.
>>
>> Further; The BPF trampoline currently has a different way of patching
>> the nops for BPF programs, than what ftrace does. That should be changed
>> to match what ftrace does (auipc/jalr t0).
>>
>> To summarize:
>> * Align BPF nop sled with patchable-function-entry: 8B.
>> * Adapt BPF trampoline for 8B nop sleds.
>> * Adapt BPF trampoline t0 return, ra parent scheme.
>
> Thanks for digging into this one, I agree we need to sort out the BPF
> breakages before we merge this. Sounds like there's a rabbit hole here,
> but hopefully we can get it sorted out.
>
> I've dropped this from patchwork and such, as we'll need at least
> another spin.
Palmer,
The needed BPF patch is upstream in the bpf-next tree, and has been for
a couple of weeks.
I think this series is a candidate for RISC-V -next! It would help
RISC-V BPF a lot in terms of completeness.
Björn
next prev parent reply other threads:[~2023-08-23 20:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-27 11:16 Song Shuai
2023-06-27 11:16 ` [PATCH V11 1/5] riscv: select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY Song Shuai
2023-06-27 11:16 ` [PATCH V11 2/5] riscv: ftrace: Add ftrace_graph_func Song Shuai
2023-06-27 11:16 ` [PATCH V11 3/5] riscv: ftrace: Add DYNAMIC_FTRACE_WITH_DIRECT_CALLS support Song Shuai
2023-06-27 11:16 ` [PATCH V11 4/5] samples: ftrace: Add riscv support for SAMPLE_FTRACE_DIRECT[_MULTI] Song Shuai
2023-06-27 11:16 ` [PATCH V11 5/5] samples: ftrace: Make the riscv samples support RV32I Song Shuai
2023-07-06 9:35 ` [PATCH V11 0/5] riscv: Optimize function trace Song Shuai
2023-07-06 9:53 ` Conor Dooley
2023-07-06 10:10 ` Song Shuai
2023-07-12 18:11 ` Björn Töpel
2023-07-12 18:26 ` Palmer Dabbelt
2023-08-23 20:20 ` Björn Töpel [this message]
2023-08-30 15:28 ` Björn Töpel
2023-07-15 9:10 ` 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=87zg2hse7m.fsf@all.your.base.are.belong.to.us \
--to=bjorn@kernel.org \
--cc=aou@eecs.berkeley.edu \
--cc=bjorn@rivosinc.com \
--cc=bpf@vger.kernel.org \
--cc=conor.dooley@microchip.com \
--cc=guoren@kernel.org \
--cc=jszhang@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=palmer@rivosinc.com \
--cc=paul.walmsley@sifive.com \
--cc=pulehui@huawei.com \
--cc=rostedt@goodmis.org \
--cc=songshuaishuai@tinylab.org \
--cc=suagrfillet@gmail.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®