Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp39095ybj; Fri, 8 May 2020 06:06:06 -0700 (PDT) X-Google-Smtp-Source: APiQypLsVRlr/vQcgeMW3SPIhm3/KwCMB5zIr0kZ7bGZUtqqIM1vejKXGFYcGeVR3IS5HazXDVCS X-Received: by 2002:aa7:c0d2:: with SMTP id j18mr2123923edp.283.1588943166356; Fri, 08 May 2020 06:06:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588943166; cv=none; d=google.com; s=arc-20160816; b=m0KJzFceag8xrG4CKGE952rzfhyMslBjVVt7cVFyhpl4GpiVJSk8i4AAmA6L39HiLR 1wSVcoSLGzkhnU8qGp2X9KOiuywYyfjJudUBG5/ZQzxWho2eIYg2gAvP64NvPdnSmZ1b OaQ+mywOiro11351oHpO3SUAFAyVPuOtFK0JRCKscaGbVH+E9NykDSpq/pZCvlE40ALa K8XwEnBZg9XGLDqCKYqtzUhIUv3yEoEeB9Uly1zD7183Rz2Ysu7aSmMHCFacc4m5k65R vbzQ876yD1vpiVPC8C3MXkQcFazciOL/wYTsBz4k1KCB+GB/V38zSLDXzFsmFOFm+XzV QlpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=duP6JQXAMdjkCie4VeIJ7sa83VXQhpRciaAD2+YPaG0=; b=vKBgrOONP8glcDlMPCSE5aW4YiJEsY64Nt+xOaV+sMMqTbnHyTA1nT+vfLr2PZqtLq jeZNgVE+yIx0QGMNLA7N7b7Y2mn+gLJSmnG94jgg8rYd+BIvQ+jJi3qyya/Myu8w52oP SQr/LByADEwjIk0vymgPb8WL9B7OUpYn3QidpFXmJOIXXJtb0sjlENuuWIi1pJUdPG6v RlS4CTJ8+1ZZojbU4pKbkkPleVCM9xXRBOAKv6s1SCUk1wjdBl4jLrTxO1ZztHXZec8a Jnn29N0ZVXjEiSXdujZ4ij9AvKEo01JP4PC6N58kD2ex7/d23JEC6mJpcFMQi3Vzis3X UnaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=H2um+Xcr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e15si930351ejc.208.2020.05.08.06.05.26; Fri, 08 May 2020 06:06:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=H2um+Xcr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730238AbgEHNDa (ORCPT + 99 others); Fri, 8 May 2020 09:03:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:57288 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729822AbgEHMuI (ORCPT ); Fri, 8 May 2020 08:50:08 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8433F24959; Fri, 8 May 2020 12:50:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588942208; bh=tS8yISY2FPSoFA2Xz5HcnvqcY9twKKqKe7VbtyvOpsU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H2um+XcrmlVfahll5O52Ua+Fai3NmpjfDc+R1V1CaEjX2BPVeBc8He7KVy3gYNgo4 24y6Wu/eXnVMSi7CrRgr3HXtK2QG60XVCDXEaf/lWo/YMwAiECwuryFJxK6D/FmtJZ RFZlh1MW+cN6oZ03mokuw9vIUozCuJWMDiu2qOfU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ning Bo , Stefano Garzarella , Jia He , "Michael S. Tsirkin" Subject: [PATCH 4.14 01/22] vhost: vsock: kick send_pkt worker once device is started Date: Fri, 8 May 2020 14:35:13 +0200 Message-Id: <20200508123034.093635974@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508123033.915895060@linuxfoundation.org> References: <20200508123033.915895060@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jia He commit 0b841030625cde5f784dd62aec72d6a766faae70 upstream. 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] https://github.com/kata-containers/runtime/issues/1917 Reported-by: Ning Bo Suggested-by: Stefano Garzarella Signed-off-by: Jia He Link: https://lore.kernel.org/r/20200501043840.186557-1-justin.he@arm.com Signed-off-by: Michael S. Tsirkin Reviewed-by: Stefano Garzarella Signed-off-by: Greg Kroah-Hartman --- drivers/vhost/vsock.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -499,6 +499,11 @@ static int vhost_vsock_start(struct vhos mutex_unlock(&vq->mutex); } + /* Some packets may have been queued before the device was started, + * let's kick the send worker to send them. + */ + vhost_work_queue(&vsock->dev, &vsock->send_pkt_work); + mutex_unlock(&vsock->dev.mutex); return 0;