[PATCH v3] RISC-V: Don't check text_mutex during stop_machine

Changbin Du changbin.du at huawei.com
Fri Feb 24 04:58:57 PST 2023


On Fri, Feb 24, 2023 at 11:07:42AM +0000, Conor Dooley wrote:
> > > -	lockdep_assert_held(&text_mutex);
> > > +	if (!riscv_ftrace_in_stop_machine)
> > > +		lockdep_assert_held(&text_mutex);
> > >  
> > >  	if (across_pages)
> > >  		patch_map(addr + len, FIX_TEXT_POKE1);
> > This misses this function.
> > 
> > int patch_text(void *addr, u32 insn)
> 
> So, with a corresponding rename to the symbol, does the following look
> okay to you?
> 
> diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/kprobes.c
> index f21592d20306..433b454e693f 100644
> --- a/arch/riscv/kernel/probes/kprobes.c
> +++ b/arch/riscv/kernel/probes/kprobes.c
> @@ -27,9 +27,15 @@ static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
>  
>  	p->ainsn.api.restore = (unsigned long)p->addr + offset;
>  
> +	/*
> +	 * kprobes takes text_mutex, but patch_text() calls stop_machine and
> +	 * lockdep gets confused by the context in which the lock is taken.
> +	 */
> +	riscv_patch_in_stop_machine = true;
>  	patch_text(p->ainsn.api.insn, p->opcode);
>  	patch_text((void *)((unsigned long)(p->ainsn.api.insn) + offset),
>  		   __BUG_INSN_32);
> +	riscv_patch_in_stop_machine = false;
>  }
hmm, why not just put 'riscv_patch_in_stop_machine' into patch_text()? Then you
just need to modify that function.

-- 
Cheers,
Changbin Du



More information about the linux-riscv mailing list