From patchwork Fri Jul 12 10:14:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13731575 X-Patchwork-Delegate: bpf@iogearbox.net 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 E6C1A13F439 for ; Fri, 12 Jul 2024 10:14:27 +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=1720779268; cv=none; b=k/a2hiWDAEwa+uHGLVxqpRBzAvlG9tGAuOMJuSe5NOm5hQ6UazRWnmLBUQNRFUdfxtiAANMmVpXbZimHq8QifAeSqsOSHnaWbnQIw6Pm7hM57wpSkCNUlzqe2ugeJOWQj+GNHvqJLRj7AoPdS0Knj9DiD8SkQssmGSxfg17s0k0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720779268; c=relaxed/simple; bh=TgYjiAZYqqzS3zDX6P4Okluhp9fFgIXHODSjz8qNH+A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KUn4CeQU1m8r51XKLHkNFvYZr0qKcwiDecP60d3EG6PsKzxfVLcfbfIyX48HeQm3wRd9KS8W4e73q4BN2mFRlz8oIQWHbJGKMXMXpCPytcqvfQZWe7Z9zKWA/xu4WyccpfCZELilH2ccdu65DmkhQBUHFvYLWXYmtU47rARES7k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WhItA0dN; 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="WhItA0dN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EE57C32782; Fri, 12 Jul 2024 10:14:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720779267; bh=TgYjiAZYqqzS3zDX6P4Okluhp9fFgIXHODSjz8qNH+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WhItA0dNIfMoDhjMr2uUUrxLcxKXZp/ZVyusEVFfDezJfNnekHOa1PIgF8gOo1cfg aeO+knzSlB/+RmouOXkL5y3tNR0ruCCrPpXXdSGBoDA2BdA5z10ebqXG/9FWa22V7M kYtt4UH5hAr4tS3HaHF7vD/W2uDwQPKJoj7NrSZvosNwOLbTFzIkz3B243rWRCc5/x CcKD1W2Wj6zQyjijfHYGVRL0p9JBu4l9OpzB8NvDsruYg7wiRq3tZWMsPEOvics5GD Ji0exViGX60TeKKuXHcXr2UvSEERSFEaFo+Wof63OUOUIxJUmcweFwEGw5DBIJdcjA MkqjNPY90im9g== From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: Geliang Tang , bpf@vger.kernel.org Subject: [PATCH bpf-next 1/2] bpf: verifier: Fix return value of fixup_call_args Date: Fri, 12 Jul 2024 18:14:12 +0800 Message-ID: <9a002aaf658c4dfb3997cf9c5981b3b2350e5c30.1720778831.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net 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 in jit_subprogs(), the error number 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(), such error number 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 10:14:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13731576 X-Patchwork-Delegate: bpf@iogearbox.net 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 A93B013F439 for ; Fri, 12 Jul 2024 10:14:32 +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=1720779272; cv=none; b=tjG3rfaq/6SDta0xAMxWGbHAtyFzpl8gLZhuWUL2ZfH7tU/0s4dFQkSAoZZiApAqLfwrHNBL+8rpQdVgcz1K36KLBwqTeCiJPZlLr9m/jXvGT9RTd1CYg790DPXrR8f+kNn2DsCUL2WiR6xVYIYZ4FR6qhe5kHwVNghrj3yoCZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720779272; c=relaxed/simple; bh=g1+jAoMq8Ne+lB0G0K685swodoixr2G/5iQQX4BxL/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BcMVtrWi4wBajlSLf4g9XW3C9XNCDppG6jIN0r1wj+eCYhQB4XsCEt5cG6z+kBZFZbm1tiKo/WO0E0Cy9NP8XePC7qMjYv4abMjDPuB69H0RkTQHQ5i1cCmZHUbteFjSINhbcq4qUgO7esMLghhluVboDsS7o+KcTqBwDkEm9Es= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BYkU00dn; 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="BYkU00dn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F8FEC32782; Fri, 12 Jul 2024 10:14:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720779272; bh=g1+jAoMq8Ne+lB0G0K685swodoixr2G/5iQQX4BxL/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BYkU00dnUy/yPRWPe/b9i75w4X3tXWj6/+yn2sX3H7XeiHenaPN+1KcX/b70pLqx2 wi3axfK7F/lWQ2Mr8PvHU1aq8WN5s5fXlJztzLi4p0oKlkCWCy+nxPadjN9h6o/7OZ 1NuMOSwY2nuTIR2nud+M3k9WhA0XmJFrwGAc2Ge4Hc/nMtYtJL9TSuLEXpeyd+ufRn 4CiW2t7p/CrAnkmggABpa4htrB3Fs8qC49wOuI8Nx1H/P+WZC54MgSGJ6zf63yUzfi pC/Bz8i43M7yEYa8z4xl4nyzu+oboOaIMyVV2momZ6+4GyAaWdEOdSdhRCBJQtnfIY NAsMt+QO8QnBA== From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: Geliang Tang , bpf@vger.kernel.org Subject: [PATCH bpf-next 2/2] libbpf: handle ENOTSUPP in libbpf_strerror_r Date: Fri, 12 Jul 2024 18:14:13 +0800 Message-ID: <2437275bb988da5c187b4d0223e5c0c9843fdc76.1720778831.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang The errno 95 (ENOTSUP or EOPNOTSUPP) can be recognized by 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 (-524) Signed-off-by: Geliang Tang --- tools/lib/bpf/str_error.c | 11 +++++++---- tools/lib/bpf/str_error.h | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/lib/bpf/str_error.c b/tools/lib/bpf/str_error.c index 5e6a1e27ddf9..10597d5124cd 100644 --- a/tools/lib/bpf/str_error.c +++ b/tools/lib/bpf/str_error.c @@ -23,10 +23,13 @@ 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) { + if (err == ENOTSUPP) + snprintf(dst, len, "Operation not supported (%d)", -err); + else + /* strerror_r() doesn't recognize this specific error */ + snprintf(dst, len, "unknown error (%d)", err < 0 ? err : -err); + } 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 */