From patchwork Fri Dec 17 12:12:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Chaignon X-Patchwork-Id: 12684505 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 D57F0C433F5 for ; Fri, 17 Dec 2021 12:12:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231992AbhLQMM0 (ORCPT ); Fri, 17 Dec 2021 07:12:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231451AbhLQMMX (ORCPT ); Fri, 17 Dec 2021 07:12:23 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86F7AC06173E for ; Fri, 17 Dec 2021 04:12:22 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id s1so3687563wrg.1 for ; Fri, 17 Dec 2021 04:12:22 -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=utqqd9ci6ew41O6zf0YypR+5F7H5LySynYJvMT/qY0g=; b=pPdHYvSd/UbI9WiPpDhuC+kvi0n2HmBey4Po86xsp+tkad8dPX8ize9kOeV6XGd351 uMcP7pg39hcsAqd2oXbrPybnTcujE3WESIxQArZn3h+vtVSTmZ2i/YNytdlHTdcc9SHA tzETivfo6YDqOGbu48M8G57bC67T6IN2AlmpmNZYJpTzz/c8zPXoh3Pfy7VBfB3zflgj C1XOAkt00jIwokaRNpGf+EW/3Mk48FOEfFEugYdM/Ir4RSLOqYFCWobUJ94DCbe2fuYw ok9oRArgumiD62B2VhQgNvwnOTTPmTAhFuxSC8984mfMK0zAS6iQ6TuhOxNatODUIvuw Gt0w== 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=utqqd9ci6ew41O6zf0YypR+5F7H5LySynYJvMT/qY0g=; b=WfQ3tComMc8B58ZFUfpvaDWwEGmerZcsg61kD4PU0GsnbMwuDn35R0E5DUM5VLP360 m/bVGRKrFmiu7zd+XnYLsvZ6U4z/Xxq0GEFZASPUcKdjVkAZHTJQYG2pLN3353gp8K2E kSfVuTQHtu03wGmLT7P5evVYqZAAYDlDNr3SaXSBzfpYIz/GvWKNnWqY4xCm5obt/f4l TMuYAB0LLxqAuRrTKribvh1ICUZmEGR6FWbncXSaBFf/gMfCNXHX/KIdPlVtWK96ZxdO a0k9NF9vEdaRyceBTc296XF5wtgE2yNpQGMMQKHQPzN+j0edfq29pqrxi9fv1HIyQDrv C2og== X-Gm-Message-State: AOAM531jl4W8hy68/g41xrhfPtWd4wTCD/VACjCTptwbdiFqxgypnPsJ LnICK79XtMzOhclGikpo5sfvbAzhTU3247A= X-Google-Smtp-Source: ABdhPJx5sqf8scmxXWVBQ+EH+H7sAvMhMrx1KiO/VOA5/erUmIrficREs7csxe8cIPBGXkTF88u8RA== X-Received: by 2002:adf:f252:: with SMTP id b18mr2341745wrp.341.1639743141114; Fri, 17 Dec 2021 04:12:21 -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 g198sm8381296wme.23.2021.12.17.04.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Dec 2021 04:12:20 -0800 (PST) Date: Fri, 17 Dec 2021 13:12:19 +0100 From: Paul Chaignon To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, Quentin Monnet Subject: [PATCH bpf-next 1/2] libbpf: Probe for bounded loop support Message-ID: 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 --- tools/lib/bpf/libbpf.h | 1 + tools/lib/bpf/libbpf.map | 1 + tools/lib/bpf/libbpf_probes.c | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) -- 2.25.1 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 12:12:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Chaignon X-Patchwork-Id: 12684507 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 504C2C433EF for ; Fri, 17 Dec 2021 12:12:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233978AbhLQMMs (ORCPT ); Fri, 17 Dec 2021 07:12:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233965AbhLQMMs (ORCPT ); Fri, 17 Dec 2021 07:12:48 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1CDAC061574 for ; Fri, 17 Dec 2021 04:12:47 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id i22so3581847wrb.13 for ; Fri, 17 Dec 2021 04:12:47 -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=dEIJSN31E2W6iR/NUCOGbDLcMpZ+tGwEkjESqopsyYs=; b=7SPfih9YuSWkT1yoYBhUbYw9YXI471b6e2Pay6fAH44bu5N0GXxQHIJOYjOYrVB/0M E6pjfPiMCVvtqNi60B7GABXL5bZRYQTD20BlgaRRsjo+KuH4nUYeL78/Cx9StEDTrHHf UoJMCErAM46hqNxCmGeuwMMRSH61Oeub7X0RDwWDOIphAJI1UlMu9uxXEJWZuUjyAbAy BeBgWaGvzTXVhXUKBqkonnFiP8rCKi5XvC37DVak381T3iXULJutHBezXAgbGMqki5mF YfUpSXjrKi7TEqfPJopHeS6a7bM0H/beq6smMyiqLFJjvfaV+JtudEoXMkqs+N82QvHZ ZURw== 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=dEIJSN31E2W6iR/NUCOGbDLcMpZ+tGwEkjESqopsyYs=; b=xw9wDc4LA4eGK3YF8d7BWyr7LskiwrU9VaAl6QwjC5jmcrkAArVPOhpSj0AZKp5mLw XIzH+uPddmGDILqGjEian5wuA9uaHY694evDQ79ewNIUm9ag/4xlH3RZtq/5VpumUn9h 31Ml8+vHiD6wA1siULpqzbi5bi2anNOvBekWnTRRkQobwiZzA4KfzoRkDnF5S/MPYFah G0jbvJxvOIBaJE/c+pPkhe6uVa6PMYSzZdGu5/kDfj6n4d6aMR7wGFFXEI2F0KwAtrIO 6UMBVVtYmPTi2XfCwUgfkPjqrfsdIZuZ1wj7rT1VdUA8bdqqzQzUovafDO6/RGOUBbR1 KkKw== X-Gm-Message-State: AOAM532S+jUL5/A4btYLxd7NZR5jS+j7grdcKe923w0Oxn+l9RPu6Izk BL/p+lGsOoE4siB3FFGDYr8Q X-Google-Smtp-Source: ABdhPJyqYinrDr4r4HgR+AiBT2LDYWpYoStrVQOa5ss5bhT1js6nCe/m6wZDJzGaBBMTTm5wvVB3sg== X-Received: by 2002:a5d:434f:: with SMTP id u15mr2425987wrr.492.1639743166236; Fri, 17 Dec 2021 04:12:46 -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 c8sm8375847wmq.34.2021.12.17.04.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Dec 2021 04:12:45 -0800 (PST) Date: Fri, 17 Dec 2021 13:12:44 +0100 From: Paul Chaignon To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, Quentin Monnet Subject: [PATCH bpf-next 2/2] bpftool: Probe for bounded loop support Message-ID: 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 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 --- tools/bpf/bpftool/feature.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) -- 2.25.1 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(); }