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]
Date:	Mon, 25 Sep 2006 16:47:22 +0900
From:	Hirokazu Takata <takata.hirokazu@...esas.com>
To:	Matthew Wilcox <matthew@....cx>
Cc:	Hirokazu Takata <takata@...ux-m32r.org>,
	Andrew Morton <akpm@...l.org>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] m32r: Revise __raw_read_trylock()

From: Matthew Wilcox <matthew@....cx>
Subject: Re: [PATCH] m32r: Revise __raw_read_trylock()
Date: Sun, 24 Sep 2006 00:20:36 -0600
> On Fri, Sep 22, 2006 at 03:29:53PM +0900, Hirokazu Takata wrote:
> >  
> > -#define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
> > +static inline int __raw_read_trylock(raw_rwlock_t *lock)
> > +{
> > +	atomic_t *count = (atomic_t*)lock;
> > +	atomic_dec(count);
> > +	if (atomic_read(count) >= 0)
> > +		return 1;
> > +	atomic_inc(count);
> > +	return 0;
> > +}
> >  
> 
> Is there a race here between __raw_read_trylock and __raw_write_trylock?
> 
> CPU A			CPU B
> __raw_read_trylock
> atomic_dec(count);
> 			__raw_write_trylock
> 			atomic_sub_and_test(RW_LOCK_BIAS, count)
> atomic_read(count)

Indeed, it is a possible race.

> It'd be fairly harmless as neither would manage to get the lock.  But
> I think it's not too hard to fix.  Seems to me you want to do:

I agree with you.
As you said, I think the above case is harmless.

> static inline int __raw_read_trylock(raw_rwlock_t *lock)
> {
> 	atomic_t *count = (atomic_t*)lock;
> 	if (atomic_dec_return(count) >= 0)
> 		return 1;
> 	atomic_inc(count);
> 	return 0;
> }
> 
> eliminating the race.
> 

All right, I think this fix is preferable.

Andrew, please drop and replace the previous my patch with the following
Matthew's fix.

Thank you.

Signed-off-by: Hirokazu Takata <takata@...ux-m32r.org>
Cc: Matthew Wilcox <matthew@....cx>
--
 include/asm-m32r/spinlock.h |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/asm-m32r/spinlock.h b/include/asm-m32r/spinlock.h
index f94c1a6..f9f9072 100644
--- a/include/asm-m32r/spinlock.h
+++ b/include/asm-m32r/spinlock.h
@@ -298,7 +298,14 @@ #endif	/* CONFIG_CHIP_M32700_TS1 */
 	);
 }
 
-#define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
+static inline int __raw_read_trylock(raw_rwlock_t *lock)
+{
+	atomic_t *count = (atomic_t*)lock;
+	if (atomic_dec_return(count) >= 0)
+		return 1;
+	atomic_inc(count);
+	return 0;
+}
 
 static inline int __raw_write_trylock(raw_rwlock_t *lock)
 {
--
Hirokazu Takata <takata@...ux-m32r.org>
Linux/M32R Project:  http://www.linux-m32r.org/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ