rpmsg: virtio_rpmsg_bus: Fix rpmsg_remove() release order
PATCH 1/1 rpmsg: virtio_rpmsg_bus: Fix rpmsg_remove() release order
In rpmsg_remove() procedure, children are removed then Name Service announcement endpoint is destroyed and device released.
Issue with current implementation is if a NS announcement creation request is ongoing (received before virtio reset), child device could be created after children removing. In that case rpmsg_remove() is freeing rpmsg_virtio_bus, leading to an inconsistent state.
This patch is destroying NS announcement service endpoint before removing children to guarantee that list of child devices is fixed and all of them will be correctly removed before cleaning resources.
--- drivers/rpmsg/virtio_rpmsg_bus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/rpmsg/virtio_rpmsg_bus.c +3 -3
@@ -1004,13 +1004,13 @@ static void rpmsg_remove(struct virtio_device *vdev) vdev->config->reset (vdev); +if (vrp->ns_ept) +__rpmsg_destroy_ept (vrp, vrp->ns_ept); + ret =device_for_each_child (&vdev->dev,NULL , rpmsg_remove_device);if (ret)dev_warn (&vdev->dev,"can't remove rpmsg device: %d\n" , ret); -if (vrp->ns_ept) -__rpmsg_destroy_ept (vrp, vrp->ns_ept); -idr_destroy (&vrp->endpoints); vdev->config->del_vqs (vrp->vdev);
Signature · 1 line
1.9.1
Hi Loic,
Quoted 9 lines · Loic Pallardy
In
rpmsg_remove()procedure, children are removed then Name Service announcement endpoint is destroyed and device released.Issue with current implementation is if a NS announcement creation request is ongoing (received before virtio reset), child device could be created after children removing. In that case
rpmsg_remove()is freeingrpmsg_virtio_bus, leading to an inconsistent state.
Quoted 4 lines
This patch is destroying NS announcement service endpoint before removing children to guarantee that list of child devices is fixed and all of them will be correctly removed before cleaning resources.
I do not think this is the right fix for the problem you explained. The removal of rpmsg devices can actually invoke the announce_destroy in the rpmsg_dev_remove().
regards
Suman
Quoted 30 lines
Fixes bcabbccabffe ("rpmsg: Split off generic tail of create_channel()")Signed-off-by Loic Pallardy <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/rpmsg/virtio_rpmsg_bus.c +3
-3@@ -1004,13 +1004,13 @@ static void rpmsg_remove(struct virtio_device *vdev) vdev->config->reset (vdev); +if (vrp->ns_ept) +__rpmsg_destroy_ept (vrp, vrp->ns_ept); + ret =device_for_each_child (&vdev->dev,NULL , rpmsg_remove_device);if (ret)dev_warn (&vdev->dev,"can't remove rpmsg device: %d\n" , ret); -if (vrp->ns_ept) -__rpmsg_destroy_ept (vrp, vrp->ns_ept); -idr_destroy (&vrp->endpoints); vdev->config->del_vqs (vrp->vdev);
Quoted 25 lines
-----Original Message-----
From: Suman Anna <[email protected]>
Sent: Thursday, July 26, 2018 12:32 AM
To: Loic PALLARDY <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; [email protected]
Subject: Re: [PATCH 1/1] rpmsg:virtio_rpmsg_bus: Fixrpmsg_remove()release orderHi Loic,
Quoted 9 lines · Loic Pallardy
In
rpmsg_remove()procedure, children are removed then Name Service announcement endpoint is destroyed and device released.Issue with current implementation is if a NS announcement creation request is ongoing (received before virtio reset), child device could be created after children removing. In that case
rpmsg_remove()is freeingrpmsg_virtio_bus, leading to an inconsistent state.
Quoted 8 lines
Quoted 4 lines
This patch is destroying NS announcement service endpoint before removing children to guarantee that list of child devices is fixed and all of them will be correctly removed before cleaning resources.
I do not think this is the right fix for the problem you explained. The removal of rpmsg devices can actually invoke the
announce_destroyin therpmsg_dev_remove().
Yes it was one of my interrogation correcting it like that. But as virtio link has been put in reset state just before, no message could be sent to coprocessor... Other possible correction (maybe less elegant), keeping current order, is to introduce a rpmsg bus "status" that will be checked before registering new device. Anyway, we need to prevent new rpmsg device register after children removal to avoid orphan device.
Regards,
Loic
Quoted 38 lines
regards
SumanReview
Quoted 9 lines
Fixes bcabbccabffe ("rpmsg: Split off generic tail of create_channel()")Signed-off-by Loic Pallardy <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/drivers/rpmsg/virtio_rpmsg_bus.cdrivers/rpmsg/virtio_rpmsg_bus.c static void rpmsg_remove(struct virtio_device
Quoted 4 lines
index 664f957..f5d481f 100644
drivers/rpmsg/virtio_rpmsg_bus.c +0
-0@@ -1004,13 +1004,13 @@ static void rpmsg_remove(struct virtio_device*vdev)
drivers/rpmsg/virtio_rpmsg_bus.c static void rpmsg_remove(struct virtio_device *vdev)
Quoted 7 lines
drivers/rpmsg/virtio_rpmsg_bus.c +3
-0vdev->config->reset (vdev); +if (vrp->ns_ept) +__rpmsg_destroy_ept (vrp, vrp->ns_ept); + ret = device_for_each_child(&vdev->dev, NULL,
rpmsg_remove_device);drivers/rpmsg/virtio_rpmsg_bus.c static void rpmsg_remove(struct virtio_device · line 1011
Quoted 2 lines
drivers/rpmsg/virtio_rpmsg_bus.c +0
-0if (ret) dev_warn(&vdev->dev, "can't remove rpmsg device: %d\n",ret);
Quoted 8 lines
drivers/rpmsg/virtio_rpmsg_bus.c +0
-3-if (vrp->ns_ept) -__rpmsg_destroy_ept (vrp, vrp->ns_ept); -idr_destroy (&vrp->endpoints); vdev->config->del_vqs (vrp->vdev);