Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64C39C6FD1F for ; Fri, 10 Mar 2023 03:26:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbjCJD04 (ORCPT ); Thu, 9 Mar 2023 22:26:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229774AbjCJD0w (ORCPT ); Thu, 9 Mar 2023 22:26:52 -0500 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9A20F8F37 for ; Thu, 9 Mar 2023 19:26:49 -0800 (PST) Received: by mail-io1-xd32.google.com with SMTP id g6so1537585iov.13 for ; Thu, 09 Mar 2023 19:26:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678418809; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=oXceP9AsMjvivVzcPWyt1cCB9rlFzG2cR5zq3gKp8kg=; b=QbqXgGD2gYCpt+l8sIVRhRlvqBcrj5iQuWzhZGHSgoxO+OlxFB+iSj3SmvEtVfUI7K hWHOOhMQ/cZTrZD17imIDty7WniaxSDwCYKg0dAWDP629YBh1aefNAjRNcWHqPA8JXL8 B9c1H3APzBtCnVwNxKJNBeBYRgEWjgIfaDPBBNNNgwtLIDz6bIUAXgMy/ifBMEhFDBSo 6a0P+8SAHqLjJy6yxGIrFvhiD+qoq4WzpLZEdwGwrnyMmnhMN9I6YZAbOKY8vE2p9cDR /wnPtgi3w1Vsq5NUaRclRtn8SZWv+TZAw+k0TaFzLuJnM412bFpIGng+ODZRq6OOLK5/ GQMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678418809; h=content-transfer-encoding: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=oXceP9AsMjvivVzcPWyt1cCB9rlFzG2cR5zq3gKp8kg=; b=1Nh1MtOc22yliSuUEO+4DwUuWejg20bJxyhIW5obBR4p1/s8G/4eTpyOgiUhaay4ZJ gJT0G9tMxpKqm7K4IzUeM0D1zQnAf96H9oI3ar5ae9+5H7vHmqmKoCIugKUhanMSk2wH 3MtBhsbi3fJiGFjqkBSYTNUnyhsOcA0eVBQmMSCWCgrF8yVlwY1j1QJxHVrC79T4Tsmw Xs2lX9oc8Rf9JE1HTdaCvEs70jWZ4m1N9DDr1al/D28JnrVqnl3hdnx/X4UCTiQAuA0U zOkHWAdvVPHEmtok8ks8xO5xo7/vvAvFfKblm6KVdjlMH4vNPuOBGV1t8UobgNnWXilp FY1A== X-Gm-Message-State: AO0yUKXO9EIDXF2ckGZ5Bi6DsN8c/mN3oHnH6KyeBt6Ri+TSjnYI4vKY PSqkFGpu3GNpwEcOij9rd8TUYk3VEPghF5xKkCEMJg== X-Google-Smtp-Source: AK7set9LTtI/PpGuBD2uqj0AoseCwQoLA/055RWxCBWhT1XMwNyc5d9vjAfhpp7M3ioVa9HBEC0v2CDu1a8mQOPw2y4= X-Received: by 2002:a5e:9413:0:b0:745:a722:4a15 with SMTP id q19-20020a5e9413000000b00745a7224a15mr11061449ioj.2.1678418808743; Thu, 09 Mar 2023 19:26:48 -0800 (PST) MIME-Version: 1.0 References: <20230116010115.490713-1-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Thu, 9 Mar 2023 19:26:35 -0800 Message-ID: Subject: Re: [PATCH v2 0/3] Assume libbpf 1.0+ To: Andrii Nakryiko Cc: Guilherme Amadio , Jiri Olsa , Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Namhyung Kim , Andres Freund , Quentin Monnet , Roberto Sassu , Christy Lee , Andrii Nakryiko , Adrian Hunter , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, Michael Petlan , Ben Hutchings Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 9, 2023 at 9:25=E2=80=AFAM Andrii Nakryiko wrote: > > On Wed, Mar 8, 2023 at 11:58=E2=80=AFPM Guilherme Amadio wrote: > > > > On Wed, Mar 08, 2023 at 06:13:34PM -0800, Ian Rogers wrote: > > > On Thu, Jan 19, 2023 at 1:13=E2=80=AFPM Jiri Olsa wrote: > > > > > > > > On Thu, Jan 19, 2023 at 02:41:12PM -0300, Arnaldo Carvalho de Melo = wrote: > > > > > Em Thu, Jan 19, 2023 at 09:11:03AM -0800, Ian Rogers escreveu: > > > > > > On Sun, Jan 15, 2023 at 5:01 PM Ian Rogers = wrote: > > > > > > > libbpf 1.0 was a major change in API. Perf has partially supp= orted > > > > > > > older libbpf's but an implementation may be: > > > > > > > .. > > > > > > > pr_err("%s: not support, update libbpf\n", __func__); > > > > > > > return -ENOTSUP; > > > > > > > .. > > > > > > > > > > > > > > Rather than build a binary that would fail at runtime it is > > > > > > > preferrential just to build libbpf statically and link agains= t > > > > > > > that. The static version is in the kernel tools tree and newe= r than > > > > > > > 1.0. > > > > > > > > > > > > > > These patches change the libbpf test to only pass when at lea= st > > > > > > > version 1.0 is installed, then remove the conditional build a= nd > > > > > > > feature logic. > > > > > > > > > > > > > > The issue is discussed here: > > > > > > > https://lore.kernel.org/lkml/20230106151320.619514-1-irogers@= google.com/ > > > > > > > perf bpf: > > > > > > > > > > > > > > A variant of this fix was added to Linux 6.2 in: > > > > > > > "perf bpf: Avoid build breakage with libbpf < 0.8.0 + LIBBPF_= DYNAMIC=3D1" > > > > > > > https://lore.kernel.org/lkml/Y71+eh00Ju7WeEFX@kernel.org/ > > > > > > > This change goes further in removing logic that is now no lon= ger > > > > > > > necessary. > > > > > > > > > > > > > > v2. Rebase now that breakage fix patch is in linus/master. > > > > > > > > > > > > I missed the: > > > > > > Acked/Tested-by: Jiri Olsa > > > > > > I believe we are waiting for package maintainer input. > > > > > > > > > > Yes, as fedora:37 still is at libbpf 0.8.0 :-\ > > > > > > > > rawhide (f38) is already on 1.1.0 ... I'll check how bad it'd be to= move > > > > f37 to 1.x, but I had to do bulk update of like 10 other dependent = packages > > > > for f38, so not sure how bad it'd be for f37 > > > > > > > > jirka > > > > > > +Guilherme > > > > > > We were looking for maintainer input on these changes, but there is n= o > > > update in over a month. Here is the original lore link: > > > https://lore.kernel.org/lkml/CAP-5=3DfVUgc8xtBzGi66YRUxZHyXvW2kiMjGz3= 9dywaLxrO4Hpg@mail.gmail.com/ > > > Should these changes land in perf-tools-next targeting Linux 6.4? > > > > Gentoo has libbpf-1.1 already available, so requiring >libbpf-1.0 is no= t > > a problem. We (Gentoo) just need to make sure to stabilize libbpf-1.x b= efore > > stabilizing newer versions of perf, as the stable libbpf is 0.8.1 at th= e moment. > > > > libbpf v0.8 is basically all the 1.0 APIs, except by default 1.0 > semantics is not enforced, unless libbpf_set_strict_mode() is enabled. > > So, if 0.8 is a restriction, perf can stay on 0.8, use all the same > APIs that are in 1.0 (except newer one added later, but I'm not sure > perf needs any of the newer additions), and just stick to setting > libbpf_set_strict_mode() unconditionally. Thanks Andrii, The default perf build is to build against tools/lib/bpf and statically link libbpf in. This means by default we have the latest libbpf 1.2. If any perf code has a dependency on 0.8 (we don't support earlier) we need to #ifdef for it. Currently we have 7 feature tests for libbpf, but perhaps there is some cruft that's carried forward. The features are: - btf__load_from_kernel_by_id - bpf_prog_load - bpf_object__next_program - bpf_object__next_map - bpf_program__set_insns - btf__raw_data - bpf_map_create The not present implementations look like: https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/p= erf/util/bpf-loader.c?h=3Dperf-tools#n36 ``` int bpf_program__set_insns(struct bpf_program *prog __maybe_unused, struct bpf_insn *new_insns __maybe_unused, size_t new_insn_cnt __maybe_un= used) { pr_err("%s: not support, update libbpf\n", __func__); return -ENOTSUP; } int libbpf_register_prog_handler(const char *sec __maybe_unused, enum bpf_prog_type prog_type __maybe_unuse= d, enum bpf_attach_type exp_attach_type __maybe_unused, const struct libbpf_prog_handler_opts *opts __maybe_unused) { pr_err("%s: not support, update libbpf\n", __func__); return -ENOTSUP; } ``` This will basically mean that while you dynamically linked with libbpf 0.8 you are in all likelihood not going to get proper BPF support. These changes up the version requirement to 1.0 and get rid entirely of the feature tests - so no runtime failing implementations. If the build determines at build time libbpf 1.0+ isn't present then it still executes, switching from dynamic libbpf to the default static libbpf that is at 1.2. As mentioned in this thread, distributions like Debian use the default static linking of libbpf. I'm not keen to hold on to the feature tests for the complexity that they hold and their needlessly (as you can always statically link) broken at runtime behavior. We could but my opinion is, let's not :-) Thanks, Ian > > Best regards, > > -Guilherme > >