diff options
author | Alex Elder <elder@linaro.org> | 2020-02-28 12:33:56 -0600 |
---|---|---|
committer | Bjorn Andersson <bjorn.andersson@linaro.org> | 2020-03-25 22:29:43 -0700 |
commit | 0b145574b6cd2b326d53fd2cf8054ffd4ad6103f (patch) | |
tree | ee31bac9a9e91b541aac48e1b590167390e2cc19 /drivers/remoteproc/remoteproc_core.c | |
parent | b1f0fa8659f333700b0ca8df7b2e33dc5d554178 (diff) | |
download | linux-0b145574b6cd2b326d53fd2cf8054ffd4ad6103f.tar.gz linux-0b145574b6cd2b326d53fd2cf8054ffd4ad6103f.tar.bz2 linux-0b145574b6cd2b326d53fd2cf8054ffd4ad6103f.zip |
remoteproc: re-check state in rproc_trigger_recovery()
Two places call rproc_trigger_recovery():
- rproc_crash_handler_work() sets rproc->state to CRASHED under
protection of the mutex, then calls it if recovery is not
disabled. This function is called in workqueue context when
scheduled in rproc_report_crash().
- rproc_recovery_write() calls it in two spots, both of which
the only call it if the rproc->state is CRASHED.
The mutex is taken right away in rproc_trigger_recovery(). However,
by the time the mutex is acquired, something else might have changed
rproc->state to something other than CRASHED.
The work that follows that is only appropriate for a remoteproc in
CRASHED state. So check the state after acquiring the mutex, and
only proceed with the recovery work if the remoteproc is still in
CRASHED state.
Delay reporting that recovering has begun until after we hold the
mutex and we know the remote processor is in CRASHED state.
Signed-off-by: Alex Elder <elder@linaro.org>
Link: https://lore.kernel.org/r/20200228183359.16229-2-elder@linaro.org
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Diffstat (limited to 'drivers/remoteproc/remoteproc_core.c')
-rw-r--r-- | drivers/remoteproc/remoteproc_core.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 0a9bb745bd0d..a9ac1d01e09b 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1662,12 +1662,16 @@ int rproc_trigger_recovery(struct rproc *rproc) struct device *dev = &rproc->dev; int ret; - dev_err(dev, "recovering %s\n", rproc->name); - ret = mutex_lock_interruptible(&rproc->lock); if (ret) return ret; + /* State could have changed before we got the mutex */ + if (rproc->state != RPROC_CRASHED) + goto unlock_mutex; + + dev_err(dev, "recovering %s\n", rproc->name); + ret = rproc_stop(rproc, true); if (ret) goto unlock_mutex; |