Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2305293lqo; Mon, 13 May 2024 14:15:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVEGQ9HOearfl9q4L4UU7+TGT6WEYuq+EjSHcbkK9XHcJUoStPd3Quhut8u41gRjplQSnL6qMWxpoLZBs+FiAw5o4kIrDCrZrnSFsVKZQ== X-Google-Smtp-Source: AGHT+IE1bcS3IbBhtkI9iYzqiw9HYqlbLROLy7sxz8Wx7PxZ0NxU42JEiW5nnPZRNqeFjbqXqiuL X-Received: by 2002:a05:6122:31a1:b0:4df:220c:45ee with SMTP id 71dfb90a1353d-4df8828011amr8174359e0c.3.1715634899656; Mon, 13 May 2024 14:14:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715634899; cv=pass; d=google.com; s=arc-20160816; b=y8+zB3Ogr0c/o0uQBDsCSp8T1MBCTFngE1PPFEFCu/zQUjlNW2stCBqqulH4mZfBjq NTw4NJVw9Jz4Ef8mQSTIXV/70Ng+jHeyZYD7MZFRXBM9aUEzSc0AWZkQ1SD9huNVM2Du ZJztD9Uq7cDFOX/8PsyaLjrhsov2ReKnS0NUGe+TyhdEQxn04wy1QOLqf4aZog1S2JeM KugYN7w3NUcWGOSrguQlDd4bJ+vNHOJ5jMO3+lmHYZuwD823TM303IQsTBbfmO1uesNc mavMfi1x4eZ+pFqz+/exQHEQ7IKnu7/GxX+RN6WEuxZvjkxR6GFiUsL42qfcTvrg5/PI 5/Vg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature:dkim-signature; bh=5jWB6u8tA+i7tSP2QC8w163S31C7XhqcLLTbhhZxvX4=; fh=J4Lg7HLK3bIhu0ApxXmWRaC67/6yJsU2a/Rru+3ERus=; b=pdWI3Vo7SVMyxvq9wKfZzpxJdoeldU807SJ6ppmvqo1La6qcDdmAj2g4iyS8aAfPSV RqTyxOMTDHRH24uWi5yF264F79JIWRn2ZWuM5IrFndwo6uJiOCRmZuFW3reMwdIQ0soe D9rZhVQMjfJ2xTzmJnOZyKTyg4Gv6w4bxkI2qFSbC1vnXgyq9c84BuVpUWI6mF+KC05p nuDUvR+Ae1Guq6XntNT0lPmsfjBJBprWyTI9ysmb/NGOpGwBHtzBT6jGhIFJwN/Y4SOt uMUMudgtlO7H8yQYg1upxAIqQx3ep3nYtDKigvMT2pg8cjEUhOmGTdAkQMEFmRN/gXr7 IHrA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm2 header.b=C3HRbjhI; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=RBirZnE3; arc=pass (i=1 spf=pass spfdomain=dxuuu.xyz dkim=pass dkdomain=dxuuu.xyz dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-178098-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178098-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-792bf38d7b1si1161608485a.710.2024.05.13.14.14.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 14:14:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178098-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm2 header.b=C3HRbjhI; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=RBirZnE3; arc=pass (i=1 spf=pass spfdomain=dxuuu.xyz dkim=pass dkdomain=dxuuu.xyz dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-178098-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178098-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 541241C22CF2 for ; Mon, 13 May 2024 21:14:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB48D8286D; Mon, 13 May 2024 21:14:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="C3HRbjhI"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RBirZnE3" Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B69971DA24; Mon, 13 May 2024 21:14:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715634891; cv=none; b=IXgxVQ1CYJl7yh8iGTi+yV2dZ9E0XKYKw+gSHW+kOEZPdOyv4Z1agl5E46xKTJmqdFQNa760xkBJ1GF4Ofw+M84P5VZ41JvktEBKSyJXAjWs15feEgjoPzG01pRAQ9H9pv5ZoV7VAbkalKas05pbMJjgLthfKLj+MjMCaKUIUrw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715634891; c=relaxed/simple; bh=3RU14hPBRJi9AV9s+50eZOV1ETZIQyBxt+R/qp8IzRE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gsRQqrfE4FQWzXeaWC7bLbdr5cqsZ3DvMGitetcPLD2CTQD/1tUq6zdji2j0D++cI+kLWWNHFCrzXRGNg9d2RPrrpg4VpWh2vIeR+jJK7tQ3Ry26yAOjp2WmOyXm6DjqoRrk+VXzjXr3eOVdKVH4cko2agoGqbsoNDQSuB62uK4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=C3HRbjhI; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RBirZnE3; arc=none smtp.client-ip=64.147.123.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id B62D61800165; Mon, 13 May 2024 17:14:47 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 13 May 2024 17:14:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1715634887; x=1715721287; bh=5jWB6u8tA+ i7tSP2QC8w163S31C7XhqcLLTbhhZxvX4=; b=C3HRbjhI8qJH4OYIqx1gxKnweB qPkVDutbLoTXx1orYCjAYNJL8jyMa6P8zr8Z5GPIQRNvQh8o76GuXgIULFWSFpyg JUCOIcFlQSmLtP/OcUkSAIwVooEmRTSyDXYVHuBJp+HOK6IDnFp/ukTWD5oTawJm 3zJApPi88xNmmYwSEsW0JXujV02B66me109zyNbrG1VViSM6RqwXKAESJnFRy8m1 IkikurFuPFrYHlPe30s5H2CMylBb1+x/5Ws9W6TRROektZZ9cWh4Oz0nyyrvCUwH WV88dSZdPc88h6gtO+SxobdvvksX9hF9KLsn5HtzQuw25W97AGqwdBpVtSTw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715634887; x=1715721287; bh=5jWB6u8tA+i7tSP2QC8w163S31C7 XhqcLLTbhhZxvX4=; b=RBirZnE3wJBSizEubcQhyFS/hGUmLA+N/h73t4J3wOsu X2fP2OVVXgbe+7MA0kw0ye8XXRkonyRCxP86X6CQGN6mRhEhqS+fI6cTIQP7B8zM +kh2qT+h4JkLyjGQ6shtG7wGCwbJj6hlHUvGB81eW2RAPLFoFUw3EjsGgixDFm3h UqiyL7bwTYw2YFWh2o7eit4w37BBw5AfIQSa3XIBb2ObsYfrcQrMhp853x3yrJMx nPHBk9GIHznfw4YitrnuXmY14X0roH2YZsR0WmMl1bEvu5Znj1w59isBX638P9jl eQZXQUAtCSij5yxHIve94rBe4T1wl9zw/mtr4pb2vw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgudehjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhepff fhvfevuffkfhggtggujgesthdtsfdttddtvdenucfhrhhomhepffgrnhhivghlucgiuhcu oegugihusegugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpedvfeekteduudefie egtdehfeffkeeuudekheduffduffffgfegiedttefgvdfhvdenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 17:14:45 -0400 (EDT) Date: Mon, 13 May 2024 15:14:44 -0600 From: Daniel Xu To: ast@kernel.org, daniel@iogearbox.net, qmo@kernel.org, andrii@kernel.org, olsajiri@gmail.com, quentin@isovalent.com, alan.maguire@oracle.com, acme@kernel.org, eddyz87@gmail.com Cc: martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: Re: [PATCH bpf-next v3 2/2] bpftool: Support dumping kfunc prototypes from BTF Message-ID: References: <6b16417c2c05019e83e420240c6d9796f9324a6c.1715625447.git.dxu@dxuuu.xyz> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6b16417c2c05019e83e420240c6d9796f9324a6c.1715625447.git.dxu@dxuuu.xyz> On Mon, May 13, 2024 at 12:38:59PM GMT, Daniel Xu wrote: > This patch enables dumping kfunc prototypes from bpftool. This is useful > b/c with this patch, end users will no longer have to manually define > kfunc prototypes. For the kernel tree, this also means we can optionally > drop kfunc prototypes from: > > tools/testing/selftests/bpf/bpf_kfuncs.h > tools/testing/selftests/bpf/bpf_experimental.h > > Example usage: > > $ make PAHOLE=/home/dxu/dev/pahole/build/pahole -j30 vmlinux > > $ ./tools/bpf/bpftool/bpftool btf dump file ./vmlinux format c | rg "__ksym;" | head -3 > extern void cgroup_rstat_updated(struct cgroup *cgrp, int cpu) __weak __ksym; > extern void cgroup_rstat_flush(struct cgroup *cgrp) __weak __ksym; > extern struct bpf_key *bpf_lookup_user_key(u32 serial, u64 flags) __weak __ksym; > > Signed-off-by: Daniel Xu > --- > tools/bpf/bpftool/btf.c | 54 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 54 insertions(+) > > diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c > index 91fcb75babe3..884af6589f0d 100644 > --- a/tools/bpf/bpftool/btf.c > +++ b/tools/bpf/bpftool/btf.c > @@ -20,6 +20,8 @@ > #include "json_writer.h" > #include "main.h" > > +#define KFUNC_DECL_TAG "bpf_kfunc" > + > static const char * const btf_kind_str[NR_BTF_KINDS] = { > [BTF_KIND_UNKN] = "UNKNOWN", > [BTF_KIND_INT] = "INT", > @@ -454,6 +456,48 @@ static int dump_btf_raw(const struct btf *btf, > return 0; > } > > +static int dump_btf_kfuncs(struct btf_dump *d, const struct btf *btf) > +{ > + LIBBPF_OPTS(btf_dump_emit_type_decl_opts, opts); > + int cnt = btf__type_cnt(btf); > + int i; > + > + printf("\n/* BPF kfuncs */\n"); > + > + for (i = 1; i < cnt; i++) { > + const struct btf_type *t = btf__type_by_id(btf, i); > + const char *name; > + int err; > + > + if (!btf_is_decl_tag(t)) > + continue; > + > + if (btf_decl_tag(t)->component_idx != -1) > + continue; > + > + name = btf__name_by_offset(btf, t->name_off); > + if (strncmp(name, KFUNC_DECL_TAG, sizeof(KFUNC_DECL_TAG))) > + continue; > + > + t = btf__type_by_id(btf, t->type); > + if (!btf_is_func(t)) > + continue; > + > + printf("extern "); > + > + opts.field_name = btf__name_by_offset(btf, t->name_off); > + err = btf_dump__emit_type_decl(d, t->type, &opts); > + if (err) > + return err; > + > + printf(" __weak __ksym;\n"); > + } > + > + printf("\n"); > + > + return 0; > +} > + > static void __printf(2, 0) btf_dump_printf(void *ctx, > const char *fmt, va_list args) > { > @@ -476,6 +520,12 @@ static int dump_btf_c(const struct btf *btf, > printf("#ifndef BPF_NO_PRESERVE_ACCESS_INDEX\n"); > printf("#pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)\n"); > printf("#endif\n\n"); > + printf("#ifndef __ksym\n"); > + printf("#define __ksym __attribute__((section(\".ksyms\")))\n"); > + printf("#endif\n\n"); > + printf("#ifndef __weak\n"); > + printf("#define __weak __attribute__((weak))\n"); > + printf("#endif\n\n"); > > if (root_type_cnt) { > for (i = 0; i < root_type_cnt; i++) { > @@ -491,6 +541,10 @@ static int dump_btf_c(const struct btf *btf, > if (err) > goto done; > } > + > + err = dump_btf_kfuncs(d, btf); > + if (err) > + goto done; > } > > printf("#ifndef BPF_NO_PRESERVE_ACCESS_INDEX\n"); > -- > 2.44.0 > > Oh, looks like selftests fail to build. I will fix that for v4.