Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp59245imm; Mon, 21 May 2018 02:10:19 -0700 (PDT) X-Google-Smtp-Source: AB8JxZobNRzzSfBTVGPI5+WxioITtYXALQ+6c1NSslkuzDmV8rV9Tyzyw0h06IA5hURV40LIjJfg X-Received: by 2002:a62:f58b:: with SMTP id b11-v6mr19253809pfm.113.1526893819578; Mon, 21 May 2018 02:10:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526893819; cv=none; d=google.com; s=arc-20160816; b=roiMPk/fGl0MA8PMpHlL8twgcCLl8htCoGCtxE6hcqqDFx6PYLnHhwHsqTIBnUHH83 aH9cP+ZKasAdB/9wJbTBZ8uj/1yguqIpMPCt8NC4L8rqQYG6E7E6xVXmZvH9b17irkjm dzZOF6d9gbcr6KG4Mc7vmCel4NJcIkZCn1bT3JWTHbju/rsReyTPeDUlYLhTprzCJCoO 49KCDZ2Lb0dFWKhm61gJ7N9lG4mHc47p3jAyRY9rrVzbDgOU2+slUJIdIynVuOwtGHas QdicYC/RvOo0dR3MN4A54Di0WsvS6lRvvniCpKGMMKH4fmRcnu0i0w2MiAGEcXxZJyHx ZTvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=8meRJOzrA2jeMVRuDhc0bysgPT0hMRmt1hdPEdblJ2Q=; b=eFqkB7dVAUBvYaJIzyFyyG+s4b8cFCxAQFlGNz3IwYT1yRtuATOtZxvCBxCcu3qAXR tUZf+Rb9ZQbryjWWZGC9BIFkJlb0WespAERAAl7LNc+EWAFzT54hzkMXe6baSPheplYp 8gSFC7qPHPp5KsAYDipwxxZID3XPkky4sFsxwBqmYtAMKlthDQoOhmFCjG/IgpYby/Tb 6yLFXAq86BoS7SUMRCZUlXAbkR6boh2YqRx6/BZdB1y51cyoMVdtCj7KTZMxUOjLMV2P bSu0sGioW31NG6XkXwySnCukzgo0m4tV6p+K6R3gcFkFMlVe1xTuKrr9PjjupV+RZGqj P3Bw== 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 f69-v6si13971030plb.503.2018.05.21.02.10.05; Mon, 21 May 2018 02:10:19 -0700 (PDT) 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 S1752231AbeEUJEz (ORCPT + 99 others); Mon, 21 May 2018 05:04:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54666 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751557AbeEUJEp (ORCPT ); Mon, 21 May 2018 05:04:45 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2504C400E9A7; Mon, 21 May 2018 09:04:45 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D2944E68B; Mon, 21 May 2018 09:04:41 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net-next 01/12] vhost_net: introduce helper to initialize tx iov iter Date: Mon, 21 May 2018 17:04:22 +0800 Message-Id: <1526893473-20128-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1526893473-20128-1-git-send-email-jasowang@redhat.com> References: <1526893473-20128-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 21 May 2018 09:04:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 21 May 2018 09:04:45 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jasowang@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Jason Wang --- drivers/vhost/net.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index c4b49fc..15d191a 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -459,6 +459,26 @@ static bool vhost_exceeds_maxpend(struct vhost_net *net) min_t(unsigned int, VHOST_MAX_PEND, vq->num >> 2); } +static size_t init_iov_iter(struct vhost_virtqueue *vq, struct iov_iter *iter, + size_t hdr_size, int out) +{ + /* Skip header. TODO: support TSO. */ + size_t len = iov_length(vq->iov, out); + + iov_iter_init(iter, WRITE, vq->iov, out, len); + iov_iter_advance(iter, hdr_size); + /* Sanity check */ + if (!iov_iter_count(iter)) { + vq_err(vq, "Unexpected header len for TX: " + "%zd expected %zd\n", + len, hdr_size); + return -EFAULT; + } + len = iov_iter_count(iter); + + return len; +} + /* Expects to be always run from workqueue - which acts as * read-size critical section for our kind of RCU. */ static void handle_tx(struct vhost_net *net) @@ -521,18 +541,10 @@ static void handle_tx(struct vhost_net *net) "out %d, int %d\n", out, in); break; } - /* Skip header. TODO: support TSO. */ - len = iov_length(vq->iov, out); - iov_iter_init(&msg.msg_iter, WRITE, vq->iov, out, len); - iov_iter_advance(&msg.msg_iter, hdr_size); - /* Sanity check */ - if (!msg_data_left(&msg)) { - vq_err(vq, "Unexpected header len for TX: " - "%zd expected %zd\n", - len, hdr_size); + + len = init_iov_iter(vq, &msg.msg_iter, hdr_size, out); + if (len < 0) break; - } - len = msg_data_left(&msg); zcopy_used = zcopy && len >= VHOST_GOODCOPY_LEN && !vhost_exceeds_maxpend(net) -- 2.7.4