Re: [PATCH 1/4] sparc64: kprobes: Single-step from an executable instruction slot
From: Masami Hiramatsu (Google)
Date: Fri Nov 13 2026 - 11:29:35 EST
Hi,
On Fri, 9 Oct 2026 20:03:32 +0200, Stian Halseth <stian@xxxxxx> wrote:
> 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;
> + }
With this change, the p->ainsn.insn becomes NULL here when kill_kprobe()
calls this function because (1) init.text is removed or (2) probed module
is unloaded.
If another module is loaded at the same region and another kprobe
is registered at the same address, register_aggr_kprobe() ->
init_aggr_kprobe() -> flush_insn_slot(NULL) is called. This can
cause a problem because it is defined as:
#define flush_insn_slot(p) \
do { flushi(&(p)->ainsn.insn[0]); \
flushi(&(p)->ainsn.insn[1]); \
flushi(&(p)->ainsn.insn[2]); \
} while (0)
Since the flush_insn_slot() is only needed if p->ainsn.insn is
embedded in the struct kprobe, as this changed it to insn_slot,
we don't need this macro anymore.
So you should update it as same as other arch like:
#define flush_insn_slot(p) do { } while (0)
Thanks,
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>