vsock: cancel connect packets when failing to connect
Subsystems (7)
cover vsock: cancel connect packets when failing to connect
Currently, if a connect call fails on a signal or timeout (e.g., guest is still in the process of starting up), we'll just return to caller and leave the connect packet queued and they are sent even though the connection is considered a failure, which can confuse applications with unwanted false connect attempt.
The patchset enables vsock (both host and guest) to cancel queued packets when a connect attempt is considered to fail.
Peng Tao (4):
vsock: track pkt owner vsock
vhost-vsock: add pkt cancel capability
vsock: add pkt cancel capability
vsock: cancel packets when failing to connect
drivers/vhost/vsock.c | 29 ++++++++++++++++++++++++++ include/linux/virtio_vsock.h | 12 +++++++++++ net/vmw_vsock/af_vsock.c | 7 +++++++ net/vmw_vsock/virtio_transport.c | 36 +++++++++++++++++++++++++++++++++ net/vmw_vsock/virtio_transport_common.c | 14 ++++++------- 5 files changed, 91 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/4 vsock: track pkt owner vsock
So that we can cancel a queued pkt later if necessary.
--- include/linux/virtio_vsock.h | 2 ++ net/vmw_vsock/virtio_transport_common.c | 7 +++++++ 2 files changed, 9 insertions(+)
include/linux/virtio_vsock.h +2 -0
@@ -48,6 +48,7 @@ struct virtio_vsock_pkt {struct virtio_vsock_hdr hdr;struct work_struct work;struct list_head list; +struct vsock_sock *vsk;void *buf;u32 len;u32 off;
@@ -56,6 +57,7 @@ struct virtio_vsock_pkt {struct virtio_vsock_pkt_info {u32 remote_cid, remote_port; +struct vsock_sock *vsk;struct msghdr *msg;u32 pkt_len;u16 type;
net/vmw_vsock/virtio_transport_common.c +7 -0
@@ -57,6 +57,7 @@ virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info, pkt->len = len; pkt->hdr.len =cpu_to_le32 (len); pkt->reply = info->reply; + pkt->vsk = info->vsk;if (info->msg && len >0 ) { pkt->buf =kmalloc (len,GFP_KERNEL );
@@ -180,6 +181,7 @@ static int virtio_transport_send_credit_update(struct vsock_sock *vsk,struct virtio_vsock_pkt_info info = { .op =VIRTIO_VSOCK_OP_CREDIT_UPDATE , .type = type, + .vsk = vsk, };return virtio_transport_send_pkt_info (vsk, &info);
@@ -519,6 +521,7 @@ int virtio_transport_connect(struct vsock_sock *vsk)struct virtio_vsock_pkt_info info = { .op =VIRTIO_VSOCK_OP_REQUEST , .type =VIRTIO_VSOCK_TYPE_STREAM , + .vsk = vsk, };return virtio_transport_send_pkt_info (vsk, &info);
@@ -534,6 +537,7 @@ int virtio_transport_shutdown(struct vsock_sock *vsk, int mode) VIRTIO_VSOCK_SHUTDOWN_RCV : 0) | (mode &SEND_SHUTDOWN ? VIRTIO_VSOCK_SHUTDOWN_SEND : 0), + .vsk = vsk, };return virtio_transport_send_pkt_info (vsk, &info);
@@ -560,6 +564,7 @@ virtio_transport_stream_enqueue(struct vsock_sock *vsk, .type = VIRTIO_VSOCK_TYPE_STREAM, .msg = msg, .pkt_len = len, + .vsk = vsk, };return virtio_transport_send_pkt_info (vsk, &info);
@@ -581,6 +586,7 @@ static int virtio_transport_reset(struct vsock_sock *vsk, .op = VIRTIO_VSOCK_OP_RST, .type = VIRTIO_VSOCK_TYPE_STREAM, .reply = !!pkt, + .vsk = vsk, };/* Send RST only if the original pkt is not a RST pkt */
@@ -826,6 +832,7 @@ virtio_transport_send_response(struct vsock_sock *vsk, .remote_cid = le32_to_cpu(pkt->hdr.src_cid), .remote_port = le32_to_cpu(pkt->hdr.src_port), .reply = true, + .vsk = vsk, };return virtio_transport_send_pkt_info (vsk, &info);
Signature · 1 line
2.7.4
PATCH 1/4 vsock: track pkt owner vsock
In reply to Peng TaoSo that we can cancel a queued pkt later if necessary.
--- include/linux/virtio_vsock.h | 2 ++ net/vmw_vsock/virtio_transport_common.c | 7 +++++++ 2 files changed, 9 insertions(+)
include/linux/virtio_vsock.h +2 -0
@@ -48,6 +48,7 @@ struct virtio_vsock_pkt {struct virtio_vsock_hdr hdr;struct work_struct work;struct list_head list; +struct vsock_sock *vsk;void *buf;u32 len;u32 off;
@@ -56,6 +57,7 @@ struct virtio_vsock_pkt {struct virtio_vsock_pkt_info {u32 remote_cid, remote_port; +struct vsock_sock *vsk;struct msghdr *msg;u32 pkt_len;u16 type;
net/vmw_vsock/virtio_transport_common.c +7 -0
@@ -57,6 +57,7 @@ virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info, pkt->len = len; pkt->hdr.len =cpu_to_le32 (len); pkt->reply = info->reply; + pkt->vsk = info->vsk;if (info->msg && len >0 ) { pkt->buf =kmalloc (len,GFP_KERNEL );
@@ -180,6 +181,7 @@ static int virtio_transport_send_credit_update(struct vsock_sock *vsk,struct virtio_vsock_pkt_info info = { .op =VIRTIO_VSOCK_OP_CREDIT_UPDATE , .type = type, + .vsk = vsk, };return virtio_transport_send_pkt_info (vsk, &info);
@@ -519,6 +521,7 @@ int virtio_transport_connect(struct vsock_sock *vsk)struct virtio_vsock_pkt_info info = { .op =VIRTIO_VSOCK_OP_REQUEST , .type =VIRTIO_VSOCK_TYPE_STREAM , + .vsk = vsk, };return virtio_transport_send_pkt_info (vsk, &info);
@@ -534,6 +537,7 @@ int virtio_transport_shutdown(struct vsock_sock *vsk, int mode) VIRTIO_VSOCK_SHUTDOWN_RCV : 0) | (mode &SEND_SHUTDOWN ? VIRTIO_VSOCK_SHUTDOWN_SEND : 0), + .vsk = vsk, };return virtio_transport_send_pkt_info (vsk, &info);
@@ -560,6 +564,7 @@ virtio_transport_stream_enqueue(struct vsock_sock *vsk, .type = VIRTIO_VSOCK_TYPE_STREAM, .msg = msg, .pkt_len = len, + .vsk = vsk, };return virtio_transport_send_pkt_info (vsk, &info);
@@ -581,6 +586,7 @@ static int virtio_transport_reset(struct vsock_sock *vsk, .op = VIRTIO_VSOCK_OP_RST, .type = VIRTIO_VSOCK_TYPE_STREAM, .reply = !!pkt, + .vsk = vsk, };/* Send RST only if the original pkt is not a RST pkt */
@@ -826,6 +832,7 @@ virtio_transport_send_response(struct vsock_sock *vsk, .remote_cid = le32_to_cpu(pkt->hdr.src_cid), .remote_port = le32_to_cpu(pkt->hdr.src_port), .reply = true, + .vsk = vsk, };return virtio_transport_send_pkt_info (vsk, &info);
Signature · 1 line
2.7.4
PATCH 2/4 vhost-vsock: add pkt cancel capability
In reply to Peng TaoTo allow canceling all packets of a connection.
--- drivers/vhost/vsock.c | 29 +++++++++++++++++++++++++++++ include/linux/virtio_vsock.h | 3 +++ 2 files changed, 32 insertions(+)
drivers/vhost/vsock.c +29 -0
@@ -218,6 +218,34 @@ vhost_transport_send_pkt(struct virtio_vsock_pkt *pkt)return len; } +static int +vhost_transport_cancel_pkt (struct vsock_sock *vsk) +{ +struct vhost_vsock *vsock; +struct virtio_vsock_pkt *pkt, *n; +LIST_HEAD (freeme); + +/* Find the vhost_vsock according to guest context id */ + vsock =vhost_vsock_get (vsk->remote_addr.svm_cid); +if (!vsock) +return -ENODEV ; + +spin_lock_bh (&vsock->send_pkt_list_lock); +list_for_each_entry_safe (pkt, n, &vsock->send_pkt_list, list) { +if (pkt->vsk != vsk) +continue ; +list_move (&pkt->list, &freeme); + } +spin_unlock_bh (&vsock->send_pkt_list_lock); + +list_for_each_entry_safe (pkt, n, &freeme, list) { +list_del (&pkt->list); +virtio_transport_free_pkt (pkt); + } + +return 0 ; +} +static struct virtio_vsock_pkt *vhost_vsock_alloc_pkt (struct vhost_virtqueue *vq,unsigned int out,unsigned int in)
@@ -698,6 +726,7 @@ static struct virtio_transport vhost_transport = { }, .send_pkt = vhost_transport_send_pkt, + .cancel_pkt = vhost_transport_cancel_pkt, };static int __init vhost_vsock_init (void )
include/linux/virtio_vsock.h +3 -0
@@ -72,6 +72,9 @@ struct virtio_transport {/* Takes ownership of the packet */ int (*send_pkt)(struct virtio_vsock_pkt *pkt); + +/* Cancel packets belonging the same vsock */ +int (*cancel_pkt)(struct vsock_sock *vsk); };ssize_t
Signature · 1 line
2.7.4
PATCH 2/4 vhost-vsock: add pkt cancel capability
In reply to Peng TaoTo allow canceling all packets of a connection.
--- drivers/vhost/vsock.c | 29 +++++++++++++++++++++++++++++ include/linux/virtio_vsock.h | 3 +++ 2 files changed, 32 insertions(+)
drivers/vhost/vsock.c +29 -0
@@ -218,6 +218,34 @@ vhost_transport_send_pkt(struct virtio_vsock_pkt *pkt)return len; } +static int +vhost_transport_cancel_pkt (struct vsock_sock *vsk) +{ +struct vhost_vsock *vsock; +struct virtio_vsock_pkt *pkt, *n; +LIST_HEAD (freeme); + +/* Find the vhost_vsock according to guest context id */ + vsock =vhost_vsock_get (vsk->remote_addr.svm_cid); +if (!vsock) +return -ENODEV ; + +spin_lock_bh (&vsock->send_pkt_list_lock); +list_for_each_entry_safe (pkt, n, &vsock->send_pkt_list, list) { +if (pkt->vsk != vsk) +continue ; +list_move (&pkt->list, &freeme); + } +spin_unlock_bh (&vsock->send_pkt_list_lock); + +list_for_each_entry_safe (pkt, n, &freeme, list) { +list_del (&pkt->list); +virtio_transport_free_pkt (pkt); + } + +return 0 ; +} +static struct virtio_vsock_pkt *vhost_vsock_alloc_pkt (struct vhost_virtqueue *vq,unsigned int out,unsigned int in)
@@ -698,6 +726,7 @@ static struct virtio_transport vhost_transport = { }, .send_pkt = vhost_transport_send_pkt, + .cancel_pkt = vhost_transport_cancel_pkt, };static int __init vhost_vsock_init (void )
include/linux/virtio_vsock.h +3 -0
@@ -72,6 +72,9 @@ struct virtio_transport {/* Takes ownership of the packet */ int (*send_pkt)(struct virtio_vsock_pkt *pkt); + +/* Cancel packets belonging the same vsock */ +int (*cancel_pkt)(struct vsock_sock *vsk); };ssize_t
Signature · 1 line
2.7.4
PATCH 3/4 vsock: add pkt cancel capability
In reply to Peng Tao--- net/vmw_vsock/virtio_transport.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
net/vmw_vsock/virtio_transport.c +36 -0
@@ -170,6 +170,41 @@ virtio_transport_send_pkt(struct virtio_vsock_pkt *pkt)return len; } +static int +virtio_transport_cancel_pkt (struct vsock_sock *vsk) +{ +struct virtio_vsock *vsock; +struct virtio_vsock_pkt *pkt, *n; +int cnt =0 ; +LIST_HEAD (freeme); + + vsock =virtio_vsock_get (); +if (!vsock) { +return -ENODEV ; + } + +if (pkt->reply) + cnt++; + +spin_lock_bh (&vsock->send_pkt_list_lock); +list_for_each_entry_safe (pkt, n, &vsock->send_pkt_list, list) { +if (pkt->vsk != vsk) +continue ; +list_move (&pkt->list, &freeme); + } +spin_unlock_bh (&vsock->send_pkt_list_lock); + +list_for_each_entry_safe (pkt, n, &freeme, list) { +if (pkt->reply) + cnt++; +list_del (&pkt->list); +virtio_transport_free_pkt (pkt); + } +atomic_sub (cnt, &vsock->queued_replies); + +return 0 ; +} +static void virtio_vsock_rx_fill (struct virtio_vsock *vsock) {int buf_len =VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE ;
@@ -453,6 +488,7 @@ static struct virtio_transport virtio_transport = { }, .send_pkt = virtio_transport_send_pkt, + .cancel_pkt = virtio_transport_cancel_pkt, };static int virtio_vsock_probe (struct virtio_device *vdev)
Signature · 1 line
2.7.4
PATCH 3/4 vsock: add pkt cancel capability
In reply to Peng Tao--- net/vmw_vsock/virtio_transport.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
net/vmw_vsock/virtio_transport.c +36 -0
@@ -170,6 +170,41 @@ virtio_transport_send_pkt(struct virtio_vsock_pkt *pkt)return len; } +static int +virtio_transport_cancel_pkt (struct vsock_sock *vsk) +{ +struct virtio_vsock *vsock; +struct virtio_vsock_pkt *pkt, *n; +int cnt =0 ; +LIST_HEAD (freeme); + + vsock =virtio_vsock_get (); +if (!vsock) { +return -ENODEV ; + } + +if (pkt->reply) + cnt++; + +spin_lock_bh (&vsock->send_pkt_list_lock); +list_for_each_entry_safe (pkt, n, &vsock->send_pkt_list, list) { +if (pkt->vsk != vsk) +continue ; +list_move (&pkt->list, &freeme); + } +spin_unlock_bh (&vsock->send_pkt_list_lock); + +list_for_each_entry_safe (pkt, n, &freeme, list) { +if (pkt->reply) + cnt++; +list_del (&pkt->list); +virtio_transport_free_pkt (pkt); + } +atomic_sub (cnt, &vsock->queued_replies); + +return 0 ; +} +static void virtio_vsock_rx_fill (struct virtio_vsock *vsock) {int buf_len =VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE ;
@@ -453,6 +488,7 @@ static struct virtio_transport virtio_transport = { }, .send_pkt = virtio_transport_send_pkt, + .cancel_pkt = virtio_transport_cancel_pkt, };static int virtio_vsock_probe (struct virtio_device *vdev)
Signature · 1 line
2.7.4
PATCH 4/4 vsock: cancel packets when failing to connect
In reply to Peng TaoOtherwise we'll leave the packets queued until releasing vsock device. E.g., if guest is slow to start up, resulting ETIMEDOUT on connect, guest will get the connect requests from failed host sockets.
--- include/linux/virtio_vsock.h | 7 +++++++ net/vmw_vsock/af_vsock.c | 7 +++++++ net/vmw_vsock/virtio_transport_common.c | 7 ------- 3 files changed, 14 insertions(+), 7 deletions(-)
include/linux/virtio_vsock.h +7 -0
@@ -156,4 +156,11 @@ void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock *vvs, struct virtio_vsu32 virtio_transport_get_credit (struct virtio_vsock_sock *vvs,u32 wanted);void virtio_transport_put_credit (struct virtio_vsock_sock *vvs,u32 credit); +static inline const struct virtio_transport *virtio_transport_get_ops (void ) +{ +const struct vsock_transport *t =vsock_core_get_transport (); + + return container_of(t, struct virtio_transport, transport); +} +#endif /* _LINUX_VIRTIO_VSOCK_H */
net/vmw_vsock/af_vsock.c +7 -0
@@ -104,6 +104,7 @@#include <linux/unistd.h> #include <linux/wait.h> #include <linux/workqueue.h> +#include <linux/virtio_vsock.h> #include <net/sock.h> #include <net/af_vsock.h>
@@ -1105,6 +1106,7 @@ static void vsock_connect_timeout(struct work_struct *work) {struct sock *sk;struct vsock_sock *vsk; +int cancel =0 ; vsk = container_of(work, struct vsock_sock, dwork.work); sk =sk_vsock (vsk);
@@ -1115,8 +1117,11 @@ static void vsock_connect_timeout(struct work_struct *work) sk->sk_state =SS_UNCONNECTED ; sk->sk_err =ETIMEDOUT ; sk->sk_error_report (sk); + cancel =1 ; }release_sock (sk); +if (cancel) +virtio_transport_get_ops ()->cancel_pkt (vsk);sock_put (sk); }
@@ -1223,11 +1228,13 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, err =sock_intr_errno (timeout); sk->sk_state =SS_UNCONNECTED ; sock->state =SS_UNCONNECTED ; +virtio_transport_get_ops ()->cancel_pkt (vsk); goto out_wait; }else if (timeout ==0 ) { err = -ETIMEDOUT ; sk->sk_state =SS_UNCONNECTED ; sock->state =SS_UNCONNECTED ; +virtio_transport_get_ops ()->cancel_pkt (vsk); goto out_wait; }
net/vmw_vsock/virtio_transport_common.c +0 -7
@@ -25,13 +25,6 @@/* How long to wait for graceful shutdown of a connection */ #define VSOCK_CLOSE_TIMEOUT (8 * HZ) -static const struct virtio_transport *virtio_transport_get_ops (void ) -{ -const struct vsock_transport *t =vsock_core_get_transport (); - - return container_of(t, struct virtio_transport, transport); -} -struct virtio_vsock_pkt * virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info, size_t len,
Signature · 1 line
2.7.4
PATCH 4/4 vsock: cancel packets when failing to connect
In reply to Peng TaoOtherwise we'll leave the packets queued until releasing vsock device. E.g., if guest is slow to start up, resulting ETIMEDOUT on connect, guest will get the connect requests from failed host sockets.
--- include/linux/virtio_vsock.h | 7 +++++++ net/vmw_vsock/af_vsock.c | 7 +++++++ net/vmw_vsock/virtio_transport_common.c | 7 ------- 3 files changed, 14 insertions(+), 7 deletions(-)
include/linux/virtio_vsock.h +7 -0
@@ -156,4 +156,11 @@ void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock *vvs, struct virtio_vsu32 virtio_transport_get_credit (struct virtio_vsock_sock *vvs,u32 wanted);void virtio_transport_put_credit (struct virtio_vsock_sock *vvs,u32 credit); +static inline const struct virtio_transport *virtio_transport_get_ops (void ) +{ +const struct vsock_transport *t =vsock_core_get_transport (); + + return container_of(t, struct virtio_transport, transport); +} +#endif /* _LINUX_VIRTIO_VSOCK_H */
net/vmw_vsock/af_vsock.c +7 -0
@@ -104,6 +104,7 @@#include <linux/unistd.h> #include <linux/wait.h> #include <linux/workqueue.h> +#include <linux/virtio_vsock.h> #include <net/sock.h> #include <net/af_vsock.h>
@@ -1105,6 +1106,7 @@ static void vsock_connect_timeout(struct work_struct *work) {struct sock *sk;struct vsock_sock *vsk; +int cancel =0 ; vsk = container_of(work, struct vsock_sock, dwork.work); sk =sk_vsock (vsk);
@@ -1115,8 +1117,11 @@ static void vsock_connect_timeout(struct work_struct *work) sk->sk_state =SS_UNCONNECTED ; sk->sk_err =ETIMEDOUT ; sk->sk_error_report (sk); + cancel =1 ; }release_sock (sk); +if (cancel) +virtio_transport_get_ops ()->cancel_pkt (vsk);sock_put (sk); }
@@ -1223,11 +1228,13 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, err =sock_intr_errno (timeout); sk->sk_state =SS_UNCONNECTED ; sock->state =SS_UNCONNECTED ; +virtio_transport_get_ops ()->cancel_pkt (vsk); goto out_wait; }else if (timeout ==0 ) { err = -ETIMEDOUT ; sk->sk_state =SS_UNCONNECTED ; sock->state =SS_UNCONNECTED ; +virtio_transport_get_ops ()->cancel_pkt (vsk); goto out_wait; }
net/vmw_vsock/virtio_transport_common.c +0 -7
@@ -25,13 +25,6 @@/* How long to wait for graceful shutdown of a connection */ #define VSOCK_CLOSE_TIMEOUT (8 * HZ) -static const struct virtio_transport *virtio_transport_get_ops (void ) -{ -const struct vsock_transport *t =vsock_core_get_transport (); - - return container_of(t, struct virtio_transport, transport); -} -struct virtio_vsock_pkt * virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info, size_t len,
Signature · 1 line
2.7.4
Re: [PATCH 3/4] vsock: add pkt cancel capability
In reply to Peng TaoQuoted 17 lines · Peng Tao
Signed-off-by Peng Tao <[email protected]>--- net/vmw_vsock/virtio_transport.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)net/vmw_vsock/virtio_transport.c +4
-0@@ -170,6 +170,41 @@ virtio_transport_send_pkt(struct virtio_vsock_pkt *pkt)return len; } +static int +virtio_transport_cancel_pkt (struct vsock_sock *vsk) +{ +struct virtio_vsock *vsock;
net/vmw_vsock/virtio_transport.c virtio_transport_send_pkt(struct virtio_vsock_pkt *pkt) · line 186
Quoted 10 lines
net/vmw_vsock/virtio_transport.c +10
-0+struct virtio_vsock_pkt *pkt, *n; +int cnt =0 ; +LIST_HEAD (freeme); + + vsock =virtio_vsock_get (); +if (!vsock) { +return -ENODEV ; + } + +if (pkt->reply)
pkt is uninitialized. I guess this if statement should be deleted, you already take care of counting reply packets below.
Quoted 7 lines
net/vmw_vsock/virtio_transport.c +7
-0+ cnt++; + +spin_lock_bh (&vsock->send_pkt_list_lock); +list_for_each_entry_safe (pkt, n, &vsock->send_pkt_list, list) { +if (pkt->vsk != vsk) +continue ; +list_move (&pkt->list, &freeme);
net/vmw_vsock/virtio_transport.c virtio_transport_send_pkt(struct virtio_vsock_pkt *pkt) · line 203
Quoted 10 lines
net/vmw_vsock/virtio_transport.c +10
-0+ } +spin_unlock_bh (&vsock->send_pkt_list_lock); + +list_for_each_entry_safe (pkt, n, &freeme, list) { +if (pkt->reply) + cnt++; +list_del (&pkt->list); +virtio_transport_free_pkt (pkt); + } +atomic_sub (cnt, &vsock->queued_replies);
If we stopped rx because there were too many replies in flight then we might be able to resume rx now:
/* Do we now have resources to resume rx processing? */ if (old_val >= virtqueue_get_vring_size(rx_vq) &&
new_val < virtqueue_get_vring_size(rx_vq))
queue_work(virtio_vsock_workqueue, &vsock->rx_work);
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 2/4] vhost-vsock: add pkt cancel capability
In reply to Peng TaoQuoted 30 lines · Peng Tao
To allow canceling all packets of a connection.
Signed-off-by Peng Tao <[email protected]>--- drivers/vhost/vsock.c | 29 +++++++++++++++++++++++++++++ include/linux/virtio_vsock.h | 3 +++ 2 files changed, 32 insertions(+)drivers/vhost/vsock.c +14
-0@@ -218,6 +218,34 @@ vhost_transport_send_pkt(struct virtio_vsock_pkt *pkt)return len; } +static int +vhost_transport_cancel_pkt (struct vsock_sock *vsk) +{ +struct vhost_vsock *vsock; +struct virtio_vsock_pkt *pkt, *n; +LIST_HEAD (freeme); + +/* Find the vhost_vsock according to guest context id */ + vsock =vhost_vsock_get (vsk->remote_addr.svm_cid); +if (!vsock) +return -ENODEV ; + +spin_lock_bh (&vsock->send_pkt_list_lock); +list_for_each_entry_safe (pkt, n, &vsock->send_pkt_list, list) {
drivers/vhost/vsock.c vhost_transport_send_pkt(struct virtio_vsock_pkt *pkt) · line 244
Quoted 10 lines
drivers/vhost/vsock.c +10
-0+if (pkt->vsk != vsk) +continue ; +list_move (&pkt->list, &freeme); + } +spin_unlock_bh (&vsock->send_pkt_list_lock); + +list_for_each_entry_safe (pkt, n, &freeme, list) { +list_del (&pkt->list); +virtio_transport_free_pkt (pkt); + }
Please handle queued_replies so we can resume rx if we fall below the threshold again.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 4/4] vsock: cancel packets when failing to connect
In reply to Peng TaoQuoted 10 lines · Peng Tao
Otherwise we'll leave the packets queued until releasing vsock device. E.g., if guest is slow to start up, resulting ETIMEDOUT on connect, guest will get the connect requests from failed host sockets.
Signed-off-by Peng Tao <[email protected]>--- include/linux/virtio_vsock.h | 7 +++++++ net/vmw_vsock/af_vsock.c | 7 +++++++ net/vmw_vsock/virtio_transport_common.c | 7 ------- 3 files changed, 14 insertions(+), 7 deletions(-)
Re: [PATCH 4/4] vsock: cancel packets when failing to connect
In reply to Peng TaoQuoted 10 lines · Peng Tao
Otherwise we'll leave the packets queued until releasing vsock device. E.g., if guest is slow to start up, resulting ETIMEDOUT on connect, guest will get the connect requests from failed host sockets.
Signed-off-by Peng Tao <[email protected]>--- include/linux/virtio_vsock.h | 7 +++++++ net/vmw_vsock/af_vsock.c | 7 +++++++ net/vmw_vsock/virtio_transport_common.c | 7 ------- 3 files changed, 14 insertions(+), 7 deletions(-)
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 3/4] vsock: add pkt cancel capability
In reply to Stefan HajnocziQuoted 23 lines · Stefan Hajnoczi
Quoted 22 lines · Peng Tao
Signed-off-by Peng Tao <[email protected]>--- net/vmw_vsock/virtio_transport.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)net/vmw_vsock/virtio_transport.c +9
-0@@ -170,6 +170,41 @@ virtio_transport_send_pkt(struct virtio_vsock_pkt *pkt)return len; } +static int +virtio_transport_cancel_pkt (struct vsock_sock *vsk) +{ +struct virtio_vsock *vsock; +struct virtio_vsock_pkt *pkt, *n; +int cnt =0 ; +LIST_HEAD (freeme); + + vsock =virtio_vsock_get ();
Quoted 9 lines
net/vmw_vsock/virtio_transport.c virtio_transport_send_pkt(struct virtio_vsock_pkt *pkt) · line 186
Quoted 5 lines
net/vmw_vsock/virtio_transport.c +5
-0+if (!vsock) { +return -ENODEV ; + } + +if (pkt->reply)pkt is uninitialized. I guess this if statement should be deleted, you already take care of counting reply packets below.
ah, sorry! I forgot to delete it after handling cnt below...
Quoted 21 lines
Quoted 7 lines
net/vmw_vsock/virtio_transport.c +7
-0+ cnt++; + +spin_lock_bh (&vsock->send_pkt_list_lock); +list_for_each_entry_safe (pkt, n, &vsock->send_pkt_list, list) { +if (pkt->vsk != vsk) +continue ; +list_move (&pkt->list, &freeme);net/vmw_vsock/virtio_transport.c virtio_transport_send_pkt(struct virtio_vsock_pkt *pkt) · line 203
Quoted 10 lines
net/vmw_vsock/virtio_transport.c +10
-0+ } +spin_unlock_bh (&vsock->send_pkt_list_lock); + +list_for_each_entry_safe (pkt, n, &freeme, list) { +if (pkt->reply) + cnt++; +list_del (&pkt->list); +virtio_transport_free_pkt (pkt); + } +atomic_sub (cnt, &vsock->queued_replies);If we stopped rx because there were too many replies in flight then we might be able to resume rx now:
Quoted 4 lines
/* Do we now have resources to resume rx processing? */ if (
old_val>=virtqueue_get_vring_size(rx_vq)&&
new_val<virtqueue_get_vring_size(rx_vq))
queue_work(virtio_vsock_workqueue, &vsock->rx_work);
Thanks! I totally missed the resume part... I'll send an updated version later.
Cheers,
Tao
Re: [PATCH 3/4] vsock: add pkt cancel capability
In reply to Stefan HajnocziQuoted 23 lines · Stefan Hajnoczi
Quoted 22 lines · Peng Tao
Signed-off-by Peng Tao <[email protected]>--- net/vmw_vsock/virtio_transport.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)net/vmw_vsock/virtio_transport.c +9
-0@@ -170,6 +170,41 @@ virtio_transport_send_pkt(struct virtio_vsock_pkt *pkt)return len; } +static int +virtio_transport_cancel_pkt (struct vsock_sock *vsk) +{ +struct virtio_vsock *vsock; +struct virtio_vsock_pkt *pkt, *n; +int cnt =0 ; +LIST_HEAD (freeme); + + vsock =virtio_vsock_get ();
Quoted 9 lines
net/vmw_vsock/virtio_transport.c virtio_transport_send_pkt(struct virtio_vsock_pkt *pkt) · line 186
Quoted 5 lines
net/vmw_vsock/virtio_transport.c +5
-0+if (!vsock) { +return -ENODEV ; + } + +if (pkt->reply)pkt is uninitialized. I guess this if statement should be deleted, you already take care of counting reply packets below.
ah, sorry! I forgot to delete it after handling cnt below...
Quoted 21 lines
Quoted 7 lines
net/vmw_vsock/virtio_transport.c +7
-0+ cnt++; + +spin_lock_bh (&vsock->send_pkt_list_lock); +list_for_each_entry_safe (pkt, n, &vsock->send_pkt_list, list) { +if (pkt->vsk != vsk) +continue ; +list_move (&pkt->list, &freeme);net/vmw_vsock/virtio_transport.c virtio_transport_send_pkt(struct virtio_vsock_pkt *pkt) · line 203
Quoted 10 lines
net/vmw_vsock/virtio_transport.c +10
-0+ } +spin_unlock_bh (&vsock->send_pkt_list_lock); + +list_for_each_entry_safe (pkt, n, &freeme, list) { +if (pkt->reply) + cnt++; +list_del (&pkt->list); +virtio_transport_free_pkt (pkt); + } +atomic_sub (cnt, &vsock->queued_replies);If we stopped rx because there were too many replies in flight then we might be able to resume rx now:
Quoted 4 lines
/* Do we now have resources to resume rx processing? */ if (
old_val>=virtqueue_get_vring_size(rx_vq)&&
new_val<virtqueue_get_vring_size(rx_vq))
queue_work(virtio_vsock_workqueue, &vsock->rx_work);
Thanks! I totally missed the resume part... I'll send an updated version later.
Cheers,
Tao