Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Johan Almbladh <johan.almbladh@anyfinetworks.com>,
	<ast@kernel.org>, <daniel@iogearbox.net>, <andrii@kernel.org>
Cc: <kafai@fb.com>, <songliubraving@fb.com>,
	<john.fastabend@gmail.com>, <kpsingh@kernel.org>,
	<Tony.Ambardar@gmail.com>, <netdev@vger.kernel.org>,
	<bpf@vger.kernel.org>
Subject: Re: [PATCH 01/14] bpf/tests: Add BPF_JMP32 test cases
Date: Wed, 28 Jul 2021 15:31:28 -0700	[thread overview]
Message-ID: <ede57ee2-a975-b98c-5978-102280a77d8c@fb.com> (raw)
In-Reply-To: <20210728170502.351010-2-johan.almbladh@anyfinetworks.com>



On 7/28/21 10:04 AM, Johan Almbladh wrote:
> An eBPF JIT may implement JMP32 operations in a different way than JMP,
> especially on 32-bit architectures. This patch adds a series of tests
> for JMP32 operations, mainly for testing JITs.
> 
> Signed-off-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>

LGTM with a few minor comments below.

Acked-by: Yonghong Song <yhs@fb.com>

> ---
>   lib/test_bpf.c | 511 +++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 511 insertions(+)
> 
> diff --git a/lib/test_bpf.c b/lib/test_bpf.c
> index f6d5d30d01bf..bfac033db590 100644
> --- a/lib/test_bpf.c
> +++ b/lib/test_bpf.c
> @@ -4398,6 +4398,517 @@ static struct bpf_test tests[] = {
>   		{ { 0, 4134 } },
>   		.fill_helper = bpf_fill_stxdw,
>   	},
> +	/* BPF_JMP32 | BPF_JEQ | BPF_K */
> +	{
> +		"JMP32_JEQ_K: Small immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, 123),
> +			BPF_JMP32_IMM(BPF_JEQ, R0, 321, 1),
> +			BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, 123 } }
> +	},
[...]
> +	/* BPF_JMP32 | BPF_JGT | BPF_X */
> +	{
> +		"JMP32_JGT_X",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
> +			BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
> +			BPF_JMP32_REG(BPF_JGT, R0, R1, 1),

Maybe change the offset from 1 to 2? Otherwise, this may jump to
   BPF_JMP32_REG(BPF_JGT, R0, R1, 1)
which will just do the same comparison and jump to BTT_EXIT_INSN()
which will also have R0 = 0xfffffffe at the end.

> +			BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
> +			BPF_JMP32_REG(BPF_JGT, R0, R1, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, 0xfffffffe } }
> +	},
> +	/* BPF_JMP32 | BPF_JGE | BPF_K */
> +	{
> +		"JMP32_JGE_K: Small immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, 123),
> +			BPF_JMP32_IMM(BPF_JGE, R0, 124, 1),
> +			BPF_JMP32_IMM(BPF_JGE, R0, 123, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, 123 } }
> +	},
> +	{
> +		"JMP32_JGE_K: Large immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
> +			BPF_JMP32_IMM(BPF_JGE, R0, 0xffffffff, 1),
> +			BPF_JMP32_IMM(BPF_JGE, R0, 0xfffffffe, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, 0xfffffffe } }
> +	},
> +	/* BPF_JMP32 | BPF_JGE | BPF_X */
> +	{
> +		"JMP32_JGE_X",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
> +			BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
> +			BPF_JMP32_REG(BPF_JGE, R0, R1, 1),

ditto, change offset 1 to 2?

> +			BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
> +			BPF_JMP32_REG(BPF_JGE, R0, R1, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, 0xfffffffe } }
> +	},
> +	/* BPF_JMP32 | BPF_JLT | BPF_K */
> +	{
> +		"JMP32_JLT_K: Small immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, 123),
> +			BPF_JMP32_IMM(BPF_JLT, R0, 123, 1),
> +			BPF_JMP32_IMM(BPF_JLT, R0, 124, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, 123 } }
> +	},
> +	{
> +		"JMP32_JLT_K: Large immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
> +			BPF_JMP32_IMM(BPF_JLT, R0, 0xfffffffd, 1),
> +			BPF_JMP32_IMM(BPF_JLT, R0, 0xffffffff, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, 0xfffffffe } }
> +	},
> +	/* BPF_JMP32 | BPF_JLT | BPF_X */
> +	{
> +		"JMP32_JLT_X",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
> +			BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
> +			BPF_JMP32_REG(BPF_JLT, R0, R1, 1),

ditto.

> +			BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
> +			BPF_JMP32_REG(BPF_JLT, R0, R1, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, 0xfffffffe } }
> +	},
> +	/* BPF_JMP32 | BPF_JLE | BPF_K */
> +	{
> +		"JMP32_JLE_K: Small immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, 123),
> +			BPF_JMP32_IMM(BPF_JLE, R0, 122, 1),
> +			BPF_JMP32_IMM(BPF_JLE, R0, 123, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, 123 } }
> +	},
> +	{
> +		"JMP32_JLE_K: Large immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
> +			BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffd, 1),
> +			BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffe, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, 0xfffffffe } }
> +	},
> +	/* BPF_JMP32 | BPF_JLE | BPF_X */
> +	{
> +		"JMP32_JLE_X",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
> +			BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
> +			BPF_JMP32_REG(BPF_JLE, R0, R1, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
> +			BPF_JMP32_REG(BPF_JLE, R0, R1, 1),

ditto

> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, 0xfffffffe } }
> +	},
> +	/* BPF_JMP32 | BPF_JSGT | BPF_K */
> +	{
> +		"JMP32_JSGT_K: Small immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, -123),
> +			BPF_JMP32_IMM(BPF_JSGT, R0, -123, 1),
> +			BPF_JMP32_IMM(BPF_JSGT, R0, -124, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, -123 } }
> +	},
> +	{
> +		"JMP32_JSGT_K: Large immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
> +			BPF_JMP32_IMM(BPF_JSGT, R0, -12345678, 1),
> +			BPF_JMP32_IMM(BPF_JSGT, R0, -12345679, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, -12345678 } }
> +	},
> +	/* BPF_JMP32 | BPF_JSGT | BPF_X */
> +	{
> +		"JMP32_JSGT_X",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
> +			BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
> +			BPF_JMP32_REG(BPF_JSGT, R0, R1, 1),

ditto

> +			BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
> +			BPF_JMP32_REG(BPF_JSGT, R0, R1, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, -12345678 } }
> +	},
> +	/* BPF_JMP32 | BPF_JSGE | BPF_K */
> +	{
> +		"JMP32_JSGE_K: Small immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, -123),
> +			BPF_JMP32_IMM(BPF_JSGE, R0, -122, 1),
> +			BPF_JMP32_IMM(BPF_JSGE, R0, -123, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, -123 } }
> +	},
> +	{
> +		"JMP32_JSGE_K: Large immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
> +			BPF_JMP32_IMM(BPF_JSGE, R0, -12345677, 1),
> +			BPF_JMP32_IMM(BPF_JSGE, R0, -12345678, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, -12345678 } }
> +	},
> +	/* BPF_JMP32 | BPF_JSGE | BPF_X */
> +	{
> +		"JMP32_JSGE_X",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
> +			BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
> +			BPF_JMP32_REG(BPF_JSGE, R0, R1, 1),

ditto

> +			BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
> +			BPF_JMP32_REG(BPF_JSGE, R0, R1, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, -12345678 } }
> +	},
> +	/* BPF_JMP32 | BPF_JSLT | BPF_K */
> +	{
> +		"JMP32_JSLT_K: Small immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, -123),
> +			BPF_JMP32_IMM(BPF_JSLT, R0, -123, 1),
> +			BPF_JMP32_IMM(BPF_JSLT, R0, -122, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, -123 } }
> +	},
> +	{
> +		"JMP32_JSLT_K: Large immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
> +			BPF_JMP32_IMM(BPF_JSLT, R0, -12345678, 1),
> +			BPF_JMP32_IMM(BPF_JSLT, R0, -12345677, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, -12345678 } }
> +	},
> +	/* BPF_JMP32 | BPF_JSLT | BPF_X */
> +	{
> +		"JMP32_JSLT_X",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
> +			BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
> +			BPF_JMP32_REG(BPF_JSLT, R0, R1, 1),

ditto

> +			BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
> +			BPF_JMP32_REG(BPF_JSLT, R0, R1, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, -12345678 } }
> +	},
> +	/* BPF_JMP32 | BPF_JSLE | BPF_K */
> +	{
> +		"JMP32_JSLE_K: Small immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, -123),
> +			BPF_JMP32_IMM(BPF_JSLE, R0, -124, 1),
> +			BPF_JMP32_IMM(BPF_JSLE, R0, -123, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, -123 } }
> +	},
> +	{
> +		"JMP32_JSLE_K: Large immediate",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
> +			BPF_JMP32_IMM(BPF_JSLE, R0, -12345679, 1),
> +			BPF_JMP32_IMM(BPF_JSLE, R0, -12345678, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, -12345678 } }
> +	},
> +	/* BPF_JMP32 | BPF_JSLE | BPF_K */
> +	{
> +		"JMP32_JSLE_X",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
> +			BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
> +			BPF_JMP32_REG(BPF_JSLE, R0, R1, 1),

ditto

> +			BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
> +			BPF_JMP32_REG(BPF_JSLE, R0, R1, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, -12345678 } }
> +	},
>   	/* BPF_JMP | BPF_EXIT */
>   	{
>   		"JMP_EXIT",
> 

  reply	other threads:[~2021-07-28 22:31 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-28 17:04 [PATCH 00/14] bpf/tests: Extend the eBPF test suite Johan Almbladh
2021-07-28 17:04 ` [PATCH 01/14] bpf/tests: Add BPF_JMP32 test cases Johan Almbladh
2021-07-28 22:31   ` Yonghong Song [this message]
2021-07-29 21:30     ` Johan Almbladh
2021-07-28 17:04 ` [PATCH 02/14] bpf/tests: Add BPF_MOV tests for zero and sign extension Johan Almbladh
2021-07-28 22:36   ` Yonghong Song
2021-07-28 17:04 ` [PATCH 03/14] bpf/tests: Fix typos in test case descriptions Johan Almbladh
2021-07-28 22:43   ` Yonghong Song
2021-07-28 17:04 ` [PATCH 04/14] bpf/tests: Add more tests of ALU32 and ALU64 bitwise operations Johan Almbladh
2021-07-28 22:53   ` Yonghong Song
2021-07-28 17:04 ` [PATCH 05/14] bpf/tests: Add more ALU32 tests for BPF_LSH/RSH/ARSH Johan Almbladh
2021-07-28 22:57   ` Yonghong Song
2021-07-28 17:04 ` [PATCH 06/14] bpf/tests: Add more BPF_LSH/RSH/ARSH tests for ALU64 Johan Almbladh
2021-07-28 23:30   ` Yonghong Song
2021-07-29 12:34     ` Johan Almbladh
2021-07-29 15:39       ` Yonghong Song
2021-07-28 17:04 ` [PATCH 07/14] bpf/tests: Add more ALU64 BPF_MUL tests Johan Almbladh
2021-07-28 23:32   ` Yonghong Song
2021-07-29 21:21     ` Johan Almbladh
2021-07-28 17:04 ` [PATCH 08/14] bpf/tests: Add tests for ALU operations implemented with function calls Johan Almbladh
2021-07-28 23:52   ` Yonghong Song
2021-07-29 21:17     ` Johan Almbladh
2021-07-29 22:54       ` Yonghong Song
2021-07-28 17:04 ` [PATCH 09/14] bpf/tests: Add word-order tests for load/store of double words Johan Almbladh
2021-07-28 23:54   ` Yonghong Song
2021-07-28 17:04 ` [PATCH 10/14] bpf/tests: Add branch conversion JIT test Johan Almbladh
2021-07-28 23:58   ` Yonghong Song
2021-07-29 12:45     ` Johan Almbladh
2021-07-29 15:46       ` Yonghong Song
2021-07-29  0:55   ` Yonghong Song
2021-07-29 13:24     ` Johan Almbladh
2021-07-29 15:50       ` Yonghong Song
2021-07-28 17:04 ` [PATCH 11/14] bpf/tests: Add test for 32-bit context pointer argument passing Johan Almbladh
2021-07-29  0:09   ` Yonghong Song
2021-07-29 13:29     ` Johan Almbladh
2021-07-29 15:50       ` Yonghong Song
2021-07-28 17:05 ` [PATCH 12/14] bpf/tests: Add tests for atomic operations Johan Almbladh
2021-07-29  0:36   ` Yonghong Song
2021-07-28 17:05 ` [PATCH 13/14] bpf/tests: Add tests for BPF_CMPXCHG Johan Almbladh
2021-07-29  0:45   ` Yonghong Song
2021-07-28 17:05 ` [PATCH 14/14] bpf/tests: Add tail call test suite Johan Almbladh
2021-07-29  2:56   ` Yonghong Song
2021-07-29 20:44     ` Johan Almbladh

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=ede57ee2-a975-b98c-5978-102280a77d8c@fb.com \
    --to=yhs@fb.com \
    --cc=Tony.Ambardar@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=johan.almbladh@anyfinetworks.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --subject='Re: [PATCH 01/14] bpf/tests: Add BPF_JMP32 test cases' \
    /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

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox