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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sun, 14 Jul 2013 01:58:24 +0900
From:	Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>
To:	Waiman Long <Waiman.Long@...com>
Cc:	Alexander Viro <viro@...iv.linux.org.uk>,
	Jeff Layton <jlayton@...hat.com>,
	Miklos Szeredi <mszeredi@...e.cz>,
	Ingo Molnar <mingo@...hat.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
	Peter Zijlstra <peterz@...radead.org>,
	Steven Rostedt <rostedt@...dmis.org>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Benjamin Herrenschmidt <benh@...nel.crashing.org>,
	Andi Kleen <andi@...stfloor.org>,
	"Chandramouleeswaran, Aswin" <aswin@...com>,
	"Norton, Scott J" <scott.norton@...com>
Subject: Re: [PATCH v6 01/14] spinlock: A new lockref structure for lockless
 update of refcount

Hi,

(2013/07/09 10:09), Waiman Long wrote:> +/**
> + * lockref_put_or_lock - decrements count unless count <= 1 before decrement
> + * @lockcnt: pointer to lockref structure
> + * Return: 1 if count updated successfully or 0 if count <= 1 and lock taken
> + *
> + * The only difference between lockref_put_or_lock and lockref_put is that
> + * the former function will hold the lock on return while the latter one
> + * will free it on return.
> + */
> +static __always_inline int lockref_put_or_locked(struct lockref *lockcnt)

Here is a function name typo. _locked should be _lock.
And also, I think we should take a note here to tell this function does *not*
guarantee lockcnt->refcnt == 0 or 1 until unlocked if this returns 0.

> +{
> +	spin_lock(&lockcnt->lock);
> +	if (likely(lockcnt->refcnt > 1)) {
> +		lockcnt->refcnt--;
> +		spin_unlock(&lockcnt->lock);
> +		return 1;
> +	}
> +	return 0;
> +}

Using this implementation guarantees lockcnt->refcnt == 0 or 1 until unlocked
if this returns 0.

However, the below one looks not guarantee it. Since lockref_add_unless
and spinlock are not done atomically, there is a chance for someone
to increment it right before locking.

Or, I missed something?

> +/**
> + * lockref_put_or_lock - Decrements count unless the count is <= 1
> + *			 otherwise, the lock will be taken
> + * @lockcnt: pointer to struct lockref structure
> + * Return: 1 if count updated successfully or 0 if count <= 1 and lock taken
> + */
> +int
> +lockref_put_or_lock(struct lockref *lockcnt)
> +{
> +	if (lockref_add_unless(lockcnt, -1, 1))
> +		return 1;
> +	spin_lock(&lockcnt->lock);
> +	return 0;
> +}

BTW, it looks that your dcache patch knows this and keeps double check for
the case of lockcnt->refcnt > 1 in dput().

Thank you,

-- 
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@...achi.com

--
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