Received: by 10.213.65.68 with SMTP id h4csp991955imn; Sun, 25 Mar 2018 20:42:52 -0700 (PDT) X-Google-Smtp-Source: AG47ELtLawfXfvw3sbLKC3wIrH9shE5EPBsNbIXBYcEh6N7bb/DWWmXswr68IHgy9OuFXdGuoVaJ X-Received: by 2002:a17:902:bd46:: with SMTP id b6-v6mr38278508plx.38.1522035772750; Sun, 25 Mar 2018 20:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522035772; cv=none; d=google.com; s=arc-20160816; b=XEGs4hZAGHAWcsMYwJ1nVu25cVvJ7hbzJCqepsAGcCtSvA8J2kgKhreeQLqefttVPW +CX9KRk8S7TfYek3IopabCHa96zdKB7Hc3vR7GPYDlugK/8wyzYtuFkO/ikvNm/SmQvj PxhCyPzqH7Wgu9dAhT2e2tX7Xku0kCvs3ORDYRLa7sR/xe9Vveon5AybDS9HG4EWIpR8 yg+nT/rt3lSjNTBoSzZc6SiOnjQtPrxEGQnG3kdlgXzCUV+k7LM5hJUO7hUYNJ2plIrA AeUVkFh1xPLDFHAnAaa/nRli+DQHzMa412eB+6fYrrTJeZGJjhCaRaYkGyzW1KwFy7cH BDsw== 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=o/WxJSC1cavRfbzfaZLVAzzYdx6I1esnmU0LymXk5Jg=; b=dvWwvyD+Qngdxa2Sb7PKKEKmadStMhjnahMW9ayIBD42mdpBvsLNsdHf/mh3/dsHdr nrk0Fg2Ey4kHidmaTxfnxIDuknSCSDNkPeNjOBo+MoCtbB/4/dw9PdRevkxick1X+4iC LGaRsSvM/MmYQC/SpcBs7Y1W1p+gJElwZM8xR8lDgsFsFXUQM7k5Y62lEYBlOCS6pcUD xipPIWubMj62U624C/AmM/hO4Ps6i9te+sMtOnzlVXdT6s8B6OidIZa1QhGJE4xVCWNU psyOpompTtMuuPsL9pXfSB/WrFmC/GG5Ih8XSldh1KQy7UwSH6Zs351cQACkOt07Se3o yRUg== 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 m1si9904620pgc.757.2018.03.25.20.42.38; Sun, 25 Mar 2018 20:42:52 -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 S1752231AbeCZDjq (ORCPT + 99 others); Sun, 25 Mar 2018 23:39:46 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46708 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751074AbeCZDjp (ORCPT ); Sun, 25 Mar 2018 23:39:45 -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 565EB722C5; Mon, 26 Mar 2018 03:39:44 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-110.pek2.redhat.com [10.72.12.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B393111DD01; Mon, 26 Mar 2018 03:39:35 +0000 (UTC) From: Jason Wang To: mst@redhat.com, virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jason Wang Subject: [RFC PATCH V2 4/8] vhost_net: do not explicitly manipulate vhost_used_elem Date: Mon, 26 Mar 2018 11:38:49 +0800 Message-Id: <1522035533-11786-5-git-send-email-jasowang@redhat.com> In-Reply-To: <1522035533-11786-1-git-send-email-jasowang@redhat.com> References: <1522035533-11786-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.2]); Mon, 26 Mar 2018 03:39:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 26 Mar 2018 03:39:44 +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 7ea2aee..7be8b55 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -337,9 +337,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 @@ -537,10 +538,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 8744dae..65954d6 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2100,11 +2100,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 8399887..d57c875 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