From patchwork Sun Jun 19 17:48:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huawei Xie X-Patchwork-Id: 14023 X-Patchwork-Delegate: yuanhan.liu@linux.intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 83E366CB1; Mon, 20 Jun 2016 11:44:01 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 4ED3F6CAC for ; Mon, 20 Jun 2016 11:44:00 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP; 20 Jun 2016 02:44:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,497,1459839600"; d="scan'208";a="831579037" Received: from dpdk15.sh.intel.com ([10.239.129.25]) by orsmga003.jf.intel.com with ESMTP; 20 Jun 2016 02:43:57 -0700 From: Huawei Xie To: dev@dpdk.org Cc: yuanhan.liu@intel.com, thomas.monjalon@6wind.com, mst@redhat.com, jianfeng.tan@intel.com, stephen@networkplumber.org, konstantin.ananyev@intel.com, bruce.richardson@intel.com, Huawei Xie Date: Mon, 20 Jun 2016 01:48:52 +0800 Message-Id: <1466358532-101416-1-git-send-email-huawei.xie@intel.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1466015437-36809-1-git-send-email-huawei.xie@intel.com> References: <1466015437-36809-1-git-send-email-huawei.xie@intel.com> Subject: [dpdk-dev] [PATCH v2] virtio: fix idx in used ring retrieved only once X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" In the following loop: while (vq->vq_used_cons_idx != vq->vq_ring.used->idx) { ... } There is no external function call or any explict memory barrier in the loop, the re-read of used->idx would be optimized and would only be retrieved once. use of voaltile normally should be prohibited, and access_once is Linux kernel's style to handle this issue; Once we have that macro in DPDK, we could change to that style. virtio_recv_mergable_pkts might have the same issue, so will be fixed. Fixes: 823ad647950a ("virtio: support multiple queues") Fixes: 13ce5e7eb94f ("virtio: mergeable buffers") Signed-off-by: Huawei Xie --- v2: use VIRTQUEUE_NUSED --- drivers/net/virtio/virtio_ethdev.c | 4 ++-- drivers/net/virtio/virtio_ring.h | 2 +- drivers/net/virtio/virtio_rxtx_simple.c | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index ea7a48e..6a51948 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -219,12 +219,12 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, virtqueue_notify(vq); rte_rmb(); - while (vq->vq_used_cons_idx == vq->vq_ring.used->idx) { + while (VIRTQUEUE_NUSED(vq) == 0) { rte_rmb(); usleep(100); } - while (vq->vq_used_cons_idx != vq->vq_ring.used->idx) { + while (VIRTQUEUE_NUSED(vq)) { uint32_t idx, desc_idx, used_idx; struct vring_used_elem *uep; diff --git a/drivers/net/virtio/virtio_ring.h b/drivers/net/virtio/virtio_ring.h index 447760a..fcecc16 100644 --- a/drivers/net/virtio/virtio_ring.h +++ b/drivers/net/virtio/virtio_ring.h @@ -79,7 +79,7 @@ struct vring_used_elem { struct vring_used { uint16_t flags; - uint16_t idx; + volatile uint16_t idx; struct vring_used_elem ring[0]; }; diff --git a/drivers/net/virtio/virtio_rxtx_simple.c b/drivers/net/virtio/virtio_rxtx_simple.c index 7b50119..242ad90 100644 --- a/drivers/net/virtio/virtio_rxtx_simple.c +++ b/drivers/net/virtio/virtio_rxtx_simple.c @@ -184,8 +184,7 @@ virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts, if (unlikely(nb_pkts < RTE_VIRTIO_DESC_PER_LOOP)) return 0; - nb_used = *(volatile uint16_t *)&vq->vq_ring.used->idx - - vq->vq_used_cons_idx; + nb_used = VIRTQUEUE_NUSED(vq); rte_compiler_barrier();