From: "Björn Töpel" <bjorn@kernel.org>
To: Puranjay Mohan <puranjay12@gmail.com>,
Mark Rutland <mark.rutland@arm.com>,
Andy Chiu <andy.chiu@sifive.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Sami Tolvanen <samitolvanen@google.com>,
Guo Ren <guoren@kernel.org>,
Ley Foon Tan <leyfoon.tan@starfivetech.com>,
Deepak Gupta <debug@rivosinc.com>,
Sia Jee Heng <jeeheng.sia@starfivetech.com>,
Bjorn Topel <bjorn@rivosinc.com>,
Song Shuai <suagrfillet@gmail.com>,
Cl'ement L'eger <cleger@rivosinc.com>,
Al Viro <viro@zeniv.linux.org.uk>,
Jisheng Zhang <jszhang@kernel.org>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org,
Robbin Ehn <rehn@rivosinc.com>
Subject: Re: [RFC PATCH] riscv: Implement HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS
Date: Thu, 14 Mar 2024 16:07:33 +0100 [thread overview]
Message-ID: <87zfv0onre.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <mb61pplvw6grf.fsf@gmail.com>
Puranjay Mohan <puranjay12@gmail.com> writes:
> Björn Töpel <bjorn@kernel.org> writes:
>
>>
>> Hmm, depending on RISC-V's CMODX path, the pro/cons CALL_OPS vs dynamic
>> trampolines changes quite a bit.
>>
>> The more I look at the pains of patching two instruction ("split
>> immediates"), the better "patch data" + one insn patching look.
>
> I was looking at how dynamic trampolines would be implemented for RISC-V.
>
> With CALL-OPS we need to patch the auipc+jalr at function entry only, the
> ops pointer above the function can be patched atomically.
>
> With a dynamic trampoline we need a auipc+jalr pair at function entry to jump
> to the trampoline and then another auipc+jalr pair to jump from trampoline to
> ops->func. When the ops->func is modified, we would need to update the
> auipc+jalr at in the trampoline.
>
> So, I am not sure how to move forward here, CALL-OPS or Dynamic trampolines?
Yeah. Honestly, we need to figure out the patching story prior
choosing the path, so let's start there.
After reading Mark's reply, and discussing with OpenJDK folks (who does
the most crazy text patching on all platforms), having to patch multiple
instructions (where the address materialization is split over multiple
instructions) is a no-go. It's just a too big can of worms. So, if we
can only patch one insn, it's CALL_OPS.
A couple of options (in addition to Andy's), and all require a
per-function landing address ala CALL_OPS) tweaking what Mark is doing
on Arm (given the poor branch range).
...and maybe we'll get RISC-V rainbows/unicorns in the future getting
better reach (full 64b! ;-)).
A) Use auipc/jalr, only patch jalr to take us to a common
dispatcher/trampoline
| <func_trace_target_data_8B> # probably on a data cache-line != func .text to avoid ping-pong
| ...
| func:
| ...make sure ra isn't messed up...
| aupic
| nop <=> jalr # Text patch point -> common_dispatch
| ACTUAL_FUNC
|
| common_dispatch:
| load <func_trace_target_data_8B> based on ra
| jalr
| ...
The auipc is never touched, and will be overhead. Also, we need a mv to
store ra in a scratch register as well -- like Arm. We'll have two insn
per-caller overhead for a disabled caller.
B) Use jal, which can only take us +/-1M, and requires multiple
dispatchers (and tracking which one to use, and properly distribute
them. Ick.)
| <func_trace_target_data_8B> # probably on a data cache-line != func .text to avoid ping-pong
| ...
| func:
| ...make sure ra isn't messed up...
| nop <=> jal # Text patch point -> within_1M_to_func_dispatch
| ACTUAL_FUNC
|
| within_1M_to_func_dispatch:
| load <func_trace_target_data_8B> based on ra
| jalr
C) Use jal, which can only take us +/-1M, and use a per-function
trampoline requires multiple dispatchers (and tracking which one to
use). Blows up text size A LOT.
| <func_trace_target_data_8B> # somewhere, but probably on a different cacheline than the .text to avoid ping-ongs
| ...
| per_func_dispatch
| load <func_trace_target_data_8B> based on ra
| jalr
| func:
| ...make sure ra isn't messed up...
| nop <=> jal # Text patch point -> per_func_dispatch
| ACTUAL_FUNC
It's a bit sad that we'll always have to have a dispatcher/trampoline,
but it's still better than stop_machine(). (And we'll need a fencei IPI
as well, but only one. ;-))
Today, I'm leaning towards A (which is what Mark suggested, and also
Robbin).. Any other options?
[Now how do we implement OPTPROBES? I'm kidding. ;-)]
Björn
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2024-03-14 15:07 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-06 16:59 [RFC PATCH] riscv: Implement HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS Puranjay Mohan
2024-03-06 20:35 ` Alexandre Ghiti
2024-03-06 20:38 ` Alexandre Ghiti
2024-03-07 0:17 ` Puranjay Mohan
2024-03-08 8:48 ` Andy Chiu
2024-03-11 13:56 ` [DMARC Error] " Evgenii Shatokhin
2024-03-07 19:27 ` Björn Töpel
2024-03-07 19:51 ` Puranjay Mohan
2024-03-08 9:18 ` Andy Chiu
2024-03-08 14:13 ` Puranjay Mohan
2024-03-10 1:37 ` Guo Ren
2024-03-08 10:16 ` Björn Töpel
2024-03-08 14:22 ` Puranjay Mohan
2024-03-08 15:15 ` Björn Töpel
2024-03-12 13:42 ` Mark Rutland
2024-03-13 11:23 ` Björn Töpel
2024-03-14 14:16 ` Puranjay Mohan
2024-03-14 15:07 ` Björn Töpel [this message]
2024-03-14 20:50 ` Björn Töpel
2024-03-20 16:41 ` Andy Chiu
2024-03-21 8:48 ` Björn Töpel
2024-03-21 17:39 ` Andy Chiu
2024-03-21 18:10 ` Björn Töpel
2024-03-25 12:50 ` Robbin Ehn
2024-03-20 18:03 ` Mark Rutland
2024-03-21 8:58 ` Björn Töpel
2024-03-21 14:49 ` Steven Rostedt
2024-03-21 20:02 ` Steven Rostedt
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=87zfv0onre.fsf@all.your.base.are.belong.to.us \
--to=bjorn@kernel.org \
--cc=andy.chiu@sifive.com \
--cc=aou@eecs.berkeley.edu \
--cc=bjorn@rivosinc.com \
--cc=cleger@rivosinc.com \
--cc=debug@rivosinc.com \
--cc=guoren@kernel.org \
--cc=jeeheng.sia@starfivetech.com \
--cc=jszhang@kernel.org \
--cc=leyfoon.tan@starfivetech.com \
--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@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=puranjay12@gmail.com \
--cc=rehn@rivosinc.com \
--cc=rostedt@goodmis.org \
--cc=samitolvanen@google.com \
--cc=suagrfillet@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/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