diff mbox series

[V4,02/13] fs/xfs: Clarify lockdep dependency for xfs_isilocked()

Message ID 20200221004134.30599-3-ira.weiny@intel.com
State Superseded
Headers show
Series Enable per-file/per-directory DAX operations V4 | expand

Commit Message

Ira Weiny Feb. 21, 2020, 12:41 a.m. UTC
From: Ira Weiny <ira.weiny@intel.com>

xfs_isilocked() can't work fully without CONFIG_LOCKDEP.  However,
making xfs_isilocked() dependant on CONFIG_LOCKDEP is not feasible
because it is used for more than the i_rwsem.  Therefore a short-circuit
was provided via debug_locks.  However, this caused confusion while
working through the xfs locking.

Rather than use debug_locks as a flag specify this clearly using
IS_ENABLED(CONFIG_LOCKDEP).

Signed-off-by: Ira Weiny <ira.weiny@intel.com>

---
Changes from V3:
	Reordered to be a "pre-cleanup" patch

Changes from V2:
	This patch is new for V3
---
 fs/xfs/xfs_inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Dave Chinner Feb. 21, 2020, 1:34 a.m. UTC | #1
On Thu, Feb 20, 2020 at 04:41:23PM -0800, ira.weiny@intel.com wrote:
> From: Ira Weiny <ira.weiny@intel.com>
> 
> xfs_isilocked() can't work fully without CONFIG_LOCKDEP.  However,
> making xfs_isilocked() dependant on CONFIG_LOCKDEP is not feasible
> because it is used for more than the i_rwsem.  Therefore a short-circuit
> was provided via debug_locks.  However, this caused confusion while
> working through the xfs locking.
> 
> Rather than use debug_locks as a flag specify this clearly using
> IS_ENABLED(CONFIG_LOCKDEP).
> 
> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> 
> ---
> Changes from V3:
> 	Reordered to be a "pre-cleanup" patch
> 
> Changes from V2:
> 	This patch is new for V3
> ---
>  fs/xfs/xfs_inode.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
> index c5077e6326c7..35df324875db 100644
> --- a/fs/xfs/xfs_inode.c
> +++ b/fs/xfs/xfs_inode.c
> @@ -364,7 +364,7 @@ xfs_isilocked(
>  
>  	if (lock_flags & (XFS_IOLOCK_EXCL|XFS_IOLOCK_SHARED)) {
>  		if (!(lock_flags & XFS_IOLOCK_SHARED))
> -			return !debug_locks ||
> +			return !IS_ENABLED(CONFIG_LOCKDEP) ||
>  				lockdep_is_held_type(&VFS_I(ip)->i_rwsem, 0);

This breaks expected lockdep behaviour.

We need to use debug_locks here because lockdep turns off lock
checking via debug_locks when lockdep encounters a locking
inconsistency.  We only want to know about the first locking
problem, not spew cascading lock problems over and over once we
already know there is a locking problem.

IOWs, checking debug_locks is required here for the same reason it
is used in lockdep_assert_held_{read/write}(). essentially we are
open coding lockdep_assert_held_write() here because this function
is only called from within ASSERT() statements and we don't want
multiple WARN/BUGs being issued when this triggers....

Cheers,

Dave.
Ira Weiny Feb. 21, 2020, 11 p.m. UTC | #2
On Fri, Feb 21, 2020 at 12:34:51PM +1100, Dave Chinner wrote:
> On Thu, Feb 20, 2020 at 04:41:23PM -0800, ira.weiny@intel.com wrote:
> > From: Ira Weiny <ira.weiny@intel.com>
> > 
> > xfs_isilocked() can't work fully without CONFIG_LOCKDEP.  However,
> > making xfs_isilocked() dependant on CONFIG_LOCKDEP is not feasible
> > because it is used for more than the i_rwsem.  Therefore a short-circuit
> > was provided via debug_locks.  However, this caused confusion while
> > working through the xfs locking.
> > 
> > Rather than use debug_locks as a flag specify this clearly using
> > IS_ENABLED(CONFIG_LOCKDEP).
> > 
> > Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> > 
> > ---
> > Changes from V3:
> > 	Reordered to be a "pre-cleanup" patch
> > 
> > Changes from V2:
> > 	This patch is new for V3
> > ---
> >  fs/xfs/xfs_inode.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
> > index c5077e6326c7..35df324875db 100644
> > --- a/fs/xfs/xfs_inode.c
> > +++ b/fs/xfs/xfs_inode.c
> > @@ -364,7 +364,7 @@ xfs_isilocked(
> >  
> >  	if (lock_flags & (XFS_IOLOCK_EXCL|XFS_IOLOCK_SHARED)) {
> >  		if (!(lock_flags & XFS_IOLOCK_SHARED))
> > -			return !debug_locks ||
> > +			return !IS_ENABLED(CONFIG_LOCKDEP) ||
> >  				lockdep_is_held_type(&VFS_I(ip)->i_rwsem, 0);
> 
> This breaks expected lockdep behaviour.
> 
> We need to use debug_locks here because lockdep turns off lock
> checking via debug_locks when lockdep encounters a locking
> inconsistency.  We only want to know about the first locking
> problem, not spew cascading lock problems over and over once we
> already know there is a locking problem.

Ah...  ok...  Seems like that should be part of the lockdep interface...

I'll drop the patch for now,
Ira

> 
> IOWs, checking debug_locks is required here for the same reason it
> is used in lockdep_assert_held_{read/write}(). essentially we are
> open coding lockdep_assert_held_write() here because this function
> is only called from within ASSERT() statements and we don't want
> multiple WARN/BUGs being issued when this triggers....
> 
> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
diff mbox series

Patch

diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index c5077e6326c7..35df324875db 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -364,7 +364,7 @@  xfs_isilocked(
 
 	if (lock_flags & (XFS_IOLOCK_EXCL|XFS_IOLOCK_SHARED)) {
 		if (!(lock_flags & XFS_IOLOCK_SHARED))
-			return !debug_locks ||
+			return !IS_ENABLED(CONFIG_LOCKDEP) ||
 				lockdep_is_held_type(&VFS_I(ip)->i_rwsem, 0);
 		return rwsem_is_locked(&VFS_I(ip)->i_rwsem);
 	}