Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp37918ybj; Fri, 8 May 2020 06:04:49 -0700 (PDT) X-Google-Smtp-Source: APiQypKOR0epbUqLQMyssk3+5to2aMPmsm63DfZtpOOrtt/8VIoyXeaxa3u7qsZv52vUtFl8/pzV X-Received: by 2002:aa7:cd6a:: with SMTP id ca10mr2042600edb.332.1588943089280; Fri, 08 May 2020 06:04:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588943089; cv=none; d=google.com; s=arc-20160816; b=B6cwGq91I4r4k3ciSaaDTrLtU+lzsOkgglkvsuZW8fxZxx/7gY9WRBE7Bxhc2ujEhX fSbPrc6QRvYBiku4ghZCYyZIX9Sh2zaHZBV+AhtANE2AW6jVYyQIG8hMtmn+ASvCLI7q HgrHTNlpfrU1fsaEwVwmdzpRWCOSpyYm2ee9npxH1PLUn0Rh7EayodTbqhfYQyO9PZ8+ 10kTRjVcsZmQh0lqzqyyquULNckRVV1kTK6MCt1396YNOz2KylMJxU3r2UyTwaGigDiH lWhLURhx2elmrjir0KPgqcGP5WuH+rFIGZFHnR+fID98U6p8ix2cpeP6hl5Efr/yZtn1 9BNQ== 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=WhhRa2NVmZB5sa5d6qt13HU+tkCXdHCzMJ/JKrdxlqQm/h/iEps+kO+uBSluRiMZxq sTH95Qjef5SuBEp6d5fQ3H6YYOaFFIk8X3dwA8gMdyjsYYqtDcUwW0ALaxMNgqQtsRYL 3CQKsGboT7kMrNvLkryLLUAGu6rnuayKgatk1unwZ1B6z0ZPL8duBRLkGbcYOmyQatLi a9DXl95OQBch75GvlDnYVdOvLo0kCqPE1Pq+KXleiXKnysbYc3joEWISVhp3TE07YYvk NEPDDpJycSOmAEAlh4JEQr6qXkX+MeRLAsXCr+ODdCdQgNWHPWuWGtTtWSGdBYCg3m24 6q2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Rfwt70Vb; 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 v19si894971edr.209.2020.05.08.06.04.14; Fri, 08 May 2020 06:04:49 -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=Rfwt70Vb; 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 S1729577AbgEHNCS (ORCPT + 99 others); Fri, 8 May 2020 09:02:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:59868 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729014AbgEHMvF (ORCPT ); Fri, 8 May 2020 08:51:05 -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 ABC6024964; Fri, 8 May 2020 12:51:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588942265; bh=tS8yISY2FPSoFA2Xz5HcnvqcY9twKKqKe7VbtyvOpsU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rfwt70VbamXErIoLiAdGG8XN1zJ3YuJQ4PXzQ2l7HIUiTpHpO0uDigad6+ESdoOZA 9D4KYeFMxQlENddr7+hRXK2N5YZDfNIq0M4vZQgL+kdFeGivFixig8i9iSov9BsGPA VpBTpwdbRq+inyQyCmFby8u7sJXOJcKYkvYXwujE= 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.19 01/32] vhost: vsock: kick send_pkt worker once device is started Date: Fri, 8 May 2020 14:35:14 +0200 Message-Id: <20200508123035.056580682@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508123034.886699170@linuxfoundation.org> References: <20200508123034.886699170@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;