Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757732AbcDEKso (ORCPT ); Tue, 5 Apr 2016 06:48:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44067 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756695AbcDEKsn (ORCPT ); Tue, 5 Apr 2016 06:48:43 -0400 Reply-To: xlpang@redhat.com Subject: Re: [PATCH] sched/deadline/rtmutex: Fix a PI crash for deadline tasks 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> <20160405092954.GC24771@twins.programming.kicks-ass.net> To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Juri Lelli , Ingo Molnar , Steven Rostedt , Thomas Gleixner From: Xunlei Pang Message-ID: <57039806.2070102@redhat.com> Date: Tue, 5 Apr 2016 18:48:38 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <20160405092954.GC24771@twins.programming.kicks-ass.net> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2366 Lines: 77 On 2016/04/05 at 17:29, Peter Zijlstra wrote: > 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. This is cool, I think we should also init "pi_task" properly for INIT_MUTEX and fork, otherwise looks good to me :-) Besides, do you think we can kill "pi_waiters_leftmost" from task_struct, as we can easily get it from "pi_waiters"? I will test it further with these new changes soon. Regards, Xunlei > > -- > 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(); > } > } >