Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3337781pxp; Tue, 8 Mar 2022 12:11:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJztOpfHHaNXMN1X8t+je+uz0KXsr7zcv6gWGOdtlYnN/sFTCts67VXUOhlLdUBm+HjRDYDs X-Received: by 2002:a05:6a00:1a8b:b0:4f7:10a6:3cea with SMTP id e11-20020a056a001a8b00b004f710a63ceamr9297425pfv.75.1646770317564; Tue, 08 Mar 2022 12:11:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646770317; cv=none; d=google.com; s=arc-20160816; b=wPkhwgPQphl+JScIMLyWsc6BodqdQHOxvTTLlCVEnyy+ni/kKxjbffdOEm5qp/3lPf adkrkl9tRQGyGWPsl3+er4KOnTX6/aS9HiyXQhNXoeCNR8TXrpS33TfBFT6+j3BreO/e Bmcqd33/s81ZcR2/Dg9JdBvhWeyvKZK0Kuj+RvZhkyw1U7QNyiwjnSp6Y5eeul/1gCqb mkJ2YTwRP+7js7nwnNcpz3IWsgy/I+EMZix+tw92ao7THiFpaPCGXf5htbZZEO59IFTO qyG1IKUJupA6Ut30mGwEvawH1c5TkkLE1+y7Z+3XMl9lKaBUzP3jPYYGfHtuwfUK/V1h HPEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=EWTDePeT9c6La97u9wbH4GX9FAATzBXHG6ctqZCvpd8=; b=a7NjtSQnAXw+lhMLeD09bqOhlUyGpMosM0CRkAUrUvBpktphZ7x+6NEYX/NW+gg/BB RyaTj/l83dFoOgBNhDtOx5TkRzewjDWb2JXPJ4itHNqouXM7mC0AJ03Y+gv0YzGNpm8Z sQy31YBDPiPV8uuu9bkPj/Gq6o0nZ85OB+zFLSglHod/GmLSj5Ahmjo632hDA4L4Mprd 44bFU0bmEqR5N9hPZxu+6am47UhFRO//V5+EALV8qGOzrh+UvysNVODJ2xXpBKTm87uy PtsOGFv/3GV4lUWxPwxzX9a5wBmoa4igUUaoPPrFDQSVJ1HoxA6x1GMMGqL50/yM7x4J GFoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SwqxHt+C; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 32-20020a631460000000b0036c42338354si16372717pgu.26.2022.03.08.12.11.41; Tue, 08 Mar 2022 12:11:57 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=SwqxHt+C; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241044AbiCHOYi (ORCPT + 99 others); Tue, 8 Mar 2022 09:24:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230433AbiCHOYg (ORCPT ); Tue, 8 Mar 2022 09:24:36 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D85E447AEE; Tue, 8 Mar 2022 06:23:38 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id q17so24704019edd.4; Tue, 08 Mar 2022 06:23:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=EWTDePeT9c6La97u9wbH4GX9FAATzBXHG6ctqZCvpd8=; b=SwqxHt+CEM8U7jF/UK1QRxl5zaWGz+Rpz4kjl8tvUvDaBAc0cOanxW07D6pncov5FM gkd2qQwI0YwO6fv6KGfwWTdIhmXVP5unai0Qp+omUXb+WQ5xFptNlsN3Il9kPfrWZRuD CeAlmjr+WCW5YMTmeG1wxqXSlw5Y8rfh6YOqPMT3r7liiLMwwk7MPSOlCqq5FNhp5spZ +bgyq/QIo2p0dq9S8g0ec/FDVJJD89jCSGDGpl+fJBco42+cQIKend21tWdBKmt4J3wO +vBMgEKph46t0L6FqdMWxfStycIg/UlleEu+fPcXuYPcf15ut2tI1yFpYukWA4Y99cq0 wetw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=EWTDePeT9c6La97u9wbH4GX9FAATzBXHG6ctqZCvpd8=; b=yVi16mZr87jj1MElEFulv7aLWUIczzorKfy2OsnTasZuzTvlFxSmBgpUmQoCEXMBUN vpfTKa/fvKxkg30hLPapnm7dYaUo46dQGQi4InVNj+6lL8KALTEOx2KEMJdVhaPKq/i1 WpTVN71N/HbzHCFn8hzz51IwZTnEkIE1qNVBP50uWJrvJTaUDPm7twkuMjY1HD0sXNiL q/QjjEsFobTT9MiYLTdiOtA6XNrUpnnJchi0yumkO0iDOlmwQekEzhHrtsiEOO+dn0gM tZDSKcLxJLTdkccratK65KWcEcrXCBsmQ6EQcAE72w5ddwfUgxAqkRt1uoEp6uwVKTTH U/1A== X-Gm-Message-State: AOAM5309a3rJmNy5plStQKOexG2Xn5T/kX8gmgBmCoR7qqtx8EiPXgri V5iz0/jhGSA32I1+ivJlMgo= X-Received: by 2002:a50:fd8e:0:b0:415:fe34:f03 with SMTP id o14-20020a50fd8e000000b00415fe340f03mr16318601edt.310.1646749417260; Tue, 08 Mar 2022 06:23:37 -0800 (PST) Received: from krava ([193.85.244.190]) by smtp.gmail.com with ESMTPSA id s14-20020aa7cb0e000000b00410bf015567sm7483195edt.92.2022.03.08.06.23.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 06:23:36 -0800 (PST) Date: Tue, 8 Mar 2022 15:23:34 +0100 From: Jiri Olsa To: Andrii Nakryiko Cc: Jiri Olsa , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu , Masami Hiramatsu , Yucong Sun , Networking , bpf , lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Steven Rostedt Subject: Re: [PATCH 08/10] libbpf: Add bpf_program__attach_kprobe_opts support for multi kprobes Message-ID: References: <20220222170600.611515-1-jolsa@kernel.org> <20220222170600.611515-9-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Mon, Mar 07, 2022 at 05:28:54PM -0800, Andrii Nakryiko wrote: > On Sun, Mar 6, 2022 at 9:29 AM Jiri Olsa wrote: > > > > On Fri, Mar 04, 2022 at 03:11:19PM -0800, Andrii Nakryiko wrote: > > > On Tue, Feb 22, 2022 at 9:07 AM Jiri Olsa wrote: > > > > > > > > Adding support to bpf_program__attach_kprobe_opts to attach kprobes > > > > to multiple functions. > > > > > > > > If the kprobe program has BPF_TRACE_KPROBE_MULTI as expected_attach_type > > > > it will use the new kprobe_multi link to attach the program. In this case > > > > it will use 'func_name' as pattern for functions to attach. > > > > > > > > Adding also new section types 'kprobe.multi' and kretprobe.multi' > > > > that allows to specify wildcards (*?) for functions, like: > > > > > > > > SEC("kprobe.multi/bpf_fentry_test*") > > > > SEC("kretprobe.multi/bpf_fentry_test?") > > > > > > > > This will set kprobe's expected_attach_type to BPF_TRACE_KPROBE_MULTI, > > > > and attach it to functions provided by the function pattern. > > > > > > > > Using glob_match from selftests/bpf/test_progs.c and adding support to > > > > match '?' based on original perf code. > > > > > > > > Cc: Masami Hiramatsu > > > > Cc: Yucong Sun > > > > Signed-off-by: Jiri Olsa > > > > --- > > > > tools/lib/bpf/libbpf.c | 130 +++++++++++++++++++++++++++++++++++++++-- > > > > 1 file changed, 125 insertions(+), 5 deletions(-) > > > > > > > > > > [...] > > > > > > > +static struct bpf_link * > > > > +attach_kprobe_multi_opts(const struct bpf_program *prog, > > > > + const char *func_pattern, > > > > + const struct bpf_kprobe_opts *kopts) > > > > +{ > > > > + DECLARE_LIBBPF_OPTS(bpf_link_create_opts, opts); > > > > > > nit: just LIBBPF_OPTS > > > > ok > > > > > > > > > > > > + struct kprobe_multi_resolve res = { > > > > + .name = func_pattern, > > > > + }; > > > > + struct bpf_link *link = NULL; > > > > + char errmsg[STRERR_BUFSIZE]; > > > > + int err, link_fd, prog_fd; > > > > + bool retprobe; > > > > + > > > > + err = libbpf_kallsyms_parse(resolve_kprobe_multi_cb, &res); > > > > > > hm... I think as a generic API we should support three modes of > > > specifying attachment target: > > > > > > > > > 1. glob-based (very convenient, I agree) > > > 2. array of function names (very convenient when I know specific set > > > of functions) > > > 3. array of addresses (advanced use case, so probably will be rarely used). > > > > > > > > > > > > So I wonder if it's better to have a separate > > > bpf_program__attach_kprobe_multi() API for this, instead of doing both > > > inside bpf_program__attach_kprobe()... > > > > > > In such case bpf_program__attach_kprobe() could either fail if > > > expected attach type is BPF_TRACE_KPROBE_MULTI or it can redirect to > > > attach_kprobe_multi with func_name as a pattern or just single > > > function (let's think which one makes more sense) > > > > > > Let's at least think about this > > > > I think it would make the code more clear, how about this: > > > > struct bpf_kprobe_multi_opts { > > /* size of this struct, for forward/backward compatiblity */ > > size_t sz; > > > > const char **funcs; > > naming nit: func_names (to oppose it to "func_pattern")? Or just > "names" to be in line with "addrs" (but then "pattern" instead of > "func_pattern"? with kprobe it's always about functions, so this > "func_" everywhere is a bit redundant) ok > > > const unsigned long *addrs; > > const u64 *cookies; > > int cnt; > > nit: let's use size_t ok > > > > bool retprobe; > > size_t :0; > > }; > > > > bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog, > > const char *pattern, > > const struct bpf_kprobe_multi_opts *opts); > > > > > > if pattern is NULL we'd use opts data: > > > > bpf_program__attach_kprobe_multi_opts(prog, "ksys_*", NULL); > > bpf_program__attach_kprobe_multi_opts(prog, NULL, &opts); > > > > to have '2. array of function names' as direct function argument, > > we'd need to add 'cnt' as well, so I think it's better to have it > > in opts, and have just pattern for quick/convenient call without opts > > > > yeah, naming pattern as direct argument for common use case makes > sense. Let's go with this scheme great, I'll make the changes thanks, jirka