Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp953798pxb; Thu, 21 Apr 2022 14:26:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMzqxliUfCrvFeTuHWUY4lfbz6uK+7yUhIuXmJgK0ACYXxbIMs1NyPQRQ6H44ow5jAeuyy X-Received: by 2002:a17:902:cacb:b0:158:694f:23ff with SMTP id y11-20020a170902cacb00b00158694f23ffmr1311653pld.119.1650576373299; Thu, 21 Apr 2022 14:26:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650576373; cv=none; d=google.com; s=arc-20160816; b=O1BljkNckQ7wJJP4euh1K73Yl9ThxWCnvAwV58gNz70ZWxZzu0/LgzoamwxFjW5qbK Gbdvdb3lcwjFG93vx85bE/ssFTC4ez3OeVGhjomyBYJCWCSvuvmfg2D/u8smxFhSUn8y yZaLoaHFOiWR7Dn/m/Zd73V7WlqFkYrx4erh1DTFnTwFuPRF5okZHfyuMlz/JGU/bJ7+ EihAdkdZzQiPkq2uNlQ9bKo+3pXpjaYycmYxVl9VbEnOp3YPOFaLtQPgx4hEea5TQSg2 lsA7DNJfU4qWX04exW5Rt5Fp1YzU6tbzxRZ9TS6M6rAEPnfN74yQDnxQ7uIAPp0e4WGu cnlQ== 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=E9YOcBF8Qte2T6InlNUSlZ6JWX6+9WNopvT5STl0eyU=; b=TEIrH1ah9YmNcdGlySbi/hDEzrjlOenWNZAlTpyjIqtZM0fMybOKAAp6sVVsu/hbve VJ3tvtflN13kcM0uXProojLPsOPLYC9mSk20M//ZN/TpYPKb4JRgTSXOakAh/uNtQtvH Z2oP7HnubDs4vJ25P1H394hZU+nB8hzrsozQSAx4hV0sRhfa6EKE36mj2dldhYmpk8qa SOIL6Jgnv05Cn3zPSXffkg2zkG+4zdWk3Cz6l2lY7jerkHi6ffVTtGLE9N/NSP/GSM6Z BmZmvU014qTDHmzXspZO8ytko1RE0HlWHNbMu853eRlY4vEC4RRqnu7Ge2v09dwvKg+9 qZwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=NSGQSQmk; 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 c63-20020a621c42000000b00505b362ec7esi5622559pfc.207.2022.04.21.14.25.56; Thu, 21 Apr 2022 14:26:13 -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=NSGQSQmk; 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 S1382677AbiDTVxA (ORCPT + 99 others); Wed, 20 Apr 2022 17:53:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234964AbiDTVw7 (ORCPT ); Wed, 20 Apr 2022 17:52:59 -0400 Received: from mail-vs1-xe2d.google.com (mail-vs1-xe2d.google.com [IPv6:2607:f8b0:4864:20::e2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84FEE1EC59; Wed, 20 Apr 2022 14:50:11 -0700 (PDT) Received: by mail-vs1-xe2d.google.com with SMTP id d9so2824610vsh.10; Wed, 20 Apr 2022 14:50:11 -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=E9YOcBF8Qte2T6InlNUSlZ6JWX6+9WNopvT5STl0eyU=; b=NSGQSQmkoJdKMFKZ0NiBhW4monmH7KmNSyzOnkiPsP1rWKrLz3Gm55Z+Dok7mxTQBH XOYyBBTjV+EWLt6uumuINFy7+Wk7ga0WQJRGTaO7ezPPEwVYebCpdO0rqn8LKXdCYsXx pDSfo5R0RLUditd6EUQ+VB5t7Wu1H4qpvUG0uN8WK86sV/pqhHmj/WVHHhNRjuckZukY yQavyfACmzadaKPtpJupvXC62gtHbp+2LhPUUFyKUv5wCY7uEDrytH2WHPFDJ0FVA6zQ 2QgO5HRfxK6tPZO6oi1ggx1WwnkZHIIOarfmjPYSBo+c9Gd6UPbYGeTsXP2G3atGeoo/ ipJw== 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=E9YOcBF8Qte2T6InlNUSlZ6JWX6+9WNopvT5STl0eyU=; b=4MeVQeDspzDQJgfe9ItNt8LnXLAKyec9X6Fpgi545lR68yVVyShvGUd1AklWPE+BRe +SRroMwLDqX4wqt4akn3UlSP90YP8Lg/9paEhT6YWKWvDPQCk9zt9VKn3Lfp8Lc/SJtU tl5RiVbZXul9lKcWNe94DWVjD0SHH8EsTFT6HCjpypgCog1aMZ1vFy9Wob3/SqrW9SLl +QT2rCiLoQ7F0KdMjKfMdwGlQBKMsl2c4BExlfYzDkcUf/ukzyhxeVd5D2Ymcc5266nk oUum/RpdQltb6BCkvccNsSjloHCQeUkCVXu75qMz4oontvz9VxxmfdTyw5Hk2c/TdZFk bfKA== X-Gm-Message-State: AOAM533t+w+gijPKJDXhGS6V0xAO+9QnAqD4GgXE3Qxibu5a1lI+4soj 3A5LY7+o8dihcrt58LIuwXoob8r8rKDrWyes020= X-Received: by 2002:a05:6102:22c3:b0:32a:4dd4:974 with SMTP id a3-20020a05610222c300b0032a4dd40974mr6925902vsh.18.1650491410399; Wed, 20 Apr 2022 14:50:10 -0700 (PDT) MIME-Version: 1.0 References: <20220418124834.829064-1-jolsa@kernel.org> <20220418124834.829064-4-jolsa@kernel.org> In-Reply-To: <20220418124834.829064-4-jolsa@kernel.org> From: Andrii Nakryiko Date: Wed, 20 Apr 2022 14:49:59 -0700 Message-ID: Subject: Re: [PATCHv2 bpf-next 3/4] bpf: Resolve symbols with kallsyms_lookup_names for kprobe multi link To: Jiri Olsa Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu , Networking , bpf , lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh 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 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, 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? > + > +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; [...]