netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 v2 bpf-next] fold test_current_pid_tgid_new_ns into into test_progs
Date: Tue, 30 Jun 2020 18:15:38 -0400	[thread overview]
Message-ID: <20200630221537.GA9818@bpf-dev> (raw)
In-Reply-To: <CAEf4BzYSKXE2aYkbE2XKa9z1Wc8Zv9-bkTmh=8unOM+Za-6uMw@mail.gmail.com>

On Tue, Jun 23, 2020 at 11:10:51AM -0700, Andrii Nakryiko wrote:
> On Tue, Jun 23, 2020 at 5:48 AM Carlos Neira <cneirabustos@gmail.com> wrote:
> >
> > folds tests from test_current_pid_tgid_new_ns into test_progs.
> >
> > Signed-off-by: Carlos Neira <cneirabustos@gmail.com>
> > ---
> >  tools/testing/selftests/bpf/Makefile          |   3 +-
> >  .../bpf/prog_tests/ns_current_pid_tgid.c      | 112 +++++++++++-
> >  .../bpf/test_current_pid_tgid_new_ns.c        | 159 ------------------
> >  3 files changed, 112 insertions(+), 162 deletions(-)
> >  delete mode 100644 tools/testing/selftests/bpf/test_current_pid_tgid_new_ns.c
> >
> > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> > index 22aaec74ea0a..7b2ea7adccb0 100644
> > --- a/tools/testing/selftests/bpf/Makefile
> > +++ b/tools/testing/selftests/bpf/Makefile
> > @@ -36,8 +36,7 @@ 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
> 
> Please update .gitignore as well.
> 
> >
> >  # Also test bpf-gcc, if present
> >  ifneq ($(BPF_GCC),)
> 
> [...]
> 
> > +
> > +       snprintf(nspath, sizeof(nspath) - 1, "/proc/%d/ns/pid", ppid);
> > +       pidns_fd = open(nspath, O_RDONLY);
> > +
> > +       if (CHECK(unshare(CLONE_NEWPID),
> > +               "unshare CLONE_NEWPID",
> > +               "error: %s\n", strerror(errno)))
> > +               return;
> > +
> > +       pid = vfork();
> 
> is vfork necessary()? Maybe just stick to fork(), as in original implementation?
> 
> > +       if (CHECK(pid < 0, "ns_current_pid_tgid_new_ns", "vfork error: %s\n",
> > +           strerror(errno))) {
> > +               return;
> > +       }
> > +       if (pid > 0) {
> > +       printf("waiting pid is %u\n", pid);
> 
> indentation off?
> 
> > +               usleep(5);
> > +               wait(NULL);
> 
> waitpid() for specific child would be more reliable, no?
> 
> > +               return;
> > +       } else {
> 
> what if fork failed?
> 
> > +               const char *probe_name = "raw_tracepoint/sys_enter";
> > +               const char *file = "test_ns_current_pid_tgid.o";
> > +               int err, key = 0, duration = 0;
> > +               struct bpf_link *link = NULL;
> > +               struct bpf_program *prog;
> > +               struct bpf_map *bss_map;
> > +               struct bpf_object *obj;
> > +               struct bss bss;
> > +               struct stat st;
> > +               __u64 id;
> > +
> 
> [...]
> 
> > +               err = bpf_map_lookup_elem(bpf_map__fd(bss_map), &key, &bss);
> > +               if (CHECK(err, "set_bss", "failed to get bss : %d\n", err))
> > +                       goto cleanup;
> > +
> > +               if (CHECK(id != bss.pid_tgid, "Compare user pid/tgid vs bpf pid/tgid",
> > +                       "User pid/tgid %llu BPF pid/tgid %llu\n", id, bss.pid_tgid))
> > +                       goto cleanup;
> 
> 
> Good half of all this code could be removed if you used BPF skeleton,
> see other tests utilizing *.skel.h for inspiration.
> 
> > +cleanup:
> > +               setns(pidns_fd, CLONE_NEWPID);
> > +               bpf_link__destroy(link);
> > +               bpf_object__close(obj);
> > +       }
> > +}
> > +
> > +void test_ns_current_pid_tgid(void)
> > +{
> > +       if (test__start_subtest("ns_current_pid_tgid_global_ns"))
> > +               test_ns_current_pid_tgid_global_ns();
> > +       if (test__start_subtest("ns_current_pid_tgid_new_ns"))
> > +               test_ns_current_pid_tgid_new_ns();
> > +}
> 
> [...]
Thanks!.
I'll include your feedback on the next version, thanks for reviewing this.

Bests

  reply	other threads:[~2020-06-30 22:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-23 12:47 [PATCH v2 bpf-next] fold test_current_pid_tgid_new_ns into into test_progs Carlos Neira
2020-06-23 18:10 ` Andrii Nakryiko
2020-06-30 22:15   ` Carlos Antonio Neira Bustos [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-06-03 15:34 Carlos Neira
2020-06-03 18:00 ` Alexei Starovoitov

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=20200630221537.GA9818@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 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).