Received: by 10.223.164.202 with SMTP id h10csp3313414wrb; Tue, 28 Nov 2017 09:19:43 -0800 (PST) X-Google-Smtp-Source: AGs4zMZhkggyEmHOuoxn5DHChFKXCNQ3LpjtAebY6ENxoQEoaDvpL4iclYvgX+MgZvIgQXVmo/uE X-Received: by 10.98.74.19 with SMTP id x19mr41366434pfa.43.1511889583663; Tue, 28 Nov 2017 09:19:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511889583; cv=none; d=google.com; s=arc-20160816; b=uYXb4EHFLDVp71IhSoQK492vLHf6qyH1uNS+oXUS7xiXyfX7To9c3TKp/q7zBbN0OJ ugT2AMYwuA36pdPJFAYaUk4T8I7SKUIP1PmtnI+UU9Xsx+y4o+VvUa0OjW65u6KgIIFY OJArwClfJ0FHp7GM9zx3t7cKGeLUlUlx3eunkqMnSR+MxEPXPv4IP4kWrKeQZ+3/YsHz AWivfhdpI7HxQ38qVVZvyWjVqc7Mmg9z0pVnN7XeltZmKyH/OQtX+vj6OpVqJ42NicKB pJcRY2QHdlQ5wS1nHaoN0h4NGJ624XWbY1jf1FzH0WGAzr424zQO88aWELEv28G09byf CrYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=WtzqybDAwfLaVjxELK/8Stzgzj72k0+GYxgwqhaQGcs=; b=0L0kg39fmxfKbd7SEF10L977sz7GBKB/Liwm4eOtqJFeQ7h4R8cgwGfdFQjwer4Mtz aow+5515cvy0BdmMk+N04X+iBGOgTrM+Se4jIrtQ7StWlvGa3RtWN5aRcMEd2OQTIgMT iPG8tzya0jYTpow0yn+QMh40MPMCDzW0Wyq1zVB9cdVL9Az6g8AudwrEXRc3aVgJLMVs /7A49J7m6l8qow19m3lREozifwFYHds1CvST+5X7fyL4yKOUvOrusIl85xugfU5tiinV f4oohh3vHvhV5KMKHceLcQ9YlcSKq3Wx16cVwScfoK6rfbxqgJz6SYxu7swge8Mmk0tN 2PLQ== 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 78si24392783pfq.361.2017.11.28.09.19.31; Tue, 28 Nov 2017 09:19:43 -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 S1753881AbdK1RSS (ORCPT + 78 others); Tue, 28 Nov 2017 12:18:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50462 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752602AbdK1RSQ (ORCPT ); Tue, 28 Nov 2017 12:18:16 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA84D13AAE; Tue, 28 Nov 2017 17:18:16 +0000 (UTC) Received: from hp-bl660cgen9-01.khw.lab.eng.bos.redhat.com (hp-bl660cgen9-01.khw.lab.eng.bos.redhat.com [10.16.184.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BB7F5D965; Tue, 28 Nov 2017 17:18:13 +0000 (UTC) From: wexu@redhat.com To: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jasowang@redhat.com, mst@redhat.com, mjrosato@linux.vnet.ibm.com, wexu@redhat.com Subject: [PATCH net,stable] vhost: fix skb leak in handle_rx() Date: Tue, 28 Nov 2017 12:17:16 -0500 Message-Id: <1511889436-12876-1-git-send-email-wexu@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 28 Nov 2017 17:18:16 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 1589693977183384363@xxx Mon Jan 15 21:05:16 +0000 2018 X-GM-THRID: 1585510398109779840 X-Gmail-Labels: Inbox,Category Forums,Downloaded_2018-01