From nobody Mon Jun 13 19:33:36 2022 X-Original-To: dev-commits-src-all@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 14ABC854F0B; Mon, 13 Jun 2022 19:33:37 +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 4LMMDw4rs6z3qNp; Mon, 13 Jun 2022 19:33:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655148816; 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=Y9BBijmarH1ybNNMhSIrCPm0SYMuboO4cLDEINn/aig=; b=VOdFMy1gwNke+PBcRd9+5ooaZA9a5MeD0MmRqrEIgQGPNwVqmJm4RXotrncwVAgtW5N30k 42nwU1WUCmzwFvswz+7EagnDXEjG7DbP0EO0WZT8c4cYf0Xfv0/dxkF6G05DEseikxFRkb xMUmtXQa9K1eEJMdhbgxQ5JpsC0sEH+uNTZO39HSCrnX6NDFhYLltPMM9EMj8O1OYe7bpR Tfz8aXbfAFqam32ZKL4vIb8/F1z2YCkqYmYMQtqGn7iGrH4DgJLkgemFwa8D4v7NQhn18j Gnaq2hIdFSzkYLViaQ25w1O2E+lsdXa+Xur59AxTgvftw5o6S/HxCoqtrkTlbA== 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 530601BE2E; Mon, 13 Jun 2022 19:33:36 +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 25DJXahn023690; Mon, 13 Jun 2022 19:33:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25DJXaI2023689; Mon, 13 Jun 2022 19:33:36 GMT (envelope-from git) Date: Mon, 13 Jun 2022 19:33:36 GMT Message-Id: <202206131933.25DJXaI2023689@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: 1b4701fe1e84 - main - thread_unsuspend(): do not unuspend the suspended leader thread doing SINGLE_ALLPROC List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 1b4701fe1e840f9ce5dae557b4dd99bda8a85735 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655148816; 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=Y9BBijmarH1ybNNMhSIrCPm0SYMuboO4cLDEINn/aig=; b=tUMg9Ndrmj6Wmf5qb70RsGqLLTv2VAEuZG1/rGzatoBl9kfnZIByIuIIAdp4xz9zzZT+Uo 4yDd9yC0JSFwtyzY5o6R4vYSyhG9Se8MsRAMxx4bsN+USVQXL0ln4zITJBRyZFw8HHixO5 lx66mkGxyzkBs+Dig8a+RD984Hdb8yRUm6WFmrL5XfEYnWK461CKCiS1e5fbx97uwHvxAp NpLgQ71bZOafSDiHrs9JWHumqhsw693N6R8DRtRwWdzIIz4mGS7fdafEFApU2UHnPwGq8v 4glbFBpDHytCKrEtEOCz2TwZzBfzZXWHxvsJ5bDZKFiWJlo2aArcpmVY5PmU9w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655148816; a=rsa-sha256; cv=none; b=JPL14uoCPZfqX48nfSezHmqeIw/F4cFP+9t5W1QsqJg6F5KHtDx/ugF/Ma8FeM6uSDidAq FZdFQIWGSqD3849H/gMq/DrGs3/O8xj+3kDP4tBVRNqmnR3gwwH4+HsdKcruh0EXZE5P7h JiaCx/o8VBL7uyvlQ2aHRVO+zfYtQ8BN5hNofP/pYNuAVY6DUw+VJFeI+kl1gsM1vpr7TC 9bbXzzE1HKuYSsDOBcjauZ/v8LqsGpzLxtc+zacQZNfuZIX7OF4mQuJ8q19eBVa7Xlfm4B 4v+TU26fWMNpDNMdrWrr1Nr9CjrAWNrkdf83fgSuvDWNezbDiTO9X7tbUvbHZw== 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=1b4701fe1e840f9ce5dae557b4dd99bda8a85735 commit 1b4701fe1e840f9ce5dae557b4dd99bda8a85735 Author: Konstantin Belousov AuthorDate: 2022-06-08 01:27:30 +0000 Commit: Konstantin Belousov CommitDate: 2022-06-13 19:30:03 +0000 thread_unsuspend(): do not unuspend the suspended leader thread doing SINGLE_ALLPROC markj wrote: tdsendsignal() may unsuspend a target thread. I think there is at least one bug there: suppose thread T is suspended in thread_single(SINGLE_ALLPROC) when trying to kill another process with REAP_KILL. Suppose a different thread sends SIGKILL to T->td_proc. Then, tdsendsignal() calls thread_unsuspend(T, T->td_proc). thread_unsuspend() incorrectly decrements T->td_proc->p_suspcount to -1. Later, when T->td_proc exits, it will wait forever in thread_single(SINGLE_EXIT) since T->td_proc->p_suspcount never reaches 1. Since the thread suspension is bounded by time needed to do thread_single(), skipping the thread_unsuspend_one() call there should not affect signal delivery if this thread is selected as target. Reported by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D35310 --- sys/kern/kern_thread.c | 14 ++++++++++++-- sys/sys/proc.h | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c index 99f76f3b014d..98e1afddc08e 100644 --- a/sys/kern/kern_thread.c +++ b/sys/kern/kern_thread.c @@ -1228,8 +1228,12 @@ thread_single(struct proc *p, int mode) else p->p_flag &= ~P_SINGLE_BOUNDARY; } - if (mode == SINGLE_ALLPROC) + if (mode == SINGLE_ALLPROC) { p->p_flag |= P_TOTAL_STOP; + thread_lock(td); + td->td_flags |= TDF_DOING_SA; + thread_unlock(td); + } p->p_flag |= P_STOPPED_SINGLE; PROC_SLOCK(p); p->p_singlethread = td; @@ -1316,6 +1320,11 @@ stopme: } } PROC_SUNLOCK(p); + if (mode == SINGLE_ALLPROC) { + thread_lock(td); + td->td_flags &= ~TDF_DOING_SA; + thread_unlock(td); + } return (0); } @@ -1602,7 +1611,8 @@ thread_unsuspend(struct proc *p) if (!P_SHOULDSTOP(p)) { FOREACH_THREAD_IN_PROC(p, td) { thread_lock(td); - if (TD_IS_SUSPENDED(td)) { + if (TD_IS_SUSPENDED(td) && (td->td_flags & + TDF_DOING_SA) == 0) { wakeup_swapper |= thread_unsuspend_one(td, p, true); } else diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 3c210c5d8ff7..cdb9cc17945d 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -468,7 +468,7 @@ do { \ #define TDF_THRWAKEUP 0x00100000 /* Libthr thread must not suspend itself. */ #define TDF_SEINTR 0x00200000 /* EINTR on stop attempts. */ #define TDF_SWAPINREQ 0x00400000 /* Swapin request due to wakeup. */ -#define TDF_UNUSED23 0x00800000 /* --available-- */ +#define TDF_DOING_SA 0x00800000 /* Doing SINGLE_ALLPROC, do not unsuspend me */ #define TDF_SCHED0 0x01000000 /* Reserved for scheduler private use */ #define TDF_SCHED1 0x02000000 /* Reserved for scheduler private use */ #define TDF_SCHED2 0x04000000 /* Reserved for scheduler private use */