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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 48E18C433EF for ; Fri, 29 Apr 2022 16:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Mime-Version:References:In-Reply-To: Message-Id:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HM26IOPfSAK+ePe3AD6Te3OJ93GmovqicPmx1iDn418=; b=cRQhJDily+qkkM tDRgwc2htrc5QdlbAZ3rJNV2m8sS52PxXOitsFPsUz3+0osPCvrQHJJ7CNlMTXWwlMUZqhv38s8+q xynnfChT8tsV5hJqFWFjmhNxGaL7rKBsFpEP0Ayqhj76EiCByfNulXhZcjIKxpsxzALNf7b98MrSJ 90tYpXHOg8Psv+CL9k0UBQoDWy2ad+YuXo/ySFmE868o2byKsGd09vmsvM1cAKCfi/VpgY2eJ1Hap 6+/XL1fUQT7L1uIE45bzfw1G4WqlsbIpUqAHl3WvAofJSxrKI9Gxj04rxgSoj+ZvokXPb2K/4QLh3 d6YL9lAHtyVqTGsYJcDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkTDo-00BuSW-Dz; Fri, 29 Apr 2022 16:11:56 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkTDk-00BuS2-KT for linux-arm-kernel@lists.infradead.org; Fri, 29 Apr 2022 16:11:54 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 22E27B835DE; Fri, 29 Apr 2022 16:11:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C30C4C385AE; Fri, 29 Apr 2022 16:11:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651248709; bh=FBoMneeOrnrJ3BE/m6VhhFiGFXn7KCDa6+5nhSmlnJM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=bNGJBQrmzpLgYVTZgguyfdQc1HT76btHUuq4hcwOr8jLNUXpZ2XO5DWfiOApqxJIC jHJ4QKTKV2aZ+mraTlmDb4/bUU+CfEum7xMSzpnVyTsRiiUUJNpgvYUH31y7uF7GuK ip402yOvPJkvcEgK5k44MV97X808qOXiektWBkBbnKIB9xfviUiJ6fFBTnICCIjGU8 72v2j3d5yeSKjIA/W20vxAZV9xcb4fWvfkcig/qqa/wyhGlXbZZM77fc3o00oklQvl 0N0c/cx6XpXuCFnd/ADJ9gvmKf2VoZS+ODVWLptnb+LQJCK1E9w2vxss0KaeRMebD+ 3sJzgPXVp9IwA== Date: Sat, 30 Apr 2022 01:11:43 +0900 From: Masami Hiramatsu To: Mark Rutland Cc: Alexei Starovoitov , Alexei Starovoitov , Daniel Borkmann , Shubham Bansal , Andrii Nakryiko , bpf@vger.kernel.org, kernel-team@fb.com, Jiri Olsa , Steven Rostedt , "Naveen N . Rao" , Anil S Keshavamurthy , "David S . Miller" , linux-kernel@vger.kernel.org, Will Deacon , Ard Biesheuvel , Russell King , Catalin Marinas , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH bpf v2 0/4] kprobes: rethook,ARM,arm64: Replace kretprobe trampoline with rethook Message-Id: <20220430011143.81fbf5ad78bae43753aa2af4@kernel.org> In-Reply-To: References: <164937903547.1272679.7244379141135199176.stgit@devnote2> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_091153_003407_E63CA14B X-CRM114-Status: GOOD ( 46.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Mark, Sorry for replying this late. On Tue, 12 Apr 2022 19:03:53 +0100 Mark Rutland wrote: > On Fri, Apr 08, 2022 at 09:50:35AM +0900, Masami Hiramatsu wrote: > > Hi, > > Hi, > > > Here is the 2nd version of the series for replacing kretprobe trampoline > > with rethook on ARM/arm64. I fixed some compiler warnings in this version. > > What tree is this based on? It doesn't cleanly apply atop v5.18-rc1: I worked on bpf tree, but I'll try rebasing on the latest linus tree (or arm/arm64 tree) in the next version. > > | [mark@lakrids:~/src/linux]% git am v2_20220408_mhiramat_kprobes_rethook_arm_arm64_replace_kretprobe_trampoline_with_rethook.mbx > | Applying: ARM: unwind: Initialize the lr_addr field of unwind_ctrl_block > | Applying: rethook,fprobe,kprobes: Check a failure in the rethook_hook() > | Applying: ARM: rethook: Replace kretprobe trampoline with rethook > | error: patch failed: arch/arm/kernel/stacktrace.c:66 > | error: arch/arm/kernel/stacktrace.c: patch does not apply > | Patch failed at 0003 ARM: rethook: Replace kretprobe trampoline with rethook > | hint: Use 'git am --show-current-patch=diff' to see the failed patch > | When you have resolved this problem, run "git am --continue". > | If you prefer to skip this patch, run "git am --skip" instead. > | To restore the original branch and stop patching, run "git am --abort". > > I've done a `git am -3` locally to make that work for now. > > > The previous version is here[1]; > > > > [1] https://lore.kernel.org/all/164915121498.982637.12787715964983738566.stgit@devnote2/T/#u > > > > This series includes a trivial bugfix for the arm unwinder to initialize > > an internal data structure([1/4]). This is not critical for stack trace, > > but required for rethook to find the LR register from the stack. > > This also have an update for the rethook interface, which allows us to > > check the rethook_hook() failure ([2/4]). This is also required for the > > rethook on arm because unwinder is able to fail. > > The rest of patches are replacing kretprobe trampoline with rethook on > > ARM ([3/4]) and arm64 ([4/4]). > > Generally, the arm and arm64 bits go via different trees, and for unwinding the > two are quite different. OK, Should I split this into 2 series? Anyway, I'll send the first one for arm tree because this is a real bug. > > IIUC the dependency between the two is just because patch 2 changes the > prototypes of some functions. Is that right? Yes. I can push it one by one. What is the best way, would you think? If I split this into some series, I will; - Send [1/4] to arm tree as a bugfix. - Send [2/4] and [3/4] to arm tree as an enhancement. - Send [4/4] to arm64 when above 2 series are merged. Is that good for you? > > > > Background: > > > > This rethook came from Jiri's request of multiple kprobe for bpf[2]. > > He tried to solve an issue that starting bpf with multiple kprobe will > > take a long time because bpf-kprobe will wait for RCU grace period for > > sync rcu events. > > > > Jiri wanted to attach a single bpf handler to multiple kprobes and > > he tried to introduce multiple-probe interface to kprobe. So I asked > > him to use ftrace and kretprobe-like hook if it is only for the > > function entry and exit, instead of adding ad-hoc interface > > to kprobes. > > For this purpose, I introduced the fprobe (kprobe like interface for > > ftrace) with the rethook (this is a generic return hook feature for > > fprobe exit handler)[3]. > > > > [2] https://lore.kernel.org/all/20220104080943.113249-1-jolsa@kernel.org/T/#u > > [3] https://lore.kernel.org/all/164191321766.806991.7930388561276940676.stgit@devnote2/T/#u > > > > The rethook is basically same as the kretprobe trampoline. I just made > > it decoupled from kprobes. Eventually, the all arch dependent kretprobe > > trampolines will be replaced with the rethook trampoline instead of > > cloning the code. > > > > When I port the rethook for all arch which supports kretprobe, the > > legacy kretprobe specific code (which is for CONFIG_KRETPROBE_ON_RETHOOK=n) > > will be removed eventually. > > > > BTW, the arm Clang support for rethook is for kretprobes only. fprobe > > and ftrace seems not working with Clang yet. > > Do you mean that's an existing issue? Yes, but the above is not enough, Clang on arm and dynamic ftrace doesn't work. Perhaps, Clang on arm doesn't support -mrecord-mcount? Thank you, > > Thanks, > Mark. > > > > > Thank you, > > > > --- > > > > Masami Hiramatsu (4): > > ARM: unwind: Initialize the lr_addr field of unwind_ctrl_block > > rethook,fprobe,kprobes: Check a failure in the rethook_hook() > > ARM: rethook: Replace kretprobe trampoline with rethook > > arm64: rethook: Replace kretprobe trampoline with rethook > > > > > > arch/arm/Kconfig | 1 > > arch/arm/include/asm/stacktrace.h | 5 + > > arch/arm/kernel/stacktrace.c | 13 +-- > > arch/arm/kernel/unwind.c | 1 > > arch/arm/probes/Makefile | 1 > > arch/arm/probes/kprobes/core.c | 62 ------------ > > arch/arm/probes/rethook.c | 127 +++++++++++++++++++++++++ > > arch/arm64/Kconfig | 1 > > arch/arm64/include/asm/kprobes.h | 2 > > arch/arm64/include/asm/stacktrace.h | 2 > > arch/arm64/kernel/Makefile | 1 > > arch/arm64/kernel/probes/Makefile | 1 > > arch/arm64/kernel/probes/kprobes.c | 15 --- > > arch/arm64/kernel/probes/kprobes_trampoline.S | 86 ----------------- > > arch/arm64/kernel/rethook.c | 28 ++++++ > > arch/arm64/kernel/rethook_trampoline.S | 87 +++++++++++++++++ > > arch/arm64/kernel/stacktrace.c | 9 +- > > arch/x86/kernel/rethook.c | 4 + > > include/linux/rethook.h | 4 - > > kernel/kprobes.c | 8 +- > > kernel/trace/fprobe.c | 5 + > > kernel/trace/rethook.c | 12 ++ > > 22 files changed, 287 insertions(+), 188 deletions(-) > > create mode 100644 arch/arm/probes/rethook.c > > delete mode 100644 arch/arm64/kernel/probes/kprobes_trampoline.S > > create mode 100644 arch/arm64/kernel/rethook.c > > create mode 100644 arch/arm64/kernel/rethook_trampoline.S > > > > -- > > Masami Hiramatsu (Linaro) -- Masami Hiramatsu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel