From patchwork Sat Aug 12 05:37:58 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: 134817 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1539047vqi; Fri, 11 Aug 2023 22:55:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXRNuxVG6WkyRr5ko+i60Ra0zFSUA1aT+QxQLp0XreDmteQbQJAHcbG7pITfr0Dgj1ZjSL X-Received: by 2002:a05:6870:c086:b0:1be:9b41:a144 with SMTP id c6-20020a056870c08600b001be9b41a144mr4816149oad.37.1691819727598; Fri, 11 Aug 2023 22:55:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691819727; cv=none; d=google.com; s=arc-20160816; b=HtAwPB1716z2Gv64bMreoPdtzp/lXdhbFBISMxzJlIUCPdayl2DvQLjQYQPRfmOcO0 rnGJb6J1gdrwWu2wpwdAKd1+Rt1KVUU43trBjZX+7eSeHvec1Xcb80PMC8WZ+0dzZuhw z1JUMZ6RDPtUC+5O2BI5WkfUJKMclpS29K1ZEsfBonG59PCVM/oA8+JdSMhKgBGsHxvf B2AMb1+5G0bBv4aS7VG8nzXcV4U8nscl7gVmR0lbto3E58RIZQFa+i7WBlGCrXfZLqBC j6oYGkgrOMhjN+oRRZE7OYgQJ8j9r3/FS70Bzx5ufveVO9jhzkGnBvaduYIPluBYcji1 GZuw== 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=L1sPBgZBqD/VPBRS76BWRdViHfXvJfXvFcWJan54Adw=; fh=nNLeqPmm07c4DrdDej5z+HdJpmx5SqFFnpeka2nrMVM=; b=EDzUyNiIl2gSXNEzPSI9/+mSEh+BWLrog4TdRmzlrG5MRQUpHBsFk2FYZjV9oN25Jn QUQcFAtMhTloC2bYvURVuf2xCQ2F0NldL5hk801uOGN7xCkWIOUhw5JNf2LX0snvT2xm 6HrqMhMrriqsyjudOjShU7/yZuoCQV+YUKRHQik68YwCOPpiqpba6k1SJsAcHveZIsJr 8obbrVUtxt88VdG8V1YIuaiHG9rQgQYxkGZ96Y7jOutdeMFByB1edpe2aUYtf9ZaOHWf 9EJxed2rNF5SSFFMkY3jOCqLIWraFIYY8f+3wXSGXNFwdwEILV75nenKcRbfo75LoiS0 5aIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jfaDa+GX; 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 z19-20020a170903409300b001bb42c27496si4281962plc.233.2023.08.11.22.55.11; Fri, 11 Aug 2023 22:55:27 -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=jfaDa+GX; 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 S236370AbjHLFiL (ORCPT + 99 others); Sat, 12 Aug 2023 01:38:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236294AbjHLFiK (ORCPT ); Sat, 12 Aug 2023 01:38:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A60993594; Fri, 11 Aug 2023 22:38:05 -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 4746064275; Sat, 12 Aug 2023 05:38:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11FC0C433C8; Sat, 12 Aug 2023 05:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691818684; bh=btg0nVFd43rpoQn9jPOpj+aatNUMeTGQfbwvThvH8GU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jfaDa+GXfxN3i5eFggQmuF2xK/ICqBU1egNhAgRLxMg/cu90+CeybZV8YhC8o3U4s TOsFDSt56jt481duvUK/MB7pxcxY15E1wXtzjzraIBAKSe9akH/flMiG/sDLA6uiWL s1a13lCN54U5hRt4XQMj1/+hgZN0JR99CeyEB8r+zpywxB+d6HB00Es1FTRQnkBrH+ zeTh0I29M9Dym4RMWzTnVfF94C8ytztViXqUYzbqJeMxxplxEO3E0UhsChayH/7CEt RU7l5ASb0IwRO4ulWNEDb0I9ds5JLFGLbjgMZYT4K9EFHQzLSHZ0JAXtE6dkIcl0e3 H5sVvQj4gWcVg== 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 v3 7/8] bpf: Enable kprobe_multi feature if CONFIG_FPROBE is enabled Date: Sat, 12 Aug 2023 14:37:58 +0900 Message-Id: <169181867839.505132.10717747708330472036.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169181859570.505132.10136520092011157898.stgit@devnote2> References: <169181859570.505132.10136520092011157898.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: 1774001562522418931 X-GMAIL-MSGID: 1774001562522418931 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) --- 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 31f2707f8df7..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 */ -#ifdef 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_DYNAMIC_FTRACE_WITH_REGS */ +#else /* !CONFIG_FPROBE */ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) { return -EOPNOTSUPP;