All of lore.kernel.org
 help / color / mirror / Atom feed
* selftests: pidfd: pidfd_wait hangs on linux next kernel on all devices
@ 2020-09-23 14:22 Naresh Kamboju
  2020-09-24 14:33 ` Christian Brauner
  0 siblings, 1 reply; 6+ messages in thread
From: Naresh Kamboju @ 2020-09-23 14:22 UTC (permalink / raw)
  To: open list:KERNEL SELFTEST FRAMEWORK, linux-api, open list
  Cc: Christian Brauner, Kees Cook, Peter Zijlstra (Intel),
	Ingo Molnar, Thomas Gleixner, Oleg Nesterov, Eric W. Biederman,
	Sargun Dhillon, Aleksa Sarai, Josh Triplett, Jens Axboe,
	Christian Brauner, Shuah Khan, lkft-triage

selftests: pidfd: pidfd_wait hangs on linux next kernel on x86_64,
i386 and arm64 Juno-r2
These devices are using NFS mounted rootfs.
I have tested pidfd testcases independently and all test PASS.

The Hang or exit from test run noticed when run by run_kselftest.sh

pidfd_wait.c:208:wait_nonblock:Expected sys_waitid(P_PIDFD, pidfd,
&info, WSTOPPED, NULL) (-1) == 0 (0)
wait_nonblock: Test terminated by assertion

metadata:
  git branch: master
  git repo: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
  git commit: e64997027d5f171148687e58b78c8b3c869a6158
  git describe: next-20200922
  make_kernelversion: 5.9.0-rc6
  kernel-config:
http://snapshots.linaro.org/openembedded/lkft/lkft/sumo/intel-core2-32/lkft/linux-next/865/config

Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>

Test output log:
---------------------
[ 1385.104983] audit: type=1701 audit(1600804535.960:87865):
auid=4294967295 uid=0 gid=0 ses=4294967295 subj=kernel pid=31268
comm=\"pidfd_wait\"
exe=\"/opt/kselftests/default-in-kernel/pidfd/pidfd_wait\" sig=6 res=1

# selftests: pidfd: pidfd_wait
# TAP version 13
# 1..3
# # Starting 3 tests from 1 test cases.
# #  RUN           global.wait_simple ...
# #            OK  global.wait_simple
# ok 1 global.wait_simple
# #  RUN           global.wait_states ...
# #            OK  global.wait_states
# ok 2 global.wait_states
# #  RUN           global.wait_nonblock ...
# # pidfd_wait.c:208:wait_nonblock:Expected sys_waitid(P_PIDFD, pidfd,
&info, WSTOPPED, NULL) (-1) == 0 (0)
# # wait_nonblock: Test terminated by assertion
# #          FAIL  global.wait_nonblock
# not ok 3 global.wait_nonblock
# # FAILED: 2 / 3 tests passed.
# # Totals: pass:2 fail:1 xfail:0 xpass:0 skip:0 error:0
Marking unfinished test run as failed

ref:
https://lkft.validation.linaro.org/scheduler/job/1782129#L11737
https://lkft.validation.linaro.org/scheduler/job/1782130#L12735
https://lkft.validation.linaro.org/scheduler/job/1782138#L14178

-- 
Linaro LKFT
https://lkft.linaro.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: selftests: pidfd: pidfd_wait hangs on linux next kernel on all devices
  2020-09-23 14:22 selftests: pidfd: pidfd_wait hangs on linux next kernel on all devices Naresh Kamboju
@ 2020-09-24 14:33 ` Christian Brauner
  2020-09-24 16:21   ` Christian Brauner
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Brauner @ 2020-09-24 14:33 UTC (permalink / raw)
  To: Naresh Kamboju
  Cc: open list:KERNEL SELFTEST FRAMEWORK, linux-api, open list,
	Christian Brauner, Kees Cook, Peter Zijlstra (Intel),
	Ingo Molnar, Thomas Gleixner, Oleg Nesterov, Eric W. Biederman,
	Sargun Dhillon, Aleksa Sarai, Josh Triplett, Jens Axboe,
	Shuah Khan, lkft-triage

On Wed, Sep 23, 2020 at 07:52:05PM +0530, Naresh Kamboju wrote:
> selftests: pidfd: pidfd_wait hangs on linux next kernel on x86_64,
> i386 and arm64 Juno-r2
> These devices are using NFS mounted rootfs.
> I have tested pidfd testcases independently and all test PASS.
> 
> The Hang or exit from test run noticed when run by run_kselftest.sh
> 
> pidfd_wait.c:208:wait_nonblock:Expected sys_waitid(P_PIDFD, pidfd,
> &info, WSTOPPED, NULL) (-1) == 0 (0)
> wait_nonblock: Test terminated by assertion
> 
> metadata:
>   git branch: master
>   git repo: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
>   git commit: e64997027d5f171148687e58b78c8b3c869a6158
>   git describe: next-20200922
>   make_kernelversion: 5.9.0-rc6
>   kernel-config:
> http://snapshots.linaro.org/openembedded/lkft/lkft/sumo/intel-core2-32/lkft/linux-next/865/config
> 
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>

Thanks for reproting this. I'm taking a look now!
Christian
 https://lkft.linaro.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: selftests: pidfd: pidfd_wait hangs on linux next kernel on all devices
  2020-09-24 14:33 ` Christian Brauner
@ 2020-09-24 16:21   ` Christian Brauner
  2020-09-25  6:09     ` Naresh Kamboju
  2020-10-02 17:31     ` Naresh Kamboju
  0 siblings, 2 replies; 6+ messages in thread
From: Christian Brauner @ 2020-09-24 16:21 UTC (permalink / raw)
  To: Naresh Kamboju
  Cc: open list:KERNEL SELFTEST FRAMEWORK, linux-api, open list,
	Christian Brauner, Kees Cook, Peter Zijlstra (Intel),
	Ingo Molnar, Thomas Gleixner, Oleg Nesterov, Eric W. Biederman,
	Sargun Dhillon, Aleksa Sarai, Josh Triplett, Jens Axboe,
	Shuah Khan, lkft-triage

On Thu, Sep 24, 2020 at 04:33:17PM +0200, Christian Brauner wrote:
> On Wed, Sep 23, 2020 at 07:52:05PM +0530, Naresh Kamboju wrote:
> > selftests: pidfd: pidfd_wait hangs on linux next kernel on x86_64,
> > i386 and arm64 Juno-r2
> > These devices are using NFS mounted rootfs.
> > I have tested pidfd testcases independently and all test PASS.
> > 
> > The Hang or exit from test run noticed when run by run_kselftest.sh
> > 
> > pidfd_wait.c:208:wait_nonblock:Expected sys_waitid(P_PIDFD, pidfd,
> > &info, WSTOPPED, NULL) (-1) == 0 (0)
> > wait_nonblock: Test terminated by assertion
> > 
> > metadata:
> >   git branch: master
> >   git repo: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
> >   git commit: e64997027d5f171148687e58b78c8b3c869a6158
> >   git describe: next-20200922
> >   make_kernelversion: 5.9.0-rc6
> >   kernel-config:
> > http://snapshots.linaro.org/openembedded/lkft/lkft/sumo/intel-core2-32/lkft/linux-next/865/config
> > 
> > Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> 
> Thanks for reproting this. I'm taking a look now!

Ok, this is a simple race in the selftests, that I overlooked and which
is more likely to hit when there's a lot of processes running on the
system. Basically the child process hasn't SIGSTOPed itself yet but the
parent is already calling waitid() on a O_NONBLOCK pidfd. Since it
doesn't find a WSTOPPED process it returns -EAGAIN correctly.

The fix for this is to move the line where we're removing the O_NONBLOCK
property from the fd before the waitid() WSTOPPED call so we hang until
the child becomes stopped.

So I believe the fix is:

diff --git a/tools/testing/selftests/pidfd/pidfd_wait.c b/tools/testing/selftests/pidfd/pidfd_wait.c
index 4063d6f31fa4..be2943f072f6 100644
--- a/tools/testing/selftests/pidfd/pidfd_wait.c
+++ b/tools/testing/selftests/pidfd/pidfd_wait.c
@@ -205,6 +205,8 @@ TEST(wait_nonblock)
        ret = sys_waitid(P_PIDFD, pidfd, &info, WEXITED | WNOHANG, NULL);
        ASSERT_EQ(ret, 0);

+       ASSERT_EQ(fcntl(pidfd, F_SETFL, (flags & ~O_NONBLOCK)), 0);
+
        ASSERT_EQ(sys_waitid(P_PIDFD, pidfd, &info, WSTOPPED, NULL), 0);
        ASSERT_EQ(info.si_signo, SIGCHLD);
        ASSERT_EQ(info.si_code, CLD_STOPPED);
@@ -212,8 +214,6 @@ TEST(wait_nonblock)

        ASSERT_EQ(sys_pidfd_send_signal(pidfd, SIGCONT, NULL, 0), 0);

-       ASSERT_EQ(fcntl(pidfd, F_SETFL, (flags & ~O_NONBLOCK)), 0);
-
        ASSERT_EQ(sys_waitid(P_PIDFD, pidfd, &info, WEXITED, NULL), 0);
        ASSERT_EQ(info.si_signo, SIGCHLD);
        ASSERT_EQ(info.si_code, CLD_EXITED);

Christian

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: selftests: pidfd: pidfd_wait hangs on linux next kernel on all devices
  2020-09-24 16:21   ` Christian Brauner
@ 2020-09-25  6:09     ` Naresh Kamboju
  2020-10-02 17:31     ` Naresh Kamboju
  1 sibling, 0 replies; 6+ messages in thread
From: Naresh Kamboju @ 2020-09-25  6:09 UTC (permalink / raw)
  To: Christian Brauner
  Cc: open list:KERNEL SELFTEST FRAMEWORK, linux-api, open list,
	Christian Brauner, Kees Cook, Peter Zijlstra (Intel),
	Ingo Molnar, Thomas Gleixner, Oleg Nesterov, Eric W. Biederman,
	Sargun Dhillon, Aleksa Sarai, Josh Triplett, Jens Axboe,
	Shuah Khan, lkft-triage

On Thu, 24 Sep 2020 at 21:51, Christian Brauner
<christian.brauner@ubuntu.com> wrote:
>
> On Thu, Sep 24, 2020 at 04:33:17PM +0200, Christian Brauner wrote:
> > On Wed, Sep 23, 2020 at 07:52:05PM +0530, Naresh Kamboju wrote:
> > > selftests: pidfd: pidfd_wait hangs on linux next kernel on x86_64,
> > > i386 and arm64 Juno-r2
> > > These devices are using NFS mounted rootfs.
> > > I have tested pidfd testcases independently and all test PASS.
> > >
> > > The Hang or exit from test run noticed when run by run_kselftest.sh
> > >
> > > pidfd_wait.c:208:wait_nonblock:Expected sys_waitid(P_PIDFD, pidfd,
> > > &info, WSTOPPED, NULL) (-1) == 0 (0)
> > > wait_nonblock: Test terminated by assertion
> > >
> > > metadata:
> > >   git branch: master
> > >   git repo: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
> > >   git commit: e64997027d5f171148687e58b78c8b3c869a6158
> > >   git describe: next-20200922
> > >   make_kernelversion: 5.9.0-rc6
> > >   kernel-config:
> > > http://snapshots.linaro.org/openembedded/lkft/lkft/sumo/intel-core2-32/lkft/linux-next/865/config
> > >
> > > Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> >
> > Thanks for reproting this. I'm taking a look now!
>
> Ok, this is a simple race in the selftests, that I overlooked and which
> is more likely to hit when there's a lot of processes running on the
> system. Basically the child process hasn't SIGSTOPed itself yet but the
> parent is already calling waitid() on a O_NONBLOCK pidfd. Since it
> doesn't find a WSTOPPED process it returns -EAGAIN correctly.
>
> The fix for this is to move the line where we're removing the O_NONBLOCK
> property from the fd before the waitid() WSTOPPED call so we hang until
> the child becomes stopped.
>
> So I believe the fix is:

This patch applied and scheduled for kselftest full test run.

>
> diff --git a/tools/testing/selftests/pidfd/pidfd_wait.c b/tools/testing/selftests/pidfd/pidfd_wait.c
> index 4063d6f31fa4..be2943f072f6 100644
> --- a/tools/testing/selftests/pidfd/pidfd_wait.c
> +++ b/tools/testing/selftests/pidfd/pidfd_wait.c
> @@ -205,6 +205,8 @@ TEST(wait_nonblock)
>         ret = sys_waitid(P_PIDFD, pidfd, &info, WEXITED | WNOHANG, NULL);
>         ASSERT_EQ(ret, 0);
>
> +       ASSERT_EQ(fcntl(pidfd, F_SETFL, (flags & ~O_NONBLOCK)), 0);
> +
>         ASSERT_EQ(sys_waitid(P_PIDFD, pidfd, &info, WSTOPPED, NULL), 0);
>         ASSERT_EQ(info.si_signo, SIGCHLD);
>         ASSERT_EQ(info.si_code, CLD_STOPPED);
> @@ -212,8 +214,6 @@ TEST(wait_nonblock)
>
>         ASSERT_EQ(sys_pidfd_send_signal(pidfd, SIGCONT, NULL, 0), 0);
>
> -       ASSERT_EQ(fcntl(pidfd, F_SETFL, (flags & ~O_NONBLOCK)), 0);
> -
>         ASSERT_EQ(sys_waitid(P_PIDFD, pidfd, &info, WEXITED, NULL), 0);
>         ASSERT_EQ(info.si_signo, SIGCHLD);
>         ASSERT_EQ(info.si_code, CLD_EXITED);
>
> Christian

- Naresh

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: selftests: pidfd: pidfd_wait hangs on linux next kernel on all devices
  2020-09-24 16:21   ` Christian Brauner
  2020-09-25  6:09     ` Naresh Kamboju
@ 2020-10-02 17:31     ` Naresh Kamboju
  2020-10-09  9:58       ` Christian Brauner
  1 sibling, 1 reply; 6+ messages in thread
From: Naresh Kamboju @ 2020-10-02 17:31 UTC (permalink / raw)
  To: Christian Brauner
  Cc: open list:KERNEL SELFTEST FRAMEWORK, linux-api, open list,
	Christian Brauner, Kees Cook, Peter Zijlstra (Intel),
	Ingo Molnar, Thomas Gleixner, Oleg Nesterov, Eric W. Biederman,
	Sargun Dhillon, Aleksa Sarai, Josh Triplett, Jens Axboe,
	Shuah Khan, lkft-triage

On Thu, 24 Sep 2020 at 21:51, Christian Brauner
<christian.brauner@ubuntu.com> wrote:
>
> On Thu, Sep 24, 2020 at 04:33:17PM +0200, Christian Brauner wrote:
> > On Wed, Sep 23, 2020 at 07:52:05PM +0530, Naresh Kamboju wrote:
> > > selftests: pidfd: pidfd_wait hangs on linux next kernel on x86_64,
> > > i386 and arm64 Juno-r2
> > > These devices are using NFS mounted rootfs.
> > > I have tested pidfd testcases independently and all test PASS.
> > >
> > > The Hang or exit from test run noticed when run by run_kselftest.sh
> > >
> > > pidfd_wait.c:208:wait_nonblock:Expected sys_waitid(P_PIDFD, pidfd,
> > > &info, WSTOPPED, NULL) (-1) == 0 (0)
> > > wait_nonblock: Test terminated by assertion
> > >
> > > metadata:
> > >   git branch: master
> > >   git repo: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
> > >   git commit: e64997027d5f171148687e58b78c8b3c869a6158
> > >   git describe: next-20200922
> > >   make_kernelversion: 5.9.0-rc6
> > >   kernel-config:
> > > http://snapshots.linaro.org/openembedded/lkft/lkft/sumo/intel-core2-32/lkft/linux-next/865/config
> > >
> > > Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> >
> > Thanks for reproting this. I'm taking a look now!
>
> Ok, this is a simple race in the selftests, that I overlooked and which
> is more likely to hit when there's a lot of processes running on the
> system. Basically the child process hasn't SIGSTOPed itself yet but the
> parent is already calling waitid() on a O_NONBLOCK pidfd. Since it
> doesn't find a WSTOPPED process it returns -EAGAIN correctly.
>
> The fix for this is to move the line where we're removing the O_NONBLOCK
> property from the fd before the waitid() WSTOPPED call so we hang until
> the child becomes stopped.
>
> So I believe the fix is:

I have tested this patch and the pidfd_wait test did not hang this time.

Tested-by: Naresh Kamboju <naresh.kamboju@linaro.org>

test log link
https://lkft.validation.linaro.org/scheduler/job/1813223

>
> diff --git a/tools/testing/selftests/pidfd/pidfd_wait.c b/tools/testing/selftests/pidfd/pidfd_wait.c
> index 4063d6f31fa4..be2943f072f6 100644
> --- a/tools/testing/selftests/pidfd/pidfd_wait.c
> +++ b/tools/testing/selftests/pidfd/pidfd_wait.c
> @@ -205,6 +205,8 @@ TEST(wait_nonblock)
>         ret = sys_waitid(P_PIDFD, pidfd, &info, WEXITED | WNOHANG, NULL);
>         ASSERT_EQ(ret, 0);
>
> +       ASSERT_EQ(fcntl(pidfd, F_SETFL, (flags & ~O_NONBLOCK)), 0);
> +
>         ASSERT_EQ(sys_waitid(P_PIDFD, pidfd, &info, WSTOPPED, NULL), 0);
>         ASSERT_EQ(info.si_signo, SIGCHLD);
>         ASSERT_EQ(info.si_code, CLD_STOPPED);
> @@ -212,8 +214,6 @@ TEST(wait_nonblock)
>
>         ASSERT_EQ(sys_pidfd_send_signal(pidfd, SIGCONT, NULL, 0), 0);
>
> -       ASSERT_EQ(fcntl(pidfd, F_SETFL, (flags & ~O_NONBLOCK)), 0);
> -
>         ASSERT_EQ(sys_waitid(P_PIDFD, pidfd, &info, WEXITED, NULL), 0);
>         ASSERT_EQ(info.si_signo, SIGCHLD);
>         ASSERT_EQ(info.si_code, CLD_EXITED);
>

- Naresh

> Christian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: selftests: pidfd: pidfd_wait hangs on linux next kernel on all devices
  2020-10-02 17:31     ` Naresh Kamboju
@ 2020-10-09  9:58       ` Christian Brauner
  0 siblings, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2020-10-09  9:58 UTC (permalink / raw)
  To: Naresh Kamboju
  Cc: open list:KERNEL SELFTEST FRAMEWORK, linux-api, open list,
	Christian Brauner, Kees Cook, Peter Zijlstra (Intel),
	Ingo Molnar, Thomas Gleixner, Oleg Nesterov, Eric W. Biederman,
	Sargun Dhillon, Aleksa Sarai, Josh Triplett, Jens Axboe,
	Shuah Khan, lkft-triage

On Fri, Oct 02, 2020 at 11:01:34PM +0530, Naresh Kamboju wrote:
> On Thu, 24 Sep 2020 at 21:51, Christian Brauner
> <christian.brauner@ubuntu.com> wrote:
> >
> > On Thu, Sep 24, 2020 at 04:33:17PM +0200, Christian Brauner wrote:
> > > On Wed, Sep 23, 2020 at 07:52:05PM +0530, Naresh Kamboju wrote:
> > > > selftests: pidfd: pidfd_wait hangs on linux next kernel on x86_64,
> > > > i386 and arm64 Juno-r2
> > > > These devices are using NFS mounted rootfs.
> > > > I have tested pidfd testcases independently and all test PASS.
> > > >
> > > > The Hang or exit from test run noticed when run by run_kselftest.sh
> > > >
> > > > pidfd_wait.c:208:wait_nonblock:Expected sys_waitid(P_PIDFD, pidfd,
> > > > &info, WSTOPPED, NULL) (-1) == 0 (0)
> > > > wait_nonblock: Test terminated by assertion
> > > >
> > > > metadata:
> > > >   git branch: master
> > > >   git repo: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
> > > >   git commit: e64997027d5f171148687e58b78c8b3c869a6158
> > > >   git describe: next-20200922
> > > >   make_kernelversion: 5.9.0-rc6
> > > >   kernel-config:
> > > > http://snapshots.linaro.org/openembedded/lkft/lkft/sumo/intel-core2-32/lkft/linux-next/865/config
> > > >
> > > > Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> > >
> > > Thanks for reproting this. I'm taking a look now!
> >
> > Ok, this is a simple race in the selftests, that I overlooked and which
> > is more likely to hit when there's a lot of processes running on the
> > system. Basically the child process hasn't SIGSTOPed itself yet but the
> > parent is already calling waitid() on a O_NONBLOCK pidfd. Since it
> > doesn't find a WSTOPPED process it returns -EAGAIN correctly.
> >
> > The fix for this is to move the line where we're removing the O_NONBLOCK
> > property from the fd before the waitid() WSTOPPED call so we hang until
> > the child becomes stopped.
> >
> > So I believe the fix is:
> 
> I have tested this patch and the pidfd_wait test did not hang this time.
> 
> Tested-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> 
> test log link
> https://lkft.validation.linaro.org/scheduler/job/1813223

Thanks for testing, Naresh. I've applied the patch:
https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/commit/?h=pidfd_o_nonblock&id=01361b665a26ef0c087e53f14cf310d1cfe0cf98

Christian

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-10-09  9:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-23 14:22 selftests: pidfd: pidfd_wait hangs on linux next kernel on all devices Naresh Kamboju
2020-09-24 14:33 ` Christian Brauner
2020-09-24 16:21   ` Christian Brauner
2020-09-25  6:09     ` Naresh Kamboju
2020-10-02 17:31     ` Naresh Kamboju
2020-10-09  9:58       ` Christian Brauner

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.