Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5445735rwl; Sun, 8 Jan 2023 15:30:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXuzuc8jI5QK2YqRXCpnSLe1+btqsQf1GDZsgFLAlDHazxFj7TkdUWmTDpUzNQRK0c+Bfn9p X-Received: by 2002:a17:906:2813:b0:7c0:f9ef:23a2 with SMTP id r19-20020a170906281300b007c0f9ef23a2mr67100016ejc.30.1673220646725; Sun, 08 Jan 2023 15:30:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673220646; cv=none; d=google.com; s=arc-20160816; b=uUwnQpZNlRYPkRB5qU/MEIpbMvUlxXDQLL0b97iOlMAH0hm17Igz9ZTXqzjM2FqQge DI6kgs8qhZYhZiqQsJNcxc9eO9n+SOWPqN1tcyMHWGmHxfldGLeICxlFkxUvGZR+6t5s 0ufX/R+oCYLoR4+eQdnQ/0wYArTsx2Igne+oGpLz1vQUDG32fXEl9n7fsmlT+pafB21N 4zPyhZ2d/NFPNhgCWKz+6rfSopFricsPHwKd3vZCYz5f14AM1OtcPqjoBsjcfncXXWeY 5/3SQe9kW1/2mxagiGqQx7oxZH+erjpbW5cOMFa1SCPFTjnKPmzqqJYQHxauiuIjWaAf tdOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=swAeOSxPoqd6eOEXYrgkE8zquyIImkg2oEpvR8IJQyA=; b=lqQpbKuKseN36dR7GkC1qgwkOr7Q2NuNuVhpuXaTwVqGxSDxwkHv1vnqNJolbps3fY nTzcskkImKAzEBJJ3kPZ8sIFVR/MC8ta5V2jSZllQPKOJDNoU/T7yKDYnt0xJm03LnBi HjwYENIIoOz1Q1f9ie6e0dZVS0UBUCsZ+zCUZeu21ucWqf49+gcTYS74ZDTAMhhGyuu2 /YaUNXz1Rom18umzuA5egALzEWiERyJk8+IF1CVprh5tUK/+71p0RbxLAn5HU37ds+H/ pbnI+9AwIZhjAYrPYr3bOTJftmSHkbOvITOXumte6DMB9srqD0VJAc+ErH9ADxG3C3xj HFwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ShrGtiNe; 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 hr42-20020a1709073faa00b0078de536a3cdsi8629742ejc.119.2023.01.08.15.30.34; Sun, 08 Jan 2023 15:30:46 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ShrGtiNe; 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 S232943AbjAHXSK (ORCPT + 52 others); Sun, 8 Jan 2023 18:18:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230431AbjAHXSH (ORCPT ); Sun, 8 Jan 2023 18:18:07 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD6F3C75E; Sun, 8 Jan 2023 15:18:06 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id gh17so16139639ejb.6; Sun, 08 Jan 2023 15:18:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=swAeOSxPoqd6eOEXYrgkE8zquyIImkg2oEpvR8IJQyA=; b=ShrGtiNep+6LyTsCgXKVo6KcvpUZqu4Hy3mDP+Ce3PcsNy798Z1x4EADEMk2ZfWP4h z/p3gUIHWKwYY1Plm4SejVbEXRyH/JaqL4DjX0+llaw/zYOq3RzrojWC63E/APqzKaaS rxJRq8QtNdmk/1pjoz2OJ6Kz6H3EQsjq0o6q2flaEDQejG3b1aDN32Mn1sWleQF6xm0T Gc+Q4BLWEl/r/FZ/vIYvQ9Yc0e9HxN/yESXsSz8oA7SzqvRVJJL/9qUR+m+NTHSTOLfE Fx2HlrfOskRcucNSHb/l/51MII4Z1E7gHAX3Z0/AaCWwOJATZxXhKJaUqNsT65IB9Ryp VxGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=swAeOSxPoqd6eOEXYrgkE8zquyIImkg2oEpvR8IJQyA=; b=jHrCsQtRX/WBTRKQ83DOiqfh1iT+mg7c2/O+wca1OhBweOr37CLU6HeiMFU3bE6TrM o+OL4971Ze91c4Ac0L14VBaLt5iRTUZma2Z+ROQfshwQHpgrJChuu4FLs7OVRUnmmdvs 6fKeHuL08icgmNiodA2SjxLkYHEwU26ww78FGHcIluTg2vuVo2trg1Ri/AQYmnnqctGn vFZ3k8cQh/UQXTYthjetq80SRtgqQmPtjnp6sJ7J6Bj4qDpNKzxl008EbgeL5UUjM7bE tznXVF8iIbYouFpXzGSh5vfF52+Gn/OX9oDazXl8ABg2jjZ+KGdCu3HuRo+EKsqXUsBR DrdQ== X-Gm-Message-State: AFqh2kr3frV1t9OG4HMYm5ZxtXrg7MNM97LTHKMCb3zEfTDIyGI68KQn AFmE6nHbavE732QpTGrsT9HJeUVXsAKgPIjkFzk= X-Received: by 2002:a17:907:3a97:b0:84d:3601:4910 with SMTP id fh23-20020a1709073a9700b0084d36014910mr252558ejc.633.1673219885266; Sun, 08 Jan 2023 15:18:05 -0800 (PST) MIME-Version: 1.0 References: <20230106195130.1216841-1-void@manifault.com> <20230106195130.1216841-2-void@manifault.com> In-Reply-To: From: Alexei Starovoitov Date: Sun, 8 Jan 2023 15:17:54 -0800 Message-ID: Subject: Re: [PATCH bpf-next 1/3] bpf: Add __bpf_kfunc tag for marking kernel functions as kfuncs To: David Vernet Cc: 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 Content-Type: text/plain; charset="UTF-8" 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 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 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 > Wdyt? I do like the idea of getting rid of those ugly __diag_push()'es. > And we could always go back to using a __bpf_kfunc macro if and when > compilers ever support using attributes to ignore warnings for specific > functions. > > > > > Also how about using bpf_kfunc on the same line ? > > Then 'git grep' will be easier. > > Sure, if we keep this approach I'll do this in v2.