diff mbox series

[11/14] bpf/tests: Add test for 32-bit context pointer argument passing

Message ID 20210728170502.351010-12-johan.almbladh@anyfinetworks.com
State Superseded
Headers show
Series [01/14] bpf/tests: Add BPF_JMP32 test cases | expand

Commit Message

Johan Almbladh July 28, 2021, 5:04 p.m. UTC
On a 32-bit architecture, the context pointer should occupy the low
half of R0, and the other half should be zero.

Signed-off-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
---
 lib/test_bpf.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Yonghong Song July 29, 2021, 12:09 a.m. UTC | #1
On 7/28/21 10:04 AM, Johan Almbladh wrote:
> On a 32-bit architecture, the context pointer should occupy the low
> half of R0, and the other half should be zero.

I think this is probably true. The word choice "should" indicates
this doesn't need to be the case if people choose a different
implementation, right?

> 
> Signed-off-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
> ---
>   lib/test_bpf.c | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
> 
> diff --git a/lib/test_bpf.c b/lib/test_bpf.c
> index 55914b6236aa..314af6eaeb92 100644
> --- a/lib/test_bpf.c
> +++ b/lib/test_bpf.c
> @@ -2084,6 +2084,22 @@ static struct bpf_test tests[] = {
>   #undef NUMER
>   #undef DENOM
>   	},
> +#ifdef CONFIG_32BIT
> +	{
> +		"INT: 32-bit context pointer word order and zero-extension",
> +		.u.insns_int = {
> +			BPF_ALU32_IMM(BPF_MOV, R0, 0),
> +			BPF_JMP32_IMM(BPF_JEQ, R1, 0, 3),
> +			BPF_ALU64_IMM(BPF_RSH, R1, 32),
> +			BPF_JMP32_IMM(BPF_JNE, R1, 0, 1),
> +			BPF_ALU32_IMM(BPF_MOV, R0, 1),
> +			BPF_EXIT_INSN(),
> +		},
> +		INTERNAL,
> +		{ },
> +		{ { 0, 1 } }
> +	},
> +#endif
>   	{
>   		"check: missing ret",
>   		.u.insns = {
>
Johan Almbladh July 29, 2021, 1:29 p.m. UTC | #2
On Thu, Jul 29, 2021 at 2:09 AM Yonghong Song <yhs@fb.com> wrote:
> On 7/28/21 10:04 AM, Johan Almbladh wrote:

> > On a 32-bit architecture, the context pointer should occupy the low

> > half of R0, and the other half should be zero.

>

> I think this is probably true. The word choice "should" indicates

> this doesn't need to be the case if people choose a different

> implementation, right?

>


Right. To the best of my knowledge this is true. I can change the
wording to "will" to remove the ambiguity.
Yonghong Song July 29, 2021, 3:50 p.m. UTC | #3
On 7/29/21 6:29 AM, Johan Almbladh wrote:
> On Thu, Jul 29, 2021 at 2:09 AM Yonghong Song <yhs@fb.com> wrote:

>> On 7/28/21 10:04 AM, Johan Almbladh wrote:

>>> On a 32-bit architecture, the context pointer should occupy the low

>>> half of R0, and the other half should be zero.

>>

>> I think this is probably true. The word choice "should" indicates

>> this doesn't need to be the case if people choose a different

>> implementation, right?

>>

> 

> Right. To the best of my knowledge this is true. I can change the

> wording to "will" to remove the ambiguity.


Sounds good. thanks!
diff mbox series

Patch

diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index 55914b6236aa..314af6eaeb92 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -2084,6 +2084,22 @@  static struct bpf_test tests[] = {
 #undef NUMER
 #undef DENOM
 	},
+#ifdef CONFIG_32BIT
+	{
+		"INT: 32-bit context pointer word order and zero-extension",
+		.u.insns_int = {
+			BPF_ALU32_IMM(BPF_MOV, R0, 0),
+			BPF_JMP32_IMM(BPF_JEQ, R1, 0, 3),
+			BPF_ALU64_IMM(BPF_RSH, R1, 32),
+			BPF_JMP32_IMM(BPF_JNE, R1, 0, 1),
+			BPF_ALU32_IMM(BPF_MOV, R0, 1),
+			BPF_EXIT_INSN(),
+		},
+		INTERNAL,
+		{ },
+		{ { 0, 1 } }
+	},
+#endif
 	{
 		"check: missing ret",
 		.u.insns = {