net/netvsc: fix number Tx queues > Rx queues
Checks
Commit Message
The previous code allowed the number of Tx queues to be set higher than
the number of Rx queues. If a packet was sent on a Tx queue with index
>= number Rx queues there was a segfault.
This commit fixes the issue by creating an Rx queue for every Tx queue
meaning that an event buffer is allocated to handle receiving Tx
completion messages.
mbuf pool and Rx ring are not allocated for these additional Rx queues
and RSS configuration ensures that no packets are received on them.
Fixes: 4e9c73e96e83 ("net/netvsc: add Hyper-V network device")
Cc: sthemmin@microsoft.com
Cc: stable@dpdk.org
Signed-off-by: Alan Elder <alan.elder@microsoft.com>
---
drivers/net/netvsc/hn_ethdev.c | 9 ++++++++
drivers/net/netvsc/hn_rxtx.c | 40 ++++++++++++++++++++++++++++++++++
drivers/net/netvsc/hn_var.h | 1 +
3 files changed, 50 insertions(+)
Comments
On Thu, 29 Feb 2024 19:29:11 +0000
Alan Elder <alan.elder@microsoft.com> wrote:
> The previous code allowed the number of Tx queues to be set higher than
> the number of Rx queues. If a packet was sent on a Tx queue with index
> >= number Rx queues there was a segfault.
>
> This commit fixes the issue by creating an Rx queue for every Tx queue
> meaning that an event buffer is allocated to handle receiving Tx
> completion messages.
>
> mbuf pool and Rx ring are not allocated for these additional Rx queues
> and RSS configuration ensures that no packets are received on them.
>
> Fixes: 4e9c73e96e83 ("net/netvsc: add Hyper-V network device")
> Cc: sthemmin@microsoft.com
> Cc: stable@dpdk.org
>
> Signed-off-by: Alan Elder <alan.elder@microsoft.com>
Don't have Azure account to test, but looks good to me.
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
> Subject: Re: [PATCH] net/netvsc: fix number Tx queues > Rx queues
>
> On Thu, 29 Feb 2024 19:29:11 +0000
> Alan Elder <alan.elder@microsoft.com> wrote:
>
> > The previous code allowed the number of Tx queues to be set higher
> > than the number of Rx queues. If a packet was sent on a Tx queue with
> > index
> > >= number Rx queues there was a segfault.
> >
> > This commit fixes the issue by creating an Rx queue for every Tx queue
> > meaning that an event buffer is allocated to handle receiving Tx
> > completion messages.
> >
> > mbuf pool and Rx ring are not allocated for these additional Rx queues
> > and RSS configuration ensures that no packets are received on them.
> >
> > Fixes: 4e9c73e96e83 ("net/netvsc: add Hyper-V network device")
> > Cc: sthemmin@microsoft.com
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Alan Elder <alan.elder@microsoft.com>
>
> Don't have Azure account to test, but looks good to me.
>
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>
Please hold on while we are discussing this patch internally with its interaction with MANA.
Long
> Subject: RE: [PATCH] net/netvsc: fix number Tx queues > Rx queues
>
> > Subject: Re: [PATCH] net/netvsc: fix number Tx queues > Rx queues
> >
> > On Thu, 29 Feb 2024 19:29:11 +0000
> > Alan Elder <alan.elder@microsoft.com> wrote:
> >
> > > The previous code allowed the number of Tx queues to be set higher
> > > than the number of Rx queues. If a packet was sent on a Tx queue
> > > with index
> > > >= number Rx queues there was a segfault.
> > >
> > > This commit fixes the issue by creating an Rx queue for every Tx
> > > queue meaning that an event buffer is allocated to handle receiving
> > > Tx completion messages.
> > >
> > > mbuf pool and Rx ring are not allocated for these additional Rx
> > > queues and RSS configuration ensures that no packets are received on
> them.
> > >
> > > Fixes: 4e9c73e96e83 ("net/netvsc: add Hyper-V network device")
> > > Cc: sthemmin@microsoft.com
> > > Cc: stable@dpdk.org
> > >
> > > Signed-off-by: Alan Elder <alan.elder@microsoft.com>
> >
> > Don't have Azure account to test, but looks good to me.
> >
> > Acked-by: Stephen Hemminger <stephen@networkplumber.org>
>
> Please hold on while we are discussing this patch internally with its interaction
> with MANA.
>
> Long
Thanks for the feedback Long and Stephen. We've discussed the interaction with MANA and I think we're good to go ahead with this now. I've submitted v2 of the patch with a minor fix.
Cheers,
Alan
@@ -313,6 +313,15 @@ static int hn_rss_reta_update(struct rte_eth_dev *dev,
if (reta_conf[idx].mask & mask)
hv->rss_ind[i] = reta_conf[idx].reta[shift];
+
+ /*
+ * Ensure we don't allow config that directs traffic to an Rx
+ * queue that we aren't going to poll
+ */
+ if (hv->rss_ind[i] >= dev->data->nb_rx_queues) {
+ PMD_DRV_LOG(ERR, "RSS distributing traffic to invalid Rx queue");
+ return -EINVAL;
+ }
}
err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
@@ -243,6 +243,7 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
{
struct hn_data *hv = dev->data->dev_private;
struct hn_tx_queue *txq;
+ struct hn_rx_queue *rxq;
char name[RTE_MEMPOOL_NAMESIZE];
uint32_t tx_free_thresh;
int err = -ENOMEM;
@@ -301,6 +302,22 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
goto error;
}
+ /*
+ * If there are more Tx queues than Rx queues, allocate rx_queues
+ * with event buffer so that Tx completion messages can still be
+ * received
+ */
+ if (queue_idx >= dev->data->nb_rx_queues) {
+ rxq = hn_rx_queue_alloc(hv, queue_idx, socket_id);
+ /*
+ * Don't allocate mbuf pool or rx ring. RSS is always configured
+ * to ensure packets aren't received by this Rx queue.
+ */
+ rxq->mb_pool = NULL;
+ rxq->rx_ring = NULL;
+ dev->data->rx_queues[queue_idx] = rxq;
+ }
+
txq->agg_szmax = RTE_MIN(hv->chim_szmax, hv->rndis_agg_size);
txq->agg_pktmax = hv->rndis_agg_pkts;
txq->agg_align = hv->rndis_agg_align;
@@ -364,6 +381,13 @@ hn_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
if (!txq)
return;
+ /*
+ * Free any Rx queues allocated for a Tx queue without a corresponding
+ * Rx queue
+ */
+ if (qid >= dev->data->nb_rx_queues)
+ hn_rx_queue_free_common(dev->data->rx_queues[qid]);
+
rte_mempool_free(txq->txdesc_pool);
rte_memzone_free(txq->tx_rndis_mz);
@@ -942,6 +966,13 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev,
if (queue_idx == 0) {
rxq = hv->primary;
} else {
+ /*
+ * If the number of Tx queues was previously greater than
+ * the number of Rx queues, we may already have allocated
+ * an rxq. If so, free it now before allocating a new one.
+ */
+ hn_rx_queue_free_common(dev->data->rx_queues[queue_idx]);
+
rxq = hn_rx_queue_alloc(hv, queue_idx, socket_id);
if (!rxq)
return -ENOMEM;
@@ -998,6 +1029,15 @@ hn_rx_queue_free(struct hn_rx_queue *rxq, bool keep_primary)
if (keep_primary && rxq == rxq->hv->primary)
return;
+ hn_rx_queue_free_common(rxq);
+}
+
+static void
+hn_rx_queue_free_common(struct hn_rx_queue *rxq)
+{
+ if (!rxq)
+ return;
+
rte_free(rxq->rxbuf_info);
rte_free(rxq->event_buf);
rte_free(rxq);
@@ -216,6 +216,7 @@ int hn_dev_tx_descriptor_status(void *arg, uint16_t offset);
struct hn_rx_queue *hn_rx_queue_alloc(struct hn_data *hv,
uint16_t queue_id,
unsigned int socket_id);
+static void hn_rx_queue_free_common(struct hn_rx_queue *rxq);
int hn_dev_rx_queue_setup(struct rte_eth_dev *dev,
uint16_t queue_idx, uint16_t nb_desc,
unsigned int socket_id,