From nobody Sun Aug 06 20:36:39 2023 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 4RJrpJ0CqNz4mNZN; Sun, 6 Aug 2023 20:36:40 +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 4RJrpH6fY5z4cCh; Sun, 6 Aug 2023 20:36:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691354199; 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=E50Nlwp2/YvgzihPlZYFXG3brNA2nPH4NnTOFQ6Knt8=; b=mnOr/4M4wGyV/CszeCUcc70Uqw+1qQl/l5UWDT7PkH61rjV6264XPEJLMjgaSZ/+xhBQuk FGTVgtQAcXdhpJzuMGqpzjn6G4Z4AYcTAljfPnFWNdeXp6dvHGxKpyvIpyOJytwbTn4BVN jk7CgSxDdBPauCQjvR9wbxdVsWidNCsV5MY5VOSYT42B/NvciMMLSPXLlanPoUaOlwfowZ 9NGmGR3n3WtOKTHmG+PguXy+xglWht9CkDq7p3IUiWHjyhHsi4Iu5nWzJ2lNamORx67LXo G2FoxJq6hQUcZvw1AXvMgR3dilEW50Sq0ZKB/fUGGbfDSoEiK1+ZRWlkVRNf3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691354199; 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=E50Nlwp2/YvgzihPlZYFXG3brNA2nPH4NnTOFQ6Knt8=; b=MjoRx6ZGaml65uIYxyiPGPHTfzTFDYV4Cq0Oqwcb21joeWroXCnO/FDZ1fPA7LbNY0LzQv q2jhzVjxyF1l9j3NQxHGkGRv1LbdOfgdDtuIFHyHCt3ERQT4Nx7IW9d44rHyBVzTu7M9F1 BgYba6mxz4wTzn2Yp/qPzhbIi5d3qBkG0jBx8Rxz3gSj+NGvm3Mi4F0Uhbi1wO18MDvbHk fvAJEpN3Xryc7wj8SsrG3U4jmC1Rayw+aKsjSFa3NQ6Cqlt5Gja3vz3B3hcr26Tn0pYUzQ ix+b5Zc2XmDjmQSngvy2B5LiTcSjlRyhgjoqXJ0OTIyMFoCCDVbU1Zpi9bvlLg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691354199; a=rsa-sha256; cv=none; b=Mo9+r4DZQIwDj9WUxl53qI9i6av+fwwbzC69E2SG3ajq80EdmOd34QIijQYznc14Y3bMlB CZE0fkPkK1NRnI7E9bzw9c9c5CFJvzColTIiDFva1XBr7KieXIo2cHaOc480mHn0CGUeI6 X23gjkBIupMQrjkXdAHzHw0yqy4bmAdzAdiMw4hVm3kj6iZdC4rPfS/QpuoC3WeZ6x6MKQ iewOHXbGBJBw0ACuYvnnHhxS3hOEM1VpHPhnIBqw9bOQdcQ/qPHT1yjBln7mZh+65jI8jC 0UVHdtuSy8jZQLVhPmY+hcjUg3DU66U5taraS/SL/cgyrgkCDVh4r17Eu8gaiQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RJrpH52s9z91G; Sun, 6 Aug 2023 20:36:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 376Kad8G042917; Sun, 6 Aug 2023 20:36:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 376Kadbo042916; Sun, 6 Aug 2023 20:36:39 GMT (envelope-from git) Date: Sun, 6 Aug 2023 20:36:39 GMT Message-Id: <202308062036.376Kadbo042916@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Marius Strobl Subject: git: 0096e445c55a - stable/13 - ffs: wait for trims earlier during unmount to avoid panic 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: marius X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 0096e445c55a4a882c213d91eaf33766e27439f4 Auto-Submitted: auto-generated The branch stable/13 has been updated by marius: URL: https://cgit.FreeBSD.org/src/commit/?id=0096e445c55a4a882c213d91eaf33766e27439f4 commit 0096e445c55a4a882c213d91eaf33766e27439f4 Author: Chuck Silvers AuthorDate: 2022-04-08 17:19:40 +0000 Commit: Marius Strobl CommitDate: 2023-08-06 17:56:42 +0000 ffs: wait for trims earlier during unmount to avoid panic All softdep processing is supposed to be completed by softdep_flushfiles() and no more deps are supposed to be created after that, but if a pending trim completes after softdep_flushfiles() and before softdep_unmount() then the blkfree that is performed by ffs_blkfree_trim_task() will create a dep when none should exist, and if softdep_unmount() is called before that dep is freed then the kernel will panic. Prevent this by waiting for trims to complete earlier in the unmount process, in ffs_flushfiles(), so that any deps will be freed and any modified CG buffers will be flushed by the final fsync of the devvp in ffs_flushfiles() as intended. (cherry picked from commit 3dc5f8e19d8c975a5e27752d65f9aa91d67c9c9e) --- sys/ufs/ffs/ffs_vfsops.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index e77d5e336bf1..23d0c9bc60df 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -1452,9 +1452,7 @@ ffs_unmount(struct mount *mp, int mntflags) if (susp) vfs_write_resume(mp, VR_START_WRITE); if (ump->um_trim_tq != NULL) { - while (ump->um_trim_inflight != 0) - pause("ufsutr", hz); - taskqueue_drain_all(ump->um_trim_tq); + MPASS(ump->um_trim_inflight == 0); taskqueue_free(ump->um_trim_tq); free (ump->um_trimhash, M_TRIM); } @@ -1564,6 +1562,20 @@ ffs_flushfiles(struct mount *mp, int flags, struct thread *td) if (qerror == 0 && (error = vflush(mp, 0, flags, td)) != 0) return (error); + /* + * If this is a forcible unmount and there were any files that + * were unlinked but still open, then vflush() will have + * truncated and freed those files, which might have started + * some trim work. Wait here for any trims to complete + * and process the blkfrees which follow the trims. + * This may create more dirty devvp buffers and softdep deps. + */ + if (ump->um_trim_tq != NULL) { + while (ump->um_trim_inflight != 0) + pause("ufsutr", hz); + taskqueue_drain_all(ump->um_trim_tq); + } + /* * Flush filesystem metadata. */