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=-5.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 462A2C31E40 for ; Mon, 12 Aug 2019 07:08:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C4C82087B for ; Mon, 12 Aug 2019 07:08:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565593692; bh=VftEajh1ff4JrgNdmTLLPWp/EKVXnRP6Bhh+D7hfXkM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=v29sfEE3nBv7cCF0pTxFbJJ7L1tw4UfnUfy60mmVa7jrcdu5MNrs5YdIvuBRKYjJP TyTirRTxTjiKnGQnuMvbQ9Deratw8Hx5m+Ykw0+lsFVDTNlPmXPUKfwcmR//9n4eCJ gRzmphuxFGzWTS1xFQGo4TviNHSYYFJQhhKTPpEk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726466AbfHLHIL (ORCPT ); Mon, 12 Aug 2019 03:08:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:32934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbfHLHIK (ORCPT ); Mon, 12 Aug 2019 03:08:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A182D2070C; Mon, 12 Aug 2019 07:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565593689; bh=VftEajh1ff4JrgNdmTLLPWp/EKVXnRP6Bhh+D7hfXkM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BKRJqKtl26WL9QSTF0JyFydbutUxHsQGziV5LbolXNpFnCXmoUiZGhtBitKDBMCd6 tLUlsjjH5rxYiomW7smrao7LLTTBeY+w1cP3Utp82xkDu5czXVATy6gws0D5cfOGeV SUl+W8BCJK5gPO68VECu/JE52mvZmdxB9/nE5+XY= Date: Mon, 12 Aug 2019 09:08:06 +0200 From: Greg KH To: Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, ast@fb.com, daniel@iogearbox.net, yhs@fb.com, andrii.nakryiko@gmail.com, kernel-team@fb.com, Masahiro Yamada , Arnaldo Carvalho de Melo , Jiri Olsa , Sam Ravnborg Subject: Re: [PATCH v3 bpf-next] btf: expose BTF info through sysfs Message-ID: <20190812070806.GA362@kroah.com> References: <20190812061405.2290824-1-andriin@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190812061405.2290824-1-andriin@fb.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Sun, Aug 11, 2019 at 11:14:05PM -0700, Andrii Nakryiko wrote: > Make .BTF section allocated and expose its contents through sysfs. > > /sys/kernel/btf directory is created to contain all the BTFs present > inside kernel. Currently there is only kernel's main BTF, represented as > /sys/kernel/btf/kernel file. Once kernel modules' BTFs are supported, > each module will expose its BTF as /sys/kernel/btf/ file. > > Current approach relies on a few pieces coming together: > 1. pahole is used to take almost final vmlinux image (modulo .BTF and > kallsyms) and generate .BTF section by converting DWARF info into > BTF. This section is not allocated and not mapped to any segment, > though, so is not yet accessible from inside kernel at runtime. > 2. objcopy dumps .BTF contents into binary file and subsequently > convert binary file into linkable object file with automatically > generated symbols _binary__btf_kernel_bin_start and > _binary__btf_kernel_bin_end, pointing to start and end, respectively, > of BTF raw data. > 3. final vmlinux image is generated by linking this object file (and > kallsyms, if necessary). sysfs_btf.c then creates > /sys/kernel/btf/kernel file and exposes embedded BTF contents through > it. This allows, e.g., libbpf and bpftool access BTF info at > well-known location, without resorting to searching for vmlinux image > on disk (location of which is not standardized and vmlinux image > might not be even available in some scenarios, e.g., inside qemu > during testing). > > Alternative approach using .incbin assembler directive to embed BTF > contents directly was attempted but didn't work, because sysfs_proc.o is > not re-compiled during link-vmlinux.sh stage. This is required, though, > to update embedded BTF data (initially empty data is embedded, then > pahole generates BTF info and we need to regenerate sysfs_btf.o with > updated contents, but it's too late at that point). > > If BTF couldn't be generated due to missing or too old pahole, > sysfs_btf.c handles that gracefully by detecting that > _binary__btf_kernel_bin_start (weak symbol) is 0 and not creating > /sys/kernel/btf at all. > > v2->v3: > - added Documentation/ABI/testing/sysfs-kernel-btf (Greg K-H); > - created proper kobject (btf_kobj) for btf directory (Greg K-H); > - undo v2 change of reusing vmlinux, as it causes extra kallsyms pass > due to initially missing __binary__btf_kernel_bin_{start/end} symbols; > > v1->v2: > - allow kallsyms stage to re-use vmlinux generated by gen_btf(); > > Cc: Masahiro Yamada > Cc: Arnaldo Carvalho de Melo > Cc: Jiri Olsa > Cc: Sam Ravnborg > Signed-off-by: Andrii Nakryiko > --- > Documentation/ABI/testing/sysfs-kernel-btf | 17 +++++++ > kernel/bpf/Makefile | 3 ++ > kernel/bpf/sysfs_btf.c | 51 +++++++++++++++++++++ > scripts/link-vmlinux.sh | 52 ++++++++++++++-------- > 4 files changed, 104 insertions(+), 19 deletions(-) > create mode 100644 Documentation/ABI/testing/sysfs-kernel-btf > create mode 100644 kernel/bpf/sysfs_btf.c Reviewed-by: Greg Kroah-Hartman