Hi Ingo, I just discovered a priority inversion bug with the current code. Attached is code for a module that forces the situation and shows that it is wrong. What the module does is the following: Creates three threads and two locks. The parent takes lock L1 and creates the other threads where P1 is the lowest priority and P3 is the highest. It then wakes up P2 which tries to grab the lock L1 which the parent already has (which should boost the parent). Then P1 wakes up, grabs it's own lock L2 and then grabs the parent's lock L1 and it too will block. Then P3 wakes up and grabs P1's lock L2 and it blocks. So this looks like this: Parent-has-L1 P1-has-L2 -blocked-L1 P2-blocked-L1 P3-blocked-L2 Now the fun part. When the parent releases L1, P1 should get the lock since P3 is the highest proirity and P1 inherits that prio. But what happens is that P2 gets the lock. Here's the output of the module: thread 2 running thread 1 running thread 1 got lock t2 thread 3 running parent releasing the t1 lock! thread 2 got lock t1 thread 1 got lock t1 thread 3 got lock t2 This bug was introduced by the addition of the plists. This is because the old way was to find who got the lock at the releasing of the lock. Now it happens at the time a task blocks on the lock. But this information is not updated when PI takes place. So below is the patch to fix this. With the patch, I get the following output: thread 2 running thread 1 running thread 1 got lock t2 thread 3 running parent releasing the t1 lock! thread 1 got lock t1 thread 3 got lock t2 thread 2 got lock t1 This shows that P1 got the lock and was able to run to release lock 2 so that the P3 can run, as expected. The patch simply changes pi_setprio to modify the pi_list in all cases. -- Steve Signed-off-by: Steven Rostedt Index: linux_realtime_goliath/kernel/rt.c =================================================================== --- linux_realtime_goliath/kernel/rt.c (revision 317) +++ linux_realtime_goliath/kernel/rt.c (working copy) @@ -857,31 +857,30 @@ __raw_spin_lock(&l->wait_lock); TRACE_BUG_ON_LOCKED(!lock_owner(l)); - if ((ALL_TASKS_PI || rt_task(p)) && plist_empty(&w->pi_list)) { - TRACE_BUG_ON_LOCKED(was_rt); - plist_init(&w->pi_list, prio); - plist_add(&w->pi_list, &lock_owner(l)->task->pi_waiters); - plist_del(&w->list, &l->wait_list); - plist_init(&w->list, prio); - plist_add(&w->list, &l->wait_list); - } - /* - * If the task is blocked on a lock, and we just restored - * it from RT to non-RT then unregister the task from - * the PI list and requeue it to the wait list. - * - * (TODO: this can be unfair to SCHED_NORMAL tasks if they - * get PI handled.) - */ - if (!ALL_TASKS_PI && !rt_task(p) && !plist_empty(&w->pi_list)) { - TRACE_BUG_ON_LOCKED(!was_rt); + if (!plist_empty(&w->pi_list)) { + TRACE_BUG_ON_LOCKED(!was_rt && !ALL_TASKS_PI && !rt_task(p)); + /* + * If the task is blocked on a lock, and we just restored + * it from RT to non-RT then unregister the task from + * the PI list and requeue it to the wait list. + * + * (TODO: this can be unfair to SCHED_NORMAL tasks if they + * get PI handled.) + */ plist_del(&w->pi_list, &lock_owner(l)->task->pi_waiters); - plist_del(&w->list, &l->wait_list); - plist_init(&w->list, prio); - plist_add(&w->list, &l->wait_list); + } else + TRACE_BUG_ON_LOCKED((ALL_TASKS_PI || rt_task(p)) && was_rt); + + if (ALL_TASKS_PI || rt_task(p)) { + plist_init(&w->pi_list,prio); + plist_add(&w->pi_list, &lock_owner(l)->task->pi_waiters); } + plist_del(&w->list, &l->wait_list); + plist_init(&w->list, prio); + plist_add(&w->list, &l->wait_list); + pi_walk++; if (p != task)