Skip to content

Commit

Permalink
ANDROID: sched/walt: Fix the potential bad unlock issue
Browse files Browse the repository at this point in the history
commit bfc5259 ("ANDROID: sched/walt: Fix lockdep assert issue")
introduce a potential bad unlock balance in move_queued_task() when
this_cpu == new_cpu.

Use double_rq_unlock() to avoid the potential bad unlock issue, which
can safely unlock two runqueues.

The following warning message occurs and lockup triggered afterwards:

[ 5862.217255] c1 WARNING: bad unlock balance detected!
[ 5862.217259] c1 4.14.78+ #22 Tainted: G S      W  O
[ 5862.217260] c1 -------------------------------------
[ 5862.217263] c1 migration/1/16 is trying to release lock (&rq->lock) at:
[ 5862.217278] c1 [<ffffff80080e2f14>] __migrate_task+0xbc/0xc8
[ 5862.217280] c1 but there are no more locks to release!
[ 5862.217281] c1
[ 5862.217281] c1 other info that might help us debug this:
[ 5862.217284] c1 1 lock held by migration/1/16:
[ 5862.217285] c1  #0: (&p->pi_lock){-.-.}, at: [<ffffff80080e38c4>] migration_cpu_stop+0x58/0x12c
[ 5862.217296] c1
[ 5862.217296] c1 stack backtrace:
[ 5862.217300] c1 CPU: 1 PID: 16 Comm: migration/1 Tainted: G S W  O    4.14.78+ #22
...
[ 5862.217304] c1 Call trace:
[ 5862.217310] c1 [<ffffff800808b07c>] dump_backtrace+0x0/0x24c
[ 5862.217313] c1 [<ffffff800808b2e8>] show_stack+0x20/0x28
[ 5862.217319] c1 [<ffffff8008a931b4>] dump_stack+0xa4/0xdc
[ 5862.217324] c1 [<ffffff80081181f8>] print_unlock_imbalance_bug+0xd0/0xe4
[ 5862.217327] c1 [<ffffff800811bae0>] lock_set_class+0xcc/0x1c8
[ 5862.217331] c1 [<ffffff80080e2adc>] move_queued_task+0x1cc/0x2e8
[ 5862.217334] c1 [<ffffff80080e2f14>] __migrate_task+0xbc/0xc8
[ 5862.217337] c1 [<ffffff80080e3924>] migration_cpu_stop+0xb8/0x12c
[ 5862.217342] c1 [<ffffff800817e294>] cpu_stopper_thread+0xb0/0x118
[ 5862.217346] c1 [<ffffff80080d9bc8>] smpboot_thread_fn+0x214/0x258
[ 5862.217351] c1 [<ffffff80080d5408>] kthread+0x128/0x130
[ 5862.217354] c1 [<ffffff8008084978>] ret_from_fork+0x10/0x18
...
[ 5880.200679] c0 Kernel panic - not syncing: Watchdog detected hard LOCKUP on cpu 1

Bug: 120440300
Signed-off-by: Ke Wang <[email protected]>
  • Loading branch information
Ke Wang authored and toddkjos committed Feb 25, 2019
1 parent 07d1bac commit 6fd50f7
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,17 +950,14 @@ static inline bool is_cpu_allowed(struct task_struct *p, int cpu)
static struct rq *move_queued_task(struct rq *rq, struct rq_flags *rf,
struct task_struct *p, int new_cpu)
{
struct rq *new_rq = cpu_rq(new_cpu);

lockdep_assert_held(&rq->lock);

p->on_rq = TASK_ON_RQ_MIGRATING;
dequeue_task(rq, p, DEQUEUE_NOCLOCK);
rq_unpin_lock(rq, rf);
double_lock_balance(rq, new_rq);
double_lock_balance(rq, cpu_rq(new_cpu));
set_task_cpu(p, new_cpu);
double_unlock_balance(rq, new_rq);
raw_spin_unlock(&rq->lock);
double_rq_unlock(cpu_rq(new_cpu), rq);

rq = cpu_rq(new_cpu);

Expand Down

0 comments on commit 6fd50f7

Please sign in to comment.