Re: [PATCH v4 1/3] asm/ptrace.h: add instruction_pointer_set
From: Magnus Lindholm
Date: Mon Nov 16 2026 - 13:10:47 EST
Hi Renzo,
On Sat, Nov 14, 2026 at 7:47 PM Renzo Davoli <renzo@xxxxxxxxxxx> wrote:
>
> Add an instruction_pointer_set function for architectures that do
> not currently provide one.
>
> Signed-off-by: Renzo Davoli <renzo@xxxxxxxxxxx>
> ---
> arch/alpha/include/asm/ptrace.h | 6 ++++++
> arch/hexagon/include/asm/ptrace.h | 6 ++++++
> arch/m68k/include/asm/ptrace.h | 6 ++++++
> arch/microblaze/include/asm/ptrace.h | 6 ++++++
> arch/nios2/include/asm/ptrace.h | 6 ++++++
> arch/um/include/asm/ptrace-generic.h | 6 ++++++
> arch/xtensa/include/asm/ptrace.h | 6 ++++++
> 7 files changed, 42 insertions(+)
>
> diff --git a/arch/alpha/include/asm/ptrace.h b/arch/alpha/include/asm/ptrace.h
> index 45d1229344b6..1a6f073e892e 100644
> --- a/arch/alpha/include/asm/ptrace.h
> +++ b/arch/alpha/include/asm/ptrace.h
> @@ -33,6 +33,12 @@ static __always_inline bool regs_irqs_disabled(struct pt_regs *regs)
> return arch_irqs_disabled_flags(regs->ps);
> }
>
> +static inline void instruction_pointer_set(struct pt_regs *regs,
> + unsigned long val)
> +{
> + instruction_pointer(regs) = val;
> +}
> +
> /* Syscall emulation defines */
> #define PTRACE_SYSEMU 0x1d
> #define PTRACE_SYSEMU_SINGLESTEP 0x1e
> diff --git a/arch/hexagon/include/asm/ptrace.h b/arch/hexagon/include/asm/ptrace.h
> index ed35da1ee685..0a121f6e3bfc 100644
> --- a/arch/hexagon/include/asm/ptrace.h
> +++ b/arch/hexagon/include/asm/ptrace.h
> @@ -18,6 +18,12 @@ extern const char *regs_query_register_name(unsigned int offset);
> ((struct pt_regs *) \
> ((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
>
> +static inline void instruction_pointer_set(struct pt_regs *regs,
> + unsigned long val)
> +{
> + instruction_pointer(regs) = val;
> +}
> +
> #if CONFIG_HEXAGON_ARCH_VERSION >= 4
> #define arch_has_single_step() (1)
> #endif
> diff --git a/arch/m68k/include/asm/ptrace.h b/arch/m68k/include/asm/ptrace.h
> index bc86ce012025..6e8a8f0daee8 100644
> --- a/arch/m68k/include/asm/ptrace.h
> +++ b/arch/m68k/include/asm/ptrace.h
> @@ -18,6 +18,12 @@
> (struct pt_regs *)((char *)current_thread_info() + THREAD_SIZE) - 1
> #define current_user_stack_pointer() rdusp()
>
> +static inline void instruction_pointer_set(struct pt_regs *regs,
> + unsigned long val)
> +{
> + instruction_pointer(regs) = val;
> +}
> +
> #define arch_has_single_step() (1)
>
> #ifdef CONFIG_MMU
> diff --git a/arch/microblaze/include/asm/ptrace.h b/arch/microblaze/include/asm/ptrace.h
> index 17982292a64f..69e10658d7a9 100644
> --- a/arch/microblaze/include/asm/ptrace.h
> +++ b/arch/microblaze/include/asm/ptrace.h
> @@ -20,5 +20,11 @@ static inline long regs_return_value(struct pt_regs *regs)
> return regs->r3;
> }
>
> +static inline void instruction_pointer_set(struct pt_regs *regs,
> + unsigned long val)
> +{
> + instruction_pointer(regs) = val;
> +}
> +
> #endif /* __ASSEMBLER__ */
> #endif /* _ASM_MICROBLAZE_PTRACE_H */
> diff --git a/arch/nios2/include/asm/ptrace.h b/arch/nios2/include/asm/ptrace.h
> index 96cbcd40c7ce..d120d8ecb187 100644
> --- a/arch/nios2/include/asm/ptrace.h
> +++ b/arch/nios2/include/asm/ptrace.h
> @@ -70,6 +70,12 @@ struct switch_stack {
> #define user_stack_pointer(regs) ((regs)->sp)
> extern void show_regs(struct pt_regs *);
>
> +static inline void instruction_pointer_set(struct pt_regs *regs,
> + unsigned long val)
> +{
> + instruction_pointer(regs) = val;
> +}
> +
> #define current_pt_regs() \
> ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE)\
> - 1)
> diff --git a/arch/um/include/asm/ptrace-generic.h b/arch/um/include/asm/ptrace-generic.h
> index 62e9916078ec..632d4ce3334d 100644
> --- a/arch/um/include/asm/ptrace-generic.h
> +++ b/arch/um/include/asm/ptrace-generic.h
> @@ -29,6 +29,12 @@ struct pt_regs {
>
> #define PTRACE_OLDSETOPTIONS 21
>
> +static inline void instruction_pointer_set(struct pt_regs *regs,
> + unsigned long val)
> +{
> + instruction_pointer(regs) = val;
> +}
> +
> #ifdef CONFIG_BINFMT_ELF_FDPIC
> #define PTRACE_GETFDPIC 31
> #define PTRACE_GETFDPIC_EXEC 0
> diff --git a/arch/xtensa/include/asm/ptrace.h b/arch/xtensa/include/asm/ptrace.h
> index d0568ff6d349..97b14418955e 100644
> --- a/arch/xtensa/include/asm/ptrace.h
> +++ b/arch/xtensa/include/asm/ptrace.h
> @@ -103,6 +103,12 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
> return regs->areg[2];
> }
>
> +static inline void instruction_pointer_set(struct pt_regs *regs,
> + unsigned long val)
> +{
> + instruction_pointer(regs) = val;
> +}
> +
> int do_syscall_trace_enter(struct pt_regs *regs);
> void do_syscall_trace_leave(struct pt_regs *regs);
>
> --
> 2.47.3
>
The Alpha change looks good and applies cleanly on my for-next,
including the generic-entry fixes.
Tested both series together on my AlphaServer ES40. The ptrace
selftests passed on all three CPUs, including syscall skipping
and instruction-pointer modification.
For the Alpha part:
Acked-by: Magnus Lindholm <linmag7@xxxxxxxxx>
Tested-by: Magnus Lindholm <linmag7@xxxxxxxxx>
Thanks,
Magnus