Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2488187ioo; Mon, 23 May 2022 21:33:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9wSdlQdCv3WD6BiPthKmtieGUK+QO/W9IH+BNd6cwzPp3qwv6pWqSNX+UIljdRPsbNzeW X-Received: by 2002:a63:296:0:b0:3fa:9d26:e568 with SMTP id 144-20020a630296000000b003fa9d26e568mr2709381pgc.2.1653366813089; Mon, 23 May 2022 21:33:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653366813; cv=none; d=google.com; s=arc-20160816; b=cNNxAwQv/cpa2IFLhYYnpN8+r96xvJEzHXWTpMTLkWT9gQ6SzYGLvkuR6weyDBAuEV mHSj36aR8Xgz452Re/T4au+oGYDDoUJL7y9UrjVG421zy23WHq1Z9vaaVU7QrGY9O47M JHuxkRPG+R1Czw3ejmwyWYUswtq0ag6hzMKCyoMPPwTdJCYUBKHXxeFXtJd2skcdKns/ 8A9K2GikF7f0drJSQOfzFcZoEqkaHBHHztXPVDvhxoDiGugDjSmOk4m/zb27Rxv7yxtm A6NsjgIWd4df6UQjgZ/QdYjx00uJLRH5aiiiV1vdZK42puHqdwHOL+C07mXOINVhnugI 7RuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=RM70btlxkJMcJZU115/sfApSU8coL9mAakE0PyR/h4Y=; b=dHGRjyw2CjLXHZH0eXC0B45T/8iXnIsv2u+fixSHFC/7S2GzIM19x020NkQca6q0Bq L9/WGlIePpDy3J7cH5nmK9dpFqr0DmYOiMHnDW89K3cBulvBnm38HeVHH37JUKwwFD8z SUXuFx8JvOm/fVnkb3UmYojB526+YP/jPfX/PVh1IrAyaVkWoebUq+FsKLsTTw6V3Ubb VeX3c0Sr2JliKYVJthfikdWWj80+uoDX0wTUzAQgNwcPt4aQMr20K2kIOqJxSQNdtd9z HnBIQ9PVQgCXvV/sKNdteL7SIQG7xLwXdCbjkGT6h/j0AAikv3+PA9yEc1tX459CTcg9 S/vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Z+O4x3cY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b1-20020a056a00114100b005187a9a74cdsi13155127pfm.269.2022.05.23.21.33.20; Mon, 23 May 2022 21:33:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Z+O4x3cY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229663AbiEWXJE (ORCPT + 99 others); Mon, 23 May 2022 19:09:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbiEWXI7 (ORCPT ); Mon, 23 May 2022 19:08:59 -0400 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45FF970369; Mon, 23 May 2022 16:08:58 -0700 (PDT) Received: by mail-qk1-x733.google.com with SMTP id c1so13916330qkf.13; Mon, 23 May 2022 16:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=RM70btlxkJMcJZU115/sfApSU8coL9mAakE0PyR/h4Y=; b=Z+O4x3cYzdfYcBo+qMsyV+PE4neCzLxUeNKd0uGm+7pOIGn2SvhFHXsWE5j1ADZgFM /9Wn6I+zqKBfX7MCQxKpCMl0c7oafuo4U0o51+RHgfcZHad66+9Vl7LCGHWIMvyZl1T/ nHOd3iHn5hTzpKFR+Iv+UyY7KgyOtooAfntO+fJze/d7dZYoqJbbh/1NxwLBJzweXq3u Ewz9nL60KfNVOua+CJkMUQOKZTKdSH9NiCSx8UBFVydJNnMmsaTN9+cn27baIcMVsgG6 mDo0hv14ycnGJszVkW27C0aali7KWXzRlgKlPb6Dew+pth3VpCO8lBWUJ/Kob/3XfZSl fOEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=RM70btlxkJMcJZU115/sfApSU8coL9mAakE0PyR/h4Y=; b=dXp1xMrgNoQfVHvwozjQeQ72dxyhjOpvVlLVgfcnjI8HHsmFbsxxxfhMYod0Q6V+d0 u+DqiSCmSC2XAVWf4bgUE9ocN5apcQjVP+E8pV/j4bTdYH1hd5Z8h5+pUDD99c49DEqy 0NEt+gvfsJ/3Zhqkq0zg77oex2D40/Scajmox9BdrByYJnoiz6tOo0AChyQCqINavbFy KA4H/t7SievrKuQw4ZUqMZ6C5VMxD8M2QsoJfVrFTIKreUlaioTWJYaZKr3AoIvZUQh2 AE8evK1h6ix3O7bROtb55m2i2lKuxOvX+tfnwXXcu8GF6ih2W9Gyn0yCLanh0uF+IXPV Ad3Q== X-Gm-Message-State: AOAM531J4YlDXpqTxrdpRpHDfySu5d11/ZrxWOJrfabBOlFoZwLDqcQ0 SPL7yz/NtZIjuOjOueREy2s= X-Received: by 2002:a05:620a:2456:b0:6a3:769a:653e with SMTP id h22-20020a05620a245600b006a3769a653emr5997540qkn.148.1653347337363; Mon, 23 May 2022 16:08:57 -0700 (PDT) Received: from jup ([2607:fea8:e2e4:d600::6ece]) by smtp.gmail.com with ESMTPSA id c10-20020ac86e8a000000b002f3ef928fbbsm1821926qtv.72.2022.05.23.16.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 16:08:56 -0700 (PDT) Date: Mon, 23 May 2022 19:08:54 -0400 From: Michael Mullin To: Andrii Nakryiko Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Networking , bpf , open list Subject: Re: [PATCH] bpftool: mmaped fields missing map structure in generated skeletons Message-ID: <20220523230854.3hdduizw36huxvxw@jup> References: <20220523202649.6iiz4h2wf5ryx3w2@jup> <20220523221954.dsqvy55ron4cfdqq@jup> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 23, 2022 at 03:38:03PM -0700, Andrii Nakryiko wrote: > On Mon, May 23, 2022 at 3:19 PM Michael Mullin wrote: > > > > On Mon, May 23, 2022 at 03:02:31PM -0700, Andrii Nakryiko wrote: > > > On Mon, May 23, 2022 at 1:26 PM Michael Mullin wrote: > > > > > > > > When generating a skeleton which has an mmaped map field, bpftool's > > > > output is missing the map structure. This causes a compile break when > > > > the generated skeleton is compiled as the field belongs to the internal > > > > struct maps, not directly to the obj. > > > > > > > > Signed-off-by: Michael Mullin > > > > --- > > > > tools/bpf/bpftool/gen.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c > > > > index f158dc1c2149..b49293795ba0 100644 > > > > --- a/tools/bpf/bpftool/gen.c > > > > +++ b/tools/bpf/bpftool/gen.c > > > > @@ -853,7 +853,7 @@ codegen_maps_skeleton(struct bpf_object *obj, size_t map_cnt, bool mmaped) > > > > i, bpf_map__name(map), i, ident); > > > > /* memory-mapped internal maps */ > > > > if (mmaped && is_internal_mmapable_map(map, ident, sizeof(ident))) { > > > > - printf("\ts->maps[%zu].mmaped = (void **)&obj->%s;\n", > > > > + printf("\ts->maps[%zu].mmaped = (void **)&obj->maps.%s;\n", > > > > > > That's not right. maps.my_map is struct bpf_map *, but mmaped is > > > supposed to be a blob of memory that is memory-mapped into map. > > > > > > Can you elaborate on how you trigger that compilation error with a > > > small example? > > > > I have an a very small example on github. I have added some sed fixes to > > my Makefile make my sample program compile. > > https://github.com/masmullin2000/libbpf-sample/tree/main/c/simple > > > > https://github.com/masmullin2000/libbpf-sample/tree/02c7f945bf9027daedec04f485a320ba2df28204/c/simple > > contains broken code. > > You are missing -g when calling clang to generate debug info (DWARF > and subsequently BTF). When BPF object file doesn't have BTF, we don't > generate those bss/data/rodata/etc sections of the skeleton. You > should be good just by adding -g. > Thank you. By using -g, I am also unable to trigger the segfault I was trying to fix with the patch https://lore.kernel.org/bpf/20220523194917.igkgorco42537arb@jup/T/#u I am not sure if there would be other ways to trigger the segfault. > > > > I apologize if this is an incorrect way to share external code. I > > haven't found the proper way to share example code from > > kernelnewbies.org > > > > > > > > > i, ident); > > > > } > > > > i++; > > > > -- > > > > 2.36.1 > > > >