From: Carlos Antonio Neira Bustos <cneirabustos@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Networking <netdev@vger.kernel.org>, Yonghong Song <yhs@fb.com>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Jesper Dangaard Brouer <brouer@redhat.com>,
bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH v4 bpf-next] bpf/selftests: fold test_current_pid_tgid_new_ns into test_progs.
Date: Thu, 6 Aug 2020 10:03:20 -0400 [thread overview]
Message-ID: <20200806140319.GA40984@bpf-dev> (raw)
In-Reply-To: <CAEf4BzYrek8shqzUj+zNC=TjGkDPCKUFP=YnbiNf6360f1MyTw@mail.gmail.com>
On Wed, Aug 05, 2020 at 01:15:05PM -0700, Andrii Nakryiko wrote:
> On Wed, Aug 5, 2020 at 1:06 PM Carlos Neira <cneirabustos@gmail.com> wrote:
> >
> > Currently tests for bpf_get_ns_current_pid_tgid() are outside test_progs.
> > This change folds a test case into test_progs.
> >
> > Changes from V3:
> > - STAT(2) check changed from CHECK_FAIL to CHECK.
> > - Changed uses of _open_ to _open_and_load.
> > - Fixed error codes were not being returned on exit.
> > - Removed unnecessary dependency on Makefile
> >
> > Signed-off-by: Carlos Neira <cneirabustos@gmail.com>
> > ---
>
> bpf-next is closed, you'll have to re-submit once it opens in roughly
> two weeks. Looks good overall, few minor things below, please
> incorporate into next revision with my ack:
>
> Acked-by: Andrii Nakryiko <andriin@fb.com>
>
> > tools/testing/selftests/bpf/.gitignore | 2 +-
> > tools/testing/selftests/bpf/Makefile | 4 +-
> > .../bpf/prog_tests/ns_current_pid_tgid.c | 85 ----------
> > .../bpf/prog_tests/ns_current_pidtgid.c | 54 ++++++
> > .../bpf/progs/test_ns_current_pid_tgid.c | 37 ----
> > .../bpf/progs/test_ns_current_pidtgid.c | 25 +++
> > .../bpf/test_current_pid_tgid_new_ns.c | 159 ------------------
> > .../bpf/test_ns_current_pidtgid_newns.c | 91 ++++++++++
> > 8 files changed, 173 insertions(+), 284 deletions(-)
> > delete mode 100644 tools/testing/selftests/bpf/prog_tests/ns_current_pid_tgid.c
> > create mode 100644 tools/testing/selftests/bpf/prog_tests/ns_current_pidtgid.c
> > delete mode 100644 tools/testing/selftests/bpf/progs/test_ns_current_pid_tgid.c
> > create mode 100644 tools/testing/selftests/bpf/progs/test_ns_current_pidtgid.c
> > delete mode 100644 tools/testing/selftests/bpf/test_current_pid_tgid_new_ns.c
> > create mode 100644 tools/testing/selftests/bpf/test_ns_current_pidtgid_newns.c
> >
> > diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore
> > index 1bb204cee853..022055f23592 100644
> > --- a/tools/testing/selftests/bpf/.gitignore
> > +++ b/tools/testing/selftests/bpf/.gitignore
> > @@ -30,8 +30,8 @@ test_tcpnotify_user
> > test_libbpf
> > test_tcp_check_syncookie_user
> > test_sysctl
> > -test_current_pid_tgid_new_ns
> > xdping
> > +test_ns_current_pidtgid_newns
> > test_cpp
> > *.skel.h
> > /no_alu32
> > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> > index e7a8cf83ba48..92fb616cdd27 100644
> > --- a/tools/testing/selftests/bpf/Makefile
> > +++ b/tools/testing/selftests/bpf/Makefile
> > @@ -36,8 +36,8 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test
> > test_sock test_btf test_sockmap get_cgroup_id_user test_socket_cookie \
> > test_cgroup_storage \
> > test_netcnt test_tcpnotify_user test_sock_fields test_sysctl \
> > - test_progs-no_alu32 \
> > - test_current_pid_tgid_new_ns
> > + test_progs-no_alu32\
>
> accidentally removed space?
>
> > + test_ns_current_pidtgid_newns
> >
> > # Also test bpf-gcc, if present
> > ifneq ($(BPF_GCC),)
>
> [...]
>
> > +
> > +void test_ns_current_pidtgid(void)
> > +{
> > + struct test_ns_current_pidtgid__bss *bss;
> > + struct test_ns_current_pidtgid *skel;
> > + int err, duration = 0;
> > + struct stat st;
> > + __u64 id;
> > +
> > + skel = test_ns_current_pidtgid__open_and_load();
> > + CHECK(!skel, "skel_open_load", "failed to load skeleton\n");
> > + goto cleanup;
> > +
> > + pid_t tid = syscall(SYS_gettid);
> > + pid_t pid = getpid();
>
> hm... I probably missed this last time. This is not a valid C89
> standard-compliant code, all variables have to be declared up top,
> please split variable declaration and initialization.
>
> > +
> > + id = (__u64) tid << 32 | pid;
> > +
> > + err = stat("/proc/self/ns/pid", &st);
> > + if (CHECK(err, "stat", "failed /proc/self/ns/pid: %d", err))
> > + goto cleanup;
> > +
>
> [...]
>
> > diff --git a/tools/testing/selftests/bpf/progs/test_ns_current_pidtgid.c b/tools/testing/selftests/bpf/progs/test_ns_current_pidtgid.c
> > new file mode 100644
> > index 000000000000..9818a56510d9
> > --- /dev/null
> > +++ b/tools/testing/selftests/bpf/progs/test_ns_current_pidtgid.c
> > @@ -0,0 +1,25 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/* Copyright (c) 2019 Carlos Neira cneirabustos@gmail.com */
> > +
> > +#include <linux/bpf.h>
> > +#include <stdint.h>
> > +#include <bpf/bpf_helpers.h>
> > +
> > +__u64 user_pid_tgid = 0;
> > +__u64 dev = 0;
> > +__u64 ino = 0;
> > +
> > +SEC("raw_tracepoint/sys_enter")
> > +int handler(const void *ctx)
> > +{
> > + struct bpf_pidns_info nsdata;
> > +
> > + if (bpf_get_ns_current_pid_tgid(dev, ino, &nsdata,
> > + sizeof(struct bpf_pidns_info)))
> > + return 0;
> > + user_pid_tgid = (__u64)nsdata.tgid << 32 | nsdata.pid;
>
> nit: good idea to put () around << expression when combined with other
> bitwise operators.
>
> > +
> > + return 0;
> > +}
> > +
> > +char _license[] SEC("license") = "GPL";
>
> [...]
>
> > +static int newns_pidtgid(void *arg)
> > +{
> > + struct test_ns_current_pidtgid__bss *bss;
> > + struct test_ns_current_pidtgid *skel;
> > + int pidns_fd = 0, err = 0;
> > + pid_t pid, tid;
> > + struct stat st;
> > + __u64 id;
> > +
> > + skel = test_ns_current_pidtgid__open_and_load();
> > + if (!skel) {
> > + perror("Failed to load skeleton");
> > + goto cleanup;
> > + }
> > +
> > + tid = syscall(SYS_gettid);
> > + pid = getpid();
> > + id = (__u64) tid << 32 | pid;
>
> see, you don't do it here :)
>
>
> > +
> > + if (stat("/proc/self/ns/pid", &st)) {
> > + printf("Failed to stat /proc/self/ns/pid: %s\n",
> > + strerror(errno));
> > + goto cleanup;
> > + }
> > +
> > + bss = skel->bss;
> > + bss->dev = st.st_dev;
> > + bss->ino = st.st_ino;
> > + bss->user_pid_tgid = 0;
> > +
>
> [...]
Andrii,
Thank you very much, I'll incorporate these changes on the next revision.
Bests.
prev parent reply other threads:[~2020-08-06 17:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-05 16:35 [PATCH v4 bpf-next] bpf/selftests: fold test_current_pid_tgid_new_ns into test_progs Carlos Neira
2020-08-05 20:15 ` Andrii Nakryiko
2020-08-06 14:03 ` Carlos Antonio Neira Bustos [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=20200806140319.GA40984@bpf-dev \
--to=cneirabustos@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=brouer@redhat.com \
--cc=ebiederm@xmission.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 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.