Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4837974ybl; Mon, 9 Dec 2019 17:58:37 -0800 (PST) X-Google-Smtp-Source: APXvYqy8w39qdKBqpJ/FJ5RG1m38tjJnU/+tu4FTsDvXUZeieujDY1J9TjPK845grl9lRC/37Ztl X-Received: by 2002:a05:6830:1d91:: with SMTP id y17mr4294801oti.276.1575943116991; Mon, 09 Dec 2019 17:58:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575943116; cv=none; d=google.com; s=arc-20160816; b=EBL1edoQ6ZVKno3E/q5779ydu939ecElOv10nCb7p/HNlC1yBi8euX6v/HauNEG6QG jysx5YjjdEXS+O/qxPASHd+vMA39TYf5XmA8boWSsBOqljtF6Y1jJYBor80Z9+zGx61k qBxekR+8bPa8HkUOHawF7Onuv3UXZ4cKM8Rdbsx7ycnXsUVh5yJjr+G6dHR6PR6lLO3s bmKIwp8IbSJvKWsmlY9jSj9jxlCfOVv9Oat6lRPb/eMcCjtlXsha0M+ucVtlu31Gequg ArRC5qgCGDI7R0YcU7d59NLx8Rjxk82hXg+hyHkaob2wrg6l0rzCwSIvDddKXhCLT6+F mBoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=X0ZaIoyR0nAfoAh+OKYqyipN9nS86d8k81AmmebC5Dc=; b=BJaqEtkOxv1TF8ReuMn6d2WXDzChdegvpgSAkDXKPNdwJAPknnxWEMpB58JzuN1Y+0 sfkaggmWyp8RPPfWAZGqfL8eiWWYPRt+M7pgV19HBLPp6tDTH80MEh8pmc0vigWBUXGL q7btvsuqdvcHRyHHR1Sjy/1V0fJa8NoFWL4HJTmc+i+pf/ITT/0PnEX17fMPzr1DFs8F qNLDgLFdwv29ip8cE/mc7Qtb1jAc7Buphn1L/DgHNiF0VJUZ714SAi0ectD5BTLrW8Fc 8z0r+bkg5s74yIGLMXBotzaZV+ME253l7foWoPPFElzGAJZWKKW0kBTv+Vx2q3MI4V60 inJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=sb87YeZv; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u144si1071676oia.107.2019.12.09.17.58.24; Mon, 09 Dec 2019 17:58:36 -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=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=sb87YeZv; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726675AbfLJB5v (ORCPT + 99 others); Mon, 9 Dec 2019 20:57:51 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:37195 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726562AbfLJB5u (ORCPT ); Mon, 9 Dec 2019 20:57:50 -0500 Received: by mail-pj1-f68.google.com with SMTP id ep17so6697211pjb.4 for ; Mon, 09 Dec 2019 17:57:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=X0ZaIoyR0nAfoAh+OKYqyipN9nS86d8k81AmmebC5Dc=; b=sb87YeZvIf6gK8MxK8th+yPOx87KM8qaPeiKcUwKrOIbUgAb9I5pwdg/HMyYMEDSSx UIUHeTq/3n/rBqNZHIglSd1ZJQNnRBMbk3fl2Jm5pL0BAUlr6J6zFW9eqct/2KKka5/+ rF/C68G6ytDbE9x3eU5OLeWVNKeFrN9mcSo/Vw1Itifv2X0/apYsiYes1MIpbZpxWJ2s 5LOa/8C2bnf2YXD0bT0S+gAJjfIgQh9JeEWoYt/LoXh45DUXGqJ2cEsH1ffV7gkHSTox UD0gocftINsuxU3GYY/IsPowiTQjL9g9wJqSZdBmrIc02mg++MVUodsJqTT1Tc3U1I0V 43/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=X0ZaIoyR0nAfoAh+OKYqyipN9nS86d8k81AmmebC5Dc=; b=g1ZlcWO0Jqju0ti6bKmtadvlNGyEP+GptYB9HrW49ODmE4Ow5lfRcnEMgII5g2sf9i RctW8OqTCQ3V+m0yAfZDYFJvvvj8VB9sCrBHNnCdKxRiNPBtfmQEzoFObeqz5zl1jMx5 gpI+2RxTbprvtysnSeU+Z0896EMk7Ld1UygZL+iXSdGyiTWb6EBryIzUbRA0S8lOgIVT O9iErp8b96C9x+rLtfs1FN+jxLvQUj76uFnCkWXjVOAgjPhLmSRCEx0bU/8/7c+Mf1Pz VLwGHGS7ODalMYoZyBk7bqSFWgBWCBtR72wk1frheJZqJzg8sInG4kEj9Iv4qTKa2eNs xEGA== X-Gm-Message-State: APjAAAVyJm48F8Tkb9+kYUBWeuHycfo5v2r4IEpzAIge1+ny6n3Nsmly gJaFWq2sG+z8cQq4ERpZx+Crqg== X-Received: by 2002:a17:90a:28a1:: with SMTP id f30mr2508921pjd.77.1575943069618; Mon, 09 Dec 2019 17:57:49 -0800 (PST) Received: from cakuba.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id h11sm775665pgv.38.2019.12.09.17.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2019 17:57:49 -0800 (PST) Date: Mon, 9 Dec 2019 17:57:45 -0800 From: Jakub Kicinski To: Andrii Nakryiko , LKML Cc: , , , , , Subject: Re: [PATCH bpf-next 11/15] bpftool: add skeleton codegen command Message-ID: <20191209175745.2d96a1f0@cakuba.netronome.com> In-Reply-To: <20191210011438.4182911-12-andriin@fb.com> References: <20191210011438.4182911-1-andriin@fb.com> <20191210011438.4182911-12-andriin@fb.com> Organization: Netronome Systems, Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > 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 :( 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.