bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>,
	Andrii Nakryiko <andrii@kernel.org>
Subject: [PATCH bpf-next v5 02/12] bpf: factor out verbose_invalid_scalar()
Date: Fri, 26 Feb 2021 12:49:22 -0800	[thread overview]
Message-ID: <20210226204922.3884375-1-yhs@fb.com> (raw)
In-Reply-To: <20210226204920.3884074-1-yhs@fb.com>

Factor out the function verbose_invalid_scalar() to verbose
print if a scalar is not in a tnum range. There is no
functionality change and the function will be used by
later patch which introduced bpf_for_each_map_elem().

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
---
 kernel/bpf/verifier.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index b14fab7a7a16..7194980c3ca4 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -390,6 +390,24 @@ __printf(3, 4) static void verbose_linfo(struct bpf_verifier_env *env,
 	env->prev_linfo = linfo;
 }
 
+static void verbose_invalid_scalar(struct bpf_verifier_env *env,
+				   struct bpf_reg_state *reg,
+				   struct tnum *range, const char *ctx,
+				   const char *reg_name)
+{
+	char tn_buf[48];
+
+	verbose(env, "At %s the register %s ", ctx, reg_name);
+	if (!tnum_is_unknown(reg->var_off)) {
+		tnum_strn(tn_buf, sizeof(tn_buf), reg->var_off);
+		verbose(env, "has value %s", tn_buf);
+	} else {
+		verbose(env, "has unknown scalar value");
+	}
+	tnum_strn(tn_buf, sizeof(tn_buf), *range);
+	verbose(env, " should have been in %s\n", tn_buf);
+}
+
 static bool type_is_pkt_pointer(enum bpf_reg_type type)
 {
 	return type == PTR_TO_PACKET ||
@@ -8455,17 +8473,7 @@ static int check_return_code(struct bpf_verifier_env *env)
 	}
 
 	if (!tnum_in(range, reg->var_off)) {
-		char tn_buf[48];
-
-		verbose(env, "At program exit the register R0 ");
-		if (!tnum_is_unknown(reg->var_off)) {
-			tnum_strn(tn_buf, sizeof(tn_buf), reg->var_off);
-			verbose(env, "has value %s", tn_buf);
-		} else {
-			verbose(env, "has unknown scalar value");
-		}
-		tnum_strn(tn_buf, sizeof(tn_buf), range);
-		verbose(env, " should have been in %s\n", tn_buf);
+		verbose_invalid_scalar(env, reg, &range, "program exit", "R0");
 		return -EINVAL;
 	}
 
-- 
2.24.1


  parent reply	other threads:[~2021-02-26 20:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-26 20:49 [PATCH bpf-next v5 00/12] bpf: add bpf_for_each_map_elem() helper Yonghong Song
2021-02-26 20:49 ` [PATCH bpf-next v5 01/12] bpf: factor out visit_func_call_insn() in check_cfg() Yonghong Song
2021-02-26 20:49 ` Yonghong Song [this message]
2021-02-26 20:49 ` [PATCH bpf-next v5 03/12] bpf: refactor check_func_call() to allow callback function Yonghong Song
2021-02-26 20:49 ` [PATCH bpf-next v5 04/12] bpf: change return value of verifier function add_subprog() Yonghong Song
2021-02-26 20:49 ` [PATCH bpf-next v5 05/12] bpf: add bpf_for_each_map_elem() helper Yonghong Song
2021-02-26 21:29   ` Alexei Starovoitov
2021-02-26 20:49 ` [PATCH bpf-next v5 06/12] bpf: add hashtab support for " Yonghong Song
2021-02-26 20:49 ` [PATCH bpf-next v5 07/12] bpf: add arraymap " Yonghong Song
2021-02-26 20:49 ` [PATCH bpf-next v5 08/12] libbpf: move function is_ldimm64() earlier in libbpf.c Yonghong Song
2021-02-26 20:49 ` [PATCH bpf-next v5 09/12] libbpf: support subprog address relocation Yonghong Song
2021-02-26 20:49 ` [PATCH bpf-next v5 10/12] bpftool: print subprog address properly Yonghong Song
2021-02-26 20:49 ` [PATCH bpf-next v5 11/12] selftests/bpf: add hashmap test for bpf_for_each_map_elem() helper Yonghong Song
2021-02-26 20:49 ` [PATCH bpf-next v5 12/12] selftests/bpf: add arraymap " Yonghong Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210226204922.3884375-1-yhs@fb.com \
    --to=yhs@fb.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).