From nobody Fri Apr 08 17:23:05 2022 X-Original-To: dev-commits-src-main@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 8EA1B1A8248B; Fri, 8 Apr 2022 17:23:05 +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 4KZlSn3cV0z3Q02; Fri, 8 Apr 2022 17:23:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649438585; 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=piHtNEb9Xa1oCAwNqmMxUpndYM6NCAQhxX+kNme9rR0=; b=U8d0K+evcd91hSGDVIevoDAM0p1yaeT+FV0YyGRqQ4RY3GneeuGUziMVQXPnh8NJZXcTUL m6zT+fRVMPoc45DVbyHu6eCUXa3UV4f+HktFvD+3NcHvhass5tTSpinGgWrTP80QxqeFKQ XUOTkkSBRzgRgwwRXeQNt/jHp05+eqz9LbnfkgJguHn4r88lAEBP1NizMium1gtE2zfGIz Yacrvd6C9X2NnnCG6iyaVofs/WpJbmNwPt82Bat8UZ1GpmM8pt6aofEppDRobUvmHHikum buS6X4hD9K9YlnyW5ZX4vfKTY5VQKb5YgFqjSdNJe6qZHDglm8UXgVBzuQJHSA== 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 5C8C0139B; Fri, 8 Apr 2022 17:23:05 +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 238HN5vX091271; Fri, 8 Apr 2022 17:23:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 238HN5a2091270; Fri, 8 Apr 2022 17:23:05 GMT (envelope-from git) Date: Fri, 8 Apr 2022 17:23:05 GMT Message-Id: <202204081723.238HN5a2091270@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Chuck Silvers Subject: git: 3dc5f8e19d8c - main - ffs: wait for trims earlier during unmount to avoid panic List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: chs X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3dc5f8e19d8c975a5e27752d65f9aa91d67c9c9e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649438585; 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=piHtNEb9Xa1oCAwNqmMxUpndYM6NCAQhxX+kNme9rR0=; b=E8CgzWyxOs05C9ellBm2z3Q3f5587sMGojjkbWmeV7A953XliNNSIDeqVidLVbHLvI0E8x QD+Yp0r+KKePkpeeime4DZvdr6NypVam2WO0r5lfEGP+QGl+p1AKgZYzt/oId2mU6+Io4H DKENl41XAuGstzPclwrIq0joaQRzxoZ1fhlTHa9OCleAlNrK+d3pUrUsJtasgdC1BkN1GK dKOISqPH9gAHXfINeyloR+enqZZ9+cQS0A0DYWMiZ//7P34tjszxwgibNR0CE9B/3b1HLD w2kNzt+D9jUNF37aeVE0Gh7I1quaGHss3bRMVQmi5AndcINd7xcvCn/YmV8+zA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649438585; a=rsa-sha256; cv=none; b=qOVtM9/6ak78tj3CjJVMTdsFHQYW8A7XLFnuVY9wVZFWhB9vXNeOiAsUEyLferxCSzho+F EhOCa8S5Z6cvl4t4i36VXruKrvM0HfNfYlVsrqqAjkEiWpYjnXLkmgdS8lgDuEUOVS7fU1 4pS/+LNcl8WjS/3XU6xcCrQE8Ee6vN6kudEM920vcRVBjQgPQ7BrXRe3Lb5JXQFJWKc7jE U1NFo2Wew5BlIBtSdxY1tvAgy/v+dp2wYLJis35sonnb1hHIz54rJyUxq23sBSegLBTHZT 5itcPXtZtrm9ou5/UkXyhL1VnhrtXbty61gL2A1Tzcic4qvpg1SLUzHx+W0rwQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by chs: URL: https://cgit.FreeBSD.org/src/commit/?id=3dc5f8e19d8c975a5e27752d65f9aa91d67c9c9e commit 3dc5f8e19d8c975a5e27752d65f9aa91d67c9c9e Author: Chuck Silvers AuthorDate: 2022-04-08 17:19:40 +0000 Commit: Chuck Silvers CommitDate: 2022-04-08 17:19:40 +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. Reviewed by: mckusick, kib Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D34806 --- 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 77361731202a..e9cbc962cd78 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -1423,9 +1423,7 @@ ffs_unmount(mp, 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); } @@ -1539,6 +1537,20 @@ ffs_flushfiles(mp, flags, 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. */