* [PATCH v2 1/4] remoteproc: core: Reset freed vring entries to FW_RSC_ADDR_ANY
2026-11-24 7:14 [PATCH v2 0/4] remoteproc: core: Fix the error unwind paths Yonghao Zhang
@ 2026-11-24 7:14 ` Yonghao Zhang
2026-11-24 7:14 ` [PATCH v2 2/4] remoteproc: core: Guard against a missing stop() in rproc_start() Yonghao Zhang
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Yonghao Zhang @ 2026-11-24 7:14 UTC (permalink / raw)
To: mathieu.poirier, andersson; +Cc: linux-remoteproc, linux-kernel, Yonghao Zhang
rproc_free_vring() resets a vring entry in the resource table as it
releases it. Resetting da to 0 leaves the entry looking like a vring
at device address 0; write FW_RSC_ADDR_ANY instead, the marker for an
unallocated address, which is what the entry means from then on.
The last sentence of the comment above the reset claims that the
cached table is only available for a processor booted by the core.
rproc_reset_rsc_table_on_{stop,detach}() now install a copy of the
table for processors started by another entity, so drop the sentence.
Fixes: c0d631570ad5 ("remoteproc: set vring addresses in resource table")
Fixes: 4d3ebb3b9990 ("remoteproc: Refactor function rproc_free_vring()")
Signed-off-by: Yonghao Zhang <hyz3367@gmail.com>
---
drivers/remoteproc/remoteproc_core.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index d5fa9d23bd5c..b6fe74d34e5c 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -417,16 +417,14 @@ void rproc_free_vring(struct rproc_vring *rvring)
* At this point rproc_stop() has been called and the installed resource
* table in the remote processor memory may no longer be accessible. As
* such and as per rproc_stop(), rproc->table_ptr points to the cached
- * resource table (rproc->cached_table). The cached resource table is
- * only available when a remote processor has been booted by the
- * remoteproc core, otherwise it is NULL.
+ * resource table (rproc->cached_table).
*
* Based on the above, reset the virtio device section in the cached
* resource table only if there is one to work with.
*/
if (rproc->table_ptr) {
rsc = (void *)rproc->table_ptr + rvring->rvdev->rsc_offset;
- rsc->vring[idx].da = 0;
+ rsc->vring[idx].da = FW_RSC_ADDR_ANY;
rsc->vring[idx].notifyid = -1;
}
}
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 2/4] remoteproc: core: Guard against a missing stop() in rproc_start()
2026-11-24 7:14 [PATCH v2 0/4] remoteproc: core: Fix the error unwind paths Yonghao Zhang
2026-11-24 7:14 ` [PATCH v2 1/4] remoteproc: core: Reset freed vring entries to FW_RSC_ADDR_ANY Yonghao Zhang
@ 2026-11-24 7:14 ` Yonghao Zhang
2026-11-24 7:14 ` [PATCH v2 3/4] remoteproc: core: Guard against a missing stop() in the attach unwind Yonghao Zhang
2026-11-24 7:14 ` [PATCH v2 4/4] remoteproc: core: Clean up after a failed recovery Yonghao Zhang
3 siblings, 0 replies; 5+ messages in thread
From: Yonghao Zhang @ 2026-11-24 7:14 UTC (permalink / raw)
To: mathieu.poirier, andersson; +Cc: linux-remoteproc, linux-kernel, Yonghao Zhang
When the subdevice registration fails after a successful ops->start(),
rproc_start() unrolls with an unconditional ops->stop() call: an
implementation without stop() turns that error path into a NULL
dereference, and there is no other way to undo a start once the
processor is up.
Nothing rules that implementation out. rproc_validate() checks the
callbacks against the state a processor registers in: start() for
an offline one, attach() for a detached one, which never look at
stop(); the only written rule, Documentation/staging/remoteproc.rst
("Every remoteproc implementation should at least provide the ->start
and ->stop handlers"), is a should the core does not enforce. The
in-tree implementations all provide both, or neither when they only
attach (commit 1168af40b1ad ("remoteproc: k3-r5: Add support for
IPC-only mode for all R5Fs")), so none of them can reach the call
today.
Skip the rollback call when there is no stop(): with nothing to roll
the start back with, the processor stays running and the failure is
reported by the boot attempt itself.
Fixes: 7bdc9650f036 ("remoteproc: Introduce subdevices")
Signed-off-by: Yonghao Zhang <hyz3367@gmail.com>
---
drivers/remoteproc/remoteproc_core.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index b6fe74d34e5c..e44b45510b4e 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1310,7 +1310,10 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw)
if (ret) {
dev_err(dev, "failed to probe subdevices for %s: %d\n",
rproc->name, ret);
- goto stop_rproc;
+ if (rproc->ops->stop)
+ goto stop_rproc;
+ dev_err(dev, "can't roll %s back: no stop()\n", rproc->name);
+ goto unprepare_subdevices;
}
rproc->state = RPROC_RUNNING;
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 3/4] remoteproc: core: Guard against a missing stop() in the attach unwind
2026-11-24 7:14 [PATCH v2 0/4] remoteproc: core: Fix the error unwind paths Yonghao Zhang
2026-11-24 7:14 ` [PATCH v2 1/4] remoteproc: core: Reset freed vring entries to FW_RSC_ADDR_ANY Yonghao Zhang
2026-11-24 7:14 ` [PATCH v2 2/4] remoteproc: core: Guard against a missing stop() in rproc_start() Yonghao Zhang
@ 2026-11-24 7:14 ` Yonghao Zhang
2026-11-24 7:14 ` [PATCH v2 4/4] remoteproc: core: Clean up after a failed recovery Yonghao Zhang
3 siblings, 0 replies; 5+ messages in thread
From: Yonghao Zhang @ 2026-11-24 7:14 UTC (permalink / raw)
To: mathieu.poirier, andersson; +Cc: linux-remoteproc, linux-kernel, Yonghao Zhang
When the subdevice registration fails after a successful ops->attach(),
__rproc_attach() unrolls with an unconditional ops->stop() call: an
implementation without stop() turns that error path into a NULL
dereference.
An attach-only implementation, such as commit 1168af40b1ad ("remoteproc:
k3-r5: Add support for IPC-only mode for all R5Fs"), has no stop() and
can reach that path. Skip the rollback call when there is no stop():
with nothing to roll the attach back with, the processor stays running
and the failure is reported by the attach attempt itself.
Fixes: d848a4819d85 ("remoteproc: Introducing function rproc_attach()")
Signed-off-by: Yonghao Zhang <hyz3367@gmail.com>
---
drivers/remoteproc/remoteproc_core.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index e44b45510b4e..8c3fc85b8f04 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1357,7 +1357,10 @@ static int __rproc_attach(struct rproc *rproc)
if (ret) {
dev_err(dev, "failed to probe subdevices for %s: %d\n",
rproc->name, ret);
- goto stop_rproc;
+ if (rproc->ops->stop)
+ goto stop_rproc;
+ dev_err(dev, "can't roll %s back: no stop()\n", rproc->name);
+ goto unprepare_subdevices;
}
rproc->state = RPROC_ATTACHED;
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 4/4] remoteproc: core: Clean up after a failed recovery
2026-11-24 7:14 [PATCH v2 0/4] remoteproc: core: Fix the error unwind paths Yonghao Zhang
` (2 preceding siblings ...)
2026-11-24 7:14 ` [PATCH v2 3/4] remoteproc: core: Guard against a missing stop() in the attach unwind Yonghao Zhang
@ 2026-11-24 7:14 ` Yonghao Zhang
3 siblings, 0 replies; 5+ messages in thread
From: Yonghao Zhang @ 2026-11-24 7:14 UTC (permalink / raw)
To: mathieu.poirier, andersson; +Cc: linux-remoteproc, linux-kernel, Yonghao Zhang
Release the resources on the failure paths of rproc_boot_recovery(),
the same way rproc_shutdown() does, and void the power count in
rproc_trigger_recovery() when a failed recovery leaves the processor
offline or detached.
Fixes: ba194232edc0 ("remoteproc: Support attach recovery after rproc crash")
Signed-off-by: Yonghao Zhang <hyz3367@gmail.com>
---
drivers/remoteproc/remoteproc_core.c | 31 +++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 8c3fc85b8f04..3e700c94110d 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1800,7 +1800,7 @@ static int rproc_boot_recovery(struct rproc *rproc)
ret = request_firmware(&firmware_p, rproc->firmware, dev);
if (ret < 0) {
dev_err(dev, "request_firmware failed: %d\n", ret);
- return ret;
+ goto clean_up_resources;
}
/* boot the remote processor up again */
@@ -1808,6 +1808,24 @@ static int rproc_boot_recovery(struct rproc *rproc)
release_firmware(firmware_p);
+ if (ret < 0)
+ goto clean_up_resources;
+
+ return 0;
+
+clean_up_resources:
+ /*
+ * rproc_stop() has already switched the remote processor off;
+ * release the resources of the boot this recovery was trying to
+ * restore.
+ */
+ rproc_resource_cleanup(rproc);
+ /* release HW resources if needed */
+ rproc_unprepare_device(rproc);
+ rproc_disable_iommu(rproc);
+ kfree(rproc->cached_table);
+ rproc->cached_table = NULL;
+ rproc->table_ptr = NULL;
return ret;
}
@@ -1848,6 +1866,17 @@ int rproc_trigger_recovery(struct rproc *rproc)
else
ret = rproc_boot_recovery(rproc);
+ /*
+ * A failed recovery leaves the remote processor offline or
+ * detached, where rproc_shutdown() cannot release the power
+ * references: void them.
+ */
+ if (ret && (rproc->state == RPROC_OFFLINE ||
+ rproc->state == RPROC_DETACHED)) {
+ dev_err(dev, "failed to recover %s: %d\n", rproc->name, ret);
+ atomic_set(&rproc->power, 0);
+ }
+
unlock_mutex:
mutex_unlock(&rproc->lock);
return ret;
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread