All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/8] PROG_TEST_RUN support for sk_lookup programs
@ 2021-02-16 10:57 Lorenz Bauer
  2021-02-16 10:57 ` [PATCH bpf-next 1/8] bpf: consolidate shared test timing code Lorenz Bauer
                   ` (9 more replies)
  0 siblings, 10 replies; 17+ messages in thread
From: Lorenz Bauer @ 2021-02-16 10:57 UTC (permalink / raw)
  To: ast, daniel, andrii, jakub; +Cc: kernel-team, bpf, netdev, Lorenz Bauer

We don't have PROG_TEST_RUN support for sk_lookup programs at the
moment. So far this hasn't been a problem, since we can run our
tests in a separate network namespace. For benchmarking it's nice
to have PROG_TEST_RUN, so I've gone and implemented it.

Multiple sk_lookup programs can be attached at once to the same
netns. This can't be expressed with the current PROG_TEST_RUN
API, so I'm proposing to extend it with an array of prog_fd.

Patches 1-2 are clean ups. Patches 3-4 add the new UAPI and
implement PROG_TEST_RUN for sk_lookup. Patch 5 adds a new
function to libbpf to access multi prog tests. Patches 6-8 add
tests.

Andrii, for patch 4 I decided on the following API:

    int bpf_prog_test_run_array(__u32 *prog_fds, __u32 prog_fds_cnt,
                                struct bpf_test_run_opts *opts)

To be consistent with the rest of libbpf it would be better
to take int *prog_fds, but I think then the function would have to
convert the array to account for platforms where

    sizeof(int) != sizeof(__u32)

Please let me know what your preference is.

Lorenz Bauer (8):
  bpf: consolidate shared test timing code
  bpf: add for_each_bpf_prog helper
  bpf: allow multiple programs in BPF_PROG_TEST_RUN
  bpf: add PROG_TEST_RUN support for sk_lookup programs
  tools: libbpf: allow testing program types with multi-prog semantics
  selftests: bpf: convert sk_lookup multi prog tests to PROG_TEST_RUN
  selftests: bpf: convert sk_lookup ctx access tests to PROG_TEST_RUN
  selftests: bpf: check that PROG_TEST_RUN repeats as requested

 include/linux/bpf-netns.h                     |   2 +
 include/linux/bpf.h                           |  24 +-
 include/linux/filter.h                        |   4 +-
 include/uapi/linux/bpf.h                      |  11 +-
 kernel/bpf/net_namespace.c                    |   2 +-
 kernel/bpf/syscall.c                          |  73 +++++-
 net/bpf/test_run.c                            | 230 +++++++++++++-----
 net/core/filter.c                             |   1 +
 tools/include/uapi/linux/bpf.h                |  11 +-
 tools/lib/bpf/bpf.c                           |  16 +-
 tools/lib/bpf/bpf.h                           |   3 +
 tools/lib/bpf/libbpf.map                      |   1 +
 .../selftests/bpf/prog_tests/prog_run_xattr.c |  51 +++-
 .../selftests/bpf/prog_tests/sk_lookup.c      | 172 +++++++++----
 .../selftests/bpf/progs/test_sk_lookup.c      |  62 +++--
 15 files changed, 499 insertions(+), 164 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: [PATCH bpf-next 1/8] bpf: consolidate shared test timing code
@ 2021-02-16 13:48 kernel test robot
  0 siblings, 0 replies; 17+ messages in thread
From: kernel test robot @ 2021-02-16 13:48 UTC (permalink / raw)
  To: kbuild

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

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210216105713.45052-2-lmb@cloudflare.com>
References: <20210216105713.45052-2-lmb@cloudflare.com>
TO: Lorenz Bauer <lmb@cloudflare.com>
TO: ast(a)kernel.org
TO: daniel(a)iogearbox.net
TO: andrii(a)kernel.org
TO: jakub(a)cloudflare.com
CC: kernel-team(a)cloudflare.com
CC: bpf(a)vger.kernel.org
CC: netdev(a)vger.kernel.org
CC: Lorenz Bauer <lmb@cloudflare.com>

Hi Lorenz,

I love your patch! Perhaps something to improve:

[auto build test WARNING on bpf-next/master]

url:    https://github.com/0day-ci/linux/commits/Lorenz-Bauer/PROG_TEST_RUN-support-for-sk_lookup-programs/20210216-190705
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
:::::: branch date: 3 hours ago
:::::: commit date: 3 hours ago
config: i386-randconfig-m021-20210215 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
net/bpf/test_run.c:774 bpf_prog_test_run_flow_dissector() error: uninitialized symbol 'retval'.

Old smatch warnings:
include/linux/u64_stats_sync.h:128 u64_stats_update_begin() warn: statement has no effect 31

vim +/retval +774 net/bpf/test_run.c

b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  714  
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  715  int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  716  				     const union bpf_attr *kattr,
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  717  				     union bpf_attr __user *uattr)
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  718  {
938a0856b8ac67 Lorenz Bauer       2021-02-16  719  	struct test_timer t = { NO_PREEMPT };
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  720  	u32 size = kattr->test.data_size_in;
7b8a1304323b35 Stanislav Fomichev 2019-04-22  721  	struct bpf_flow_dissector ctx = {};
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  722  	u32 repeat = kattr->test.repeat;
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  723  	struct bpf_flow_keys *user_ctx;
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  724  	struct bpf_flow_keys flow_keys;
7b8a1304323b35 Stanislav Fomichev 2019-04-22  725  	const struct ethhdr *eth;
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  726  	unsigned int flags = 0;
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  727  	u32 retval, duration;
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  728  	void *data;
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  729  	int ret;
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  730  
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  731  	if (prog->type != BPF_PROG_TYPE_FLOW_DISSECTOR)
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  732  		return -EINVAL;
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  733  
1b4d60ec162f82 Song Liu           2020-09-25  734  	if (kattr->test.flags || kattr->test.cpu)
1b4d60ec162f82 Song Liu           2020-09-25  735  		return -EINVAL;
1b4d60ec162f82 Song Liu           2020-09-25  736  
7b8a1304323b35 Stanislav Fomichev 2019-04-22  737  	if (size < ETH_HLEN)
7b8a1304323b35 Stanislav Fomichev 2019-04-22  738  		return -EINVAL;
7b8a1304323b35 Stanislav Fomichev 2019-04-22  739  
7b8a1304323b35 Stanislav Fomichev 2019-04-22  740  	data = bpf_test_init(kattr, size, 0, 0);
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  741  	if (IS_ERR(data))
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  742  		return PTR_ERR(data);
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  743  
7b8a1304323b35 Stanislav Fomichev 2019-04-22  744  	eth = (struct ethhdr *)data;
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  745  
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  746  	if (!repeat)
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  747  		repeat = 1;
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  748  
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  749  	user_ctx = bpf_ctx_init(kattr, sizeof(struct bpf_flow_keys));
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  750  	if (IS_ERR(user_ctx)) {
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  751  		kfree(data);
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  752  		return PTR_ERR(user_ctx);
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  753  	}
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  754  	if (user_ctx) {
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  755  		ret = verify_user_bpf_flow_keys(user_ctx);
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  756  		if (ret)
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  757  			goto out;
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  758  		flags = user_ctx->flags;
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  759  	}
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  760  
7b8a1304323b35 Stanislav Fomichev 2019-04-22  761  	ctx.flow_keys = &flow_keys;
7b8a1304323b35 Stanislav Fomichev 2019-04-22  762  	ctx.data = data;
7b8a1304323b35 Stanislav Fomichev 2019-04-22  763  	ctx.data_end = (__u8 *)data + size;
7b8a1304323b35 Stanislav Fomichev 2019-04-22  764  
938a0856b8ac67 Lorenz Bauer       2021-02-16  765  	while (t_check(&t, repeat, &ret, &duration)) {
7b8a1304323b35 Stanislav Fomichev 2019-04-22  766  		retval = bpf_flow_dissect(prog, &ctx, eth->h_proto, ETH_HLEN,
b2ca4e1cfa7d3d Stanislav Fomichev 2019-07-25  767  					  size, flags);
a439184d515fbf Stanislav Fomichev 2019-02-19  768  	}
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  769  
938a0856b8ac67 Lorenz Bauer       2021-02-16  770  	if (ret < 0)
938a0856b8ac67 Lorenz Bauer       2021-02-16  771  		goto out;
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  772  
b7a1848e8398b8 Stanislav Fomichev 2019-01-28  773  	ret = bpf_test_finish(kattr, uattr, &flow_keys, sizeof(flow_keys),
b7a1848e8398b8 Stanislav Fomichev 2019-01-28 @774  			      retval, duration);

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 38029 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-02-24 21:38 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-16 10:57 [PATCH bpf-next 0/8] PROG_TEST_RUN support for sk_lookup programs Lorenz Bauer
2021-02-16 10:57 ` [PATCH bpf-next 1/8] bpf: consolidate shared test timing code Lorenz Bauer
2021-02-16 10:57 ` [PATCH bpf-next 2/8] bpf: add for_each_bpf_prog helper Lorenz Bauer
2021-02-16 10:57 ` [PATCH bpf-next 3/8] bpf: allow multiple programs in BPF_PROG_TEST_RUN Lorenz Bauer
2021-02-16 10:57 ` [PATCH bpf-next 4/8] bpf: add PROG_TEST_RUN support for sk_lookup programs Lorenz Bauer
2021-02-23  1:11   ` Alexei Starovoitov
2021-02-23 10:10     ` Lorenz Bauer
2021-02-24  6:11       ` Alexei Starovoitov
2021-02-16 10:57 ` [PATCH bpf-next 5/8] tools: libbpf: allow testing program types with multi-prog semantics Lorenz Bauer
2021-02-16 10:57 ` [PATCH bpf-next 6/8] selftests: bpf: convert sk_lookup multi prog tests to PROG_TEST_RUN Lorenz Bauer
2021-02-16 10:57 ` [PATCH bpf-next 7/8] selftests: bpf: convert sk_lookup ctx access " Lorenz Bauer
2021-02-16 10:57 ` [PATCH bpf-next 8/8] selftests: bpf: check that PROG_TEST_RUN repeats as requested Lorenz Bauer
2021-02-17 20:08 ` [PATCH bpf-next 0/8] PROG_TEST_RUN support for sk_lookup programs John Fastabend
2021-02-23  7:29 ` Andrii Nakryiko
2021-02-23 10:12   ` Lorenz Bauer
2021-02-24 21:37   ` Daniel Borkmann
2021-02-16 13:48 [PATCH bpf-next 1/8] bpf: consolidate shared test timing code kernel test robot

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.