Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp449788pxk; Thu, 24 Sep 2020 09:25:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeFs9zYyMFruaWKSCHcV9tMakhUMCcC1BVqcLtkqTX3gt/gSxuPo3E7glaTKPrQKrU81LY X-Received: by 2002:a17:906:2b4f:: with SMTP id b15mr676671ejg.477.1600964704108; Thu, 24 Sep 2020 09:25:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600964704; cv=none; d=google.com; s=arc-20160816; b=WyWYaILhU3+TsJR5j6HiWsvwarnj3ws5Y/2w8pyC3Gqr5XX7Jg+7/qzSiNAZPYCKM8 bUAm8lp4oR7bqU/Y7yn9gd5JK83HlIgTIOdUSjAPED4gCxVND/ePsyPlOTT9oPGvUlHN t+70Fl6qTNE2n+Gmnuw78eT3gs25aI0SwFFdecRHD43l+pwKC98z5arjM3URZdJWpylI WtntKvOhVgU8T8W/D/3oJ4HpnMNa/hjnZ0mCNe6nnQR4CQ4luusESFLixVu+vm0cdO1S 8FUwsvzRgOSD9B1TlfNxyGnHznOPbaqR8OdDHUp1bBSoucfRQdFfjrqr/9qBgFNPK/xw vxqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=qslkEX2GtrSk+bhmibRjDZmEzRb2UcB80rqkBCIaEhI=; b=bvYbvMKOE4xhikkUym2apce+W6GsWPXUibvH8Cbj+VP9TBaradjcFSxo4VX47lZmX1 vqLzoiqakkJ8Wgq/pOodszNUB/dtEjQf9oR9aPc5JHz4mMzVx2DRFHjSWngj4E5tXNtN Pj270aAK8f/hDB+0GfL63HjjMOaPujh4zeyqP9I9Qyy/070QVV8kd5YJS6cKsRM0Abvg 7AileTejQkk4a1vxY7GJ/q1kEsJ2R0dasSqgke76DOgKoGYHJfrTIY+wbQiuIy2eX0Ev ztOSQhtMtVOdo1vbkCCuCL+EpW1wkZDJQsys8oHmMYNIf6E9yEtbIcpHW3nc33QvOW8n 1YuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t22si3046910edi.341.2020.09.24.09.24.40; Thu, 24 Sep 2020 09:25:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726815AbgIXQVa (ORCPT + 99 others); Thu, 24 Sep 2020 12:21:30 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:35348 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726477AbgIXQVa (ORCPT ); Thu, 24 Sep 2020 12:21:30 -0400 Received: from ip5f5af089.dynamic.kabel-deutschland.de ([95.90.240.137] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kLTzr-00031R-6I; Thu, 24 Sep 2020 16:21:27 +0000 Date: Thu, 24 Sep 2020 18:21:26 +0200 From: Christian Brauner To: Naresh Kamboju Cc: "open list:KERNEL SELFTEST FRAMEWORK" , linux-api@vger.kernel.org, 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@lists.linaro.org Subject: Re: selftests: pidfd: pidfd_wait hangs on linux next kernel on all devices Message-ID: <20200924162126.mbthwz32w7rba7oe@wittgenstein> References: <20200924143317.getruzwu423g3o3e@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200924143317.getruzwu423g3o3e@wittgenstein> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > 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