linux-next: manual merge of the net-next tree with the bpf tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

Today's linux-next merge of the net-next tree got a conflict in:

  tools/testing/selftests/bpf/test_progs.c

between commit:

  f6be4d16039b ("selftests/bpf: make sure signal interrupts BPF_PROG_TEST_RUN")

from the bpf tree and commits:

  bf0f0fd93945 ("selftests/bpf: add simple BPF_PROG_TEST_RUN examples for flow dissector")
  ab963beb9f5d ("selftests/bpf: add bpf_spin_lock C test")
  ba72a7b4badb ("selftests/bpf: test for BPF_F_LOCK")

from the net-next tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc tools/testing/selftests/bpf/test_progs.c
index 7842e3749b19,c52bd90fbb34..000000000000
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@@ -10,8 -10,8 +10,9 @@@
  #include <string.h>
  #include <assert.h>
  #include <stdlib.h>
+ #include <stdarg.h>
  #include <time.h>
 +#include <signal.h>
  
  #include <linux/types.h>
  typedef __u16 __sum16;
@@@ -28,9 -28,8 +29,9 @@@
  #include <sys/ioctl.h>
  #include <sys/wait.h>
  #include <sys/types.h>
 +#include <sys/time.h>
  #include <fcntl.h>
- 
+ #include <pthread.h>
  #include <linux/bpf.h>
  #include <linux/err.h>
  #include <bpf/bpf.h>
@@@ -1914,47 -1925,189 +1927,230 @@@ out
  	bpf_object__close(obj);
  }
  
 +static void sigalrm_handler(int s) {}
 +static struct sigaction sigalrm_action = {
 +	.sa_handler = sigalrm_handler,
 +};
 +
 +static void test_signal_pending(void)
 +{
 +	struct bpf_insn prog[4096];
 +	struct itimerval timeo = {
 +		.it_value.tv_usec = 100000, /* 100ms */
 +	};
 +	__u32 duration, retval;
 +	int prog_fd;
 +	int err;
 +	int i;
 +
 +	for (i = 0; i < ARRAY_SIZE(prog); i++)
 +		prog[i] = BPF_ALU64_IMM(BPF_MOV, BPF_REG_0, 0);
 +	prog[ARRAY_SIZE(prog) - 1] = BPF_EXIT_INSN();
 +
 +	prog_fd = bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER,
 +				   prog, ARRAY_SIZE(prog),
 +				   "GPL", 0, NULL, 0);
 +	CHECK(prog_fd < 0, "test-run", "errno %d\n", errno);
 +
 +	err = sigaction(SIGALRM, &sigalrm_action, NULL);
 +	CHECK(err, "test-run-signal-sigaction", "errno %d\n", errno);
 +
 +	err = setitimer(ITIMER_REAL, &timeo, NULL);
 +	CHECK(err, "test-run-signal-timer", "errno %d\n", errno);
 +
 +	err = bpf_prog_test_run(prog_fd, 0xffffffff, &pkt_v4, sizeof(pkt_v4),
 +				NULL, NULL, &retval, &duration);
 +	CHECK(err != -1 || errno != EINTR || duration > 1000000000,
 +	      "test-run-signal-run",
 +	      "err %d errno %d retval %d\n",
 +	      err, errno, retval);
 +
 +	signal(SIGALRM, SIG_DFL);
 +}
 +
+ #define CHECK_FLOW_KEYS(desc, got, expected)				\
+ 	CHECK(memcmp(&got, &expected, sizeof(got)) != 0,		\
+ 	      desc,							\
+ 	      "nhoff=%u/%u "						\
+ 	      "thoff=%u/%u "						\
+ 	      "addr_proto=0x%x/0x%x "					\
+ 	      "is_frag=%u/%u "						\
+ 	      "is_first_frag=%u/%u "					\
+ 	      "is_encap=%u/%u "						\
+ 	      "n_proto=0x%x/0x%x "					\
+ 	      "sport=%u/%u "						\
+ 	      "dport=%u/%u\n",						\
+ 	      got.nhoff, expected.nhoff,				\
+ 	      got.thoff, expected.thoff,				\
+ 	      got.addr_proto, expected.addr_proto,			\
+ 	      got.is_frag, expected.is_frag,				\
+ 	      got.is_first_frag, expected.is_first_frag,		\
+ 	      got.is_encap, expected.is_encap,				\
+ 	      got.n_proto, expected.n_proto,				\
+ 	      got.sport, expected.sport,				\
+ 	      got.dport, expected.dport)
+ 
+ static struct bpf_flow_keys pkt_v4_flow_keys = {
+ 	.nhoff = 0,
+ 	.thoff = sizeof(struct iphdr),
+ 	.addr_proto = ETH_P_IP,
+ 	.ip_proto = IPPROTO_TCP,
+ 	.n_proto = bpf_htons(ETH_P_IP),
+ };
+ 
+ static struct bpf_flow_keys pkt_v6_flow_keys = {
+ 	.nhoff = 0,
+ 	.thoff = sizeof(struct ipv6hdr),
+ 	.addr_proto = ETH_P_IPV6,
+ 	.ip_proto = IPPROTO_TCP,
+ 	.n_proto = bpf_htons(ETH_P_IPV6),
+ };
+ 
+ static void test_flow_dissector(void)
+ {
+ 	struct bpf_flow_keys flow_keys;
+ 	struct bpf_object *obj;
+ 	__u32 duration, retval;
+ 	int err, prog_fd;
+ 	__u32 size;
+ 
+ 	err = bpf_flow_load(&obj, "./bpf_flow.o", "flow_dissector",
+ 			    "jmp_table", &prog_fd);
+ 	if (err) {
+ 		error_cnt++;
+ 		return;
+ 	}
+ 
+ 	err = bpf_prog_test_run(prog_fd, 10, &pkt_v4, sizeof(pkt_v4),
+ 				&flow_keys, &size, &retval, &duration);
+ 	CHECK(size != sizeof(flow_keys) || err || retval != 1, "ipv4",
+ 	      "err %d errno %d retval %d duration %d size %u/%lu\n",
+ 	      err, errno, retval, duration, size, sizeof(flow_keys));
+ 	CHECK_FLOW_KEYS("ipv4_flow_keys", flow_keys, pkt_v4_flow_keys);
+ 
+ 	err = bpf_prog_test_run(prog_fd, 10, &pkt_v6, sizeof(pkt_v6),
+ 				&flow_keys, &size, &retval, &duration);
+ 	CHECK(size != sizeof(flow_keys) || err || retval != 1, "ipv6",
+ 	      "err %d errno %d retval %d duration %d size %u/%lu\n",
+ 	      err, errno, retval, duration, size, sizeof(flow_keys));
+ 	CHECK_FLOW_KEYS("ipv6_flow_keys", flow_keys, pkt_v6_flow_keys);
+ 
+ 	bpf_object__close(obj);
+ }
+ 
+ static void *test_spin_lock(void *arg)
+ {
+ 	__u32 duration, retval;
+ 	int err, prog_fd = *(u32 *) arg;
+ 
+ 	err = bpf_prog_test_run(prog_fd, 10000, &pkt_v4, sizeof(pkt_v4),
+ 				NULL, NULL, &retval, &duration);
+ 	CHECK(err || retval, "",
+ 	      "err %d errno %d retval %d duration %d\n",
+ 	      err, errno, retval, duration);
+ 	pthread_exit(arg);
+ }
+ 
+ static void test_spinlock(void)
+ {
+ 	const char *file = "./test_spin_lock.o";
+ 	pthread_t thread_id[4];
+ 	struct bpf_object *obj;
+ 	int prog_fd;
+ 	int err = 0, i;
+ 	void *ret;
+ 
+ 	err = bpf_prog_load(file, BPF_PROG_TYPE_CGROUP_SKB, &obj, &prog_fd);
+ 	if (err) {
+ 		printf("test_spin_lock:bpf_prog_load errno %d\n", errno);
+ 		goto close_prog;
+ 	}
+ 	for (i = 0; i < 4; i++)
+ 		assert(pthread_create(&thread_id[i], NULL,
+ 				      &test_spin_lock, &prog_fd) == 0);
+ 	for (i = 0; i < 4; i++)
+ 		assert(pthread_join(thread_id[i], &ret) == 0 &&
+ 		       ret == (void *)&prog_fd);
+ 	goto close_prog_noerr;
+ close_prog:
+ 	error_cnt++;
+ close_prog_noerr:
+ 	bpf_object__close(obj);
+ }
+ 
+ static void *parallel_map_access(void *arg)
+ {
+ 	int err, map_fd = *(u32 *) arg;
+ 	int vars[17], i, j, rnd, key = 0;
+ 
+ 	for (i = 0; i < 10000; i++) {
+ 		err = bpf_map_lookup_elem_flags(map_fd, &key, vars, BPF_F_LOCK);
+ 		if (err) {
+ 			printf("lookup failed\n");
+ 			error_cnt++;
+ 			goto out;
+ 		}
+ 		if (vars[0] != 0) {
+ 			printf("lookup #%d var[0]=%d\n", i, vars[0]);
+ 			error_cnt++;
+ 			goto out;
+ 		}
+ 		rnd = vars[1];
+ 		for (j = 2; j < 17; j++) {
+ 			if (vars[j] == rnd)
+ 				continue;
+ 			printf("lookup #%d var[1]=%d var[%d]=%d\n",
+ 			       i, rnd, j, vars[j]);
+ 			error_cnt++;
+ 			goto out;
+ 		}
+ 	}
+ out:
+ 	pthread_exit(arg);
+ }
+ 
+ static void test_map_lock(void)
+ {
+ 	const char *file = "./test_map_lock.o";
+ 	int prog_fd, map_fd[2], vars[17] = {};
+ 	pthread_t thread_id[6];
+ 	struct bpf_object *obj;
+ 	int err = 0, key = 0, i;
+ 	void *ret;
+ 
+ 	err = bpf_prog_load(file, BPF_PROG_TYPE_CGROUP_SKB, &obj, &prog_fd);
+ 	if (err) {
+ 		printf("test_map_lock:bpf_prog_load errno %d\n", errno);
+ 		goto close_prog;
+ 	}
+ 	map_fd[0] = bpf_find_map(__func__, obj, "hash_map");
+ 	if (map_fd[0] < 0)
+ 		goto close_prog;
+ 	map_fd[1] = bpf_find_map(__func__, obj, "array_map");
+ 	if (map_fd[1] < 0)
+ 		goto close_prog;
+ 
+ 	bpf_map_update_elem(map_fd[0], &key, vars, BPF_F_LOCK);
+ 
+ 	for (i = 0; i < 4; i++)
+ 		assert(pthread_create(&thread_id[i], NULL,
+ 				      &test_spin_lock, &prog_fd) == 0);
+ 	for (i = 4; i < 6; i++)
+ 		assert(pthread_create(&thread_id[i], NULL,
+ 				      &parallel_map_access, &map_fd[i - 4]) == 0);
+ 	for (i = 0; i < 4; i++)
+ 		assert(pthread_join(thread_id[i], &ret) == 0 &&
+ 		       ret == (void *)&prog_fd);
+ 	for (i = 4; i < 6; i++)
+ 		assert(pthread_join(thread_id[i], &ret) == 0 &&
+ 		       ret == (void *)&map_fd[i - 4]);
+ 	goto close_prog_noerr;
+ close_prog:
+ 	error_cnt++;
+ close_prog_noerr:
+ 	bpf_object__close(obj);
+ }
+ 
  int main(void)
  {
  	srand(time(NULL));
@@@ -1982,7 -2135,9 +2178,10 @@@
  	test_reference_tracking();
  	test_queue_stack_map(QUEUE);
  	test_queue_stack_map(STACK);
 +	test_signal_pending();
+ 	test_flow_dissector();
+ 	test_spinlock();
+ 	test_map_lock();
  
  	printf("Summary: %d PASSED, %d FAILED\n", pass_cnt, error_cnt);
  	return error_cnt ? EXIT_FAILURE : EXIT_SUCCESS;

Attachment: pgpWCxWtW3JUa.pgp
Description: OpenPGP digital signature


[Index of Archives]     [Linux Kernel]     [Linux USB Development]     [Yosemite News]     [Linux SCSI]

  Powered by Linux