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 DFBCD373BF2 for ; Wed, 20 May 2026 11:49:09 +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=1779277751; cv=none; b=uXOOD/5sGbRu0vnklzLgEtRGGRm5gKZTVyY/EomSIwHf4qBU2jigoS9s2eQQJ0yX85TbJ77pObEKXfPUmozJVH8d8XbnKYb2suOXllvRe9GwAhb6V7mzS2MfaLfMujY3JuPoY7yN7hJuOcLjntn0fwOWKDdPiEKkAIsoL/hLygU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779277751; c=relaxed/simple; bh=m45IJalGFJ4vaxIfg0Dpeq0pJwymm2QGdfVBxpGhBi8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fu7I82Hkr6U7Spmroa/MyDoJMCLIJatGYLDioW0wk+BMbn/kOTmHsbORaGOXR5aPYOjV4wGBE7qxcTYyu7k07mmOZWGno8mz22zpSwHqzO/ayOrmAbUzRO0dlYDOQI5/lnVjbbOvejlksAWb3vPcx4O10fr+pH3q2JE1DlamIvY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H/GuvSjR; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H/GuvSjR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC4981F000E9; Wed, 20 May 2026 11:49:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779277749; bh=an6tZCmvB2sJNzGWPwrQwv6QAhiZSOTC+e6Og8gB8jI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=H/GuvSjRgy8dtyryMpq1gU0icVfZ5aFYZuyQhYvbnZf3T4kmL+iuwsKTlBpFSVbeR uB96FDscMd5bt9kt/2vEM2cloJLHcciX4QqWwiYK/ot0LsN4YNi7A7eM5ElP3Sg9QI VEFCWhMBgicZKWI++y0gMUv8VqflhlRCf+cty7ptuUTIzAvK9qb9gBeQ2FTm2xuBFV Hkr5fHCD4t0W80HLUEgd0sLCMcaypU/K5boMo1UesKEvwAcrvaRt7KwyDJNyOtwW/L q4VaiW1wWDQ1e9A/2WqbccvWQmzYKK7WhxVKrITLEn6kFVVpNdq0WDBa01OO16jIth s3HpBMUlkuUsA== From: Sasha Levin To: stable@vger.kernel.org Cc: Chao Yu , stable@kernel.org, Shin'ichiro Kawasaki , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.15.y] f2fs: fix false alarm of lockdep on cp_global_sem lock Date: Wed, 20 May 2026 07:49:07 -0400 Message-ID: <20260520114907.3473814-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026051240-overthrow-lumpiness-9c49@gregkh> References: <2026051240-overthrow-lumpiness-9c49@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chao Yu [ Upstream commit 6a5e3de9c2bb0b691d16789a5d19e9276a09b308 ] 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-shinichiro.kawasaki@wdc.com Signed-off-by: Shin'ichiro Kawasaki Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim [ adapted to plain `struct rw_semaphore` (no `f2fs_rwsem` wrapper) and moved success-path `lockdep_unregister_key` from `kill_f2fs_super` to `f2fs_put_super` where sbi is actually freed ] Signed-off-by: Sasha Levin --- 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 31968257ad8e2..121d7c361b617 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1798,6 +1798,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 }; struct f2fs_private_dio { diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 6f6368400ee46..595e6a6fcdad1 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1667,6 +1667,9 @@ static void f2fs_put_super(struct super_block *sb) kvfree(sbi->write_io[i]); #ifdef CONFIG_UNICODE utf8_unload(sb->s_encoding); +#endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC + lockdep_unregister_key(&sbi->cp_global_sem_key); #endif kfree(sbi); } @@ -4118,6 +4121,11 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) init_rwsem(&sbi->gc_lock); mutex_init(&sbi->writepages); init_rwsem(&sbi->cp_global_sem); +#ifdef CONFIG_DEBUG_LOCK_ALLOC + lockdep_register_key(&sbi->cp_global_sem_key); + lockdep_set_class(&sbi->cp_global_sem, + &sbi->cp_global_sem_key); +#endif init_rwsem(&sbi->node_write); init_rwsem(&sbi->node_change); @@ -4519,6 +4527,9 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) free_sbi: if (sbi->s_chksum_driver) crypto_free_shash(sbi->s_chksum_driver); +#ifdef CONFIG_DEBUG_LOCK_ALLOC + lockdep_unregister_key(&sbi->cp_global_sem_key); +#endif kfree(sbi); /* give only one another chance */ -- 2.53.0