Re: [PATCH] sched/deadline/rtmutex: Fix a PI crash for deadline tasks

From: Peter Zijlstra
Date: Fri Apr 01 2016 - 07:38:38 EST


On Fri, Apr 01, 2016 at 07:00:18PM +0800, Xunlei Pang wrote:
> I found a kernel crash while playing with deadline PI rtmutex.
>
> BUG: unable to handle kernel NULL pointer dereference at 0000000000000018
> IP: [<ffffffff810eeb8f>] rt_mutex_get_top_task+0x1f/0x30
> PGD 232a75067 PUD 230947067 PMD 0
> Oops: 0000 [#1] SMP
> CPU: 1 PID: 10994 Comm: a.out Not tainted
>
> Call Trace:
> [<ffffffff810cf8aa>] ? enqueue_task_dl+0x2a/0x320
> [<ffffffff810b658c>] enqueue_task+0x2c/0x80
> [<ffffffff810ba763>] activate_task+0x23/0x30
> [<ffffffff810d0ab5>] pull_dl_task+0x1d5/0x260
> [<ffffffff810d0be6>] pre_schedule_dl+0x16/0x20
> [<ffffffff8164e783>] __schedule+0xd3/0x900
> [<ffffffff8164efd9>] schedule+0x29/0x70
> [<ffffffff8165035b>] __rt_mutex_slowlock+0x4b/0xc0
> [<ffffffff81650501>] rt_mutex_slowlock+0xd1/0x190
> [<ffffffff810eeb33>] rt_mutex_timed_lock+0x53/0x60
> [<ffffffff810ecbfc>] futex_lock_pi.isra.18+0x28c/0x390
> [<ffffffff810cfa15>] ? enqueue_task_dl+0x195/0x320
> [<ffffffff810d0bac>] ? prio_changed_dl+0x6c/0x90
> [<ffffffff810ed8b0>] do_futex+0x190/0x5b0
> [<ffffffff810edd50>] SyS_futex+0x80/0x180
> [<ffffffff8165a089>] system_call_fastpath+0x16/0x1b
> RIP [<ffffffff810eeb8f>] rt_mutex_get_top_task+0x1f/0x30
>
> This is because rt_mutex_enqueue_pi() and rt_mutex_dequeue_pi()
> are only protected by pi_lock when operating pi waiters, while
> rt_mutex_get_top_task() will access them with rq lock held but
> not holding pi_lock.
>
> It's hard for rt_mutex_get_top_task() to hold pi_lock, so the
> patch ensures rt_mutex_enqueue_pi() and rt_mutex_dequeue_pi()
> lock rq when operating "pi_waiters" and "pi_waiters_leftmost".
> We need this iff lock owner has the deadline priority.

How is this deadline specific, those functions you modify are
deadline/rt agnostic.