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.2 required=3.0 tests=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 3F84FC433FF for ; Tue, 13 Aug 2019 14:20:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1B6CF20644 for ; Tue, 13 Aug 2019 14:20:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729407AbfHMOU1 (ORCPT ); Tue, 13 Aug 2019 10:20:27 -0400 Received: from www62.your-server.de ([213.133.104.62]:46688 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729272AbfHMOU1 (ORCPT ); Tue, 13 Aug 2019 10:20:27 -0400 Received: from sslproxy05.your-server.de ([78.46.172.2]) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1hxXez-0005Jm-B6; Tue, 13 Aug 2019 16:20:25 +0200 Received: from [2a02:120b:2c12:c120:71a0:62dd:894c:fd0e] (helo=pc-66.home) by sslproxy05.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1hxXez-000FfH-2d; Tue, 13 Aug 2019 16:20:25 +0200 Subject: Re: [RESEND][PATCH v3 bpf-next] btf: expose BTF info through sysfs To: Andrii Nakryiko , bpf@vger.kernel.org, netdev@vger.kernel.org, ast@fb.com Cc: andrii.nakryiko@gmail.com, kernel-team@fb.com References: <20190812183947.130889-1-andriin@fb.com> From: Daniel Borkmann Message-ID: Date: Tue, 13 Aug 2019 16:20:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190812183947.130889-1-andriin@fb.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.3/25540/Tue Aug 13 10:16:47 2019) Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On 8/12/19 8:39 PM, 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). Small question: given modules will be covered later, would it not be more obvious to name it /sys/kernel/btf/vmlinux instead? > 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(); > > Reviewed-by: Greg Kroah-Hartman > Signed-off-by: Andrii Nakryiko In any case, this is great progress, applied thanks!