From nobody Thu Apr 9 17:19:55 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4C338329C7F for ; Fri, 6 Mar 2026 12:24:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772799875; cv=none; b=i+dKV8zLY5kxje2fSyJUkd0uo35+S36H4YTK8Fvr8BfpGAozsJJd76hG93/Fv57dDHFEsJxrLURaCqosEGLQnF0xTb7QFi1fbY4A3mLEYPPiSfzjuQeTT67GAFggJdzyCzuKoqRTptp6pQaxT6T356bvAsrVM65lujVskJwPJ6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772799875; c=relaxed/simple; bh=GJ6H/6SW9BWS8IUAa2gKMPL+Oo1QfMavlJfext1dils=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=pebdOeGtkhYN5BWsxTt2zC2nhLnOQj77cCWjzrRzYWV9lNe8eknlOMVR1si/jCsf4YU4z1gjzui2UCl9llKsvolmft0wlBAhp1bpdmz/80knVQL68Bnuvgv53T4NzQvub7EWWXQbixOeKu3l5nxkeagVjiC5biVb+sVorkJE/x4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FLhkRbDp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FLhkRbDp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF136C2BC87; Fri, 6 Mar 2026 12:24:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772799875; bh=GJ6H/6SW9BWS8IUAa2gKMPL+Oo1QfMavlJfext1dils=; h=From:To:Cc:Subject:Date:From; b=FLhkRbDp94ubZaKfL/jfyrpqv6RnCbXhUFTLI/pAQLOXd2E99h+yY9bkEF7pPUn/q MSiBrx15yap+TWjxTS73VSWE2CWWSDaVWOI0+EHXS/F6fNlRxxe9MDDdovqsV80V6Z 75u0LlcPgeAnbfiZfgzi9pfG8Y62aLlbW3gkLlOe4CWg9kMS3hqYd4bCVjt5Nobqyu veF1Hw7pHiWQ/U6z1/4QaybSFxZTGNCa4/+4KCpOIqcbInqLR25MYYa90JIba/AnFa pznPrBnD4bvfKiGZj+t0zbM2Na+mLAm3MBB5wZta0N585QZNiMP/BbgUZWiusZdhqG CrDPje/J2PQUg== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , stable@kernel.org, Shin'ichiro Kawasaki Subject: [PATCH] f2fs: fix false alarm of lockdep on cp_global_sem lock Date: Fri, 6 Mar 2026 12:24:20 +0000 Message-ID: <20260306122421.209903-1-chao@kernel.org> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" lockdep reported a potential deadlock: a) TCMU device removal context: - call del_gendisk() to get q->q_usage_counter - call start_flush_work() to get work_completion of wb->dwork b) f2fs writeback context: - in wb_workfn(), which holds work_completion of wb->dwork - call f2fs_balance_fs() to get sbi->gc_lock c) f2fs vfs_write context: - call f2fs_gc() to get sbi->gc_lock - call f2fs_write_checkpoint() to get sbi->cp_global_sem d) f2fs mount context: - call recover_fsync_data() to get sbi->cp_global_sem - call f2fs_check_and_fix_write_pointer() to call blkdev_report_zones() that goes down to blk_mq_alloc_request and get q->q_usage_counter Original callstack is in Closes tag. However, I think this is a false alarm due to before mount returns successfully (context d), we can not access file therein via vfs_write (context c). Let's introduce per-sb cp_global_sem_key, and assign the key for cp_global_sem, so that lockdep can recognize cp_global_sem from different super block correctly. A lot of work are done by Shin'ichiro Kawasaki, thanks a lot for the work. Fixes: c426d99127b1 ("f2fs: Check write pointer consistency of open zones") Cc: stable@kernel.org Reported-and-tested-by: Shin'ichiro Kawasaki Closes: https://lore.kernel.org/linux-f2fs-devel/20260218125237.3340441-1-s= hinichiro.kawasaki@wdc.com Signed-off-by: Shin'ichiro Kawasaki Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 3 +++ fs/f2fs/super.c | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 8942b2a63cfd..87a83c21837c 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2042,6 +2042,9 @@ struct f2fs_sb_info { spinlock_t iostat_lat_lock; struct iostat_lat_info *iostat_io_lat; #endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC + struct lock_class_key cp_global_sem_key; +#endif }; =20 /* Definitions to access f2fs_sb_info */ diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 8774c60b4be4..1d97dded4ee5 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4948,6 +4948,11 @@ static int f2fs_fill_super(struct super_block *sb, s= truct fs_context *fc) init_f2fs_rwsem_trace(&sbi->gc_lock, sbi, LOCK_NAME_GC_LOCK); mutex_init(&sbi->writepages); init_f2fs_rwsem_trace(&sbi->cp_global_sem, sbi, LOCK_NAME_CP_GLOBAL); +#ifdef CONFIG_DEBUG_LOCK_ALLOC + lockdep_register_key(&sbi->cp_global_sem_key); + lockdep_set_class(&sbi->cp_global_sem.internal_rwsem, + &sbi->cp_global_sem_key); +#endif init_f2fs_rwsem_trace(&sbi->node_write, sbi, LOCK_NAME_NODE_WRITE); init_f2fs_rwsem_trace(&sbi->node_change, sbi, LOCK_NAME_NODE_CHANGE); spin_lock_init(&sbi->stat_lock); @@ -5419,6 +5424,9 @@ static int f2fs_fill_super(struct super_block *sb, st= ruct fs_context *fc) free_sb_buf: kfree(raw_super); free_sbi: +#ifdef CONFIG_DEBUG_LOCK_ALLOC + lockdep_unregister_key(&sbi->cp_global_sem_key); +#endif kfree(sbi); sb->s_fs_info =3D NULL; =20 @@ -5500,6 +5508,9 @@ static void kill_f2fs_super(struct super_block *sb) /* Release block devices last, after fscrypt_destroy_keyring(). */ if (sbi) { destroy_device_list(sbi); +#ifdef CONFIG_DEBUG_LOCK_ALLOC + lockdep_unregister_key(&sbi->cp_global_sem_key); +#endif kfree(sbi); sb->s_fs_info =3D NULL; } --=20 2.49.0