mbox series

[0/7] riscv: Various text patching improvements

Message ID 20240212025529.1971876-1-samuel.holland@sifive.com (mailing list archive)
Headers show
Series riscv: Various text patching improvements | expand

Message

Samuel Holland Feb. 12, 2024, 2:55 a.m. UTC
Here are a few changes to minimize calls to stop_machine() and
flush_icache_*() in the various text patching functions, as well as
to simplify the code.


Samuel Holland (7):
  riscv: jump_label: Batch icache maintenance
  riscv: jump_label: Simplify assembly syntax
  riscv: kprobes: Use patch_text_nosync() for insn slots
  riscv: Simplify text patching loops
  riscv: Pass patch_text() the length in bytes
  riscv: Use offset_in_page() in text patching functions
  riscv: Remove extra variable in patch_text_nosync()

 arch/riscv/include/asm/jump_label.h |  4 ++-
 arch/riscv/include/asm/patch.h      |  3 +-
 arch/riscv/kernel/jump_label.c      | 16 ++++++---
 arch/riscv/kernel/patch.c           | 56 +++++++++++++----------------
 arch/riscv/kernel/probes/kprobes.c  | 20 ++++++-----
 arch/riscv/net/bpf_jit_comp64.c     |  7 ++--
 6 files changed, 56 insertions(+), 50 deletions(-)

Comments

Andrea Parri Feb. 13, 2024, 12:58 p.m. UTC | #1
Hi Samuel,

On Sun, Feb 11, 2024 at 06:55:11PM -0800, Samuel Holland wrote:
> Here are a few changes to minimize calls to stop_machine() and
> flush_icache_*() in the various text patching functions, as well as
> to simplify the code.
> 
> 
> Samuel Holland (7):
>   riscv: jump_label: Batch icache maintenance
>   riscv: jump_label: Simplify assembly syntax
>   riscv: kprobes: Use patch_text_nosync() for insn slots
>   riscv: Simplify text patching loops
>   riscv: Pass patch_text() the length in bytes
>   riscv: Use offset_in_page() in text patching functions
>   riscv: Remove extra variable in patch_text_nosync()

This does look like a nice clean-up.  Just curious (a "teach me"-like question),
how did you test these changes? kselftests, micro-benchmarks, other?

BTW, I recall a parallel work from Alex and Bjorn [1] that might have some minor
conflict with these changes; + both of them to Cc: for further sync.

  Andrea

[1] https://lore.kernel.org/lkml/20240206204607.527195-1-alexghiti@rivosinc.com/
Björn Töpel Feb. 19, 2024, 12:25 p.m. UTC | #2
Andrea Parri <parri.andrea@gmail.com> writes:

> Hi Samuel,
>
> On Sun, Feb 11, 2024 at 06:55:11PM -0800, Samuel Holland wrote:
>> Here are a few changes to minimize calls to stop_machine() and
>> flush_icache_*() in the various text patching functions, as well as
>> to simplify the code.
>> 
>> 
>> Samuel Holland (7):
>>   riscv: jump_label: Batch icache maintenance
>>   riscv: jump_label: Simplify assembly syntax
>>   riscv: kprobes: Use patch_text_nosync() for insn slots
>>   riscv: Simplify text patching loops
>>   riscv: Pass patch_text() the length in bytes
>>   riscv: Use offset_in_page() in text patching functions
>>   riscv: Remove extra variable in patch_text_nosync()
>
> This does look like a nice clean-up.  Just curious (a "teach me"-like question),
> how did you test these changes? kselftests, micro-benchmarks, other?
>
> BTW, I recall a parallel work from Alex and Bjorn [1] that might have some minor
> conflict with these changes; + both of them to Cc: for further sync.

Indeed! I think Alex is still working on the v2.
Alexandre Ghiti Feb. 20, 2024, 10:11 p.m. UTC | #3
On Mon, Feb 19, 2024 at 1:25 PM Björn Töpel <bjorn@kernel.org> wrote:
>
> Andrea Parri <parri.andrea@gmail.com> writes:
>
> > Hi Samuel,
> >
> > On Sun, Feb 11, 2024 at 06:55:11PM -0800, Samuel Holland wrote:
> >> Here are a few changes to minimize calls to stop_machine() and
> >> flush_icache_*() in the various text patching functions, as well as
> >> to simplify the code.
> >>
> >>
> >> Samuel Holland (7):
> >>   riscv: jump_label: Batch icache maintenance
> >>   riscv: jump_label: Simplify assembly syntax
> >>   riscv: kprobes: Use patch_text_nosync() for insn slots
> >>   riscv: Simplify text patching loops
> >>   riscv: Pass patch_text() the length in bytes
> >>   riscv: Use offset_in_page() in text patching functions
> >>   riscv: Remove extra variable in patch_text_nosync()
> >
> > This does look like a nice clean-up.  Just curious (a "teach me"-like question),
> > how did you test these changes? kselftests, micro-benchmarks, other?
> >
> > BTW, I recall a parallel work from Alex and Bjorn [1] that might have some minor
> > conflict with these changes; + both of them to Cc: for further sync.
>
> Indeed! I think Alex is still working on the v2.

Actually I was blocked by Andrea's comment about patch_map(), but it's
not related so I can spin another version soon. I'd say mine should
land first because AIA support may get into 6.9 (?) and then this
patch would be needed. In case you re-spin another version, can you
rebase on top of it? Unless you have another solution of course.

Thanks,

Alex
Samuel Holland March 27, 2024, 3:32 p.m. UTC | #4
Hi Andrea,

On 2024-02-13 6:58 AM, Andrea Parri wrote:
> On Sun, Feb 11, 2024 at 06:55:11PM -0800, Samuel Holland wrote:
>> Here are a few changes to minimize calls to stop_machine() and
>> flush_icache_*() in the various text patching functions, as well as
>> to simplify the code.
>>
>>
>> Samuel Holland (7):
>>   riscv: jump_label: Batch icache maintenance
>>   riscv: jump_label: Simplify assembly syntax
>>   riscv: kprobes: Use patch_text_nosync() for insn slots
>>   riscv: Simplify text patching loops
>>   riscv: Pass patch_text() the length in bytes
>>   riscv: Use offset_in_page() in text patching functions
>>   riscv: Remove extra variable in patch_text_nosync()
> 
> This does look like a nice clean-up.  Just curious (a "teach me"-like question),
> how did you test these changes? kselftests, micro-benchmarks, other?

For all my patches, I do boot testing on various physical boards (Unmatched, D1,
some internal hardware), plus some standard internal workloads. For
performance-related patches, I run microbenchmarks or whole-system benchmarks
(e.g. UnixBench). For this series specifically, I didn't do any extra
benchmarking, as all of the functional changes should be as fast or faster by
virtue of simply doing less work.

> BTW, I recall a parallel work from Alex and Bjorn [1] that might have some minor
> conflict with these changes; + both of them to Cc: for further sync.

As suggested by Alex, v2 of this series will be based on the latest version of
that patch.

Regards,
Samuel

> 
>   Andrea
> 
> [1] https://lore.kernel.org/lkml/20240206204607.527195-1-alexghiti@rivosinc.com/