Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F298C25B50 for ; Mon, 23 Jan 2023 19:05:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231753AbjAWTFG (ORCPT ); Mon, 23 Jan 2023 14:05:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231501AbjAWTFD (ORCPT ); Mon, 23 Jan 2023 14:05:03 -0500 Received: from www62.your-server.de (www62.your-server.de [213.133.104.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69372658F; Mon, 23 Jan 2023 11:05:02 -0800 (PST) Received: from sslproxy02.your-server.de ([78.47.166.47]) by www62.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pK27m-00070k-O9; Mon, 23 Jan 2023 20:04:59 +0100 Received: from [85.1.206.226] (helo=linux.home) by sslproxy02.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pK27m-000ON9-8v; Mon, 23 Jan 2023 20:04:58 +0100 Subject: Re: [PATCH bpf-next v2 3/3] bpf: Use BPF_KFUNC macro at all kfunc definitions To: Alexei Starovoitov , David Vernet Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@meta.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, memxor@gmail.com References: <20230123171506.71995-1-void@manifault.com> <20230123171506.71995-4-void@manifault.com> <20230123183305.2mgoxgw4ca3sfk24@macbook-pro-6.dhcp.thefacebook.com> <20230123185434.ybfhrmbootcnjuoj@macbook-pro-6.dhcp.thefacebook.com> From: Daniel Borkmann Message-ID: Date: Mon, 23 Jan 2023 20:04:57 +0100 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: <20230123185434.ybfhrmbootcnjuoj@macbook-pro-6.dhcp.thefacebook.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.103.7/26790/Mon Jan 23 09:31:32 2023) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/23/23 7:54 PM, Alexei Starovoitov wrote: > On Mon, Jan 23, 2023 at 12:48:27PM -0600, David Vernet wrote: >> On Mon, Jan 23, 2023 at 10:33:05AM -0800, Alexei Starovoitov wrote: >>> On Mon, Jan 23, 2023 at 11:15:06AM -0600, David Vernet wrote: >>>> -void *bpf_obj_new_impl(u64 local_type_id__k, void *meta__ign) >>>> +BPF_KFUNC(void *bpf_obj_new_impl(u64 local_type_id__k, void *meta__ign)) >>>> { >>>> struct btf_struct_meta *meta = meta__ign; >>>> u64 size = local_type_id__k; >>>> @@ -1790,7 +1786,7 @@ void *bpf_obj_new_impl(u64 local_type_id__k, void *meta__ign) >>>> return p; >>>> } >>>> >>>> -void bpf_obj_drop_impl(void *p__alloc, void *meta__ign) >>>> +BPF_KFUNC(void bpf_obj_drop_impl(void *p__alloc, void *meta__ign)) >>>> { >>> >>> The following also works: >>> -BPF_KFUNC(void *bpf_obj_new_impl(u64 local_type_id__k, void *meta__ign)) >>> +BPF_KFUNC( >>> +void *bpf_obj_new_impl(u64 local_type_id__k, void *meta__ign) >>> +) >>> >>> and it looks little bit cleaner to me. >>> >>> git grep -A1 BPF_KFUNC >>> can still find all instances of kfuncs. >>> >>> wdyt? >> >> I'm fine with putting it on its own line if that's your preference. >> Agreed that it might be a bit cleaner, especially for functions with the >> return type on its own line, so we'd have e.g.: >> >> BPF_KFUNC( >> struct nf_conn * >> bpf_skb_ct_lookup(struct __sk_buff *skb_ctx, struct bpf_sock_tuple *bpf_tuple, >> u32 tuple__sz, struct bpf_ct_opts *opts, u32 opts__sz) > > Yeah. Especially for those. > >> ) { >> >> // ... >> >> } >> >> Note the presence of the { on the closing paren. Are you ok with that? >> Otherwise I think it will look a bit odd: > > Yep. Good idea. Either ){ or ) { look good to me. > >> BPF_KFUNC( >> struct nf_conn * >> bpf_skb_ct_lookup(struct __sk_buff *skb_ctx, struct bpf_sock_tuple *bpf_tuple, >> u32 tuple__sz, struct bpf_ct_opts *opts, u32 opts__sz) >> ) >> { >> >> } Did you look into making this similar to the EXPORT_SYMBOL() infra? If possible that would look much more natural to developers, e.g. : struct nf_conn * bpf_skb_ct_lookup(struct __sk_buff *skb_ctx, struct bpf_sock_tuple *bpf_tuple, u32 tuple__sz, struct bpf_ct_opts *opts, u32 opts__sz) { [...] } EXPORT_BPF_KFUNC(bpf_skb_ct_lookup);