Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2480807pxp; Fri, 18 Mar 2022 11:21:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw10F7bzAX4umTJrxjI4GXNJf8vPwQeh5QNFLlt+NEQbp2ofkkcjPB0k22+UnbHK/tqwO8a X-Received: by 2002:a17:90b:3e8b:b0:1c6:a5f6:1ccd with SMTP id rj11-20020a17090b3e8b00b001c6a5f61ccdmr6640586pjb.120.1647627704066; Fri, 18 Mar 2022 11:21:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647627704; cv=none; d=google.com; s=arc-20160816; b=HcmvM4hp5je2+GnxTlqAjuTfvMKbchLQzm5bIiPFMmXc0BzVBPHxzRnxlQx2pap7f6 3akuXfug7yxLn3awhpHYtKOEFvQ0SGjeyuNZrDWlgMUrN4WFJ92pDOuekRs5c55/omfq 9rY6yKT1OjluPqv2il8Wy42nM9nsEQ/qBqB2mdmEYY3Jp0G3JAnKYbPNVMjWYgd0WD0I 4jHmLrNNFrg/cQeR9M/ICpPAZSOB178KzhRwbsXiEI/ByhkSJNb53h+tuWMRrmMInIXg Cc14MPQXqRq1gZc0WwWcIExhDPVEMUq3Qcc7OAiI8EF5FbMATk/+azJlSzvzsudZaWGk TBCw== 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=H57joah6JRzSVyTYQU9KgsPj7jpKF/h05WJs7NLLPns=; b=PpmMsBWd581KJ+IDe38Wn/9mDgyeXJ9SgayjFbxQCBsR0Hx2jGXIm0RM6YR4Ip7DQF 0liDpltRN63sO4v3brFNzYp+YOrGl0xcrvx+E6fspvmRaNq7ia5NkTNabt4uVIjFGr4+ foJq+qAEx+mQwj/3CSCXT25CGfCj5jsDz7TAmeXCsa9dyjJ+4VgQwfAIHGIAGpdJx6H7 4QfxavbNCRmLTVUQ8ME1beQq1sfh/CnNTRlDuQR1I9wPfbZPy1mVgQmtQIYIFDLczJut WjuXznvfvLpo0Vxb4u8WT82nYoFke2iWqR9LUapzkezYfDeYS8Nk+K5792mkrFCCEF8T fZrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=U03bJzQT; 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 q7-20020a656a87000000b003816043eedesi6470606pgu.211.2022.03.18.11.21.27; Fri, 18 Mar 2022 11:21:44 -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=@gmail.com header.s=20210112 header.b=U03bJzQT; 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 S234062AbiCRJJt (ORCPT + 99 others); Fri, 18 Mar 2022 05:09:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiCRJJr (ORCPT ); Fri, 18 Mar 2022 05:09:47 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79966F05; Fri, 18 Mar 2022 02:08:27 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id l1-20020a05600c4f0100b00389645443d2so4483541wmq.2; Fri, 18 Mar 2022 02:08:27 -0700 (PDT) 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=H57joah6JRzSVyTYQU9KgsPj7jpKF/h05WJs7NLLPns=; b=U03bJzQT0bJEJexS9V+NX2I4JCuYr9aZlksheW/sF/hJzk4knck8d4PTQg/42l5M+j 8BI94ADqtc8LYVbhYyQf4WfPjF8JeKZbV9CLpHOuumRXb47Imnpg+UlGjFqYhIZTrazR IQYWLCJSe66umM+bPfz0Xc1Ykzkxs2SmWHVqsXxa1dELbg8qaGU8FCnEc3SFJsBAhgMw K4znPLSc9pu2I33NibQYseyJyttB7ARdDJkL8tXMBNJV/EytZxCSX65ym3JCf9NGfY3y 6vJKvTsPLrOwFmEld8bJnusWw/inq0z8v+PFQEneVo58AGh5oHPCXgJg8XcG1zOYeRDN 8sxg== 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=H57joah6JRzSVyTYQU9KgsPj7jpKF/h05WJs7NLLPns=; b=GINRlbppYgmK6EITmFkOAtPjaKR+37xQjTApNladPYzqOLTpyIk9CPmgM/XHbPdFOm Oh6p0AaWLTz10Fsa7hfI7pNeYaUhnn3PDbk2+cx8T/2JIEB4GWIR6gZOEVFIjeeUS5fP iE1u6bSO704ogotRWclG/i5fDmOsGfr45VNakaE4N40Vw8zWRonBWENvKBLiTM4L5xVW Fsv/iMMvO2c9i/KqDhfXO2l5m7TzBuZ8Mz6XmTH/Bagak4ZaBsfGsBOxxRjtQFoN3rgc VlEIXl32W43xIl2Jxhx3BRxNDLDsNejoMIhPLmg3cSQqH0Cwwg2Y4vmWK0MOuBKJSddM cKBQ== X-Gm-Message-State: AOAM532cFi6JindYKWD2MxK8gFxg6MOZBRryGaAN1/S6MRmGJpcIgvcT ewZZii4dWWuKGJlCQqFnTHY= X-Received: by 2002:a05:600c:1e1f:b0:38b:d7ea:99b9 with SMTP id ay31-20020a05600c1e1f00b0038bd7ea99b9mr7345798wmb.8.1647594505926; Fri, 18 Mar 2022 02:08:25 -0700 (PDT) Received: from krava ([193.85.244.190]) by smtp.gmail.com with ESMTPSA id f8-20020adfb608000000b0020229d72a4esm5686171wre.38.2022.03.18.02.08.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Mar 2022 02:08:25 -0700 (PDT) Date: Fri, 18 Mar 2022 10:08:22 +0100 From: Jiri Olsa To: Alexei Starovoitov Cc: Jiri Olsa , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu , Network Development , bpf , lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Steven Rostedt Subject: Re: [PATCHv3 bpf-next 09/13] libbpf: Add bpf_program__attach_kprobe_multi_opts function Message-ID: References: <20220316122419.933957-1-jolsa@kernel.org> <20220316122419.933957-10-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 Thu, Mar 17, 2022 at 08:53:15PM -0700, Alexei Starovoitov wrote: > On Wed, Mar 16, 2022 at 5:26 AM Jiri Olsa wrote: > > + > > +struct bpf_link * > > +bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog, > > + const char *pattern, > > + const struct bpf_kprobe_multi_opts *opts) > > +{ > > + LIBBPF_OPTS(bpf_link_create_opts, lopts); > > + struct kprobe_multi_resolve res = { > > + .pattern = pattern, > > + }; > > + struct bpf_link *link = NULL; > > + char errmsg[STRERR_BUFSIZE]; > > + const unsigned long *addrs; > > + int err, link_fd, prog_fd; > > + const __u64 *cookies; > > + const char **syms; > > + bool retprobe; > > + size_t cnt; > > + > > + if (!OPTS_VALID(opts, bpf_kprobe_multi_opts)) > > + return libbpf_err_ptr(-EINVAL); > > + > > + syms = OPTS_GET(opts, syms, false); > > + addrs = OPTS_GET(opts, addrs, false); > > + cnt = OPTS_GET(opts, cnt, false); > > + cookies = OPTS_GET(opts, cookies, false); > > + > > + if (!pattern && !addrs && !syms) > > + return libbpf_err_ptr(-EINVAL); > > + if (pattern && (addrs || syms || cookies || cnt)) > > + return libbpf_err_ptr(-EINVAL); > > + if (!pattern && !cnt) > > + return libbpf_err_ptr(-EINVAL); > > + if (addrs && syms) > > + return libbpf_err_ptr(-EINVAL); > > + > > + if (pattern) { > > + err = libbpf_kallsyms_parse(resolve_kprobe_multi_cb, &res); > > + if (err) > > + goto error; > > + if (!res.cnt) { > > + err = -ENOENT; > > + goto error; > > + } > > + addrs = res.addrs; > > + cnt = res.cnt; > > + } > > Thanks Jiri. > Great stuff and a major milestone! > I've applied Masami's and your patches to bpf-next. great, thanks > > But the above needs more work. > Currently test_progs -t kprobe_multi > takes 4 seconds on lockdep+debug kernel. > Mainly because of the above loop. > > 18.05% test_progs [kernel.kallsyms] [k] > kallsyms_expand_symbol.constprop.4 > 12.53% test_progs libc-2.28.so [.] _IO_vfscanf > 6.31% test_progs [kernel.kallsyms] [k] number > 4.66% test_progs [kernel.kallsyms] [k] format_decode > 4.65% test_progs [kernel.kallsyms] [k] string_nocheck > > Single test_skel_api() subtest takes almost a second. hm, I'll check on lockdep+debug kernel.. I think this test should be going through kallsyms just once, will check anyway libbpf_kallsyms_parse could use ksym_get_addr, which is now cached > > A cache inside libbpf probably won't help. > Maybe introduce a bpf iterator for kallsyms? > > On the kernel side kprobe_multi_resolve_syms() looks similarly inefficient. > I'm not sure whether it would be a bottle neck though. > > Orthogonal to this issue please add a new stress test > to selftest/bpf that attaches to a lot of functions. ok, will add that thanks, jirka