Re: [REGRESSION] Random oops on SG2042 with Linux 6.16-rc and dynamic ftrace

From: Steven Rostedt
Date: Tue Jul 01 2025 - 11:21:42 EST


On Tue, 1 Jul 2025 14:27:32 +0200
Alexandre Ghiti <alex@xxxxxxxx> wrote:

> @@ -149,16 +157,17 @@ int ftrace_init_nop(struct module *mod, struct
> dyn_ftrace *rec)
>         unsigned int nops[2], offset;
>         int ret;
>
> +       mutex_lock(&text_mutex);

This looks like a prime candidate for:

guard(mutex)(&text_mutex);

>         ret = ftrace_rec_set_nop_ops(rec);
>         if (ret)
> -               return ret;
> +               goto end;

Then this change wouldn't be needed.

>
>         offset = (unsigned long) &ftrace_caller - pc;
>         nops[0] = to_auipc_t0(offset);
>         nops[1] = RISCV_INSN_NOP4;
>
> -       mutex_lock(&text_mutex);
>         ret = patch_insn_write((void *)pc, nops, 2 * MCOUNT_INSN_SIZE);
> +end:
>         mutex_unlock(&text_mutex);

and "end:" as well as the mutex_unlock() can be removed.

>
>         return ret;
>
>
> Andy is also taking a look, I'll let him confirm the above fix is correct.
>
> Thanks for the thorough report!

Yes, thank you Yao Zi for the very detailed bug report! That made
things so much easier.

-- Steve