linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: Bernd Schubert <bernd.schubert@fastmail.fm>,
	Mateusz Guzik <mjguzik@gmail.com>,
	brauner@kernel.org, viro@zeniv.linux.org.uk,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [RFC PATCH] vfs: add inode lockdep assertions
Date: Wed, 6 Sep 2023 19:33:48 +0100	[thread overview]
Message-ID: <ZPjGDGyDf2/ngML9@casper.infradead.org> (raw)
In-Reply-To: <20230906170724.GI28202@frogsfrogsfrogs>

On Wed, Sep 06, 2023 at 10:07:24AM -0700, Darrick J. Wong wrote:
> On Wed, Sep 06, 2023 at 05:00:14PM +0100, Matthew Wilcox wrote:
> > +++ b/fs/xfs/xfs_inode.c
> > @@ -361,7 +361,7 @@ xfs_isilocked(
> >  {
> >  	if (lock_flags & (XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)) {
> >  		if (!(lock_flags & XFS_ILOCK_SHARED))
> > -			return !!ip->i_lock.mr_writer;
> > +			return rwsem_is_write_locked(&ip->i_lock.mr_lock);
> 
> You'd be better off converting this to:
> 
> 	return __xfs_rwsem_islocked(&ip->i_lock.mr_lock,
> 				(lock_flags & XFS_ILOCK_SHARED));
> 
> And then fixing __xfs_rwsem_islocked to do:
> 
> static inline bool
> __xfs_rwsem_islocked(
> 	struct rw_semaphore	*rwsem,
> 	bool			shared)
> {
> 	if (!debug_locks) {
> 		if (!shared)
> 			return rwsem_is_write_locked(rwsem);
> 		return rwsem_is_locked(rwsem);
> 	}
> 
> 	...
> }

Thanks.

> > +++ b/include/linux/rwsem.h
> > @@ -72,6 +72,11 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem)
> >  	return atomic_long_read(&sem->count) != 0;
> >  }
> >  
> > +static inline int rwsem_is_write_locked(struct rw_semaphore *sem)
> > +{
> > +	return atomic_long_read(&sem->count) & 1;
> 
> 
> atomic_long_read(&sem->count) & RWSEM_WRITER_LOCKED ?

Then this would either have to be in rwsem.c or we'd have to move the
definition of RWSEM_WRITER_LOCKED to rwsem.h.  All three options are
kind of bad.  I think I hate the bare '1' least.

  reply	other threads:[~2023-09-06 18:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-31 15:14 [RFC PATCH] vfs: add inode lockdep assertions Mateusz Guzik
2023-09-01 12:43 ` Christian Brauner
2023-09-06 15:20 ` Matthew Wilcox
2023-09-06 15:23   ` Bernd Schubert
2023-09-06 15:27     ` Matthew Wilcox
2023-09-14 13:16       ` Mateusz Guzik
2023-09-06 15:29     ` Darrick J. Wong
2023-09-06 16:00       ` Matthew Wilcox
2023-09-06 17:07         ` Darrick J. Wong
2023-09-06 18:33           ` Matthew Wilcox [this message]
2023-09-06 18:43             ` Darrick J. Wong
2023-09-06 19:01               ` Matthew Wilcox
2023-09-06 19:19                 ` Darrick J. Wong
2023-09-06 21:10           ` Matthew Wilcox
2023-09-06 21:26             ` Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZPjGDGyDf2/ngML9@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=bernd.schubert@fastmail.fm \
    --cc=brauner@kernel.org \
    --cc=djwong@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjguzik@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).