From: "Jose E. Marchesi" <jose.marchesi@oracle.com>
To: Quentin Monnet <quentin@isovalent.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
James Hilliard <james.hilliard1@gmail.com>,
Yonghong Song <yhs@fb.com>, bpf <bpf@vger.kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Tom Rix <trix@redhat.com>, Networking <netdev@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
llvm@lists.linux.dev
Subject: Re: [PATCH v2] bpf/scripts: Generate GCC compatible helpers
Date: Tue, 12 Jul 2022 13:29:58 +0200 [thread overview]
Message-ID: <87r12q6021.fsf@oracle.com> (raw)
In-Reply-To: <a443a6f9-fd6f-d283-ce00-68d72b40539d@isovalent.com> (Quentin Monnet's message of "Tue, 12 Jul 2022 10:48:20 +0100")
> On 12/07/2022 05:40, Andrii Nakryiko wrote:
>> CC Quentin as well
>>
>> On Mon, Jul 11, 2022 at 5:11 PM James Hilliard
>> <james.hilliard1@gmail.com> wrote:
>>>
>>> On Mon, Jul 11, 2022 at 5:36 PM Yonghong Song <yhs@fb.com> wrote:
>>>>
>>>>
>>>>
>>>> On 7/6/22 10:28 AM, James Hilliard wrote:
>>>>> The current bpf_helper_defs.h helpers are llvm specific and don't work
>>>>> correctly with gcc.
>>>>>
>>>>> GCC appears to required kernel helper funcs to have the following
>>>>> attribute set: __attribute__((kernel_helper(NUM)))
>>>>>
>>>>> Generate gcc compatible headers based on the format in bpf-helpers.h.
>>>>>
>>>>> This adds conditional blocks for GCC while leaving clang codepaths
>>>>> unchanged, for example:
>>>>> #if __GNUC__ && !__clang__
>>>>> void *bpf_map_lookup_elem(void *map, const void *key)
>>>>> __attribute__((kernel_helper(1)));
>>>>> #else
>>>>> static void *(*bpf_map_lookup_elem)(void *map, const void *key) = (void *) 1;
>>>>> #endif
>>>>
>>>> It does look like that gcc kernel_helper attribute is better than
>>>> '(void *) 1' style. The original clang uses '(void *) 1' style is
>>>> just for simplicity.
>>>
>>> Isn't the original style going to be needed for backwards compatibility with
>>> older clang versions for a while?
>>
>> I'm curious, is there any added benefit to having this special
>> kernel_helper attribute vs what we did in Clang for a long time? Did
>> GCC do it just to be different and require workarounds like this or
>> there was some technical benefit to this?
>>
>> This duplication of definitions with #if for each one looks really
>> awful, IMO. I'd rather have a macro invocation like below (or
>> something along those lines) for each helper:
>>
>> BPF_HELPER_DEF(2, void *, bpf_map_update_elem, void *map, const void
>> *key, const void *value, __u64 flags);
>>
>> And then define BPF_HELPER_DEF() once based on whether it's Clang or GCC.
>
> Hi, for what it's worth I agree with Andrii, I would rather avoid the
> #if/else/endif and dual definition for each helper in the header, using
> a macro should keep it more readable indeed. The existing one
> (BPF_HELPER(return_type, name, args, id)) can likely be adapted.
>
> Also I note that contrarily to clang's helpers, you don't declare GCC's
> as "static" (although I'm not sure of the effect of declaring them
> static in this case).
That's because in the clang line bpf_map_lookup_elem is a static
variable, a pointer to a function type, initialized to 1.
On the other hand, in the GCC line bpf_map_lookup_elem is just a normal
function declaration. No variable, and thus no need for `static'.
>
> Thanks,
> Quentin
next prev parent reply other threads:[~2022-07-12 11:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-06 17:28 [PATCH v2] bpf/scripts: Generate GCC compatible helpers James Hilliard
2022-07-11 23:35 ` Yonghong Song
2022-07-12 0:11 ` James Hilliard
2022-07-12 4:40 ` Andrii Nakryiko
2022-07-12 9:48 ` Quentin Monnet
2022-07-12 11:29 ` Jose E. Marchesi [this message]
2022-07-12 23:29 ` James Hilliard
2022-07-12 11:19 ` Jose E. Marchesi
2022-07-12 16:48 ` Alexei Starovoitov
2022-07-13 1:10 ` James Hilliard
2022-07-13 1:18 ` Alexei Starovoitov
2022-07-13 1:29 ` James Hilliard
2022-07-13 1:44 ` Alexei Starovoitov
2022-07-13 2:56 ` James Hilliard
2022-07-13 4:25 ` Alexei Starovoitov
2022-07-13 5:25 ` James Hilliard
2022-08-27 11:03 ` James Hilliard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r12q6021.fsf@oracle.com \
--to=jose.marchesi@oracle.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=james.hilliard1@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=netdev@vger.kernel.org \
--cc=quentin@isovalent.com \
--cc=songliubraving@fb.com \
--cc=trix@redhat.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.