Skip to content

riscv: Add runtime constant support

Charlie Jenkins linux-riscv linux-trace-kernel lkml llvm 10 versions – Applied

Status from this message: This series was applied to riscv/linux.git (for-next)

Get series with b4
b4 am [email protected] change-id 20250123-runtime_const_riscv-6cd854ee2817

Versions newest first

  1. v10 Latest2 patches 8 repliesApplied 2/2
  2. v92 patches 4 repliesSuperseded
  3. v81 patch 1 replySuperseded
Earlier versions · 7
VersionPostedPatchesRepliesStatus
v71 patch0 repliesSuperseded
v61 patch0 repliesSuperseded
v51 patch0 repliesSuperseded
v41 patch0 repliesSuperseded
v31 patch4 repliesSuperseded
v21 patch0 repliesSuperseded
v11 patch2 repliesSuperseded

Changes in v10 from the cover letter

- Use _AC() instead of just adding U to the end of a constant
- Link to v9: https://lore.kernel.org/r/[email protected]

Patches in v10 All 2 applied

#Subject and filesSizeRepliesApplied
1/2riscv: Move nop definition to insn-def.harch/riscv/include/asm/ftrace.h arch/riscv/include/asm/insn-def.h arch/riscv/kernel/ftrace.c +1 more+8 -61 replyApplied
2/2riscv: Add runtime constant supportarch/riscv/Kconfig arch/riscv/include/asm/asm.h arch/riscv/include/asm/runtime-const.h +1 more+291 -07 repliesApplied

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchAlexandre GhitiAndrew Jones
1/2R-b T-b R-b
2/2R-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v10 thread

Cover letter [PATCH v10 0/2] riscv: Add runtime constant support

Ard brought this to my attention in this patch [1].

I benchmarked this patch on the Nezha D1 (which does not contain Zba or Zbkb so it uses the default algorithm) by navigating through a large directory structure. I created a 1000-deep directory structure and then cd and ls through it. With this patch there was a 0.57% performance improvement.

[1] https://lore.kernel.org/lkml/CAMj1kXE4DJnwFejNWQu784GvyJO=aGNrzuLjSxiowX_e7nW8QA@mail.gmail.com/

---
Changes in v10:
- Use _AC() instead of just adding U to the end of a constant
- Link to v9: https://lore.kernel.org/r/[email protected]

Changes in v9:
- Fix bug where stale register data may be used when an lui is replaced
with a nop. In the following addiw, add to register x0 instead of the
stale register to resolve.
- Add locks for text_mutex before using patch_insn_write()
- Link to v8: https://lore.kernel.org/r/[email protected]

Changes in v8:
- Rebase to linux v6.14-rc5
- Link to v7: https://lore.kernel.org/r/[email protected]

Changes in v7:
- Added benchmarking info
- Added CONFIG_RISCV_ISA_ZBA and CONFIG_RISCV_ISA_ZBKB to check that the
compiler supports the extensions.
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- .option arch only became officially supported by clang in version 17.
Add a config to check that and guard the alternatives uses .option
arch.
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Split instructions into 16-bit parcels to avoid alignment (Emil)
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Add newlines after riscv32 assembler directives
- Align instructions along 32-bit boundary (Emil)
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Leverage "pack" instruction for runtime_const_ptr() to reduce hot path
by 3 instructions if Zbkb is supported. Suggested by Pasha Bouzarjomehri ([email protected])
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Treat instructions as __le32 and do proper conversions (Ben)
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Charlie Jenkins (2):
riscv: Move nop definition to insn-def.h
riscv: Add runtime constant support

 arch/riscv/Kconfig                     |  22 +++
 arch/riscv/include/asm/asm.h           |   1 +
 arch/riscv/include/asm/ftrace.h        |   1 -
 arch/riscv/include/asm/insn-def.h      |   3 +
 arch/riscv/include/asm/runtime-const.h | 265 +++++++++++++++++++++++++++++++++
 arch/riscv/kernel/ftrace.c             |   6 +-
 arch/riscv/kernel/jump_label.c         |   4 +-
 arch/riscv/kernel/vmlinux.lds.S        |   3 +
 8 files changed, 299 insertions(+), 6 deletions(-)

---
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
change-id: 20250123-runtime_const_riscv-6cd854ee2817

Signature · 1 line
- Charlie