Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2962306imm; Mon, 28 May 2018 21:03:15 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqmKXEbAa2v844O4J9QTiRPVRtMDeUkFOizFwaYi97KkL85g5oSwbe+wKT+6Rr6FL17U13a X-Received: by 2002:a63:af0e:: with SMTP id w14-v6mr12558037pge.221.1527566595553; Mon, 28 May 2018 21:03:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527566595; cv=none; d=google.com; s=arc-20160816; b=fqybubMtJu6JhBu1LLZW6ue8XzNl8Q0pHQ3zn6lJXUyLqjO3VGDj856icBe3MJqhBV m/Z9OafFzeuZUw9zKhyQQY442gqDRAssXB5QTBH9893f3umeJ8FWSWuzT1rXzWP3/PIO 733/nVmm8uANa+yXrxhHh+OLwcA9fLq1yDDsAnh3wv/2TRDoio2qtHMJM/U37PBIaIPS OhPoF+5nidLwG7L98n8rfOHXsaunAfiGvzJn8cunB9G22DEmhdJ0lemEY/1Y2iAB0E2Z k30ecpxt4JC2MtQeoqfS3Sr3VYkbeNnq53c4FJtXqk1UDpZYww7x0d1eXll1dqcPbg4p 54iw== 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=7EqlZTjDXsc+LLCw6MZNt5vWdNKcn4XBbgL1fwgsQXo=; b=YKHdJ5Xe77FYtwbOmWjYgI9FBmG3vXNyitL/8fpVZnd7Vwq9dsNPWZeYAgBvsU9Ghb BQwBsVZVffmSYKV08qWi9UJi8lXbQzG0og+kIIBjynhxynmaTueYgsbcnR26IVBzWRgM p025YRytZ43baQs5xSWBEFpQlmRzlQdVDrALVDWvkHBBtzl9ElmWebmKjDXWqiFiaYvt 249xRVfnnM8e+V8KStspQovHyEZepwHkWwbjNSW3K1/XAaV0/SFBT2iqSX7tG/u/cmAQ XQCtdnxO6NQOFSraBWFPCqvy939wi0zRoWcsVBBqTu3W6X/rx1klGmNXJocV4uMu0XTz 0B2w== 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 y8-v6si24551632pgp.527.2018.05.28.21.03.00; Mon, 28 May 2018 21:03:15 -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 S1755921AbeE2CL0 (ORCPT + 99 others); Mon, 28 May 2018 22:11:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57264 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752647AbeE2CLV (ORCPT ); Mon, 28 May 2018 22:11:21 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66A4F818BAF6; Tue, 29 May 2018 02:11:20 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-44.pek2.redhat.com [10.72.12.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 672FE10F1C0A; Tue, 29 May 2018 02:11:09 +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, jfreimann@redhat.com, wexu@redhat.com, tiwei.bie@intel.com Subject: [RFC V5 PATCH 4/8] vhost_net: do not explicitly manipulate vhost_used_elem Date: Tue, 29 May 2018 10:10:26 +0800 Message-Id: <1527559830-8133-5-git-send-email-jasowang@redhat.com> In-Reply-To: <1527559830-8133-1-git-send-email-jasowang@redhat.com> References: <1527559830-8133-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 29 May 2018 02:11:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 29 May 2018 02:11:20 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 Two helpers of setting/getting used len were introduced to avoid explicitly manipulating vhost_used_elem in zerocopy code. This will be used to hide used_elem internals and simplify packed ring implementation. Signed-off-by: Jason Wang --- drivers/vhost/net.c | 11 +++++------ drivers/vhost/vhost.c | 12 ++++++++++-- drivers/vhost/vhost.h | 5 +++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 3826f1f..30273ad 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -341,9 +341,10 @@ static void vhost_zerocopy_signal_used(struct vhost_net *net, int j = 0; for (i = nvq->done_idx; i != nvq->upend_idx; i = (i + 1) % UIO_MAXIOV) { - if (vq->heads[i].elem.len == VHOST_DMA_FAILED_LEN) + if (vhost_get_used_len(vq, &vq->heads[i]) == + VHOST_DMA_FAILED_LEN) vhost_net_tx_err(net); - if (VHOST_DMA_IS_DONE(vq->heads[i].elem.len)) { + if (VHOST_DMA_IS_DONE(vhost_get_used_len(vq, &vq->heads[i]))) { vq->heads[i].elem.len = VHOST_DMA_CLEAR_LEN; ++j; } else @@ -542,10 +543,8 @@ static void handle_tx(struct vhost_net *net) struct ubuf_info *ubuf; ubuf = nvq->ubuf_info + nvq->upend_idx; - vq->heads[nvq->upend_idx].elem.id = - cpu_to_vhost32(vq, used.elem.id); - vq->heads[nvq->upend_idx].elem.len = - VHOST_DMA_IN_PROGRESS; + vhost_set_used_len(vq, &used, VHOST_DMA_IN_PROGRESS); + vq->heads[nvq->upend_idx] = used; ubuf->callback = vhost_zerocopy_callback; ubuf->ctx = nvq->ubufs; ubuf->desc = nvq->upend_idx; diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 2b2a776..e0fcfec 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2067,11 +2067,19 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq, } EXPORT_SYMBOL_GPL(vhost_get_vq_desc); -static void vhost_set_used_len(struct vhost_virtqueue *vq, - struct vhost_used_elem *used, int len) +void vhost_set_used_len(struct vhost_virtqueue *vq, + struct vhost_used_elem *used, int len) { used->elem.len = cpu_to_vhost32(vq, len); } +EXPORT_SYMBOL_GPL(vhost_set_used_len); + +int vhost_get_used_len(struct vhost_virtqueue *vq, + struct vhost_used_elem *used) +{ + return vhost32_to_cpu(vq, used->elem.len); +} +EXPORT_SYMBOL_GPL(vhost_get_used_len); /* This is a multi-buffer version of vhost_get_desc, that works if * vq has read descriptors only. diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 8dea44b..604821b 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -198,6 +198,11 @@ int vhost_get_bufs(struct vhost_virtqueue *vq, unsigned *log_num, unsigned int quota, s16 *count); +void vhost_set_used_len(struct vhost_virtqueue *vq, + struct vhost_used_elem *used, + int len); +int vhost_get_used_len(struct vhost_virtqueue *vq, + struct vhost_used_elem *used); void vhost_discard_vq_desc(struct vhost_virtqueue *, int n); int vhost_vq_init_access(struct vhost_virtqueue *); -- 2.7.4