From: Xiao Wang Date: Wed, 10 Jan 2018 01:23:52 +0000 (+0800) Subject: net/virtio: make control queue thread-safe X-Git-Tag: spdx-start~310 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=a2ffb87b1b60ded74a5e73be69503065faa827c7;p=dpdk.git net/virtio: make control queue thread-safe 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 Reviewed-by: Maxime Coquelin --- diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 954989efc0..e6b537b17f 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -151,6 +151,8 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, PMD_INIT_LOG(ERR, "Control queue is not supported."); return -1; } + + rte_spinlock_lock(&cvq->lock); vq = cvq->vq; head = vq->vq_desc_head_idx; @@ -158,8 +160,10 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, "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->lock); return -1; + } memcpy(cvq->virtio_net_hdr_mz->addr, ctrl, sizeof(struct virtio_pmd_ctrl)); @@ -235,6 +239,7 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, result = cvq->virtio_net_hdr_mz->addr; + rte_spinlock_unlock(&cvq->lock); return result->status; } diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index 994458ced2..265debf203 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -378,6 +378,7 @@ virtio_dev_cq_start(struct rte_eth_dev *dev) struct virtio_hw *hw = dev->data->dev_private; if (hw->cvq && hw->cvq->vq) { + rte_spinlock_init(&hw->cvq->lock); VIRTQUEUE_DUMP((struct virtqueue *)hw->cvq->vq); } } diff --git a/drivers/net/virtio/virtio_rxtx.h b/drivers/net/virtio/virtio_rxtx.h index ca546ccaa9..49e9d98eec 100644 --- a/drivers/net/virtio/virtio_rxtx.h +++ b/drivers/net/virtio/virtio_rxtx.h @@ -55,6 +55,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 lock; /**< spinlock for control queue. */ }; int virtio_rxq_vec_setup(struct virtnet_rx *rxvq);