[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190611131131.GG3402@hirez.programming.kicks-ass.net>
Date: Tue, 11 Jun 2019 15:11:31 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Waiman Long <longman@...hat.com>
Cc: Ingo Molnar <mingo@...hat.com>, Will Deacon <will.deacon@....com>,
Thomas Gleixner <tglx@...utronix.de>,
Borislav Petkov <bp@...en8.de>,
"H. Peter Anvin" <hpa@...or.com>, linux-kernel@...r.kernel.org,
x86@...nel.org, Davidlohr Bueso <dave@...olabs.net>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Tim Chen <tim.c.chen@...ux.intel.com>,
huang ying <huang.ying.caritas@...il.com>
Subject: Re: [PATCH v8 16/19] locking/rwsem: Guard against making count
negative
On Mon, May 20, 2019 at 04:59:15PM -0400, Waiman Long wrote:
> +static inline long rwsem_read_trylock(struct rw_semaphore *sem, long *cnt)
> +{
> + long adjustment = -RWSEM_READER_BIAS;
> +
> + *cnt = atomic_long_fetch_add_acquire(RWSEM_READER_BIAS, &sem->count);
I'm thinking we'd actually want add_return_acquire() here.
> + if (unlikely(*cnt < 0)) {
> + atomic_long_add(-RWSEM_READER_BIAS, &sem->count);
> + adjustment = 0;
> + }
> + return adjustment;
> +}
> @@ -1271,9 +1332,10 @@ static struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem)
> */
> inline void __down_read(struct rw_semaphore *sem)
> {
> + long tmp, adjustment = rwsem_read_trylock(sem, &tmp);
> +
> + if (unlikely(tmp & RWSEM_READ_FAILED_MASK)) {
> + rwsem_down_read_slowpath(sem, TASK_UNINTERRUPTIBLE, adjustment);
> DEBUG_RWSEMS_WARN_ON(!is_rwsem_reader_owned(sem), sem);
> } else {
> rwsem_set_reader_owned(sem);
> @@ -1282,9 +1344,11 @@ inline void __down_read(struct rw_semaphore *sem)
>
> static inline int __down_read_killable(struct rw_semaphore *sem)
> {
> + long tmp, adjustment = rwsem_read_trylock(sem, &tmp);
> +
> + if (unlikely(tmp & RWSEM_READ_FAILED_MASK)) {
> + if (IS_ERR(rwsem_down_read_slowpath(sem, TASK_KILLABLE,
> + adjustment)))
> return -EINTR;
> DEBUG_RWSEMS_WARN_ON(!is_rwsem_reader_owned(sem), sem);
> } else {
I'm confused by the need for @tmp; isn't that returning the exact same
state !adjustment is?
Also; half the patch seems to do cnt<0, while the other half (above)
does &READ_FAILED, what gives?
Powered by blists - more mailing lists