Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp12525344rwl; Tue, 3 Jan 2023 16:10:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXsWlGaAzefacxTS4BULC3+g5zq0dpDEAXmNZWK0YAm6T+BJEmNyeUDJRe19tgS/R3hSga6t X-Received: by 2002:a17:902:c2d2:b0:192:e726:9acc with SMTP id c18-20020a170902c2d200b00192e7269accmr866349pla.54.1672791059248; Tue, 03 Jan 2023 16:10:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672791059; cv=none; d=google.com; s=arc-20160816; b=IELnEINABDHiF+M3XcJMwaj2VMMdHjlSuDS0+H4c1VlQ6QgUqQo8dV9y9fxSvHyPCn PHR41m2f6WP7LPVyyTgOmd8BX7A//X37TbWKIdFyHDBOmRLfMgYEMRdA3oH3vmOYm25A J6sWYEfA1nGBQQw/MC4cLDplPda/1bsWrrfGRWDGenxjggdN2SBgWJfcttAGCCk9QQ+5 VeO7XrmLzGYJWZOOS1HhK7B4uOydcdTU3HDaqvI62gBl8LXUGbpGLuGIMflUsb0jJb95 61FFd7OKik+JTAvq0kr95lo0znRY15WHj1XBMfbh569CN2wrfTu50Rp2bTOc1vrKw7JJ hgbQ== 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=3oSb7JXJVS/6HsFecUnGwQqOOB9BR+/FVmXe6sUvBjE=; b=borMV2pIDWnNwpnO7xevFDpTYIrWk7T1uOMKMLSWiJGKfnfZ6vRvpY5sjaqcaFIZiu 0vcNqVCSlQpH6yI1D2hvywrpn6uH01MS3KROQj2jqt+VB6MTETc0Y8EQ95II/CMFhlwT ENdfOthRcfg4LW7EgXnpJkMdPV+9bnY8D9Lk1FEB6lSlf6RZOKULfER+WEUG6r4c7CUT 8zK/DCWcTSlc0KsXe9Om3GOeJyOVQHb3Brrcso9tw8/Fo9Kj5sI7yOKMfob6xSafqur+ pzs2zprsJkhzDn6pVZ3eCta3u0k1lKjS5r0ctGlmFdQt76CalREBbRhwwuZnsgGt+IKx J1uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gTbDgWlC; 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 w4-20020a170902904400b00176953fee67si31578100plz.86.2023.01.03.16.10.52; Tue, 03 Jan 2023 16:10:59 -0800 (PST) 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=gTbDgWlC; 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 S238123AbjACXrC (ORCPT + 57 others); Tue, 3 Jan 2023 18:47:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237815AbjACXq7 (ORCPT ); Tue, 3 Jan 2023 18:46:59 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FBDD1004E; Tue, 3 Jan 2023 15:46:58 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id u19so78606786ejm.8; Tue, 03 Jan 2023 15:46:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=3oSb7JXJVS/6HsFecUnGwQqOOB9BR+/FVmXe6sUvBjE=; b=gTbDgWlCH4NUcCEHgth2YTnVqtz4s4PKz+5t3gYtxN5MZc/LvN+nJoGJJTISFRSwrs w7pwymo+rn2BVMZudW2Xk6ZRv9sxlcO321RroJPRpATfUSEdl99e2+eBB6dFfFWEqyRr KHR4OANaK7QgwTNcrf6CpPboBwZ+H3m74npjgBNekhmRjZBp5BDdZTG28bEyZEKLe1aj LN0OAKAxx+3FOh4o6EhTjiNSXUmxihBDxy+xbXN2esrqPr8F88hN8W/l+k1QT4wDHM0C ZU3GvFfRsG3VaXyuhXEpYQVBw0ikmucnv4PLXcvg0Gabb1PjMBYaokh3LO1pb323WZ+9 Z/AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3oSb7JXJVS/6HsFecUnGwQqOOB9BR+/FVmXe6sUvBjE=; b=57Q2UmTxvpuubDmxLNSh0wrvy9lWbT4yeOo87y3wZeDu/ld/x12HF5MFq5b4bJVCkf MJtxCR3EWQZ5IV9rrdNmYDNqVTQn/LKcE0X296WayEKMAcCDqYdPjpdnxyKIKlcAMAGU ecbhnMCAv0OfJQE0eDvC+aftYCDeuQUNnX5hUwGMgEQJfZ0VgXgFOBVdNq5JU4LgQvVS rhFKioxrHMj6tIzyR/5XuzhpFeek23i270FXQhvh2Zo8MNKje9mUSMUBPr0AQZJq53BK hlUzLc9GzS6XDNQtWUHOsiMDmd2+svcbVz6TjJjpa9OaUMug5d0hMRMJBykEgcOXZGTa sSJg== X-Gm-Message-State: AFqh2kow8FDFah/O7bEibL4MExqnBpXI8ZZO/Z0+Hijqzve8o0cjnCXI A6YP5tEibEKT2dUQ+6vWLV0T4ygYOLsXsxDojrM= X-Received: by 2002:a17:906:f43:b0:84c:95c7:304d with SMTP id h3-20020a1709060f4300b0084c95c7304dmr2153565ejj.545.1672789616772; Tue, 03 Jan 2023 15:46:56 -0800 (PST) MIME-Version: 1.0 References: <20221217223509.88254-1-changbin.du@gmail.com> <20221217223509.88254-2-changbin.du@gmail.com> <20221220013114.zkkxkqh7orahxbzh@mail.google.com> In-Reply-To: From: Andrii Nakryiko Date: Tue, 3 Jan 2023 15:46:44 -0800 Message-ID: Subject: Re: [PATCH v3 1/2] libbpf: show error info about missing ".BTF" section To: Quentin Monnet Cc: Leo Yan , Changbin Du , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Shuah Khan , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Rutland , Alexander Shishkin , Namhyung Kim , Mykola Lysenko , linux-perf-users@vger.kernel.org, linux-kselftest@vger.kernel.org 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 Tue, Jan 3, 2023 at 7:03 AM Quentin Monnet wrote: > > 2022-12-20 16:13 UTC-0800 ~ Andrii Nakryiko > > On Tue, Dec 20, 2022 at 3:34 AM Leo Yan wrote: > >> > >> On Tue, Dec 20, 2022 at 09:31:14AM +0800, Changbin Du wrote: > >> > >> [...] > >> > >>>>> Now will print below info: > >>>>> libbpf: failed to find '.BTF' ELF section in /home/changbin/work/linux/vmlinux > >>>> > >>>> Recently I encountered the same issue, it could be caused by: > >>>> either missing to install tool pahole or missing to enable kernel > >>>> configuration CONFIG_DEBUG_INFO_BTF. > >>>> > >>>> Could we give explict info for reasoning failure? Like: > >>>> > >>>> "libbpf: failed to find '.BTF' ELF section in /home/changbin/work/linux/vmlinux, > >>>> please install pahole and enable CONFIG_DEBUG_INFO_BTF=y for kernel building". > >>>> > >>> This is vmlinux special information and similar tips are removed from > >>> patch V2. libbpf is common for all ELFs. > >> > >> Okay, I see. Sorry for noise. > >> > >>>>> Error: failed to load BTF from /home/changbin/work/linux/vmlinux: No such file or directory > >>>> > >>>> This log is confusing when we can find vmlinux file but without BTF > >>>> section. Consider to use a separate patch to detect vmlinux not > >>>> found case and print out "No such file or directory"? > >>>> > >>> I think it's already there. If the file doesn't exist, open will fail. > >> > >> [...] > >> > >>>>> @@ -990,6 +990,7 @@ static struct btf *btf_parse_elf(const char *path, struct btf *base_btf, > >>>>> err = 0; > >>>>> > >>>>> if (!btf_data) { > >>>>> + pr_warn("failed to find '%s' ELF section in %s\n", BTF_ELF_SEC, path); > >>>>> err = -ENOENT; > >> > >> btf_parse_elf() returns -ENOENT when ELF file doesn't contain BTF > >> section, therefore, bpftool dumps error string "No such file or > >> directory". It's confused that actually vmlinux is existed. > >> > >> I am wondering if we can use error -LIBBPF_ERRNO__FORMAT (or any > >> better choice?) to replace -ENOENT at here, this can avoid bpftool to > >> outputs "No such file or directory" in this case. > > > > The only really meaningful error code would be -ESRCH, which > > strerror() will translate to "No such process", which is also > > completely confusing. > > > > In general, I always found these strerror() messages extremely > > unhelpful and confusing. I wonder if we should make an effort to > > actually emit symbolic names of errors instead (literally, "-ENOENT" > > in this case). This is all tooling for engineers, I find -ENOENT or > > -ESRCH much more meaningful as an error message, compared to "No such > > file" seemingly human-readable interpretation. > > > > Quenting, what do you think about the above proposal for bpftool? We > > can have some libbpf helper internally and do it in libbpf error > > messages as well and just reuse the logic in bpftool, perhaps? > > Apologies for the delay. > What you're proposing is to replace all messages currently looking like > this: > > $ bpftool prog > Error: can't get next program: Operation not permitted > > by: > > $ bpftool prog > Error: can't get next program: -EPERM > > Do I understand correctly? yep, that's what I had in mind > > I think the strerror() messages are helpful in some occasions (they > _are_ more human-friendly to many users), but it's also true that > they're not always precise. With bpftool, "Invalid argument" is a > classic when the program doesn't load, and may lead to confusion with > the args passed to bpftool on the command line. Then there are the other > corner cases like the one discussed in this thread. So, why not. maybe the right approach would be to have both symbolic error name and its human-readable representation, so for example above Error: can't get next program: [-EPERM] Operation not permitted or something like that? And if error value is unknown, just keep it as integer: "[-5555]" ? > > If we do change, yeah I'd rather have as much of this handling in libbpf > itself, and then adjust bpftool to handle the remaining cases, for > consistency. we can teach libbpf_strerror_r() to do this and if bpftool is going to use it consistently then it would get the benefit automatically > > Quentin