From patchwork Thu Jan 4 07:41:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Wang X-Patchwork-Id: 32860 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B977B1B01F; Thu, 4 Jan 2018 00:06:30 +0100 (CET) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id D963F1B020 for ; Thu, 4 Jan 2018 00:06:28 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jan 2018 15:06:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,504,1508828400"; d="scan'208";a="24053273" Received: from dpdk-xiao-1.sh.intel.com ([10.67.110.153]) by orsmga002.jf.intel.com with ESMTP; 03 Jan 2018 15:06:04 -0800 From: Xiao Wang To: tiwei.bie@intel.com Cc: dev@dpdk.org, yliu@fridaylinux.org, stephen@networkplumber.org, Xiao Wang Date: Wed, 3 Jan 2018 23:41:39 -0800 Message-Id: <1515051700-117262-2-git-send-email-xiao.w.wang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1515051700-117262-1-git-send-email-xiao.w.wang@intel.com> References: <1512396128-119985-3-git-send-email-xiao.w.wang@intel.com> <1515051700-117262-1-git-send-email-xiao.w.wang@intel.com> Subject: [dpdk-dev] [PATCH v3 1/2] net/virtio: make control queue thread-safe X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The virtio_send_command function may be called from app's configuration routine, but also from an interrupt handler called when live migration is done on the backup side. So this patch makes control queue thread-safe first. Signed-off-by: Xiao Wang --- v2: - Use spaces instead of tabs between the code and comments. - Remove unnecessary parentheses. --- drivers/net/virtio/virtio_ethdev.c | 7 ++++++- drivers/net/virtio/virtio_rxtx.c | 1 + drivers/net/virtio/virtio_rxtx.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index e0328f6..ac73950 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -177,6 +177,8 @@ struct rte_virtio_xstats_name_off { PMD_INIT_LOG(ERR, "Control queue is not supported."); return -1; } + + rte_spinlock_lock(&cvq->sl); vq = cvq->vq; head = vq->vq_desc_head_idx; @@ -184,8 +186,10 @@ struct rte_virtio_xstats_name_off { "vq->hw->cvq = %p vq = %p", vq->vq_desc_head_idx, status, vq->hw->cvq, vq); - if ((vq->vq_free_cnt < ((uint32_t)pkt_num + 2)) || (pkt_num < 1)) + if (vq->vq_free_cnt < pkt_num + 2 || pkt_num < 1) { + rte_spinlock_unlock(&cvq->sl); return -1; + } memcpy(cvq->virtio_net_hdr_mz->addr, ctrl, sizeof(struct virtio_pmd_ctrl)); @@ -261,6 +265,7 @@ struct rte_virtio_xstats_name_off { result = cvq->virtio_net_hdr_mz->addr; + rte_spinlock_unlock(&cvq->sl); return result->status; } diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index 390c137..6a24fde 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -407,6 +407,7 @@ struct virtio_hw *hw = dev->data->dev_private; if (hw->cvq && hw->cvq->vq) { + rte_spinlock_init(&hw->cvq->sl); VIRTQUEUE_DUMP((struct virtqueue *)hw->cvq->vq); } } diff --git a/drivers/net/virtio/virtio_rxtx.h b/drivers/net/virtio/virtio_rxtx.h index 54f1e84..71b5798 100644 --- a/drivers/net/virtio/virtio_rxtx.h +++ b/drivers/net/virtio/virtio_rxtx.h @@ -84,6 +84,7 @@ struct virtnet_ctl { rte_iova_t virtio_net_hdr_mem; /**< hdr for each xmit packet */ uint16_t port_id; /**< Device port identifier. */ const struct rte_memzone *mz; /**< mem zone to populate CTL ring. */ + rte_spinlock_t sl; /**< spinlock for control queue. */ }; int virtio_rxq_vec_setup(struct virtnet_rx *rxvq);