lkml.org 
[lkml]   [2019]   [Jun]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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?

\
 
 \ /
  Last update: 2019-06-11 15:12    [W:0.411 / U:3.500 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site