From nobody Sat Dec 21 19:24:19 2024 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 4YFvNg3Q52z5Wy3w; Sat, 21 Dec 2024 19:24:19 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YFvNg2fXdz4jJp; Sat, 21 Dec 2024 19:24:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734809059; 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=Oz6dKQDtIs41SFv+52cNPHgV2yknDSk6SxCt70cTHXk=; b=a1Ocu1G0SsSyLRDls+oqoNTNbG8FeD7kUMlT/5OhY+BHFz+Kntq8LZxQNPEO352t7GYjTO DcViRuXJ182YYQeP1fRjE6wIWt7f2BUqGe6/72alqRBja5qLjkT9ax0qZV9HatXwitp/mh jrmiNYSR3CHvhhYhjEBIfuRsLOY1ET7WK1iWIcbB6j70jOo4fbUPxoNQqHUKCfAuP93H7Y D3rPTbEfKImmkgioDxFfCRqpwTNXoU94GM8cblovU47+77cFDENWJl+jcdLJo/Iv/SnAIB KFwaYuoh/Bjb7G0XVmMWEEUCVZE9AHMsDbrP0cPyhsRa8Tl0PaMeMyKvRueLbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734809059; 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=Oz6dKQDtIs41SFv+52cNPHgV2yknDSk6SxCt70cTHXk=; b=vO+rcOg70GKiwhfhdLGzs6iBh1Ao8WP+P/i1gUHOso0zjiKzRT5l+MfcBU9lRTIlyiNTkk IFeVKFePZUGcOarsBWpaHnQpteL9HBe6gVQC16tfbkPu9ulLmu4KVDM115lgXvNTwJZQZT NKDbldM81ADMkr6Jbrccqeu2HhdVuRrcrZFooyXO5kORvDplq6esLVjr1OXdndpEaQa+4W UmCfVC/orKQU2TWKRyJMUpO4WAZ9Nf7s3QDxFSV1mitjokzFpNhJqfMO5lp3GdKXx/E0hj mtNs59FpcGocKu6ts64HaGrJ1+nHPBrqT3alT3Qt9ykvQTNHr4t9ln8IX7LS3Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734809059; a=rsa-sha256; cv=none; b=T62BpvlXMub6jjimKw3DcIj5vsGeTyh7EeqwGmbAXzYReM8b1fRn20Uut9S8Noqlyuh6bg OxLxTMMzPAKOijxccCiZloWNUJz1Docqggf7t0yn+k3mn8ycErMUovdd3ds1XQq64bAPmy bDN9e+q8OnfOLS1ozX8y7VYUwbgNbqUkspqPH7mA9aurYGw+RE9DulRBQPHKUGyd82zkKX NpxkXHNhs+qL5MhQk6vVVgU2oENiVvmpYhXq44DDTSC6oYZ6Q2w8INcBaJpBcOWj3s0sCX HA1lapp0w20+pQRnVo2YwEPvKMqddq8S1PV24YGuF9C4G0z2xMYWPKU96y0r3Q== 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 4YFvNg1VQnzcdh; Sat, 21 Dec 2024 19:24:19 +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 4BLJOJKI032306; Sat, 21 Dec 2024 19:24:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BLJOJm7032303; Sat, 21 Dec 2024 19:24:19 GMT (envelope-from git) Date: Sat, 21 Dec 2024 19:24:19 GMT Message-Id: <202412211924.4BLJOJm7032303@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 8cf955f3f48a - main - 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/main X-Git-Reftype: branch X-Git-Commit: 8cf955f3f48a45db22a3cc3ad89a22b543fa38ce Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=8cf955f3f48a45db22a3cc3ad89a22b543fa38ce commit 8cf955f3f48a45db22a3cc3ad89a22b543fa38ce Author: Mark Johnston AuthorDate: 2024-12-21 19:23:51 +0000 Commit: Mark Johnston CommitDate: 2024-12-21 19:23:51 +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 --- 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 d5651f671110..ad6483ed374d 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"); @@ -2902,7 +2908,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); } } @@ -2976,7 +2982,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); } }