Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp780486pxb; Fri, 22 Apr 2022 11:00:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0KdZheY6c/e6qjGonZ9qObqOq0i/6Qef6Mh+eDIWKCiBd/j0BYlLmIQHlrnREmd1E7u6X X-Received: by 2002:a05:6808:dc3:b0:2ef:86e7:a0b with SMTP id g3-20020a0568080dc300b002ef86e70a0bmr2869429oic.48.1650650450027; Fri, 22 Apr 2022 11:00:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650650450; cv=none; d=google.com; s=arc-20160816; b=VEaYfMqJ5GhysmxOyquoMe5DtJYpbb5ioH1ZSfWm3RDSit7DUZ3sqTVJbHU25Wmaoe yt+YR1GoFXK+Xrx08f/HWUpz2Ptrv8n6vSdyZ3mGoHu42rLFgIEAk2UlO/S8I6kKoEgR d/FzXOkTrcyDsHg0zadaHOGLwHZApNN6KwCchvIf06GsZmDeUiD6Jm8VJZOdVFoP9iho 3a+XopdT6B/ebvVUUBD0js7Hh3ecxGphavoggWejyalFy8+bbJNFCEBhIxJ/88hhd2pt Akrl9kQCD2WGqhDyVo7yv5GPH2AZSj8bOQ76rFf29lorFOau2GII99wZMts0lPVDD8+6 zuQw== 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=Ufzy6GPDCT+EdtxABpNGV4M1WRq60zj8Sw9h2+oqp74=; b=fBl08ScrN9QRUDBz0UXnUrKxDQcZjsZ6O0flb23/JJERNqwC1LQD0lOM7TXymcswLD ECDQdND2Pxp6eUoKBwyNuBKCz1CUVhFHEAIdai/pRaszLCSfi9FMZGV68ph9HaRBB/lQ 7YqEpyZqyp9KnfHZEHiQbOQHJFI8O1T+ZJkFYSDX8X5DhCPqbPkKV9lBY4NTxeFIYB2w aGfjrtS33hZ9mLCmAaJJMJC9SEAnezAbWWUdq1lIPFgK5i6697aB5/6rwfhy9jP8psod Q1RFCrObzelEHj1QTA+gGemorGS/yb6kVL7tWTHVOe9wIhr6NVpPVnQ/LFwBZX1vjrJ1 bfiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DHdXFxPy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a9-20020a4ab109000000b0032993b133dasi5166247ooo.11.2022.04.22.11.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 11:00:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DHdXFxPy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0B5B3114FA7; Fri, 22 Apr 2022 10:41:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385362AbiDUGyy (ORCPT + 99 others); Thu, 21 Apr 2022 02:54:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385934AbiDUGxp (ORCPT ); Thu, 21 Apr 2022 02:53:45 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCC7B140CD; Wed, 20 Apr 2022 23:49:17 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id g18so5218272wrb.10; Wed, 20 Apr 2022 23:49:17 -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=Ufzy6GPDCT+EdtxABpNGV4M1WRq60zj8Sw9h2+oqp74=; b=DHdXFxPyfcpHgkSUAcXrGuzDeAjqa5UHlI+cGdFeoPbULu4EkX2UhzMtRctCGhBtcn 9ZaRyEnT9tt/8RzDKcNzwzTsmMBQXHCSsjuazlWOqRQSrJH8UYMTyEKk0fiPKgXKMg+j A1cI7Y0+nsT0207B0m8KsAemhqf8ozCWtxQ7/2rYTK57metyxd2vUpx/Rkf7Rb7+n0Zi T5ZNfEjX0FuPo2TmSnv9YBU6smDe7PjvYutBmhgQ302EOQqFWzzNVAuj0jEhxAUrxac+ Yy6KIdGFpgWTrkU24ecF2g1FocrjLsZSzHjOW/tZJgsMCAgcmeOU9M1Y+K9gXh6G+Riq btvw== 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=Ufzy6GPDCT+EdtxABpNGV4M1WRq60zj8Sw9h2+oqp74=; b=U3+pTQYhqIvnX9NTrBA2aZk4tRffSylj6yrNxOhHFzRNlWwGstzmmaJO8UWGffKgiD hTY+dxFwE6cqbhQ2S+2oEV238EYgGxfNLvZm0lSJqA9KlMKdJNgZGsxWyymKDMQIEBtM 5SA5CG3buupW1fPkd3u4BDcF9EmGT+3jKoIp+GLUX4yo+sy6VOEgD7oR2nHcHyHkZCn3 fFaMl26hiF0lawnEQrRsybuyQEV30vsyIMR4IJhhx3pkY2TiXoClMuvVI1Xf/BFjC9sd A80K7Dmr6+clMXOjGFtKlOKSkIgq4DKeR+n7nh6+mhojGN+pefYcg24T1bxyUJNGP6Wj Zjaw== X-Gm-Message-State: AOAM531gQRZjFwAGDn762jDE2zPZin2dJMqZ4QJ79x2sFedrETsii12H +e9zZLXNaNOLxj23oXtbMTt6w+RtPtd4swCt X-Received: by 2002:adf:efc6:0:b0:207:b89b:232b with SMTP id i6-20020adfefc6000000b00207b89b232bmr17752793wrp.403.1650523756225; Wed, 20 Apr 2022 23:49:16 -0700 (PDT) Received: from krava ([193.85.244.190]) by smtp.gmail.com with ESMTPSA id d18-20020a05600c34d200b0038ed14b7ac3sm1223454wmq.40.2022.04.20.23.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 23:49:15 -0700 (PDT) Date: Thu, 21 Apr 2022 08:49:13 +0200 From: Jiri Olsa To: Andrii Nakryiko Cc: Jiri Olsa , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu , Networking , bpf , lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh Subject: Re: [PATCHv2 bpf-next 3/4] bpf: Resolve symbols with kallsyms_lookup_names for kprobe multi link Message-ID: References: <20220418124834.829064-1-jolsa@kernel.org> <20220418124834.829064-4-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=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no 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, Apr 20, 2022 at 02:49:59PM -0700, Andrii Nakryiko wrote: > On Mon, Apr 18, 2022 at 5:49 AM Jiri Olsa wrote: > > > > Using kallsyms_lookup_names function to speed up symbols lookup in > > kprobe multi link attachment and replacing with it the current > > kprobe_multi_resolve_syms function. > > > > This speeds up bpftrace kprobe attachment: > > > > # perf stat -r 5 -e cycles ./src/bpftrace -e 'kprobe:x* { } i:ms:1 { exit(); }' > > ... > > 6.5681 +- 0.0225 seconds time elapsed ( +- 0.34% ) > > > > After: > > > > # perf stat -r 5 -e cycles ./src/bpftrace -e 'kprobe:x* { } i:ms:1 { exit(); }' > > ... > > 0.5661 +- 0.0275 seconds time elapsed ( +- 4.85% ) > > > > Signed-off-by: Jiri Olsa > > --- > > LGTM. > > Acked-by: Andrii Nakryiko > > > kernel/trace/bpf_trace.c | 113 +++++++++++++++++++++++---------------- > > 1 file changed, 67 insertions(+), 46 deletions(-) > > > > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > > index b26f3da943de..f49cdc46a21f 100644 > > --- a/kernel/trace/bpf_trace.c > > +++ b/kernel/trace/bpf_trace.c > > @@ -2226,6 +2226,60 @@ struct bpf_kprobe_multi_run_ctx { > > unsigned long entry_ip; > > }; > > > > +struct user_syms { > > + const char **syms; > > + char *buf; > > +}; > > + > > +static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 cnt) > > +{ > > + unsigned long __user usymbol; > > + const char **syms = NULL; > > + char *buf = NULL, *p; > > + int err = -EFAULT; > > + unsigned int i; > > + > > + err = -ENOMEM; > > + syms = kvmalloc(cnt * sizeof(*syms), GFP_KERNEL); > > + if (!syms) > > + goto error; > > + > > + buf = kvmalloc(cnt * KSYM_NAME_LEN, GFP_KERNEL); > > + if (!buf) > > + goto error; > > + > > + for (p = buf, i = 0; i < cnt; i++) { > > + if (__get_user(usymbol, usyms + i)) { > > + err = -EFAULT; > > + goto error; > > + } > > + err = strncpy_from_user(p, (const char __user *) usymbol, KSYM_NAME_LEN); > > + if (err == KSYM_NAME_LEN) > > + err = -E2BIG; > > + if (err < 0) > > + goto error; > > + syms[i] = p; > > + p += err + 1; > > + } > > + > > + err = 0; > > + us->syms = syms; > > + us->buf = buf; > > return 0 here instead of falling through into error: block? ok, will change jirka > > > + > > +error: > > + if (err) { > > + kvfree(syms); > > + kvfree(buf); > > + } > > + return err; > > +} > > + > > +static void free_user_syms(struct user_syms *us) > > +{ > > + kvfree(us->syms); > > + kvfree(us->buf); > > +} > > + > > static void bpf_kprobe_multi_link_release(struct bpf_link *link) > > { > > struct bpf_kprobe_multi_link *kmulti_link; > > [...]