From 735123f18d11a2db69f00b71e90bab8c6c4611bd Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 17 Apr 2025 13:27:20 +0200 Subject: [PATCH] 6.1-stable patches added patches: btrfs-fix-non-empty-delayed-iputs-list-on-unmount-due-to-compressed-write-workers.patch --- ...ount-due-to-compressed-write-workers.patch | 80 +++++++++++++++++++ queue-6.1/series | 1 + 2 files changed, 81 insertions(+) create mode 100644 queue-6.1/btrfs-fix-non-empty-delayed-iputs-list-on-unmount-due-to-compressed-write-workers.patch diff --git a/queue-6.1/btrfs-fix-non-empty-delayed-iputs-list-on-unmount-due-to-compressed-write-workers.patch b/queue-6.1/btrfs-fix-non-empty-delayed-iputs-list-on-unmount-due-to-compressed-write-workers.patch new file mode 100644 index 0000000000..b74e84eab9 --- /dev/null +++ b/queue-6.1/btrfs-fix-non-empty-delayed-iputs-list-on-unmount-due-to-compressed-write-workers.patch @@ -0,0 +1,80 @@ +From 4c782247b89376a83fa132f7d45d6977edae0629 Mon Sep 17 00:00:00 2001 +From: Filipe Manana +Date: Wed, 5 Mar 2025 16:52:26 +0000 +Subject: btrfs: fix non-empty delayed iputs list on unmount due to compressed write workers + +From: Filipe Manana + +commit 4c782247b89376a83fa132f7d45d6977edae0629 upstream. + +At close_ctree() after we have ran delayed iputs either through explicitly +calling btrfs_run_delayed_iputs() or later during the call to +btrfs_commit_super() or btrfs_error_commit_super(), we assert that the +delayed iputs list is empty. + +When we have compressed writes this assertion may fail because delayed +iputs may have been added to the list after we last ran delayed iputs. +This happens like this: + +1) We have a compressed write bio executing; + +2) We enter close_ctree() and flush the fs_info->endio_write_workers + queue which is the queue used for running ordered extent completion; + +3) The compressed write bio finishes and enters + btrfs_finish_compressed_write_work(), where it calls + btrfs_finish_ordered_extent() which in turn calls + btrfs_queue_ordered_fn(), which queues a work item in the + fs_info->endio_write_workers queue that we have flushed before; + +4) At close_ctree() we proceed, run all existing delayed iputs and + call btrfs_commit_super() (which also runs delayed iputs), but before + we run the following assertion below: + + ASSERT(list_empty(&fs_info->delayed_iputs)) + + A delayed iput is added by the step below... + +5) The ordered extent completion job queued in step 3 runs and results in + creating a delayed iput when dropping the last reference of the ordered + extent (a call to btrfs_put_ordered_extent() made from + btrfs_finish_one_ordered()); + +6) At this point the delayed iputs list is not empty, so the assertion at + close_ctree() fails. + +Fix this by flushing the fs_info->compressed_write_workers queue at +close_ctree() before flushing the fs_info->endio_write_workers queue, +respecting the queue dependency as the later is responsible for the +execution of ordered extent completion. + +CC: stable@vger.kernel.org # 5.15+ +Reviewed-by: Qu Wenruo +Signed-off-by: Filipe Manana +Signed-off-by: David Sterba +Signed-off-by: Greg Kroah-Hartman +--- + fs/btrfs/disk-io.c | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +--- a/fs/btrfs/disk-io.c ++++ b/fs/btrfs/disk-io.c +@@ -4662,6 +4662,18 @@ void __cold close_ctree(struct btrfs_fs_ + btrfs_flush_workqueue(fs_info->delalloc_workers); + + /* ++ * When finishing a compressed write bio we schedule a work queue item ++ * to finish an ordered extent - btrfs_finish_compressed_write_work() ++ * calls btrfs_finish_ordered_extent() which in turns does a call to ++ * btrfs_queue_ordered_fn(), and that queues the ordered extent ++ * completion either in the endio_write_workers work queue or in the ++ * fs_info->endio_freespace_worker work queue. We flush those queues ++ * below, so before we flush them we must flush this queue for the ++ * workers of compressed writes. ++ */ ++ flush_workqueue(fs_info->compressed_write_workers); ++ ++ /* + * After we parked the cleaner kthread, ordered extents may have + * completed and created new delayed iputs. If one of the async reclaim + * tasks is running and in the RUN_DELAYED_IPUTS flush state, then we diff --git a/queue-6.1/series b/queue-6.1/series index 360ae3bf56..d7b4fb5a88 100644 --- a/queue-6.1/series +++ b/queue-6.1/series @@ -126,3 +126,4 @@ mtd-inftlcore-add-error-check-for-inftl_read_oob.patch mtd-rawnand-add-status-chack-in-r852_ready.patch arm64-mm-correct-the-update-of-max_pfn.patch arm64-dts-mediatek-mt8173-fix-disp-pwm-compatible-string.patch +btrfs-fix-non-empty-delayed-iputs-list-on-unmount-due-to-compressed-write-workers.patch -- 2.47.3