From: Masami Hiramatsu <mhiramat@kernel.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>, Song Liu <songliubraving@fb.com>,
Martin KaFai Lau <kafai@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Russell King <linux@armlinux.org.uk>,
Network Development <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
Will Deacon <will@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Yonghong Song <yhs@fb.com>, bpf <bpf@vger.kernel.org>,
Andrii Nakryiko <andriin@fb.com>, Ingo Molnar <mingo@kernel.org>,
linux-arm-kernel@lists.infradead.org,
Eelco Chaudron <echaudro@redhat.com>
Subject: [RFC PATCH v2 0/3] kprobes: Support nested kprobes
Date: Fri, 8 May 2020 23:24:55 +0900 [thread overview]
Message-ID: <158894789510.14896.13461271606820304664.stgit@devnote2> (raw)
Hi,
Here is the 2nd version of the series to add nested-kprobes support
to x86, arm64 and arm. This makes kprobes to accept 1-level nesting
instead of incrementing missed count.
In this version, I fixed a mistake for the kprobes on ftrace on x86
and dump nested probes when we detect an unrecoverable kprobe.
Nested Kprobes
--------------
Any kprobes hits in kprobes pre/post handler context can be nested
at once. If the other kprobes hits in the nested pre/post handler
context or in the single-stepping context, that will be still
missed.
The nest level is actually easily extended, but too many nest
level can lead the overflow of the kernel stack (for each nest,
the stack will be consumed by saving registers, handling kprobes
and pre/post handlers.) Thus, at this moment it allows only one
level nest.
This feature allows BPF or ftrace user to put a kprobe on BPF
jited code or ftrace internal code running in the kprobe context
for debugging.
We can test this feature on the kernel with
CONFIG_KPROBE_EVENTS_ON_NOTRACE=y as below.
# cd /sys/kernel/debug/tracing
# echo p ring_buffer_lock_reserve > kprobe_events
# echo p vfs_read >> kprobe_events
# echo stacktrace > events/kprobes/p_ring_buffer_lock_reserve_0/trigger
# echo 1 > events/kprobes/enable
# cat trace
...
cat-151 [000] ...1 48.669190: p_vfs_read_0: (vfs_read+0x0/0x160)
cat-151 [000] ...2 48.669276: p_ring_buffer_lock_reserve_0: (ring_buffer_lock_reserve+0x0/0x400)
cat-151 [000] ...2 48.669288: <stack trace>
=> kprobe_dispatcher
=> opt_pre_handler
=> optimized_callback
=> 0xffffffffa0002331
=> ring_buffer_lock_reserve
=> kprobe_trace_func
=> kprobe_dispatcher
=> opt_pre_handler
=> optimized_callback
=> 0xffffffffa00023b0
=> vfs_read
=> load_elf_phdrs
=> load_elf_binary
=> search_binary_handler.part.0
=> __do_execve_file.isra.0
=> __x64_sys_execve
=> do_syscall_64
=> entry_SYSCALL_64_after_hwframe
To check unoptimized code, disable optprobe and dump the log.
# echo 0 > /proc/sys/debug/kprobes-optimization
# echo > trace
# cat trace
cat-153 [000] d..1 140.581433: p_vfs_read_0: (vfs_read+0x0/0x160)
cat-153 [000] d..2 140.581780: p_ring_buffer_lock_reserve_0: (ring_buffer_lock_reserve+0x0/0x400)
cat-153 [000] d..2 140.581811: <stack trace>
=> kprobe_dispatcher
=> aggr_pre_handler
=> kprobe_int3_handler
=> do_int3
=> int3
=> ring_buffer_lock_reserve
=> kprobe_trace_func
=> kprobe_dispatcher
=> aggr_pre_handler
=> kprobe_int3_handler
=> do_int3
=> int3
=> vfs_read
=> load_elf_phdrs
=> load_elf_binary
=> search_binary_handler.part.0
=> __do_execve_file.isra.0
=> __x64_sys_execve
=> do_syscall_64
=> entry_SYSCALL_64_after_hwframe
So we can see the kprobe can be nested.
Thank you,
---
Masami Hiramatsu (3):
x86/kprobes: Support nested kprobes
arm64: kprobes: Support nested kprobes
arm: kprobes: Support nested kprobes
arch/arm/include/asm/kprobes.h | 5 +-
arch/arm/probes/kprobes/core.c | 83 +++++++++++++++---------------
arch/arm/probes/kprobes/core.h | 30 +++++++++++
arch/arm/probes/kprobes/opt-arm.c | 6 +-
arch/arm64/include/asm/kprobes.h | 5 +-
arch/arm64/kernel/probes/kprobes.c | 79 +++++++++++++++++-----------
arch/x86/include/asm/kprobes.h | 5 +-
arch/x86/kernel/kprobes/common.h | 39 +++++++++++++-
arch/x86/kernel/kprobes/core.c | 100 ++++++++++++++++--------------------
arch/x86/kernel/kprobes/ftrace.c | 6 +-
arch/x86/kernel/kprobes/opt.c | 13 +++--
kernel/kprobes.c | 1
12 files changed, 226 insertions(+), 146 deletions(-)
--
Masami Hiramatsu (Linaro) <mhiramat@kernel.org>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2020-05-08 14:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-08 14:24 Masami Hiramatsu [this message]
2020-05-08 14:25 ` [RFC PATCH v2 1/3] x86/kprobes: Support nested kprobes Masami Hiramatsu
2020-05-08 14:25 ` [RFC PATCH v2 2/3] arm64: kprobes: " Masami Hiramatsu
2020-05-08 14:25 ` [RFC PATCH v2 3/3] arm: " Masami Hiramatsu
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=158894789510.14896.13461271606820304664.stgit@devnote2 \
--to=mhiramat@kernel.org \
--cc=acme@kernel.org \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=echaudro@redhat.com \
--cc=kafai@fb.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mingo@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=songliubraving@fb.com \
--cc=wangnan0@huawei.com \
--cc=will@kernel.org \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).