Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6516286rwl; Mon, 9 Jan 2023 09:16:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXtK1z+u4Zr4ININhuo4hX9eoMsbZ4FBESQD8RMSK5BcCe21sEjZ5VeNpp7UaYdxW1cvps0y X-Received: by 2002:a17:907:6026:b0:84d:445b:8aa6 with SMTP id fs38-20020a170907602600b0084d445b8aa6mr3860099ejc.70.1673284581813; Mon, 09 Jan 2023 09:16:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673284581; cv=none; d=google.com; s=arc-20160816; b=nSS+VlicYz+ugBSvkl3wGKQjgmnDng16frcHYg3viYpT5SZViUETdpiFbfcQJFDDep EidqmGBqgzV63ZWm9JUtH22uol1dF1SLxE774PR+6QGBD8zaOr/R9aIjbvFwUXGGVr4/ MJQsR+Ar0jIi1S9xKeYwV+w4NDylaiYnSyVQHpu5A1Q2Ek6xxjWiu5KtCzps+oXDHA/1 bzCl75WB9qZgs8dJftlRXT+cgEPFrkqj1yJMfiT83RHjZg3vHJbFYOMzlUw4uEOJcI8Z QV9EuDwQ58OWOvMB056UEvkS8xibGPErGyGyfThValcsv5wpaPoIa0h46MhK4pi4hnMc Z8IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=zPVCpbi7IFUjfl+kqKF1GBf38n57/rlv+lygUdA5yNk=; b=JPyquwMEizkAwW1W1fyBLCWh/Z37bEvbkeTYL/OD41GvLGiSzSYkRq+zkEVgvdPuOj gqnyefnmEMB7kGolOGQoKGODWU393JIxrSNdfD/BbrjAKJ2/u0EqD48flUYA8bwGW1OK a1bADKkw2qI0/CJhG/6WhVAuUc2YQRoHON5N9ImTyKpY06CK0k42u1kgJbxOpgvWbzWf NnuF4tvAhdHYK3WWoea4EfrSlmoxKErT5OyS4rqRpsXQ2EVGcvCUk3/r160yt0X1dx/a KT1lbDqFtwmAkeNBmoulFuODAK529Cj9W7gCUIQuk57UlC4/ebkuP5+VbjzgtC0FGEpT kItA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt33-20020a1709072da100b007c151fc73d0si11764492ejc.653.2023.01.09.09.16.01; Mon, 09 Jan 2023 09:16:21 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237287AbjAIRHR (ORCPT + 53 others); Mon, 9 Jan 2023 12:07:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234827AbjAIRG1 (ORCPT ); Mon, 9 Jan 2023 12:06:27 -0500 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1D0142E21; Mon, 9 Jan 2023 09:05:44 -0800 (PST) Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-4c186ff0506so121373537b3.6; Mon, 09 Jan 2023 09:05:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zPVCpbi7IFUjfl+kqKF1GBf38n57/rlv+lygUdA5yNk=; b=C6sdNlPKP8IVlDrgemUvnEB8JOAhcPneEchpbYmapkPi9Sv5JE4M2uEc66dXNCr3EC LDulgFnacU5lW2hGmxy1S6PdSELbF4cVP26FPGm8ga3xK8B8W6V/rylU+epqi2DTNBna X+Hb2DVzevjcALkHNcikM9H0X9XSzl8/1Ip8oPjwVbd/t8513U2xzq6J+Frlo3w+sw+U UidYWO7Re0E+Up7/2RTfzPRCFBHL27MCYEV8Dopr5HQlUGd8vHNLWjpHINxX7jUUnrO/ KyCYwczlLSItwe2KhSb5IHvbEWmsdAvF3BDBIeHQBLdeaWSJS25GeCubnfVaGCIfXRwU Bo6w== X-Gm-Message-State: AFqh2kpzl+AdAZwTtPIJD/jFToNrrRCZFviaWozWSbaiQ4n71m6o31DZ HpyA9UILLFVFqs8OuIaNNdc= X-Received: by 2002:a05:7500:338a:b0:f0:3bdd:b78f with SMTP id cr10-20020a057500338a00b000f03bddb78fmr446307gab.4.1673283943376; Mon, 09 Jan 2023 09:05:43 -0800 (PST) Received: from maniforge.lan ([2620:10d:c091:480::1:40cc]) by smtp.gmail.com with ESMTPSA id bq35-20020a05620a46a300b00704c9015e68sm5656045qkb.116.2023.01.09.09.05.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 09:05:42 -0800 (PST) Date: Mon, 9 Jan 2023 11:05:42 -0600 From: David Vernet To: Kumar Kartikeya Dwivedi Cc: Alexei Starovoitov , bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , LKML , Kernel Team Subject: Re: [PATCH bpf-next 1/3] bpf: Add __bpf_kfunc tag for marking kernel functions as kfuncs Message-ID: References: <20230106195130.1216841-1-void@manifault.com> <20230106195130.1216841-2-void@manifault.com> <20230109120815.zx5mif4hnee6gyvc@apollo> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230109120815.zx5mif4hnee6gyvc@apollo> User-Agent: Mutt/2.2.9 (2022-11-12) X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no 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, Jan 09, 2023 at 05:38:15PM +0530, Kumar Kartikeya Dwivedi wrote: > On Mon, Jan 09, 2023 at 04:47:54AM IST, Alexei Starovoitov wrote: > > On Fri, Jan 6, 2023 at 6:09 PM David Vernet wrote: > > > > > > On Fri, Jan 06, 2023 at 05:04:02PM -0800, Alexei Starovoitov wrote: > > > > On Fri, Jan 6, 2023 at 11:51 AM David Vernet wrote: > > > > > > > > > > kfuncs are functions defined in the kernel, which may be invoked by BPF > > > > > programs. They may or may not also be used as regular kernel functions, > > > > > implying that they may be static (in which case the compiler could e.g. > > > > > inline it away), or it could have external linkage, but potentially be > > > > > elided in an LTO build if a function is observed to never be used, and > > > > > is stripped from the final kernel binary. > > > > > > > > > > We therefore require some convenience macro that kfunc developers can > > > > > use just add to their kfuncs, and which will prevent all of the above > > > > > issues from happening. This is in contrast with what we have today, > > > > > where some kfunc definitions have "noinline", some have "__used", and > > > > > others are static and have neither. > > > > > > > > > > In addition to providing the obvious correctness benefits, having such a > > > > > macro / tag also provides the following advantages: > > > > > > > > > > - Giving an easy and intuitive thing to query for if people are looking > > > > > for kfuncs, as Christoph suggested at the kernel maintainers summit > > > > > (https://lwn.net/Articles/908464/). This is currently possible by > > > > > grepping for BTF_ID_FLAGS(func, but having something more self > > > > > describing would be useful as well. > > > > > > > > > > - In the future, the tag can be expanded with other useful things such > > > > > as the ability to suppress -Wmissing-prototype for the kfuncs rather > > > > > than requiring developers to surround the kfunc with __diags to > > > > > suppress the warning (this requires compiler support that as far as I > > > > > know currently does not exist). > > > > > > > > Have you considered doing bpf_kfunc_start/bpf_kfunc_end ? > > > > The former would include: > > > > __diag_push(); __diag_ignore_all(); __used noinline > > > > > > Yeah that's certainly an option. The downside is that all functions > > > within scope of the __diag_push() will be affected, and sometimes we mix > > > kfuncs with non-kfuncs (including e.g. static helper functions that are > > > used by the kfuncs themselves). -Wmissing-prototypes isn't a big deal, > > > but __used and noinline are kind of unfortunate. Not a big deal though, > > > it'll just result in a few extra __bpf_kfuncs_start() and > > > __bpf_kfuncs_end() sprinkled throughout to avoid them being included. > > > The upside is of course that we can get rid of the __diag_push()'es we > > > currently have to prevent -Wmissing-prototypes. > > > > I meant to use bpf_kfunc_start/bpf_kfunc_end around every kfunc. > > Ideally bpf_kfunc_start would be on the same line as func proto > > for nice grepping. > > Maybe it's an overkill. > > Maybe 3 macroses then? > > bpf_kfunc_start to hide __diag > > bpf_kfunc on the proto line > > bpf_kfunc_end to finish __diag_pop Ah, I see. Hmm, I guess this is better than what we have now, but is still a lot of macros and boilerplate which IMO is a sign we're not going in quite the right direction. I don't really have a better suggestion at this point, though I do like Kumar's suggestion below. > There's also the option of doing this: > > #define BPF_KFUNC(proto) proto; __used noinline proto > > BPF_KFUNC(void kfunc(arg1, arg2)) { > ... > } > > No need to disable the warning with diag push/pop, just put a declaration before > the definition to silence the compiler. The only awkward part is entire function > prototype becoming a macro argument (unlike the common case void MACRO(...)) but > it becomes less noisy and easy to grep as well. If nobody would come after us with pitchforks for this, IMO this is the most user-friendly option and what I would vote for. It doesn't seem like this is violating anything in [0]? [0]: https://www.kernel.org/doc/html/latest/process/coding-style.html#macros-enums-and-rtl