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 AD077401A0A; Thu, 16 Jul 2026 14:20:19 +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=1784211620; cv=none; b=Zc1KC05xhv+p8ySXJ48282dczFAdXmOhD7gl77rykLnrGfMXELOR/Q4I2/yoskPDnrBuNJZKpQri/8XyytRII+a4qnmX19BXtoLAqrIER7A+gR70Sy7oPdo0efWeZbHXIDOkqNdwBABG3r3JCqHPJ9J8ZfT0tmho4Y9uOLFWwx0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784211620; c=relaxed/simple; bh=JNBYSXrQlWXRlbxcMIisOjqbd5o/fzrwWdJBc3Uk9zE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jjDKbTqpbJlkL7DIaDjmUihUMc4J/N5lESds1fBAml6eAWGJ5Qj7RfJq1pQj20A7DaqZGpCj+bRDEaVu9eiMeRMpDo/Wx3x3FFnat4inVRefXge9O6WdN3XKDJsq9aXEy3wHPZUG7JI7u7TQhk/SM+jAmhkNnjp0bMfZnfJXY8w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=DJh/nL+o; 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="DJh/nL+o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20D161F000E9; Thu, 16 Jul 2026 14:20:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784211619; bh=yWPo8fBt4AtBHpVG5uc0UL1F1x70LDRGTgDPwImFjjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DJh/nL+ol8KyganF3d2CilRASX+WP7b49z2g2fM43tAyUpItIYes9PdSMqVLcDPk/ RJ1BMfM8iPm4oN2ZgjvU1FwxBFConqrZd+r2jF7Uaxe2a9IE6REJYytCL72OQfr9LN zYoC/cwKZSMJl17FlZKJoIUBD6dd9sixDF/9v0xU= 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.12 017/349] f2fs: fix potential deadlock in gc_merge path of f2fs_balance_fs() Date: Thu, 16 Jul 2026 15:29:11 +0200 Message-ID: <20260716133033.682201459@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260716133033.287196923@linuxfoundation.org> References: <20260716133033.287196923@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.12-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 @@ -434,6 +434,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); @@ -452,13 +459,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);