Skip to contentSkip to conversation

selftests/bpf: Use _REGION1_SIZE in test_snprintf_btf on s390

PATCH Superseded Ilya Leoshkevich 2 participants 2 messages Feb 26, 2021

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftests/bpf: Use _REGION1_SIZE in test_snprintf_btf on s390

test_snprintf_btf fails on s390, because NULL points to a readable struct lowcore there. Fix by using _REGION1_SIZE instead.

Error message example:

    printing 0000000000000000 should generate error, got (361)

---

v1: https://lore.kernel.org/bpf/[email protected]/
v1 -> v2: Yonghong suggested to add the pointer value to the error
message.
I've noticed that I've been passing BADPTR as flags, therefore the fix worked only by accident. Put it into p.ptr where it belongs.

 .../testing/selftests/bpf/progs/netif_receive_skb.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/progs/netif_receive_skb.c +10 -3
index 6b670039ea67..4d158de73c2d 100644
@@ -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
@@ -113,11 +120,11 @@ int BPF_PROG(trace_netif_receive_skb, struct sk_buff *skb)
 	}
 
 	/* Check invalid ptr value */
-	p.ptr = 0;
+	p.ptr = BADPTR;
 	__ret = bpf_snprintf_btf(str, STRSIZE, &p, sizeof(p), 0);
 	if (__ret >= 0) {
-		bpf_printk("printing NULL should generate error, got (%d)",
-			   __ret);
+		bpf_printk("printing %p should generate error, got (%d)",
+			   BADPTR, __ret);
 		ret = -ERANGE;
 	}
 
Signature · 1 line
2.29.2
#1 lore raw
Quoted 41 lines · Ilya Leoshkevich

test_snprintf_btf fails on s390, because NULL points to a readable struct lowcore there. Fix by using _REGION1_SIZE instead.

Error message example:

    printing 0000000000000000 should generate error, got (361)

---

v1: https://lore.kernel.org/bpf/[email protected]/
v1 -> v2: Yonghong suggested to add the pointer value to the error
message.
I've noticed that I've been passing BADPTR as flags, therefore the fix worked only by accident. Put it into p.ptr where it belongs.

 .../testing/selftests/bpf/progs/netif_receive_skb.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/progs/netif_receive_skb.c +7 -0
index 6b670039ea67..4d158de73c2d 100644
@@ -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
@@ -113,11 +120,11 @@ int BPF_PROG(trace_netif_receive_skb, struct sk_buff *skb)
 	}
 

tools/testing/selftests/bpf/progs/netif_receive_skb.c int BPF_PROG(trace_netif_receive_skb, struct sk_buff *skb) · line 128

Quoted 10 lines
tools/testing/selftests/bpf/progs/netif_receive_skb.c +3 -3
 	/* Check invalid ptr value */
-	p.ptr = 0;
+	p.ptr = BADPTR;
 	__ret = bpf_snprintf_btf(str, STRSIZE, &p, sizeof(p), 0);
 	if (__ret >= 0) {
-		bpf_printk("printing NULL should generate error, got (%d)",
-			   __ret);
+		bpf_printk("printing %p should generate error, got (%d)",
+			   BADPTR, __ret);
 		ret = -ERANGE;

This will work for now on s390, since _right now_ we don't map anything that high, but there is no guarantee that it will stay this way.
I'd rather skip this test for s390.