From nobody Fri Oct 30 22:04:32 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 4jGZrc2XzYz6xf4K for ; Fri, 30 Oct 2026 22:04:32 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jGZrc1RrPz4XxB for ; Fri, 30 Oct 2026 22:04:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793397872; 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=mRb0ZQkQj3gRSqetUtX2YpA1PBB6MOFhd60C7IOxH3w=; b=BElAg5YdZhirghTTvjUTlaxkq8Ue1axmqg+APcxtJXf+ox5f9wcTkPMfeDv3X7yePKhkI5 Kx58BMPoKA8YNCj6pXw6fbD8PnIqTkKgnsdrlLUImY2rhDw+23TtxcRoCaX9Xw3vgiJTHJ BfmpfGwsAEXHFeQkOh96uIaJrCb6LJDE/MYbeuu0H59aL0bUIxmCqdEEuGCQTQMtYLrQYA zDY05xGf6KXjXmdUQkHQ6BVQvX0maYvVbFhIs3PzEVHnVf2gEyJB+YY2U3doitjMO+c0/Q 6F42jBeTYN6DqgFmHPgFXtbn8DGRFlxjIzvt1gpSRWRun7Tb/SVss6Sq6wo06Q== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793397872; b=s/OB2EjZFRxVW89HY8KHfr0PHHf5rQeTGHKo0/dEmw/Wn9pXP3dlstUkxm4Jpt4HJVYTZV xpThapOPrfuicfrl7IGMzDKndIEme7/jpLVuQhk8MMY2JjgUBkYotEgXPFjV9h081MCRBR mC+jdtaWY+XFzjYeT2zoMOUjEVpyhRfOl5BQPM2SE5M7m3IDz0lMsvioAl76wp5o8NsWdw IYVAN4GUx+1s7jJCetFA7cUodfxusl8m92DkP4atPMJ/bxHmc1OPiYHr+EEsxJgw6lpqXO HEBg6ag/+35Rx6AmVclnkQufnemxNRmDBHseTdgwE0ZS9all4Gtnf/0R7PVH3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793397872; 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=mRb0ZQkQj3gRSqetUtX2YpA1PBB6MOFhd60C7IOxH3w=; b=XD/VJdYeTH/Qew/zG8HMffdbb8EMzNBwScfgiMWr/U8xziHJfYcQZsyJYrYEa9QZCrf1xg 9YSpGwhbTHk0qxjw8jAYslRTTGsP6ktNe/QAia0eLFIU8myHMwSW5r7S/JKy8k25dS/Nfw GVAVSyECnnmzznZPJw7AURTEiAzP9vZathTb3aOpzSp1QMbNFjVtreGUvlILco2Va7xguz hyKA6ZU8LVSAmoxHozJ6Z5hO6CDaU16Dgt5LP/g84I65IPXuDUpElG4s+PeaslrNOOIYm8 80BWRnehet8rTmvLovEjvYtkRYvh8oedDZFflVx5HZ4Pw2DW46eQLtB9U98drw== 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 4jGZrc15n4zmpS for ; Fri, 30 Oct 2026 22:04:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 35fab by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 30 Oct 2026 22:04:32 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kevin Bowling Subject: git: 084f245a8514 - main - tpm: Tie exclusive-open cleanup to the file lifetime List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository 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: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 084f245a8514e89a506e43efd1a7ed44ffdbb5eb Auto-Submitted: auto-generated Date: Fri, 30 Oct 2026 22:04:32 +0000 Message-Id: <6ae51470.35fab.7e8348ed@gitrepo.freebsd.org> The branch main has been updated by kbowling: URL: https://cgit.FreeBSD.org/src/commit/?id=084f245a8514e89a506e43efd1a7ed44ffdbb5eb commit 084f245a8514e89a506e43efd1a7ed44ffdbb5eb Author: Kevin Bowling AuthorDate: 2026-09-18 12:16:54 +0000 Commit: Kevin Bowling CommitDate: 2026-10-30 22:03:58 +0000 tpm: Tie exclusive-open cleanup to the file lifetime Use a cdevpriv destructor to abort an unfinished TPM 1.2 transaction and release exclusive-open ownership. Register it before setting TPM_OPEN so a failed registration leaves the device available. The last reference to the successful open triggers cleanup, including after dup() or fork(). Suggested by: kevans MFC after: 2 weeks Sponsored by: BBOX.io Differential Revision: https://reviews.freebsd.org/D59812 --- sys/dev/tpm/tpm.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/sys/dev/tpm/tpm.c b/sys/dev/tpm/tpm.c index 2880c69cf85c..42c31ba75518 100644 --- a/sys/dev/tpm/tpm.c +++ b/sys/dev/tpm/tpm.c @@ -139,15 +139,14 @@ int tpm_enabled; ((struct tpm_softc *)dev->si_drv1) d_open_t tpmopen; -d_close_t tpmclose; d_read_t tpmread; d_write_t tpmwrite; d_ioctl_t tpmioctl; +static d_priv_dtor_t tpm_dtor; static struct cdevsw tpm_cdevsw = { .d_version = D_VERSION, .d_open = tpmopen, - .d_close = tpmclose, .d_read = tpmread, .d_write = tpmwrite, .d_ioctl = tpmioctl, @@ -404,7 +403,8 @@ tpm_detach(device_t dev) /* * Prevent new methods from touching the transport. Do not hold the - * lock while destroy_dev() drains methods already waiting for it. + * lock while destroy_dev() drains methods and cdevpriv destructors + * which also acquire it. */ if (sc->sc_cdev != NULL) { destroy_dev(sc->sc_cdev); @@ -1659,36 +1659,26 @@ tpmopen(struct cdev *dev, int flag, int mode, struct thread *td) else if (sc->sc_suspend != 0 || (sc->sc_flags & TPM_OPEN) != 0) error = EBUSY; else { - sc->sc_flags |= TPM_OPEN; - error = 0; + error = devfs_set_cdevpriv(sc, tpm_dtor); + if (error == 0) + sc->sc_flags |= TPM_OPEN; } sx_xunlock(&sc->sc_lock); return (error); } -int -tpmclose(struct cdev *dev, int flag, int mode, struct thread *td) +static void +tpm_dtor(void *arg) { struct tpm_softc *sc; - int error; - - sc = TPMSOFTC(dev); - if (sc == NULL) - return (ENXIO); + sc = arg; sx_xlock(&sc->sc_lock); - if ((sc->sc_flags & TPM_OPEN) == 0) - error = EINVAL; - else { - if (sc->sc_init == tpm_tis12_init) - tpm_tis12_abort(sc); - sc->sc_flags &= ~TPM_OPEN; - error = 0; - } + if (sc->sc_init == tpm_tis12_init) + tpm_tis12_abort(sc); + sc->sc_flags &= ~TPM_OPEN; sx_xunlock(&sc->sc_lock); - - return (error); } int