Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B02D7A for ; Tue, 12 Jul 2022 09:48:23 +0000 (UTC) Received: by mail-wr1-f47.google.com with SMTP id a5so10370257wrx.12 for ; Tue, 12 Jul 2022 02:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=WcPIJHWyToGVlIzDYOdfUB4mbv1ws7QerB6L3JMPYZ0=; b=qTn9s6H2hO+MfqMpLno3oo6tu+sKBx1LyvIZ9q4T2q6toceAyIopXU8BLiLSSJh8Y5 gOMGN/tva7VtKfi/E7zxIfu4EygB4KXSzlahhUZABzcp0mb8n22EtrxNnN2uhka+jt3F jM7yPbQN2NxmfGSx3Zu+dILeI4CqzzLaJYElYWrxe9g/4rWz4fFvP6zYieOJNN1aUE0B KtcyVselTQRu9d1tyguKxAQcYRrhkv0zB4zefB0/vdgeqLAqu+U4hiqadhnGm6thgaYC hSBVL+vaVO61bTPDOqmObpLN88sGQJxNa8oHy271N7jyFymCls6oJoecMFJUm1XLOrLW PNoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=WcPIJHWyToGVlIzDYOdfUB4mbv1ws7QerB6L3JMPYZ0=; b=z5+4yM9jqSzJS7pAVR5H4EZYBhulyGi5IXQtRax5rTlU2sSDKS28xg8bZkbk4VshYa m+HIbUK86P8COShkF1WbS4/YrWHqteGMzQ/fgVpD/WLzygHVbax5CGF4p5LAJxvCPe0B A23Fxr8xumKAkx0etnjd5I5xYUEg/M1OXooVWzcXfl/uhexsntUh+Lq5ov1D7X6YtJb9 gskfDwo3goYE2BFwFmAdUI4txLjJmB876R3OY4I4KsR1ymFG7KFy/HwjUN8Pg69Va6BY 4gtfmVw7bqCaygul91XW2PAQ5+/+PvkfMoMj383VmvJT6tnowKQHbVuJ2G+DiFTVEJGd lK1Q== X-Gm-Message-State: AJIora8VvEzoHNifUHmpGUhvBeIfu2IIpqpE8WYahsJxmFgsNxGj65pJ SWO0DQG1u1hOGTgjNRyTOd8D6A== X-Google-Smtp-Source: AGRyM1t8KGr5XoQft8lPqDZI8l7AxfbF/t6JDU+4e6F9ndr5oYREAwYjj1hvJgKWw4r5YUmX41ahuA== X-Received: by 2002:a5d:6d49:0:b0:21b:a3ba:30b5 with SMTP id k9-20020a5d6d49000000b0021ba3ba30b5mr21773949wri.513.1657619301745; Tue, 12 Jul 2022 02:48:21 -0700 (PDT) Received: from [192.168.178.32] ([51.155.200.13]) by smtp.gmail.com with ESMTPSA id n68-20020a1c2747000000b0039c96b97359sm9024370wmn.37.2022.07.12.02.48.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Jul 2022 02:48:21 -0700 (PDT) Message-ID: Date: Tue, 12 Jul 2022 10:48:20 +0100 Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.0.1 Subject: Re: [PATCH v2] bpf/scripts: Generate GCC compatible helpers Content-Language: en-GB To: Andrii Nakryiko , James Hilliard Cc: Yonghong Song , bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Nathan Chancellor , Nick Desaulniers , Tom Rix , Networking , Linux Kernel Mailing List , llvm@lists.linux.dev References: <20220706172814.169274-1-james.hilliard1@gmail.com> From: Quentin Monnet In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/07/2022 05:40, Andrii Nakryiko wrote: > CC Quentin as well > > On Mon, Jul 11, 2022 at 5:11 PM James Hilliard > wrote: >> >> On Mon, Jul 11, 2022 at 5:36 PM Yonghong Song 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). Thanks, Quentin