Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp811021pxb; Tue, 12 Apr 2022 14:06:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAWNvTT4x4BF28xzUToPI3CDKBZX5KDyBB0J51shXESTQdn6CWWQOBizYyyOrGB4wWU4yL X-Received: by 2002:a05:6a00:2402:b0:4e1:46ca:68bd with SMTP id z2-20020a056a00240200b004e146ca68bdmr6381026pfh.70.1649797567379; Tue, 12 Apr 2022 14:06:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649797567; cv=none; d=google.com; s=arc-20160816; b=q1AKDkQDc+Olo1zCwPvbBraHnhP6hpm03sKKG8U2+IRpy9OmZizV0klvaQmQKk9wSZ +pcnnRrJVFRrIyb5cmUt1Xbr+QOUX1TpiwqjTSK5kS30XgWwZyeveahTpJBZprlL2jNA j4lVwr5Lv1TsKr8/riELbD/t7Y/yNuohgb95/bb3f86CKhC5l38SqYYKORpFwxbyvqFp XLY3y0YGmJ9pt9BorTbbfHBtjBAGdzdKKHOIPZoeIvAgdi0mc2pDZJ7ESNpK/G7xDqag exapQ8ez6Qq1S9c9i2zN4IvKFdAq1qwipwQIbgD+8HZYPofaaq+rifuh5TOllztwqyVs fm7Q== 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=irgS8qcLKLYtl+m3fmwnnbCWqovp3OYwRZKXDq3z+5s=; b=UH6GqIZMkJ6ImQWYuYzBBN4sqiotZ9hJH1JXti64Y49X9REj38W3ZlZwxu1Jws02zB ZXlNTVxvDFp5BcO1rg0ncyNC29PxPyswDCpLketKWMRhPVHxgpVba26O97B5fc4I9nKe wSBZhxspUCs2e1l0XJDaNFetnLnA8zeGnYcl7Ab7Udd8Cwc3lrL5Vmi3rM/UB20xeVlt VCLDwWaxHtjIMlOvE/WKoIFa6t+4U6Q+jH1KFqtHhHxqh8GFtP8tFuF68D2f6N17AFRM i1QO8zAlFcBFODEkR2ihbLHf6BGUCOX1UEin0/nXAFOK2sEWLSLF/jve2PoXDIi9yo2f NFdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jNMPcmM9; 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 s17-20020a632151000000b00382250a328bsi3617070pgm.387.2022.04.12.14.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 14:06:07 -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=jNMPcmM9; 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 928599A9B6; Tue, 12 Apr 2022 13:24:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241795AbiDIU05 (ORCPT + 99 others); Sat, 9 Apr 2022 16:26:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241675AbiDIU0z (ORCPT ); Sat, 9 Apr 2022 16:26:55 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F063C2156C4; Sat, 9 Apr 2022 13:24:45 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id u3so17641174wrg.3; Sat, 09 Apr 2022 13:24:45 -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=irgS8qcLKLYtl+m3fmwnnbCWqovp3OYwRZKXDq3z+5s=; b=jNMPcmM90NMUyrhE2B8ZBIlp2m1ScB1/ipCXsgf/fK6FVQzgpP/uVly1wsP8tVl6mz U1KlOP/1aJsKHNn9TwNxu6BQowOrw9uVmMUnTdF+0PRTcsplScLNjP5CLcKRTYTJesl8 RMevXyH6Pocqfo9Dcs5iv2OwPy9wulWmhGrJI7p40dpym3fkRZoSExtmc35RUAO227/t BKK2DKBRLYXO3AR2Y8Qt4N/5792hybM6TrzonLJDXqzowBT6weZr2sFp1xYw8szyaUkS wwj/B9/v+LP38s1ISxR99V550TfrEjkpf1IEHTvl6fT1IsH2BSsVvX2Ybc6kf/HzqhTH yG+g== 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=irgS8qcLKLYtl+m3fmwnnbCWqovp3OYwRZKXDq3z+5s=; b=oGE6MTPAVzCEBuAL3tPoajGPG6X1HnLA5jE7jv0bqb0MTfzL5n9ZJdl6t1ZDwRZYSv P4pzvrkPmWWWi+K+uQCZUIkn5mi0ox7lYAl0DdwlAgXZR+ii/WOx52gMz1tavWYM0+Sn +gfRCNW4pN1Q8qQGkskjioCVN1Pk0odPMuOz3OW4iHeDCe2niR/Ato6KUrKP66Vr47zl e3/PPt0zNb9WCmL07xkZw7XUQiiO14TSvj1Ma7uydiYSd4NkJLWR/QmTSM4e6x3lITf3 bt3xzPsuam+MtNYlf+nqD1EMWRAYT+NtX4PQ89DBhbpyxuaQwTo5Q+khaSezlqxJHaDf hCSw== X-Gm-Message-State: AOAM530Ni8OE34M3mIMshsLCEi8l0OI1rVDCe7p6y3H5VvDDF2u2F+2L Iorg//ue+mCP7vKThcnhho4= X-Received: by 2002:adf:fbcd:0:b0:207:94ee:f648 with SMTP id d13-20020adffbcd000000b0020794eef648mr7388312wrs.541.1649535884288; Sat, 09 Apr 2022 13:24:44 -0700 (PDT) Received: from krava (94.113.247.30.static.b2b.upcbusiness.cz. [94.113.247.30]) by smtp.gmail.com with ESMTPSA id bs12-20020a056000070c00b00207a2c698b1sm639914wrb.40.2022.04.09.13.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Apr 2022 13:24:44 -0700 (PDT) Date: Sat, 9 Apr 2022 22:24:41 +0200 From: Jiri Olsa To: Alexei Starovoitov Cc: Jiri Olsa , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu , netdev@vger.kernel.org, bpf@vger.kernel.org, lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh Subject: Re: [RFC bpf-next 3/4] bpf: Resolve symbols with kallsyms_lookup_names for kprobe multi link Message-ID: References: <20220407125224.310255-1-jolsa@kernel.org> <20220407125224.310255-4-jolsa@kernel.org> <20220408232610.nwtcuectacpwh6rk@MBP-98dd607d3435.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220408232610.nwtcuectacpwh6rk@MBP-98dd607d3435.dhcp.thefacebook.com> 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,T_SCC_BODY_TEXT_LINE 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 Fri, Apr 08, 2022 at 04:26:10PM -0700, Alexei Starovoitov wrote: > On Thu, Apr 07, 2022 at 02:52:23PM +0200, 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 > > --- > > kernel/trace/bpf_trace.c | 123 +++++++++++++++++++++++---------------- > > 1 file changed, 73 insertions(+), 50 deletions(-) > > > > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > > index b26f3da943de..2602957225ba 100644 > > --- a/kernel/trace/bpf_trace.c > > +++ b/kernel/trace/bpf_trace.c > > @@ -2226,6 +2226,72 @@ 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, void __user *usyms, u32 cnt) > > +{ > > + const char __user **usyms_copy = NULL; > > + const char **syms = NULL; > > + char *buf = NULL, *p; > > + int err = -EFAULT; > > + unsigned int i; > > + size_t size; > > + > > + size = cnt * sizeof(*usyms_copy); > > + > > + usyms_copy = kvmalloc(size, GFP_KERNEL); > > + if (!usyms_copy) > > + return -ENOMEM; > > + > > + if (copy_from_user(usyms_copy, usyms, size)) > > + goto error; > > + > > + err = -ENOMEM; > > + syms = kvmalloc(size, GFP_KERNEL); > > + if (!syms) > > + goto error; > > + > > + /* TODO this potentially allocates lot of memory (~6MB in my tests > > + * with attaching ~40k functions). I haven't seen this to fail yet, > > + * but it could be changed to allocate memory gradually if needed. > > + */ > > Why would 6MB kvmalloc fail? > If we don't have such memory the kernel will be ooming soon anyway. > I don't think we'll see this kvmalloc triggering oom in practice. > The verifier allocates a lot more memory to check large programs. > > imo this approach is fine. It's simple. > Trying to do gradual alloc with realloc would be just guessing. > > Another option would be to ask user space (libbpf) to do the sort. > There are pros and cons. > This vmalloc+sort is slightly better imo. ok, makes sense, will keep it jirka