From nobody Sun Jul 03 19:25:27 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 1E9B88B382A; Sun, 3 Jul 2022 19:25:28 +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 4Lbf6J0Md7z3H1l; Sun, 3 Jul 2022 19:25:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656876328; 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=4+ky3QzFLgQAbE1OPKKo4yUqv85edCUH3n/ewDF1OLo=; b=twE4NB8moLNIAldZBrx3lLvJmJudDgH9Jn1LxoOACFX2LNez+xyB/XNWzst2Jb+DZWo5Tm /thnNqYHGRIW6l96KCY1O8Ai4V31XnxinaWsT8q+CCtfsHZFtx/6kLH9tIfjAPrO3wo3Wf tBgb1Ee/btZr87Dl7xov8PuX0L6/vj5FFmUp7hfKZmEy+7YLLsJNmv8E/1nq+su7FEFYyb CKEansSM89OP0lbOkRVGZOWElb/UFoX+V3UWm/AVjNZ+iX/3vpIGNOus0RkxwfbDlOmDJE ijBLLhpUsUjwY8QwX20VzDcpbij1BpLGZI2jgqqzya2GQK08jH/jiuHPWoE/xA== 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 DCA372A3B9; Sun, 3 Jul 2022 19:25:27 +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 263JPRD7018902; Sun, 3 Jul 2022 19:25:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 263JPRZ3018901; Sun, 3 Jul 2022 19:25:27 GMT (envelope-from git) Date: Sun, 3 Jul 2022 19:25:27 GMT Message-Id: <202207031925.263JPRZ3018901@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jamie Gritton Subject: git: 06dcf1499bf5 - stable/13 - MFC jail: add prison_cleanup() to release resources held by a dying jail 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: jamie X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 06dcf1499bf5d194bd89a7e37d50df80d8c3c609 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656876328; 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=4+ky3QzFLgQAbE1OPKKo4yUqv85edCUH3n/ewDF1OLo=; b=KYqml+Ky1/liKjsW+gKiVMldH6UrhlU8OonSeMxhKGE292b+NQBKtkocXSu8X/fjkanNz5 jdADvu9zwNvqiSlOwVoSI8VrVN5JAjFKKNmjleSvlLVCmssfdBT/Tn2WubPrGt+2BOkSTL Uvf0CRCJ8GPyxCI/PVNgTF4nEMUwQVpcAFEIMdpCSSy3Kys3VAsmNITjV2Mfjq/fxO2XXa DANrmYUL4+xAfKNtIwSEVeFpXt4dQh9ekFTOD5SLse3RqwP7r8sKBNsn63ydWUsGhRUovB 5ZFEH6affKIX4DOqb32rQSu+iiwC2wsVzQNSeiiGiwVNRcfQr2Ce46HxGmlHtw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656876328; a=rsa-sha256; cv=none; b=WomplGUey7LxRs1SsuSK3gTjWuuZOuVVZnCnV3QH9NNPgJamw0RkbojWOtSvGuu1DWyKWQ NFXgb1eQUsYsFaIi0LjAaQedm/tk8TpYnC+1UCF7SCldtobdW0tFnrz8302asXUc9eicxF b5uQXc+MyEVjms8BMLkvN+nvh/z9GK8gy9qCEGzeHZPjFB7FXsheLqgmv+XP1GC6IWCA39 Vh70HSbhVhFIDaME/T/Ct9kwjMaCdxf8gqsU9xUyFwl6+cii/FBwSlqoO9u2WzVgsM4rsu nHforLYifbZbD6eqzc9P5AZ3Fehu/cTTpoRwVlMmNjuOY3o0cQwYfXLDP+DXjw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jamie: URL: https://cgit.FreeBSD.org/src/commit/?id=06dcf1499bf5d194bd89a7e37d50df80d8c3c609 commit 06dcf1499bf5d194bd89a7e37d50df80d8c3c609 Author: Jamie Gritton AuthorDate: 2022-06-29 17:33:05 +0000 Commit: Jamie Gritton CommitDate: 2022-07-03 19:24:49 +0000 MFC jail: add prison_cleanup() to release resources held by a dying jail Currently, when a jail starts dying, either by losing its last user reference or by being explicitly killed, osd_jail_call(...PR_METHOD_REMOVE...) is called. Encapsulate this into a function prison_cleanup() that can then do other cleanup. (cherry picked from commit a9f7455c38c19438d1061227b1fa11d40c5407a6) --- sys/kern/kern_jail.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c index c86c945b3807..43e101176a71 100644 --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -142,6 +142,7 @@ static void prison_complete(void *context, int pending); static void prison_deref(struct prison *pr, int flags); static void prison_deref_kill(struct prison *pr, struct prisonlist *freeprison); static int prison_lock_xlock(struct prison *pr, int flags); +static void prison_cleanup(struct prison *pr); static void prison_free_not_last(struct prison *pr); static void prison_proc_free_not_last(struct prison *pr); static void prison_set_allow_locked(struct prison *pr, unsigned flag, @@ -2776,8 +2777,7 @@ prison_deref(struct prison *pr, int flags) pr->pr_state = PRISON_STATE_DYING; mtx_unlock(&pr->pr_mtx); flags &= ~PD_LOCKED; - (void)osd_jail_call(pr, - PR_METHOD_REMOVE, NULL); + prison_cleanup(pr); } } } @@ -2932,7 +2932,7 @@ prison_deref_kill(struct prison *pr, struct prisonlist *freeprison) } if (!(cpr->pr_flags & PR_REMOVE)) continue; - (void)osd_jail_call(cpr, PR_METHOD_REMOVE, NULL); + prison_cleanup(cpr); mtx_lock(&cpr->pr_mtx); cpr->pr_flags &= ~PR_REMOVE; if (cpr->pr_flags & PR_PERSIST) { @@ -2968,7 +2968,7 @@ prison_deref_kill(struct prison *pr, struct prisonlist *freeprison) if (rpr != NULL) LIST_REMOVE(rpr, pr_sibling); - (void)osd_jail_call(pr, PR_METHOD_REMOVE, NULL); + prison_cleanup(pr); mtx_lock(&pr->pr_mtx); if (pr->pr_flags & PR_PERSIST) { pr->pr_flags &= ~PR_PERSIST; @@ -3014,6 +3014,18 @@ prison_lock_xlock(struct prison *pr, int flags) return flags; } +/* + * Release a prison's resources when it starts dying (when the last user + * reference is dropped, or when it is killed). + */ +static void +prison_cleanup(struct prison *pr) +{ + sx_assert(&allprison_lock, SA_XLOCKED); + mtx_assert(&pr->pr_mtx, MA_NOTOWNED); + (void)osd_jail_call(pr, PR_METHOD_REMOVE, NULL); +} + /* * Set or clear a permission bit in the pr_allow field, passing restrictions * (cleared permission) down to child jails.