From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23034C56202 for ; Fri, 20 Nov 2020 23:12:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C165E2240C for ; Fri, 20 Nov 2020 23:12:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KeDt4hdf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728454AbgKTXMx (ORCPT ); Fri, 20 Nov 2020 18:12:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728261AbgKTXMx (ORCPT ); Fri, 20 Nov 2020 18:12:53 -0500 Received: from mail-yb1-xb41.google.com (mail-yb1-xb41.google.com [IPv6:2607:f8b0:4864:20::b41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1C37C0613CF; Fri, 20 Nov 2020 15:12:52 -0800 (PST) Received: by mail-yb1-xb41.google.com with SMTP id s8so10032677yba.13; Fri, 20 Nov 2020 15:12:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XwhX7mqdBZb79BJALMUFBwrzROJPtHHkHdKkiNfguEk=; b=KeDt4hdfc+q/0oF73O4HS7X9TSOYKZZYWGByDrzcIRKJ3NECZTKm7ROxjqcNjnCXp3 rPJIy0mLxuiQ9phxJGbWPjhHJzy4nXJZ5ASlaeKJiGH1LujzZBMjWWC94qSFPKtXXLdI hhevbmkhojIMEyNZNinaOI3c93nPTUxbyFGLnSp984PPMVCbPVhiUGmwo8tq5eUsHXB2 dQePymuawBEjAa1Fs4xxcu/eRwLS4kg+IzWTPbUpZr9vwtk+2/IbBI0enLZZjfYiRQ2z Bg7sTUNx9Eas3dq9B+QGLdLtW4GG3gRTRsaF9EJSDM4KiXgMSRMYEe0LkM4a+KzYUBfU Yckw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XwhX7mqdBZb79BJALMUFBwrzROJPtHHkHdKkiNfguEk=; b=IgNnnzf5J7lymzhqMywWtvIOzDNgJwA0LUu7hsONAeiQPN6KGDNhmpaR42kgOr8sK5 Q6JPoUc4qOMiH0lFmdT6TEWAcE2tfOJn/UkHVdmxHC+LLkUB/aSRufKkpwZjJ+lEZfm1 CzzSMbP3hn2caDdOyU0kqzqI5FOjuD/UsjqXr8Rr9vmS+2Hxqk9NNycvJvpvRZ2pHQAF XYDcQBb1oyNhrOmwfsVoYxoNHWaVLBh6z4Le/0mUv5JqLBSb+W1SrDWbkE8cgifKA/9t n3HGBgV3yhLYRBkn1V8/m8Wt4klCPOuvsUU/zVQALYM2HwM0Sw1HlYGSdNJmgwMdzVq4 WXFw== X-Gm-Message-State: AOAM530+RfknFhQx5ZktNe7NOervuHmNIYb6mImJEQ+8l7hsD3cBNU51 8LA4S+PQmUOgSBRDfQvcJtuiAhPdV43KknNt/FM= X-Google-Smtp-Source: ABdhPJxGZAcp/N28eGNsF140NVGcycVpm0Pu+ec2TbPCFIweRgBoPqjugdoxcpeLth8SEHIfhsSU2e6WulLvvP2Mjy0= X-Received: by 2002:a25:585:: with SMTP id 127mr22124564ybf.425.1605913972228; Fri, 20 Nov 2020 15:12:52 -0800 (PST) MIME-Version: 1.0 References: <20201119232244.2776720-1-andrii@kernel.org> <20201119232244.2776720-5-andrii@kernel.org> <20201120230549.37k4zsjsrxbyjin3@kafai-mbp.dhcp.thefacebook.com> In-Reply-To: <20201120230549.37k4zsjsrxbyjin3@kafai-mbp.dhcp.thefacebook.com> From: Andrii Nakryiko Date: Fri, 20 Nov 2020 15:12:41 -0800 Message-ID: Subject: Re: [PATCH bpf-next 4/6] libbpf: add kernel module BTF support for CO-RE relocations To: Martin KaFai Lau Cc: Andrii Nakryiko , bpf , Networking , Alexei Starovoitov , Daniel Borkmann , Kernel Team Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Fri, Nov 20, 2020 at 3:06 PM Martin KaFai Lau wrote: > > On Thu, Nov 19, 2020 at 03:22:42PM -0800, Andrii Nakryiko wrote: > [ ... ] > > > +static int load_module_btfs(struct bpf_object *obj) > > +{ > > + struct bpf_btf_info info; > > + struct module_btf *mod_btf; > > + struct btf *btf; > > + char name[64]; > > + __u32 id, len; > > + int err, fd; > > + > > + if (obj->btf_modules_loaded) > > + return 0; > > + > > + /* don't do this again, even if we find no module BTFs */ > > + obj->btf_modules_loaded = true; > > + > > + /* kernel too old to support module BTFs */ > > + if (!kernel_supports(FEAT_MODULE_BTF)) > > + return 0; > > + > > + while (true) { > > + err = bpf_btf_get_next_id(id, &id); > > + if (err && errno == ENOENT) > > + return 0; > > + if (err) { > > + err = -errno; > > + pr_warn("failed to iterate BTF objects: %d\n", err); > > + return err; > > + } > > + > > + fd = bpf_btf_get_fd_by_id(id); > > + if (fd < 0) { > > + if (errno == ENOENT) > > + continue; /* expected race: BTF was unloaded */ > > + err = -errno; > > + pr_warn("failed to get BTF object #%d FD: %d\n", id, err); > > + return err; > > + } > > + > > + len = sizeof(info); > > + memset(&info, 0, sizeof(info)); > > + info.name = ptr_to_u64(name); > > + info.name_len = sizeof(name); > > + > > + err = bpf_obj_get_info_by_fd(fd, &info, &len); > > + if (err) { > > + err = -errno; > > + pr_warn("failed to get BTF object #%d info: %d\n", id, err); > > close(fd); > > > + return err; > > + } > > + > > + /* ignore non-module BTFs */ > > + if (!info.kernel_btf || strcmp(name, "vmlinux") == 0) { > > + close(fd); > > + continue; > > + } > > + > > [ ... ] > > > @@ -8656,9 +8815,6 @@ static inline int __find_vmlinux_btf_id(struct btf *btf, const char *name, > > else > > err = btf__find_by_name_kind(btf, name, BTF_KIND_FUNC); > > > > - if (err <= 0) > > - pr_warn("%s is not found in vmlinux BTF\n", name); > > - > > return err; > > } > > > > @@ -8675,6 +8831,9 @@ int libbpf_find_vmlinux_btf_id(const char *name, > > } > > > > err = __find_vmlinux_btf_id(btf, name, attach_type); > > + if (err <= 0) > > + pr_warn("%s is not found in vmlinux BTF\n", name); > > + > Please explain this move in the commit message. ok, I'll add something about that. The short answer is that __find_vmlinux_btf_id() is now expected to not find a type in vmlinux BTF, so emitting error would be wrong. So I moved it up a level where it's not expected. > > > btf__free(btf); > > return err; > > } > > -- > > 2.24.1 > >