remoteproc: core: full attach detach during recovery
RFC PATCH 1/1 remoteproc: core: full attach detach during recovery
Current recovery operation does only virtio device reset, but do not free and re-allocate all the resources. As third-party is booting the remote processor during attach-detach, it is better to free and re-allocate resoruces as resource table state might be unknown to linux when remote processor boots and reports crash.
---
Note: RFC patch for design discussion. Please do not merge.
drivers/remoteproc/remoteproc_core.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +14 -1
@@ -1786,7 +1786,20 @@ static int rproc_attach_recovery(struct rproc *rproc)if (ret)return ret; -return __rproc_attach (rproc); +/* clean up all acquired resources */ +rproc_resource_cleanup (rproc); + +/* release HW resources if needed */ +rproc_unprepare_device (rproc); + +rproc_disable_iommu (rproc); + +/* Free the copy of the resource table */ +kfree (rproc->cached_table); + rproc->cached_table =NULL ; + rproc->table_ptr =NULL ; + +return rproc_attach (rproc); }static int rproc_boot_recovery (struct rproc *rproc)
base-commit: 56d030ea3330ab737fe6c05f89d52f56208b07ac
Signature · 1 line
2.34.1
Mathieu Poirier
maintainerGood morning,
Quoted 5 lines · Tanmay Shah
Current recovery operation does only virtio device reset, but do not free and re-allocate all the resources. As third-party is booting the remote processor during attach-detach, it is better to free and re-allocate resoruces as resource table state might be unknown to linux when remote processor boots and reports crash.
1) When referring to "third-party", should I assume boot loader?
2) Function rproc_attach_recovery() calls __rproc_detach(), which in turn calls rproc_reset_rsc_table_on_detach(). That function deals explicitly with the resource table.
3) The code in this patch mixes __rproc_detach() with rproc_attach(), something that is likely not a good idea. We either do __rproc_detach/__rproc_attach or rproc_detach/rproc_attach but I'd like to avoid the mix-and-match to keep the amount of possible states to a minimum.
If I understand correctly, the main motivation for this patch is the management of the resource table. But as noted in (2), this should be taken care of. Am I missing some information?
Thanks,
Mathieu
Quoted 40 lines
Signed-off-by Tanmay Shah <[email protected]>---
Note: RFC patch for design discussion. Please do not merge.
drivers/remoteproc/remoteproc_core.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)drivers/remoteproc/remoteproc_core.c +14
-1@@ -1786,7 +1786,20 @@ static int rproc_attach_recovery(struct rproc *rproc)if (ret)return ret; -return __rproc_attach (rproc); +/* clean up all acquired resources */ +rproc_resource_cleanup (rproc); + +/* release HW resources if needed */ +rproc_unprepare_device (rproc); + +rproc_disable_iommu (rproc); + +/* Free the copy of the resource table */ +kfree (rproc->cached_table); + rproc->cached_table =NULL ; + rproc->table_ptr =NULL ; + +return rproc_attach (rproc); }static int rproc_boot_recovery (struct rproc *rproc)base-commit:
56d030ea3330ab737fe6c05f89d52f56208b07acSignature · 1 line
2.34.1
Hello,
Please find my comments below:
Quoted 10 lines · Mathieu Poirier
Good morning,
Quoted 5 lines · Tanmay Shah
Current recovery operation does only virtio device reset, but do not free and re-allocate all the resources. As third-party is booting the remote processor during attach-detach, it is better to free and re-allocate resoruces as resource table state might be unknown to linux when remote processor boots and reports crash.
1) When referring to "third-party", should I assume boot loader?
Here, "third-party" could be a bootloader or another core in a heterogeneous system. In my-case it is a platform management controller.
Quoted 3 lines
2) Function
rproc_attach_recovery()calls__rproc_detach(), which in turn callsrproc_reset_rsc_table_on_detach(). That function deals explicitly with the resource table.
As per my understanding, rproc_reset_rsc_table_on_detach() will setup clean resource table, that sets vring addresses to 0xffffffff. Please let me know if this understanding is not correct.
If we do not, call rproc_attach(), then correct vring addresses are not setup in the resource table for next attach to work. Because, rproc_handle_resources() and rproc_alloc_registered_carveouts() are not called as part __rproc_attach().
Quoted 5 lines
3) The code in this patch mixes
__rproc_detach()withrproc_attach(), something that is likely not a good idea. We either do __rproc_detach/__rproc_attach or rproc_detach/rproc_attach but I'd like to avoid the mix-and-match to keep the amount of possible states to a minimum.
I agree to this. I can find a way to call rproc_detach() and rproc_attach() sequentially, instead of __rproc_detach() and rproc_attach() calls. I might have to remove rproc_trigger_attach_recovery completely, but that is implementation details. We can work it out later, once we agree to the current problem & solution.
Quoted 4 lines
If I understand correctly, the main motivation for this patch is the management of the resource table. But as noted in (2), this should be taken care of. Am I missing some information?
The main motivation is to make the attach operation works during attach_recovery(). The __rproc_detach() works as expected, but attach doesn't work. After recovery, I am not able to strat RPMsg communication.
Please let me know if I am missing something.
Thanks,
Tanmay
Quoted 43 lines
Thanks,
MathieuQuoted 40 lines
Signed-off-by Tanmay Shah <[email protected]>---
Note: RFC patch for design discussion. Please do not merge.
drivers/remoteproc/remoteproc_core.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)drivers/remoteproc/remoteproc_core.c +14
-1@@ -1786,7 +1786,20 @@ static int rproc_attach_recovery(struct rproc *rproc)if (ret)return ret; -return __rproc_attach (rproc); +/* clean up all acquired resources */ +rproc_resource_cleanup (rproc); + +/* release HW resources if needed */ +rproc_unprepare_device (rproc); + +rproc_disable_iommu (rproc); + +/* Free the copy of the resource table */ +kfree (rproc->cached_table); + rproc->cached_table =NULL ; + rproc->table_ptr =NULL ; + +return rproc_attach (rproc); }static int rproc_boot_recovery (struct rproc *rproc)base-commit:
56d030ea3330ab737fe6c05f89d52f56208b07acSignature · 1 line
2.34.1
Mathieu Poirier
maintainerQuoted 15 lines · Tanmay Shah
Hello,
Please find my comments below:
Quoted 9 lines · Mathieu Poirier
Good morning,
Quoted 5 lines · Tanmay Shah
Current recovery operation does only virtio device reset, but do not free and re-allocate all the resources. As third-party is booting the remote processor during attach-detach, it is better to free and re-allocate resoruces as resource table state might be unknown to linux when remote processor boots and reports crash.
Quoted 4 lines
Quoted 1 line
1) When referring to "third-party", should I assume boot loader?
Here, "third-party" could be a bootloader or another core in a heterogeneous system. In my-case it is a platform management controller.
Ok
Quoted 6 lines
Quoted 5 lines
2) Function
rproc_attach_recovery()calls__rproc_detach(), which in turn callsrproc_reset_rsc_table_on_detach(). That function deals explicitly with the resource table.
Quoted 8 lines
As per my understanding,
rproc_reset_rsc_table_on_detach()will setup clean resource table, that sets vring addresses to0xffffffff. Please let me know if this understanding is not correct.If we do not, call
rproc_attach(), then correct vring addresses are not setup in the resource table for next attach to work. Because,rproc_handle_resources()andrproc_alloc_registered_carveouts()are not called as part__rproc_attach().
Your assessment is correct. When the clean_table was introduced, it was to address the detach->attach scenario. At that time the only recovery we supported was to stop and start again, which did not involved the clean_table. Re-attaching on crash was introduced later in a scenario that may not have included a resource table.
Quoted 7 lines
Quoted 6 lines
3) The code in this patch mixes
__rproc_detach()withrproc_attach(), something that is likely not a good idea. We either do __rproc_detach/__rproc_attach or rproc_detach/rproc_attach but I'd like to avoid the mix-and-match to keep the amount of possible states to a minimum.
Quoted 6 lines
I agree to this. I can find a way to call
rproc_detach()andrproc_attach()sequentially, instead of__rproc_detach()andrproc_attach()calls. I might have to removerproc_trigger_attach_recoverycompletely, but that is implementation details. We can work it out later, once we agree to the current problem & solution.
Humm... You might just be able to call rproc_detach/rproc_attach from rproc_attach_recovery() if you enhance rproc_detach to be called in a CRASHED context [1]. Let's see what you find when trying this on real HW.
[1]. https://elixir.bootlin.com/linux/v6.17.1/source/drivers/remoteproc/remoteproc_core.c#L2065
Quoted 56 lines
Quoted 4 lines
If I understand correctly, the main motivation for this patch is the management of the resource table. But as noted in (2), this should be taken care of. Am I missing some information?
The main motivation is to make the attach operation works during
attach_recovery(). The__rproc_detach()works as expected, but attach doesn't work. After recovery, I am not able to strat RPMsg communication.Please let me know if I am missing something.
Thanks,
TanmayQuoted 41 lines
Thanks,
MathieuQuoted 38 lines
Signed-off-by Tanmay Shah <[email protected]>---
Note: RFC patch for design discussion. Please do not merge.
drivers/remoteproc/remoteproc_core.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)drivers/remoteproc/remoteproc_core.c +14
-1@@ -1786,7 +1786,20 @@ static int rproc_attach_recovery(struct rproc *rproc)if (ret)return ret; -return __rproc_attach (rproc); +/* clean up all acquired resources */ +rproc_resource_cleanup (rproc); + +/* release HW resources if needed */ +rproc_unprepare_device (rproc); + +rproc_disable_iommu (rproc); + +/* Free the copy of the resource table */ +kfree (rproc->cached_table); + rproc->cached_table =NULL ; + rproc->table_ptr =NULL ; + +return rproc_attach (rproc); }static int rproc_boot_recovery (struct rproc *rproc)base-commit:
56d030ea3330ab737fe6c05f89d52f56208b07acSignature · 1 line
2.34.1
Quoted 38 lines · Mathieu Poirier
Quoted 15 lines · Tanmay Shah
Hello,
Please find my comments below:
Quoted 9 lines · Mathieu Poirier
Good morning,
Quoted 5 lines · Tanmay Shah
Current recovery operation does only virtio device reset, but do not free and re-allocate all the resources. As third-party is booting the remote processor during attach-detach, it is better to free and re-allocate resoruces as resource table state might be unknown to linux when remote processor boots and reports crash.
Quoted 4 lines
Quoted 1 line
1) When referring to "third-party", should I assume boot loader?
Here, "third-party" could be a bootloader or another core in a heterogeneous system. In my-case it is a platform management controller.
Ok
Quoted 6 lines
Quoted 5 lines
2) Function
rproc_attach_recovery()calls__rproc_detach(), which in turn callsrproc_reset_rsc_table_on_detach(). That function deals explicitly with the resource table.Quoted 8 lines
As per my understanding,
rproc_reset_rsc_table_on_detach()will setup clean resource table, that sets vring addresses to0xffffffff. Please let me know if this understanding is not correct.If we do not, call
rproc_attach(), then correct vring addresses are not setup in the resource table for next attach to work. Because,rproc_handle_resources()andrproc_alloc_registered_carveouts()are not called as part__rproc_attach().
Quoted 6 lines
Your assessment is correct. When the
clean_tablewas introduced, it was to address thedetach->attachscenario. At that time the only recovery we supported was to stop and start again, which did not involved theclean_table. Re-attaching on crash was introduced later in a scenario that may not have included a resource table.
Okay that explains the current architecture.
Quoted 14 lines
Quoted 7 lines
Quoted 6 lines
3) The code in this patch mixes
__rproc_detach()withrproc_attach(), something that is likely not a good idea. We either do __rproc_detach/__rproc_attach or rproc_detach/rproc_attach but I'd like to avoid the mix-and-match to keep the amount of possible states to a minimum.Quoted 6 lines
I agree to this. I can find a way to call
rproc_detach()andrproc_attach()sequentially, instead of__rproc_detach()andrproc_attach()calls. I might have to removerproc_trigger_attach_recoverycompletely, but that is implementation details. We can work it out later, once we agree to the current problem & solution.
Quoted 7 lines
Humm... You might just be able to call rproc_detach/rproc_attach from
rproc_attach_recovery()if you enhancerproc_detachto be called in a CRASHED context [1]. Let's see what you find when trying this on real HW.[1]. https://elixir.bootlin.com/linux/v6.17.1/source/drivers/remoteproc/remoteproc_core.c#L2065
Thank You for the suggestion. Agreed. Since we are coming to an agreement on the final solution, I will send the actual series which also takes care of start/stop recovery on xlnx platform driver. I will implement above suggestion, and test on HW.
Thanks,
Tanmay
Quoted 56 lines
Quoted 56 lines
Quoted 4 lines
If I understand correctly, the main motivation for this patch is the management of the resource table. But as noted in (2), this should be taken care of. Am I missing some information?
The main motivation is to make the attach operation works during
attach_recovery(). The__rproc_detach()works as expected, but attach doesn't work. After recovery, I am not able to strat RPMsg communication.Please let me know if I am missing something.
Thanks,
TanmayQuoted 41 lines
Thanks,
MathieuQuoted 38 lines
Signed-off-by Tanmay Shah <[email protected]>---
Note: RFC patch for design discussion. Please do not merge.
drivers/remoteproc/remoteproc_core.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)drivers/remoteproc/remoteproc_core.c +14
-1@@ -1786,7 +1786,20 @@ static int rproc_attach_recovery(struct rproc *rproc)if (ret)return ret; -return __rproc_attach (rproc); +/* clean up all acquired resources */ +rproc_resource_cleanup (rproc); + +/* release HW resources if needed */ +rproc_unprepare_device (rproc); + +rproc_disable_iommu (rproc); + +/* Free the copy of the resource table */ +kfree (rproc->cached_table); + rproc->cached_table =NULL ; + rproc->table_ptr =NULL ; + +return rproc_attach (rproc); }static int rproc_boot_recovery (struct rproc *rproc)base-commit:
56d030ea3330ab737fe6c05f89d52f56208b07acSignature · 1 line
2.34.1