From owner-svn-src-all@freebsd.org Sat Feb 17 16:38:33 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2DAF8F1E680; Sat, 17 Feb 2018 16:38:33 +0000 (UTC) (envelope-from pho@holm.cc) Received: from relay01.pair.com (relay01.pair.com [209.68.5.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CFA5688491; Sat, 17 Feb 2018 16:38:32 +0000 (UTC) (envelope-from pho@holm.cc) Received: from x2.osted.lan (87-58-223-204-dynamic.dk.customer.tdc.net [87.58.223.204]) by relay01.pair.com (Postfix) with ESMTP id 75228D00377; Sat, 17 Feb 2018 11:38:25 -0500 (EST) Received: from x2.osted.lan (localhost [127.0.0.1]) by x2.osted.lan (8.14.9/8.14.9) with ESMTP id w1HGcM9h081691 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 17 Feb 2018 17:38:23 +0100 (CET) (envelope-from pho@x2.osted.lan) Received: (from pho@localhost) by x2.osted.lan (8.14.9/8.14.9/Submit) id w1HGcMx3081690; Sat, 17 Feb 2018 17:38:22 +0100 (CET) (envelope-from pho) Date: Sat, 17 Feb 2018 17:38:22 +0100 From: Peter Holm To: Konstantin Belousov Cc: Mateusz Guzik , Mateusz Guzik , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r329448 - head/sys/kern Message-ID: <20180217163822.GA81555@x2.osted.lan> References: <201802170848.w1H8mkfb081764@repo.freebsd.org> <20180217112738.GO94212@kib.kiev.ua> <20180217162632.GQ94212@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180217162632.GQ94212@kib.kiev.ua> User-Agent: Mutt/1.5.23 (2014-03-12) X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Feb 2018 16:38:33 -0000 On Sat, Feb 17, 2018 at 06:26:32PM +0200, Konstantin Belousov wrote: > On Sat, Feb 17, 2018 at 05:07:07PM +0100, Mateusz Guzik wrote: > > On Sat, Feb 17, 2018 at 01:27:38PM +0200, Konstantin Belousov wrote: > > > On Sat, Feb 17, 2018 at 08:48:46AM +0000, Mateusz Guzik wrote: > > > > Author: mjg > > > > Date: Sat Feb 17 08:48:45 2018 > > > > New Revision: 329448 > > > > URL: https://svnweb.freebsd.org/changeset/base/329448 > > > > > > > > Log: > > > > exit: get rid of PROC_SLOCK when checking a process to report > > > Was this tested ? > > > > > > > I was trussing multithreaded microbenchmarks, no issues. > > > > > In particular, are you aware of r309539 ? > > > > > > > So it looks like I misread the code - I have grepped > > thread_suspend_switch operating with the proc locked and misread > > thread_suspend_one's assert as PROC_LOCK_ASSERT. > > > > That said, I think this is harmless. Regardless of the lock the > > inspecting thread can race and check "too soon". Even for a case where > > it decides to report, I don't see anything which would depend on the > > suspending thread to finish. > It was definitely not harmless when I tried to avoid the spin lock there, > but I do not remember exact failure mode. Most likely, it was a missed > report of the traced child indeed, but I am not sure that truss triggered > it. Most likely, Peter Holm was the reporter, since he is listed in > the commit. > I ran a truss(1) test on r329456 and it fails. I have not had a chance to look closer at this, but this is what I see: [root@mercat1 /home/pho]# pgrep truss | xargs ps -Hlp UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND 0 41149 41118 0 52 0 11532 2588 wait I 0 0:01.38 truss /tmp/ttruss 10 0 41151 41149 0 52 0 13156 2300 - TX 0 0:00.98 /tmp/ttruss 10 0 41151 41149 0 52 0 13156 2300 - TX 0 0:00.00 /tmp/ttruss 10 [root@mercat1 /home/pho]# procstat -k 41151 PID TID COMM TDNAME KSTACK 41151 100211 ttruss - mi_switch thread_suspend_switch ptracestop amd64_syscall fast_syscall_common 41151 100765 ttruss - mi_switch thread_suspend_check ast doreti_ast [root@mercat1 /home/pho]# > > > > However, locking can be employed in a way which is avoided in the common > > case: > > > > diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c > > index b063bda5b7ff..4ae24bcd7059 100644 > > --- a/sys/kern/kern_exit.c > > +++ b/sys/kern/kern_exit.c > > @@ -1174,6 +1174,7 @@ kern_wait6(struct thread *td, idtype_t idtype, id_t > > id, int *status, > > struct proc *p, *q; > > pid_t pid; > > int error, nfound, ret; > > + bool report; > > > > AUDIT_ARG_VALUE((int)idtype); /* XXX - This is likely wrong! */ > > AUDIT_ARG_PID((pid_t)id); /* XXX - This may be wrong! */ > > @@ -1226,27 +1227,36 @@ kern_wait6(struct thread *td, idtype_t idtype, id_t > > id, int *status, > > PROC_LOCK_ASSERT(p, MA_OWNED); > > > > if ((options & WTRAPPED) != 0 && > > - (p->p_flag & P_TRACED) != 0 && > > - (p->p_flag & (P_STOPPED_TRACE | P_STOPPED_SIG)) != 0 && > > - p->p_suspcount == p->p_numthreads && > > - (p->p_flag & P_WAITED) == 0) { > > + (p->p_flag & P_TRACED) != 0) { > > + PROC_SLOCK(p); > > + report = > > + ((p->p_flag & (P_STOPPED_TRACE | > > P_STOPPED_SIG)) && > > + p->p_suspcount == p->p_numthreads && > > + (p->p_flag & P_WAITED) == 0); > > + PROC_SUNLOCK(p); > > + if (report) { > > CTR4(KTR_PTRACE, > > "wait: returning trapped pid %d status %#x " > > "(xstat %d) xthread %d", > > p->p_pid, W_STOPCODE(p->p_xsig), p->p_xsig, > > p->p_xthread != NULL ? > > p->p_xthread->td_tid : -1); > > - report_alive_proc(td, p, siginfo, status, options, > > - CLD_TRAPPED); > > - return (0); > > + report_alive_proc(td, p, siginfo, status, > > + options, CLD_TRAPPED); > > + return (0); > > + } > > } > > if ((options & WUNTRACED) != 0 && > > - (p->p_flag & P_STOPPED_SIG) != 0 && > > - p->p_suspcount == p->p_numthreads && > > - (p->p_flag & P_WAITED) == 0) { > > - report_alive_proc(td, p, siginfo, status, options, > > + report_alive_proc(td, p, siginfo, status, > > + options, CLD_TRAPPED); > > + return (0); > > + } > > } > > if ((options & WUNTRACED) != 0 && > > - (p->p_flag & P_STOPPED_SIG) != 0 && > > - p->p_suspcount == p->p_numthreads && > > - (p->p_flag & P_WAITED) == 0) { > > - report_alive_proc(td, p, siginfo, status, options, > > - CLD_STOPPED); > > - return (0); > > + (p->p_flag & P_STOPPED_SIG) != 0) { > > + PROC_SLOCK(p); > > + report = (p->p_suspcount == p->p_numthreads && > > + ((p->p_flag & P_WAITED) == 0)); > > + PROC_SUNLOCK(p); > > + if (report) { > > + report_alive_proc(td, p, siginfo, status, > > + options, CLD_STOPPED); > > + return (0); > > + } > > } > > if ((options & WCONTINUED) != 0 && > > (p->p_flag & P_CONTINUED) != 0) { > > > If this works, I am fine with the patch. Still, I would prefer to have > the original commit reverted for now, until the fix is tested. Then, > commit updated patch. -- Peter