Re: [PATCH] x86/kprobes: Simplify alloc_insn_page() with __vmalloc_node_range

From: Masami Hiramatsu
Date: Wed Apr 14 2021 - 04:23:11 EST


Hi Jisheng,

On Wed, 14 Apr 2021 15:27:28 +0800
Jisheng Zhang <Jisheng.Zhang@xxxxxxxxxxxxx> wrote:

\
> >
> > On Tue, 13 Apr 2021 18:03:24 +0800
> > Jisheng Zhang <Jisheng.Zhang@xxxxxxxxxxxxx> wrote:
> >
> > > Use the __vmalloc_node_range() to simplify x86's alloc_insn_page()
> > > implementation.
> >
> > Have you checked this is equivarent to the original code on all
> > architecture? IIRC, some arch has a special module_alloc(),
>
> > Indeed, this isn't equivarent to the original code. FWICT, the differences on x86 are:
>
> > 1) module_alloc() allocates a special vmalloc range
> > 2) module_alloc() randomizes the return address via. module_load_offset()
> > 3) module_alloc() also supports kasan instrumentation by kasan_module_alloc()
>
> > But I'm not sure whether the above differences are useful for kprobes ss
> > insn slot page or not. Take 1) for example, special range in module_alloc
> > is due to relative jump limitation, modules need to call kernel .text. does
> > kprobes ss ins slot needs this limitation too?
>
> Oops, I found this wonderful thread:
> https://www.lkml.org/lkml/2020/7/28/1413
>
> So kprobes ss ins slot page "must be in the range of relative branching only
> for x86 and arm"

Yes, at this moment. (Not sure we can introduce similar feature on other arch too)

>
> And Jarkko's "arch/x86: kprobes: Remove MODULES dependency" series look
> much better. The last version is v5, I'm not sure whether Jarkko will
> send new version to mainline the series.

I hope so. If module_alloc() itself is implemented on the generic text_alloc(),
I can replace the module_alloc() with text_alloc().

Thank you,

--
Masami Hiramatsu <mhiramat@xxxxxxxxxx>