From nobody Mon Jun 13 19:33:28 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id B7235854961; Mon, 13 Jun 2022 19:33:28 +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 4LMMDm4dt4z3pky; Mon, 13 Jun 2022 19:33:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655148808; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=m8EZ2OaVNxAP9WvKsj74eUe7Ec0w+TPNrPQSvyZPvFc=; b=KiNIcVVQWNKLwPiaj2ZU8l7O4MlVtLF6U9HGITAH6NR9jjV5BgL6xRNqJdCLauWHSwDZEU pBlfWis8qvmk1xinYgzMUr7XyoijYds3vnQ53rRdRHm6n6CD2ztu+PsWtKIKjOoCePeVgE AxiVoagyfYIrJMWszApQD+HQkyjQw/oxZR+HwnQOfnBHBhtMwBlKZ6GjyYBt79UnO/iDJ7 psnXGWc8MMguSrkTcrF+gEBLp69Crt42RSv2+zBz8CYOuPgLIZmqDNmBS5Kxl5XDYMJEx5 LrhaOXpxTMK17er0xVGfZFnbdHuALN91d6EB9+H5cSzkIR4VgN/PTuwlM8Hu+Q== 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 7F7381BB2B; Mon, 13 Jun 2022 19:33:28 +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 25DJXSuX023509; Mon, 13 Jun 2022 19:33:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25DJXSCx023508; Mon, 13 Jun 2022 19:33:28 GMT (envelope-from git) Date: Mon, 13 Jun 2022 19:33:28 GMT Message-Id: <202206131933.25DJXSCx023508@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: d3000939c7b9 - main - P2_WEXIT: avoid thread_single() for exiting process earlier List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org 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: d3000939c7b94fc887f23dd8946861cf0fa1b73b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655148808; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=m8EZ2OaVNxAP9WvKsj74eUe7Ec0w+TPNrPQSvyZPvFc=; b=VLGvEfwefdmtn1I2DPoQq6Jl+ETCll8fVSNgFWL5udVUyz/xQ3FhezC6zr/K9WHAPt7R4I zJF8blTcfZcfk1VxWqMEg1or72nzXKPcuLRp8Y6LcvnO8P4tM5yPCkNc6ljtWeRKiLIQgp Dtxo6CMwJYQq9+0orDq0NkH1Flh6vTgOukuPY2iulqjOoZ4Z1+1q0GVKS6uxzaf5oBqSCM Uhvg4jfatlkGvmh6XXEmLlqEZLE8q0DH0dk+0/qmKtJQjYZsB6/ov1AiqdOEPQzgiLiEMD TRCzqbF8ItAy6/+7AGQC+MfqGo2Ra87bCmEZ4NZkjEchwkbH0/HtsI47/PqKBw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655148808; a=rsa-sha256; cv=none; b=cxsl0ikcLbJqGzf+58rvpQ0SCzIiXq9MzaPQ6SA6h9Ppf/o8BfLuzSj2hZm6+0iMUJLNzz a+3tK3VWrwASQvN9kJe2LStkO4iJPkuB7+5Q2SL0UE81fYez5VN/oFBbsTKQQOHFAw7tCx T3kZhwkYS1KN/0GnKTGvi7vFPrLOSTPpAvYpcAndwZIou4tvfxvsuPpTU+asxoOnH1FZl1 vNItQK921rGBfWJZxK120DGz003nzLQujZQo6bXPh2FcXX2DJF6EzGnrYDraUB5MHDuxTz rziY9h0Vk90n74TZ1eEhkp3XwCZndquLgUnoxCxI3jU+DO7zuU7k/lF3NlLWNQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=d3000939c7b94fc887f23dd8946861cf0fa1b73b commit d3000939c7b94fc887f23dd8946861cf0fa1b73b Author: Konstantin Belousov AuthorDate: 2022-05-04 23:57:26 +0000 Commit: Konstantin Belousov CommitDate: 2022-06-13 19:30:02 +0000 P2_WEXIT: avoid thread_single() for exiting process earlier before the process itself does thread_single(SINGLE_EXIT). We cannot single-thread such process in ALLPROC (external) mode, and properly detect and report the failure to do so due to the process becoming zombie is easier to prevent than handle. In collaboration with: pho Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D35310 --- sys/kern/kern_exit.c | 2 ++ sys/kern/kern_proc.c | 2 +- sys/kern/kern_procctl.c | 2 +- sys/kern/kern_sig.c | 1 + sys/sys/proc.h | 3 +++ 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 0fc7a471f3f0..fcd9bffe862d 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -251,6 +251,8 @@ exit1(struct thread *td, int rval, int signo) * MUST abort all other threads before proceeding past here. */ PROC_LOCK(p); + p->p_flag2 |= P2_WEXIT; + /* * First check if some other thread or external request got * here before us. If so, act appropriately: exit or suspend. diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index cd528d47830d..6796d672afd7 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -3446,7 +3446,7 @@ allproc_loop: PROC_UNLOCK(p); continue; } - if ((p->p_flag & P_WEXIT) != 0) { + if ((p->p_flag2 & P2_WEXIT) != 0) { seen_exiting = true; PROC_UNLOCK(p); continue; diff --git a/sys/kern/kern_procctl.c b/sys/kern/kern_procctl.c index 9db9577fde3d..640ebc32ee55 100644 --- a/sys/kern/kern_procctl.c +++ b/sys/kern/kern_procctl.c @@ -325,7 +325,7 @@ reap_kill_proc(struct thread *td, struct proc *p2, ksiginfo_t *ksi, res = true; PROC_LOCK(p2); - if ((p2->p_flag & P_WEXIT) == 0) { + if ((p2->p_flag2 & P2_WEXIT) == 0) { _PHOLD_LITE(p2); res = reap_kill_proc_locked(td, p2, ksi, rk, error); _PRELE(p2); diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index ce6f517262a4..afb2fd78c231 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -3406,6 +3406,7 @@ sigexit(struct thread *td, int sig) struct proc *p = td->td_proc; PROC_LOCK_ASSERT(p, MA_OWNED); + p->p_flag2 |= P2_WEXIT; p->p_acflag |= AXSIG; /* * We must be single-threading to generate a core dump. This diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 223714724aca..5027cca5da8b 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -847,6 +847,9 @@ struct proc { #define P2_NO_NEW_PRIVS 0x00008000 /* Ignore setuid */ #define P2_WXORX_DISABLE 0x00010000 /* WX mappings enabled */ #define P2_WXORX_ENABLE_EXEC 0x00020000 /* WXORX enabled after exec */ +#define P2_WEXIT 0x00040000 /* exit just started, no + external thread_single() is + permitted */ /* Flags protected by proctree_lock, kept in p_treeflags. */ #define P_TREE_ORPHANED 0x00000001 /* Reparented, on orphan list */