From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id 662CD1B311 for ; Thu, 15 Feb 2018 13:03:28 +0100 (CET) Received: by mail-wm0-f68.google.com with SMTP id 141so360505wme.3 for ; Thu, 15 Feb 2018 04:03:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IWVhJGOYnvPmH0HXXgzTBJABH9UtCYZlzdV9b7xhdpI=; b=OAcTkZ5QoB9c6U/mHhSFvpQC3Dy1DMLsp9I/sEiFFex2jMUkXxEJhjsuN4ei69CYPg YGHi8e/v1MQCAnXUvXEKeQdVhNa4563aTOwR6M41cV8Pf7kx28/OPmhyFibzBfAad0hG 6ictYGae8aUKd9WQ7Z4XHpAcN4dXhhFMwDcdQBS5svx7eI52s344/+dblG8dafND6GpM XFeLLZMRk34ImcpOE+jpIL4LZh5NvZSM+IxUCdna7N20cN/26F/QK2CC6um8H9gm2L2x e0Z5R0oghsDoja5HJfG5+ANMCd4rbOg/bO2v0JqaG9BYz5Rh90rqcLcC/aamcuao9zQ5 u5dg== X-Gm-Message-State: APf1xPCjyCIlPZ8Lgg2Ln8xc7SUA5zWQb2mlwjmNLrNCHFVLSE8UUoCA /M4thljPDE6PZNdNJJWtIKc= X-Google-Smtp-Source: AH8x224CYwiJgstPGeK9TY3f/Gr1xh2V+kAxuH5RXinSxU4CeT3GSAkq5ngS+YXvEpvWyoRlr9NdlA== X-Received: by 10.28.105.80 with SMTP id e77mr2008252wmc.123.1518696208052; Thu, 15 Feb 2018 04:03:28 -0800 (PST) Received: from localhost ([213.251.34.146]) by smtp.gmail.com with ESMTPSA id r1sm13625643wmg.22.2018.02.15.04.03.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Feb 2018 04:03:27 -0800 (PST) From: Luca Boccassi To: Maxime Coquelin Cc: Olivier Matz , Tiwei Bie , Jianfeng Tan , dpdk stable Date: Thu, 15 Feb 2018 12:03:05 +0000 Message-Id: <20180215120309.28937-3-bluca@debian.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180215120309.28937-1-bluca@debian.org> References: <20180211124911.14557-2-bluca@debian.org> <20180215120309.28937-1-bluca@debian.org> Subject: [dpdk-stable] patch 'net/virtio: fix resuming port with Rx vector path' has been queued to LTS release 16.11.5 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Feb 2018 12:03:28 -0000 Hi, FYI, your patch has been queued to LTS release 16.11.5 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 02/17/18. So please shout if anyone has objections. Thanks. Luca Boccassi --- >>From a7fd826d344d65863e9164bf5dbf45c6d0d6ae7d Mon Sep 17 00:00:00 2001 From: Maxime Coquelin Date: Mon, 12 Feb 2018 16:46:11 +0100 Subject: [PATCH] net/virtio: fix resuming port with Rx vector path [ upstream commit 478574706638ff78cbc7e82731a4eae743322ac6 ] Since commit efc83a1e7fc3 ("net/virtio: fix queue setup consistency"), when resuming a virtio port, the rx rings are refilled with new mbufs until they are full (vq->vq_free_cnt == 0). This is done without ensuring that the descriptor index remains a multiple of RTE_VIRTIO_VPMD_RX_REARM_THRESH, which is a prerequisite when using the vector mode. This can cause an out of bound access in the rx ring. This commit changes the vector refill method from virtqueue_enqueue_recv_refill_simple() to virtio_rxq_rearm_vec(), which properly checks that the refill is done by batch of RTE_VIRTIO_VPMD_RX_REARM_THRESH. As virtqueue_enqueue_recv_refill_simple() is no more used, this patch also removes the function. Fixes: efc83a1e7fc3 ("net/virtio: fix queue setup consistency") Signed-off-by: Maxime Coquelin Signed-off-by: Olivier Matz Signed-off-by: Tiwei Bie Reviewed-by: Jianfeng Tan --- drivers/net/virtio/virtio_rxtx.c | 38 ++++++++++++++++++--------------- drivers/net/virtio/virtio_rxtx.h | 3 --- drivers/net/virtio/virtio_rxtx_simple.c | 31 +-------------------------- drivers/net/virtio/virtio_rxtx_simple.h | 2 +- 4 files changed, 23 insertions(+), 51 deletions(-) diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index 285af8a37..c2fe9eb57 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -61,6 +61,7 @@ #include "virtio_pci.h" #include "virtqueue.h" #include "virtio_rxtx.h" +#include "virtio_rxtx_simple.h" #ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP #define VIRTIO_DUMP_PACKET(m, len) rte_pktmbuf_dump(stdout, m, len) @@ -458,6 +459,8 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx) vq->vq_ring.desc[desc_idx].flags = VRING_DESC_F_WRITE; } + + virtio_rxq_vec_setup(rxvq); } memset(&rxvq->fake_mbuf, 0, sizeof(rxvq->fake_mbuf)); @@ -467,30 +470,31 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx) &rxvq->fake_mbuf; } - while (!virtqueue_full(vq)) { - m = rte_mbuf_raw_alloc(rxvq->mpool); - if (m == NULL) - break; + if (hw->use_simple_rxtx) { + while (vq->vq_free_cnt >= RTE_VIRTIO_VPMD_RX_REARM_THRESH) { + virtio_rxq_rearm_vec(rxvq); + nbufs += RTE_VIRTIO_VPMD_RX_REARM_THRESH; + } + } else { + while (!virtqueue_full(vq)) { + m = rte_mbuf_raw_alloc(rxvq->mpool); + if (m == NULL) + break; - /* Enqueue allocated buffers */ - if (hw->use_simple_rxtx) - error = virtqueue_enqueue_recv_refill_simple(vq, m); - else + /* Enqueue allocated buffers */ error = virtqueue_enqueue_recv_refill(vq, m); - - if (error) { - rte_pktmbuf_free(m); - break; + if (error) { + rte_pktmbuf_free(m); + break; + } + nbufs++; } - nbufs++; + + vq_update_avail_idx(vq); } - vq_update_avail_idx(vq); - PMD_INIT_LOG(DEBUG, "Allocated %d bufs", nbufs); - virtio_rxq_vec_setup(rxvq); - VIRTQUEUE_DUMP(vq); return 0; diff --git a/drivers/net/virtio/virtio_rxtx.h b/drivers/net/virtio/virtio_rxtx.h index 28f82d6a8..e2db823d4 100644 --- a/drivers/net/virtio/virtio_rxtx.h +++ b/drivers/net/virtio/virtio_rxtx.h @@ -88,7 +88,4 @@ struct virtnet_ctl { int virtio_rxq_vec_setup(struct virtnet_rx *rxvq); -int virtqueue_enqueue_recv_refill_simple(struct virtqueue *vq, - struct rte_mbuf *m); - #endif /* _VIRTIO_RXTX_H_ */ diff --git a/drivers/net/virtio/virtio_rxtx_simple.c b/drivers/net/virtio/virtio_rxtx_simple.c index aa29b6eec..5285c2b18 100644 --- a/drivers/net/virtio/virtio_rxtx_simple.c +++ b/drivers/net/virtio/virtio_rxtx_simple.c @@ -57,35 +57,6 @@ #pragma GCC diagnostic ignored "-Wcast-qual" #endif -int __attribute__((cold)) -virtqueue_enqueue_recv_refill_simple(struct virtqueue *vq, - struct rte_mbuf *cookie) -{ - struct vq_desc_extra *dxp; - struct vring_desc *start_dp; - uint16_t desc_idx; - - cookie->port = vq->rxq.port_id; - cookie->data_off = RTE_PKTMBUF_HEADROOM; - - desc_idx = vq->vq_avail_idx & (vq->vq_nentries - 1); - dxp = &vq->vq_descx[desc_idx]; - dxp->cookie = (void *)cookie; - vq->sw_ring[desc_idx] = cookie; - - start_dp = vq->vq_ring.desc; - start_dp[desc_idx].addr = - VIRTIO_MBUF_ADDR(cookie, vq) + - RTE_PKTMBUF_HEADROOM - vq->hw->vtnet_hdr_size; - start_dp[desc_idx].len = cookie->buf_len - - RTE_PKTMBUF_HEADROOM + vq->hw->vtnet_hdr_size; - - vq->vq_free_cnt--; - vq->vq_avail_idx++; - - return 0; -} - uint16_t virtio_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) @@ -103,7 +74,7 @@ virtio_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts, rte_compiler_barrier(); if (nb_used >= VIRTIO_TX_FREE_THRESH) - virtio_xmit_cleanup(vq); + virtio_xmit_cleanup_simple(vq); nb_commit = nb_pkts = RTE_MIN((vq->vq_free_cnt >> 1), nb_pkts); desc_idx = (uint16_t)(vq->vq_avail_idx & desc_idx_max); diff --git a/drivers/net/virtio/virtio_rxtx_simple.h b/drivers/net/virtio/virtio_rxtx_simple.h index b08f85948..bca677c0f 100644 --- a/drivers/net/virtio/virtio_rxtx_simple.h +++ b/drivers/net/virtio/virtio_rxtx_simple.h @@ -89,7 +89,7 @@ virtio_rxq_rearm_vec(struct virtnet_rx *rxvq) #define VIRTIO_TX_FREE_NR 32 /* TODO: vq->tx_free_cnt could mean num of free slots so we could avoid shift */ static inline void -virtio_xmit_cleanup(struct virtqueue *vq) +virtio_xmit_cleanup_simple(struct virtqueue *vq) { uint16_t i, desc_idx; uint32_t nb_free = 0; -- 2.14.2