[RFC PATCH 10/10] rpmsg: virtio: Set default dst address on flow control

From: Arnaud Pouliquen
Date: Fri May 20 2022 - 04:34:05 EST


When a rpmsg channel has been created locally with a destination address
set to RPMSG_ADDR_ANY, a name service announcement message is sent to
the remote side. Then the destination address is never updated, making it
impossible to send messages to the remote.

An example of kernel trace observed:
rpmsg_tty virtio0.rpmsg-tty.29.-1: invalid addr (src 0x1d, dst 0xffffffff)

The flow control can be used to set the rpmsg device address.
If the destination address is RPMSG_ADDR_ANY, then set it to
address of the remote endpoint that send the message.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@xxxxxxxxxxx>
---
This patch is an alternative of the fix proposed in patch [1]

[1] https://lore.kernel.org/lkml/20220316153001.662422-1-arnaud.pouliquen@xxxxxxxxxxx/
---
drivers/rpmsg/virtio_rpmsg_bus.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index a8e60ca4cd08..0337a07e278c 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -393,6 +393,16 @@ static int virtio_rpmsg_remote_flowctrl(struct rpmsg_device *rpdev,
if (!ept)
return -EINVAL;

+ /*
+ * If the endpoint is the rpmsg device default one, then it can not be yet associated
+ * to the remote endpoint. This can occur if a ns announcement message has been
+ * previously sent to the remote side.
+ * Update the rpmsg device destination address in such case to store the remote
+ * address as default remote endpoint.
+ */
+ if (rpdev->ept == ept && rpdev->dst == RPMSG_ADDR_ANY)
+ rpdev->dst = __rpmsg32_to_cpu(virtio_is_little_endian(vrp->vdev), chinfo->src);
+
/* Make sure ept->sig_cb doesn't go away while we use it */
mutex_lock(&ept->cb_lock);

--
2.25.1