From patchwork Fri Dec 17 13:52:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Chaignon X-Patchwork-Id: 12684677 X-Patchwork-Delegate: bpf@iogearbox.net 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 D46CBC433F5 for ; Fri, 17 Dec 2021 13:52:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234343AbhLQNwJ (ORCPT ); Fri, 17 Dec 2021 08:52:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233098AbhLQNwH (ORCPT ); Fri, 17 Dec 2021 08:52:07 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88CB1C061574 for ; Fri, 17 Dec 2021 05:52:07 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id r17so3842788wrc.3 for ; Fri, 17 Dec 2021 05:52:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=BXYvhD66m9qpew2FPguNtB1xEh61JrPI9dWMrSoJbWk=; b=IZVQ/4KE/ygWz48NKMaB/422pHUYknCW0AW7tISThNA4nyigvJ0yhCksx9N/bugl3B cNk66wY6RGIkYQ+vejm2m7imjiIFlljV2zdYcBLKDHOgflZr4e6wQj7FlqF6wE+olR4c O040JwtsGeTFir85IyLDMFOqStfE+jePrFP8kQebBoxt45CcSkv8HS0K3pRttCXpj2yD i261ZXYkFQu7VkcFQT0MIJQ0HHbXKezxWjEhRL3RQtJ542Drh9dAAHtEwDeMI7UjvIul /48KYT4Qg1SoSLV2i2xeWEAMNZAIHb7ZUGxDfPVLUwPaWcY8nNAEh/4zoo4KS7kd4YGu 8Zlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=BXYvhD66m9qpew2FPguNtB1xEh61JrPI9dWMrSoJbWk=; b=Fh4gbiuc1o4JSjxuqnUGNueISx3ucnPyQsPindPyOVRsw5R1ZJyEqygd1lonYEzt0/ /fOGtk1BCnKQbY6b0+3KrwzykZf0dvX8etU1ItLifgv0TtPrXj0dZt1wAeB84c5jTH6y fMztA/lLxWL4KzUyYyyFx+p1guiwHa6b5ASE4h9ejHgwzR1v2hD4Jw+m4txfQr0Qka9m oZndG+mDOU/n1lE+PIQpFKWwc5GLU9pPjZfwXtc7FxKAH5jswH+cGWVb9y+paay+9pck r/cAu1Q73k8stGomC6gMcVVeB8kp5MLTYVuj0rmkgeLKT34+CXX5M1ooKFM+uugkBwL+ eRag== X-Gm-Message-State: AOAM5314Nibnl1OSNZ5Widc1l4D58oWpeudpwjn53nFh3T6D6/MKBxUS AnSQ8xge52AUHGoYjQX40nU3 X-Google-Smtp-Source: ABdhPJxVhD5h89F4ke06EdIJFLmfoLjffR4UZ++AajqsXFDHKBWoCgGesbzflTCLXqUZZrmIe1Ce2w== X-Received: by 2002:a5d:6d09:: with SMTP id e9mr2542102wrq.17.1639749126147; Fri, 17 Dec 2021 05:52:06 -0800 (PST) Received: from Mem (2a01cb088160fc0089020d359cf3dd66.ipv6.abo.wanadoo.fr. [2a01:cb08:8160:fc00:8902:d35:9cf3:dd66]) by smtp.gmail.com with ESMTPSA id d2sm3606309wrw.26.2021.12.17.05.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Dec 2021 05:52:05 -0800 (PST) Date: Fri, 17 Dec 2021 14:52:04 +0100 From: Paul Chaignon To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, Quentin Monnet Subject: [PATCH bpf-next v2 1/2] libbpf: Probe for bounded loop support Message-ID: <7dfdf3f93467c619c14c40e957c54b87bb734294.1639748569.git.paul@isovalent.com> MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net This patch introduces a new probe to check whether the verifier supports bounded loops as introduced in commit 2589726d12a1 ("bpf: introduce bounded loops"). This patch will allow BPF users such as Cilium to probe for loop support on startup and only unconditionally unroll loops on older kernels. Reviewed-by: Quentin Monnet Signed-off-by: Paul Chaignon --- Changes in v2: - Resending to fix a format error. I had the good idea of saving the patch in Gmail as a draft before sending with mutt, which caused Gmail to remove the trailing space in the Git version signature. That then caused pathwork to generate an incorrect mbox file. tools/lib/bpf/libbpf.h | 1 + tools/lib/bpf/libbpf.map | 1 + tools/lib/bpf/libbpf_probes.c | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 42b2f36fd9f0..3621aaaff67c 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -1058,6 +1058,7 @@ LIBBPF_API bool bpf_probe_map_type(enum bpf_map_type map_type, __u32 ifindex); LIBBPF_API bool bpf_probe_helper(enum bpf_func_id id, enum bpf_prog_type prog_type, __u32 ifindex); LIBBPF_API bool bpf_probe_large_insn_limit(__u32 ifindex); +LIBBPF_API bool bpf_probe_bounded_loops(__u32 ifindex); /* * Get bpf_prog_info in continuous memory diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index b3938b3f8fc9..059d168452d7 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -423,6 +423,7 @@ LIBBPF_0.6.0 { LIBBPF_0.7.0 { global: bpf_btf_load; + bpf_probe_bounded_loops; bpf_program__log_buf; bpf_program__log_level; bpf_program__set_log_buf; diff --git a/tools/lib/bpf/libbpf_probes.c b/tools/lib/bpf/libbpf_probes.c index 4bdec69523a7..e5bd691059e4 100644 --- a/tools/lib/bpf/libbpf_probes.c +++ b/tools/lib/bpf/libbpf_probes.c @@ -356,3 +356,23 @@ bool bpf_probe_large_insn_limit(__u32 ifindex) return errno != E2BIG && errno != EINVAL; } + +/* + * Probe for bounded loop support introduced in commit 2589726d12a1 + * ("bpf: introduce bounded loops"). + */ +bool bpf_probe_bounded_loops(__u32 ifindex) +{ + struct bpf_insn insns[4] = { + BPF_MOV64_IMM(BPF_REG_0, 10), + BPF_ALU64_IMM(BPF_SUB, BPF_REG_0, 1), + BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, -2), + BPF_EXIT_INSN() + }; + + errno = 0; + probe_load(BPF_PROG_TYPE_SOCKET_FILTER, insns, ARRAY_SIZE(insns), NULL, + 0, ifindex); + + return !errno; +} From patchwork Fri Dec 17 13:52:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Chaignon X-Patchwork-Id: 12684679 X-Patchwork-Delegate: bpf@iogearbox.net 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 2E1E2C433EF for ; Fri, 17 Dec 2021 13:52:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233267AbhLQNwm (ORCPT ); Fri, 17 Dec 2021 08:52:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231667AbhLQNwk (ORCPT ); Fri, 17 Dec 2021 08:52:40 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05DAFC061574 for ; Fri, 17 Dec 2021 05:52:40 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id r17so3845622wrc.3 for ; Fri, 17 Dec 2021 05:52:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=1hmYcL8ZBpuziqt1kJhEnz2Faitl0n8iiR6HII1rL+Y=; b=fMWZlIavO+dRbmRTwGFnxOdORj89uXfN0YghwhHOrUyv+zef1iTygBCzDHFA8LDBsO 6N4QozKU0bvda+Eq5FqtdxM5eoArB4bSWf8en3JFvjXADmeBDBwIYStknqHiYP8XUDbu 3ZKqxce/+a4FqW0oq8f+rMdf1+QcJUenEA++XHV0J6QwjqfiEUKlmJyE9UVvby9EcRx3 BxARd29dVjwczlZ21M3nRdUaZFBk6FMsYJ4pR0MVHcMMMO9e5104mQ0ZYRNCVa/UIJdY +TjES5SY6jpldfj5w598lJrc71aZS0Pi98AuXM3TZitM6FoUpbaYc7XNqwLr77MYETih XgDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=1hmYcL8ZBpuziqt1kJhEnz2Faitl0n8iiR6HII1rL+Y=; b=STPVudtF02ztQuY24er6UHXigI3AnMRSr3H0VTLRKT1N2KmOVtqisX1m9T1h+xj432 IH0vnvSShjNcI6IgWUUotk1+6yn79aTAV5tNmrnwOCrg5whF0BGZjZDN+6ZC/aWjvufI Wdu2B7t5jr9XoVWU/hUxAbmh1UHO0o4nPV32pp8XVQ8LWTts1nAmumbqC0WwZZgK1ejL DVEXp8+C+k9pfh0YIeV10nwSHr0AK/j8fmH1aLQFIjw+bYrHkZtrBXi18bYevHI3nnqF iAyAkI13ttMBkhzct+51bwG8PGqhpOIO6L2wlvuxywF1YELyl93flto79lJWjn+ZNT0Y BsNQ== X-Gm-Message-State: AOAM531/vmQ5HwHAH+tbVZr1Vk925FQR4zVXZCz77QRAcG7SuHZEyxos ge0lh45eoRlWZzEwakbYFfOW X-Google-Smtp-Source: ABdhPJwA22eS32pDfRhs1YLM8PAM9oxL4+k7yWlMnZRiNQinPJgMQk2JMLRt8iCzmkjdLy20RhuESQ== X-Received: by 2002:a5d:62cf:: with SMTP id o15mr2684911wrv.651.1639749158591; Fri, 17 Dec 2021 05:52:38 -0800 (PST) Received: from Mem (2a01cb088160fc0089020d359cf3dd66.ipv6.abo.wanadoo.fr. [2a01:cb08:8160:fc00:8902:d35:9cf3:dd66]) by smtp.gmail.com with ESMTPSA id w17sm8142208wmc.14.2021.12.17.05.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Dec 2021 05:52:38 -0800 (PST) Date: Fri, 17 Dec 2021 14:52:37 +0100 From: Paul Chaignon To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, Quentin Monnet Subject: [PATCH bpf-next v2 2/2] bpftool: Probe for bounded loop support Message-ID: <9ad43ccea2929be6e94f16f6ee7482ad89524531.1639748569.git.paul@isovalent.com> References: <7dfdf3f93467c619c14c40e957c54b87bb734294.1639748569.git.paul@isovalent.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <7dfdf3f93467c619c14c40e957c54b87bb734294.1639748569.git.paul@isovalent.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net This patch probes for bounded loop support and displays the results as part of the miscellaneous section, as shown below. $ bpftool feature probe | grep loops Bounded loop support is available $ bpftool feature probe macro | grep LOOPS #define HAVE_BOUNDED_LOOPS $ bpftool feature probe -j | jq .misc { "have_large_insn_limit": true, "have_bounded_loops": true } Reviewed-by: Quentin Monnet Signed-off-by: Paul Chaignon --- Changes in v2: - Resending to fix a format error. tools/bpf/bpftool/feature.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c index 5397077d0d9e..7aee920162e5 100644 --- a/tools/bpf/bpftool/feature.c +++ b/tools/bpf/bpftool/feature.c @@ -654,6 +654,18 @@ probe_large_insn_limit(const char *define_prefix, __u32 ifindex) res, define_prefix); } +static void +probe_bounded_loops(const char *define_prefix, __u32 ifindex) +{ + bool res; + + res = bpf_probe_bounded_loops(ifindex); + print_bool_feature("have_bounded_loops", + "Bounded loop support", + "BOUNDED_LOOPS", + res, define_prefix); +} + static void section_system_config(enum probe_component target, const char *define_prefix) { @@ -768,6 +780,7 @@ static void section_misc(const char *define_prefix, __u32 ifindex) "/*** eBPF misc features ***/", define_prefix); probe_large_insn_limit(define_prefix, ifindex); + probe_bounded_loops(define_prefix, ifindex); print_end_section(); }