Skip to contentSkip to conversation

remoteproc: qcom: pas: Request stop before tearing down GLINK and SMD

PATCH New Jure Rebernik 1 participant 1 message Nov 26

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 remoteproc: qcom: pas: Request stop before tearing down GLINK and SMD

On QCS8550, a crash of the ADSP that the host reports, for example through the remoteproc debugfs crash file, can reset the whole SoC instead of restarting the ADSP. On two QCS8550-based boards, crashing the ADSP about 4.5 seconds after it had started reset the SoC in 19 of 42 tries. The system stopped right after the recovery started, nothing more was logged, and the SoC was reset 6 to 7 seconds later.

Since commit 0ea50486978f ("remoteproc: qcom: q6v5: Request shutdown if crash is triggered host-side"), qcom_q6v5_request_stop() sets the SMP2P stop bit also for a crash that the host reports. It is called from qcom_pas_stop(), which runs after rproc_stop() has stopped all subdevices, so the GLINK and SMD edges to the DSP are already gone. The QCS8550 ADSP firmware treats the stop bit as a fatal error and runs its error handler without those links.

Request the stop from a new subdevice that is added before sysmon, so that it stops after sysmon and before SMD and GLINK. The firmware then handles the stop request while its edges are still registered. Crashes that the firmware reports and graceful stops that sysmon completed are not affected, as qcom_q6v5_request_stop() still skips the request for them. The call in qcom_pas_stop() stays for a stop without subdevices.

With this change, none of 104 host-reported crashes on the same boards reset the SoC, 24 of them CDSP crashes.

The problem was found and this change was written with the help of an AI coding assistant. The change was tested on QCS8550 hardware, and I reviewed it and the test results.

Fixes 0ea50486978f ("remoteproc: qcom: q6v5: Request shutdown if crash is triggered host-side")

---

Notes:
Changes in v2:
- Shorten the changelog and move the test details and the tool-use note below the --- (Val Packett).
- Rebase on rproc-next f39ba58941ef. No code changes.

v1: https://lore.kernel.org/r/[email protected]

Testing: Luxonis OAK4-S boards (QCS8550) with a kernel based on v7.2.6, which has 0ea50486978f as stable commit 0dc9e289bbb5. Crashes were triggered through the debugfs crash file. Without this patch, 19 of 42 ADSP crashes 4.5 s after start reset the SoC. With it, none of 104 did:
40 ADSP crashes at 4.5 s, 20 at 4 to 15 s, 20 while the ADSP was streaming IMU sensor data, and 24 CDSP crashes. A crash that the firmware reports could not be injected.

On v1, Val noted that a subdevice for the stop reads a bit oddly. The alternative is a hook in the remoteproc core that runs before rproc_stop() stops the subdevices. That changes the core for every driver, so I kept the change in the PAS driver, but I'm happy to rework it if you prefer the core hook.

qcom_q6v5_adsp and qcom_q6v5_mss also call qcom_q6v5_request_stop() from their .stop callbacks, after the subdevices have stopped, and qcom_q6v5_wcss does when requires_force_stop is set. I have no hardware for them and left them unchanged.

Built for arm64 (defconfig, drivers/remoteproc/, W=1) on rproc-next f39ba58941ef, without warnings. Not done: sparse and runtime tests with lockdep and the other debug options.

Tool use: Claude Code (Anthropic) ran the investigation and the tests on our boards, found the ordering problem, and wrote the code and the changelog. Its first fix skipped the stop request for a crashed DSP; I asked for the request to be sent before the teardown instead, which is this patch. I reviewed the code and the results.

 drivers/remoteproc/qcom_q6v5_pas.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/remoteproc/qcom_q6v5_pas.c +20 -0
index 57a111a0d7..ddbffe45d9 100644
@@ -138,6 +138,7 @@ struct qcom_pas {
 	struct qcom_rproc_glink glink_subdev;
 	struct qcom_rproc_subdev smd_subdev;
 	struct qcom_rproc_pdm pdm_subdev;
+	struct rproc_subdev stop_subdev;
 	struct qcom_rproc_ssr ssr_subdev;
 	struct qcom_sysmon *sysmon;
 	struct platform_device *bam_dmux;
@@ -429,6 +430,14 @@ static void qcom_pas_handover(struct qcom_q6v5 *q6v5)
 	qcom_pas_pds_disable(pas, pas->proxy_pds, pas->proxy_pd_count);
 }
 
+static void qcom_pas_stop_subdev(struct rproc_subdev *subdev, bool crashed)
+{
+	struct qcom_pas *pas = container_of(subdev, struct qcom_pas, stop_subdev);
+
+	if (qcom_q6v5_request_stop(&pas->q6v5, pas->sysmon) == -ETIMEDOUT)
+		dev_err(pas->dev, "timed out on wait\n");
+}
+
 static int qcom_pas_stop(struct rproc *rproc)
 {
 	struct qcom_pas *pas = rproc->priv;
@@ -1012,6 +1021,15 @@ static int qcom_pas_probe(struct platform_device *pdev)
 	qcom_add_glink_subdev(rproc, &pas->glink_subdev, desc->ssr_name);
 	qcom_add_smd_subdev(rproc, &pas->smd_subdev);
 	qcom_add_pdm_subdev(rproc, &pas->pdm_subdev);
+
+	/*
+	 * Subdevices stop in the reverse order of addition. Request the stop
+	 * after sysmon has asked for a graceful shutdown and before smd and
+	 * glink are torn down.
+	 */
+	pas->stop_subdev.stop = qcom_pas_stop_subdev;
+	rproc_add_subdev(rproc, &pas->stop_subdev);
+
 	pas->sysmon = qcom_add_sysmon_subdev(rproc, desc->sysmon_name, desc->ssctl_id);
 	if (IS_ERR(pas->sysmon)) {
 		ret = PTR_ERR(pas->sysmon);
@@ -1049,6 +1067,7 @@ static int qcom_pas_probe(struct platform_device *pdev)
 	qcom_remove_ssr_subdev(rproc, &pas->ssr_subdev);
 	qcom_remove_sysmon_subdev(pas->sysmon);
 deinit_remove_pdm_smd_glink:
+	rproc_remove_subdev(rproc, &pas->stop_subdev);
 	qcom_remove_pdm_subdev(rproc, &pas->pdm_subdev);
 	qcom_remove_smd_subdev(rproc, &pas->smd_subdev);
 	qcom_remove_glink_subdev(rproc, &pas->glink_subdev);
@@ -1081,6 +1100,7 @@ static void qcom_pas_remove(struct platform_device *pdev)
 	qcom_remove_sysmon_subdev(pas->sysmon);
 	qcom_remove_smd_subdev(pas->rproc, &pas->smd_subdev);
 	qcom_remove_pdm_subdev(pas->rproc, &pas->pdm_subdev);
+	rproc_remove_subdev(pas->rproc, &pas->stop_subdev);
 	qcom_remove_ssr_subdev(pas->rproc, &pas->ssr_subdev);
 	qcom_pas_pds_detach(pas, pas->proxy_pds, pas->proxy_pd_count);
 	device_init_wakeup(pas->dev, false);

base-commit: f39ba58941efa63e6c7d10d53d183d6077524bdb

Signature · 1 line
2.56.0