netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	David Ahern <dsahern@kernel.org>
Cc: Networking <netdev@vger.kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Jesper Dangaard Brouer" <brouer@redhat.com>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"john fastabend" <john.fastabend@gmail.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Martin Lau" <kafai@fb.com>, "Song Liu" <songliubraving@fb.com>,
	"Yonghong Song" <yhs@fb.com>, "Andrii Nakryiko" <andriin@fb.com>
Subject: Re: [PATCH v2 bpf-next 5/5] selftest: Add tests for XDP programs in devmap entries
Date: Thu, 28 May 2020 16:54:50 -0600	[thread overview]
Message-ID: <f9386b9a-a059-ffee-7144-57d32be30f3e@gmail.com> (raw)
In-Reply-To: <CAEf4BzapqhtWOz666YN1m1wQd0pWJtjYFe4DrUEQpEgPX5UL9g@mail.gmail.com>

On 5/28/20 1:08 AM, Andrii Nakryiko wrote:
>> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
>> new file mode 100644
>> index 000000000000..d81b2b366f39
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
>> @@ -0,0 +1,94 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +#include <uapi/linux/bpf.h>
>> +#include <linux/if_link.h>
>> +#include <test_progs.h>
>> +
>> +#define IFINDEX_LO 1
>> +
>> +void test_xdp_devmap_attach(void)
>> +{
>> +       struct bpf_prog_load_attr attr = {
>> +               .prog_type = BPF_PROG_TYPE_XDP,
>> +       };
>> +       struct bpf_object *obj, *dm_obj = NULL;
>> +       int err, dm_fd = -1, fd = -1, map_fd;
>> +       struct bpf_prog_info info = {};
>> +       struct devmap_val val = {
>> +               .ifindex = IFINDEX_LO,
>> +       };
>> +       __u32 id, len = sizeof(info);
>> +       __u32 duration = 0, idx = 0;
>> +
>> +       attr.file = "./test_xdp_with_devmap.o",
>> +       err = bpf_prog_load_xattr(&attr, &obj, &fd);
> 
> please use skeletons instead of loading .o files.

I will look into it.

> 
>> +       if (CHECK(err, "load of xdp program with 8-byte devmap",
>> +                 "err %d errno %d\n", err, errno))
>> +               return;
>> +
> 
> [...]
> 

>> diff --git a/tools/testing/selftests/bpf/progs/test_xdp_devmap2.c b/tools/testing/selftests/bpf/progs/test_xdp_devmap2.c
>> new file mode 100644
>> index 000000000000..64fc2c3cae01
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/progs/test_xdp_devmap2.c
>> @@ -0,0 +1,19 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* program inserted into devmap entry */
>> +#include <linux/bpf.h>
>> +#include <bpf/bpf_helpers.h>
>> +
>> +SEC("xdp_devmap_log")
>> +int xdpdm_devlog(struct xdp_md *ctx)
>> +{
>> +       char fmt[] = "devmap redirect: dev %u -> dev %u len %u\n";
>> +       void *data_end = (void *)(long)ctx->data_end;
>> +       void *data = (void *)(long)ctx->data;
>> +       unsigned int len = data_end - data;
>> +
>> +       bpf_trace_printk(fmt, sizeof(fmt), ctx->ingress_ifindex, ctx->egress_ifindex, len);
> 
> instead of just printing ifindexes, why not return them through global
> variable and validate in a test?

The point of this program to access the egress_ifindex with the expected
attached type NOT set to BPF_XDP_DEVMAP to FAIL the verifier checks.



      parent reply	other threads:[~2020-05-28 22:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-28  0:14 [PATCH v2 bpf-next 0/5] bpf: Add support for XDP programs in DEVMAP entries David Ahern
2020-05-28  0:14 ` [PATCH v2 bpf-next 1/5] devmap: Formalize map value as a named struct David Ahern
2020-05-28  7:01   ` Andrii Nakryiko
2020-05-28 22:37     ` David Ahern
2020-05-28  0:14 ` [PATCH v2 bpf-next 2/5] bpf: Add support to attach bpf program to a devmap entry David Ahern
2020-05-28  7:01   ` Andrii Nakryiko
2020-05-28 22:40     ` David Ahern
2020-05-28 22:54       ` Andrii Nakryiko
2020-05-28  8:54   ` Toke Høiland-Jørgensen
2020-05-28  0:14 ` [PATCH v2 bpf-next 3/5] xdp: Add xdp_txq_info to xdp_buff David Ahern
2020-05-28  0:14 ` [PATCH v2 bpf-next 4/5] libbpf: Add SEC name for xdp programs attached to device map David Ahern
2020-05-28  7:04   ` Andrii Nakryiko
2020-05-28 22:49     ` David Ahern
2020-05-28  0:14 ` [PATCH v2 bpf-next 5/5] selftest: Add tests for XDP programs in devmap entries David Ahern
2020-05-28  7:08   ` Andrii Nakryiko
2020-05-28 10:25     ` Jesper Dangaard Brouer
2020-05-28 22:56       ` David Ahern
2020-05-28 22:54     ` David Ahern [this message]

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=f9386b9a-a059-ffee-7144-57d32be30f3e@gmail.com \
    --to=dsahern@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=toke@redhat.com \
    --cc=yhs@fb.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).