remoteproc: virtio: Fix wdg cannot recovery remote processor
PATCH v2 1/1 remoteproc: virtio: Fix wdg cannot recovery remote processor
From: Joakim Zhang <[email protected]>
Recovery remote processor failed when wdg irq received:
[ 0.842574] remoteproc remoteproc0: crash detected in cix-dsp-rproc: type watchdog [ 0.842750] remoteproc remoteproc0: handling crash #1 in cix-dsp-rproc [ 0.842824] remoteproc remoteproc0: recovering cix-dsp-rproc [ 0.843342] remoteproc remoteproc0: stopped remote processor cix-dsp-rproc [ 0.847901] rproc-virtio rproc-virtio.0.auto: Failed to associate buffer [ 0.847979] remoteproc remoteproc0: failed to probe subdevices for cix-dsp-rproc: -16
The reason is that dma coherent mem would not be released when recovering the remote processor, due to rproc_virtio_remove() would not be called, where the mem released. It will fail when it try to allocate and associate buffer again.
We can see that dma coherent mem allocated from rproc_add_virtio_dev(), so should release it from rproc_remove_virtio_dev(). These functions should appear symmetrically:
-rproc_vdev_do_start()->rproc_add_virtio_dev()->dma_declare_coherent_memory() -rproc_vdev_do_stop()->rproc_remove_virtio_dev()->dma_release_coherent_memory()
The same for of_reserved_mem_device_init_by_idx() and of_reserved_mem_device_release().
---
ChangeLogs:V1->V2:
* the same for of_reserved_mem_device_release()
--- drivers/remoteproc/remoteproc_virtio.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/remoteproc/remoteproc_virtio.c +4 -3
@@ -465,8 +465,12 @@ static int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)static int rproc_remove_virtio_dev (struct device *dev,void *data) {struct virtio_device *vdev =dev_to_virtio (dev); +struct rproc_vdev *rvdev =vdev_to_rvdev (vdev);unregister_virtio_device (vdev); +of_reserved_mem_device_release (&rvdev->pdev->dev); +dma_release_coherent_memory (&rvdev->pdev->dev); +return 0 ; }
@@ -584,9 +588,6 @@ static void rproc_virtio_remove(struct platform_device *pdev)rproc_remove_subdev (rproc, &rvdev->subdev);rproc_remove_rvdev (rvdev); -of_reserved_mem_device_release (&pdev->dev); -dma_release_coherent_memory (&pdev->dev); -put_device (&rproc->dev); }
Signature · 1 line
2.25.1
Hello Joakim,
Quoted 38 lines · On 12/15/23 15:50, [email protected] wrote:
From: Joakim Zhang <[email protected]>
Recovery remote processor failed when wdg irq received:
[ 0.842574] remoteproc remoteproc0: crash detected in cix-dsp-rproc: type watchdog [ 0.842750] remoteproc remoteproc0: handling crash #1 in cix-dsp-rproc [ 0.842824] remoteproc remoteproc0: recovering cix-dsp-rproc [ 0.843342] remoteproc remoteproc0: stopped remote processor cix-dsp-rproc [ 0.847901] rproc-virtio rproc-virtio.0.auto: Failed to associate buffer [ 0.847979] remoteproc remoteproc0: failed to probe subdevices for cix-dsp-rproc: -16The reason is that dma coherent mem would not be released when recovering the remote processor, due to
rproc_virtio_remove()would not be called, where the mem released. It will fail when it try to allocate and associate buffer again.We can see that dma coherent mem allocated from
rproc_add_virtio_dev(), so should release it fromrproc_remove_virtio_dev(). These functions should appear symmetrically:(quoted diff) +0
-2-rproc_vdev_do_start()->rproc_add_virtio_dev()->dma_declare_coherent_memory() -rproc_vdev_do_stop()->rproc_remove_virtio_dev()->dma_release_coherent_memory()The same for
of_reserved_mem_device_init_by_idx()andof_reserved_mem_device_release().Fixes 1d7b61c06dc3 ("remoteproc: virtio: Create platform device for the remoteproc_virtio")Signed-off-by Joakim Zhang <[email protected]>---
ChangeLogs:V1->V2:
* the same forof_reserved_mem_device_release()--- drivers/remoteproc/remoteproc_virtio.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/remoteproc/remoteproc_virtio.c +0
-0
drivers/remoteproc/remoteproc_virtio.c static int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id) · line 473
Quoted 9 lines
drivers/remoteproc/remoteproc_virtio.c +4
-0@@ -465,8 +465,12 @@ static int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)static int rproc_remove_virtio_dev (struct device *dev,void *data) {struct virtio_device *vdev =dev_to_virtio (dev); +struct rproc_vdev *rvdev =vdev_to_rvdev (vdev);unregister_virtio_device (vdev); +of_reserved_mem_device_release (&rvdev->pdev->dev); +dma_release_coherent_memory (&rvdev->pdev->dev); +
At this step, the virtio device may not be released and may still be using the memory.
Do you try to move this in rproc_virtio_dev_release?
Regards,
Arnaud
Quoted 19 lines
drivers/remoteproc/remoteproc_virtio.c +0
-4return 0 ; }@@ -584,9 +588,6 @@ static void rproc_virtio_remove(struct platform_device *pdev)rproc_remove_subdev (rproc, &rvdev->subdev);rproc_remove_rvdev (rvdev); -of_reserved_mem_device_release (&pdev->dev); -dma_release_coherent_memory (&pdev->dev); -put_device (&rproc->dev); } --2.25.1
This email (including its attachments) is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. Unauthorized use, dissemination, distribution or copying of this email or the information herein or taking any action in reliance on the contents of this email or the information herein, by anyone other than the intended recipient, or an employee or agent responsible for delivering the message to the intended recipient, is strictly prohibited. If you are not the intended recipient, please do not read, copy, use or disclose any part of this e-mail to others. Please notify the sender immediately and permanently delete this e-mail and any attachments if you received it in error. Internet communications cannot be guaranteed to be timely, secure, error-free or virus-free. The sender does not accept liability for any errors or omissions.
Hello Arnaud,
Quoted 66 lines
-----Original Message-----
From: Arnaud POULIQUEN <[email protected]>
Sent: Saturday, December 16, 2023 12:56 AM
To: Joakim Zhang <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; cix- kernel-upstream <[email protected]>
Subject: Re: [PATCH V2] remoteproc: virtio: Fix wdg cannot recovery remote processorHello Joakim,
Quoted 4 lines · On 12/15/23 15:50, [email protected] wrote:
From: Joakim Zhang <[email protected]>
Recovery remote processor failed when wdg irq received:
[ 0.842574] remoteproc remoteproc0: crash detected in cix-dsp-rproc:type watchdog
Quoted 3 lines
[ 0.842750] remoteproc remoteproc0: handling crash #1 in cix-dsp-rproc [ 0.842824] remoteproc remoteproc0: recovering cix-dsp-rproc [ 0.843342] remoteproc remoteproc0: stopped remote processor cix-dsp-rproc
Quoted 2 lines
[ 0.847901] rproc-virtio rproc-virtio.0.auto: Failed to associate buffer [ 0.847979] remoteproc remoteproc0: failed to probe subdevices for cix-dsp-rproc: -16
Quoted 16 lines
The reason is that dma coherent mem would not be released when recovering the remote processor, due to
rproc_virtio_remove()would not be called, where the mem released. It will fail when it try to allocate and associate buffer again.We can see that dma coherent mem allocated from
rproc_add_virtio_dev(), so should release it fromrproc_remove_virtio_dev(). These functions should appear symmetrically:
-rproc_vdev_do_start()->rproc_add_virtio_dev()-dma_declare_coherent_memory()
-rproc_vdev_do_stop()->rproc_remove_virtio_dev()-dma_release_coherent_memory()Quoted 1 line
The same for
of_reserved_mem_device_init_by_idx()and
of_reserved_mem_device_release().Quoted 23 lines
Fixes 1d7b61c06dc3 ("remoteproc: virtio: Create platform device forthe
remoteproc_virtio")Signed-off-by Joakim Zhang <[email protected]>---
ChangeLogs:V1->V2:
* the same forof_reserved_mem_device_release()--- drivers/remoteproc/remoteproc_virtio.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/remoteproc/remoteproc_virtio.c +1
-0@@ -465,8 +465,12 @@ static int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id) static int rproc_remove_virtio_dev(struct device *dev,void *data) {struct virtio_device *vdev =dev_to_virtio (dev); +struct rproc_vdev *rvdev =vdev_to_rvdev (vdev);
Quoted 8 lines
drivers/remoteproc/remoteproc_virtio.c static int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id) · line 473
Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +3
-0unregister_virtio_device (vdev); +of_reserved_mem_device_release (&rvdev->pdev->dev); +dma_release_coherent_memory (&rvdev->pdev->dev); +At this step, the virtio device may not be released and may still be using the memory.
Do you try to move this inrproc_virtio_dev_release?
Oh, yes, thanks for the hint, I tested, and it can fix the issue, I will send v3 soon.
Joakim
Quoted 19 lines
Regards,
Arnauddrivers/remoteproc/remoteproc_virtio.c static void rproc_virtio_remove(struct
Quoted 4 lines
drivers/remoteproc/remoteproc_virtio.c +0
-0return 0 ; }@@ -584,9 +588,6 @@ static void rproc_virtio_remove(struct
platform_device*pdev)Quoted 11 lines
drivers/remoteproc/remoteproc_virtio.c +0
-4rproc_remove_subdev (rproc, &rvdev->subdev);rproc_remove_rvdev (rvdev); -of_reserved_mem_device_release (&pdev->dev); -dma_release_coherent_memory (&pdev->dev); -put_device (&rproc->dev); } --2.25.1