From patchwork Mon May 10 16:43:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 98212 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4AGlDqG023717 for ; Mon, 10 May 2010 16:47:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754524Ab0EJQrL (ORCPT ); Mon, 10 May 2010 12:47:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13831 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752539Ab0EJQrK (ORCPT ); Mon, 10 May 2010 12:47:10 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4AGl1vQ003006 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 10 May 2010 12:47:01 -0400 Received: from redhat.com (vpn-6-12.tlv.redhat.com [10.35.6.12]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o4AGkwlH007454; Mon, 10 May 2010 12:46:59 -0400 Date: Mon, 10 May 2010 19:43:03 +0300 From: "Michael S. Tsirkin" To: David L Stevens Cc: netdev@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.osdl.org Subject: Re: [PATCHv7] add mergeable buffers support to vhost_net Message-ID: <20100510164303.GA28798@redhat.com> References: <1272488232.11307.4.camel@w-dls.beaverton.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1272488232.11307.4.camel@w-dls.beaverton.ibm.com> User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 10 May 2010 16:47:14 +0000 (UTC) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index c16db02..9d7496d 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -219,7 +219,7 @@ static int peek_head_len(struct vhost_virtqueue *vq, struct sock *sk) /* This is a multi-buffer version of vhost_get_desc, that works if * vq has read descriptors only. * @vq - the relevant virtqueue - * @datalen - data length we'll be reading + * @datalen - data length we'll be reading. must be > 0 * @iovcount - returned count of io vectors we fill * @log - vhost log * @log_num - log offset @@ -236,9 +236,10 @@ static int get_rx_bufs(struct vhost_virtqueue *vq, int seg = 0; int headcount = 0; unsigned d; + size_t len; int r, nlogs = 0; - while (datalen > 0) { + for (;;) { if (unlikely(headcount >= VHOST_NET_MAX_SG)) { r = -ENOBUFS; goto err; @@ -260,16 +261,20 @@ static int get_rx_bufs(struct vhost_virtqueue *vq, nlogs += *log_num; log += *log_num; } + len = iov_length(vq->iov + seg, in); + seg += in; heads[headcount].id = d; - heads[headcount].len = iov_length(vq->iov + seg, in); - datalen -= heads[headcount].len; + if (datalen <= len) + break; + heads[headcount].len = len; ++headcount; - seg += in; + datalen -= len; } + heads[headcount].len = datalen; *iovcount = seg; if (unlikely(log)) *log_num = nlogs; - return headcount; + return headcount + 1; err: vhost_discard_desc(vq, headcount); return r;