lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230906184336.GH28160@frogsfrogsfrogs>
Date:   Wed, 6 Sep 2023 11:43:36 -0700
From:   "Darrick J. Wong" <djwong@...nel.org>
To:     Matthew Wilcox <willy@...radead.org>
Cc:     Bernd Schubert <bernd.schubert@...tmail.fm>,
        Mateusz Guzik <mjguzik@...il.com>, brauner@...nel.org,
        viro@...iv.linux.org.uk, linux-kernel@...r.kernel.org,
        linux-fsdevel@...r.kernel.org
Subject: Re: [RFC PATCH] vfs: add inode lockdep assertions

On Wed, Sep 06, 2023 at 07:33:48PM +0100, Matthew Wilcox wrote:
> 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.

I disagree, because using the bare 1 brings the most risk that someone
will subtly break the locking assertions some day when they get the
bright idea to move RWSEM_WRITER_LOCKED to the upper bit and fail to
notice this predicate and its magic number.  IMO moving it to the header
file (possibly with the usual __ prefix) would be preferable to leaving
a landmine.

--D

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ