Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2312661rwn; Fri, 9 Sep 2022 11:35:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR4ZBbGh6VKXC8ozScnElWVnQJdec2HigwNt4eNHB2tmEj+960WmMyTC6E9l8Db1PQU5hwvE X-Received: by 2002:a17:906:4fc9:b0:76e:d46e:4419 with SMTP id i9-20020a1709064fc900b0076ed46e4419mr10423729ejw.610.1662748532152; Fri, 09 Sep 2022 11:35:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662748532; cv=none; d=google.com; s=arc-20160816; b=fwiAGicznL4e0b0qAGRC15hun9RRT+qZKT2gd4Rp4AcBRuo3X4bskvnlhz5KeT8zFA NKAOrep7NbBy/z5MMhLthQ9QCVrKdR43nPnDjHDRt70CXpRHNkgxofE+ITrJifivXCR/ q0j7+PA3fjS8ND9reCc9Ur5mGzQGay2tqnd3OvSgwtY1RifqQJmXg0gVwlVOrprfawXQ KxiENo7Qb7Y3sN0vZbM6icRj/UjBZeWthzxms1aISk4ZFpGCePtGTlMyJcyk6ZULGiMI 00qgxCltXChz1YYEjCqkaWIsLemqPdab4OT+kkNXtZk8ODwLVIL28vFYLRGnk17e1G+x DfAQ== 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=kdzvynSrjQXSxRcVhr0A6ulDTMYUYOd9fHLtb7whJ3k=; b=vtxi6pq//w2eOANNjZs57/87ywh8DuvhwFI4uGoRYhWyjmRp5CwoB/hYHOZrxarGHV WrBabrbWRS0wuqF9GzKPCt9ZecYzLVQgQmglYoRftArB5d9Svtv9RLOB4vvXvp5XSq3M BY7Mk2tajLhCIFnh7hEDTn5W3ZQqP0j8Wj03OeGMWqMehPBHMQatIq3VLV6FmFYggYMD cR/iqHnJFlAVZNL3KGN+tJXWeQ5ndPSEHnDdaPwEh3YHRRyxke7fqO/D2klm6llGFJn7 nNjvvDD00BEQyXY8G+HBqDvQFSWFOOAGwGhf9zKqLmLYZ9eQLBK3BsH/5WKbWYbef3db dmJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Yb5ALLke; 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 gs37-20020a1709072d2500b00770d9e664f8si1360086ejc.152.2022.09.09.11.35.02; Fri, 09 Sep 2022 11:35:32 -0700 (PDT) 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=Yb5ALLke; 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 S229546AbiIISXC (ORCPT + 99 others); Fri, 9 Sep 2022 14:23:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbiIISXA (ORCPT ); Fri, 9 Sep 2022 14:23:00 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0933DFDB91; Fri, 9 Sep 2022 11:23:00 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id t6-20020a17090a950600b0020063f8f964so6059478pjo.0; Fri, 09 Sep 2022 11:23:00 -0700 (PDT) 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; bh=kdzvynSrjQXSxRcVhr0A6ulDTMYUYOd9fHLtb7whJ3k=; b=Yb5ALLkeGadLMU/XGuRrx2Zgeuz9W6Me6MiC1B5JUv6cQ0hBtCV+JPH/8X/eq6oGz0 x0c2EYTRmmPsEuAGgaJs182HeJe7ky3QLRL2Agt5TsSa5KBDCq4Tw6rZVTI8lA+UFJiM Ag1zQUSVKLNwxCDGMOq9I7gMJsLFSvOAYpZ0MmxTKMePKCXS4s0T1WpGg8cnibHKzyue 4rBSORgGEFvpSUsouRfjgnM//HFpTxEoBDere4uIi2B2OHf0zz1g7xjjbnXr5XiDRFx9 pUIWmfGfzvNL5xjKpXUPtqefBDfD8K6Pydh9fBfTE0WW5Ygy7yciCP0+JAKFdF15TJ4F MPNg== 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; bh=kdzvynSrjQXSxRcVhr0A6ulDTMYUYOd9fHLtb7whJ3k=; b=KScgJhHt5+pI8Bd2hbSw4bAGlmREICEueQRNCrPE/qg3JdaYmHrGQcTFI5WXqnesbi FPFSiqkEaOp3wS3OTVtqxbBLV3y03rBdhck/qiMvW0Bc4f6014HUnLMhMMxJvOKbeBNe z5sHcFCU5UjLyce8mBIdJvSEe2PQuVOtjOYsu90D7P9HQ/8kKAy55QfeAsVZ2J4hw9hp KA8jLLhY2ENZl23Mt/Fy0aED7lfsVqaEjSylfeodRqgTlQ6fI1FWXi061x61k10MSpmQ BBLFkUa9mYkpv52gk/yGMC8lKX5Arcinitiu9RqT4cWpSy+rYTA4Ec/zhSm4bREs7GvF +FfQ== X-Gm-Message-State: ACgBeo1g4Fny7oW8Jy0WM8/FFNBT/9D3I0eZZJa8f4PxMvyHPNhmQNXo wyaonuirqZRXRBfaZ3QNco/1afnGxz207hLCSg0gGM/g9wR/SQ== X-Received: by 2002:a17:90b:4acc:b0:1f5:7f05:12e8 with SMTP id mh12-20020a17090b4acc00b001f57f0512e8mr10702485pjb.92.1662747779460; Fri, 09 Sep 2022 11:22:59 -0700 (PDT) MIME-Version: 1.0 References: <20220829210546.755377-1-james.hilliard1@gmail.com> In-Reply-To: From: James Hilliard Date: Fri, 9 Sep 2022 12:22:47 -0600 Message-ID: Subject: Re: [PATCH v2] libbpf: add GCC support for bpf_tail_call_static To: Andrii Nakryiko , "Jose E. Marchesi" , "Jose E. Marchesi" , David Faust Cc: bpf@vger.kernel.org, Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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, Sep 9, 2022 at 12:05 PM Andrii Nakryiko wrote: > > On Mon, Aug 29, 2022 at 2:05 PM James Hilliard > wrote: > > > > The bpf_tail_call_static function is currently not defined unless > > using clang >= 8. > > > > To support bpf_tail_call_static on GCC we can check if __clang__ is > > not defined to enable bpf_tail_call_static. > > > > We need to use GCC assembly syntax when the compiler does not define > > __clang__ as LLVM inline assembly is not fully compatible with GCC. > > > > Signed-off-by: James Hilliard > > --- > > Changes v1 -> v2: > > - drop __BPF__ check as GCC now defines __bpf__ > > --- > > tools/lib/bpf/bpf_helpers.h | 19 +++++++++++++------ > > 1 file changed, 13 insertions(+), 6 deletions(-) > > > > diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h > > index 7349b16b8e2f..867b734839dd 100644 > > --- a/tools/lib/bpf/bpf_helpers.h > > +++ b/tools/lib/bpf/bpf_helpers.h > > @@ -131,7 +131,7 @@ > > /* > > * Helper function to perform a tail call with a constant/immediate map slot. > > */ > > -#if __clang_major__ >= 8 && defined(__bpf__) > > +#if (!defined(__clang__) || __clang_major__ >= 8) && defined(__bpf__) > > static __always_inline void > > bpf_tail_call_static(void *ctx, const void *map, const __u32 slot) > > { > > @@ -139,8 +139,8 @@ bpf_tail_call_static(void *ctx, const void *map, const __u32 slot) > > __bpf_unreachable(); > > > > /* > > - * Provide a hard guarantee that LLVM won't optimize setting r2 (map > > - * pointer) and r3 (constant map index) from _different paths_ ending > > + * Provide a hard guarantee that the compiler won't optimize setting r2 > > + * (map pointer) and r3 (constant map index) from _different paths_ ending > > * up at the _same_ call insn as otherwise we won't be able to use the > > * jmpq/nopl retpoline-free patching by the x86-64 JIT in the kernel > > * given they mismatch. See also d2e4c1e6c294 ("bpf: Constant map key > > @@ -148,12 +148,19 @@ bpf_tail_call_static(void *ctx, const void *map, const __u32 slot) > > * > > * Note on clobber list: we need to stay in-line with BPF calling > > * convention, so even if we don't end up using r0, r4, r5, we need > > - * to mark them as clobber so that LLVM doesn't end up using them > > - * before / after the call. > > + * to mark them as clobber so that the compiler doesn't end up using > > + * them before / after the call. > > */ > > - asm volatile("r1 = %[ctx]\n\t" > > + asm volatile( > > +#ifdef __clang__ > > + "r1 = %[ctx]\n\t" > > "r2 = %[map]\n\t" > > "r3 = %[slot]\n\t" > > +#else > > + "mov %%r1,%[ctx]\n\t" > > + "mov %%r2,%[map]\n\t" > > + "mov %%r3,%[slot]\n\t" > > +#endif > > Hey James, > > I don't think it's a good idea to have a completely different BPF asm > syntax in GCC-BPF vs what Clang is supporting. Note that Clang syntax > is also what BPF users see in BPF verifier log and in llvm-objdump > output, so that's what BPF users are familiar with. Is the difference a BPF specific assembly format deviation or a generic deviation in assembler template syntax between GCC/llvm? https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#AssemblerTemplate > > This will cause constant and unavoidable maintenance burden both for > libraries like libbpf and end users and their BPF apps as well. > > Given you are trying to make GCC-BPF part of the BPF ecosystem, please > think about how to help the ecosystem, move it forward and unify it, > not how to branch out and have Clang vs GCC differences everywhere. > There is a lot of embedded BPF asm in production applications, having > to write something as trivial as `r1 = X` in GCC or Clang-specific > ways is a huge burden. > > As such, we've reverted your patch ([0]). Please add de facto BPF asm > syntax support to GCC-BPF and this change won't be necessary. > > [0] https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=665f5d3577ef43e929d59cf39683037887c351bf > > > "call 12" > > :: [ctx]"r"(ctx), [map]"r"(map), [slot]"i"(slot) > > : "r0", "r1", "r2", "r3", "r4", "r5"); > > -- > > 2.34.1 > >