Re: [PATCH v4 13/16] arm/ftrace: Use __patch_text_real()

From: Peter Zijlstra
Date: Mon Oct 28 2019 - 12:55:44 EST


On Mon, Oct 28, 2019 at 04:47:59PM +0000, Will Deacon wrote:
> On Mon, Oct 28, 2019 at 05:34:21PM +0100, Peter Zijlstra wrote:
> > On Mon, Oct 28, 2019 at 04:25:26PM +0000, Will Deacon wrote:
> > > On Fri, Oct 18, 2019 at 09:35:38AM +0200, Peter Zijlstra wrote:
> > > > @@ -97,10 +100,7 @@ static int ftrace_modify_code(unsigned l
> > > > return -EINVAL;
> > > > }
> > > >
> > > > - if (probe_kernel_write((void *)pc, &new, MCOUNT_INSN_SIZE))
> > > > - return -EPERM;
> > > > -
> > > > - flush_icache_range(pc, pc + MCOUNT_INSN_SIZE);
> > > > + __patch_text_real((void *)pc, new, patch_text_remap);
> > >
> > > Why can't you just pass 'true' for patch_text_remap? AFAICT, the only
> > > time you want to pass false is during early boot when the text is
> > > assumedly still writable without the fixmap.
> >
> > Ah, it will also become true for module loading once we rework where we
> > flip the module text RO,X. See this patch:
> >
> > https://lkml.kernel.org/r/20191018074634.858645375@xxxxxxxxxxxxx
> >
> > But for that to land, there's still a few other issues to fix (KLP).
>
> Passing 'true' would still work though, right? Just feels a bit error
> prone having to maintain the state of patch_test_remap() and remember
> that 'ftrace_lock' is holding the concurrency together.

It should, provided your fixmap stuff is working when we do the early
stuff I suppose. Module loading will be a wee bit slower too, but I'm
not the person to care about that.