DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/virtio: fix Rx scatter offload
@ 2021-07-06 14:14 Andrew Rybchenko
  2021-07-13  9:27 ` Maxime Coquelin
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Andrew Rybchenko @ 2021-07-06 14:14 UTC (permalink / raw)
  To: Maxime Coquelin, Chenbo Xia, Konstantin Ananyev, Shahaf Shuler,
	Andrew Rybchenko
  Cc: dev, Ivan Ilchenko, stable

From: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>

Report Rx scatter offload capability depending on VIRTIO_NET_F_MRG_RXBUF.

If Rx scatter is not requested, ensure that provided Rx buffers on
each Rx queue are big enough to fit Rx packets up to configured MTU.

Fixes: ce17eddefc20 ("ethdev: introduce Rx queue offloads API")
Cc: stable@dpdk.org

Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/net/virtio/virtio.h        |  2 +
 drivers/net/virtio/virtio_ethdev.c | 63 ++++++++++++++++++++++++++++++
 drivers/net/virtio/virtio_ethdev.h |  5 +++
 drivers/net/virtio/virtio_rxtx.c   | 10 +++++
 4 files changed, 80 insertions(+)

diff --git a/drivers/net/virtio/virtio.h b/drivers/net/virtio/virtio.h
index 2c987d19ab..525e2dad4c 100644
--- a/drivers/net/virtio/virtio.h
+++ b/drivers/net/virtio/virtio.h
@@ -167,6 +167,7 @@ struct virtio_hw {
 	uint8_t started;
 	uint8_t weak_barriers;
 	uint8_t vlan_strip;
+	bool rx_ol_scatter;
 	uint8_t has_tx_offload;
 	uint8_t has_rx_offload;
 	uint8_t use_vec_rx;
@@ -180,6 +181,7 @@ struct virtio_hw {
 	uint8_t duplex;
 	uint8_t intr_lsc;
 	uint16_t max_mtu;
+	size_t max_rx_pkt_len;
 	/*
 	 * App management thread and virtio interrupt handler thread
 	 * both can change device state, this lock is meant to avoid
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 0568305667..6d6e105960 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -841,6 +841,54 @@ virtio_dev_allmulticast_disable(struct rte_eth_dev *dev)
 	return 0;
 }
 
+uint16_t
+virtio_rx_mem_pool_buf_size(struct rte_mempool *mp)
+{
+	return rte_pktmbuf_data_room_size(mp) - RTE_PKTMBUF_HEADROOM;
+}
+
+bool
+virtio_rx_check_scatter(uint16_t max_rx_pkt_len, uint16_t rx_buf_size,
+			bool rx_scatter_enabled, const char **error)
+{
+	if (!rx_scatter_enabled && max_rx_pkt_len > rx_buf_size) {
+		*error = "Rx scatter is disabled and RxQ mbuf pool object size is too small";
+		return false;
+	}
+
+	return true;
+}
+
+static bool
+virtio_check_scatter_on_all_rx_queues(struct rte_eth_dev *dev,
+				      uint16_t frame_size)
+{
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtnet_rx *rxvq;
+	struct virtqueue *vq;
+	unsigned int qidx;
+	uint16_t buf_size;
+	const char *error;
+
+	if (hw->vqs == NULL)
+		return true;
+
+	for (qidx = 0; (vq = hw->vqs[2 * qidx + VTNET_SQ_RQ_QUEUE_IDX]) != NULL;
+	     qidx++) {
+		rxvq = &vq->rxq;
+		buf_size = virtio_rx_mem_pool_buf_size(rxvq->mpool);
+
+		if (!virtio_rx_check_scatter(frame_size, buf_size,
+					     hw->rx_ol_scatter, &error)) {
+			PMD_INIT_LOG(ERR, "MTU check for RxQ %u failed: %s",
+				     qidx, error);
+			return false;
+		}
+	}
+
+	return true;
+}
+
 #define VLAN_TAG_LEN           4    /* 802.3ac tag (not DMA'd) */
 static int
 virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
@@ -858,6 +906,15 @@ virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 			RTE_ETHER_MIN_MTU, max_frame_size - ether_hdr_len);
 		return -EINVAL;
 	}
+
+	if (!virtio_check_scatter_on_all_rx_queues(dev, frame_size)) {
+		PMD_INIT_LOG(ERR, "MTU vs Rx scatter and Rx buffers check failed");
+		return -EINVAL;
+	}
+
+	hw->max_rx_pkt_len = frame_size;
+	dev->data->dev_conf.rxmode.max_rx_pkt_len = hw->max_rx_pkt_len;
+
 	return 0;
 }
 
@@ -2042,6 +2099,8 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 	if (rxmode->max_rx_pkt_len > hw->max_mtu + ether_hdr_len)
 		req_features &= ~(1ULL << VIRTIO_NET_F_MTU);
 
+	hw->max_rx_pkt_len = rxmode->max_rx_pkt_len;
+
 	if (rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM |
 			   DEV_RX_OFFLOAD_TCP_CKSUM))
 		req_features |= (1ULL << VIRTIO_NET_F_GUEST_CSUM);
@@ -2090,6 +2149,8 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 	if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
 		hw->vlan_strip = 1;
 
+	hw->rx_ol_scatter = (rx_offloads & DEV_RX_OFFLOAD_SCATTER);
+
 	if ((rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER) &&
 			!virtio_with_feature(hw, VIRTIO_NET_F_CTRL_VLAN)) {
 		PMD_DRV_LOG(ERR,
@@ -2445,6 +2506,8 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	host_features = VIRTIO_OPS(hw)->get_features(hw);
 	dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
 	dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+	if (host_features & (1ULL << VIRTIO_NET_F_MRG_RXBUF))
+		dev_info->rx_offload_capa = DEV_RX_OFFLOAD_SCATTER;
 	if (host_features & (1ULL << VIRTIO_NET_F_GUEST_CSUM)) {
 		dev_info->rx_offload_capa |=
 			DEV_RX_OFFLOAD_TCP_CKSUM |
diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h
index 5a501e7890..2f63ef2b2d 100644
--- a/drivers/net/virtio/virtio_ethdev.h
+++ b/drivers/net/virtio/virtio_ethdev.h
@@ -120,4 +120,9 @@ int virtio_dev_close(struct rte_eth_dev *dev);
 int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
 		int nb_pkts);
 
+bool virtio_rx_check_scatter(uint16_t max_rx_pkt_len, uint16_t rx_buf_size,
+			bool rx_scatter_enabled, const char **error);
+
+uint16_t virtio_rx_mem_pool_buf_size(struct rte_mempool *mp);
+
 #endif /* _VIRTIO_ETHDEV_H_ */
diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index 34108fb946..511b3d71b1 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -634,6 +634,8 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 	struct virtqueue *vq = hw->vqs[vq_idx];
 	struct virtnet_rx *rxvq;
 	uint16_t rx_free_thresh;
+	uint16_t buf_size;
+	const char *error;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -642,6 +644,14 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 		return -EINVAL;
 	}
 
+	buf_size = virtio_rx_mem_pool_buf_size(mp);
+	if (!virtio_rx_check_scatter(hw->max_rx_pkt_len, buf_size,
+				     hw->rx_ol_scatter, &error)) {
+		PMD_INIT_LOG(ERR, "RxQ %u Rx scatter check failed: %s",
+			     queue_idx, error);
+		return -EINVAL;
+	}
+
 	rx_free_thresh = rx_conf->rx_free_thresh;
 	if (rx_free_thresh == 0)
 		rx_free_thresh =
-- 
2.30.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH] net/virtio: fix Rx scatter offload
  2021-07-06 14:14 [dpdk-dev] [PATCH] net/virtio: fix Rx scatter offload Andrew Rybchenko
@ 2021-07-13  9:27 ` Maxime Coquelin
  2021-07-19 19:15 ` [dpdk-dev] [PATCH v2] " Andrew Rybchenko
  2021-07-20  7:54 ` [dpdk-dev] [PATCH v3] " Andrew Rybchenko
  2 siblings, 0 replies; 9+ messages in thread
From: Maxime Coquelin @ 2021-07-13  9:27 UTC (permalink / raw)
  To: Andrew Rybchenko, Chenbo Xia, Konstantin Ananyev, Shahaf Shuler,
	Andrew Rybchenko
  Cc: dev, Ivan Ilchenko, stable



On 7/6/21 4:14 PM, Andrew Rybchenko wrote:
> From: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
> 
> Report Rx scatter offload capability depending on VIRTIO_NET_F_MRG_RXBUF.
> 
> If Rx scatter is not requested, ensure that provided Rx buffers on
> each Rx queue are big enough to fit Rx packets up to configured MTU.
> 
> Fixes: ce17eddefc20 ("ethdev: introduce Rx queue offloads API")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> ---
>  drivers/net/virtio/virtio.h        |  2 +
>  drivers/net/virtio/virtio_ethdev.c | 63 ++++++++++++++++++++++++++++++
>  drivers/net/virtio/virtio_ethdev.h |  5 +++
>  drivers/net/virtio/virtio_rxtx.c   | 10 +++++
>  4 files changed, 80 insertions(+)
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH v2] net/virtio: fix Rx scatter offload
  2021-07-06 14:14 [dpdk-dev] [PATCH] net/virtio: fix Rx scatter offload Andrew Rybchenko
  2021-07-13  9:27 ` Maxime Coquelin
@ 2021-07-19 19:15 ` Andrew Rybchenko
  2021-07-19 19:38   ` Andrew Rybchenko
  2021-07-20  7:54 ` [dpdk-dev] [PATCH v3] " Andrew Rybchenko
  2 siblings, 1 reply; 9+ messages in thread
From: Andrew Rybchenko @ 2021-07-19 19:15 UTC (permalink / raw)
  To: Maxime Coquelin, Chenbo Xia, Konstantin Ananyev,
	Andrew Rybchenko, Shahaf Shuler
  Cc: dev, Ivan Ilchenko, stable

From: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>

Report Rx scatter offload capability depending on VIRTIO_NET_F_MRG_RXBUF.

If Rx scatter is not requested, ensure that provided Rx buffers on
each Rx queue are big enough to fit Rx packets up to configured MTU.

Fixes: ce17eddefc20 ("ethdev: introduce Rx queue offloads API")
Cc: stable@dpdk.org

Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
v2:
 - do not overwrite Rx offloads when Rx scatter is added

 drivers/net/virtio/virtio.h        |  2 +
 drivers/net/virtio/virtio_ethdev.c | 63 ++++++++++++++++++++++++++++++
 drivers/net/virtio/virtio_ethdev.h |  5 +++
 drivers/net/virtio/virtio_rxtx.c   | 10 +++++
 4 files changed, 80 insertions(+)

diff --git a/drivers/net/virtio/virtio.h b/drivers/net/virtio/virtio.h
index 2c987d19ab..525e2dad4c 100644
--- a/drivers/net/virtio/virtio.h
+++ b/drivers/net/virtio/virtio.h
@@ -167,6 +167,7 @@ struct virtio_hw {
 	uint8_t started;
 	uint8_t weak_barriers;
 	uint8_t vlan_strip;
+	bool rx_ol_scatter;
 	uint8_t has_tx_offload;
 	uint8_t has_rx_offload;
 	uint8_t use_vec_rx;
@@ -180,6 +181,7 @@ struct virtio_hw {
 	uint8_t duplex;
 	uint8_t intr_lsc;
 	uint16_t max_mtu;
+	size_t max_rx_pkt_len;
 	/*
 	 * App management thread and virtio interrupt handler thread
 	 * both can change device state, this lock is meant to avoid
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 0568305667..e8d8fb557b 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -841,6 +841,54 @@ virtio_dev_allmulticast_disable(struct rte_eth_dev *dev)
 	return 0;
 }
 
+uint16_t
+virtio_rx_mem_pool_buf_size(struct rte_mempool *mp)
+{
+	return rte_pktmbuf_data_room_size(mp) - RTE_PKTMBUF_HEADROOM;
+}
+
+bool
+virtio_rx_check_scatter(uint16_t max_rx_pkt_len, uint16_t rx_buf_size,
+			bool rx_scatter_enabled, const char **error)
+{
+	if (!rx_scatter_enabled && max_rx_pkt_len > rx_buf_size) {
+		*error = "Rx scatter is disabled and RxQ mbuf pool object size is too small";
+		return false;
+	}
+
+	return true;
+}
+
+static bool
+virtio_check_scatter_on_all_rx_queues(struct rte_eth_dev *dev,
+				      uint16_t frame_size)
+{
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtnet_rx *rxvq;
+	struct virtqueue *vq;
+	unsigned int qidx;
+	uint16_t buf_size;
+	const char *error;
+
+	if (hw->vqs == NULL)
+		return true;
+
+	for (qidx = 0; (vq = hw->vqs[2 * qidx + VTNET_SQ_RQ_QUEUE_IDX]) != NULL;
+	     qidx++) {
+		rxvq = &vq->rxq;
+		buf_size = virtio_rx_mem_pool_buf_size(rxvq->mpool);
+
+		if (!virtio_rx_check_scatter(frame_size, buf_size,
+					     hw->rx_ol_scatter, &error)) {
+			PMD_INIT_LOG(ERR, "MTU check for RxQ %u failed: %s",
+				     qidx, error);
+			return false;
+		}
+	}
+
+	return true;
+}
+
 #define VLAN_TAG_LEN           4    /* 802.3ac tag (not DMA'd) */
 static int
 virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
@@ -858,6 +906,15 @@ virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 			RTE_ETHER_MIN_MTU, max_frame_size - ether_hdr_len);
 		return -EINVAL;
 	}
+
+	if (!virtio_check_scatter_on_all_rx_queues(dev, frame_size)) {
+		PMD_INIT_LOG(ERR, "MTU vs Rx scatter and Rx buffers check failed");
+		return -EINVAL;
+	}
+
+	hw->max_rx_pkt_len = frame_size;
+	dev->data->dev_conf.rxmode.max_rx_pkt_len = hw->max_rx_pkt_len;
+
 	return 0;
 }
 
@@ -2042,6 +2099,8 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 	if (rxmode->max_rx_pkt_len > hw->max_mtu + ether_hdr_len)
 		req_features &= ~(1ULL << VIRTIO_NET_F_MTU);
 
+	hw->max_rx_pkt_len = rxmode->max_rx_pkt_len;
+
 	if (rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM |
 			   DEV_RX_OFFLOAD_TCP_CKSUM))
 		req_features |= (1ULL << VIRTIO_NET_F_GUEST_CSUM);
@@ -2090,6 +2149,8 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 	if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
 		hw->vlan_strip = 1;
 
+	hw->rx_ol_scatter = (rx_offloads & DEV_RX_OFFLOAD_SCATTER);
+
 	if ((rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER) &&
 			!virtio_with_feature(hw, VIRTIO_NET_F_CTRL_VLAN)) {
 		PMD_DRV_LOG(ERR,
@@ -2445,6 +2506,8 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	host_features = VIRTIO_OPS(hw)->get_features(hw);
 	dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
 	dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+	if (host_features & (1ULL << VIRTIO_NET_F_MRG_RXBUF))
+		dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_SCATTER;
 	if (host_features & (1ULL << VIRTIO_NET_F_GUEST_CSUM)) {
 		dev_info->rx_offload_capa |=
 			DEV_RX_OFFLOAD_TCP_CKSUM |
diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h
index 5a501e7890..2f63ef2b2d 100644
--- a/drivers/net/virtio/virtio_ethdev.h
+++ b/drivers/net/virtio/virtio_ethdev.h
@@ -120,4 +120,9 @@ int virtio_dev_close(struct rte_eth_dev *dev);
 int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
 		int nb_pkts);
 
+bool virtio_rx_check_scatter(uint16_t max_rx_pkt_len, uint16_t rx_buf_size,
+			bool rx_scatter_enabled, const char **error);
+
+uint16_t virtio_rx_mem_pool_buf_size(struct rte_mempool *mp);
+
 #endif /* _VIRTIO_ETHDEV_H_ */
diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index 34108fb946..511b3d71b1 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -634,6 +634,8 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 	struct virtqueue *vq = hw->vqs[vq_idx];
 	struct virtnet_rx *rxvq;
 	uint16_t rx_free_thresh;
+	uint16_t buf_size;
+	const char *error;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -642,6 +644,14 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 		return -EINVAL;
 	}
 
+	buf_size = virtio_rx_mem_pool_buf_size(mp);
+	if (!virtio_rx_check_scatter(hw->max_rx_pkt_len, buf_size,
+				     hw->rx_ol_scatter, &error)) {
+		PMD_INIT_LOG(ERR, "RxQ %u Rx scatter check failed: %s",
+			     queue_idx, error);
+		return -EINVAL;
+	}
+
 	rx_free_thresh = rx_conf->rx_free_thresh;
 	if (rx_free_thresh == 0)
 		rx_free_thresh =
-- 
2.30.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH v2] net/virtio: fix Rx scatter offload
  2021-07-19 19:15 ` [dpdk-dev] [PATCH v2] " Andrew Rybchenko
@ 2021-07-19 19:38   ` Andrew Rybchenko
  0 siblings, 0 replies; 9+ messages in thread
From: Andrew Rybchenko @ 2021-07-19 19:38 UTC (permalink / raw)
  To: Maxime Coquelin, Chenbo Xia, Konstantin Ananyev,
	Andrew Rybchenko, Shahaf Shuler
  Cc: dev, Ivan Ilchenko, stable

On 7/19/21 10:15 PM, Andrew Rybchenko wrote:
> From: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
> 
> Report Rx scatter offload capability depending on VIRTIO_NET_F_MRG_RXBUF.
> 
> If Rx scatter is not requested, ensure that provided Rx buffers on
> each Rx queue are big enough to fit Rx packets up to configured MTU.
> 
> Fixes: ce17eddefc20 ("ethdev: introduce Rx queue offloads API")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Sorry, self NACK. The patch has problem with MTU set when not all
queues are setup. Will send v3 tomorrow.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [dpdk-dev] [PATCH v3] net/virtio: fix Rx scatter offload
  2021-07-06 14:14 [dpdk-dev] [PATCH] net/virtio: fix Rx scatter offload Andrew Rybchenko
  2021-07-13  9:27 ` Maxime Coquelin
  2021-07-19 19:15 ` [dpdk-dev] [PATCH v2] " Andrew Rybchenko
@ 2021-07-20  7:54 ` Andrew Rybchenko
  2021-07-20 16:19   ` Maxime Coquelin
  2021-07-21  6:17   ` Xia, Chenbo
  2 siblings, 2 replies; 9+ messages in thread
From: Andrew Rybchenko @ 2021-07-20  7:54 UTC (permalink / raw)
  To: Maxime Coquelin, Chenbo Xia, Andrew Rybchenko,
	Konstantin Ananyev, Shahaf Shuler
  Cc: dev, Ivan Ilchenko, stable

From: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>

Report Rx scatter offload capability depending on VIRTIO_NET_F_MRG_RXBUF.

If Rx scatter is not requested, ensure that provided Rx buffers on
each Rx queue are big enough to fit Rx packets up to configured MTU.

Fixes: ce17eddefc20 ("ethdev: introduce Rx queue offloads API")
Cc: stable@dpdk.org

Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
v3:
 - fix segfault on MTU set if an Rx queue is not setup

v2:
 - do not overwrite Rx offloads when Rx scatter is added

 drivers/net/virtio/virtio.h        |  2 +
 drivers/net/virtio/virtio_ethdev.c | 65 ++++++++++++++++++++++++++++++
 drivers/net/virtio/virtio_ethdev.h |  5 +++
 drivers/net/virtio/virtio_rxtx.c   | 10 +++++
 4 files changed, 82 insertions(+)

diff --git a/drivers/net/virtio/virtio.h b/drivers/net/virtio/virtio.h
index 2c987d19ab..525e2dad4c 100644
--- a/drivers/net/virtio/virtio.h
+++ b/drivers/net/virtio/virtio.h
@@ -167,6 +167,7 @@ struct virtio_hw {
 	uint8_t started;
 	uint8_t weak_barriers;
 	uint8_t vlan_strip;
+	bool rx_ol_scatter;
 	uint8_t has_tx_offload;
 	uint8_t has_rx_offload;
 	uint8_t use_vec_rx;
@@ -180,6 +181,7 @@ struct virtio_hw {
 	uint8_t duplex;
 	uint8_t intr_lsc;
 	uint16_t max_mtu;
+	size_t max_rx_pkt_len;
 	/*
 	 * App management thread and virtio interrupt handler thread
 	 * both can change device state, this lock is meant to avoid
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 0568305667..72d3dda71f 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -841,6 +841,56 @@ virtio_dev_allmulticast_disable(struct rte_eth_dev *dev)
 	return 0;
 }
 
+uint16_t
+virtio_rx_mem_pool_buf_size(struct rte_mempool *mp)
+{
+	return rte_pktmbuf_data_room_size(mp) - RTE_PKTMBUF_HEADROOM;
+}
+
+bool
+virtio_rx_check_scatter(uint16_t max_rx_pkt_len, uint16_t rx_buf_size,
+			bool rx_scatter_enabled, const char **error)
+{
+	if (!rx_scatter_enabled && max_rx_pkt_len > rx_buf_size) {
+		*error = "Rx scatter is disabled and RxQ mbuf pool object size is too small";
+		return false;
+	}
+
+	return true;
+}
+
+static bool
+virtio_check_scatter_on_all_rx_queues(struct rte_eth_dev *dev,
+				      uint16_t frame_size)
+{
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtnet_rx *rxvq;
+	struct virtqueue *vq;
+	unsigned int qidx;
+	uint16_t buf_size;
+	const char *error;
+
+	if (hw->vqs == NULL)
+		return true;
+
+	for (qidx = 0; (vq = hw->vqs[2 * qidx + VTNET_SQ_RQ_QUEUE_IDX]) != NULL;
+	     qidx++) {
+		rxvq = &vq->rxq;
+		if (rxvq->mpool == NULL)
+			continue;
+		buf_size = virtio_rx_mem_pool_buf_size(rxvq->mpool);
+
+		if (!virtio_rx_check_scatter(frame_size, buf_size,
+					     hw->rx_ol_scatter, &error)) {
+			PMD_INIT_LOG(ERR, "MTU check for RxQ %u failed: %s",
+				     qidx, error);
+			return false;
+		}
+	}
+
+	return true;
+}
+
 #define VLAN_TAG_LEN           4    /* 802.3ac tag (not DMA'd) */
 static int
 virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
@@ -858,6 +908,15 @@ virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 			RTE_ETHER_MIN_MTU, max_frame_size - ether_hdr_len);
 		return -EINVAL;
 	}
+
+	if (!virtio_check_scatter_on_all_rx_queues(dev, frame_size)) {
+		PMD_INIT_LOG(ERR, "MTU vs Rx scatter and Rx buffers check failed");
+		return -EINVAL;
+	}
+
+	hw->max_rx_pkt_len = frame_size;
+	dev->data->dev_conf.rxmode.max_rx_pkt_len = hw->max_rx_pkt_len;
+
 	return 0;
 }
 
@@ -2042,6 +2101,8 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 	if (rxmode->max_rx_pkt_len > hw->max_mtu + ether_hdr_len)
 		req_features &= ~(1ULL << VIRTIO_NET_F_MTU);
 
+	hw->max_rx_pkt_len = rxmode->max_rx_pkt_len;
+
 	if (rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM |
 			   DEV_RX_OFFLOAD_TCP_CKSUM))
 		req_features |= (1ULL << VIRTIO_NET_F_GUEST_CSUM);
@@ -2090,6 +2151,8 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 	if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
 		hw->vlan_strip = 1;
 
+	hw->rx_ol_scatter = (rx_offloads & DEV_RX_OFFLOAD_SCATTER);
+
 	if ((rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER) &&
 			!virtio_with_feature(hw, VIRTIO_NET_F_CTRL_VLAN)) {
 		PMD_DRV_LOG(ERR,
@@ -2445,6 +2508,8 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	host_features = VIRTIO_OPS(hw)->get_features(hw);
 	dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
 	dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+	if (host_features & (1ULL << VIRTIO_NET_F_MRG_RXBUF))
+		dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_SCATTER;
 	if (host_features & (1ULL << VIRTIO_NET_F_GUEST_CSUM)) {
 		dev_info->rx_offload_capa |=
 			DEV_RX_OFFLOAD_TCP_CKSUM |
diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h
index 5a501e7890..2f63ef2b2d 100644
--- a/drivers/net/virtio/virtio_ethdev.h
+++ b/drivers/net/virtio/virtio_ethdev.h
@@ -120,4 +120,9 @@ int virtio_dev_close(struct rte_eth_dev *dev);
 int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
 		int nb_pkts);
 
+bool virtio_rx_check_scatter(uint16_t max_rx_pkt_len, uint16_t rx_buf_size,
+			bool rx_scatter_enabled, const char **error);
+
+uint16_t virtio_rx_mem_pool_buf_size(struct rte_mempool *mp);
+
 #endif /* _VIRTIO_ETHDEV_H_ */
diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index 34108fb946..511b3d71b1 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -634,6 +634,8 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 	struct virtqueue *vq = hw->vqs[vq_idx];
 	struct virtnet_rx *rxvq;
 	uint16_t rx_free_thresh;
+	uint16_t buf_size;
+	const char *error;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -642,6 +644,14 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 		return -EINVAL;
 	}
 
+	buf_size = virtio_rx_mem_pool_buf_size(mp);
+	if (!virtio_rx_check_scatter(hw->max_rx_pkt_len, buf_size,
+				     hw->rx_ol_scatter, &error)) {
+		PMD_INIT_LOG(ERR, "RxQ %u Rx scatter check failed: %s",
+			     queue_idx, error);
+		return -EINVAL;
+	}
+
 	rx_free_thresh = rx_conf->rx_free_thresh;
 	if (rx_free_thresh == 0)
 		rx_free_thresh =
-- 
2.30.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH v3] net/virtio: fix Rx scatter offload
  2021-07-20  7:54 ` [dpdk-dev] [PATCH v3] " Andrew Rybchenko
@ 2021-07-20 16:19   ` Maxime Coquelin
  2021-07-21  9:29     ` Andrew Rybchenko
  2021-07-21  6:17   ` Xia, Chenbo
  1 sibling, 1 reply; 9+ messages in thread
From: Maxime Coquelin @ 2021-07-20 16:19 UTC (permalink / raw)
  To: Andrew Rybchenko, Chenbo Xia, Andrew Rybchenko,
	Konstantin Ananyev, Shahaf Shuler
  Cc: dev, Ivan Ilchenko, stable



On 7/20/21 9:54 AM, Andrew Rybchenko wrote:
> From: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
> 
> Report Rx scatter offload capability depending on VIRTIO_NET_F_MRG_RXBUF.
> 
> If Rx scatter is not requested, ensure that provided Rx buffers on
> each Rx queue are big enough to fit Rx packets up to configured MTU.
> 
> Fixes: ce17eddefc20 ("ethdev: introduce Rx queue offloads API")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
> v3:
>  - fix segfault on MTU set if an Rx queue is not setup
> 
> v2:
>  - do not overwrite Rx offloads when Rx scatter is added
> 
>  drivers/net/virtio/virtio.h        |  2 +
>  drivers/net/virtio/virtio_ethdev.c | 65 ++++++++++++++++++++++++++++++
>  drivers/net/virtio/virtio_ethdev.h |  5 +++
>  drivers/net/virtio/virtio_rxtx.c   | 10 +++++
>  4 files changed, 82 insertions(+)
> 

Thanks for the fix.
I see my R-by is already there, but I confirm this is good to me.

Maxime


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH v3] net/virtio: fix Rx scatter offload
  2021-07-20  7:54 ` [dpdk-dev] [PATCH v3] " Andrew Rybchenko
  2021-07-20 16:19   ` Maxime Coquelin
@ 2021-07-21  6:17   ` Xia, Chenbo
  1 sibling, 0 replies; 9+ messages in thread
From: Xia, Chenbo @ 2021-07-21  6:17 UTC (permalink / raw)
  To: Andrew Rybchenko, Maxime Coquelin, Andrew Rybchenko, Ananyev,
	Konstantin, Shahaf Shuler
  Cc: dev, Ivan Ilchenko, stable

> -----Original Message-----
> From: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> Sent: Tuesday, July 20, 2021 3:55 PM
> To: Maxime Coquelin <maxime.coquelin@redhat.com>; Xia, Chenbo
> <chenbo.xia@intel.com>; Andrew Rybchenko <arybchenko@solarflare.com>; Ananyev,
> Konstantin <konstantin.ananyev@intel.com>; Shahaf Shuler <shahafs@mellanox.com>
> Cc: dev@dpdk.org; Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>; stable@dpdk.org
> Subject: [PATCH v3] net/virtio: fix Rx scatter offload
> 
> From: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
> 
> Report Rx scatter offload capability depending on VIRTIO_NET_F_MRG_RXBUF.
> 
> If Rx scatter is not requested, ensure that provided Rx buffers on
> each Rx queue are big enough to fit Rx packets up to configured MTU.
> 
> Fixes: ce17eddefc20 ("ethdev: introduce Rx queue offloads API")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
> --
> 2.30.2

Applied to next-virtio/main. Thanks


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH v3] net/virtio: fix Rx scatter offload
  2021-07-20 16:19   ` Maxime Coquelin
@ 2021-07-21  9:29     ` Andrew Rybchenko
  2021-07-22  7:37       ` Maxime Coquelin
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew Rybchenko @ 2021-07-21  9:29 UTC (permalink / raw)
  To: Maxime Coquelin, Chenbo Xia, Andrew Rybchenko,
	Konstantin Ananyev, Shahaf Shuler
  Cc: dev, Ivan Ilchenko, stable

On 7/20/21 7:19 PM, Maxime Coquelin wrote:
> 
> 
> On 7/20/21 9:54 AM, Andrew Rybchenko wrote:
>> From: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
>>
>> Report Rx scatter offload capability depending on VIRTIO_NET_F_MRG_RXBUF.
>>
>> If Rx scatter is not requested, ensure that provided Rx buffers on
>> each Rx queue are big enough to fit Rx packets up to configured MTU.
>>
>> Fixes: ce17eddefc20 ("ethdev: introduce Rx queue offloads API")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
>> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>> ---
>> v3:
>>   - fix segfault on MTU set if an Rx queue is not setup
>>
>> v2:
>>   - do not overwrite Rx offloads when Rx scatter is added
>>
>>   drivers/net/virtio/virtio.h        |  2 +
>>   drivers/net/virtio/virtio_ethdev.c | 65 ++++++++++++++++++++++++++++++
>>   drivers/net/virtio/virtio_ethdev.h |  5 +++
>>   drivers/net/virtio/virtio_rxtx.c   | 10 +++++
>>   4 files changed, 82 insertions(+)
>>
> 
> Thanks for the fix.
> I see my R-by is already there, but I confirm this is good to me.

It was inherited from v1, since changes from v1 to v3 are really minor
fixes.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [dpdk-dev] [PATCH v3] net/virtio: fix Rx scatter offload
  2021-07-21  9:29     ` Andrew Rybchenko
@ 2021-07-22  7:37       ` Maxime Coquelin
  0 siblings, 0 replies; 9+ messages in thread
From: Maxime Coquelin @ 2021-07-22  7:37 UTC (permalink / raw)
  To: Andrew Rybchenko, Chenbo Xia, Andrew Rybchenko,
	Konstantin Ananyev, Shahaf Shuler
  Cc: dev, Ivan Ilchenko, stable



On 7/21/21 11:29 AM, Andrew Rybchenko wrote:
> On 7/20/21 7:19 PM, Maxime Coquelin wrote:
>>
>>
>> On 7/20/21 9:54 AM, Andrew Rybchenko wrote:
>>> From: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
>>>
>>> Report Rx scatter offload capability depending on
>>> VIRTIO_NET_F_MRG_RXBUF.
>>>
>>> If Rx scatter is not requested, ensure that provided Rx buffers on
>>> each Rx queue are big enough to fit Rx packets up to configured MTU.
>>>
>>> Fixes: ce17eddefc20 ("ethdev: introduce Rx queue offloads API")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
>>> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>>> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>>> ---
>>> v3:
>>>   - fix segfault on MTU set if an Rx queue is not setup
>>>
>>> v2:
>>>   - do not overwrite Rx offloads when Rx scatter is added
>>>
>>>   drivers/net/virtio/virtio.h        |  2 +
>>>   drivers/net/virtio/virtio_ethdev.c | 65 ++++++++++++++++++++++++++++++
>>>   drivers/net/virtio/virtio_ethdev.h |  5 +++
>>>   drivers/net/virtio/virtio_rxtx.c   | 10 +++++
>>>   4 files changed, 82 insertions(+)
>>>
>>
>> Thanks for the fix.
>> I see my R-by is already there, but I confirm this is good to me.
> 
> It was inherited from v1, since changes from v1 to v3 are really minor
> fixes.
> 

Yes, no problem. I was just to let Chenbo know, so that he can add it to
the PR.

Maxime


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-07-22  7:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 14:14 [dpdk-dev] [PATCH] net/virtio: fix Rx scatter offload Andrew Rybchenko
2021-07-13  9:27 ` Maxime Coquelin
2021-07-19 19:15 ` [dpdk-dev] [PATCH v2] " Andrew Rybchenko
2021-07-19 19:38   ` Andrew Rybchenko
2021-07-20  7:54 ` [dpdk-dev] [PATCH v3] " Andrew Rybchenko
2021-07-20 16:19   ` Maxime Coquelin
2021-07-21  9:29     ` Andrew Rybchenko
2021-07-22  7:37       ` Maxime Coquelin
2021-07-21  6:17   ` Xia, Chenbo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).