From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19D163E3DB4; Tue, 21 Jul 2026 20:11:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784664708; cv=none; b=lkX8qptSSi9qzBaClyYYXLd8fnGOAg2nayUDEfBqnH29+KEDeD7pWU0PBoUuKc5D6/X9fx2MZa5QL0wqhhySaUWlpXaYaVpsZLwxG6E5zz/s72PEEYl0FzGdeuNVB8xIBe/TbPtAWUTvjewipEmIUblKNpWOJw8MItXrdGZfw7Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784664708; c=relaxed/simple; bh=WSTUS+YcP63loQGLK+J4gj6VGu1+CGqc5WoPNSqz/6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hJ/bx+TjHBqAhqyPvJdXf/bAkjb9e/VE2giw+F6H3c+neRLoaSBFvla+GwTkBmDa3uyCPJW36TzMmDla3ooT8sJdcCFrAULE6cElviEG5r6MOEap+Kj2KzZOcOOKvLe81EBYgGMDadppD+oZOlIWQBKcVQjbiqCDwD2ap0CInYc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZMkiD4yj; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ZMkiD4yj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12D6E1F000E9; Tue, 21 Jul 2026 20:11:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784664706; bh=KUt84+cbC8n60zUWNHTu7+PTXTHl9rIJI7p3qkLVuHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZMkiD4yjcTHISmfcK4P3V49GCm6bno6SIHMCM7icjsuYCaoRU0agjzwWVXQebHWEh 8ryfjNpDCnKpwCNLYDLmYdG/QiRzKHYpQ+DZd4W3NSXdV4H1biJ5M458ElwxJxer4y QgdBrEMhIVRcFG0ieV0x8cCpUtW/WnrOmntCq5DY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable@kernel.org, Ruipeng Qi , Chao Yu , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 6.6 0028/1266] f2fs: fix potential deadlock in gc_merge path of f2fs_balance_fs() Date: Tue, 21 Jul 2026 17:07:45 +0200 Message-ID: <20260721152442.423625076@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152441.786066624@linuxfoundation.org> References: <20260721152441.786066624@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chao Yu [ Upstream commit 8b4468ec023d0d1b4669dfb867588997cc03a06b ] When we mount device w/ gc_merge mount option, we may suffer below potential deadlock: Kworker GC trehad Truncator - f2fs_write_cache_pages - f2fs_write_single_data_page - f2fs_do_write_data_page - folio_start_writeback --- set writeback flag on folio - f2fs_outplace_write_data : cached folio in internal bio cache - f2fs_balance_fs - wake_up(gc_thread) : wake up gc thread to run foreground GC - finish_wait(fggc_wq) : wait on the waitqueue --- wait on GC thread to finish the work - truncate_inode_pages_range - __filemap_get_folio(, FGP_LOCK) --- lock folio - truncate_inode_partial_folio - folio_wait_writeback --- wait on writeback being cleared - do_garbage_collect - move_data_page - f2fs_get_lock_data_folio - lock on folio --- blocked on folio's lock In order to avoid such deadlock, let's call below functions to commit cached bios in GC_MERGE path of f2fs_balance_fs() as the same as we did in NOGC_MERGE path. - f2fs_submit_merged_write(sbi, DATA); - f2fs_submit_all_merged_ipu_writes(sbi); Cc: stable@kernel.org Fixes: 351df4b20115 ("f2fs: add segment operations") Cc: Ruipeng Qi Reported: Sandeep Dhavale Signed-off-by: Chao Yu Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/segment.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -433,6 +433,13 @@ void f2fs_balance_fs(struct f2fs_sb_info if (has_enough_free_secs(sbi, 0, 0)) return; + /* + * Submit all cached OPU/IPU DATA bios before triggering + * foreground GC to avoid potential deadlocks. + */ + f2fs_submit_merged_write(sbi, DATA); + f2fs_submit_all_merged_ipu_writes(sbi); + if (test_opt(sbi, GC_MERGE) && sbi->gc_thread && sbi->gc_thread->f2fs_gc_task) { DEFINE_WAIT(wait); @@ -451,13 +458,6 @@ void f2fs_balance_fs(struct f2fs_sb_info .err_gc_skipped = false, .nr_free_secs = 1 }; - /* - * Submit all cached OPU/IPU DATA bios before triggering - * foreground GC to avoid potential deadlocks. - */ - f2fs_submit_merged_write(sbi, DATA); - f2fs_submit_all_merged_ipu_writes(sbi); - f2fs_down_write(&sbi->gc_lock); stat_inc_gc_call_count(sbi, FOREGROUND); f2fs_gc(sbi, &gc_control);