remoteproc: Panic handling
Subsystems (2)
v5 cover remoteproc: Panic handling
Add support for invoking a panic handler in remoteproc drivers, to allow them to invoke e.g. cache flushing on the remote processors in response to a kernel panic - to aid in post mortem debugging of system issues.
Bjorn Andersson (4):
remoteproc: Traverse rproc_list under RCU read lock
remoteproc: Introduce "panic" callback in ops
remoteproc: qcom: q6v5: Add common panic handler
remoteproc: qcom: Introduce panic handler for PAS and ADSP
drivers/remoteproc/qcom_q6v5.c | 20 ++++++++++ drivers/remoteproc/qcom_q6v5.h | 1 + drivers/remoteproc/qcom_q6v5_adsp.c | 8 ++++ drivers/remoteproc/qcom_q6v5_pas.c | 8 ++++ drivers/remoteproc/remoteproc_core.c | 57 +++++++++++++++++++++++++--- include/linux/remoteproc.h | 3 ++ 6 files changed, 92 insertions(+), 5 deletions(-)
Signature · 1 line
2.24.0
PATCH v5 1/4 remoteproc: Traverse rproc_list under RCU read lock
In order to be able to traverse the mostly read-only rproc_list without locking during panic migrate traversal to be done under rcu_read_lock().
Mutual exclusion for modifications of the list continues to be handled by the rproc_list_mutex and a synchronization point is added before releasing objects that are popped from the list.
---
Changes since v4:
- Added rculist include
- Picked up Mathieu's r-b
drivers/remoteproc/remoteproc_core.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/remoteproc/remoteproc_core.c +9 -5
@@ -26,6 +26,7 @@#include <linux/string.h> #include <linux/debugfs.h> #include <linux/devcoredump.h> +#include <linux/rculist.h> #include <linux/remoteproc.h> #include <linux/iommu.h> #include <linux/idr.h>
@@ -1868,8 +1869,8 @@ struct rproc *rproc_get_by_phandle(phandle phandle)if (!np)return NULL ; -mutex_lock (&rproc_list_mutex); -list_for_each_entry (r, &rproc_list, node) { +rcu_read_lock (); +list_for_each_entry_rcu (r, &rproc_list, node) {if (r->dev.parent && r->dev.parent->of_node == np) {/* prevent underlying implementation from being removed */ if (!try_module_get (r->dev.parent->driver->owner)) {
@@ -1882,7 +1883,7 @@ struct rproc *rproc_get_by_phandle(phandle phandle)break ; } } -mutex_unlock (&rproc_list_mutex); +rcu_read_unlock ();of_node_put (np);
@@ -1939,7 +1940,7 @@ int rproc_add(struct rproc *rproc)/* expose to rproc_get_by_phandle users */ mutex_lock (&rproc_list_mutex); -list_add (&rproc->node, &rproc_list); +list_add_rcu (&rproc->node, &rproc_list);mutex_unlock (&rproc_list_mutex);return 0 ;
@@ -2156,9 +2157,12 @@ int rproc_del(struct rproc *rproc)/* the rproc is downref'ed as soon as it's removed from the klist */ mutex_lock (&rproc_list_mutex); -list_del (&rproc->node); +list_del_rcu (&rproc->node);mutex_unlock (&rproc_list_mutex); +/* Ensure that no readers of rproc_list are still active */ +synchronize_rcu (); +device_del (&rproc->dev);return 0 ;
Signature · 1 line
2.24.0
PATCH v5 2/4 remoteproc: Introduce "panic" callback in ops
In reply to Bjorn AnderssonIntroduce generic support for handling kernel panics in remoteproc drivers, in order to allow operations needed for aiding in post mortem system debugging, such as flushing caches etc.
The function can return a number of milliseconds needed by the remote to "settle" and the core will wait the longest returned duration before returning from the panic handler.
---
Changes since v4:
- Reworded comment about delay
- Picked up Mathieu's r-b
drivers/remoteproc/remoteproc_core.c | 43 ++++++++++++++++++++++++++++ include/linux/remoteproc.h | 3 ++ 2 files changed, 46 insertions(+)
drivers/remoteproc/remoteproc_core.c +43 -0
@@ -16,6 +16,7 @@#define pr_fmt (fmt) "%s: " fmt, __func__ +#include <linux/delay.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/device.h>
@@ -45,6 +46,7 @@static DEFINE_MUTEX (rproc_list_mutex);static LIST_HEAD (rproc_list); +static struct notifier_block rproc_panic_nb;typedef int (*rproc_handle_resource_t )(struct rproc *rproc,void *,int offset,int avail);
@@ -2236,10 +2238,50 @@ void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type) }EXPORT_SYMBOL (rproc_report_crash); +static int rproc_panic_handler (struct notifier_block *nb,unsigned long event, +void *ptr) +{ +unsigned int longest =0 ; +struct rproc *rproc; +unsigned int d; + +rcu_read_lock (); +list_for_each_entry_rcu (rproc, &rproc_list, node) { +if (!rproc->ops->panic || rproc->state !=RPROC_RUNNING ) +continue ; + + d = rproc->ops->panic (rproc); + longest =max (longest, d); + } +rcu_read_unlock (); + +/* +* Delay for the longest requested duration before returning. This can +* be used by the remoteproc drivers to give the remote processor time +* to perform any requested operations (such as flush caches), when +* it's not possible to signal the Linux side due to the panic. +*/ +mdelay (longest); + +return NOTIFY_DONE ; +} + +static void __init rproc_init_panic (void ) +{ + rproc_panic_nb.notifier_call = rproc_panic_handler; +atomic_notifier_chain_register (&panic_notifier_list, &rproc_panic_nb); +} + +static void __exit rproc_exit_panic(void) +{ +atomic_notifier_chain_unregister (&panic_notifier_list, &rproc_panic_nb); +} +static int __init remoteproc_init (void ) {rproc_init_sysfs ();rproc_init_debugfs (); +rproc_init_panic ();return 0 ; }
@@ -2249,6 +2291,7 @@ static void __exit remoteproc_exit(void) {ida_destroy (&rproc_dev_index); +rproc_exit_panic ();rproc_exit_debugfs ();rproc_exit_sysfs (); }
include/linux/remoteproc.h +3 -0
@@ -369,6 +369,8 @@ enum rsc_handling_status {* expects to find it * @sanity_check: sanity check the fw image * @get_boot_addr: get boot address to entry point specified in firmware +* @panic: optional callback to react to system panic, core will delay +* panic at least the returned number of milliseconds */ struct rproc_ops {int (*start)(struct rproc *rproc);
@@ -383,6 +385,7 @@ struct rproc_ops {int (*load)(struct rproc *rproc,const struct firmware *fw);int (*sanity_check)(struct rproc *rproc,const struct firmware *fw);u64 (*get_boot_addr)(struct rproc *rproc,const struct firmware *fw); +unsigned long (*panic)(struct rproc *rproc); };/**
Signature · 1 line
2.24.0
PATCH v5 3/4 remoteproc: qcom: q6v5: Add common panic handler
In reply to Bjorn AnderssonAdd a common panic handler that invokes a stop request and sleep enough to let the remoteproc flush it's caches etc in order to aid post mortem debugging. For now a hard coded 200ms is returned to the remoteproc core, this value is taken from the downstream kernel.
---
Changes since v4:
- Picked up Mathieu's r-b
drivers/remoteproc/qcom_q6v5.c | 20 ++++++++++++++++++++ drivers/remoteproc/qcom_q6v5.h | 1 + 2 files changed, 21 insertions(+)
drivers/remoteproc/qcom_q6v5.c +20 -0
@@ -15,6 +15,8 @@#include <linux/remoteproc.h> #include "qcom_q6v5.h" +#define Q6V5_PANIC_DELAY_MS 200 +/** * qcom_q6v5_prepare() - reinitialize the qcom_q6v5 context before start * @q6v5: reference to qcom_q6v5 context to be reinitialized
@@ -162,6 +164,24 @@ int qcom_q6v5_request_stop(struct qcom_q6v5 *q6v5) }EXPORT_SYMBOL_GPL (qcom_q6v5_request_stop); +/** +* qcom_q6v5_panic() - panic handler to invoke a stop on the remote +* @q6v5: reference to qcom_q6v5 context +* +* Set the stop bit and sleep in order to allow the remote processor to flush +* its caches etc for post mortem debugging. +* +* Return: 200ms +*/ +unsigned long qcom_q6v5_panic (struct qcom_q6v5 *q6v5) +{ +qcom_smem_state_update_bits (q6v5->state, +BIT (q6v5->stop_bit),BIT (q6v5->stop_bit)); + +return Q6V5_PANIC_DELAY_MS ; +} +EXPORT_SYMBOL_GPL (qcom_q6v5_panic); +/** * qcom_q6v5_init() - initializer of the q6v5 common struct * @q6v5: handle to be initialized
drivers/remoteproc/qcom_q6v5.h +1 -0
@@ -42,5 +42,6 @@ int qcom_q6v5_prepare(struct qcom_q6v5 *q6v5);int qcom_q6v5_unprepare (struct qcom_q6v5 *q6v5);int qcom_q6v5_request_stop (struct qcom_q6v5 *q6v5);int qcom_q6v5_wait_for_start (struct qcom_q6v5 *q6v5,int timeout); +unsigned long qcom_q6v5_panic (struct qcom_q6v5 *q6v5);#endif
Signature · 1 line
2.24.0
PATCH v5 4/4 remoteproc: qcom: Introduce panic handler for PAS and ADSP
In reply to Bjorn AnderssonMake the PAS and ADSP/CDSP remoteproc drivers implement the panic handler that will invoke a stop to prepare the remoteprocs for post mortem debugging.
---
Changes since v4:
- Picked up Mathieu's r-b
drivers/remoteproc/qcom_q6v5_adsp.c | 8 ++++++++ drivers/remoteproc/qcom_q6v5_pas.c | 8 ++++++++ 2 files changed, 16 insertions(+)
drivers/remoteproc/qcom_q6v5_adsp.c +8 -0
@@ -282,12 +282,20 @@ static void *adsp_da_to_va(struct rproc *rproc, u64 da, size_t len)return adsp->mem_region + offset; } +static unsigned long adsp_panic (struct rproc *rproc) +{ +struct qcom_adsp *adsp = rproc->priv; + +return qcom_q6v5_panic (&adsp->q6v5); +} +static const struct rproc_ops adsp_ops = { .start = adsp_start, .stop = adsp_stop, .da_to_va = adsp_da_to_va, .parse_fw = qcom_register_dump_segments, .load = adsp_load, + .panic = adsp_panic, };static int adsp_init_clock (struct qcom_adsp *adsp,const char **clk_ids)
drivers/remoteproc/qcom_q6v5_pas.c +8 -0
@@ -234,12 +234,20 @@ static void *adsp_da_to_va(struct rproc *rproc, u64 da, size_t len)return adsp->mem_region + offset; } +static unsigned long adsp_panic (struct rproc *rproc) +{ +struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; + +return qcom_q6v5_panic (&adsp->q6v5); +} +static const struct rproc_ops adsp_ops = { .start = adsp_start, .stop = adsp_stop, .da_to_va = adsp_da_to_va, .parse_fw = qcom_register_dump_segments, .load = adsp_load, + .panic = adsp_panic, };static int adsp_init_clock (struct qcom_adsp *adsp)
Signature · 1 line
2.24.0
This series was applied to andersson/remoteproc.git (refs/heads/for-next).
Hello:
This series was applied to andersson/remoteproc.git (refs/heads/for-next).
Quoted 11 lines · On Mon, 23 Mar 2020 22:29:00 -0700 you wrote:
Add support for invoking a panic handler in remoteproc drivers, to allow them to invoke e.g. cache flushing on the remote processors in response to a kernel panic - to aid in post mortem debugging of system issues.
Bjorn Andersson (4):
remoteproc: Traverserproc_listunder RCU read lock
remoteproc: Introduce "panic" callback in ops
remoteproc: qcom: q6v5: Add common panic handler
remoteproc: qcom: Introduce panic handler for PAS and ADSP[...]
Here is a summary with links:
- [v5,1/4] remoteproc: Traverse rproc_list under RCU read lock
https://git.kernel.org/andersson/remoteproc/c/c0abe2ca3605e4c4fb25bf69d0218c63baf71d2b - [v5,2/4] remoteproc: Introduce "panic" callback in ops https://git.kernel.org/andersson/remoteproc/c/dc5192c449368eed3385f4405670aa3ed21d6270 - [v5,3/4] remoteproc: qcom: q6v5: Add common panic handler https://git.kernel.org/andersson/remoteproc/c/e9142f5c28e997ab45fac23bc27a3bc01725bb49 - [v5,4/4] remoteproc: qcom: Introduce panic handler for PAS and ADSP https://git.kernel.org/andersson/remoteproc/c/717c21bad161dd7127f6e6acf86a3571e1102254
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.wiki.kernel.org/userdoc/pwbot