BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Dimitar Kanaliev <dimitar.kanaliev@siteground.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	 John Fastabend <john.fastabend@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau	 <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>, KP Singh <kpsingh@kernel.org>,
	 Stanislav Fomichev	 <sdf@fomichev.me>,
	Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>,
	 Mykola Lysenko	 <mykolal@fb.com>,
	Yonghong Song <yonghong.song@linux.dev>,
	Shung-Hsi Yu	 <shung-hsi.yu@suse.com>
Subject: Re: [PATCH v0 3/3] selftests/bpf: Extend tests with more coverage for sign extension
Date: Thu, 30 Jan 2025 14:48:48 -0800	[thread overview]
Message-ID: <1622c76ba2b780105de3c25502357a527b18b4d8.camel@gmail.com> (raw)
In-Reply-To: <20250130112342.69843-4-dimitar.kanaliev@siteground.com>

On Thu, 2025-01-30 at 13:23 +0200, Dimitar Kanaliev wrote:
> This commit adds a few more tests related to tnum_scast that explicitly
> check cases with known / unknown sign bit, as well as values that cross
> zero (going from negative to positive).
> 
> Signed-off-by: Dimitar Kanaliev <dimitar.kanaliev@siteground.com>
> ---
>  .../selftests/bpf/progs/verifier_movsx.c      | 73 +++++++++++++++++++
>  1 file changed, 73 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/progs/verifier_movsx.c b/tools/testing/selftests/bpf/progs/verifier_movsx.c
> index 994bbc346d25..20abeec09dee 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_movsx.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_movsx.c
> @@ -327,6 +327,79 @@ label_%=: 	                                        \
>  	: __clobber_all);
>  }
>  
> +SEC("socket")
> +__description("MOV64SX, S8, unknown value")
> +__success __success_unpriv __retval(1)

Note: __retval() annotation is needed when one wants to execute the
      test using libbpf's bpf_prog_test_run_opts().
      The changes for register range tracking should not affect
      runtime behaviour (unless there is a bug in and some dead code
      elimination is done incorrectly).
      I suggest to add __log_level(2) annotation and check verifier
      log output using __msg() annotations to check what range is
      inferred for specific registers.
      As-is these new tests are passing on master as well,
      so the feature is effectively untested.

> +__naked void mov64sx_s8_unknown(void)
> +{
> +	asm volatile ("                                      \
> +	call %[bpf_get_prandom_u32];                         \
> +	r1 = r0;                                             \
> +	r1 &= 0xFF;      			             \
> +	r1 = (s8)r1;  					     \
> +	if r1 s>= -128 goto l0_%=;                           \
> +	r0 = 0;                                              \
> +	exit;                                                \
> +l0_%=:                                                       \
> +	if r1 s<= 127 goto l1_%=;                            \
> +	r0 = 0;                                              \
> +	exit;                                                \
> +l1_%=:                                                       \
> +	r0 = 1;                                              \
> +	exit;                                                \
> +"	:
> +	: __imm(bpf_get_prandom_u32)
> +	: __clobber_all);
> +}

[...]


      reply	other threads:[~2025-01-30 22:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-30 11:23 [PATCH v0 0/3] Add tnum_scast helper Dimitar Kanaliev
2025-01-30 11:23 ` [PATCH v0 1/3] bpf: Introduce tnum_scast as a tnum native sign extension helper Dimitar Kanaliev
2025-01-30 21:59   ` Eduard Zingerman
2025-01-30 11:23 ` [PATCH v0 2/3] bpf: verifier: Simplify register sign extension with tnum_scast Dimitar Kanaliev
2025-01-30 23:24   ` Eduard Zingerman
2025-01-30 11:23 ` [PATCH v0 3/3] selftests/bpf: Extend tests with more coverage for sign extension Dimitar Kanaliev
2025-01-30 22:48   ` Eduard Zingerman [this message]

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=1622c76ba2b780105de3c25502357a527b18b4d8.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dimitar.kanaliev@siteground.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=sdf@fomichev.me \
    --cc=shung-hsi.yu@suse.com \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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