Message ID | 20240325171238.82511-1-marco.pinn95@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | vsock/virtio: fix packet delivery to tap device | expand |
On Mon, Mar 25, 2024 at 06:12:38PM +0100, Marco Pinna wrote: >Commit 82dfb540aeb2 ("VSOCK: Add virtio vsock vsockmon hooks") added >virtio_transport_deliver_tap_pkt() for handing packets to the >vsockmon device. However, in virtio_transport_send_pkt_work(), >the function is called before actually sending the packet (i.e. >before placing it in the virtqueue with virtqueue_add_sgs() and checking >whether it returned successfully). From here.. > This may cause timing issues since >the sending of the packet may fail, causing it to be re-queued >(possibly multiple times), while the tap device would show the >packet being sent correctly. to here... This a bit unclear, I would rephrase with something like this: Queuing the packet in the virtqueue can fail even multiple times. However, in virtio_transport_deliver_tap_pkt() we deliver the packet to the monitoring tap interface only the first time we call it. This certainly avoids seeing the same packet replicated multiple times in the monitoring interface, but it can show the packet sent with the wrong timestamp or even before we succeed to queue it in the virtqueue. > >Move virtio_transport_deliver_tap_pkt() after calling virtqueue_add_sgs() >and making sure it returned successfully. > >Fixes: 82dfb540aeb2 ("VSOCK: Add virtio vsock vsockmon hooks") >Signed-off-by: Marco Pinna <marco.pinn95@gmail.com> >--- > net/vmw_vsock/virtio_transport.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > >diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c >index 1748268e0694..ee5d306a96d0 100644 >--- a/net/vmw_vsock/virtio_transport.c >+++ b/net/vmw_vsock/virtio_transport.c >@@ -120,7 +120,6 @@ virtio_transport_send_pkt_work(struct work_struct *work) > if (!skb) > break; > >- virtio_transport_deliver_tap_pkt(skb); > reply = virtio_vsock_skb_reply(skb); > sgs = vsock->out_sgs; > sg_init_one(sgs[out_sg], virtio_vsock_hdr(skb), >@@ -170,6 +169,8 @@ virtio_transport_send_pkt_work(struct work_struct *work) > break; > } > >+ virtio_transport_deliver_tap_pkt(skb); >+ I was just worried that consume_skb(), called in virtio_transport_tx_work() when the host sends an interrupt to the guest after it has consumed the packet, might be called before this point, but both run with `vsock->tx_lock` held, so we are protected from this case. So, the patch LGTM, I would just clarify the commit message. Thanks, Stefano > if (reply) { > struct virtqueue *rx_vq = vsock->vqs[VSOCK_VQ_RX]; > int val; >-- >2.44.0 >
diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index 1748268e0694..ee5d306a96d0 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -120,7 +120,6 @@ virtio_transport_send_pkt_work(struct work_struct *work) if (!skb) break; - virtio_transport_deliver_tap_pkt(skb); reply = virtio_vsock_skb_reply(skb); sgs = vsock->out_sgs; sg_init_one(sgs[out_sg], virtio_vsock_hdr(skb), @@ -170,6 +169,8 @@ virtio_transport_send_pkt_work(struct work_struct *work) break; } + virtio_transport_deliver_tap_pkt(skb); + if (reply) { struct virtqueue *rx_vq = vsock->vqs[VSOCK_VQ_RX]; int val;
Commit 82dfb540aeb2 ("VSOCK: Add virtio vsock vsockmon hooks") added virtio_transport_deliver_tap_pkt() for handing packets to the vsockmon device. However, in virtio_transport_send_pkt_work(), the function is called before actually sending the packet (i.e. before placing it in the virtqueue with virtqueue_add_sgs() and checking whether it returned successfully). This may cause timing issues since the sending of the packet may fail, causing it to be re-queued (possibly multiple times), while the tap device would show the packet being sent correctly. Move virtio_transport_deliver_tap_pkt() after calling virtqueue_add_sgs() and making sure it returned successfully. Fixes: 82dfb540aeb2 ("VSOCK: Add virtio vsock vsockmon hooks") Signed-off-by: Marco Pinna <marco.pinn95@gmail.com> --- net/vmw_vsock/virtio_transport.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)