Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2015874pxp; Fri, 18 Mar 2022 00:45:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0WwuTlIPrDRbTecKqYR2D3LuBoe6d0t9bLQqnz0eHwkxMTk5kSGBAJcs52FjHfburEbJV X-Received: by 2002:a62:1a53:0:b0:4f7:69d:9731 with SMTP id a80-20020a621a53000000b004f7069d9731mr8965563pfa.31.1647589506148; Fri, 18 Mar 2022 00:45:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647589506; cv=none; d=google.com; s=arc-20160816; b=CkfSQe9FEekuv7MhOsruEK5nA+oKuE3XL3mirguWHTNzSf4oEd9PxWRejL0f8jlTN1 neu7hshuDweEz8IKKV0ihRV/fndKIextaUGsRjPhx0WlfrE72edPZydWyhPD0wxaJ53B vi7K3P6Zj+BNvqgvXwMgWmi+mvzJaHR1TqW1H4cIC6huw0HjffVe9Z2bHcMY859CcqM2 zh1f8DKvYloI2en9o7MeV/95mbNV0/LW4dipv+VQeZ8hfdeAUD6lFFjb5Y9N0NZIEcYj CIXhk6UPOYBJdHZqxKjmbxpt+j64kR1HNExZOo9t+tglzLLsG4aI9DJYTm4Urjyj4Jx3 v2BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=rI0FrmQ3+ceiLgNiqpfsxdYGbjB79Df3AZRI5bRwQ0o=; b=T1j+goIS9Fw3BOK3QYn0N2O6HAAIfMi+bf/mH9qEPtUxH4qttZmCRCGci98LBC1vgd jrZG2DsAmMJAYnITsTsBFryx4IHVFdPyQ8cNSN5TkA6BAXNTNic0vWIDSgKW/Jj2XXm5 dZTAi2Q8nPozH0eEtrdIm9ruIPpUjGUDr7ji0xjGgKVXe2oUgN4Kck6n0gdZNMqM4Xu8 8RcDiwOyXe21b7/KW/xM+RlRHi7oF9gTVTm7fTAkbHG94qTfH6sdhXLRqm4Ec7+t2sLf FtQfwLg/4U26MvUhEBkpVNsDQ4eK+s+ZBDcti+011YuLkcarLQEbEPOxBAF+O/+b+4jK nBwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Hn4JBwIy; 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 g6-20020a170902c38600b00153e6d033b5si1351194plg.31.2022.03.18.00.44.54; Fri, 18 Mar 2022 00:45:06 -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=Hn4JBwIy; 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 S231700AbiCRDyr (ORCPT + 99 others); Thu, 17 Mar 2022 23:54:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230156AbiCRDyp (ORCPT ); Thu, 17 Mar 2022 23:54:45 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8310B1760D8; Thu, 17 Mar 2022 20:53:27 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id n18so6084512plg.5; Thu, 17 Mar 2022 20:53:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rI0FrmQ3+ceiLgNiqpfsxdYGbjB79Df3AZRI5bRwQ0o=; b=Hn4JBwIy1jFjd69nBo+JFJCVJTNTD+3bEmjId2ADMgJLcte32nRtt93TpmWQRS4c7x rR3dQlzClV0KAYsGDhtSw8cDWKQ2t/uiy5tlnOJIYD3VY9RESUiS6CnLqkdazkns/6pv UAHAKywoeebHtivA1rdf1btn57gw/UFuxxO4ILGRDP6jhPc3W8CRA2pVUs0Y4QvLIuQ9 x/i37jh/SlO7Rj/lk0Raz/Wv5GvcU34ithzP8JXKVzYdvCz/gMAuQT76Qps4bLfKGpS9 iF44e0+FX8XLrJ9zp8D1QK50IQKSEpT/T09RfNixVI/NIZzXht9u9PY/z2YmhBY4TxEL sTbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rI0FrmQ3+ceiLgNiqpfsxdYGbjB79Df3AZRI5bRwQ0o=; b=myUwgMgfEjOURmVrguPuQL9F8B5CNc1nQiHx/I80q0un7b06zcJaODO6zf8R1fhcl5 cfU96kCzCnOQGnXIGOg+GVM5r/HKFTeeTh+6/7FIwaEPxME3ZgD8RQWafCAVPNZ4zsjc XJN1vNvvBT9/ijLM/kMkUgdohg2aGgtf1ixdXlhDYhZtESjoxZVn77NSxVS/zYDC9S9T hmqmQ/L5Lb1wnp9Y866Kitm0NIHrWONju26Kb8WWt+taIKxilD2dC97Jg4TILumxF+EG G/uEKaDPpPhwKzGgZZkfaC4PK5PjKvRqNsgmVs16ccYAO85sG+yL3x+bvPhjiIH8jyUG KJIQ== X-Gm-Message-State: AOAM531jsO0adzyj4QqFwvrZIXWHA97+o89aGO3B1ZXeYX/d7CyWG+xH iYnpEKWKB4sKUZ5iEdAGjubpn1kg1ihRN9whnu8= X-Received: by 2002:a17:902:ab10:b0:153:b520:dbbe with SMTP id ik16-20020a170902ab1000b00153b520dbbemr7875333plb.55.1647575606916; Thu, 17 Mar 2022 20:53:26 -0700 (PDT) MIME-Version: 1.0 References: <20220316122419.933957-1-jolsa@kernel.org> <20220316122419.933957-10-jolsa@kernel.org> In-Reply-To: <20220316122419.933957-10-jolsa@kernel.org> From: Alexei Starovoitov Date: Thu, 17 Mar 2022 20:53:15 -0700 Message-ID: Subject: Re: [PATCHv3 bpf-next 09/13] libbpf: Add bpf_program__attach_kprobe_multi_opts function To: Jiri Olsa Cc: 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 Content-Type: text/plain; charset="UTF-8" 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 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. 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. 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.