From patchwork Fri Jul 12 14:24:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13731854 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5443C13F439; Fri, 12 Jul 2024 14:24:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720794274; cv=none; b=V5f96nfkfe1w+Ch4nOlwXyklhSrcy0Gl9cwvXRESmGPVauUHNL8wVQnGcgBewJ+0oynf7aRCe2liC0cs4tUBtD0Ts0ZYaSRg9glFotjOyXgF9xTE6Uzk2nqDHx0N+fq7DPAkCGaNOs9GKD0mSBZL8z/WX6aWbnpDdurqW4l0vBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720794274; c=relaxed/simple; bh=uRAkMAu6p5BoCnsavdR/O4GrREdstMoQXHGClq1Bu7E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kh7fLJwyqjOd8Zb4rBePvvwvbS3B7Ou5X56Mfwu9/KAJ+sHlc3SJ388ZgafquOYTIvdKAplV0APf9EGEFfx7R1F1L2Ri3PF7DBX1D3DvZqHlrEkDEe6seFc3P2o05Menunm5+pl5BvQdS0pqIHm2hBFi/xjfi9SHXLjNtsp7nRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eXtjQI9j; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eXtjQI9j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE9E9C32782; Fri, 12 Jul 2024 14:24:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720794274; bh=uRAkMAu6p5BoCnsavdR/O4GrREdstMoQXHGClq1Bu7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eXtjQI9j1fC5l5AoepYHH3RIcn5E56Ly3BrIzabbs08UVOumK3OIllm4RygGdgHkA 5MT7wv/kQYfkULfJhVopX8qxfuWP3HfVHlTqLEEahGWdwbG2imCGusfRo8bntRAlCT zcPMHgFXE66iohF7N6GHjKoCOZ9lPaO/raagZMF9+IQHSUhhXE8kWxQ7jGhWzaad9y iKKLYw6V5Wdxeqh8wjkiMnW+xeAciipbi7DwE96P/dEAgmFKozsKwBFX0EZ9sbM2mQ JmQ7TXVHxxO8uXPH1qBkWuvxc9NipblhC2SjoacHLcPkrkJgmgr9PuuFcCi9bKH6ea Y1Sr9cSXPuw1g== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 1/3] bpf: verifier: Fix return value of fixup_call_args Date: Fri, 12 Jul 2024 22:24:16 +0800 Message-ID: <7f220cc167aac5a0a50b1e20da1390983d61b1f8.1720791489.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Run bloom_filter_map selftests (./test_progs -t bloom_filter_map) on a Loongarch platform, an error message "JIT doesn't support bpf-to-bpf calls" is got in user space, together with an unexpected errno EINVAL (22), not ENOTSUPP (524): libbpf: prog 'inner_map': BPF program load failed: Invalid argument libbpf: prog 'inner_map': -- BEGIN PROG LOAD LOG -- JIT doesn't support bpf-to-bpf calls callbacks are not allowed in non-JITed programs processed 37 insns (limit 1000000) max_states_per_insn 1 total_states -- END PROG LOAD LOG -- libbpf: prog 'inner_map': failed to load: -22 libbpf: failed to load object 'bloom_filter_map' libbpf: failed to load BPF skeleton 'bloom_filter_map': -22 setup_progs:FAIL:bloom_filter_map__open_and_load unexpected error: -22 #16 bloom_filter_map:FAIL Although the return value of jit_subprogs() does be set as "ENOTSUPP": verbose(env, "JIT doesn't support bpf-to-bpf calls\n"); err = -ENOTSUPP; goto out_free; But afterwards in fixup_call_args(), the return value of jit_subprogs() is ignored, and overwritten as "-EINVAL": verbose(env, "callbacks are not allowed in non-JITed programs\n"); return -EINVAL; This patch fixes this by changing return values of fixup_call_args() from "-EINVAL" to "err ?: -EINVAL". With this change, errno 524 is got in user space now: libbpf: prog 'inner_map': BPF program load failed: unknown error (-524) libbpf: prog 'inner_map': -- BEGIN PROG LOAD LOG -- JIT doesn't support bpf-to-bpf calls processed 37 insns (limit 1000000) max_states_per_insn 1 total_states -- END PROG LOAD LOG -- libbpf: prog 'inner_map': failed to load: -524 libbpf: failed to load object 'bloom_filter_map' libbpf: failed to load BPF skeleton 'bloom_filter_map': -524 setup_progs:FAIL:bloom_filter_map__open_and_load unexpected error: -524 Signed-off-by: Geliang Tang --- kernel/bpf/verifier.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index c0263fb5ca4b..aa589fedd036 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -19717,14 +19717,14 @@ static int fixup_call_args(struct bpf_verifier_env *env) #ifndef CONFIG_BPF_JIT_ALWAYS_ON if (has_kfunc_call) { verbose(env, "calling kernel functions are not allowed in non-JITed programs\n"); - return -EINVAL; + return err ?: -EINVAL; } if (env->subprog_cnt > 1 && env->prog->aux->tail_call_reachable) { /* When JIT fails the progs with bpf2bpf calls and tail_calls * have to be rejected, since interpreter doesn't support them yet. */ verbose(env, "tail_calls are not allowed in non-JITed programs with bpf-to-bpf calls\n"); - return -EINVAL; + return err ?: -EINVAL; } for (i = 0; i < prog->len; i++, insn++) { if (bpf_pseudo_func(insn)) { @@ -19732,7 +19732,7 @@ static int fixup_call_args(struct bpf_verifier_env *env) * have to be rejected, since interpreter doesn't support them yet. */ verbose(env, "callbacks are not allowed in non-JITed programs\n"); - return -EINVAL; + return err ?: -EINVAL; } if (!bpf_pseudo_call(insn)) From patchwork Fri Jul 12 14:24:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13731855 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F4EE13F439; Fri, 12 Jul 2024 14:24:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720794279; cv=none; b=UrCtofbyMYqFGvNVjqDc9wUrFTH9NL1lTk4p6B8UFlEz0Y8j9oMrqClXhpJ50mDnS80PGfoq3iBiisnDu3E5RPVqY32LeexF+RrcBfAga12+qvZPMIviM1lt89M6zgSQO+LYsqGRCI0gHgLdRk8LJA9OTfAvh2nxTHxSZLN4naU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720794279; c=relaxed/simple; bh=FOFEopIEgkSl/GAHe6VBDmsgPaR+r2/zBmzqcK309pA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sC+vtitIG9AUdxPE+YeLIlZmH1fEvrBpc+hD7LxaeIaYh539qpwqJtix7UgP6lVYpYXX7wb8DPqsSeoSj5EsCIfs2cWs8c49PWsLiLjAJ9khqEk6mK/NYU6Xttwe66ttlVVR6kc3dmVZgFdp+QK9Qk8u9+zch4lhiNsHYmEXCXU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kr26z2e0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kr26z2e0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9568C4AF0B; Fri, 12 Jul 2024 14:24:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720794278; bh=FOFEopIEgkSl/GAHe6VBDmsgPaR+r2/zBmzqcK309pA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kr26z2e0m4McpCRzPEx2PPfRdB7CVF4l5N6G9uSZ/iSn7J4e/duC3z5FAIbkXhfv9 a0LgrnMRKnhcJbOluYi4bxja/6fZiuehjZceM2vY4oiiDVaRO3BaU8p04WqUKJ3tAZ v0YYPLszNOlHMZ2I9IA8BA3YXdkADgQJR2o2ORTuAG2CoHWQV3Ry79+z2EKkAWAaY7 w8jix5agqUbEOKJE2DizuKF7FdVNIKIeWQLbA2xCG1dUYsSXt9Y56trqFZoMJ9gGPR cQ5VyWukTU4hLRjapPva7O+Tnw8OfRVsErqgkDd++gaB0tVJRJ8EpTShJLY7CZVA4s nyaNA9sf6tqNw== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 2/3] libbpf: handle ENOTSUPP in libbpf_strerror_r Date: Fri, 12 Jul 2024 22:24:17 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Errno 95 (ENOTSUP or EOPNOTSUPP) can be recognized by libbpf_strerror_r(), but 524 (ENOTSUPP) can't: prog 'basic_alloc3': BPF program load failed: Operation not supported prog 'basic_alloc3': failed to load: -95 failed to load object 'verifier_arena' FAIL:unexpected_load_failure unexpected error: -95 (errno 95) prog 'inner_map': BPF program load failed: unknown error (-524) prog 'inner_map': failed to load: -524 failed to load object 'bloom_filter_map' failed to load BPF skeleton 'bloom_filter_map': -524 FAIL:bloom_filter_map__open_and_load unexpected error: -524 This patch fixes this by handling ENOTSUPP in libbpf_strerror_r(). With this change, the new error string looks like: prog 'inner_map': BPF program load failed: Operation not supported Signed-off-by: Geliang Tang --- tools/lib/bpf/str_error.c | 18 +++++++++++++----- tools/lib/bpf/str_error.h | 4 ++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tools/lib/bpf/str_error.c b/tools/lib/bpf/str_error.c index 5e6a1e27ddf9..5eef2bc7fac5 100644 --- a/tools/lib/bpf/str_error.c +++ b/tools/lib/bpf/str_error.c @@ -15,7 +15,8 @@ */ char *libbpf_strerror_r(int err, char *dst, int len) { - int ret = strerror_r(err < 0 ? -err : err, dst, len); + unsigned int no = err < 0 ? -err : err; + int ret = strerror_r(no, dst, len); /* on glibc <2.13, ret == -1 and errno is set, if strerror_r() can't * handle the error, on glibc >=2.13 *positive* (errno-like) error * code is returned directly @@ -23,11 +24,18 @@ char *libbpf_strerror_r(int err, char *dst, int len) if (ret == -1) ret = errno; if (ret) { - if (ret == EINVAL) - /* strerror_r() doesn't recognize this specific error */ - snprintf(dst, len, "unknown error (%d)", err < 0 ? err : -err); - else + if (ret == EINVAL) { + switch (no) { + case ENOTSUPP: + snprintf(dst, len, "Operation not supported"); + break; + default: + /* strerror_r() doesn't recognize this specific error */ + snprintf(dst, len, "unknown error (-%u)", no); + } + } else { snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret); + } } return dst; } diff --git a/tools/lib/bpf/str_error.h b/tools/lib/bpf/str_error.h index 626d7ffb03d6..c41f6ba133cf 100644 --- a/tools/lib/bpf/str_error.h +++ b/tools/lib/bpf/str_error.h @@ -4,6 +4,10 @@ #define STRERR_BUFSIZE 128 +#ifndef ENOTSUPP +#define ENOTSUPP 524 +#endif + char *libbpf_strerror_r(int err, char *dst, int len); #endif /* __LIBBPF_STR_ERROR_H */ From patchwork Fri Jul 12 14:24:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13731856 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 691BC13F439; Fri, 12 Jul 2024 14:24:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720794284; cv=none; b=gHb3hzRu0luoyrJlo/Ka+9qS89GwaHMmoxVmUnBtPA34aN8rVkZgDwxUllXb7in7GSEXYxLB8WAroeKU/I5c7lCVulPUci1nXb5OAuXGOx5WUP1FbstRNnX/h07s5zcX3GXoSBpVHVbYeT9pteAt3ASUBWRyY2K/D/buIkNZlY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720794284; c=relaxed/simple; bh=06ifw7SQRypt3Wn5ttQJBek4EMBqirRgHFBshtecyKk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZP+213lyOYANDTda21VFioz7s6Enk/pZjwh17br384jqIDhJAMJ7YhQT3bLND6jZvha2YsQUdJ9Zc9i5m+VwE5x3Iyeak/YQleyaaNiWht62t7w+V+XQNXZih+aA2pWDUt+lSMf8i4T8Nm4Wuo+f6CQcX+IAsVFAG5NN5b4WcyU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uhHJr2fY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uhHJr2fY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69A27C32782; Fri, 12 Jul 2024 14:24:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720794283; bh=06ifw7SQRypt3Wn5ttQJBek4EMBqirRgHFBshtecyKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uhHJr2fY6WOYsyx66VG68oOKlorW0Z5Lz70FTz6zXSrfwBJF3n9vMCgLXgTSgcibU Xw3sgRdLd8E0DLfc7d6v6fHr7WA0bCShejU9spKpdjsoBnePEbyQ+Gm9B9lhxseBdh Uw162BaGqb6fDKOk5JcktcVo/DdCWI6Gla5OdOFomzjZEpLJa6sepOTJQx/VlM0Ow9 ZZYEvh2l4kI1u4VBjYVM9ikDzriWU9Xne6/l28bBcp0h1n9uIHWhCChTeeKfjZY8KT hlTZU3EShSfuqRklZ6jO7Tjo+GLMnKvNXBL0PwXqXC/IJ9TJaFCj3Gbhki7p5HdDb9 V//w49rnGIfsA== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v2 3/3] selftests/bpf: Drop duplicate ENOTSUPP definitions Date: Fri, 12 Jul 2024 22:24:18 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang ENOTSUPP is defined in bpf/str_error.h now, so no need to redefine it in so many places in bpf selftests. This patch includes in testing_helpers.h, which is almost included by each tests. And drop all duplicate definitions. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 4 ---- tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c | 4 ---- tools/testing/selftests/bpf/prog_tests/sock_addr.c | 4 ---- tools/testing/selftests/bpf/test_maps.c | 4 ---- tools/testing/selftests/bpf/test_verifier.c | 4 ---- tools/testing/selftests/bpf/testing_helpers.h | 1 + 6 files changed, 1 insertion(+), 20 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c index 1d494b4453f4..676eb7cd7fb0 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -16,10 +16,6 @@ #include "tcp_ca_kfunc.skel.h" #include "bpf_cc_cubic.skel.h" -#ifndef ENOTSUPP -#define ENOTSUPP 524 -#endif - static const unsigned int total_bytes = 10 * 1024 * 1024; static int expected_stg = 0xeB9F; diff --git a/tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c b/tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c index 130a3b21e467..6df25de8f080 100644 --- a/tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c +++ b/tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c @@ -10,10 +10,6 @@ #include "cgroup_helpers.h" #include "network_helpers.h" -#ifndef ENOTSUPP -#define ENOTSUPP 524 -#endif - static struct btf *btf; static __u32 query_prog_cnt(int cgroup_fd, const char *attach_func) diff --git a/tools/testing/selftests/bpf/prog_tests/sock_addr.c b/tools/testing/selftests/bpf/prog_tests/sock_addr.c index b880c564a204..68d9255d2bb7 100644 --- a/tools/testing/selftests/bpf/prog_tests/sock_addr.c +++ b/tools/testing/selftests/bpf/prog_tests/sock_addr.c @@ -23,10 +23,6 @@ #include "getpeername_unix_prog.skel.h" #include "network_helpers.h" -#ifndef ENOTSUPP -# define ENOTSUPP 524 -#endif - #define TEST_NS "sock_addr" #define TEST_IF_PREFIX "test_sock_addr" #define TEST_IPV4 "127.0.0.4" diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c index dfbab214f4d1..227d7d6eaf8e 100644 --- a/tools/testing/selftests/bpf/test_maps.c +++ b/tools/testing/selftests/bpf/test_maps.c @@ -26,10 +26,6 @@ #include "test_maps.h" #include "testing_helpers.h" -#ifndef ENOTSUPP -#define ENOTSUPP 524 -#endif - int skips; static struct bpf_map_create_opts map_opts = { .sz = sizeof(map_opts) }; diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index 610392dfc4fb..447b68509d76 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -42,10 +42,6 @@ #include "../../../include/linux/filter.h" #include "testing_helpers.h" -#ifndef ENOTSUPP -#define ENOTSUPP 524 -#endif - #define MAX_INSNS BPF_MAXINSNS #define MAX_EXPECTED_INSNS 32 #define MAX_UNEXPECTED_INSNS 32 diff --git a/tools/testing/selftests/bpf/testing_helpers.h b/tools/testing/selftests/bpf/testing_helpers.h index d55f6ab12433..1e882f408596 100644 --- a/tools/testing/selftests/bpf/testing_helpers.h +++ b/tools/testing/selftests/bpf/testing_helpers.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #define __TO_STR(x) #x