From nobody Sat Jan 04 14:08:16 2025 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 4YQMjX4TGdz5kJkb; Sat, 04 Jan 2025 14:08:16 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YQMjX1j82z4Thk; Sat, 4 Jan 2025 14:08:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735999696; 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=fIqmzup+N23EReSyhufHh0hPwaySLt9kux2VBSSLNx4=; b=CVtEGvQgFP0mX3wul1pTvv9RKgwsrbtG+K6j/QKgfV3R2kc5jfh/F+rUaZ3SonmVWqhf+A LOvZyPt2O0riCwUmUU2x0OEiC0m0c9U7LLFEv+dvIxPSFwBmCn8K2wnY/PC9B603Ca18Tn v8khkzAoz5u8UTkd5aN6KjLReGsDk2TmBWDxHYKKjExFidUZpOUNk/VY0NsOxULtr+QOcb IPWrzNP+PNPfbFF35N32yDnUOzgScg0A6K79xV9QPkVZEae7IxN+S07Hqoi2rCvtoWaQaA wufo9NQnEWsffnIsenIZ9powUK6Ofht4aeVNH+OfiW50fd6tvFSQpF89sMZa9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735999696; 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=fIqmzup+N23EReSyhufHh0hPwaySLt9kux2VBSSLNx4=; b=Z12JFFvPuoib61DlCH5+OG+kJU1HuMcEn1uIjeFab3ExmTWBRWuRtTvizjOhFma9Q11joH mXoJ1mtRO8Z60QebAdPSDYqpvfZayf57pbbwH7ckuZf+1p02GT1N4RgEk/gF2GqxBnptoN HsW5YuNNdaJhYOjinRlv5Z6k3OhO8k1kLKWEh4cPELzetNtwylffrU/A8L8ilOG1V4u91h JHZ6pYOkpUrWlLvaZrWoJZ6VfaCwv+pkBxSGo6k5fCwB6AjrjFMqeMkCvbGdjUJBF/BWg/ p7vliniSU7CzU37rW30H8y9NiwngWJ6Q5fKhC+feTsOcg6PLRjv0YRC3GdnDwg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735999696; a=rsa-sha256; cv=none; b=hUwuRGQ0JK+KquSLv1n7T5qcpfRrfgxSG+ArKr6b7Y3O5tS9xOfdAtvfYoILF7serLt9My RD2iWCKV4SvnvurVkoVFqnrVe2MqK8vTXOB7Wzh/qV9L1c3CSes7qIVRn51/UQpujh5bf+ t2fh4b7H5x7Vlbfq9PNDn7sO/dFphDy1bRQIBXPI4BdtQvl6dwzD5Q9qH/kbPsT5+rNCOK 7bDpKI8N3xaW9Aspo2xdlv37H0hm7x8jOJGet9+bQDJGdigY5Gs5HEvjaALV/dc/IEkdyZ kNgFdJCeTGmzQJdM+fyiWeQNPHJYEcUqm/YgT2pa+TFB6sAH85wfTbVYpJ4+GQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YQMjX13rCzwSJ; Sat, 04 Jan 2025 14:08:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 504E8Gjx070485; Sat, 4 Jan 2025 14:08:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 504E8GWj070482; Sat, 4 Jan 2025 14:08:16 GMT (envelope-from git) Date: Sat, 4 Jan 2025 14:08:16 GMT Message-Id: <202501041408.504E8GWj070482@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: f1933eda43e6 - stable/14 - jail: Handle jail removal in a dedicated thread 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: f1933eda43e6d15bc237a63741bda56bfed953e0 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f1933eda43e6d15bc237a63741bda56bfed953e0 commit f1933eda43e6d15bc237a63741bda56bfed953e0 Author: Mark Johnston AuthorDate: 2024-12-21 19:23:51 +0000 Commit: Mark Johnston CommitDate: 2025-01-04 13:56:37 +0000 jail: Handle jail removal in a dedicated thread Otherwise a deadlock is possible: the system taskqueue thread removes a prison and calls vnet_destroy(), vnet_vlan_uninit() destroys the if_vlan cloner, the vlan_clone_destroy() callback calls taskqueue_drain() on the thread taskqueue. Fix the problem by introducing a new thread for jail removals. Ideally, the taskqueue interface would let consumers define queues without having to map them to threads, as that'd make it possible to avoid such deadlocks without extra threads; for now, this is the only solution. Reviewed by: jamie MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D47991 (cherry picked from commit 8cf955f3f48a45db22a3cc3ad89a22b543fa38ce) --- sys/kern/kern_jail.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c index c4e89774f18b..6f2b4f7fc336 100644 --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -130,6 +130,12 @@ struct jailsys_flags { unsigned new; }; +/* + * Handle jail teardown in a dedicated thread to avoid deadlocks from + * vnet_destroy(). + */ +TASKQUEUE_DEFINE_THREAD(jail_remove); + /* allprison, allprison_racct and lastprid are protected by allprison_lock. */ struct sx allprison_lock; SX_SYSINIT(allprison_lock, &allprison_lock, "allprison"); @@ -2868,7 +2874,7 @@ prison_free(struct prison *pr) * Don't remove the last reference in this context, * in case there are locks held. */ - taskqueue_enqueue(taskqueue_thread, &pr->pr_task); + taskqueue_enqueue(taskqueue_jail_remove, &pr->pr_task); } } @@ -2942,7 +2948,7 @@ prison_proc_free(struct prison *pr) pr->pr_id)); pr->pr_flags |= PR_COMPLETE_PROC; mtx_unlock(&pr->pr_mtx); - taskqueue_enqueue(taskqueue_thread, &pr->pr_task); + taskqueue_enqueue(taskqueue_jail_remove, &pr->pr_task); } }