Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5644576ybl; Tue, 10 Dec 2019 09:12:37 -0800 (PST) X-Google-Smtp-Source: APXvYqwh7h3x0ncTQlcbFOrnEaQtV1328aZuTGomw8NHzNFL5Iun4XuhcUqUGbEsgUKun/9YCB8P X-Received: by 2002:aca:c256:: with SMTP id s83mr4951927oif.57.1575997957032; Tue, 10 Dec 2019 09:12:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575997957; cv=none; d=google.com; s=arc-20160816; b=vSGmMdJ8d4Y0UjVS0lX32a+vI6FipGLTGmvw35k92CAk9VtKyzHF5K7lnW3Bw+ChY5 Ye/qsc7YRUBYFvTyvVxMBc6ud88S7wywnhsVD1RUE0VhLzAMGN3HU5g7csA5GihlMKTR WLX33eKjheXU9jDjw3fddoLLmT8TXz1QJ/qbHdrShJYWDozsFKqHpHOjn+EFXNDMwNCk YL9pGSfhTlu9rFk+ct/+LlTgjixlIBcEJyLv+hSAbxo3a9yFOK3iYetb8v386FIFASNM fzVaKuljUsitf6l7TYzQozF3gOCR8SFYwtbuMhU1GFv3EGLkgYRw234y363i//mWbzdO 5eMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=7RagCXx4PLk5Qp49HJqKwcJPIWIyspcsm+oNaqdbslM=; b=H5wZ7eE6/AhWOkISxQ2TmjERHmlSwQaUKOI5fTd7YjBQQwreLodkinzSxEs5DUPAnj eSptRFZQmBZVgTMX61VMrEpCB2z3QeDsyAg/NffxzDZcedsqRalrLrHslGEcP3MzVrs4 Mu7xmB9T6Gy4A3tYfmiZ6ih+rzh7Zs8Ce5NJCas04znSt2XedJfIWVTnr0q3ySo4J5/n 6aIs2ih+3qJ6sLtFfagVNCiU/B71UmrjgmfXatTkDqZ1VgK4cLpk9C4lA0nYqxKpNjYl PquciOUywhD7dh4KB0f2X4lI9uFpFrMmkiBIiQyuVHFp76O7ET9jsQTZolpXpkpnUiJV EsEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DoyQL4Kc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q26si2181577oij.38.2019.12.10.09.12.24; Tue, 10 Dec 2019 09:12:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DoyQL4Kc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727874AbfLJRLo (ORCPT + 99 others); Tue, 10 Dec 2019 12:11:44 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:44584 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726780AbfLJRLn (ORCPT ); Tue, 10 Dec 2019 12:11:43 -0500 Received: by mail-qt1-f193.google.com with SMTP id g17so3410590qtp.11; Tue, 10 Dec 2019 09:11:42 -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=7RagCXx4PLk5Qp49HJqKwcJPIWIyspcsm+oNaqdbslM=; b=DoyQL4KcMkvz7vmH3s3eQU8CtblHmOfXtg+ZpUXRAFLGVApTwLQ2X4LxuezG4hPs3o UKninZ55uaTToohw31YCmCgZZlHWGGXsb6JmJ/SodnaPv9Wc/18KczLZWzqO8YbBodrm r8bQr/Rx9Pr5GxFncLGbvR0Y5vRMxfl30/apLikbjSRcHJWYrSJFeuxQ7BmlBCl4xsfv YZu+4Ojivyp+JpHhIKmeuIlNKsP699nBFDzXn4u9aBdwOfIosV/TpukkRIEb3g0kUOEg 570HmX9VOtMunjx6aMrD2R92K+rZJIBoNTBihxii1+T5ac+bLA4c8qoR6neDxOOnPoPS F2Lg== 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=7RagCXx4PLk5Qp49HJqKwcJPIWIyspcsm+oNaqdbslM=; b=C/9UHY8xi4NxIAurarXCrYF15oHUq+OQ81orCLtOTw21ImlzZHtLazkO+CO2Fseqpl VKeXqpZZ0AdYTmBZtDC7YNjlUn/EkiQFIfuvGvpumeHRNELOxro8De6GW6GBuy4upXhP PYzdgAvOHb3XgCfDEebaXH1EvoNBc/jElsUxEPpXNuh4fX6f4qdepx9UgxefdmiFcgU2 zmAjxrdBxYPWtFGiZzJSssh7OlXJzO8a274I7LXf5YJ/BKmiJSutnzaHI/rlcl85iowG HXO32FGubX+1RkZ5B9lNI+76NcY1fDciany0GF+49tNx1lZP2tc9/Y2xXDR12Q3je0u1 B5Pw== X-Gm-Message-State: APjAAAUZwVAK6Px+D7x6xFpvDqR8wlo2VRLYzIeX4+t/YswHiokxoIvt hDIVVFjyqL0sviOGA6o16ep5TjQfbicBykYCxTs= X-Received: by 2002:ac8:5457:: with SMTP id d23mr29404307qtq.93.1575997901883; Tue, 10 Dec 2019 09:11:41 -0800 (PST) MIME-Version: 1.0 References: <20191210011438.4182911-1-andriin@fb.com> <20191210011438.4182911-12-andriin@fb.com> <20191209175745.2d96a1f0@cakuba.netronome.com> In-Reply-To: <20191209175745.2d96a1f0@cakuba.netronome.com> From: Andrii Nakryiko Date: Tue, 10 Dec 2019 09:11:31 -0800 Message-ID: Subject: Re: [PATCH bpf-next 11/15] bpftool: add skeleton codegen command To: Jakub Kicinski Cc: Andrii Nakryiko , LKML , bpf , Networking , Alexei Starovoitov , Daniel Borkmann , Kernel Team Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 9, 2019 at 5:57 PM Jakub Kicinski wrote: > > On Mon, 9 Dec 2019 17:14:34 -0800, Andrii Nakryiko wrote: > > struct { > > /* used by libbpf's skeleton API */ > > struct bpf_object_skeleton *skeleton; > > /* bpf_object for libbpf APIs */ > > struct bpf_object *obj; > > struct { > > /* for every defined map in BPF object: */ > > struct bpf_map *; > > } maps; > > struct { > > /* for every program in BPF object: */ > > struct bpf_program *; > > } progs; > > struct { > > /* for every program in BPF object: */ > > struct bpf_link *; > > } links; > > /* for every present global data section: */ > > struct __ { > > /* memory layout of corresponding data section, > > * with every defined variable represented as a struct field > > * with exactly the same type, but without const/volatile > > * modifiers, e.g.: > > */ > > int *my_var_1; > > ... > > } *; > > }; > > I think I understand how this is useful, but perhaps the problem here > is that we're using C for everything, and simple programs for which > loading the ELF is majority of the code would be better of being > written in a dynamic language like python? Would it perhaps be a > better idea to work on some high-level language bindings than spend > time writing code gens and working around limitations of C? None of this work prevents Python bindings and other improvements, is it? Patches, as always, are greatly appreciated ;) This skeleton stuff is not just to save code, but in general to simplify and streamline working with BPF program from userspace side. Fortunately or not, but there are a lot of real-world applications written in C and C++ that could benefit from this, so this is still immensely useful. selftests/bpf themselves benefit a lot from this work, see few of the last patches in this series. > > > This provides great usability improvements: > > - no need to look up maps and programs by name, instead just > > my_obj->maps.my_map or my_obj->progs.my_prog would give necessary > > bpf_map/bpf_program pointers, which user can pass to existing libbpf APIs; > > - pre-defined places for bpf_links, which will be automatically populated for > > program types that libbpf knows how to attach automatically (currently > > tracepoints, kprobe/kretprobe, raw tracepoint and tracing programs). On > > tearing down skeleton, all active bpf_links will be destroyed (meaning BPF > > programs will be detached, if they are attached). For cases in which libbpf > > doesn't know how to auto-attach BPF program, user can manually create link > > after loading skeleton and they will be auto-detached on skeleton > > destruction: > > > > my_obj->links.my_fancy_prog = bpf_program__attach_cgroup_whatever( > > my_obj->progs.my_fancy_prog, > > > - it's extremely easy and convenient to work with global data from userspace > > now. Both for read-only and read/write variables, it's possible to > > pre-initialize them before skeleton is loaded: > > > > skel = my_obj__open(raw_embed_data); > > my_obj->rodata->my_var = 123; > > my_obj__load(skel); /* 123 will be initialization value for my_var */ > > > > After load, if kernel supports mmap() for BPF arrays, user can still read > > (and write for .bss and .data) variables values, but at that point it will > > be directly mmap()-ed to BPF array, backing global variables. This allows to > > seamlessly exchange data with BPF side. From userspace program's POV, all > > the pointers and memory contents stay the same, but mapped kernel memory > > changes to point to created map. > > If kernel doesn't yet support mmap() for BPF arrays, it's still possible to > > use those data section structs to pre-initialize .bss, .data, and .rodata, > > but after load their pointers will be reset to NULL, allowing user code to > > gracefully handle this condition, if necessary. > > > > Given a big surface area, skeleton is kept as an experimental non-public > > API for now, until more feedback and real-world experience is collected. > > That makes no sense to me. bpftool has the same backward compat > requirements as libbpf. You're just pushing the requirements from > one component to the other. Feedback and real-world use cases have > to be exercised before code is merged to any project with backward > compatibility requirements :( To get this feedback we need to have this functionality adopted. To have it adopted, we need it available in tool users already know, have, and use. If you feel that "experimental" disclaimer is not enough, I guess we can add extra flag to bpftool itself to enable experimental functionality, something like: bpftool --experimental gen skeleton > > Also please run checkpatch on your patches, and fix reverse xmas tree. > This is bpftool, not libbpf. Creating a separate tool for this codegen > stuff is also an option IMHO. Sure, will fix few small things checkpatch detected. Will reverse christmas-ize all the variables, of course :) As for separate tool just for this, you are not serious, right? If bpftool is not right tool for this, I don't know which one is.