From owner-dev-commits-src-all@freebsd.org Tue Jun 15 23:55:20 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 17277656A8E; Tue, 15 Jun 2021 23:55:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4G4QDR5XXQz3qvP; Tue, 15 Jun 2021 23:55:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8A1D911949; Tue, 15 Jun 2021 23:55:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 15FNtJDn086721; Tue, 15 Jun 2021 23:55:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 15FNtJQj086720; Tue, 15 Jun 2021 23:55:19 GMT (envelope-from git) Date: Tue, 15 Jun 2021 23:55:19 GMT Message-Id: <202106152355.15FNtJQj086720@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: a12e901a5a65 - main - Add a knob to disable dequeueing SIGCHLD on waiting for live process MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a12e901a5a65417849c1ccf1e37b8d092fa438da Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jun 2021 23:55:20 -0000 The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=a12e901a5a65417849c1ccf1e37b8d092fa438da commit a12e901a5a65417849c1ccf1e37b8d092fa438da Author: Konstantin Belousov AuthorDate: 2021-06-05 18:24:35 +0000 Commit: Konstantin Belousov CommitDate: 2021-06-15 23:00:19 +0000 Add a knob to disable dequeueing SIGCHLD on waiting for live process It seems that Linux does not dequeue siginfo for SIGCHLD when wait*(2) reports status of the running process. In particular, sigwaitinfo(2) and other signal querying syscalls can observe the siginfo after wait. FreeBSD dequeued siginfo from the beginning, so we cannot change the default ABI to be more compatible. Still, add a knob to enable to change to the other behavior for debugging purposes. Reported by: dchagin Reviewed by: dchagin, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D30675 --- sys/kern/kern_exit.c | 14 +++++++++++--- sys/sys/sysent.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index cb5996982a3a..fcd8b39a8ee2 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -105,6 +105,11 @@ SYSCTL_INT(_kern, OID_AUTO, kill_on_debugger_exit, CTLFLAG_RWTUN, &kern_kill_on_dbg_exit, 0, "Kill ptraced processes when debugger exits"); +static bool kern_wait_dequeue_sigchld = 1; +SYSCTL_BOOL(_kern, OID_AUTO, wait_dequeue_sigchld, CTLFLAG_RWTUN, + &kern_wait_dequeue_sigchld, 0, + "Dequeue SIGCHLD on wait(2) for live process"); + struct proc * proc_realparent(struct proc *child) { @@ -1207,9 +1212,12 @@ report_alive_proc(struct thread *td, struct proc *p, siginfo_t *siginfo, p->p_flag &= ~P_CONTINUED; else p->p_flag |= P_WAITED; - PROC_LOCK(td->td_proc); - sigqueue_take(p->p_ksi); - PROC_UNLOCK(td->td_proc); + if (kern_wait_dequeue_sigchld && + (td->td_proc->p_sysent->sv_flags & SV_SIG_WAITNDQ) == 0) { + PROC_LOCK(td->td_proc); + sigqueue_take(p->p_ksi); + PROC_UNLOCK(td->td_proc); + } } sx_xunlock(&proctree_lock); if (siginfo != NULL) { diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h index 95e9dcb1a335..8b0903f7dcc0 100644 --- a/sys/sys/sysent.h +++ b/sys/sys/sysent.h @@ -162,6 +162,7 @@ struct sysentvec { #define SV_ASLR 0x080000 /* ASLR allowed. */ #define SV_RNG_SEED_VER 0x100000 /* random(4) reseed generation. */ #define SV_SIG_DISCIGN 0x200000 /* Do not discard ignored signals */ +#define SV_SIG_WAITNDQ 0x400000 /* Wait does not dequeue SIGCHLD */ #define SV_ABI_MASK 0xff #define SV_PROC_FLAG(p, x) ((p)->p_sysent->sv_flags & (x))