Received: by 2002:a05:622a:1442:b0:3a5:28ea:c4b9 with SMTP id v2csp837358qtx; Mon, 31 Oct 2022 15:21:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Lt8VegNlFWrbEmO696cglRIFrn2KYeC1xa/E/PmL61GWjkWsZ1zwL2nS1eaBsGaT4/061 X-Received: by 2002:a17:906:6a13:b0:7ad:b598:9a52 with SMTP id qw19-20020a1709066a1300b007adb5989a52mr13395711ejc.205.1667254865293; Mon, 31 Oct 2022 15:21:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667254865; cv=none; d=google.com; s=arc-20160816; b=DkYlHZz4hTE5wg3UqoO4FyhuC0QS5pCexK4HhJ221LXgeAJbN0HCPwqCft/lqoO9Mm cR7UViMTQ+iYC5GQRGEblwTmUs5yhP8insdC0EuwMzp8Y83A0/qwTdKntcjqY/zyqUmI gNZZhJSdrW5BMI6NOV6R3Lsfu1vdXse9y1aePozLxZEfkSiogJwHX340zqTvKIVnXnUa z38JmWUqiEdRo8uIzjHQq0NqtbMNBg2V0pjBZ0d5kR2NlPIOnkg4QAGGGM3J4eX95Vtd mnB5dtGhmMeZUErIIyB1PrtDOQmPGKIsJC7jST4CKV5rSYgq+yFFeosNoLO/QclmaCEu m+hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=zdYNF6EUojfs0G57LtoPct7Uq38+dK+sU9/t/CK1zr8=; b=uGxtx3i+8QFpWTlbeKnlDfMXt0KNAbeFENb261AwfDD22nRrrGY1Foo1gh1DlPpR75 QA3YsJ40jeD/HEcKddh2sJUzspucR6Wk6muV0OL6gyO7H0z+P2AnLeF1gFn6cSLrq7zM Py0pJpGEAmS7xmag8muRQKsILBrMZOlWB1zPRfMvkUdwjBVGV6nAgh8QVYvt21GDyzmJ iIdMjTAgsqNepyAPkYw0jnK1v0CYzNkrYxpLpmLt7kOIP6EerTuLqBQmg9/C7PZ8AW1G SxPi7o7rqQsb4Bb1aSqkzgoaDycbrk/LL70jrnWlRrh6GiETkbH9qSNeL1TD7X1BVIRX GDkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dd3qB6WA; 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 he12-20020a1709073d8c00b0072b0f6f1456si10684741ejc.612.2022.10.31.15.20.40; Mon, 31 Oct 2022 15:21:05 -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=dd3qB6WA; 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 S229849AbiJaVyB (ORCPT + 99 others); Mon, 31 Oct 2022 17:54:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229827AbiJaVxx (ORCPT ); Mon, 31 Oct 2022 17:53:53 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CDA8140C9; Mon, 31 Oct 2022 14:53:52 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id b2so32827950eja.6; Mon, 31 Oct 2022 14:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from:from:to :cc:subject:date:message-id:reply-to; bh=zdYNF6EUojfs0G57LtoPct7Uq38+dK+sU9/t/CK1zr8=; b=dd3qB6WAJlYsE9wP/tCQU7sxRC0VEJ+ENYOIJBZ9x1nxKLDOs+gxPbNJ3JcbqZzMUj Eu1uqtwJ71JjtASe52CsARhT8J0G08u+lioi2hLW9JmLWGw7JZxUbj2v2+Vz9/oF0wFY BP3gIMhTMlj0zsGsTlDK22Jh0xeEOsszTlclrU6JrJG+M60xmKqiZkTw5H+cWGFgzWdz VTU7V95R2LMK5ShBWu+/7YNP227U1iesGBdzg4lvecjema4ij3HNVmUmi+Tb0MEQ4MF3 zP27dLqDAqqgQG2un5DQlD8wGVvNKYf2wbcrl1/h1YbAV9NYmUUgOdu0OusLw1QvagHc J6jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zdYNF6EUojfs0G57LtoPct7Uq38+dK+sU9/t/CK1zr8=; b=W9igpE1lZPqc9Cqj+F+Vr6yEzOq5uQqCXfcCcwPIFcqpTNs7PRVrfyc2eI9IVKGLnd yOrAsMVpw7lm31ykd7JGnVDvKlNdbk7TEknB2Nbv5mQndAvV1S+hUrXm+RD35eRhhS0s KxeMhqTMAKbViB58Elg4N899wxsReagvrxKVBM7ny/W6msAwqbWfKGYQjhXftLt+4h3C Rs2TbRipSzNznAZamMISVWah83Tx2rQmyRjQ8IQKhRCJqNh/zwpI9vtD0oC1xdcebhzK sZ/2ZuI/89JSnx+HI6lPU9+dm9XQ3SOAhbwc1GufRnzxaZJdTaeOLUq2JXQ5xqiv5+x/ iskg== X-Gm-Message-State: ACrzQf1ACYWENtRAD+WVCs3WiK4uTiwbdw+iJ/LIDPL1aIyg/nNHCAd0 BzXrfsekjZNXijLy37M9E/o= X-Received: by 2002:a17:907:6d94:b0:7ad:95fd:d1e4 with SMTP id sb20-20020a1709076d9400b007ad95fdd1e4mr15608353ejc.233.1667253230605; Mon, 31 Oct 2022 14:53:50 -0700 (PDT) Received: from krava ([83.240.62.146]) by smtp.gmail.com with ESMTPSA id l1-20020a1709067d4100b00782e3cf7277sm3416697ejp.120.2022.10.31.14.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 14:53:49 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Mon, 31 Oct 2022 22:53:47 +0100 To: Peter Zijlstra , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Toke =?iso-8859-1?Q?H=F8iland-J=F8rgensen?= Cc: Jiri Olsa , David Laight , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , bpf@vger.kernel.org Subject: Re: Linux 6.1-rc3 build fail in include/linux/bpf.h Message-ID: References: <439d8dc735bb4858875377df67f1b29a@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Mon, Oct 31, 2022 at 04:21:42PM +0100, Peter Zijlstra wrote: > On Mon, Oct 31, 2022 at 01:17:16PM +0100, Jiri Olsa wrote: > > On Mon, Oct 31, 2022 at 11:14:31AM +0000, David Laight wrote: > > > The 6.1-rc3 sources fail to build because bpf.h unconditionally > > > #define BPF_DISPATCHER_ATTRIBUTES __attribute__((patchable_function_entry(5))) > > > for X86_64 builds. > > > > > > I'm pretty sure that should depend on some other options > > > since the compiler isn't required to support it. > > > (The gcc 7.5.0 on my Ubunti 18.04 system certainly doesn't) > > > > > > The only other reference to that attribute is in the definition > > > of 'notrace' in compiler.h. > > > > I guess we need to make some __has_attribute check and make all that conditional > > > > cc-ing Peter > > Does something crazy like the below work? It compiles but is otherwise > totally untested. looks good it has now the ftrace nop and the jump to the dispatcher image or the bpf_dispatcher_nop_func.. great :) bpf_dispatcher_xdp_func: ffffffff81cc87b0 : ffffffff81cc87b0: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) ffffffff81cc87b5: e9 a6 fe 65 ff jmp 0xffffffff81328660 tests work for me.. Toke, Bj?rn, could you please check? thanks, jirka > > --- > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > index 9e7d46d16032..7d7a00306d19 100644 > --- a/include/linux/bpf.h > +++ b/include/linux/bpf.h > @@ -953,6 +953,10 @@ struct bpf_dispatcher { > void *rw_image; > u32 image_off; > struct bpf_ksym ksym; > +#ifdef CONFIG_HAVE_STATIC_CALL > + struct static_call_key *sc_key; > + void *sc_tramp; > +#endif > }; > > static __always_inline __nocfi unsigned int bpf_dispatcher_nop_func( > @@ -970,6 +974,20 @@ struct bpf_trampoline *bpf_trampoline_get(u64 key, > struct bpf_attach_target_info *tgt_info); > void bpf_trampoline_put(struct bpf_trampoline *tr); > int arch_prepare_bpf_dispatcher(void *image, void *buf, s64 *funcs, int num_funcs); > + > + > +#ifdef CONFIG_HAVE_STATIC_CALL > +#define BPF_DISPATCH_CALL(name) static_call(bpf_dispatcher_##name##_call)(ctx, insnsi, bpf_func) > + > +#define __BPF_DISPATCHER_SC_INIT(_name) \ > + .sc_key = &STATIC_CALL_KEY(_name), \ > + .sc_tramp = STATIC_CALL_TRAMP_ADDR(_name), > + > +#else > +#define BPF_DISPATCH_CALL(name) bpf_func(ctx, insnsi) > +#define __BPF_DISPATCHER_SC_INIT(name) > +#endif > + > #define BPF_DISPATCHER_INIT(_name) { \ > .mutex = __MUTEX_INITIALIZER(_name.mutex), \ > .func = &_name##_func, \ > @@ -981,32 +999,29 @@ int arch_prepare_bpf_dispatcher(void *image, void *buf, s64 *funcs, int num_func > .name = #_name, \ > .lnode = LIST_HEAD_INIT(_name.ksym.lnode), \ > }, \ > + __BPF_DISPATCHER_SC_INIT(_name##_call) \ > } > > -#ifdef CONFIG_X86_64 > -#define BPF_DISPATCHER_ATTRIBUTES __attribute__((patchable_function_entry(5))) > -#else > -#define BPF_DISPATCHER_ATTRIBUTES > -#endif > - > #define DEFINE_BPF_DISPATCHER(name) \ > - notrace BPF_DISPATCHER_ATTRIBUTES \ > + DEFINE_STATIC_CALL(bpf_dispatcher_##name##_call, bpf_dispatcher_nop_func); \ > noinline __nocfi unsigned int bpf_dispatcher_##name##_func( \ > const void *ctx, \ > const struct bpf_insn *insnsi, \ > bpf_func_t bpf_func) \ > { \ > - return bpf_func(ctx, insnsi); \ > + return BPF_DISPATCH_CALL(name); \ > } \ > EXPORT_SYMBOL(bpf_dispatcher_##name##_func); \ > struct bpf_dispatcher bpf_dispatcher_##name = \ > BPF_DISPATCHER_INIT(bpf_dispatcher_##name); > + > #define DECLARE_BPF_DISPATCHER(name) \ > unsigned int bpf_dispatcher_##name##_func( \ > const void *ctx, \ > const struct bpf_insn *insnsi, \ > bpf_func_t bpf_func); \ > extern struct bpf_dispatcher bpf_dispatcher_##name; > + > #define BPF_DISPATCHER_FUNC(name) bpf_dispatcher_##name##_func > #define BPF_DISPATCHER_PTR(name) (&bpf_dispatcher_##name) > void bpf_dispatcher_change_prog(struct bpf_dispatcher *d, struct bpf_prog *from, > diff --git a/kernel/bpf/dispatcher.c b/kernel/bpf/dispatcher.c > index fa64b80b8bca..1ca8bd6da6bb 100644 > --- a/kernel/bpf/dispatcher.c > +++ b/kernel/bpf/dispatcher.c > @@ -4,6 +4,7 @@ > #include > #include > #include > +#include > > /* The BPF dispatcher is a multiway branch code generator. The > * dispatcher is a mechanism to avoid the performance penalty of an > @@ -106,7 +107,6 @@ static void bpf_dispatcher_update(struct bpf_dispatcher *d, int prev_num_progs) > { > void *old, *new, *tmp; > u32 noff; > - int err; > > if (!prev_num_progs) { > old = NULL; > @@ -128,11 +128,10 @@ static void bpf_dispatcher_update(struct bpf_dispatcher *d, int prev_num_progs) > return; > } > > - err = bpf_arch_text_poke(d->func, BPF_MOD_JUMP, old, new); > - if (err || !new) > - return; > + __static_call_update(d->sc_key, d->sc_tramp, new ?: &bpf_dispatcher_nop_func); > > - d->image_off = noff; > + if (new) > + d->image_off = noff; > } > > void bpf_dispatcher_change_prog(struct bpf_dispatcher *d, struct bpf_prog *from,