From nobody Mon Jun 13 19:33:38 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 EABF28550CC; Mon, 13 Jun 2022 19:33:39 +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 4LMMDz33bXz3qLQ; Mon, 13 Jun 2022 19:33:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655148819; 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=YKqi5Npl62dDbjKHx4bZBC2Fd5Toku/LSFMcqACTRNI=; b=TIrIWy1b1VlDxBMs58/4ACSjuejOYSLlJ429nWfdq6hQYCIO26aPqsXwdsjInu+IYrCXBY 8oatosLWfURtdffUs1ZSfOOz9GDLa4gjRDB5GfudJ9Ymf0jYRgmcUUrA0bg3czchh5oOim 4S57QFmOT1YAGfTJoC9hkZrn0RCcmGdAEb7mO0bvj3nkc3Lc2Bs2bvSEvdntAIPqsE4oUl g4JiJg+j9QqpEf68+243fi1VHQwN/TZ6juS93GkT07uDW3+lQz5nMc4/vxklIBMDsF+rJY KlsK6OhT2kK3rooDgjNKy/TzX60y+seFGGt0O4T11KUWfnWPK0sR0NLC6G3o9A== 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 92D6C1BABE; Mon, 13 Jun 2022 19:33:38 +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 25DJXcKt023738; Mon, 13 Jun 2022 19:33:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25DJXc0b023737; Mon, 13 Jun 2022 19:33:38 GMT (envelope-from git) Date: Mon, 13 Jun 2022 19:33:38 GMT Message-Id: <202206131933.25DJXc0b023737@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: 008b2e65442a - main - Make stop_all_proc_block interruptible to avoid deadlock with parallel suspension 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: 008b2e65442a0d65bc5be9ca625616ddfa6f9ce2 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655148819; 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=YKqi5Npl62dDbjKHx4bZBC2Fd5Toku/LSFMcqACTRNI=; b=Zrua9nylUYbEI4vmX3UMzxIL9ADC9wHAniECMs6nI66rmmbQxqGO21WA1W22TabxUCBn6z cM8sU2JkRNK/Nmx0KZ7a79r0Jd0RKecSOKGU6q2dkmV2thWFH/Ps+GmTDAlG1SDgiu8++b kTsNV7xE8u9qCb/PBl47J1qjIeYBWMJ4cPYR3kPXg9/kxxuwenIEGZQQR9i0T0hdy1l1zL 4AzKURfYVBLZNV0EWHs/nyRHAXom3wl5J4+LTCknQf/fxsktSZl9EElxSpaBq4QYIISE2p AzIZlW+1zf/qCK1ZpEjONF1suTtCBExhLHYaCxqLLLWBq1B0Uf3rUH8/Yg7DKA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655148819; a=rsa-sha256; cv=none; b=plykqHGL5ucq7/EMZ6m1LMexB/eaijPdV02DuAgad0sEail6+vEEc4JIB/6sS7q6+iO5DQ 1d5e5xiQY3oRJnoSNi+rJBGM1UEnsRAQvrb+SkUTRINZelAXOx38aBswYq743OMA44UKG1 W3r9wX4/H7h/aIRTY1R76X2k1Awtd98iXSXSfwAe97R+qFxH8dCzh8nbXyziJlzOjDubeu 7vcne2ai9oaUL37XnHeK8p3cgpmlXjRMc/0F6H6WCb4+TBNgPy4LT9dmMhRlOK4lwBAcF0 eNRVeKzqbPzoUPNd4YeTwe2RCNNHoMniQ75e9gvlv5SO+c/tDwOwsZgsGo0VlA== 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=008b2e65442a0d65bc5be9ca625616ddfa6f9ce2 commit 008b2e65442a0d65bc5be9ca625616ddfa6f9ce2 Author: Konstantin Belousov AuthorDate: 2022-04-30 23:29:25 +0000 Commit: Konstantin Belousov CommitDate: 2022-06-13 19:30:03 +0000 Make stop_all_proc_block interruptible to avoid deadlock with parallel suspension If we try to single-thread a process which thread entered procctl(REAP_KILL_SUBTREE), and sleeping waiting for us unlocking stop_all_proc_blocker, we must be able to finish single-threading. This requires the sleep to be interruptible. Reported and tested by: pho Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D35310 --- sys/kern/kern_proc.c | 7 ++++--- sys/kern/kern_procctl.c | 4 ++-- sys/sys/proc.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 6796d672afd7..67299472231a 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -3399,10 +3399,10 @@ static SYSCTL_NODE(_kern_proc, KERN_PROC_VM_LAYOUT, vm_layout, CTLFLAG_RD | static struct sx stop_all_proc_blocker; SX_SYSINIT(stop_all_proc_blocker, &stop_all_proc_blocker, "sapblk"); -void +bool stop_all_proc_block(void) { - sx_xlock(&stop_all_proc_blocker); + return (sx_xlock_sig(&stop_all_proc_blocker) == 0); } void @@ -3426,7 +3426,8 @@ stop_all_proc(void) int r, gen; bool restart, seen_stopped, seen_exiting, stopped_some; - stop_all_proc_block(); + if (!stop_all_proc_block()) + return; cp = curproc; allproc_loop: diff --git a/sys/kern/kern_procctl.c b/sys/kern/kern_procctl.c index 6919fac71c5a..b6e48b46bb5c 100644 --- a/sys/kern/kern_procctl.c +++ b/sys/kern/kern_procctl.c @@ -1063,8 +1063,8 @@ kern_procctl(struct thread *td, idtype_t idtype, id_t id, int com, void *data) sapblk = false; if (cmd_info->sapblk != NULL) { sapblk = cmd_info->sapblk(td, data); - if (sapblk) - stop_all_proc_block(); + if (sapblk && !stop_all_proc_block()) + return (ERESTART); } switch (cmd_info->lock_tree) { diff --git a/sys/sys/proc.h b/sys/sys/proc.h index cdb9cc17945d..5521f8321e2b 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1238,7 +1238,7 @@ void thread_unlink(struct thread *td); void thread_unsuspend(struct proc *p); void thread_wait(struct proc *p); -void stop_all_proc_block(void); +bool stop_all_proc_block(void); void stop_all_proc_unblock(void); void stop_all_proc(void); void resume_all_proc(void);