From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC61BC47254 for ; Fri, 8 May 2020 14:25:07 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A33C12495A for ; Fri, 8 May 2020 14:25:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="mMfqFyS2"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="NJFrQWS+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A33C12495A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Y5CGR/j1KucrrTEI6t1MHxNtBoPW2+y+Vdwd6tzdjVg=; b=mMfqFyS2V5LbkM I5CqOsrhXn/Zr4suEoRaVyBUrmYUtjsXW/Wr4rDh99C7GBCVyeXIOHvNcW34uRm6mVAECrmeFIY85 Sk6rIhzTpp/jrO6OBrCA/koIWnMbi7itsHaRJsApgIn1PR694Y77Um40Y8aO85L1ZmskWwfL5yJ84 5+kZ4eJ79xOLFx+XSW/00l4xznZ4NP7ZwYXcumF7mcUZPsqoaVfarGVnhabG6fs5rL+zVgeeleqR3 i//xvtctV+9+5MPND9kYYSputcHPj7SN8grLB0eAL7wmHPfyHJYlZgXiLUQiCaV+SXKdGACoaHu7A VpEHvHCqXPAHeWpmHQOA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX3w2-0005YS-Lz; Fri, 08 May 2020 14:25:06 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX3vy-0004cY-Nm for linux-arm-kernel@lists.infradead.org; Fri, 08 May 2020 14:25:04 +0000 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A861424954; Fri, 8 May 2020 14:24:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588947901; bh=1L390ZlzW+T338vHbYoOog6Isii+Mo0lwCGOSbNRxC4=; h=From:To:Cc:Subject:Date:From; b=NJFrQWS+h7Y0+pYeYuDhkDVyF+g8+Vpj7AZrIj05ORkRKqVvMS6yiW5KkxDRMN9Bp y2l2jIfJxXwwDXv0Y5o7BK6xF0jt5JSb5NcI7rw3IcHnT09ghnOwGxcsORL8oy1W+s kF6QauU5fNE54gVCRvxZ2GEZ3WOFyU0NYXOriA74= From: Masami Hiramatsu To: LKML Subject: [RFC PATCH v2 0/3] kprobes: Support nested kprobes Date: Fri, 8 May 2020 23:24:55 +0900 Message-Id: <158894789510.14896.13461271606820304664.stgit@devnote2> X-Mailer: git-send-email 2.20.1 User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200508_072502_836264_D9F9F582 X-CRM114-Status: GOOD ( 12.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wang Nan , Song Liu , Martin KaFai Lau , Daniel Borkmann , Russell King , Network Development , Alexei Starovoitov , Arnaldo Carvalho de Melo , "David S . Miller" , Will Deacon , Steven Rostedt , Catalin Marinas , Yonghong Song , bpf , Andrii Nakryiko , Ingo Molnar , linux-arm-kernel@lists.infradead.org, Eelco Chaudron Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: => 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: => 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) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel