netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Rothwell <sfr@canb.auug.org.au>
To: David Miller <davem@davemloft.net>,
	Networking <netdev@vger.kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Alexei Starovoitov <ast@kernel.org>
Cc: Linux Next Mailing List <linux-next@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Stanislav Fomichev <sdf@google.com>
Subject: linux-next: manual merge of the net-next tree with the bpf tree
Date: Wed, 20 Feb 2019 11:37:29 +1100	[thread overview]
Message-ID: <20190220113729.49f28f73@canb.auug.org.au> (raw)

[-- Attachment #1: Type: text/plain, Size: 8862 bytes --]

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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

             reply	other threads:[~2019-02-20  0:37 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-20  0:37 Stephen Rothwell [this message]
2019-02-20  0:41 ` linux-next: manual merge of the net-next tree with the bpf tree Alexei Starovoitov
2019-02-20  0:45   ` Stanislav Fomichev
2019-02-20  1:03     ` Stephen Rothwell
2019-02-20  0:48   ` Daniel Borkmann
2019-02-20  3:03     ` Stanislav Fomichev
  -- strict thread matches above, loose matches on Subject: below --
2022-10-04  1:24 Stephen Rothwell
2022-10-04  2:07 ` Jakub Kicinski
2022-10-04 22:45   ` Stephen Rothwell
2022-09-23  0:45 Stephen Rothwell
2021-10-27  0:12 Stephen Rothwell
2021-06-22  1:06 Stephen Rothwell
2021-04-08  3:11 Stephen Rothwell
2021-04-08  3:02 Stephen Rothwell
2021-03-29  1:29 Stephen Rothwell
2021-03-29  8:28 ` Jiri Olsa
2020-07-16  1:59 Stephen Rothwell
2020-05-26  3:12 Stephen Rothwell
2020-05-26  5:45 ` Björn Töpel
2019-06-06  1:34 Stephen Rothwell
2018-12-14  0:56 Stephen Rothwell
2018-12-03  2:16 Stephen Rothwell
2018-12-03  2:03 Stephen Rothwell
2018-08-01  1:35 Stephen Rothwell
2018-08-01  4:23 ` Yonghong Song
2018-07-26  1:19 Stephen Rothwell
2018-07-26 15:32 ` Martin KaFai Lau
2018-01-09  0:21 Stephen Rothwell
2018-01-09  0:29 ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190220113729.49f28f73@canb.auug.org.au \
    --to=sfr@canb.auug.org.au \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).