From abc1cb55887a5bd6723d32c9a93148a79065e195 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Wed, 3 Jul 2024 14:22:17 -0700 Subject: [PATCH] xfs: add a lockdep class key per rtgroup Add a dynamic lockdep class key to each rtgroup. This will enable lockdep to deduce inconsistencies in the rtgroup metadata ILOCK locking order. Each class can have 8 subclasses, and for now we will only have 2 inodes per group. This enables rtgroup order and inode order checks. Signed-off-by: Darrick J. Wong --- libxfs/xfs_rtgroup.c | 8 ++++++++ libxfs/xfs_rtgroup.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/libxfs/xfs_rtgroup.c b/libxfs/xfs_rtgroup.c index 97451ea3a..258d47403 100644 --- a/libxfs/xfs_rtgroup.c +++ b/libxfs/xfs_rtgroup.c @@ -160,6 +160,8 @@ xfs_initialize_rtgroups( /* Place kernel structure only init below this point. */ spin_lock_init(&rtg->rtg_state_lock); init_waitqueue_head(&rtg->rtg_active_wq); + memset(&rtg->lock_class, 0, sizeof(rtg->lock_class)); + lockdep_register_key(&rtg->lock_class); #endif /* __KERNEL__ */ /* Active ref owned by mount indicates rtgroup is online. */ @@ -199,6 +201,9 @@ xfs_free_unused_rtgroup_range( spin_unlock(&mp->m_rtgroup_lock); if (!rtg) break; +#ifdef __KERNEL__ + lockdep_unregister_key(&rtg->lock_class); +#endif kfree(rtg); } } @@ -232,6 +237,9 @@ xfs_free_rtgroups( spin_unlock(&mp->m_rtgroup_lock); ASSERT(rtg); XFS_IS_CORRUPT(mp, atomic_read(&rtg->rtg_ref) != 0); +#ifdef __KERNEL__ + lockdep_unregister_key(&rtg->lock_class); +#endif /* drop the mount's active reference */ xfs_rtgroup_rele(rtg); diff --git a/libxfs/xfs_rtgroup.h b/libxfs/xfs_rtgroup.h index c79786276..7f5e04eee 100644 --- a/libxfs/xfs_rtgroup.h +++ b/libxfs/xfs_rtgroup.h @@ -36,6 +36,8 @@ struct xfs_rtgroup { #ifdef __KERNEL__ /* -- kernel only structures below this line -- */ spinlock_t rtg_state_lock; + + struct lock_class_key lock_class; #endif /* __KERNEL__ */ }; -- 2.50.1