# Re: \[PATCH\] kprobes: Enable tracing for mololithic kernel images

- From: Jarkko Sakkinen \<jarkko@kernel.org\>
- Date: 2022-06-09 05:40:05 
- List: linuxppc-dev
- Page: https://ratatoskr.run/linuxppc-dev/2022/06/1812957
- Thread: https://ratatoskr.run/linux-mips/2022/06/1811301/t.md

```text
Yamada [ref], Jarkko Sakkinen [ref], Sami Tolvanen [ref], "Naveen N. Rao" [ref], Marco Elver [ref], Kees Cook [ref], Steven Rostedt [ref], Nathan Chancellor [ref], "Russell King \(Oracle\)" [ref], Mark Brown [ref], Borislav Petkov [ref], Alexander Egorenkov [ref], Thomas Bogendoerfer [ref], linux-parisc@vger.kernel.org, Nathaniel McCallum [ref], Dmitry Torokhov [ref], "David S. Miller" [ref], "Kirill A. Shutemov" [ref], Tobias Huschle [ref], "Peter Zijlstra \(Intel\)" [ref], "H. Peter Anvin" [ref], sparclinux@vger.kernel.org, Tiezhu Yang [ref], Miroslav Benes [ref], Chen Zhongjin [ref], l
 inux-riscv@lists.infradead.org, X86 ML [ref], Russell King [ref], Ingo Molnar [ref], Aaron Tomlin [ref], Albert Ou [ref], Heiko Carstens [ref], Liao Chang [ref], Paul Walmsley [ref], Josh Poimboeuf [ref], Thomas Richter [ref], linux-mips@vger.kernel.org, Changbin Du [ref], Palmer Dabbelt [ref], linuxppc-dev@lists.ozlabs.org, linux-modules@vger.kernel.org
Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org
Sender: "Linuxppc-dev" [ref]

On Wed, Jun 08, 2022 at 06:27:51PM +0200, Ard Biesheuvel wrote:
> Hello Jarkko,
> 
> On Wed, 8 Jun 2022 at 02:02, Jarkko Sakkinen [ref] wrote:
> >
> > Tracing with kprobes while running a monolithic kernel is currently
> > impossible because CONFIG_KPROBES is dependent of CONFIG_MODULES.  This
> > dependency is a result of kprobes code using the module allocator for the
> > trampoline code.
> >
> > Detaching kprobes from modules helps to squeeze down the user space,
> > e.g. when developing new core kernel features, while still having all
> > the nice tracing capabilities.
> >
> > For kernel/ and arch/*, move module_alloc() and module_memfree() to
> > module_alloc.c, and compile as part of vmlinux when either CONFIG_MODULES
> > or CONFIG_KPROBES is enabled.  In addition, flag kernel module specific
> > code with CONFIG_MODULES.
> >
> > As the result, kprobes can be used with a monolithic kernel.
> 
> I think I may have mentioned this the previous time as well, but I
> don't think this is the right approach.

OK, I apologize for my ignorance. It's been a while.

> Kprobes uses alloc_insn_page() to allocate executable memory, but the
> requirements for this memory are radically different compared to
> loadable modules, which need to be within an arch-specific distance of
> the core kernel, need KASAN backing etc etc.
> 
> This is why arm64, for instance, does not implement alloc_insn_page()
> in terms of module_alloc() [and likely does not belong in this patch
> for that reason]
> 
> Is there any reason kprobes cannot simply use vmalloc()?

All arch's, except nios2 use vmalloc() in the end for module_alloc().
nios2 uses kmalloc() for the reasons that I'm not aware of, but it does
not support kprobes in the first place.

Based on this, I think that could work out just fine.

I could cope with that.

BR, Jarkko
```
