From patchwork Wed May 4 16:13:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Landaverde X-Patchwork-Id: 12838121 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 6BAD4C433EF for ; Wed, 4 May 2022 16:15:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353173AbiEDQSf (ORCPT ); Wed, 4 May 2022 12:18:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352806AbiEDQSe (ORCPT ); Wed, 4 May 2022 12:18:34 -0400 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BC874553A for ; Wed, 4 May 2022 09:14:58 -0700 (PDT) Received: by mail-qk1-x732.google.com with SMTP id f186so1278032qke.8 for ; Wed, 04 May 2022 09:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mdaverde-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=25gauivTso+aPDMUMdYArAx6UKOEKikakpvozYIXV04=; b=aJJHRw1hrM+eJoAEQHKr+3xCNLpAHdUG6nAl8WdDBwP5qaPNhOkhyCGPzGJCfIn33d zKZAJYIXqJ/qqrS9DeFl0frOfu/CvrpCm0Q8620pqKw6fSCRsdgWw6GIjFcp5I3sH2bv VqR+CrVQBxBM1vWr4chDe2J2XgBLvFZDUt/lSD/TAjyUyokDfx1IQ5cvlicgdJOsIrNf iLk+IXHTbfFO0745eWHzGr/MKzLfZ0fGuHUnAYBqJ/80vBMvn5SzkdaVstLfnhSbHI2t cEnwTl1ZYiE+2SDeDcbcPClmIkNLEIl/Sbk8ZDcy4U1QK5YPertXolXtvbOZw2Y2/xhX JceQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=25gauivTso+aPDMUMdYArAx6UKOEKikakpvozYIXV04=; b=Cqhvj6hncC0uZmmghq42s1NskIEXrB5QJ+lcS1+KT9HkzK7VDC2vAf+DZkm9RgvbYk N1V7avK/YQdImi8K5f+z5zXKauAVQ3Uk9Axg+DHXLbNqyQHF7gZSXWFn7DkRZTj1axQi ZndhDGOe1Is8MH38QVfO/jX5lRf9PExY5+YxJsPw1VkScozT89SlxN/mv414jzNewL3E d8RvADYEA8Nght7HZY/TX5qSXzXOhVFZbK+z4YI53HJHVjZoD3YP7yvvEqj+h4fH1Ps4 WYqc2YeVDlVCbtb26htD7FxViLEd23iOzkSETzAqY5pmmjdiGeA/92ux56HKtrZhhQvn f4nw== X-Gm-Message-State: AOAM5317t0uIHtjcJsu6jrLAEiHCQ13iC0MQ9AdITSUA5j9voa74C/Yx 1F9O5QReSSWhNrNAHSnd95zRhQ== X-Google-Smtp-Source: ABdhPJx0dx8kcVi/eEjgGDxAh5m/w84UJmNT0c86lwP/MjJLFqD6oWOX0PmxZa+8Kho55+03vEsAEA== X-Received: by 2002:a05:620a:2a14:b0:69f:fc99:48de with SMTP id o20-20020a05620a2a1400b0069ffc9948demr7666553qkp.604.1651680897202; Wed, 04 May 2022 09:14:57 -0700 (PDT) Received: from pop-os.attlocal.net ([2600:1700:1d10:5830:4611:5fd6:ef88:7605]) by smtp.gmail.com with ESMTPSA id 18-20020ac85652000000b002f39b99f66dsm7594467qtt.7.2022.05.04.09.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 09:14:56 -0700 (PDT) From: Milan Landaverde Cc: milan@mdaverde.com, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Quentin Monnet , Paul Chaignon , =?utf-8?q?Niklas_S=C3=B6derlund?= , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 1/2] bpftool: adjust for error codes from libbpf probes Date: Wed, 4 May 2022 12:13:31 -0400 Message-Id: <20220504161356.3497972-2-milan@mdaverde.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220504161356.3497972-1-milan@mdaverde.com> References: <20220504161356.3497972-1-milan@mdaverde.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Originally [1], libbpf's (now deprecated) probe functions returned a bool to acknowledge support but the new APIs return an int with a possible negative error code to reflect probe failure. This change decides for bpftool to declare maps and helpers are not available on probe failures. [1]: https://lore.kernel.org/bpf/20220202225916.3313522-3-andrii@kernel.org/ Signed-off-by: Milan Landaverde --- tools/bpf/bpftool/feature.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c index be130e35462f..c532c8855c24 100644 --- a/tools/bpf/bpftool/feature.c +++ b/tools/bpf/bpftool/feature.c @@ -638,7 +638,7 @@ probe_map_type(enum bpf_map_type map_type, const char *define_prefix, res = probe_map_type_ifindex(map_type, ifindex); } else { - res = libbpf_probe_bpf_map_type(map_type, NULL); + res = libbpf_probe_bpf_map_type(map_type, NULL) > 0; } /* Probe result depends on the success of map creation, no additional @@ -701,7 +701,7 @@ probe_helper_for_progtype(enum bpf_prog_type prog_type, bool supported_type, if (ifindex) res = probe_helper_ifindex(id, prog_type, ifindex); else - res = libbpf_probe_bpf_helper(prog_type, id, NULL); + res = libbpf_probe_bpf_helper(prog_type, id, NULL) > 0; #ifdef USE_LIBCAP /* Probe may succeed even if program load fails, for * unprivileged users check that we did not fail because of From patchwork Wed May 4 16:13:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Landaverde X-Patchwork-Id: 12838122 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 C1962C4332F for ; Wed, 4 May 2022 16:15:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353187AbiEDQTO (ORCPT ); Wed, 4 May 2022 12:19:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353287AbiEDQTB (ORCPT ); Wed, 4 May 2022 12:19:01 -0400 Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19E7C18E18 for ; Wed, 4 May 2022 09:15:24 -0700 (PDT) Received: by mail-qv1-xf2a.google.com with SMTP id dv4so1150791qvb.13 for ; Wed, 04 May 2022 09:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mdaverde-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aRTT3Khcb1rZ/aGFwRbPNDE/jeWlp1F0NgwR7yaPUME=; b=MVEwt4lEQ6odj4JoF+ekWEO601myqPUssVHGiuBUWjYeEk+C9+mjc+l5YmEzVre3wm oPHisIb2b7rw3Vl1n0uzeWrxDQ2jd+MZfaZQ2mO9wbchYzPrHzE5tXh1hEdD0neRiBWs t63roERMr0X3TbTo3+J/O0aWy0hzRNzyEqrrG9pZ1yIKBX0zorrkDwbAFY1IxQO1sZ1k x/LWIhGKSHkg4sKxgV6ZkpA1y4SEiVYAAnCuzTXZmaHUjl8O3dYpodQ50sZKuN4FVz3n vaMmLwN9gXgsCLUZSo8hf0yWnVJLeq7oskBqjm2qTnmEvnXceq8Cl5mERkSrwlWNY9vH mZJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aRTT3Khcb1rZ/aGFwRbPNDE/jeWlp1F0NgwR7yaPUME=; b=cxVY/YeQy5kqC1WkF/FsQcpDOsiHvpDGtpOVU+5CRUEY3OvU7y3si/LzEKUB5KIH6j q04Mv2qXrZHK9r2yQVifdNAwAv74fysVDG08qorxDfLTDaWdAxBVDZbzwrw4otnMBNAN ncrbXWSU+bjP0OlZ6a7FcYZ+GGZXLsEhxhfRF8vXnOXzjvyGGr9aa57Bz/H9/nBWDxPi 3nDT/E36eO05UoHH/zEvy95OlBHLUQZUxYBY+QP2fNNh1r4G2Z3H4xBqLv9TulnsH5QE uvEQRb03v3KGOYY0yLEW8qCdm4L3NCo7i4V8b7nk4liclRPEPWIgW2Z+URZRkdOT+Br7 7MLA== X-Gm-Message-State: AOAM531KfKTHIsrx9jYspkMLGv3lpZK/V578/UPrxtnTsqwYrqEeETZk z/S1AwTf6b3gRgvKsu9hmekjRQ== X-Google-Smtp-Source: ABdhPJxVYo/IWIg5lLnfnd4q5/JBFnRFyOg9pQqgHLIhnd2mJGMlex3zVNr4pwIGyKX3YYDu+DyO5w== X-Received: by 2002:a0c:f1d2:0:b0:45a:8012:1a90 with SMTP id u18-20020a0cf1d2000000b0045a80121a90mr16256965qvl.31.1651680923269; Wed, 04 May 2022 09:15:23 -0700 (PDT) Received: from pop-os.attlocal.net ([2600:1700:1d10:5830:4611:5fd6:ef88:7605]) by smtp.gmail.com with ESMTPSA id 18-20020ac85652000000b002f39b99f66dsm7594467qtt.7.2022.05.04.09.15.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 09:15:22 -0700 (PDT) From: Milan Landaverde Cc: milan@mdaverde.com, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Quentin Monnet , Paul Chaignon , =?utf-8?q?Niklas_S=C3=B6derlund?= , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 2/2] bpftool: output message if no helpers found in feature probing Date: Wed, 4 May 2022 12:13:32 -0400 Message-Id: <20220504161356.3497972-3-milan@mdaverde.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220504161356.3497972-1-milan@mdaverde.com> References: <20220504161356.3497972-1-milan@mdaverde.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Currently in libbpf, we have hardcoded program types that are not supported for helper function probing (e.g. tracing, ext, lsm). Due to this (and other legitimate failures), bpftool feature probe returns empty for those program type helper functions. Instead of implying to the user that there are no helper functions available for a program type, we output a message to the user explaining that helper function probing failed for that program type. Signed-off-by: Milan Landaverde --- tools/bpf/bpftool/feature.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c index c532c8855c24..d12f46051aac 100644 --- a/tools/bpf/bpftool/feature.c +++ b/tools/bpf/bpftool/feature.c @@ -690,7 +690,7 @@ probe_helper_ifindex(enum bpf_func_id id, enum bpf_prog_type prog_type, return res; } -static void +static bool probe_helper_for_progtype(enum bpf_prog_type prog_type, bool supported_type, const char *define_prefix, unsigned int id, const char *ptype_name, __u32 ifindex) @@ -723,6 +723,8 @@ probe_helper_for_progtype(enum bpf_prog_type prog_type, bool supported_type, if (res) printf("\n\t- %s", helper_name[id]); } + + return res; } static void @@ -732,6 +734,7 @@ probe_helpers_for_progtype(enum bpf_prog_type prog_type, bool supported_type, const char *ptype_name = prog_type_name[prog_type]; char feat_name[128]; unsigned int id; + bool probe_res = false; if (ifindex) /* Only test helpers for offload-able program types */ @@ -764,7 +767,7 @@ probe_helpers_for_progtype(enum bpf_prog_type prog_type, bool supported_type, continue; /* fallthrough */ default: - probe_helper_for_progtype(prog_type, supported_type, + probe_res |= probe_helper_for_progtype(prog_type, supported_type, define_prefix, id, ptype_name, ifindex); } @@ -772,8 +775,17 @@ probe_helpers_for_progtype(enum bpf_prog_type prog_type, bool supported_type, if (json_output) jsonw_end_array(json_wtr); - else if (!define_prefix) + else if (!define_prefix) { printf("\n"); + if (!probe_res) { + if (!supported_type) + printf("\tProgram type not supported\n"); + else + printf("\tCould not determine which helpers are available\n"); + } + } + + } static void