From: Stanislav Fomichev <sdf@fomichev.me>
To: Martin Lau <kafai@fb.com>
Cc: "bpf@vger.kernel.org" <bpf@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
David Miller <davem@davemloft.net>,
Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 2/2] bpf: Add test for SO_REUSEPORT_DETACH_BPF
Date: Wed, 12 Jun 2019 14:47:57 -0700 [thread overview]
Message-ID: <20190612214757.GC9056@mini-arch> (raw)
In-Reply-To: <20190612213046.e7tkduk5nfuv5s6a@kafai-mbp.dhcp.thefacebook.com>
On 06/12, Martin Lau wrote:
> On Wed, Jun 12, 2019 at 12:59:17PM -0700, Stanislav Fomichev wrote:
> > On 06/12, Martin KaFai Lau wrote:
> > > This patch adds a test for the new sockopt SO_REUSEPORT_DETACH_BPF.
> > >
> > > '-I../../../../usr/include/' is added to the Makefile to get
> > > the newly added SO_REUSEPORT_DETACH_BPF.
> > >
> > > Signed-off-by: Martin KaFai Lau <kafai@fb.com>
> > > ---
> > > tools/testing/selftests/bpf/Makefile | 1 +
> > > .../selftests/bpf/test_select_reuseport.c | 50 +++++++++++++++++++
> > > 2 files changed, 51 insertions(+)
> > >
> > > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> > > index 44fb61f4d502..c7370361fa81 100644
> > > --- a/tools/testing/selftests/bpf/Makefile
> > > +++ b/tools/testing/selftests/bpf/Makefile
> > > @@ -16,6 +16,7 @@ LLVM_OBJCOPY ?= llvm-objcopy
> > > LLVM_READELF ?= llvm-readelf
> > > BTF_PAHOLE ?= pahole
> > > CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(BPFDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include \
> > > + -I../../../../usr/include/ \
> > Why not copy inlude/uapi/asm-generic/socket.h into tools/include
> > instead? Will that work?
> Sure. I am ok with copy. I don't think we need to sync very often.
> Do you know how to do that considering multiple arch's socket.h
> have been changed in Patch 1?
No, I don't know how to handle arch specific stuff. I suggest to copy
asm-generic and have ifdefs in the tests if someone complains :-)
> Is copy better?
Doesn't ../../../../usr/include provide the same headers we have in
tools/include/uapi? If you add -I../../../../usr/include, then is there
a point of having copies under tools/include/uapi? I don't really
know why we keep the copies under tools/include/uapi rather than including
../../../usr/include directly.
> > > -Dbpf_prog_load=bpf_prog_test_load \
> > > -Dbpf_load_program=bpf_test_load_program
> > > LDLIBS += -lcap -lelf -lrt -lpthread
> > > diff --git a/tools/testing/selftests/bpf/test_select_reuseport.c b/tools/testing/selftests/bpf/test_select_reuseport.c
> > > index 75646d9b34aa..5aa00b4a4702 100644
> > > --- a/tools/testing/selftests/bpf/test_select_reuseport.c
> > > +++ b/tools/testing/selftests/bpf/test_select_reuseport.c
> > > @@ -523,6 +523,54 @@ static void test_pass_on_err(int type, sa_family_t family)
> > > printf("OK\n");
> > > }
> > >
> > > +static void test_detach_bpf(int type, sa_family_t family)
> > > +{
> > > + __u32 nr_run_before = 0, nr_run_after = 0, tmp, i;
> > > + struct epoll_event ev;
> > > + int cli_fd, err, nev;
> > > + struct cmd cmd = {};
> > > + int optvalue = 0;
> > > +
> > > + printf("%s: ", __func__);
> > > + err = setsockopt(sk_fds[0], SOL_SOCKET, SO_DETACH_REUSEPORT_BPF,
> > > + &optvalue, sizeof(optvalue));
> > > + CHECK(err == -1, "setsockopt(SO_DETACH_REUSEPORT_BPF)",
> > > + "err:%d errno:%d\n", err, errno);
> > > +
> > > + err = setsockopt(sk_fds[1], SOL_SOCKET, SO_DETACH_REUSEPORT_BPF,
> > > + &optvalue, sizeof(optvalue));
> > > + CHECK(err == 0 || errno != ENOENT, "setsockopt(SO_DETACH_REUSEPORT_BPF)",
> > > + "err:%d errno:%d\n", err, errno);
> > > +
> > > + for (i = 0; i < NR_RESULTS; i++) {
> > > + err = bpf_map_lookup_elem(result_map, &i, &tmp);
> > > + CHECK(err == -1, "lookup_elem(result_map)",
> > > + "i:%u err:%d errno:%d\n", i, err, errno);
> > > + nr_run_before += tmp;
> > > + }
> > > +
> > > + cli_fd = send_data(type, family, &cmd, sizeof(cmd), PASS);
> > > + nev = epoll_wait(epfd, &ev, 1, 5);
> > > + CHECK(nev <= 0, "nev <= 0",
> > > + "nev:%d expected:1 type:%d family:%d data:(0, 0)\n",
> > > + nev, type, family);
> > > +
> > > + for (i = 0; i < NR_RESULTS; i++) {
> > > + err = bpf_map_lookup_elem(result_map, &i, &tmp);
> > > + CHECK(err == -1, "lookup_elem(result_map)",
> > > + "i:%u err:%d errno:%d\n", i, err, errno);
> > > + nr_run_after += tmp;
> > > + }
> > > +
> > > + CHECK(nr_run_before != nr_run_after,
> > > + "nr_run_before != nr_run_after",
> > > + "nr_run_before:%u nr_run_after:%u\n",
> > > + nr_run_before, nr_run_after);
> > > +
> > > + printf("OK\n");
> > > + close(cli_fd);
> > > +}
> > > +
> > > static void prepare_sk_fds(int type, sa_family_t family, bool inany)
> > > {
> > > const int first = REUSEPORT_ARRAY_SIZE - 1;
> > > @@ -664,6 +712,8 @@ static void test_all(void)
> > > test_pass(type, family);
> > > test_syncookie(type, family);
> > > test_pass_on_err(type, family);
> > > + /* Must be the last test */
> > > + test_detach_bpf(type, family);
> > >
> > > cleanup_per_test();
> > > printf("\n");
> > > --
> > > 2.17.1
> > >
next prev parent reply other threads:[~2019-06-13 17:16 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-12 19:05 [PATCH bpf-next 0/2] bpf: net: Detach BPF prog from reuseport sk Martin KaFai Lau
2019-06-12 19:05 ` [PATCH bpf-next 1/2] bpf: net: Add SO_DETACH_REUSEPORT_BPF Martin KaFai Lau
2019-06-13 4:39 ` Andrii Nakryiko
2019-06-13 19:18 ` kbuild test robot
2019-06-13 20:14 ` Andrii Nakryiko
2019-06-13 21:18 ` Martin Lau
2019-06-12 19:05 ` [PATCH bpf-next 2/2] bpf: Add test for SO_REUSEPORT_DETACH_BPF Martin KaFai Lau
2019-06-12 19:59 ` Stanislav Fomichev
2019-06-12 21:30 ` Martin Lau
2019-06-12 21:47 ` Stanislav Fomichev [this message]
2019-06-12 21:53 ` Alexei Starovoitov
2019-06-12 22:15 ` Martin Lau
2019-06-12 22:25 ` Alexei Starovoitov
2019-06-12 22:39 ` Martin Lau
2019-06-12 21:47 ` Martin Lau
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=20190612214757.GC9056@mini-arch \
--to=sdf@fomichev.me \
--cc=Kernel-team@fb.com \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=kafai@fb.com \
--cc=netdev@vger.kernel.org \
/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