Skip to contentSkip to conversation

net/netvsc: more minor fixes

PATCH In review Stephen Hemminger 2 participants 9 messages Apr 30, 2020 – May 5, 2020 Network drivers

lore
Share & tools
lore
#0 lore raw

cover net/netvsc: more minor fixes

These are fixes for several small issues found during review and my testing of netvsc PMD.

Stephen Hemminger (7):
net/netvsc: fix comment spelling errors bus/vmbus: fix comment spelling errors net/vmbus: add missing barrier
net/netvsc: check the vmbus ring buffer more often net/netvsc: manage VF port under rwlock net/netvsc: do RSS across rx queue only net/netvsc: don't configure RSS if disabled

 drivers/bus/vmbus/linux/vmbus_uio.c |   2 +-
 drivers/bus/vmbus/vmbus_channel.c   |   1 +
 drivers/bus/vmbus/vmbus_common.c    |   2 +-
 drivers/net/netvsc/hn_ethdev.c      |  31 +++++----
 drivers/net/netvsc/hn_nvs.h         |   2 +-
 drivers/net/netvsc/hn_rxtx.c        |  30 +++++---
 drivers/net/netvsc/hn_var.h         |  10 +--
 drivers/net/netvsc/hn_vf.c          | 104 +++++++++++++---------------
 8 files changed, 93 insertions(+), 89 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/7 net/netvsc: fix comment spelling errors

No code change here.

---
 drivers/net/netvsc/hn_ethdev.c | 2 +-
 drivers/net/netvsc/hn_nvs.h    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/netvsc/hn_ethdev.c +1 -1
index 05f1a25a1abc..46da5a4e8170 100644
@@ -72,7 +72,7 @@ static const struct hn_xstats_name_off hn_stat_strings[] = {
 
 /* The default RSS key.
  * This value is the same as MLX5 so that flows will be
- * received on same path for both VF ans synthetic NIC.
+ * received on same path for both VF and synthetic NIC.
  */
 static const uint8_t rss_default_key[NDIS_HASH_KEYSIZE_TOEPLITZ] = {
 	0x2c, 0xc6, 0x81, 0xd1,	0x5b, 0xdb, 0xf4, 0xf7,
drivers/net/netvsc/hn_nvs.h +1 -1
index 2563fd8d8669..015839e3644f 100644
@@ -37,7 +37,7 @@
 #define NVS_RNDIS_MTYPE_CTRL		1
 
 /*
- * NVS message transacion status codes.
+ * NVS message transaction status codes.
  */
 #define NVS_STATUS_OK		1
 #define NVS_STATUS_FAILED		2
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/7 bus/vmbus: fix comment spelling errors

In reply to Stephen Hemminger

No code change here.

---
 drivers/bus/vmbus/linux/vmbus_uio.c | 2 +-
 drivers/bus/vmbus/vmbus_common.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/bus/vmbus/linux/vmbus_uio.c +1 -1
index 10e50c9b5a10..5451bfd1501d 100644
@@ -165,7 +165,7 @@ vmbus_uio_map_resource_by_index(struct rte_vmbus_device *dev, int idx,
 	dev->resource[idx].addr = mapaddr;
 	vmbus_map_addr = RTE_PTR_ADD(mapaddr, size);
 
-	/* Record result of sucessful mapping for use by secondary */
+	/* Record result of successful mapping for use by secondary */
 	maps[idx].addr = mapaddr;
 	maps[idx].size = size;
 
drivers/bus/vmbus/vmbus_common.c +1 -1
index 48a219f73529..eaf5c292f986 100644
@@ -131,7 +131,7 @@ vmbus_probe_one_driver(struct rte_vmbus_driver *dr,
 }
 
 /*
- * IF device class GUID mathces, call the probe function of
+ * If device class GUID matches, call the probe function of
  * registere drivers for the vmbus device.
  * Return -1 if initialization failed,
  * and 1 if no driver found for this device.
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/7 net/vmbus: add missing barrier

In reply to Stephen Hemminger

The check for event ring being empty needs a barrier to avoid any over agressive optimization. This is same barrier as Linux kernel.

---
 drivers/bus/vmbus/vmbus_channel.c | 1 +
 1 file changed, 1 insertion(+)
drivers/bus/vmbus/vmbus_channel.c +1 -0
index 46b3ba3f9f9e..ff2985c25758 100644
@@ -199,6 +199,7 @@ bool rte_vmbus_chan_rx_empty(const struct vmbus_channel *channel)
 {
 	const struct vmbus_br *br = &channel->rxbr;
 
+	rte_smp_rmb();
 	return br->vbr->rindex == br->vbr->windex;
 }
 
Signature · 1 line
2.20.1
#4 lore raw

PATCH 4/7 net/netvsc: check the vmbus ring buffer more often

In reply to Stephen Hemminger

Since VF notfications are handled as VMBUS notifications on the primary channel (and not as hotplug). The channel should be checked before deciding to use VF for Rx or Tx.

---
 drivers/net/netvsc/hn_rxtx.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/net/netvsc/hn_rxtx.c +12 -10
index 19f00a05285f..773ba31fcc64 100644
@@ -1372,25 +1372,29 @@ hn_xmit_pkts(void *ptxq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 	struct hn_data *hv = txq->hv;
 	struct rte_eth_dev *vf_dev;
 	bool need_sig = false;
-	uint16_t nb_tx, avail;
+	uint16_t nb_tx, tx_thresh;
 	int ret;
 
 	if (unlikely(hv->closed))
 		return 0;
 
+	/*
+	 * Always check for events on the primary channel
+	 * because that is where hotplug notifications occur.
+	 */
+	tx_thresh = RTE_MAX(txq->free_thresh, nb_pkts);
+	if (txq->queue_id == 0 ||
+	    rte_mempool_avail_count(txq->txdesc_pool) < tx_thresh)
+		hn_process_events(hv, txq->queue_id, 0);
+
 	/* Transmit over VF if present and up */
 	vf_dev = hn_get_vf_dev(hv);
-
 	if (vf_dev && vf_dev->data->dev_started) {
 		void *sub_q = vf_dev->data->tx_queues[queue_id];
 
 		return (*vf_dev->tx_pkt_burst)(sub_q, tx_pkts, nb_pkts);
 	}
 
-	avail = rte_mempool_avail_count(txq->txdesc_pool);
-	if (nb_pkts > avail || avail <= txq->free_thresh)
-		hn_process_events(hv, txq->queue_id, 0);
-
 	for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
 		struct rte_mbuf *m = tx_pkts[nb_tx];
 		uint32_t pkt_size = m->pkt_len + HN_RNDIS_PKT_LEN;
@@ -1487,10 +1491,7 @@ hn_recv_pkts(void *prxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 	if (unlikely(hv->closed))
 		return 0;
 
-	/* Receive from VF if present and up */
-	vf_dev = hn_get_vf_dev(hv);
-
-	/* Check for new completions */
+	/* Check for new completions (and hotplug) */
 	if (likely(rte_ring_count(rxq->rx_ring) < nb_pkts))
 		hn_process_events(hv, rxq->queue_id, 0);
 
@@ -1499,6 +1500,7 @@ hn_recv_pkts(void *prxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 					   (void **)rx_pkts, nb_pkts, NULL);
 
 	/* If VF is available, check that as well */
+	vf_dev = hn_get_vf_dev(hv);
 	if (vf_dev && vf_dev->data->dev_started)
 		nb_rcv += hn_recv_vf(vf_dev->data->port_id, rxq,
 				     rx_pkts + nb_rcv, nb_pkts - nb_rcv);
Signature · 1 line
2.20.1
#5 lore raw

PATCH 5/7 net/netvsc: manage VF port under rwlock

In reply to Stephen Hemminger

With multiple channels, the primary channel may receive notification that VF has been added or removed while secondary channel is in process of doing receive or transmit. Resolve this race by converting existing vf_lock to a reader/writer lock.

Users of lock (tx/rx/stats) acquire for read, and actions like add/remove acquire it for write.

---
 drivers/net/netvsc/hn_ethdev.c |   2 +-
 drivers/net/netvsc/hn_rxtx.c   |   8 ++-
 drivers/net/netvsc/hn_var.h    |  10 ++--
 drivers/net/netvsc/hn_vf.c     | 104 +++++++++++++++------------------
 4 files changed, 61 insertions(+), 63 deletions(-)
drivers/net/netvsc/hn_ethdev.c +1 -1
index 46da5a4e8170..7bf5465ce5e7 100644
@@ -957,7 +957,7 @@ eth_hn_dev_init(struct rte_eth_dev *eth_dev)
 	hv->port_id = eth_dev->data->port_id;
 	hv->latency = HN_CHAN_LATENCY_NS;
 	hv->max_queues = 1;
-	rte_spinlock_init(&hv->vf_lock);
+	rte_rwlock_init(&hv->vf_lock);
 	hv->vf_port = HN_INVALID_PORT;
 
 	err = hn_parse_args(eth_dev);
drivers/net/netvsc/hn_rxtx.c +7 -1
index 773ba31fcc64..31fae5597598 100644
@@ -1388,12 +1388,16 @@ hn_xmit_pkts(void *ptxq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 		hn_process_events(hv, txq->queue_id, 0);
 
 	/* Transmit over VF if present and up */
+	rte_rwlock_read_lock(&hv->vf_lock);
 	vf_dev = hn_get_vf_dev(hv);
 	if (vf_dev && vf_dev->data->dev_started) {
 		void *sub_q = vf_dev->data->tx_queues[queue_id];
 
-		return (*vf_dev->tx_pkt_burst)(sub_q, tx_pkts, nb_pkts);
+		nb_tx = (*vf_dev->tx_pkt_burst)(sub_q, tx_pkts, nb_pkts);
+		rte_rwlock_read_unlock(&hv->vf_lock);
+		return nb_tx;
 	}
+	rte_rwlock_read_unlock(&hv->vf_lock);
 
 	for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
 		struct rte_mbuf *m = tx_pkts[nb_tx];
@@ -1500,11 +1504,13 @@ hn_recv_pkts(void *prxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 					   (void **)rx_pkts, nb_pkts, NULL);
 
 	/* If VF is available, check that as well */
+	rte_rwlock_read_lock(&hv->vf_lock);
 	vf_dev = hn_get_vf_dev(hv);
 	if (vf_dev && vf_dev->data->dev_started)
 		nb_rcv += hn_recv_vf(vf_dev->data->port_id, rxq,
 				     rx_pkts + nb_rcv, nb_pkts - nb_rcv);
 
+	rte_rwlock_read_unlock(&hv->vf_lock);
 	return nb_rcv;
 }
 
drivers/net/netvsc/hn_var.h +5 -5
index b4c61717379f..d1d38b459601 100644
@@ -98,7 +98,7 @@ struct hn_rx_bufinfo {
 struct hn_data {
 	struct rte_vmbus_device *vmbus;
 	struct hn_rx_queue *primary;
-	rte_spinlock_t  vf_lock;
+	rte_rwlock_t    vf_lock;
 	uint16_t	port_id;
 	uint16_t	vf_port;
 
@@ -188,15 +188,15 @@ hn_vf_attached(const struct hn_data *hv)
 	return hv->vf_port != HN_INVALID_PORT;
 }
 
-/* Get VF device for existing netvsc device */
+/*
+ * Get VF device for existing netvsc device
+ * Assumes vf_lock is held.
+ */
 static inline struct rte_eth_dev *
 hn_get_vf_dev(const struct hn_data *hv)
 {
 	uint16_t vf_port = hv->vf_port;
 
-	/* make sure vf_port is loaded */
-	rte_smp_rmb();
-
 	if (vf_port == HN_INVALID_PORT)
 		return NULL;
 	else
drivers/net/netvsc/hn_vf.c +48 -56

344 lines not on this page · raw message

Signature · 1 line
2.20.1
#6 lore raw

PATCH 6/7 net/netvsc: do RSS across rx queue only

In reply to Stephen Hemminger

If number of tx queues is greater than the number of rx queues; the driver ends up allocating more channels than rx queues. The problem is that the RSS indirection table is programed such that some packets will end up on a channel that would never be polled. The fix is to limit the RSS indirection table by number of rx queues not channels.

Fixes 92d23a57cafe ("net/netvsc: support configuring RSS parameters")
---
 drivers/net/netvsc/hn_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/netvsc/hn_ethdev.c +1 -1
index 7bf5465ce5e7..60102362e124 100644
@@ -575,7 +575,7 @@ static int hn_dev_configure(struct rte_eth_dev *dev)
 				 dev->data->nb_tx_queues);
 
 	for (i = 0; i < NDIS_HASH_INDCNT; i++)
-		hv->rss_ind[i] = i % hv->num_queues;
+		hv->rss_ind[i] = i % dev->data->nb_rx_queues;
 
 	hn_rss_hash_init(hv, rss_conf);
 
Signature · 1 line
2.20.1
#7 lore raw

PATCH 7/7 net/netvsc: don't configure RSS if disabled

In reply to Stephen Hemminger

This fixes the problem where driver would not start if only have a single Rx queue and multiple Txq. In that case, RSS should stay disabled.

Fixes 92d23a57cafe ("net/netvsc: support configuring RSS parameters")
---
 drivers/net/netvsc/hn_ethdev.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/net/netvsc/hn_ethdev.c +14 -11
index 60102362e124..55b8a63804a9 100644
@@ -376,14 +376,15 @@ static int hn_rss_hash_update(struct rte_eth_dev *dev,
 
 	hn_rss_hash_init(hv, rss_conf);
 
-	err = hn_rndis_conf_rss(hv, 0);
-	if (err) {
-		PMD_DRV_LOG(NOTICE,
-			    "rss reconfig failed (RSS disabled)");
-		return err;
+	if (rss_conf->rss_hf != 0) {
+		err = hn_rndis_conf_rss(hv, 0);
+		if (err) {
+			PMD_DRV_LOG(NOTICE,
+				    "rss reconfig failed (RSS disabled)");
+			return err;
+		}
 	}
 
-
 	return hn_vf_rss_hash_update(dev, rss_conf);
 }
 
@@ -595,11 +596,13 @@ static int hn_dev_configure(struct rte_eth_dev *dev)
 			return err;
 		}
 
-		err = hn_rndis_conf_rss(hv, 0);
-		if (err) {
-			PMD_DRV_LOG(NOTICE,
-				    "initial RSS config failed");
-			return err;
+		if (rss_conf->rss_hf != 0) {
+			err = hn_rndis_conf_rss(hv, 0);
+			if (err) {
+				PMD_DRV_LOG(NOTICE,
+					    "initial RSS config failed");
+				return err;
+			}
 		}
 	}
 
Signature · 1 line
2.20.1
#8 lore raw
In reply to Stephen Hemminger
Quoted 12 lines · Stephen Hemminger

These are fixes for several small issues found during review and my testing of netvsc PMD.

Stephen Hemminger (7):
net/netvsc: fix comment spelling errors bus/vmbus: fix comment spelling errors net/vmbus: add missing barrier
net/netvsc: check the vmbus ring buffer more often net/netvsc: manage VF port under rwlock net/netvsc: do RSS across rx queue only net/netvsc: don't configure RSS if disabled

Series applied to dpdk-next-net/master, thanks.