bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
	Daniel Borkmann <borkmann@iogearbox.net>,
	maze@google.com, lmb@cloudflare.com, shaun@tigera.io,
	Lorenzo Bianconi <lorenzo@kernel.org>,
	marek@cloudflare.com, John Fastabend <john.fastabend@gmail.com>,
	Jakub Kicinski <kuba@kernel.org>,
	eyal.birger@gmail.com, colrack@gmail.com
Subject: Re: [PATCH bpf-next V7 8/8] bpf/selftests: activating bpf_check_mtu BPF-helper
Date: Fri, 20 Nov 2020 13:50:51 -0800	[thread overview]
Message-ID: <20201120215051.cqrlmxtujrgaidc6@ast-mbp> (raw)
In-Reply-To: <160588912738.2817268.9380466634324530673.stgit@firesoul>

On Fri, Nov 20, 2020 at 05:18:47PM +0100, Jesper Dangaard Brouer wrote:
> Adding selftest for BPF-helper bpf_check_mtu(). Making sure
> it can be used from both XDP and TC.
> 
> Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
> ---
>  tools/testing/selftests/bpf/prog_tests/check_mtu.c |   37 ++++++++++++++++++++
>  tools/testing/selftests/bpf/progs/test_check_mtu.c |   33 ++++++++++++++++++
>  2 files changed, 70 insertions(+)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/check_mtu.c
>  create mode 100644 tools/testing/selftests/bpf/progs/test_check_mtu.c
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/check_mtu.c b/tools/testing/selftests/bpf/prog_tests/check_mtu.c
> new file mode 100644
> index 000000000000..09b8f986a17b
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/check_mtu.c
> @@ -0,0 +1,37 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2020 Red Hat */
> +#include <uapi/linux/bpf.h>
> +#include <linux/if_link.h>
> +#include <test_progs.h>
> +
> +#include "test_check_mtu.skel.h"
> +#define IFINDEX_LO 1
> +
> +void test_check_mtu_xdp(struct test_check_mtu *skel)
> +{
> +	int err = 0;
> +	int fd;
> +
> +	fd = bpf_program__fd(skel->progs.xdp_use_helper);
> +	err = bpf_set_link_xdp_fd(IFINDEX_LO, fd, XDP_FLAGS_SKB_MODE);
> +	if (CHECK_FAIL(err))
> +		return;
> +
> +	bpf_set_link_xdp_fd(IFINDEX_LO, -1, 0);
> +}
> +
> +void test_check_mtu(void)
> +{
> +	struct test_check_mtu *skel;
> +
> +	skel = test_check_mtu__open_and_load();
> +	if (CHECK_FAIL(!skel)) {
> +		perror("test_check_mtu__open_and_load");
> +		return;
> +	}
> +
> +	if (test__start_subtest("bpf_check_mtu XDP-attach"))
> +		test_check_mtu_xdp(skel);
> +
> +	test_check_mtu__destroy(skel);
> +}
> diff --git a/tools/testing/selftests/bpf/progs/test_check_mtu.c b/tools/testing/selftests/bpf/progs/test_check_mtu.c
> new file mode 100644
> index 000000000000..ab97ec925a32
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/test_check_mtu.c
> @@ -0,0 +1,33 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2020 Red Hat */
> +#include <linux/bpf.h>
> +#include <bpf/bpf_helpers.h>
> +
> +#include <stddef.h>
> +#include <stdint.h>
> +
> +char _license[] SEC("license") = "GPL";
> +
> +SEC("xdp")
> +int xdp_use_helper(struct xdp_md *ctx)
> +{
> +	uint32_t mtu_len = 0;
> +	int delta = 20;
> +
> +	if (bpf_check_mtu(ctx, 0, &mtu_len, delta, 0)) {
> +		return XDP_ABORTED;
> +	}
> +	return XDP_PASS;
> +}
> +
> +SEC("classifier")
> +int tc_use_helper(struct __sk_buff *ctx)
> +{
> +	uint32_t mtu_len = 0;
> +	int delta = -20;
> +
> +	if (bpf_check_mtu(ctx, 0, &mtu_len, delta, 0)) {
> +		return BPF_DROP;
> +	}
> +	return BPF_OK;
> +}

Patches 7 and 8 are not adequate as tests.
They do not testing the functionality of earlier patches.
bpf_check_mtu() could be returning random value and "tests" 7 and 8 would still pass.
Please fix.

  reply	other threads:[~2020-11-20 21:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-20 16:18 [PATCH bpf-next V7 0/8] bpf: New approach for BPF MTU handling Jesper Dangaard Brouer
2020-11-20 16:18 ` [PATCH bpf-next V7 1/8] bpf: Remove MTU check in __bpf_skb_max_len Jesper Dangaard Brouer
2020-11-20 16:18 ` [PATCH bpf-next V7 2/8] bpf: fix bpf_fib_lookup helper MTU check for SKB ctx Jesper Dangaard Brouer
2020-12-02 21:44   ` Daniel Borkmann
2020-12-02 22:00     ` Daniel Borkmann
2020-11-20 16:18 ` [PATCH bpf-next V7 3/8] bpf: bpf_fib_lookup return MTU value as output when looked up Jesper Dangaard Brouer
2020-11-20 16:18 ` [PATCH bpf-next V7 4/8] bpf: add BPF-helper for MTU checking Jesper Dangaard Brouer
2020-12-03 18:25   ` sdf
2020-12-14 11:52     ` Jesper Dangaard Brouer
2020-11-20 16:18 ` [PATCH bpf-next V7 5/8] bpf: drop MTU check when doing TC-BPF redirect to ingress Jesper Dangaard Brouer
2020-11-20 16:18 ` [PATCH bpf-next V7 6/8] bpf: make it possible to identify BPF redirected SKBs Jesper Dangaard Brouer
2020-11-20 16:18 ` [PATCH bpf-next V7 7/8] selftests/bpf: use bpf_check_mtu in selftest test_cls_redirect Jesper Dangaard Brouer
2020-11-20 16:18 ` [PATCH bpf-next V7 8/8] bpf/selftests: activating bpf_check_mtu BPF-helper Jesper Dangaard Brouer
2020-11-20 21:50   ` Alexei Starovoitov [this message]
2020-11-21  7:41   ` Andrii Nakryiko
2020-11-24 14:33     ` Jesper Dangaard Brouer
2020-11-24 16:50       ` Yonghong Song

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=20201120215051.cqrlmxtujrgaidc6@ast-mbp \
    --to=alexei.starovoitov@gmail.com \
    --cc=borkmann@iogearbox.net \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=colrack@gmail.com \
    --cc=eyal.birger@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=lmb@cloudflare.com \
    --cc=lorenzo@kernel.org \
    --cc=marek@cloudflare.com \
    --cc=maze@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=shaun@tigera.io \
    /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).