From: Masami Hiramatsu (Google) <mhiramat@kernel•org>
To: Song Liu <song@kernel•org>
Cc: "Dan Li" <ashimida@linux•alibaba.com>,
"Heiko Stuebner" <heiko@sntech•de>,
"Linus Walleij" <linus.walleij@linaro•org>,
"Paul Mackerras" <paulus@samba•org>,
"Alexander Gordeev" <agordeev@linux•ibm.com>,
"Javier Martinez Canillas" <javierm@redhat•com>,
"Geert Uytterhoeven" <geert@linux-m68k•org>,
"Catalin Marinas" <catalin.marinas@arm•com>,
"Christian Borntraeger" <borntraeger@linux•ibm.com>,
"Guenter Roeck" <linux@roeck-us•net>,
"André Almeida" <andrealmeid@igalia•com>,
"Michael Roth" <michael.roth@amd•com>,
"Nicholas Piggin" <npiggin@gmail•com>,
"Thomas Gleixner" <tglx@linutronix•de>,
"Andrey Konovalov" <andreyknvl@gmail•com>,
"Nick Desaulniers" <ndesaulniers@google•com>,
"Linux Kernel Mailing List" <linux-kernel@vger•kernel.org>,
"Luis Chamberlain" <mcgrof@kernel•org>,
"Masami Hiramatsu" <mhiramat@kernel•org>,
"Wu Caize" <zepan@sipeed•com>, "Guo Ren" <guoren@kernel•org>,
"Andrew Morton" <akpm@linux-foundation•org>,
"Mark Rutland" <mark.rutland@arm•com>,
"Luis Machado" <luis.machado@linaro•org>,
"Atsushi Nemoto" <anemo@mba•ocn.ne.jp>,
"Dave Hansen" <dave.hansen@linux•intel.com>,
"Joey Gouly" <joey.gouly@arm•com>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership•com>,
linux-s390@vger•kernel.org,
"Ilya Leoshkevich" <iii@linux•ibm.com>,
"Anup Patel" <anup@brainfault•org>,
"Helge Deller" <deller@gmx•de>,
"Anil S Keshavamurthy" <anil.s.keshavamurthy@intel•com>,
"Sven Schnelle" <svens@linux•ibm.com>,
"Tom Lendacky" <thomas.lendacky@amd•com>,
"Vasily Gorbik" <gor@linux•ibm.com>,
"Philipp Tomsich" <philipp.tomsich@vrull•eu>,
"Dave Anglin" <dave.anglin@bell•net>,
linux-arm-kernel@lists•infradead.org,
"Daniel Axtens" <dja@axtens•net>,
"Nicolas Pitre" <nico@fluxnic•net>,
"Jarkko Sakkinen" <jarkko@kernel•org>,
"Eric W. Biederman" <ebiederm@xmission•com>,
"Aneesh Kumar K.V" <aneesh.kumar@linux•ibm.com>,
"Daniel Bristot de Oliveira" <bristot@redhat•com>,
"Kefeng Wang" <wangkefeng.wang@huawei•com>,
"Emil Renner Berthing" <kernel@esmil•dk>,
"Jordan Niethe" <jniethe5@gmail•com>,
"Atish Patra" <atishp@atishpatra•org>,
"Alexei Starovoitov" <ast@kernel•org>,
"Will Deacon" <will@kernel•org>
Subject: Re: [PATCH] kprobes: Enable tracing for mololithic kernel images
Date: Sun, 12 Jun 2022 21:30:41 +0900 [thread overview]
Message-ID: <20220612213041.b1ec5d1ec3426e90e669c495@kernel.org> (raw)
In-Reply-To: <CAPhsuW7NZXepczZGyV2Ti4hNSupLBoKgA64K=zJN4uVBTxN37g@mail.gmail.com>
hiro Yamada <masahiroy@kernel•org>, Jarkko Sakkinen <jarkko@profian•com>, Sami Tolvanen <samitolvanen@google•com>, "Naveen N. Rao" <naveen.n.rao@linux•ibm.com>, Marco Elver <elver@google•com>, Kees Cook <keescook@chromium•org>, Steven Rostedt <rostedt@goodmis•org>, Nathan Chancellor <nathan@kernel•org>, "Russell King \(Oracle\)" <rmk+kernel@armlinux•org.uk>, Mark Brown <broonie@kernel•org>, Borislav Petkov <bp@alien8•de>, Alexander Egorenkov <egorenar@linux•ibm.com>, Thomas Bogendoerfer <tsbogend@alpha•franken.de>, linux-parisc@vger•kernel.org, Nathaniel McCallum <nathaniel@profian•com>, Dmitry Torokhov <dmitry.torokhov@gmail•com>, "David S. Miller" <davem@davemloft•net>, "Kirill A. Shutemov" <kirill.shutemov@linux•intel.com>, Tobias Huschle <huschle@linux•ibm.com>, "Peter Zijlstra \(Intel\)" <peterz@infradead•org>, "H. Peter Anvin" <hpa@zytor•com>, sparclinux@vger•kernel.org, Tiezhu Yang <yangtiezhu@loongson•cn>, Miroslav Benes <mbenes@suse•cz>, Chen Zhongjin <chenzhongjin@huawei•co
m>, Ard Biesheuvel <ardb@kernel•org>, X86 ML <x86@kernel•org>, Russell King <linux@armlinux•org.uk>, linux-riscv@lists•infradead.org, Ingo Molnar <mingo@redhat•com>, Aaron Tomlin <atomlin@redhat•com>, Albert Ou <aou@eecs•berkeley.edu>, Heiko Carstens <hca@linux•ibm.com>, Liao Chang <liaochang1@huawei•com>, Paul Walmsley <paul.walmsley@sifive•com>, Josh Poimboeuf <jpoimboe@kernel•org>, Thomas Richter <tmricht@linux•ibm.com>, linux-mips@vger•kernel.org, Changbin Du <changbin.du@intel•com>, Palmer Dabbelt <palmer@dabbelt•com>, 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" <linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists•ozlabs.org>
On Wed, 8 Jun 2022 11:19:19 -0700
Song Liu <song@kernel•org> wrote:
> On Wed, Jun 8, 2022 at 9:28 AM Ard Biesheuvel <ardb@kernel•org> wrote:
> >
> > Hello Jarkko,
> >
> > On Wed, 8 Jun 2022 at 02:02, Jarkko Sakkinen <jarkko@profian•com> 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.
> >
> > 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.
>
> I think the distance of core kernel requirement is the same for kprobe
> alloc_insn_page and modules, no?
This strongly depends on how kprobes (software breakpoint and
single-step) is implemented on the arch. For example, x86 implements
the so-called "kprobe-booster" which jumps back from the single
stepping trampoline buffer. Then the buffer address must be within
the range where it can jump to the original address.
However, if the arch implements single-step as an instruction
emulation, it has no such limitation. As far as I know, arm64
will do emulation for the instructions which change PC register
and will do direct execution with another software breakpoint
for other instructions.
Why I'm using module_alloc() for a generic function, is that
can cover the limitation most widely.
Thus, if we have CONFIG_ARCH_HAVE_ALLOC_INSN_PAGE flag and
kprobes can check it instead of using __weak function, the
kprobes may not need to depend on module_alloc() in general.
Thank you,
>
> Thanks,
> Song
>
> >
> > 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()?
> >
--
Masami Hiramatsu (Google) <mhiramat@kernel•org>
next prev parent reply other threads:[~2022-06-13 11:30 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-07 23:59 [PATCH] kprobes: Enable tracing for mololithic kernel images Jarkko Sakkinen
2022-06-08 2:35 ` Guo Ren
2022-06-08 5:25 ` Jarkko Sakkinen
2022-06-08 14:21 ` Masami Hiramatsu
2022-06-08 16:12 ` Song Liu
2022-06-08 18:20 ` Song Liu
2022-06-08 20:26 ` Luis Chamberlain
2022-06-09 3:48 ` Christoph Hellwig
2022-06-09 13:24 ` Luis Chamberlain
2022-06-09 18:41 ` Edgecombe, Rick P
2022-06-09 22:48 ` Song Liu
2022-06-14 12:32 ` jarkko
2022-06-15 6:37 ` hch
2022-06-15 21:29 ` jarkko
2022-06-09 8:33 ` Christophe Leroy
2022-06-09 22:23 ` Song Liu
2022-06-09 13:12 ` Jarkko Sakkinen
2022-06-09 13:23 ` Ard Biesheuvel
2022-06-12 12:18 ` Masami Hiramatsu
2022-06-12 15:59 ` Christophe Leroy
2022-06-13 0:01 ` Masami Hiramatsu
2022-06-14 10:54 ` Jarkko Sakkinen
2022-06-09 12:59 ` Jarkko Sakkinen
2022-06-08 16:27 ` Ard Biesheuvel
2022-06-08 18:19 ` Song Liu
2022-06-12 12:30 ` Masami Hiramatsu [this message]
2022-06-14 12:30 ` Jarkko Sakkinen
2022-06-09 5:37 ` Jarkko Sakkinen
2022-06-09 7:47 ` Russell King (Oracle)
2022-06-09 11:48 ` Jarkko Sakkinen
2022-06-09 13:44 ` Luis Chamberlain
2022-06-14 12:26 ` Jarkko Sakkinen
2022-06-14 12:36 ` Christophe Leroy
2022-06-15 21:24 ` Jarkko Sakkinen
2022-06-09 8:30 ` Christophe Leroy
2022-06-09 12:57 ` Jarkko Sakkinen
2022-06-09 13:42 ` Christophe Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220612213041.b1ec5d1ec3426e90e669c495@kernel.org \
--to=mhiramat@kernel$(echo .)org \
--cc=James.Bottomley@hansenpartnership$(echo .)com \
--cc=agordeev@linux$(echo .)ibm.com \
--cc=akpm@linux-foundation$(echo .)org \
--cc=andrealmeid@igalia$(echo .)com \
--cc=andreyknvl@gmail$(echo .)com \
--cc=aneesh.kumar@linux$(echo .)ibm.com \
--cc=anemo@mba$(echo .)ocn.ne.jp \
--cc=anil.s.keshavamurthy@intel$(echo .)com \
--cc=anup@brainfault$(echo .)org \
--cc=ashimida@linux$(echo .)alibaba.com \
--cc=ast@kernel$(echo .)org \
--cc=atishp@atishpatra$(echo .)org \
--cc=borntraeger@linux$(echo .)ibm.com \
--cc=bristot@redhat$(echo .)com \
--cc=catalin.marinas@arm$(echo .)com \
--cc=dave.anglin@bell$(echo .)net \
--cc=dave.hansen@linux$(echo .)intel.com \
--cc=deller@gmx$(echo .)de \
--cc=dja@axtens$(echo .)net \
--cc=ebiederm@xmission$(echo .)com \
--cc=geert@linux-m68k$(echo .)org \
--cc=gor@linux$(echo .)ibm.com \
--cc=guoren@kernel$(echo .)org \
--cc=heiko@sntech$(echo .)de \
--cc=iii@linux$(echo .)ibm.com \
--cc=jarkko@kernel$(echo .)org \
--cc=javierm@redhat$(echo .)com \
--cc=jniethe5@gmail$(echo .)com \
--cc=joey.gouly@arm$(echo .)com \
--cc=kernel@esmil$(echo .)dk \
--cc=linus.walleij@linaro$(echo .)org \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=linux-s390@vger$(echo .)kernel.org \
--cc=linux@roeck-us$(echo .)net \
--cc=luis.machado@linaro$(echo .)org \
--cc=mark.rutland@arm$(echo .)com \
--cc=mcgrof@kernel$(echo .)org \
--cc=michael.roth@amd$(echo .)com \
--cc=ndesaulniers@google$(echo .)com \
--cc=nico@fluxnic$(echo .)net \
--cc=npiggin@gmail$(echo .)com \
--cc=paulus@samba$(echo .)org \
--cc=philipp.tomsich@vrull$(echo .)eu \
--cc=song@kernel$(echo .)org \
--cc=svens@linux$(echo .)ibm.com \
--cc=tglx@linutronix$(echo .)de \
--cc=thomas.lendacky@amd$(echo .)com \
--cc=wangkefeng.wang@huawei$(echo .)com \
--cc=will@kernel$(echo .)org \
--cc=zepan@sipeed$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox