From nobody Wed Oct 06 14:05:34 2021 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 491FE17E711A; Wed, 6 Oct 2021 14:05:35 +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 4HPbnp5s5Xz3hRF; Wed, 6 Oct 2021 14:05:34 +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 7BB172182C; Wed, 6 Oct 2021 14:05:34 +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 196E5YTU086726; Wed, 6 Oct 2021 14:05:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 196E5YML086725; Wed, 6 Oct 2021 14:05:34 GMT (envelope-from git) Date: Wed, 6 Oct 2021 14:05:34 GMT Message-Id: <202110061405.196E5YML086725@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: 9b86d3e5de19 - main - When queuing ignored signal, only abort target thread' sleep if it is inside sigwait() 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: 9b86d3e5de1997ed8d3153d4530bcb981e6602b9 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=9b86d3e5de1997ed8d3153d4530bcb981e6602b9 commit 9b86d3e5de1997ed8d3153d4530bcb981e6602b9 Author: Konstantin Belousov AuthorDate: 2021-10-03 02:03:59 +0000 Commit: Konstantin Belousov CommitDate: 2021-10-06 14:05:22 +0000 When queuing ignored signal, only abort target thread' sleep if it is inside sigwait() Reported and tested by: trasz Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D32252 --- sys/kern/kern_sig.c | 16 ++++++++++++++-- sys/kern/subr_sleepqueue.c | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 59e16ca8e6c8..b88556f2954d 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -2156,6 +2156,18 @@ tdksignal(struct thread *td, int sig, ksiginfo_t *ksi) (void) tdsendsignal(td->td_proc, td, sig, ksi); } +static int +sig_sleepq_abort(struct thread *td, int intrval) +{ + THREAD_LOCK_ASSERT(td, MA_OWNED); + + if (intrval == 0 && (td->td_flags & TDF_SIGWAIT) == 0) { + thread_unlock(td); + return (0); + } + return (sleepq_abort(td, intrval)); +} + int tdsendsignal(struct proc *p, struct thread *td, int sig, ksiginfo_t *ksi) { @@ -2374,7 +2386,7 @@ tdsendsignal(struct proc *p, struct thread *td, int sig, ksiginfo_t *ksi) PROC_SLOCK(p); thread_lock(td); if (TD_CAN_ABORT(td)) - wakeup_swapper = sleepq_abort(td, intrval); + wakeup_swapper = sig_sleepq_abort(td, intrval); else thread_unlock(td); PROC_SUNLOCK(p); @@ -2505,7 +2517,7 @@ tdsigwakeup(struct thread *td, int sig, sig_t action, int intrval) if (td->td_priority > PUSER && !TD_IS_IDLETHREAD(td)) sched_prio(td, PUSER); - wakeup_swapper = sleepq_abort(td, intrval); + wakeup_swapper = sig_sleepq_abort(td, intrval); PROC_SUNLOCK(p); if (wakeup_swapper) kick_proc0(); diff --git a/sys/kern/subr_sleepqueue.c b/sys/kern/subr_sleepqueue.c index 8d61383f9737..36832ef96ba4 100644 --- a/sys/kern/subr_sleepqueue.c +++ b/sys/kern/subr_sleepqueue.c @@ -1126,7 +1126,8 @@ sleepq_abort(struct thread *td, int intrval) THREAD_LOCK_ASSERT(td, MA_OWNED); MPASS(TD_ON_SLEEPQ(td)); MPASS(td->td_flags & TDF_SINTR); - MPASS(intrval == 0 || intrval == EINTR || intrval == ERESTART); + MPASS((intrval == 0 && (td->td_flags & TDF_SIGWAIT) != 0) || + intrval == EINTR || intrval == ERESTART); /* * If the TDF_TIMEOUT flag is set, just leave. A