Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2921714iob; Sun, 1 May 2022 01:20:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyN34/gmye6B844JpXDxulC/kxjCmqPm9pQpqMClnWSOGymD9brGFzxMWFDxZvxo1qlI60r X-Received: by 2002:ac2:4e98:0:b0:448:3039:d170 with SMTP id o24-20020ac24e98000000b004483039d170mr5795579lfr.233.1651393242518; Sun, 01 May 2022 01:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651393242; cv=none; d=google.com; s=arc-20160816; b=OYVExeKH4Y0ijFtKI3mGnRjnc6Gm3e7rHtP9QdGQRhmUv8EtJp4ekSFy1Za/Gwa3vl THvDjv+2Wuui3QGEHqSObL6lsBPgG0Qo3H6Np9wY67ycoUqlclbQzde2x1NaOMDrktnF xE4utjU+GUR1jj97SfNT/wKS4SIt5+PZ6LdquiS3jn3zxNhJC+tcqhz7KlEY/edZ17LS B9zqGEz94k4rXX/NeThAFE8bVSCDx5j/jd0PYhfEl02+K2CHeS1QzqRmBEPaQxTbp48U 5BHMrGfFEgrzgYYvjBYmenKTVjVuIezgAANd5WGv54saLAYwFBSzoQZjtXkszTumqE03 wpzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=7S0emoeLBTIfbiECPzr9IRfBfa/YPEcvDkG0xra3P0Y=; b=TannSyBkg0I6069vKAH7zevsIaIEKbfrVD/wC/xg9PdDUB1rONQsoMKGAerFaxBZ8g UKcbfiXINVjrUrfk2CctIbCtOBhABXaX/0Rtw3q+Ik1krB7UymWeLa+GEc2vUNdiPp2f 6o303SThGuoCZh807oCHUCheqvKUucSB+GyN3NAaAwRGU/Miu96/NPYEnSgjfEtydA+0 q/339lubbFCfYevXwyLkk+U3GTD/E5RbIRrG0v6FXidCtaEhZdlfSJWE+Lr7HijTmIth OPTdAmZm7K+iT1F5+Xz0d03GfN9TeCvzvd6nukh3ImEwnWUaJBGzADMNBN9FAZDSkrcH x6zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GujnCsDy; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bx41-20020a05651c19a900b0024f0ff73a13si13613130ljb.434.2022.05.01.01.20.15; Sun, 01 May 2022 01:20:42 -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=@kernel.org header.s=k20201202 header.b=GujnCsDy; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378015AbiD2O6J (ORCPT + 99 others); Fri, 29 Apr 2022 10:58:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378009AbiD2O6G (ORCPT ); Fri, 29 Apr 2022 10:58:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C167BE9F2; Fri, 29 Apr 2022 07:54:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 267C8B835DD; Fri, 29 Apr 2022 14:54:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C4F5C385A4; Fri, 29 Apr 2022 14:54:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651244085; bh=hrsovH+LFFku1FXppgR3a5Fig56Iz/nETCoLPh/sA/8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=GujnCsDyMGYSxhrbrnfHBbgpLaxpVw/hFIqzVYZrB30YCJQeJM1PYc7i9NfEOup82 j2kFnB0FUF/2nw+6yM2dMkOvf1fdO1q4No97pdrKzFCyH7rngr1m+Jsw6bkazCjvJT 0nhM+mCHHCFwD7cx7bxM/BuH/aZig7R2v5Kb+UetPtbI22pajNvG5PvKmuRWRs83ou Jt/xLsMv7eriHRQGnmpHkAdP7bUQN1CpeTZrx7o7TxRtOxSzMqMQTpBcicbkNqiCkk pxeQpugNfoDnfiIn56auMdZPR//8ucBuFlZ3t/4fuEH6AB4FABPR3i3ugzEl2eDiRi olX4NjQn4AckA== Date: Fri, 29 Apr 2022 23:54:40 +0900 From: Masami Hiramatsu To: Jiri Olsa Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , netdev@vger.kernel.org, bpf@vger.kernel.org, lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Steven Rostedt Subject: Re: [PATCHv4 bpf-next 3/5] fprobe: Resolve symbols with ftrace_lookup_symbols Message-Id: <20220429235440.58aa5045a507e79230a7ac86@kernel.org> In-Reply-To: <20220428201207.954552-4-jolsa@kernel.org> References: <20220428201207.954552-1-jolsa@kernel.org> <20220428201207.954552-4-jolsa@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,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 Thu, 28 Apr 2022 22:12:05 +0200 Jiri Olsa wrote: > Using ftrace_lookup_symbols to speed up symbols lookup > in register_fprobe_syms API. > > This requires syms array to be alphabetically sorted. This line is no more needed because get_ftrace_locations sorts the syms. Except for that, this looks good to me. Acked-by: Masami Hiramatsu Thanks! > > Signed-off-by: Jiri Olsa > --- > kernel/trace/fprobe.c | 32 ++++++++++++-------------------- > 1 file changed, 12 insertions(+), 20 deletions(-) > > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c > index 89d9f994ebb0..aac63ca9c3d1 100644 > --- a/kernel/trace/fprobe.c > +++ b/kernel/trace/fprobe.c > @@ -85,39 +85,31 @@ static void fprobe_exit_handler(struct rethook_node *rh, void *data, > } > NOKPROBE_SYMBOL(fprobe_exit_handler); > > +static int symbols_cmp(const void *a, const void *b) > +{ > + const char **str_a = (const char **) a; > + const char **str_b = (const char **) b; > + > + return strcmp(*str_a, *str_b); > +} > + > /* Convert ftrace location address from symbols */ > static unsigned long *get_ftrace_locations(const char **syms, int num) > { > - unsigned long addr, size; > unsigned long *addrs; > - int i; > > /* Convert symbols to symbol address */ > addrs = kcalloc(num, sizeof(*addrs), GFP_KERNEL); > if (!addrs) > return ERR_PTR(-ENOMEM); > > - for (i = 0; i < num; i++) { > - addr = kallsyms_lookup_name(syms[i]); > - if (!addr) /* Maybe wrong symbol */ > - goto error; > - > - /* Convert symbol address to ftrace location. */ > - if (!kallsyms_lookup_size_offset(addr, &size, NULL) || !size) > - goto error; > + /* ftrace_lookup_symbols expects sorted symbols */ > + sort(syms, num, sizeof(*syms), symbols_cmp, NULL); > > - addr = ftrace_location_range(addr, addr + size - 1); > - if (!addr) /* No dynamic ftrace there. */ > - goto error; > + if (!ftrace_lookup_symbols(syms, num, addrs)) > + return addrs; > > - addrs[i] = addr; > - } > - > - return addrs; > - > -error: > kfree(addrs); > - > return ERR_PTR(-ENOENT); > } > > -- > 2.35.1 > -- Masami Hiramatsu