Re: [PATCH v2 1/4] sparc64: kprobes: Single-step from an executable instruction slot

From: Masami Hiramatsu (Google)

Date: Sat Nov 14 2026 - 06:53:41 EST


On Fri, 13 Nov 2026 15:40:54 +0100, Stian Halseth <stian@xxxxxx> wrote:
> kprobes single-steps the probed instruction from kprobe->ainsn.insn[].
> The array is embedded in struct kprobe, in the linear mapping. The
> sun4v linear mapping is not executable. Every probe hit oopses:
>
> sun4v_insn_access_exception: ADDR[fff800005b0cd66c] CTX[0000] TYPE[0006], going.
>
> Allocate the copy with get_insn_slot(), as other architectures do. The
> slot comes from executable memory in the module area.
>
> flush_insn_slot() flushed the embedded copy after init_aggr_kprobe()
> had copied it into the aggregator. The aggregator now shares the slot
> by pointer. arch_prepare_kprobe() flushes the slot when it writes it.
> Make the macro a no-op, like x86 and arm64.
>
> Fixes: c4bce90ea2069 ("[SPARC64]: Deal with PTE layout differences in SUN4V.")
> Closes: https://github.com/sparclinux/issues/issues/110
> Signed-off-by: Stian Halseth <stian@xxxxxx>

Looks good to me from kprobe point of view.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>

Thanks,

> ---
> arch/sparc/include/asm/kprobes.h | 12 ++++++------
> arch/sparc/kernel/kprobes.c | 12 ++++++++++++
> 2 files changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/arch/sparc/include/asm/kprobes.h b/arch/sparc/include/asm/kprobes.h
> index aec742cd898f2..d14206c063e25 100644
> --- a/arch/sparc/include/asm/kprobes.h
> +++ b/arch/sparc/include/asm/kprobes.h
> @@ -11,25 +11,25 @@
> #include <linux/types.h>
> #include <linux/percpu.h>
>
> +#define __ARCH_WANT_KPROBES_INSN_SLOT
> +
> typedef u32 kprobe_opcode_t;
>
> #define MAX_INSN_SIZE 2
>
> #define kretprobe_blacklist_size 0
>
> -#define arch_remove_kprobe(p) do {} while (0)
> +struct kprobe;
> +void arch_remove_kprobe(struct kprobe *p);
>
> -#define flush_insn_slot(p) \
> -do { flushi(&(p)->ainsn.insn[0]); \
> - flushi(&(p)->ainsn.insn[1]); \
> -} while (0)
> +#define flush_insn_slot(p) do { } while (0)
>
> void __kretprobe_trampoline(void);
>
> /* Architecture specific copy of original instruction*/
> struct arch_specific_insn {
> /* copy of the original instruction */
> - kprobe_opcode_t insn[MAX_INSN_SIZE];
> + kprobe_opcode_t *insn;
> };
>
> struct prev_kprobe {
> diff --git a/arch/sparc/kernel/kprobes.c b/arch/sparc/kernel/kprobes.c
> index 191bbaca99212..608efda8cb948 100644
> --- a/arch/sparc/kernel/kprobes.c
> +++ b/arch/sparc/kernel/kprobes.c
> @@ -52,6 +52,10 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
> if ((unsigned long) p->addr & 0x3UL)
> return -EILSEQ;
>
> + p->ainsn.insn = get_insn_slot();
> + if (!p->ainsn.insn)
> + return -ENOMEM;
> +
> p->ainsn.insn[0] = *p->addr;
> flushi(&p->ainsn.insn[0]);
>
> @@ -62,6 +66,14 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
> return 0;
> }
>
> +void __kprobes arch_remove_kprobe(struct kprobe *p)
> +{
> + if (p->ainsn.insn) {
> + free_insn_slot(p->ainsn.insn, 0);
> + p->ainsn.insn = NULL;
> + }
> +}
> +
> void __kprobes arch_arm_kprobe(struct kprobe *p)
> {
> *p->addr = BREAKPOINT_INSTRUCTION;
> --
> 2.43.0
>
>

--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>