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: <20190418082206.GT12232@hirez.programming.kicks-ass.net>
Date:   Thu, 18 Apr 2019 10:22:06 +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>,
        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 v4 07/16] locking/rwsem: Implement lock handoff to
 prevent lock starvation

On Wed, Apr 17, 2019 at 12:39:19PM -0400, Waiman Long wrote:
> On 04/17/2019 04:05 AM, Peter Zijlstra wrote:
> > So what is wrong with the below?
> >
> > --- a/include/linux/sched/wake_q.h
> > +++ b/include/linux/sched/wake_q.h
> > @@ -51,6 +51,11 @@ static inline void wake_q_init(struct wa
> >  	head->lastp = &head->first;
> >  }
> >  
> > +static inline bool wake_q_empty(struct wake_q_head *head)
> > +{
> > +	return head->first == WAKE_Q_TAIL;
> > +}
> > +
> >  extern void wake_q_add(struct wake_q_head *head, struct task_struct *task);
> >  extern void wake_q_add_safe(struct wake_q_head *head, struct task_struct *task);
> >  extern void wake_up_q(struct wake_q_head *head);
> > --- a/kernel/locking/rwsem.c
> > +++ b/kernel/locking/rwsem.c
> > @@ -700,25 +700,22 @@ __rwsem_down_write_failed_common(struct
> >  		 *     must be read owned; so we try to wake any read lock
> >  		 *     waiters that were queued ahead of us.
> >  		 */
> > -		if (!(count & RWSEM_LOCKED_MASK))
> > -			__rwsem_mark_wake(sem, RWSEM_WAKE_ANY, &wake_q);
> > -		else if (!(count & RWSEM_WRITER_MASK) &&
> > -				(count & RWSEM_READER_MASK))
> > -			__rwsem_mark_wake(sem, RWSEM_WAKE_READERS, &wake_q);
> > -		else
> > +		if (count & RWSEM_WRITER_LOCKED)
> >  			goto wait;
> > -		/*
> > -		 * The wakeup is normally called _after_ the wait_lock
> > -		 * is released, but given that we are proactively waking
> > -		 * readers we can deal with the wake_q overhead as it is
> > -		 * similar to releasing and taking the wait_lock again
> > -		 * for attempting rwsem_try_write_lock().
> > -		 */
> > -		wake_up_q(&wake_q);
> > -		/*
> > -		 * Reinitialize wake_q after use.
> > -		 */
> > -		wake_q_init(&wake_q);
> > +
> > +		__rwsem_mark_wake(sem, (count & RWSEM_READER_MASK) ?
> > +				RWSEM_WAKE_READERS :
> > +				RWSEM_WAKE_ANY, &wake_q);
> > +
> > +		if (!wake_q_empty(&wake_q)) {
> > +			raw_spin_unlock_irq(&sem->wait_lock);
> > +			wake_up_q(&wake_q);
> > +			/* used again, reinit */
> > +			wake_q_init(&wake_q);
> > +			raw_spin_lock_irq(&sem->wait_lock);
> > +			if (rwsem_waiter_is_first(sem, &waiter))
> > +				wstate = WRITER_FIRST;
> > +		}
> >  	} else {
> >  		count = atomic_long_add_return(RWSEM_FLAG_WAITERS, &sem->count);
> >  	}
> 
> Yes, we can certainly do that. My point is that I haven't changed the
> existing logic regarding that wakeup, I only move it around in the
> patch. As it is not related to lock handoff, we can do it as a separate
> patch.

Ah, I missed that the old code did that too (too much looking at the new
code I suppose). Then yes, a separate patch fixing this would be good.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ