Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp329646pxb; Wed, 13 Apr 2022 01:54:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKSRuUIAP79lh7/2nBNBudzD8owkdoLLWEvKzT6U+++9VCs2tXFO0dA08sb9vDno3RJNW2 X-Received: by 2002:a65:46cf:0:b0:399:13b3:dd8b with SMTP id n15-20020a6546cf000000b0039913b3dd8bmr34363084pgr.585.1649840056146; Wed, 13 Apr 2022 01:54:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649840056; cv=none; d=google.com; s=arc-20160816; b=Q2rGsv/EwbSK8yKbRwtvgW76xCfnwdsFEnYtjsrHhkERNC10o6Fn20aeDfa9tTjdL6 bqat60YgqyaogPPHxpP584S18K8Kd4iDve0vfMEw5PF9q/xgJ1J4MyHzn+6Le27fgSAi xt73MeUlgohOWT+L9++z2FLC72ifa0YuFTLO3rAvtD2vQe/yJjZ5OKXvRnomRYFEigdp zmzz1maXzfZMTyhlv+iWyYmqg8wc4sjqzCYBEXWnKhS13RBtLKOyG/Tep3rBXtgcyL3W uuLIy91A4f76C6Y9UpXiHXFia9/UCPX/tkb7oM+pRKkXUgzUWLKg37SUlsID/rTYkQYD P10g== 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=qwO5x8daEsKn7AJxj0XCIjFXgnsykAoMFtFOPr30/OY=; b=rmkemt/aSISTOKQ4TYGAU6hrSl8g4uk2dYLZbB65XUMU5ql5wHot+at0dpeaXMJUXw U5ErlawtjSr9jzmyuiSbu1c2Xc9Xg6mlFoFqF2gAVdVtg8US6XASeOkDkweAhylBSdxT h/E/5ZyBTSADGseET+jla//QzR6iDPecbcwvPtQxEpuZ16eSoKyAUDPLG6qli3giXQPF eAxi0r+g5yOR7YzXWlkcOktVvXRRiNSZ8gOJ04eE4vlv6GI/vLcj7ujPD3aMdq+jyTmd EWote5nJBBES7dIkmWfUWiEAzedM7TGfUd6UWzCDNYkwj7Lx2dKZD+4ulZR+YLHwfeQ8 L6Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="omH/vMEm"; 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 n1-20020a170902e54100b00153b2d1660csi3974120plf.532.2022.04.13.01.54.03; Wed, 13 Apr 2022 01:54:16 -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="omH/vMEm"; 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 S233346AbiDMHaH (ORCPT + 99 others); Wed, 13 Apr 2022 03:30:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229718AbiDMHaF (ORCPT ); Wed, 13 Apr 2022 03:30:05 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 007D618E0C; Wed, 13 Apr 2022 00:27:44 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id ks6so2155675ejb.1; Wed, 13 Apr 2022 00:27:44 -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=qwO5x8daEsKn7AJxj0XCIjFXgnsykAoMFtFOPr30/OY=; b=omH/vMEmEDVQszB0OIuSdTvi7p/jJXy6R7A4244H80S4k3+XRyMjfRgpMOFKczNheK 0jy7I2xFnKdHegbsri9PY8EXS+4uFYoIGtYTxKnQ/I1UBHEt3e/74Tk+DLZwRfczFDpL 4nNc2M9wLBIW/NcnCJpG3Nwg22ZUYnph1J536J98rJMFw4wSWrNNxwdCYDzXjpoELrb8 AiYRB7OjbIX80I0M3LzLL+ukfZ3T35MEbZ7hX6tNFGAwytw5AuBCjFFIbH7dL7b1ku0X TxjTMYhCbTwQn0DDRcsEGgsEp0t2OHz72ifkKSR4lHRLVLybOQnppkwpv8o9RuAJmVOv jLaA== 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=qwO5x8daEsKn7AJxj0XCIjFXgnsykAoMFtFOPr30/OY=; b=hWU0dyWKA1xacCZ4qhwUtkslimdEHXFO9Ni3Bcnlf3CgPV01Ma2A3n9CEQ1YQ3PaCD Bd//xRIshLJbJnj0sht+ZDFOkvrcU3wX5yh86LS2JEXdhGyDA5Sn+OgEUu8+xserxEqQ 5AMdyvdw/5odPWi3aIJIb+djkIWAdPA5YbcaK4CFPNRwIr3LyBKkM0ht2aycDV+NhpUM NRHMNqElnj01RidwJrXJE26ZAWisW2pn2oKfWyTg5S/eBd4eGBFN05Syns8hJk/05m4Y zo00FTPVFul2shk+q6VFmTlgxz/qrch2yg/9Y2+wDgTmx3Szo1dIkDe/P0O/X/Ab8neo wY2g== X-Gm-Message-State: AOAM533/g2UAUJnyRTCYTPjVzthlUr+PyxuPrwIRQi+sIbgi9yleF3+w UKA1a1ScYxgpo5o4jPDbbO0= X-Received: by 2002:a17:907:6093:b0:6e0:dabf:1a9f with SMTP id ht19-20020a170907609300b006e0dabf1a9fmr37979065ejc.424.1649834863420; Wed, 13 Apr 2022 00:27:43 -0700 (PDT) Received: from krava ([83.240.62.142]) by smtp.gmail.com with ESMTPSA id q3-20020a5085c3000000b0041d7958ae70sm831859edh.25.2022.04.13.00.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 00:27:43 -0700 (PDT) Date: Wed, 13 Apr 2022 09:27:40 +0200 From: Jiri Olsa To: Masami Hiramatsu Cc: Jiri Olsa , 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 Subject: Re: [RFC bpf-next 1/4] kallsyms: Add kallsyms_lookup_names function Message-ID: References: <20220407125224.310255-1-jolsa@kernel.org> <20220407125224.310255-2-jolsa@kernel.org> <20220408095701.54aea15c3cafcf66dd628a95@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220408095701.54aea15c3cafcf66dd628a95@kernel.org> 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 Fri, Apr 08, 2022 at 09:57:01AM +0900, Masami Hiramatsu wrote: SNIP > > /* > > * These will be re-linked against their real values > > @@ -572,6 +574,52 @@ int sprint_backtrace_build_id(char *buffer, unsigned long address) > > return __sprint_symbol(buffer, address, -1, 1, 1); > > } > > > > +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); > > +} > > + > > +struct kallsyms_data { > > + unsigned long *addrs; > > + const char **syms; > > + u32 cnt; > > + u32 found; > > BTW, why do you use 'u32' for this arch independent code? > I think 'size_t' will make its role clearer. right, will change > > > +}; > > + > > +static int kallsyms_callback(void *data, const char *name, > > + struct module *mod, unsigned long addr) > > +{ > > + struct kallsyms_data *args = data; > > + > > + if (!bsearch(&name, args->syms, args->cnt, sizeof(*args->syms), symbols_cmp)) > > + return 0; > > + > > + addr = ftrace_location(addr); > > + if (!addr) > > + return 0; > > + > > + args->addrs[args->found++] = addr; > > + return args->found == args->cnt ? 1 : 0; > > +} > > + > > +int kallsyms_lookup_names(const char **syms, u32 cnt, unsigned long *addrs) > > Ditto. I think 'size_t cnt' is better. ok, thanks jirka > > Thank you, > > > +{ > > + struct kallsyms_data args; > > + > > + sort(syms, cnt, sizeof(*syms), symbols_cmp, NULL); > > + > > + args.addrs = addrs; > > + args.syms = syms; > > + args.cnt = cnt; > > + args.found = 0; > > + kallsyms_on_each_symbol(kallsyms_callback, &args); > > + > > + return args.found == args.cnt ? 0 : -EINVAL; > > +} > > + > > /* To avoid using get_symbol_offset for every symbol, we carry prefix along. */ > > struct kallsym_iter { > > loff_t pos; > > -- > > 2.35.1 > > > > > -- > Masami Hiramatsu