Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2073555pxb; Fri, 25 Mar 2022 10:36:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFvy4eGylLIpW72dqYPVM8dZuU9HzaqzUAdlqzsI1YtUcs3olyaZu9Hw/a74lEPEN1TFNu X-Received: by 2002:a17:902:c215:b0:153:8d90:a108 with SMTP id 21-20020a170902c21500b001538d90a108mr13111105pll.172.1648229783347; Fri, 25 Mar 2022 10:36:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648229783; cv=none; d=google.com; s=arc-20160816; b=sg8u99wcC6IsphQjWUW3jURo/xCWJS2kzgCmnFxy/VtLrEin47bX9MwmteLRoIz0QB SM0QOu1lt3oAC6fKaWyGJKptAEGimRGhHX4esuTLO+3NsULnyJBe6Ty2VE5A8Ml/DCMa SGvi+oOd95X/61R6FGBAajFaSPDZXrPtvS/SHYHrpUCjbDhVWtvVAe8RbhDexg9HoYb4 HQ0FCFy6a407rj17oxgZHziYG3vomhVMl4T2rxDoJqaUdFGiTpF9XWO9q2ioEjglmOyE dVWeX61/r8ZkUSplbCXmFbj6c8sU1ANIyxx9fDGulijxenaN0KaCIwaDAYAagvY0nJKJ 4KAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:date:subject:cc:to:from:dkim-signature; bh=cv2HAi1/GqMdHqYi4kD1QKC4J7xbp//rH90NrjAm15U=; b=EyI/UVFfabMe1/C68VEFt0VRPJBhJF0DNyt2azyS0GlEngD8m7m+w/xbzTpTRY14vb Vm+ej+BVpEbCMl86+4uvNQIj4TiseajsOdHG4sUySmRAfSahp8JupJUJQXNdlAMjKwbR YO7TgT8hqhm9HwL2Kip4xESjlFp1R+c4X4czAD40vOuzV8n4uveJesyq8xKHf5svNfRU V18JwMazTzTOeNPUO6pssFmE7rdLVsm37sXwsE2cEWbDfNosH1JwHbQiMK9nYUsd0LI+ sPnFpho8wud81hHGRzZXdh2S1c3yj2dQhtwC7tu4twTYIeDYuKfoRlG7C+Zo7X/pEvx7 hIKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mVs6t1TT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m16-20020a170902f65000b00153b2d16444si3033226plg.76.2022.03.25.10.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 10:36:23 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mVs6t1TT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DC1E510EC65; Fri, 25 Mar 2022 10:24:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244876AbiCYOYi (ORCPT + 99 others); Fri, 25 Mar 2022 10:24:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239999AbiCYOYg (ORCPT ); Fri, 25 Mar 2022 10:24:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5F671009; Fri, 25 Mar 2022 07:23:01 -0700 (PDT) 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 86123B8288C; Fri, 25 Mar 2022 14:23:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DB2FC340E9; Fri, 25 Mar 2022 14:22:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648218179; bh=DltTo5IPp+afM/kBYNU4tPTueYUlNlIcT8OkeI7iSc4=; h=From:To:Cc:Subject:Date:From; b=mVs6t1TTgTES6UGTw6RJ8sDXSHojLSRLLWiNxhLt8we3mDe1b7WuYekeoJ83/sWl1 2GJcqoQhSxFRPTM9r/L76MpjtXHYjdDCW3bIV7B9UszcKTvyd5hiJnXmakk8RcFiD+ Cm7wV2QsaaE5W4c0Q2+wXO5ApBQQNxyk8kYA2xyatCIrW/HmpkqlzJdULF60g+frPV UvBAZ6J24a7QScYWI3uXkoZYoSg4Hd+LihWsqYrRLlOuoUreUHVziDf7VCZykzbK+w UttGpR9+Jy+LHbV1zVcITs5dmQldYAtm31KXosleoX9QDbRQk6VC+e6Htv/L4svaDd qXXObgd8ONnsQ== From: Masami Hiramatsu To: Alexei Starovoitov , Andrii Nakryiko , x86@kernel.org, Peter Zijlstra Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Dan Carpenter , kernel-janitors@vger.kernel.org, Steven Rostedt , Masami Hiramatsu , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2 0/4] kprobes: rethook: x86: Replace kretprobe trampoline with rethook Date: Fri, 25 Mar 2022 23:22:53 +0900 Message-Id: <164821817332.2373735.12048266953420821089.stgit@devnote2> X-Mailer: git-send-email 2.25.1 User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Here are the 2nd version for generic kretprobe and kretprobe on x86 for replacing the kretprobe trampoline with rethook. The previous version is here[1] [1] https://lore.kernel.org/all/164818251899.2252200.7306353689206167903.stgit@devnote2/T/#u In this version I added completing pt_regs by saving regs->ss register for rethook (from Peter) and optprobe. Background: This rethook came from Jiri's request of multiple kprobe for bpf[1]. 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)[2]. [1] https://lore.kernel.org/all/20220104080943.113249-1-jolsa@kernel.org/T/#u [2] 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 and set HAVE_RETHOOK=y. 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. Worktree notice: BTW, this patch can be applied to next-20220324, not the bpf-next tree directly, because this depends on ANNOTATE_NOENDBR macro. However, since the fprobe is merged in the bpf-next, I marked this for bpf-next. So until merging the both of fprobes and ENDBR series, to compile this you need below 2 lines in arch/x86/kernel/rethook.c. #ifndef ANNOTATE_NOENDBR #define ANNOTATE_NOENDBR But after those are merged, these lines will be unneeded. How should I handle this issue? (Just remove ANNOTATE_NOENDBR line in bpf-next?) Thank you, --- Masami Hiramatsu (3): kprobes: Use rethook for kretprobe if possible rethook: kprobes: x86: Replace kretprobe with rethook on x86 x86,kprobes: Fix optprobe trampoline to generate complete pt_regs Peter Zijlstra (1): Subject: x86,rethook: Fix arch_rethook_trampoline() to generate a complete pt_regs arch/Kconfig | 7 ++ arch/x86/Kconfig | 1 arch/x86/include/asm/unwind.h | 23 +++---- arch/x86/kernel/Makefile | 1 arch/x86/kernel/kprobes/common.h | 1 arch/x86/kernel/kprobes/core.c | 107 --------------------------------- arch/x86/kernel/kprobes/opt.c | 25 +++++--- arch/x86/kernel/rethook.c | 123 ++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/unwind_orc.c | 10 ++- include/linux/kprobes.h | 51 +++++++++++++++- kernel/kprobes.c | 124 ++++++++++++++++++++++++++++++++------ kernel/trace/trace_kprobe.c | 4 + 12 files changed, 319 insertions(+), 158 deletions(-) create mode 100644 arch/x86/kernel/rethook.c -- Masami Hiramatsu (Linaro)