From nobody Wed Sep 30 09:51:25 2026 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 4hvr0Z1dMcz6v8cm for ; Wed, 30 Sep 2026 09:51:26 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hvr0Y6RlVz3Mr8 for ; Wed, 30 Sep 2026 09:51:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1790761885; 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=85HiffYtgrZR6fJC8zfl1ODSy2J9QZQBFkDQbyTdkAI=; b=NpwZv3rEF5ms5i914mcaRlAaco7qAPOLR9/ti24dZ8kFK2RJ5k5RECc2kbCUU+CsZH+Vv+ /f3DnpA+tOqkvyaoNOq1716hDnk6nbpoSMWGoq7UaiYmL9pJ+vK8fKbdSH0n3mORjBY0MV 33WDgiDjJAFiRsDT+0OiAwXf/7TxejoBY6g4/Tyii7e5AQhI/zCNlOX9gc16dGKEWpAuk9 FYNGyuOqMkNAwA+3Uy1HV51dHUnYqQUOqX2yZttCCLfUK45950r8h6iE9rf56IALjePHaA WreyFVAtpXA8ia8/+80rNagmakndSt3S7zSdO23uiDY/2Q7f0H+cDZwJaB/0zA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1790761885; b=G66vX+THguvi1ZzwKFADugimcNuZFN7W91ElcuKkQvhI/HjKrZr1lntkIMj9QLks11GUBJ RnIh5207gY37vht4rE4IO/qK2qCO5BMYu1t22u228M3xbM9MGoPxwKLNw3rM2HfMyc6JdF cC233u8RT4NfJdvP4S8DDhZZIAlIAOrDifbYbujbsH60HlUhM5Wry5g1XiTscu8eluLnDE UPxbymfrXWHyuNoX/5h5Z1slvYxBJSouqDEIg20V6AK6DdGFm8Ni0wsqX42y0gDL6pfXB6 K1LC2Q8nshQor07ZhffjlCh0aDxqw6HzzxA0nAptH8Bk+2+iHqEJ5x5ZW3GGWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1790761885; 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=85HiffYtgrZR6fJC8zfl1ODSy2J9QZQBFkDQbyTdkAI=; b=CD5EVejHqLVLiV40uXew4bCYssUmelgVWab9WTXYDVdMNQy0orwffhkZvywE/fRY5qN4/D mYRCtMSNl03UWHJsSbNGtYyBHMfYFUFnQCFBsBH8RdvI6c84cm+ZYZayAv4RbyS26vCMKS 8NMq45e9tUlejE9/rPEaxRzZC1xZO8iN1cARQXVPnT9uA4vkf9cvwol8MKJT8EmcI7V908 JdoW9rsAChiXKl+YrzoJs7pAECvqb7qQ/pM3nsV3NUyWlWdogSreq5oUeE9Zn56H3eo1Dp inn/0XxC2V0CANhmgG5noL14Z0wE0ok+fhgFS3J4EMetcvttWqBB5u8eYNPsTw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hvr0Y5F7pzgyM for ; Wed, 30 Sep 2026 09:51:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 325f3 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 30 Sep 2026 09:51:25 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 40431ec4da1d - main - cuse: Improve server cleanup 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 40431ec4da1d14032462ea6327ef695c2f58a3b1 Auto-Submitted: auto-generated Date: Wed, 30 Sep 2026 09:51:25 +0000 Message-Id: <6abcdb9d.325f3.549943c6@gitrepo.freebsd.org> The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=40431ec4da1d14032462ea6327ef695c2f58a3b1 commit 40431ec4da1d14032462ea6327ef695c2f58a3b1 Author: Christos Margiolis AuthorDate: 2026-09-30 09:49:52 +0000 Commit: Christos Margiolis CommitDate: 2026-09-30 09:49:52 +0000 cuse: Improve server cleanup Move cuse_server_unref()'s device cleanup loop into a new cuse_server_free_devs_locked(), and call it from cuse_server_free() instead. The cdevpriv destructor now destroys the server's devices before dropping its reference, which closes the clients using them, so that the destructor is always the one that takes the last reference. By the time cuse_server_unref() frees the server, the device list should be empty, so assert this. In cuse_kern_uninit(), delete the infinite loop which waits for all open /dev/cuse instances to exit, and instead call destroy_dev() directly, which runs their cdevpriv destructor. MFC after: 1 week Sponsored by: The FreeBSD Foundation Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D59872 --- sys/fs/cuse/cuse.c | 52 ++++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/sys/fs/cuse/cuse.c b/sys/fs/cuse/cuse.c index 37b5f0494b38..1b562221fce3 100644 --- a/sys/fs/cuse/cuse.c +++ b/sys/fs/cuse/cuse.c @@ -290,25 +290,12 @@ cuse_kern_init(void) static void cuse_kern_uninit(void) { - void *ptr; - - while (1) { - printf("Cuse: Please exit all /dev/cuse instances " - "and processes which have used this device.\n"); - - pause("DRAIN", 2 * hz); - - cuse_global_lock(); - ptr = TAILQ_FIRST(&cuse_server_head); - cuse_global_unlock(); - - if (ptr == NULL) - break; - } - + /* destroy_dev() runs the cdevpriv destructor of every open instance. */ if (cuse_dev != NULL) destroy_dev(cuse_dev); + MPASS(TAILQ_EMPTY(&cuse_server_head)); + mtx_destroy(&cuse_global_mtx); } @@ -672,9 +659,21 @@ cuse_server_free_dev(struct cuse_server_dev *pcsd) } static void -cuse_server_unref(struct cuse_server *pcs) +cuse_server_free_devs_locked(struct cuse_server *pcs) { struct cuse_server_dev *pcsd; + + while ((pcsd = TAILQ_FIRST(&pcs->hdev)) != NULL) { + TAILQ_REMOVE(&pcs->hdev, pcsd, entry); + cuse_server_unlock(pcs); + cuse_server_free_dev(pcsd); + cuse_server_lock(pcs); + } +} + +static void +cuse_server_unref(struct cuse_server *pcs) +{ struct cuse_memory *mem; cuse_server_lock(pcs); @@ -690,12 +689,8 @@ cuse_server_unref(struct cuse_server *pcs) TAILQ_REMOVE(&cuse_server_head, pcs, entry); cuse_global_unlock(); - while ((pcsd = TAILQ_FIRST(&pcs->hdev)) != NULL) { - TAILQ_REMOVE(&pcs->hdev, pcsd, entry); - cuse_server_unlock(pcs); - cuse_server_free_dev(pcsd); - cuse_server_lock(pcs); - } + /* The cdevpriv destructor destroys the devices before unreffing. */ + MPASS(TAILQ_EMPTY(&pcs->hdev)); cuse_free_unit_by_id_locked(pcs, -1); @@ -743,13 +738,10 @@ cuse_server_free(void *arg) { struct cuse_server *pcs = arg; - /* - * The final server unref should be done by the server thread - * to prevent deadlock in the client cdevpriv destructor, - * which cannot destroy itself. - */ - while (cuse_server_do_close(pcs) != 1) - pause("W", hz); + cuse_server_lock(pcs); + cuse_server_is_closing(pcs); + cuse_server_free_devs_locked(pcs); + cuse_server_unlock(pcs); /* drop final refcount */ cuse_server_unref(pcs);