From patchwork Wed Aug 23 15:16:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 136720 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp694030vqm; Wed, 23 Aug 2023 13:06:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLE7cbGzrsbum4hQQyDLsG55Xv4Ru66RqASZlhgkw24dHnNxhco8UHN62iSk11Ag7xCusx X-Received: by 2002:a05:6a20:324c:b0:131:6fd:8f5a with SMTP id hm12-20020a056a20324c00b0013106fd8f5amr10814382pzc.32.1692821165307; Wed, 23 Aug 2023 13:06:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692821165; cv=none; d=google.com; s=arc-20160816; b=qLpd8JfdmRgDIMwH2nEWgjhwQEI/q7gDfOfsGJtmISqK1Ou4SRdtyxxJgPUY9u3AHq NsioYllDCtydrqMcO/xstvFArAek/OxznTUDGcbLYthbyNdWNKMxyiyFzQ9uzP5TVP2t 9NrAJR7XJDesUjKxucrV2J9vBOPrkEC3n/xEV6sG/WMbWDcQBJpAzsSjwzfuhIzV1oif 1+5qtewLJ0QUZ9b2LMYUxJXDaGRuxBOImnURB+ynzAOK0d02VZWoPXURkKWQdPWYwXy/ HedE0CqnO5jafkd0P01QNuKEVK9+bQwYzOrtXeCr63/MgA/7gvCeZ30o61DeVfEfAcKc DWjA== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kvL28OBCkLpWr6szs+ti5tpLxLNqYukFPA6n/vHEuyA=; fh=nNLeqPmm07c4DrdDej5z+HdJpmx5SqFFnpeka2nrMVM=; b=ocKIUqVZ/rmCs6bBgi7Szmjsl8pEQFH7Wnd4NEdL3nRco3TXWM3D+rj1NLiWp88Mu+ euwGS5ouniCey9Kuq9LEsivWBENulSV8oiPZuA2uTDk06qZqZtec28aAwKxskk3zwk/j pbeWTzRwbPPBwFGNQqHhvrpNvcH5jI5oXOvxMoIMJmGXDec36yvkF5LWsIz1+Je/WTVv 8E7hF3EPMEt/p5GXUSpanBXBcHkvEy7VNA/b4qybKYjG78WRyihVho2VFCDSY7oNxKp0 2FRHBElv3HoNHqiSdKQvORzqlo0/Tixbqinj7WGqnT/Ptx3Vz1sq/YrhC+Aj/QbWZL5j SDEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=H7oOGHI+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ea18-20020a056a004c1200b00689f65ece99si4277368pfb.225.2023.08.23.13.05.44; Wed, 23 Aug 2023 13:06:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=H7oOGHI+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237089AbjHWPSL (ORCPT + 99 others); Wed, 23 Aug 2023 11:18:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237065AbjHWPSD (ORCPT ); Wed, 23 Aug 2023 11:18:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C66101738; Wed, 23 Aug 2023 08:17:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BE6EB64E61; Wed, 23 Aug 2023 15:16:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52F74C433C7; Wed, 23 Aug 2023 15:16:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692803811; bh=7B4CIzVJLnLCmWiU4haDKVfyzxSXSWysR7Bdn2Pzp1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H7oOGHI+6cNBySWTDApvSYjiXOwCS3lUZ70b9FAR9meElipdFe9RAQ8tbjSRohg6f afZj6zv4mFUwzLIQDPQFoZJOlzIO7uzxjy+ZXT9D0Z25yq0LiQi/aU1lAryknpLJne jpzAUIP3Fy80gUQV4Yuz504zmfBPIjVUwrvgIVZpB8rWPAtIHz1/fgSO7DRtWxSF0d 4ZHOcxSFyvW9cPgBq0wShwAyxDR/qn1xeMX9Q33JqZ/kWWDogvXhTxl9KrnoWBYp9P wi/gA5Xw1ZL0mrSqujBB5YDHwws5aF6pv85zCtctiu1xWGORsqe2NGA7QP8CkYOesK /wYQzPVf9/dIQ== From: "Masami Hiramatsu (Google)" To: Alexei Starovoitov , Steven Rostedt , Florent Revest Cc: linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Mark Rutland , Peter Zijlstra , Thomas Gleixner Subject: [PATCH v4 7/9] bpf: Enable kprobe_multi feature if CONFIG_FPROBE is enabled Date: Thu, 24 Aug 2023 00:16:47 +0900 Message-Id: <169280380720.282662.17571417296398071399.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169280372795.282662.9784422934484459769.stgit@devnote2> References: <169280372795.282662.9784422934484459769.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775051646303078791 X-GMAIL-MSGID: 1775051646303078791 From: Masami Hiramatsu (Google) Enable kprobe_multi feature if CONFIG_FPROBE is enabled. The pt_regs is converted from ftrace_regs by ftrace_partial_regs(), thus some registers may always returns 0. But it should be enough for function entry (access arguments) and exit (access return value). Signed-off-by: Masami Hiramatsu (Google) Acked-by: Florent Revest --- kernel/trace/bpf_trace.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index c4d57c7cdc7c..ac9bd5e7ec27 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2467,7 +2467,7 @@ static int __init bpf_event_init(void) fs_initcall(bpf_event_init); #endif /* CONFIG_MODULES */ -#if defined(CONFIG_FPROBE) && defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS) +#ifdef CONFIG_FPROBE struct bpf_kprobe_multi_link { struct bpf_link link; struct fprobe fp; @@ -2489,6 +2489,8 @@ struct user_syms { char *buf; }; +static DEFINE_PER_CPU(struct pt_regs, bpf_kprobe_multi_pt_regs); + static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 cnt) { unsigned long __user usymbol; @@ -2630,13 +2632,14 @@ static u64 bpf_kprobe_multi_entry_ip(struct bpf_run_ctx *ctx) static int kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link, - unsigned long entry_ip, struct pt_regs *regs) + unsigned long entry_ip, struct ftrace_regs *fregs) { struct bpf_kprobe_multi_run_ctx run_ctx = { .link = link, .entry_ip = entry_ip, }; struct bpf_run_ctx *old_run_ctx; + struct pt_regs *regs; int err; if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1)) { @@ -2646,6 +2649,7 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link, migrate_disable(); rcu_read_lock(); + regs = ftrace_partial_regs(fregs, this_cpu_ptr(&bpf_kprobe_multi_pt_regs)); old_run_ctx = bpf_set_run_ctx(&run_ctx.run_ctx); err = bpf_prog_run(link->link.prog, regs); bpf_reset_run_ctx(old_run_ctx); @@ -2663,13 +2667,9 @@ kprobe_multi_link_handler(struct fprobe *fp, unsigned long fentry_ip, void *data) { struct bpf_kprobe_multi_link *link; - struct pt_regs *regs = ftrace_get_regs(fregs); - - if (!regs) - return 0; link = container_of(fp, struct bpf_kprobe_multi_link, fp); - kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs); + kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), fregs); return 0; } @@ -2679,13 +2679,9 @@ kprobe_multi_link_exit_handler(struct fprobe *fp, unsigned long fentry_ip, void *data) { struct bpf_kprobe_multi_link *link; - struct pt_regs *regs = ftrace_get_regs(fregs); - - if (!regs) - return; link = container_of(fp, struct bpf_kprobe_multi_link, fp); - kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs); + kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), fregs); } static int symbols_cmp_r(const void *a, const void *b, const void *priv) @@ -2925,7 +2921,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr kvfree(cookies); return err; } -#else /* !CONFIG_FPROBE || !CONFIG_DYNAMIC_FTRACE_WITH_REGS */ +#else /* !CONFIG_FPROBE */ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) { return -EOPNOTSUPP;