diff mbox series

[bpf-next] selftests/bpf: Use _REGION1_SIZE in test_snprintf_btf on s390

Message ID 20210226135923.114211-1-iii@linux.ibm.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: Use _REGION1_SIZE in test_snprintf_btf on s390 | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 10 maintainers not CCed: netdev@vger.kernel.org shuah@kernel.org kpsingh@kernel.org songliubraving@fb.com linux-kselftest@vger.kernel.org yhs@fb.com kafai@fb.com john.fastabend@gmail.com alan.maguire@oracle.com andrii@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 24 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Ilya Leoshkevich Feb. 26, 2021, 1:59 p.m. UTC
test_snprintf_btf fails on s390, because NULL points to a readable
struct lowcore there. Fix by using _REGION1_SIZE instead.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 tools/testing/selftests/bpf/progs/netif_receive_skb.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Yonghong Song Feb. 26, 2021, 5:19 p.m. UTC | #1
On 2/26/21 5:59 AM, Ilya Leoshkevich wrote:
> test_snprintf_btf fails on s390, because NULL points to a readable
> struct lowcore there. Fix by using _REGION1_SIZE instead.
> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>

Ack with a minor nit below.

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

> ---
>   tools/testing/selftests/bpf/progs/netif_receive_skb.c | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/progs/netif_receive_skb.c b/tools/testing/selftests/bpf/progs/netif_receive_skb.c
> index 6b670039ea67..fa54d2abc41e 100644
> --- a/tools/testing/selftests/bpf/progs/netif_receive_skb.c
> +++ b/tools/testing/selftests/bpf/progs/netif_receive_skb.c
> @@ -16,6 +16,13 @@ bool skip = false;
>   #define STRSIZE			2048
>   #define EXPECTED_STRSIZE	256
>   
> +#if defined(bpf_target_s390)
> +/* NULL points to a readable struct lowcore on s390, so take _REGION1_SIZE */
> +#define BADPTR			((void *)(1ULL << 53))
> +#else
> +#define BADPTR			0
> +#endif
> +
>   #ifndef ARRAY_SIZE
>   #define ARRAY_SIZE(x)	(sizeof(x) / sizeof((x)[0]))
>   #endif
> @@ -114,9 +121,9 @@ int BPF_PROG(trace_netif_receive_skb, struct sk_buff *skb)
>   
>   	/* Check invalid ptr value */
>   	p.ptr = 0;
> -	__ret = bpf_snprintf_btf(str, STRSIZE, &p, sizeof(p), 0);
> +	__ret = bpf_snprintf_btf(str, STRSIZE, &p, sizeof(p), BADPTR);
>   	if (__ret >= 0) {
> -		bpf_printk("printing NULL should generate error, got (%d)",
> +		bpf_printk("printing BADPTR should generate error, got (%d)",
>   			   __ret);

The previous error message NULL implies address 0. The new error message
did not print out the badptr address. Do you want to print them out so
in case of errors, you don't need to search source code?

>   		ret = -ERANGE;
>   	}
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/progs/netif_receive_skb.c b/tools/testing/selftests/bpf/progs/netif_receive_skb.c
index 6b670039ea67..fa54d2abc41e 100644
--- a/tools/testing/selftests/bpf/progs/netif_receive_skb.c
+++ b/tools/testing/selftests/bpf/progs/netif_receive_skb.c
@@ -16,6 +16,13 @@  bool skip = false;
 #define STRSIZE			2048
 #define EXPECTED_STRSIZE	256
 
+#if defined(bpf_target_s390)
+/* NULL points to a readable struct lowcore on s390, so take _REGION1_SIZE */
+#define BADPTR			((void *)(1ULL << 53))
+#else
+#define BADPTR			0
+#endif
+
 #ifndef ARRAY_SIZE
 #define ARRAY_SIZE(x)	(sizeof(x) / sizeof((x)[0]))
 #endif
@@ -114,9 +121,9 @@  int BPF_PROG(trace_netif_receive_skb, struct sk_buff *skb)
 
 	/* Check invalid ptr value */
 	p.ptr = 0;
-	__ret = bpf_snprintf_btf(str, STRSIZE, &p, sizeof(p), 0);
+	__ret = bpf_snprintf_btf(str, STRSIZE, &p, sizeof(p), BADPTR);
 	if (__ret >= 0) {
-		bpf_printk("printing NULL should generate error, got (%d)",
+		bpf_printk("printing BADPTR should generate error, got (%d)",
 			   __ret);
 		ret = -ERANGE;
 	}