From nobody Wed Oct 07 06:24:36 2026 X-Original-To: dev-commits-src-branches@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 4j034j1zl7z6vMd5 for ; Wed, 07 Oct 2026 06:24:37 +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 4j034h32pfz3N8m for ; Wed, 07 Oct 2026 06:24:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791354276; 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=UPb9FM1ll+A9pzTBKumL1CQ1ZzbWEAGUb1CuY04ueQU=; b=G99z4tDxA6nLto9qeYV1h5sI32DW4/b/9iwE6Pkv9M/slriY4GpMyps8KWX1Zr3OV2BwLV a7JVq6Hl2beTS0KgEyPNq+fiE8qvc/k+L7uM79t/qqITkH4wIE1N3/vawERpx8aKtXB0PR IAu5TIY8MsymlZ6v41nz0j39RAx+r9f88ssPPUs+D/KNxDlCDkKWw9RkMwOrNIJ4w+5ssY jfe40VraSMaAre4jFStQQ5IScB0/hKujvgXPNFKU9+PybH0u/i1bf7hUEvxJvOY+0/O6WO a1YtOYwiiAWPFvSGROxLjQPzsoUSFZ3hiF9n+Md9f05qBiSvVPSZHHu5EX1Xwg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1791354276; b=vGthqsCOHeKfH1oj1CNKpqOnL0e1YALMT2VIj8tB+gxtG9ATC8IxxGyGm+PVC5Mt8LCrIE Y/rHDtxMohaYD6LwYfM/9kK7DM3DXBXa1V5Xvcses7GZTe6lreN6X8CmQETDQ+2YlivkbT z+/7RNHwXu0wfpvGPo/rmV4uBD/F7cTaQi2LZ0SuyhIjTHlchAB1WtZ5h+ZM/lVSK2DR3N h8CcQ1Kqt6XPuSYKer1ylP6ZXJJL04vcM74aNhtaa2oJ2nQ9kEy/eNSfcPKUMSUa7H8x+v 9ErV+C68NtQnX4RQ3OAZnTtBKd/HoacJAxV6ayYQN2bc1Jr6CSU6S7QxlRbTPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791354276; 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=UPb9FM1ll+A9pzTBKumL1CQ1ZzbWEAGUb1CuY04ueQU=; b=bL6AXNFlzF9+4p5pZWJowmvNyi7a8XkN3RDcGY9hp1wzFOXfx8UJ/yOwKvD/u0K79w0hn5 cjT9UM2d/65X+Yuyd+7x4KTuYG3b+TMHY0wUtA/1LgmLTw/p/8Lr2jq4orYzIlY1w0afZL 70vluMRSe2pnesX5oeMv3yBzxbPZ+z7PIHWDkroEy0feVGcLJ0bc+RT22nafTeh49tlnuN OKghqQcCs52twf6U60MtylcsyCDGgiHRQTTs2T+n88NWbYbcS3cXVdnx5yyUDqSye2ZoKM Y0SKb+8a0nEBJZcvFzCmBRfqwGOezdbj1a3ircyrU7vXp8uqmhDlMxHD2Z7T8A== 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 4j034h24VLzj5D for ; Wed, 07 Oct 2026 06:24:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 42394 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 07 Oct 2026 06:24:36 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Christos Margiolis Subject: git: ba847a03d607 - stable/15 - cuse: Improve server cleanup List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/15 X-Git-Reftype: branch X-Git-Commit: ba847a03d60743086646ac462049cd1e48fb24e1 Auto-Submitted: auto-generated Date: Wed, 07 Oct 2026 06:24:36 +0000 Message-Id: <6ac5e5a4.42394.77607e40@gitrepo.freebsd.org> The branch stable/15 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=ba847a03d60743086646ac462049cd1e48fb24e1 commit ba847a03d60743086646ac462049cd1e48fb24e1 Author: Christos Margiolis AuthorDate: 2026-09-30 09:49:52 +0000 Commit: Christos Margiolis CommitDate: 2026-10-07 06:23:31 +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 (cherry picked from commit 40431ec4da1d14032462ea6327ef695c2f58a3b1) --- 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);