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=-8.4 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 1D194CA9EAF for ; Mon, 21 Oct 2019 14:02:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E565C2166E for ; Mon, 21 Oct 2019 14:02:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZST1+EYq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728753AbfJUOCn (ORCPT ); Mon, 21 Oct 2019 10:02:43 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:41381 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727152AbfJUOCn (ORCPT ); Mon, 21 Oct 2019 10:02:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571666562; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E76Ncd4hkPdyEmWthnzq2lnetFoG06/DZ+e4atVNaro=; b=ZST1+EYq72qtaFP+1v9BvwQ8BgtH1rumUAexzHd+d8sw8Wys5FdgMDy9JxNd6v+puhIjg4 +jgqvOpCyHRjZq+zXZ6CgG+bmontEIz8/in/mtb4rkZsL3Y1NuoBx6+tHRfYifKq4fac5z iu3q8OMwTBNQQFfvqRLI8jgK5d0PwaY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-309-42IKWHNWNBWdYFohri2Hfw-1; Mon, 21 Oct 2019 10:02:36 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D63EB107AD33; Mon, 21 Oct 2019 14:02:29 +0000 (UTC) Received: from krava (unknown [10.43.17.61]) by smtp.corp.redhat.com (Postfix) with SMTP id 09CAB60166; Mon, 21 Oct 2019 14:02:27 +0000 (UTC) Date: Mon, 21 Oct 2019 16:02:27 +0200 From: Jiri Olsa To: Jakub Kicinski Cc: Jiri Olsa , Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Yonghong Song , Martin KaFai Lau Subject: Re: [PATCH] bpftool: Try to read btf as raw data if elf read fails Message-ID: <20191021140227.GD32718@krava> References: <20191018103404.12999-1-jolsa@kernel.org> <20191018153905.600d7c8a@cakuba.netronome.com> MIME-Version: 1.0 In-Reply-To: <20191018153905.600d7c8a@cakuba.netronome.com> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: 42IKWHNWNBWdYFohri2Hfw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Fri, Oct 18, 2019 at 03:39:05PM -0700, Jakub Kicinski wrote: > On Fri, 18 Oct 2019 12:34:04 +0200, Jiri Olsa wrote: > > The bpftool interface stays the same, but now it's possible > > to run it over BTF raw data, like: > >=20 > > $ bpftool btf dump file /sys/kernel/btf/vmlinux > > libbpf: failed to get EHDR from /sys/kernel/btf/vmlinux > > [1] INT '(anon)' size=3D4 bits_offset=3D0 nr_bits=3D32 encoding=3D(no= ne) > > [2] INT 'long unsigned int' size=3D8 bits_offset=3D0 nr_bits=3D64 enc= oding=3D(none) > > [3] CONST '(anon)' type_id=3D2 > >=20 > > I'm also adding err init to 0 because I was getting uninitialized > > warnings from gcc. > >=20 > > Signed-off-by: Jiri Olsa > > --- > > tools/bpf/bpftool/btf.c | 47 ++++++++++++++++++++++++++++++++++++----- > > 1 file changed, 42 insertions(+), 5 deletions(-) > >=20 > > diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c > > index 9a9376d1d3df..100fb7e02329 100644 > > --- a/tools/bpf/bpftool/btf.c > > +++ b/tools/bpf/bpftool/btf.c > > @@ -12,6 +12,9 @@ > > #include > > #include > > #include > > +#include > > +#include > > +#include > > =20 > > #include "btf.h" > > #include "json_writer.h" > > @@ -388,6 +391,35 @@ static int dump_btf_c(const struct btf *btf, > > =09return err; > > } > > =20 > > +static struct btf *btf__parse_raw(const char *file) > > +{ > > +=09struct btf *btf =3D ERR_PTR(-EINVAL); > > +=09__u8 *buf =3D NULL; >=20 > Please drop the inits >=20 > > +=09struct stat st; > > +=09FILE *f; > > + > > +=09if (stat(file, &st)) > > +=09=09return btf; >=20 > And return constants here >=20 > > +=09f =3D fopen(file, "rb"); > > +=09if (!f) > > +=09=09return btf; >=20 > and here >=20 > > +=09buf =3D malloc(st.st_size); > > +=09if (!buf) > > +=09=09goto err; >=20 > and jump to the right place here. >=20 > > +=09if ((size_t) st.st_size !=3D fread(buf, 1, st.st_size, f)) > > +=09=09goto err; > > + > > +=09btf =3D btf__new(buf, st.st_size); > > + > > +err: >=20 > The prefix for error labels which is shared with non-error path is exit_ >=20 > > +=09free(buf); > > +=09fclose(f); > > +=09return btf; > > +} > > + ok for all above > > static int do_dump(int argc, char **argv) > > { > > =09struct btf *btf =3D NULL; > > @@ -397,7 +429,7 @@ static int do_dump(int argc, char **argv) > > =09__u32 btf_id =3D -1; > > =09const char *src; > > =09int fd =3D -1; > > -=09int err; > > +=09int err =3D 0; >=20 > This change looks unnecessary. I'm getting confusing warnings from gcc about this, but there is a code path where do_dump would return untouched err: do_dump int err; } else if (is_prefix(src, "file")) { btf =3D btf__parse_elf(*argv, NULL); // succeeds } while (argc) { if (is_prefix(*argv, "format")) { else { // in here goto done; } done: return err; thanks, jirka