Re: [RFC PATCH 03/13] arm64: ptrace: Always inline pt_regs_[read,write}_reg()

From: Jinjie Ruan

Date: Wed Jul 29 2026 - 00:05:31 EST




在 2026/7/28 20:38, Mark Rutland 写道:
> In subsequent patches we'll want to use pt_regs_read_reg() and
> pt_regs_write_reg() in noinstr code.
>
> To ensure noinstr safety, both functions must be inlined into their
> caller. As both functions are marked as 'inline' rather than
> '__always_inline', that's not strictly guaranteed, and the compiler is
> permitted to generate out-of-line copies.

Reviewed-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>

>
> Mark both functions as '__always_inline' to ensure this.
>
> There should be no functional change as a result of this patch.
>
> Signed-off-by: Mark Rutland <mark.rutland@xxxxxxx>
> Cc: Ada Couprie Diaz <ada.coupriediaz@xxxxxxx>
> Cc: Ard Biesheuvel <ardb@xxxxxxxxxx>
> Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
> Cc: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
> Cc: Marc Zyngier <maz@xxxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Cc: Vladimir Murzin <vladimir.murzin@xxxxxxx>
> Cc: Will Deacon <will@xxxxxxxxxx>
> Cc: Yang Shi <yang@xxxxxxxxxxxxxxxxxxxxxx>
> ---
> arch/arm64/include/asm/ptrace.h | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h
> index 39582511ad72f..a1aa668aad50e 100644
> --- a/arch/arm64/include/asm/ptrace.h
> +++ b/arch/arm64/include/asm/ptrace.h
> @@ -268,7 +268,8 @@ static inline u64 regs_get_register(struct pt_regs *regs, unsigned int offset)
> * Read a register given an architectural register index r.
> * This handles the common case where 31 means XZR, not SP.
> */
> -static inline unsigned long pt_regs_read_reg(const struct pt_regs *regs, int r)
> +static __always_inline unsigned long
> +pt_regs_read_reg(const struct pt_regs *regs, int r)
> {
> return (r == 31) ? 0 : regs->regs[r];
> }
> @@ -277,8 +278,8 @@ static inline unsigned long pt_regs_read_reg(const struct pt_regs *regs, int r)
> * Write a register given an architectural register index r.
> * This handles the common case where 31 means XZR, not SP.
> */
> -static inline void pt_regs_write_reg(struct pt_regs *regs, int r,
> - unsigned long val)
> +static __always_inline void
> +pt_regs_write_reg(struct pt_regs *regs, int r, unsigned long val)
> {
> if (r != 31)
> regs->regs[r] = val;