Skip to content

[WIP] [Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] riscv: Add runtime constant support#1904

Draft
opsiff wants to merge 1 commit into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.18.y-2026-06-24-riscv
Draft

[WIP] [Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] riscv: Add runtime constant support#1904
opsiff wants to merge 1 commit into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.18.y-2026-06-24-riscv

Conversation

@opsiff

@opsiff opsiff commented Jun 24, 2026

Copy link
Copy Markdown
Member

mainline inclusion
from mainline-v6.15-rc1
category: performance

Implement the runtime constant infrastructure for riscv. Use this infrastructure to generate constants to be used by the d_hash() function.

This is the riscv variant of commit 94a2bc0 ("arm64: add 'runtime constant' support") and commit e3c92e8 ("runtime constants: add x86 architecture support").

[ alex: Remove trailing whitespace ]

Reviewed-by: Alexandre Ghiti alexghiti@rivosinc.com
Tested-by: Alexandre Ghiti alexghiti@rivosinc.com
Link: https://lore.kernel.org/r/20250319-runtime_const_riscv-v10-2-745b31a11d65@rivosinc.com

Conflicts:
arch/riscv/Kconfig
(cherry picked from commit a44fb57)

Summary by Sourcery

Add RISC-V runtime constant infrastructure and integrate it into the kernel image layout to support architecture-specific optimization of computed constants.

New Features:

  • Introduce RISC-V-specific runtime constant support for pointers and shifts via a new asm/runtime-const.h interface.

Enhancements:

  • Extend the RISC-V linker script to include the runtime constant variables section.
  • Add an SRLI helper macro to abstract word-size-specific shift-right-immediate instructions used by the runtime constant logic.

mainline inclusion
from mainline-v6.15-rc1
category: performance

Implement the runtime constant infrastructure for riscv. Use this
infrastructure to generate constants to be used by the d_hash()
function.

This is the riscv variant of commit 94a2bc0 ("arm64: add 'runtime
constant' support") and commit e3c92e8 ("runtime constants: add
x86 architecture support").

[ alex: Remove trailing whitespace ]

Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20250319-runtime_const_riscv-v10-2-745b31a11d65@rivosinc.com
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Conflicts:
	arch/riscv/Kconfig
(cherry picked from commit a44fb57)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@sourcery-ai

sourcery-ai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds RISC-V runtime constant infrastructure and wires it into the linker script, providing assembly helpers and fixup routines to materialize and patch pointer and shift-immediate constants at runtime, with optional use of Zba/Zbkb ISA extensions for optimized 64-bit constant formation.

Flow diagram for RISC-V runtime constant initialization and fixup

flowchart TD
    Caller["caller of runtime_const_init(type,sym)"] --> runtime_const_init

    runtime_const_init["runtime_const_init(type,sym)"] --> runtime_const_fixup

    runtime_const_fixup["runtime_const_fixup(fn,val,start,end)"] --> Loop["[iterate runtime_* section entries]"]
    Loop --> runtime_fixup_fn

    runtime_fixup_fn["__runtime_fixup_ptr / __runtime_fixup_shift"] --> runtime_fixup_32
    runtime_fixup_fn --> runtime_fixup_caches

    runtime_fixup_32["__runtime_fixup_32(lui_parcel, addi_parcel, val)"] --> PatchedInsns["[patch lui/addi immediates]"]
    PatchedInsns --> runtime_fixup_caches

    runtime_fixup_caches["__runtime_fixup_caches(where,insns)"] --> Done["[runtime constants materialized in code]"]
Loading

File-Level Changes

Change Details Files
Wire runtime-constant variable section into the RISC-V vmlinux linker script so runtime-constant metadata is retained and located at link time.
  • Insert RUNTIME_CONST_VARIABLES section after EXIT_DATA and before per-CPU sections in the RISC-V kernel linker script
arch/riscv/kernel/vmlinux.lds.S
Extend RISC-V asm helpers with a width-dependent shift-right-immediate mnemonic for use in runtime-constant code sequences.
  • Add SRLI macro to select srliw on RV64 and srli on RV32 based on __REG_SEL
arch/riscv/include/asm/asm.h
Introduce RISC-V runtime-constant infrastructure to generate, record, and later patch pointer and shift constants, including optimized 64-bit constant formation paths and corresponding runtime fixup routines.
  • Define runtime_const_ptr() for 32-bit and 64-bit RISC-V, emitting placeholder LUI/ADDI sequences and recording their locations in dedicated runtime_ptr_* sections
  • Provide alternative sequences for 64-bit constant formation using base instructions, Zba add.uw, or Zbkb pack, selected via ALTERNATIVE macros and ISA config options
  • Add runtime_const_shift_right_32() to emit SRLI/SRLIW with placeholder shift amounts and record them in runtime_shift_* sections
  • Implement runtime_const_init() and runtime_const_fixup() helper that iterate over recorded locations and patch instruction streams with final values, including cache maintenance and text_mutex synchronization
  • Implement __runtime_fixup_32(), __runtime_fixup_ptr(), and __runtime_fixup_shift() helpers that decode/encode RISC-V instructions, update immediates, and write them back using patch_insn_write/patch_text_nosync
arch/riscv/include/asm/runtime-const.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@opsiff opsiff requested a review from dongert June 24, 2026 01:59
@Avenger-285714 Avenger-285714 self-requested a review June 24, 2026 02:00

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Avenger-285714

Copy link
Copy Markdown
Member

/approve

Link: #1902

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Avenger-285714

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Avenger-285714 Avenger-285714 marked this pull request as draft June 24, 2026 02:20
@Avenger-285714 Avenger-285714 changed the title [Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] riscv: Add runtime constant support [WIP] [Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] riscv: Add runtime constant support Jun 24, 2026
@dongert dongert requested a review from Copilot June 24, 2026 12:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants