Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp55918lfv; Tue, 12 Apr 2022 17:06:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxq0tLlhGMK1LmUOnXcTcaHq+pPUptWseWuYCmZrzEcZndVunbeowk+Nfx5MSn/OOdSa/+ X-Received: by 2002:a17:90a:5409:b0:1ca:8a21:323b with SMTP id z9-20020a17090a540900b001ca8a21323bmr7780759pjh.135.1649808367818; Tue, 12 Apr 2022 17:06:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649808367; cv=none; d=google.com; s=arc-20160816; b=pe5joJ/ss0Ik74/sXiOWsEHgAdkLSX5u5xbGBRP9wl9R5HczGPQ6dj0sct9JA+5jLW xRDuVOs9qRELV/jyhqJ9ZPtrEzaVasvzcqk9/aZR7+vf75vum7oNjVTsNNAecUvo1S0Z 9l4qorsLvSIR4jY7MPCSoNtJ7kpxw2nmrDeY7ppJOJdvsODBy7+8XjKVk2WZkJ6eQ3qG u+w0aGifm+wFd2hpdIvsyGOG4vowaAWnJHKEh82IPisxgQO6pbUaHTsL0kkb78Bn2J2P pMmJ2bj61Kt+hmnvqrUuhy2mqm2EAnTHp1c2xSztRGIOCicS7HBc7xGkTbSJGRaCTH1/ u4ng== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=m1dR6jtUuMTJiOEauYrZ+LgWz+ZA4crd9zsyU4t9Jps=; b=t4QHOFjQ3BeK4mgDWsXjpZS9UYSmgEPiLEiHyHqatNYheqBT3CifRw44nnxbk0y9QG I87xZFTf1tV+RRq5Qp281rt/MWRPBCqu20xUox8m1vJEMrv2uUW6GhnWCWoD26B2xwWh H+XaNliXMT7j/iFnia1MBdXk2DcnSrTL8ixz9SIdg3FIz3JWj1u93mMbHIIgCns7UrNm G79TsgOIZVq5XSahq+YKmZumhy5R8dXTiKE1mvZhrqIkEa/8O1EiYAOplCVvHUwQosrQ D5uWz+K+7lBgv826xPsdKpAk32EGNww0WCtFL8EzKg0UvlHyrkHP7hyek/KSEACSmlzt A4Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=C8jkE0dJ; 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 x1-20020a056a00188100b00505929703d3si15623786pfh.56.2022.04.12.17.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 17: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=C8jkE0dJ; 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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7667015B99A; Tue, 12 Apr 2022 15:02:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231796AbiDLUiD (ORCPT + 99 others); Tue, 12 Apr 2022 16:38:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231608AbiDLUhu (ORCPT ); Tue, 12 Apr 2022 16:37:50 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06A4EFABE6; Tue, 12 Apr 2022 13:32:29 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id k23so39570133ejd.3; Tue, 12 Apr 2022 13:32:28 -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:content-transfer-encoding:in-reply-to; bh=m1dR6jtUuMTJiOEauYrZ+LgWz+ZA4crd9zsyU4t9Jps=; b=C8jkE0dJScs5ZfDVUMAGI83DPAYueYpncxIN1ENu5DuHkYvQ9fAArTRGRj0b8ZWZ87 2SC+M2RWQN4eJa+rXcdScpp/hjgrX/t4r5l8fasRpp/XAGas5mJuLTP7JRJphIXcpOna ws9E1finUVliP65HHEAJi1tBBcdKru0m6IGFFVCOBZHY8gPiFC8H8U28PvHKYC0zEaQy YPg7gMES0WtfPA6Ig/jfJTIizEetGJZ+9x6z11VArTgg1OXOYDUR4Zo9vdZd9GM32GQD G20PPB06YLStneJ3/l3SVv6GkJ6rnyEiNWI/sCZTljqRukcSAfODyR04vGB2FFazZ/IS xAFA== 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:content-transfer-encoding :in-reply-to; bh=m1dR6jtUuMTJiOEauYrZ+LgWz+ZA4crd9zsyU4t9Jps=; b=0hnMATVzMetvCuGHvTGPunNU+cMXCDkRPQDR4ppNzlvWuFrb82JY7uB2sjibmpG79s 0Zusxz1lKzLskJ7Ap/tI+GCrrhd+kxeCN/3POcmT9DDzAwU4DCXS2tWlz334dPlKPpVM O/Vzaydp8GI24uiDguf5w2SpfyZGtYVhFAB3zQeYyOwhM8U8DwBWF2UoX3UowQEtg2g6 56SLDJErxvFkNmzE1Bsy4QeM/p9Gi/8vOiIYAlqhgYR+y3/0qr+Gv1DRUOoKBuKzCWik b3ORdS86dO2Nu7tBKKqt3GTgYk88Z17ea44LoatYCmyqZ6XDoAGgkBgDGoT23x85qFfd XiHw== X-Gm-Message-State: AOAM533ttoMGPCYSYE6qMAKBwaJMt8Lcr++w8lVg1aZCYYsgBTnBcAZL PZ5EmydDgT9UIljUifZ8LQg= X-Received: by 2002:a17:907:7815:b0:6ce:5242:1280 with SMTP id la21-20020a170907781500b006ce52421280mr36153644ejc.217.1649795293117; Tue, 12 Apr 2022 13:28:13 -0700 (PDT) Received: from krava ([83.240.62.142]) by smtp.gmail.com with ESMTPSA id r3-20020aa7cb83000000b0041b573e2654sm210558edt.94.2022.04.12.13.28.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 13:28:12 -0700 (PDT) Date: Tue, 12 Apr 2022 22:28:09 +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: [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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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,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 Mon, Apr 11, 2022 at 03:15:23PM -0700, Andrii Nakryiko wrote: SNIP > > static inline int kallsyms_lookup_size_offset(unsigned long addr, > > unsigned long *symbolsize, > > unsigned long *offset) > > diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c > > index 79f2eb617a62..a3738ddf9e87 100644 > > --- a/kernel/kallsyms.c > > +++ b/kernel/kallsyms.c > > @@ -29,6 +29,8 @@ > > #include > > #include > > #include > > +#include > > +#include > > > > /* > > * 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) > > isn't this literally strcmp? Or compiler will actually complain about > const void * vs const char *? yes.. kernel/kallsyms.c: In function ‘kallsyms_callback’: kernel/kallsyms.c:597:73: error: passing argument 5 of ‘bsearch’ from incompatible pointer type [-Werror=incompatible-pointer-types] 597 | if (!bsearch(&name, args->syms, args->cnt, sizeof(*args->syms), strcmp)) | ^~~~~~ | | | int (*)(const char *, const char *) > > > +{ > > + 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; > > +}; > > + > > +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) > > +{ > > + 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; > > ESRCH or ENOENT makes a bit more sense as an error? ok jirka > > > > +} > > + > > /* To avoid using get_symbol_offset for every symbol, we carry prefix along. */ > > struct kallsym_iter { > > loff_t pos; > > -- > > 2.35.1 > >