From: John Fastabend <john.fastabend@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
John Fastabend <john.fastabend@gmail.com>
Cc: Yonghong Song <yhs@fb.com>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Lorenz Bauer <lmb@cloudflare.com>, bpf <bpf@vger.kernel.org>,
Jakub Sitnicki <jakub@cloudflare.com>,
Networking <netdev@vger.kernel.org>
Subject: Re: [bpf-next PATCH v3 5/5] bpf: selftests, test probe_* helpers from SCHED_CLS
Date: Thu, 21 May 2020 12:11:03 -0700 [thread overview]
Message-ID: <5ec6d2473d523_7d832ae77617e5c07a@john-XPS-13-9370.notmuch> (raw)
In-Reply-To: <CAEf4BzYJRaY+tsa2TH5WoLAEo=ckd=D2XK5u4YFezkj4jfrZLQ@mail.gmail.com>
Andrii Nakryiko wrote:
> On Thu, May 21, 2020 at 7:36 AM John Fastabend <john.fastabend@gmail.com> wrote:
> >
> > Lets test using probe* in SCHED_CLS network programs as well just
> > to be sure these keep working. Its cheap to add the extra test
> > and provides a second context to test outside of sk_msg after
> > we generalized probe* helpers to all networking types.
> >
> > Signed-off-by: John Fastabend <john.fastabend@gmail.com>
> > ---
[...]
> > +++ b/tools/testing/selftests/bpf/progs/test_skb_helpers.c
> > @@ -0,0 +1,33 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +#include "vmlinux.h"
> > +#include <bpf/bpf_helpers.h>
> > +#include <bpf/bpf_endian.h>
> > +
> > +int _version SEC("version") = 1;
>
> version is not needed
>
> > +
> > +#define TEST_COMM_LEN 10
>
> doesn't matter for this test, but it's 16 everywhere, let's stay consistent
>
> > +
> > +struct bpf_map_def SEC("maps") cgroup_map = {
> > + .type = BPF_MAP_TYPE_CGROUP_ARRAY,
> > + .key_size = sizeof(u32),
> > + .value_size = sizeof(u32),
> > + .max_entries = 1,
> > +};
> > +
>
> Please use new BTF syntax for maps
>
> > +char _license[] SEC("license") = "GPL";
> > +
> > +SEC("classifier/test_skb_helpers")
> > +int test_skb_helpers(struct __sk_buff *skb)
> > +{
> > + struct task_struct *task;
> > + char *comm[TEST_COMM_LEN];
>
> this is array of pointer, not array of chars
>
> > + __u32 tpid;
> > + int ctask;
> > +
> > + ctask = bpf_current_task_under_cgroup(&cgroup_map, 0);
>
> compiler might complain that ctask is written, but not read. Let's
> assign it to some global variable?
I'll do a read here and check the value then it should be fine.
Will fold in the above comments as well.
> > + task = (struct task_struct *)bpf_get_current_task();
> > +
> > + bpf_probe_read_kernel(&tpid , sizeof(tpid), &task->tgid);
> > + bpf_probe_read_kernel_str(&comm, sizeof(comm), &task->comm);
> > + return 0;
> > +}
> >
prev parent reply other threads:[~2020-05-21 19:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-21 14:34 [bpf-next PATCH v3 0/5] bpf: Add sk_msg and networking helpers John Fastabend
2020-05-21 14:34 ` [bpf-next PATCH v3 1/5] bpf: sk_msg add some generic helpers that may be useful from sk_msg John Fastabend
2020-05-21 14:35 ` [bpf-next PATCH v3 2/5] bpf: extend bpf_base_func_proto helpers with probe_* and *current_task* John Fastabend
2020-05-21 14:35 ` [bpf-next PATCH v3 3/5] bpf: sk_msg add get socket storage helpers John Fastabend
2020-05-21 14:35 ` [bpf-next PATCH v3 4/5] bpf: selftests, add sk_msg helpers load and attach test John Fastabend
2020-05-21 18:23 ` Yonghong Song
2020-05-21 18:51 ` John Fastabend
2020-05-21 18:51 ` Andrii Nakryiko
2020-05-21 19:03 ` John Fastabend
2020-05-21 19:09 ` John Fastabend
2020-05-21 19:12 ` Andrii Nakryiko
2020-05-21 14:36 ` [bpf-next PATCH v3 5/5] bpf: selftests, test probe_* helpers from SCHED_CLS John Fastabend
2020-05-21 18:32 ` Yonghong Song
2020-05-21 18:47 ` Andrii Nakryiko
2020-05-21 19:11 ` John Fastabend [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=5ec6d2473d523_7d832ae77617e5c07a@john-XPS-13-9370.notmuch \
--to=john.fastabend@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jakub@cloudflare.com \
--cc=lmb@cloudflare.com \
--cc=netdev@vger.kernel.org \
--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).