Received: by 10.223.164.202 with SMTP id h10csp3973681wrb; Tue, 28 Nov 2017 21:52:24 -0800 (PST) X-Google-Smtp-Source: AGs4zMYvzW0a6TM8VXOb4Yk6+9QdkNk+4nJr3T2sBFBZ0oH5RGL6iWOr2bwdqbIYrpeP2mWn/ROn X-Received: by 10.84.253.1 with SMTP id z1mr1734247pll.115.1511934744307; Tue, 28 Nov 2017 21:52:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511934744; cv=none; d=google.com; s=arc-20160816; b=TZxw6pdYO/cynuRvOWqxqeQ3JhJNLX7Iul0JvfY3DHlZnu6jIL7AtdvzqKJDvBU8Ac U91vJfhgoV8aufXs2CV6l9O5ym45rh6rUjNqiiVrgH611CekVuzoek7kYtLBlFBA8GmG HcDdltYzayHbJ4WT7h7QBIUIThfwzOiyUdR3uU2c0HHLpyah91gHEsTCgSpmCdIxxO6U tv9xIhHVPduw87gIFcAwBe8ZAVKnb9HjgurVgeIEKOCaPeUbSSpjCpuorMW2SHGwfvTH gj7w/EUEAGaCYponZFYCv1qUhE9W5aEFtcI0W6KJgkI4QFQ6gNIfe/rX7E0sVI0z7dgG yj5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=eyyrKKMsGkeA/17ugPXO9LtAC2GwqDZzrBo0y5nzKxI=; b=EtPV+yqnWjYDa0y82eedEfXmBdaHJjfmqMKzHYzqWJdo9+6jrpLfPlWRioycby7VnE Ob2gKSiKpJWJCJSkhtyqpo4Ce36P2pMvNjZGJLEh9Fvk8R5lq3oBm1xL9Q1SojLwb8mc s1qDYzfb79E5i4Ju/5Ca7Op8CHRhHSMGZa7qTM+W9O9LQH2xUw7/ixPQ1n6+0NXfTsic EW/8B8iUoca08ToRcX57bYWlth6tiYaBX3kMmSfiaO88PzEBdwMRvZyxIknTuQCmQiz5 eJmnvHO1UeodbCkrQbim+7LEABnKxTlIc79VA0jhtA//exozBIWcVKzOMuq2TiKtOAJE UXfA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 88si705302plc.803.2017.11.28.21.52.06; Tue, 28 Nov 2017 21:52:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751786AbdK2FvN (ORCPT + 71 others); Wed, 29 Nov 2017 00:51:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56474 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750813AbdK2FvL (ORCPT ); Wed, 29 Nov 2017 00:51:11 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D6EA85550; Wed, 29 Nov 2017 05:51:11 +0000 (UTC) Received: from Wei-Dev (dhcp-15-231.nay.redhat.com [10.66.15.231]) by smtp.corp.redhat.com (Postfix) with SMTP id 5BE211717C; Wed, 29 Nov 2017 05:51:07 +0000 (UTC) Date: Wed, 29 Nov 2017 14:12:40 +0800 From: Wei Xu To: "Michael S. Tsirkin" Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, jasowang@redhat.com, mjrosato@linux.vnet.ibm.com Subject: Re: [PATCH net,stable] vhost: fix skb leak in handle_rx() Message-ID: <20171129061240.mhlw5uwi4hf57nf3@Wei-Dev> References: <1511889436-12876-1-git-send-email-wexu@redhat.com> <20171128193713-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171128193713-mutt-send-email-mst@kernel.org> User-Agent: NeoMutt/20170113-14-7f1397-dirty (1.7.2) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 29 Nov 2017 05:51:11 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 28, 2017 at 07:50:58PM +0200, Michael S. Tsirkin wrote: > On Tue, Nov 28, 2017 at 12:17:16PM -0500, wexu@redhat.com wrote: > > From: Wei Xu > > > > Matthew found a roughly 40% tcp throughput regression with commit > > c67df11f(vhost_net: try batch dequing from skb array) as discussed > > in the following thread: > > https://www.mail-archive.com/netdev@vger.kernel.org/msg187936.html > > > > Eventually we figured out that it was a skb leak in handle_rx() > > when sending packets to the VM. This usually happens when a guest > > can not drain out vq as fast as vhost fills in, afterwards it sets > > off the traffic jam and leaks skb(s) which occurs as no headcount > > to send on the vq from vhost side. > > > > This can be avoided by making sure we have got enough headcount > > before actually consuming a skb from the batched rx array while > > transmitting, which is simply done by deferring it a moment later > > in this patch. > > > > Signed-off-by: Wei Xu > > Looks like a good way to fix it, but it will still leak if recvmsg > returns a wrong length (I'm not sure this can happen in practice, but > best to keep it simple). Right, it is better to defend this case, will include it in v2. > > Also, we need to add this before each recvmsg, including overrun, > and discard on error. OK. Wei > > > --- > > drivers/vhost/net.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c > > index 8d626d7..e76535e 100644 > > --- a/drivers/vhost/net.c > > +++ b/drivers/vhost/net.c > > @@ -778,8 +778,6 @@ static void handle_rx(struct vhost_net *net) > > /* On error, stop handling until the next kick. */ > > if (unlikely(headcount < 0)) > > goto out; > > - if (nvq->rx_array) > > - msg.msg_control = vhost_net_buf_consume(&nvq->rxq); > > /* On overrun, truncate and discard */ > > if (unlikely(headcount > UIO_MAXIOV)) { > > iov_iter_init(&msg.msg_iter, READ, vq->iov, 1, 1); > > @@ -809,6 +807,8 @@ static void handle_rx(struct vhost_net *net) > > */ > > iov_iter_advance(&msg.msg_iter, vhost_hlen); > > } > > + if (nvq->rx_array) > > + msg.msg_control = vhost_net_buf_consume(&nvq->rxq); > > err = sock->ops->recvmsg(sock, &msg, > > sock_len, MSG_DONTWAIT | MSG_TRUNC); > > /* Userspace might have consumed the packet meanwhile: > > -- > > 1.8.3.1 From 1585376680231153871@xxx Wed Nov 29 05:23:41 +0000 2017 X-GM-THRID: 1585331132080725538 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread