From: "Björn Töpel" <bjorn@kernel.org>
To: Guo Ren <guoren@kernel.org>, "liaochang (A)" <liaochang1@huawei.com>
Cc: palmer@dabbelt.com, paul.walmsley@sifive.com,
mhiramat@kernel.org, conor.dooley@microchip.com,
penberg@kernel.org, mark.rutland@arm.com,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
Guo Ren <guoren@linux.alibaba.com>
Subject: Re: [PATCH] riscv: kprobe: Optimize kprobe with accurate atomicity
Date: Mon, 30 Jan 2023 16:28:15 +0100 [thread overview]
Message-ID: <87r0vc9h4g.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <CAJF2gTS0s4X_uwLaEeSqKAyRmxCR2vxRuHhz7-SP2w4bBqzr+Q@mail.gmail.com>
Guo Ren <guoren@kernel.org> writes:
>> In the serie of RISCV OPTPROBES [1], it patches a long-jump instructions pair
>> AUIPC/JALR in kernel text, so in order to ensure other CPUs does not execute
>> in the instructions that will be modified, it is still need to stop other CPUs
>> via patch_text API, or you have any better solution to achieve the purpose?
> - The stop_machine is an expensive way all architectures should
> avoid, and you could keep that in your OPTPROBES implementation files
> with static functions.
> - The stop_machine couldn't work with PREEMPTION, so your
> implementation needs to work with !PREEMPTION.
...and stop_machine() with !PREEMPTION is broken as well, when you're
replacing multiple instructions (see Mark's post at [1]). The
stop_machine() dance might work when you're replacing *one* instruction,
not multiple as in the RISC-V case. I'll expand on this in a comment in
the OPTPROBES v6 series.
>> > static void __kprobes arch_prepare_simulate(struct kprobe *p)
>> > @@ -114,16 +120,23 @@ void *alloc_insn_page(void)
>> > /* install breakpoint in text */
>> > void __kprobes arch_arm_kprobe(struct kprobe *p)
>> > {
>> > - if ((p->opcode & __INSN_LENGTH_MASK) == __INSN_LENGTH_32)
>> > - patch_text(p->addr, __BUG_INSN_32);
>> > - else
>> > - patch_text(p->addr, __BUG_INSN_16);
>> > +#ifdef CONFIG_RISCV_ISA_C
>> > + u32 opcode = __BUG_INSN_16;
>> > +#else
>> > + u32 opcode = __BUG_INSN_32;
>> > +#endif
>> > + patch_text_nosync(p->addr, &opcode, GET_INSN_LENGTH(opcode));
>>
>> Sounds good, but it will leave some RVI instruction truncated in kernel text,
>> i doubt kernel behavior depends on the rest of the truncated instruction, well,
>> it needs more strict testing to prove my concern :)
> I do this on purpose, and it doesn't cause any problems. Don't worry;
> IFU hw must enforce the fetch sequence, and there is no way to execute
> broken instructions even in the speculative execution path.
This is stretching reality a bit much. ARMv8, e.g., has a chapter in the
Arm ARM [2] Appendix B "Concurrent modification and execution of
instructions" (CMODX). *Some* instructions can be replaced concurrently,
and others cannot without caution. Assuming that that all RISC-V
implementations can, is a stretch. RISC-V hasn't even specified the
behavior of CMODX (which is problematic).
If anything it would be more likely that the existing
"stop_machine()-to-replace-with-ebreak" works (again, replacing one
instruction does not have the !PREEMPTION issues). Then again, no spec,
so mostly guessing from my side. :-(
Oh, but the existing "ebreak replace" might be broken like [3].
Björn
[1] https://lore.kernel.org/linux-riscv/Y7%2F6AtX5X0+5qF6Y@FVFF77S0Q05N/
[2] https://developer.arm.com/documentation/ddi0487/latest
[3] https://lore.kernel.org/linux-riscv/20230126170607.1489141-2-guoren@kernel.org/
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: "Björn Töpel" <bjorn@kernel.org>
To: Guo Ren <guoren@kernel.org>, "liaochang (A)" <liaochang1@huawei.com>
Cc: palmer@dabbelt.com, paul.walmsley@sifive.com,
mhiramat@kernel.org, conor.dooley@microchip.com,
penberg@kernel.org, mark.rutland@arm.com,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
Guo Ren <guoren@linux.alibaba.com>
Subject: Re: [PATCH] riscv: kprobe: Optimize kprobe with accurate atomicity
Date: Mon, 30 Jan 2023 16:28:15 +0100 [thread overview]
Message-ID: <87r0vc9h4g.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <CAJF2gTS0s4X_uwLaEeSqKAyRmxCR2vxRuHhz7-SP2w4bBqzr+Q@mail.gmail.com>
Guo Ren <guoren@kernel.org> writes:
>> In the serie of RISCV OPTPROBES [1], it patches a long-jump instructions pair
>> AUIPC/JALR in kernel text, so in order to ensure other CPUs does not execute
>> in the instructions that will be modified, it is still need to stop other CPUs
>> via patch_text API, or you have any better solution to achieve the purpose?
> - The stop_machine is an expensive way all architectures should
> avoid, and you could keep that in your OPTPROBES implementation files
> with static functions.
> - The stop_machine couldn't work with PREEMPTION, so your
> implementation needs to work with !PREEMPTION.
...and stop_machine() with !PREEMPTION is broken as well, when you're
replacing multiple instructions (see Mark's post at [1]). The
stop_machine() dance might work when you're replacing *one* instruction,
not multiple as in the RISC-V case. I'll expand on this in a comment in
the OPTPROBES v6 series.
>> > static void __kprobes arch_prepare_simulate(struct kprobe *p)
>> > @@ -114,16 +120,23 @@ void *alloc_insn_page(void)
>> > /* install breakpoint in text */
>> > void __kprobes arch_arm_kprobe(struct kprobe *p)
>> > {
>> > - if ((p->opcode & __INSN_LENGTH_MASK) == __INSN_LENGTH_32)
>> > - patch_text(p->addr, __BUG_INSN_32);
>> > - else
>> > - patch_text(p->addr, __BUG_INSN_16);
>> > +#ifdef CONFIG_RISCV_ISA_C
>> > + u32 opcode = __BUG_INSN_16;
>> > +#else
>> > + u32 opcode = __BUG_INSN_32;
>> > +#endif
>> > + patch_text_nosync(p->addr, &opcode, GET_INSN_LENGTH(opcode));
>>
>> Sounds good, but it will leave some RVI instruction truncated in kernel text,
>> i doubt kernel behavior depends on the rest of the truncated instruction, well,
>> it needs more strict testing to prove my concern :)
> I do this on purpose, and it doesn't cause any problems. Don't worry;
> IFU hw must enforce the fetch sequence, and there is no way to execute
> broken instructions even in the speculative execution path.
This is stretching reality a bit much. ARMv8, e.g., has a chapter in the
Arm ARM [2] Appendix B "Concurrent modification and execution of
instructions" (CMODX). *Some* instructions can be replaced concurrently,
and others cannot without caution. Assuming that that all RISC-V
implementations can, is a stretch. RISC-V hasn't even specified the
behavior of CMODX (which is problematic).
If anything it would be more likely that the existing
"stop_machine()-to-replace-with-ebreak" works (again, replacing one
instruction does not have the !PREEMPTION issues). Then again, no spec,
so mostly guessing from my side. :-(
Oh, but the existing "ebreak replace" might be broken like [3].
Björn
[1] https://lore.kernel.org/linux-riscv/Y7%2F6AtX5X0+5qF6Y@FVFF77S0Q05N/
[2] https://developer.arm.com/documentation/ddi0487/latest
[3] https://lore.kernel.org/linux-riscv/20230126170607.1489141-2-guoren@kernel.org/
next prev parent reply other threads:[~2023-01-30 16:03 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-26 16:15 [PATCH] riscv: kprobe: Optimize kprobe with accurate atomicity guoren
2023-01-26 16:15 ` guoren
2023-01-28 3:52 ` liaochang (A)
2023-01-28 3:52 ` liaochang (A)
2023-01-28 4:45 ` Guo Ren
2023-01-28 4:45 ` Guo Ren
2023-01-30 15:28 ` Björn Töpel [this message]
2023-01-30 15:28 ` Björn Töpel
2023-01-30 15:49 ` Mark Rutland
2023-01-30 15:49 ` Mark Rutland
2023-01-30 16:56 ` Björn Töpel
2023-01-30 16:56 ` Björn Töpel
2023-01-31 1:48 ` Guo Ren
2023-01-31 1:48 ` Guo Ren
2023-01-31 7:12 ` Björn Töpel
2023-01-31 7:12 ` Björn Töpel
2023-01-31 8:30 ` Guo Ren
2023-01-31 8:30 ` Guo Ren
2023-01-31 10:33 ` Mark Rutland
2023-01-31 10:33 ` Mark Rutland
2023-02-16 15:23 ` Masami Hiramatsu
2023-02-16 15:23 ` Masami Hiramatsu
2023-02-20 10:35 ` Mark Rutland
2023-02-20 10:35 ` Mark Rutland
2023-02-21 1:30 ` Guo Ren
2023-02-21 1:30 ` Guo Ren
2023-01-31 1:01 ` Guo Ren
2023-01-31 1:01 ` Guo Ren
2023-01-31 1:09 ` Guo Ren
2023-01-31 1:09 ` Guo Ren
2023-01-31 7:03 ` Björn Töpel
2023-01-31 7:03 ` Björn Töpel
2023-01-31 8:27 ` Guo Ren
2023-01-31 8:27 ` Guo Ren
2023-01-31 6:40 ` Björn Töpel
2023-01-31 6:40 ` Björn Töpel
2023-01-31 8:15 ` Guo Ren
2023-01-31 8:15 ` Guo Ren
2023-01-31 10:56 ` Andrea Parri
2023-01-31 10:56 ` Andrea Parri
2023-01-31 13:23 ` Guo Ren
2023-01-31 13:23 ` Guo Ren
2023-02-16 7:54 ` Björn Töpel
2023-02-16 7:54 ` Björn Töpel
2023-02-17 2:28 ` Guo Ren
2023-02-17 2:28 ` Guo Ren
2023-02-17 7:32 ` Björn Töpel
2023-02-17 7:32 ` Björn Töpel
2023-02-21 1:56 ` Guo Ren
2023-02-21 1:56 ` Guo Ren
2023-02-16 15:42 ` Masami Hiramatsu
2023-02-16 15:42 ` Masami Hiramatsu
2023-02-21 0:57 ` Guo Ren
2023-02-21 0:57 ` Guo Ren
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=87r0vc9h4g.fsf@all.your.base.are.belong.to.us \
--to=bjorn@kernel.org \
--cc=conor.dooley@microchip.com \
--cc=guoren@kernel.org \
--cc=guoren@linux.alibaba.com \
--cc=liaochang1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=penberg@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.