Skip to content

Commit

Permalink
PM / QoS: Fix workqueue deadlock when using pm_qos_update_request_tim…
Browse files Browse the repository at this point in the history
…eout()

pm_qos_update_request_timeout() updates a qos and then schedules
a delayed work item to bring the qos back down to the default
after the timeout. When the work item runs, pm_qos_work_fn() will
call pm_qos_update_request() and deadlock because it tries to
cancel itself via cancel_delayed_work_sync(). Future callers of
that qos will also hang waiting to cancel the work that is
canceling itself. Let's extract the little bit of code that does
the real work of pm_qos_update_request() and call it from the
work function so that we don't deadlock.

Before ed1ac6e (PM: don't use [delayed_]work_pending()) this didn't
happen because the work function wouldn't try to cancel itself.

Signed-off-by: Stephen Boyd <[email protected]>
Reviewed-by: Tejun Heo <[email protected]>
Cc: 3.9+ <[email protected]> # 3.9+
Signed-off-by: Rafael J. Wysocki <[email protected]>
  • Loading branch information
bebarino authored and rafaeljw committed Aug 13, 2013
1 parent d4e4ab8 commit 40fea92
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions kernel/power/qos.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@ int pm_qos_request_active(struct pm_qos_request *req)
}
EXPORT_SYMBOL_GPL(pm_qos_request_active);

static void __pm_qos_update_request(struct pm_qos_request *req,
s32 new_value)
{
trace_pm_qos_update_request(req->pm_qos_class, new_value);

if (new_value != req->node.prio)
pm_qos_update_target(
pm_qos_array[req->pm_qos_class]->constraints,
&req->node, PM_QOS_UPDATE_REQ, new_value);
}

/**
* pm_qos_work_fn - the timeout handler of pm_qos_update_request_timeout
* @work: work struct for the delayed work (timeout)
Expand All @@ -308,7 +319,7 @@ static void pm_qos_work_fn(struct work_struct *work)
struct pm_qos_request,
work);

pm_qos_update_request(req, PM_QOS_DEFAULT_VALUE);
__pm_qos_update_request(req, PM_QOS_DEFAULT_VALUE);
}

/**
Expand Down Expand Up @@ -364,12 +375,7 @@ void pm_qos_update_request(struct pm_qos_request *req,
}

cancel_delayed_work_sync(&req->work);

trace_pm_qos_update_request(req->pm_qos_class, new_value);
if (new_value != req->node.prio)
pm_qos_update_target(
pm_qos_array[req->pm_qos_class]->constraints,
&req->node, PM_QOS_UPDATE_REQ, new_value);
__pm_qos_update_request(req, new_value);
}
EXPORT_SYMBOL_GPL(pm_qos_update_request);

Expand Down

0 comments on commit 40fea92

Please sign in to comment.