bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Martin KaFai Lau <kafai@fb.com>
Cc: Andrii Nakryiko <andriin@fb.com>, bpf <bpf@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <kernel-team@fb.com>
Subject: Re: [Potential Spoof] [PATCH bpf-next] selftests/bpf: fix nanosleep for real this time
Date: Fri, 13 Mar 2020 17:10:29 -0700	[thread overview]
Message-ID: <CAEf4BzbKAz699qu0ae=A_8WryUXWywXDJm17d4ogp8x=oHXa_Q@mail.gmail.com> (raw)
In-Reply-To: <20200314000510.cmsepdhnywtglrcm@kafai-mbp>

On Fri, Mar 13, 2020 at 5:05 PM Martin KaFai Lau <kafai@fb.com> wrote:
>
> On Fri, Mar 13, 2020 at 04:35:35PM -0700, Andrii Nakryiko wrote:
> > Amazingly, some libc implementations don't call __NR_nanosleep syscall from
> > their nanosleep() APIs. Hammer it down with explicit syscall() call and never
> > get back to it again. Also simplify code for timespec initialization.
> >
> > I verified that nanosleep is called w/ printk and in exactly same Linux image
> > that is used in Travis CI. So it should both sleep and call correct syscall.
> >
> > Fixes: 4e1fd25d19e8 ("selftests/bpf: Fix usleep() implementation")
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > ---
> >  tools/testing/selftests/bpf/test_progs.c | 16 ++++++----------
> >  1 file changed, 6 insertions(+), 10 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
> > index f85a06512541..6956d722a463 100644
> > --- a/tools/testing/selftests/bpf/test_progs.c
> > +++ b/tools/testing/selftests/bpf/test_progs.c
> > @@ -35,16 +35,12 @@ struct prog_test_def {
> >   */
> >  int usleep(useconds_t usec)
> >  {
> > -     struct timespec ts;
> > -
> > -     if (usec > 999999) {
> > -             ts.tv_sec = usec / 1000000;
> > -             ts.tv_nsec = usec % 1000000;
> > -     } else {
> > -             ts.tv_sec = 0;
> > -             ts.tv_nsec = usec;
> > -     }
> > -     return nanosleep(&ts, NULL);
> > +     struct timespec ts = {
> > +             .tv_sec = usec / 1000000,
> > +             .tv_nsec = usec % 1000000,
> usec is in micro and tv_nsec is in nano?
>

Yes, this is implementation of usleep() (microsecond sleep), so usec
is microseconds. We call nanosleep internally, though, which accepts
seconds and nanoseconds units. Did I mess up math here?

But either way, sending v2, there is another place we explicitly are
calling nanosleep as well, fixing that one as well.

> > +     };
> > +
> > +     return syscall(__NR_nanosleep, &ts, NULL);
> >  }
> >

      reply	other threads:[~2020-03-14  0:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-13 23:35 [PATCH bpf-next] selftests/bpf: fix nanosleep for real this time Andrii Nakryiko
2020-03-14  0:05 ` [Potential Spoof] " Martin KaFai Lau
2020-03-14  0:10   ` Andrii Nakryiko [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='CAEf4BzbKAz699qu0ae=A_8WryUXWywXDJm17d4ogp8x=oHXa_Q@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /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).