All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC bpf-next 2/3] bpf: Make use of 'any' alignment in selftests.
@ 2018-11-29  7:41 David Miller
  0 siblings, 0 replies; only message in thread
From: David Miller @ 2018-11-29  7:41 UTC (permalink / raw)
  To: daniel; +Cc: ast, netdev


Add F_LOAD_WITH_ANY_ALIGNMENT.

On architectures which are don't have efficient unaligned accesses,
this provides a way to force test cases to ignore alignment issues and
instead test the actual problem the testcase is targetting.

Only use this initially for programs where the expected result is
REJECT.

Signed-off-by: David S. Miller <davem@davemloft.net>
---
 tools/testing/selftests/bpf/test_verifier.c | 47 ++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index a8f0a54..1a68863 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -54,6 +54,7 @@
 
 #define F_NEEDS_EFFICIENT_UNALIGNED_ACCESS	(1 << 0)
 #define F_LOAD_WITH_STRICT_ALIGNMENT		(1 << 1)
+#define F_LOAD_WITH_ANY_ALIGNMENT		(1 << 2)
 
 #define UNPRIV_SYSCTL "kernel/unprivileged_bpf_disabled"
 static bool unpriv_disabled = false;
@@ -1823,6 +1824,7 @@ static struct bpf_test tests[] = {
 		.errstr = "invalid bpf_context access",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_SK_MSG,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"direct packet read for SK_MSG",
@@ -2199,6 +2201,7 @@ static struct bpf_test tests[] = {
 		},
 		.errstr = "invalid bpf_context access",
 		.result = REJECT,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"check skb->hash half load not permitted, unaligned 3",
@@ -2215,6 +2218,7 @@ static struct bpf_test tests[] = {
 		},
 		.errstr = "invalid bpf_context access",
 		.result = REJECT,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"check cb access: half, wrong type",
@@ -3281,6 +3285,7 @@ static struct bpf_test tests[] = {
 		.result = REJECT,
 		.errstr = "R0 invalid mem access 'inv'",
 		.prog_type = BPF_PROG_TYPE_SCHED_CLS,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"raw_stack: skb_load_bytes, spilled regs corruption 2",
@@ -3311,6 +3316,7 @@ static struct bpf_test tests[] = {
 		.result = REJECT,
 		.errstr = "R3 invalid mem access 'inv'",
 		.prog_type = BPF_PROG_TYPE_SCHED_CLS,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"raw_stack: skb_load_bytes, spilled regs + data",
@@ -3810,6 +3816,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R2 invalid mem access 'inv'",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_SCHED_CLS,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"direct packet access: test16 (arith on data_end)",
@@ -3993,6 +4000,7 @@ static struct bpf_test tests[] = {
 		.prog_type = BPF_PROG_TYPE_SCHED_CLS,
 		.result = REJECT,
 		.errstr = "invalid access to packet, off=0 size=8, R5(id=1,off=0,r=0)",
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"direct packet access: test24 (x += pkt_ptr, 5)",
@@ -5149,6 +5157,7 @@ static struct bpf_test tests[] = {
 		.result = REJECT,
 		.errstr = "invalid access to map value, value_size=64 off=-2 size=4",
 		.prog_type = BPF_PROG_TYPE_CGROUP_SKB,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"invalid cgroup storage access 5",
@@ -5265,6 +5274,7 @@ static struct bpf_test tests[] = {
 		.result = REJECT,
 		.errstr = "invalid access to map value, value_size=64 off=-2 size=4",
 		.prog_type = BPF_PROG_TYPE_CGROUP_SKB,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"invalid per-cpu cgroup storage access 5",
@@ -7206,6 +7216,7 @@ static struct bpf_test tests[] = {
 		.errstr = "invalid mem access 'inv'",
 		.result = REJECT,
 		.result_unpriv = REJECT,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"map element value illegal alu op, 5",
@@ -7228,6 +7239,7 @@ static struct bpf_test tests[] = {
 		.fixup_map_hash_48b = { 3 },
 		.errstr = "R0 invalid mem access 'inv'",
 		.result = REJECT,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"map element value is preserved across register spilling",
@@ -9720,6 +9732,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_end > pkt_data', good access",
@@ -9758,6 +9771,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_end > pkt_data', bad access 2",
@@ -9776,6 +9790,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_data' < pkt_end, good access",
@@ -9814,6 +9829,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_data' < pkt_end, bad access 2",
@@ -9832,6 +9848,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_end < pkt_data', good access",
@@ -9886,6 +9903,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_data' >= pkt_end, good access",
@@ -9922,6 +9940,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_data' >= pkt_end, bad access 2",
@@ -9997,6 +10016,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_data' <= pkt_end, good access",
@@ -10053,6 +10073,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_end <= pkt_data', good access",
@@ -10089,6 +10110,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_end <= pkt_data', bad access 2",
@@ -10162,6 +10184,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_data > pkt_meta', good access",
@@ -10200,6 +10223,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_data > pkt_meta', bad access 2",
@@ -10218,6 +10242,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_meta' < pkt_data, good access",
@@ -10256,6 +10281,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_meta' < pkt_data, bad access 2",
@@ -10274,6 +10300,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_data < pkt_meta', good access",
@@ -10328,6 +10355,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_meta' >= pkt_data, good access",
@@ -10364,6 +10392,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_meta' >= pkt_data, bad access 2",
@@ -10439,6 +10468,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_meta' <= pkt_data, good access",
@@ -10495,6 +10525,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_data <= pkt_meta', good access",
@@ -10531,6 +10562,7 @@ static struct bpf_test tests[] = {
 		.errstr = "R1 offset is outside of the packet",
 		.result = REJECT,
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"XDP pkt read, pkt_data <= pkt_meta', bad access 2",
@@ -10635,6 +10667,7 @@ static struct bpf_test tests[] = {
 		},
 		.result = REJECT,
 		.errstr = "dereference of modified ctx ptr",
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"check deducing bounds from const, 8",
@@ -10648,6 +10681,7 @@ static struct bpf_test tests[] = {
 		},
 		.result = REJECT,
 		.errstr = "dereference of modified ctx ptr",
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"check deducing bounds from const, 9",
@@ -11122,6 +11156,7 @@ static struct bpf_test tests[] = {
 		.result = REJECT,
 		.errstr = "R6 invalid mem access 'inv'",
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"calls: two calls with args",
@@ -11987,6 +12022,7 @@ static struct bpf_test tests[] = {
 		.fixup_map_hash_8b = { 12, 22 },
 		.result = REJECT,
 		.errstr = "invalid access to map value, value_size=8 off=2 size=8",
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"calls: two calls that receive map_value via arg=ptr_stack_of_caller. test2",
@@ -12130,6 +12166,7 @@ static struct bpf_test tests[] = {
 		.fixup_map_hash_8b = { 12, 22 },
 		.result = REJECT,
 		.errstr = "invalid access to map value, value_size=8 off=2 size=8",
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"calls: two calls that receive map_value_ptr_or_null via arg. test1",
@@ -12301,6 +12338,7 @@ static struct bpf_test tests[] = {
 		.result = ACCEPT,
 		.prog_type = BPF_PROG_TYPE_SCHED_CLS,
 		.retval = POINTER_VALUE,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"calls: pkt_ptr spill into caller stack 2",
@@ -12332,6 +12370,7 @@ static struct bpf_test tests[] = {
 		.prog_type = BPF_PROG_TYPE_SCHED_CLS,
 		.errstr = "invalid access to packet",
 		.result = REJECT,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"calls: pkt_ptr spill into caller stack 3",
@@ -12434,6 +12473,7 @@ static struct bpf_test tests[] = {
 		.prog_type = BPF_PROG_TYPE_SCHED_CLS,
 		.errstr = "same insn cannot be used with different",
 		.result = REJECT,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"calls: pkt_ptr spill into caller stack 6",
@@ -12469,6 +12509,7 @@ static struct bpf_test tests[] = {
 		.prog_type = BPF_PROG_TYPE_SCHED_CLS,
 		.errstr = "R4 invalid mem access",
 		.result = REJECT,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"calls: pkt_ptr spill into caller stack 7",
@@ -12503,6 +12544,7 @@ static struct bpf_test tests[] = {
 		.prog_type = BPF_PROG_TYPE_SCHED_CLS,
 		.errstr = "R4 invalid mem access",
 		.result = REJECT,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"calls: pkt_ptr spill into caller stack 8",
@@ -12584,6 +12626,7 @@ static struct bpf_test tests[] = {
 		.prog_type = BPF_PROG_TYPE_SCHED_CLS,
 		.errstr = "invalid access to packet",
 		.result = REJECT,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"calls: caller stack init to zero or map_value_or_null",
@@ -12949,6 +12992,7 @@ static struct bpf_test tests[] = {
 		.result = REJECT,
 		.errstr = "BPF_XADD stores into R2 pkt is not allowed",
 		.prog_type = BPF_PROG_TYPE_XDP,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"xadd/w check whether src/dst got mangled, 1",
@@ -13435,6 +13479,7 @@ static struct bpf_test tests[] = {
 		.prog_type = BPF_PROG_TYPE_SCHED_CLS,
 		.errstr = "Unreleased reference",
 		.result = REJECT,
+		.flags = F_LOAD_WITH_ANY_ALIGNMENT,
 	},
 	{
 		"reference tracking: alloc, check, free in both subbranches",
@@ -14276,7 +14321,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
 
 	fd_prog = bpf_verify_program(prog_type, prog, prog_len,
 				     test->flags & F_LOAD_WITH_STRICT_ALIGNMENT,
-				     0,
+				     test->flags & F_LOAD_WITH_ANY_ALIGNMENT,
 				     "GPL", 0, bpf_vlog, sizeof(bpf_vlog), 1);
 
 	expected_ret = unpriv && test->result_unpriv != UNDEF ?
-- 
2.1.2.532.g19b5d50

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-11-29 18:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-29  7:41 [PATCH RFC bpf-next 2/3] bpf: Make use of 'any' alignment in selftests David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.