Skip to content

Commit 0b84103

Browse files
justin-hemstsirkin
authored andcommitted
vhost: vsock: kick send_pkt worker once device is started
Ning Bo reported an abnormal 2-second gap when booting Kata container [1]. The unconditional timeout was caused by VSOCK_DEFAULT_CONNECT_TIMEOUT of connecting from the client side. The vhost vsock client tries to connect an initializing virtio vsock server. The abnormal flow looks like: host-userspace vhost vsock guest vsock ============== =========== ============ connect() --------> vhost_transport_send_pkt_work() initializing | vq->private_data==NULL | will not be queued V schedule_timeout(2s) vhost_vsock_start() <--------- device ready set vq->private_data wait for 2s and failed connect() again vq->private_data!=NULL recv connecting pkt Details: 1. Host userspace sends a connect pkt, at that time, guest vsock is under initializing, hence the vhost_vsock_start has not been called. So vq->private_data==NULL, and the pkt is not been queued to send to guest 2. Then it sleeps for 2s 3. After guest vsock finishes initializing, vq->private_data is set 4. When host userspace wakes up after 2s, send connecting pkt again, everything is fine. As suggested by Stefano Garzarella, this fixes it by additional kicking the send_pkt worker in vhost_vsock_start once the virtio device is started. This makes the pending pkt sent again. After this patch, kata-runtime (with vsock enabled) boot time is reduced from 3s to 1s on a ThunderX2 arm64 server. [1] kata-containers/runtime#1917 Reported-by: Ning Bo <[email protected]> Suggested-by: Stefano Garzarella <[email protected]> Signed-off-by: Jia He <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]>
1 parent 90b5feb commit 0b84103

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/vhost/vsock.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,11 @@ static int vhost_vsock_start(struct vhost_vsock *vsock)
543543
mutex_unlock(&vq->mutex);
544544
}
545545

546+
/* Some packets may have been queued before the device was started,
547+
* let's kick the send worker to send them.
548+
*/
549+
vhost_work_queue(&vsock->dev, &vsock->send_pkt_work);
550+
546551
mutex_unlock(&vsock->dev.mutex);
547552
return 0;
548553

0 commit comments

Comments
 (0)