Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp39655ybj; Fri, 8 May 2020 06:06:38 -0700 (PDT) X-Google-Smtp-Source: APiQypKK9yCTQtQPqs4LDZqcl+cph/BCdNQ5BaYspluWS9DBHALU7hykLdyUaJB8SWOqSqvNGdfn X-Received: by 2002:a17:906:7f01:: with SMTP id d1mr1744413ejr.49.1588943197787; Fri, 08 May 2020 06:06:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588943197; cv=none; d=google.com; s=arc-20160816; b=uCPhzXRhfRRARIVq1FxIlLQJShcOyx63XAzm5rsh9ry7R6MthH3YhoXd0Y2nw06mwC NlY1DJmLTra6Zu/lo1OjwZLcdxEgpuWdbsLPKDa2wsKFVtJPXpMpnOZwp5RjYHN8/hN4 /GwX5uKsinRqnIs5hVtCnfoVtQ51RNwLOqrRmoGWW0IXQyThj2HHdZqub0Mchtq1C9Bs c6zv0EE/O3dXaz6i53YJfnKJdygI9lFJsyw9xcf8+tdsNo5MiGra4EFZyyiRuLi97vh6 fb+4desQMZIekqYO/rPACaz0fD9WU4ufkL6WrR7JlkqFu5xlWuCrADXILPZH9SLwgu59 tLhw== 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=wv83qx9yNp4CA0Kii5LO2XxqfHlw5NBDK3aOGqpVqCM=; b=XReE2bkGdwrm6OB6z5Erjz8ZUVtgd/+Rdv1DYieKs0AM0co0/ZLQbVudO8nLEhbWD+ ISUwWj1hEDh6sWQSVf53j5nXUFibrh5+8Erc5eSmd61H0CrZrckRjYguu1pw0zbKhEZv cKRFt3qwGQd/GYM50WTVYaZDW64Qx2rdtvICiFISwAu1CFWFbLm+MWDGrENtMJyBW9zx 8eyYxhAP2CGEm42F3wvq+A7ANUF7luNYJnM0bPouceIgZeL1UUu8yN6QhHhYyb4UPQjo 2p3x3362VlS7cuvZepBngv//uBMzmPArvAj4vccXqmDvMFSqlkTDMLSUDMW0Z3rA5KIV f/jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BppeGgr3; 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 c17si887375edt.167.2020.05.08.06.06.11; Fri, 08 May 2020 06:06:37 -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=BppeGgr3; 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 S1728955AbgEHNEH (ORCPT + 99 others); Fri, 8 May 2020 09:04:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:54854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729711AbgEHMtV (ORCPT ); Fri, 8 May 2020 08:49:21 -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 7AF13218AC; Fri, 8 May 2020 12:49:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588942160; bh=WTjfYyt1tNj0vHu2bkWyXHfuboHGAurigpDyTeWo5mQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BppeGgr3YhZAdrEvnkjnEx4eZ9DZlDFuGVB9T5nfwpkskRincGPlhOvFtpP3N8I4n IOxlCdh4jkI45zg2H4k4oUkuC8E9tbbWr1HPQTni1t8ys1ukqdme8DZsqjldZqDgmi lNLr/aogAdSfjP0hjvdnGmM2Iusgf9CKGfbqTfKk= 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.9 01/18] vhost: vsock: kick send_pkt worker once device is started Date: Fri, 8 May 2020 14:35:04 +0200 Message-Id: <20200508123031.429916359@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508123030.497793118@linuxfoundation.org> References: <20200508123030.497793118@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 @@ -460,6 +460,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;