Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757886AbcDEJaC (ORCPT ); Tue, 5 Apr 2016 05:30:02 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:50956 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752863AbcDEJaA (ORCPT ); Tue, 5 Apr 2016 05:30:00 -0400 Date: Tue, 5 Apr 2016 11:29:54 +0200 From: Peter Zijlstra To: xlpang@redhat.com Cc: linux-kernel@vger.kernel.org, Juri Lelli , Ingo Molnar , Steven Rostedt , Thomas Gleixner Subject: Re: [PATCH] sched/deadline/rtmutex: Fix a PI crash for deadline tasks Message-ID: <20160405092954.GC24771@twins.programming.kicks-ass.net> References: <1459508418-25577-1-git-send-email-xlpang@redhat.com> <20160401113827.GQ3430@twins.programming.kicks-ass.net> <56FE685E.6080001@redhat.com> <19912883-8AB1-4DFD-A0E1-F23057785243@infradead.org> <56FE78E0.5060504@redhat.com> <20160401215143.GB2906@worktop> <57037974.1020002@redhat.com> <20160405091954.GI3448@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160405091954.GI3448@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1914 Lines: 65 On Tue, Apr 05, 2016 at 11:19:54AM +0200, Peter Zijlstra wrote: > Or did I miss something (again) ? :-) > > --- > kernel/locking/rtmutex.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c > index 3e746607abe5..36eb232bd29f 100644 > --- a/kernel/locking/rtmutex.c > +++ b/kernel/locking/rtmutex.c > @@ -1390,11 +1390,11 @@ rt_mutex_fastunlock(struct rt_mutex *lock, > } else { > bool deboost = slowfn(lock, &wake_q); > > - wake_up_q(&wake_q); > - > /* Undo pi boosting if necessary: */ > if (deboost) > rt_mutex_adjust_prio(current); > + > + wake_up_q(&wake_q); > } > } So one potential issue with this -- and this might be reason this code is the way it is -- is that the moment we de-boost we can get preempted, before having had a chance to wake the higher prio task, getting ourselves into a prio-inversion. But again, that should be fairly simply to fix. -- kernel/locking/rtmutex.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index 3e746607abe5..1896baf28e9c 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -1390,11 +1390,21 @@ rt_mutex_fastunlock(struct rt_mutex *lock, } else { bool deboost = slowfn(lock, &wake_q); - wake_up_q(&wake_q); - - /* Undo pi boosting if necessary: */ + /* + * Undo pi boosting (if necessary) and wake top waiter. + * + * We should deboost before waking the high-prio task such that + * we don't run two tasks with the 'same' state. This however + * can lead to prio-inversion if we would get preempted after + * the deboost but before waking our high-prio task, hence the + * preempt_disable. + */ + preempt_disable(); if (deboost) rt_mutex_adjust_prio(current); + + wake_up_q(&wake_q); + preempt_enable(); } }