NetBSD Problem Report #56276

From mlelstv@hoppa.1st.de  Fri Jun 25 04:28:13 2021
Return-Path: <mlelstv@hoppa.1st.de>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id A8E201A921F
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 25 Jun 2021 04:28:13 +0000 (UTC)
Message-Id: <20210625042749.9BA551D@hoppa.1st.de>
Date: Fri, 25 Jun 2021 06:27:49 +0200 (CEST)
From: mlelstv@netbsd.org
Reply-To: mlelstv@netbsd.org
To: gnats-bugs@NetBSD.org
Subject: exit hangs with vfork waiting
X-Send-Pr-Version: 3.95

>Number:         56276
>Category:       kern
>Synopsis:       exit hangs with vfork waiting
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jun 25 04:30:01 +0000 2021
>Last-Modified:  Sun Jun 27 18:50:01 +0000 2021
>Originator:     Michael van Elst
>Release:        NetBSD 9.99.85
>Organization:

>Environment:
System: NetBSD slowpoke 9.99.85 NetBSD 9.99.85 (SLOWPOKE) #13: Tue Jun 15 22:51:58 UTC 2021 mlelstv@slowpoke:/scratch2/obj.amd64/scratch/netbsd-current/src/sys/arch/amd64/compile/SLOWPOKE amd64
Architecture: x86_64
Machine: amd64
>Description:

When a process calls vfork(), it is suspended until the child exits
or calls execve().

When in this situation, a second thread of the parent calls exit()
the parent doesn't exit but waits uninterruptibly for the child.

 UID   PID PPID  CPU   PRI NI VSZ        RSS WCHAN   STAT TTY        TIME COMMAND
9997 26124 8261  29702 95  0  1074208864 716 lwpwait DEl+ pts/3 240:17.87 (ghc)
9997 15381 26124 29702 29  0  1074208864 716 parked  IV+  pts/3   0:00.00 /usr/pk

In this particular case the child also waits for a parent thread before calling
execve which results in a deadlock.

>How-To-Repeat:
Regularly happens when building ghc packages.

>Fix:
The parent thread that called vfork() should just be woken up and exit
with the process.

>Audit-Trail:
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/56276: exit hangs with vfork waiting
Date: Fri, 25 Jun 2021 05:31:52 +0000

 On Fri, Jun 25, 2021 at 04:30:01AM +0000, mlelstv@netbsd.org wrote:
  > When a process calls vfork(), it is suspended until the child exits
  > or calls execve().
  > 
  > When in this situation, a second thread of the parent calls exit()
  > the parent doesn't exit but waits uninterruptibly for the child.

 Shouldn't all threads be suspended for vfork? (as for regular fork)

 -- 
 David A. Holland
 dholland@netbsd.org

From: Michael van Elst <mlelstv@serpens.de>
To: gnats-bugs@netbsd.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org, mlelstv@netbsd.org
Subject: Re: kern/56276: exit hangs with vfork waiting
Date: Fri, 25 Jun 2021 09:16:31 +0200

 On Fri, Jun 25, 2021 at 05:35:01AM +0000, David Holland wrote:

 >  On Fri, Jun 25, 2021 at 04:30:01AM +0000, mlelstv@netbsd.org wrote:
 >   > When a process calls vfork(), it is suspended until the child exits
 >   > or calls execve().
 >   > 
 >   > When in this situation, a second thread of the parent calls exit()
 >   > the parent doesn't exit but waits uninterruptibly for the child.
 >  
 >  Shouldn't all threads be suspended for vfork? (as for regular fork)

 I would guess exit() races with vfork(). The second thread was almost
 done and waits for the other threads to finish so that it can then
 release the process resources.


 Greetings,
 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/56276: exit hangs with vfork waiting
Date: Sun, 27 Jun 2021 18:49:47 +0000

 On Fri, Jun 25, 2021 at 07:20:02AM +0000, Michael van Elst wrote:
  >  >   > When a process calls vfork(), it is suspended until the child exits
  >  >   > or calls execve().
  >  >   > 
  >  >   > When in this situation, a second thread of the parent calls exit()
  >  >   > the parent doesn't exit but waits uninterruptibly for the child.
  >  >  
  >  >  Shouldn't all threads be suspended for vfork? (as for regular fork)
  >  
  >  I would guess exit() races with vfork(). The second thread was almost
  >  done and waits for the other threads to finish so that it can then
  >  release the process resources.

 Hrm. It looks like we don't actually suspend other threads during
 fork. That is likely wrong (we can get an inconsistent copy of the
 memory space) but maybe apart from this case it doesn't matter...

 -- 
 David A. Holland
 dholland@netbsd.org

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.