* [dpdk-dev] [PATCH] ethdev: fix crash with multiprocess
@ 2015-03-26 17:02 Bruce Richardson
2015-03-26 17:36 ` De Lara Guarch, Pablo
2015-03-27 12:27 ` Mcnamara, John
0 siblings, 2 replies; 4+ messages in thread
From: Bruce Richardson @ 2015-03-26 17:02 UTC (permalink / raw)
To: dev
The data structure for the rx and tx callbacks is local to each process
since it contains function pointers and cannot be shared between
different unique binaries. However, because it is not in
rte_eth_dev_data structure, the array is not getting initialized for
secondary processes - neither is it getting appropriately resized if the
number of RX/TX queues changes. This causes crashes in secondary
processes as they dereference a null pointer in struct rte_eth_dev.
This patch fixes this by introducing an upper-bound on the number of
queues per port that can be configured, and then uses this to make the
array statically sized, thereby avoiding the crashes.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
config/common_bsdapp | 1 +
config/common_linuxapp | 1 +
lib/librte_ether/rte_ethdev.c | 64 ++++++++++---------------------------------
lib/librte_ether/rte_ethdev.h | 4 +--
4 files changed, 18 insertions(+), 52 deletions(-)
diff --git a/config/common_bsdapp b/config/common_bsdapp
index 8ff4dc2..93d2f9e 100644
--- a/config/common_bsdapp
+++ b/config/common_bsdapp
@@ -137,6 +137,7 @@ CONFIG_RTE_LIBRTE_KVARGS=y
CONFIG_RTE_LIBRTE_ETHER=y
CONFIG_RTE_LIBRTE_ETHDEV_DEBUG=n
CONFIG_RTE_MAX_ETHPORTS=32
+CONFIG_RTE_MAX_QUEUES_PER_PORT=256
CONFIG_RTE_LIBRTE_IEEE1588=n
CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
diff --git a/config/common_linuxapp b/config/common_linuxapp
index 09a58ac..19de75f 100644
--- a/config/common_linuxapp
+++ b/config/common_linuxapp
@@ -134,6 +134,7 @@ CONFIG_RTE_LIBRTE_KVARGS=y
CONFIG_RTE_LIBRTE_ETHER=y
CONFIG_RTE_LIBRTE_ETHDEV_DEBUG=n
CONFIG_RTE_MAX_ETHPORTS=32
+CONFIG_RTE_MAX_QUEUES_PER_PORT=256
CONFIG_RTE_LIBRTE_IEEE1588=n
CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 03fce08..9328bd8 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -741,19 +741,6 @@ rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
dev->data->nb_rx_queues = 0;
return -(ENOMEM);
}
-#ifdef RTE_ETHDEV_RXTX_CALLBACKS
- dev->post_rx_burst_cbs = rte_zmalloc(
- "ethdev->post_rx_burst_cbs",
- sizeof(*dev->post_rx_burst_cbs) * nb_queues,
- RTE_CACHE_LINE_SIZE);
- if (dev->post_rx_burst_cbs == NULL) {
- rte_free(dev->data->rx_queues);
- dev->data->rx_queues = NULL;
- dev->data->nb_rx_queues = 0;
- return -ENOMEM;
- }
-#endif
-
} else { /* re-configure */
FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
@@ -765,22 +752,10 @@ rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
RTE_CACHE_LINE_SIZE);
if (rxq == NULL)
return -(ENOMEM);
-#ifdef RTE_ETHDEV_RXTX_CALLBACKS
- dev->post_rx_burst_cbs = rte_realloc(
- dev->post_rx_burst_cbs,
- sizeof(*dev->post_rx_burst_cbs) *
- nb_queues, RTE_CACHE_LINE_SIZE);
- if (dev->post_rx_burst_cbs == NULL)
- return -ENOMEM;
-#endif
if (nb_queues > old_nb_queues) {
uint16_t new_qs = nb_queues - old_nb_queues;
memset(rxq + old_nb_queues, 0,
sizeof(rxq[0]) * new_qs);
-#ifdef RTE_ETHDEV_RXTX_CALLBACKS
- memset(dev->post_rx_burst_cbs + old_nb_queues, 0,
- sizeof(dev->post_rx_burst_cbs[0]) * new_qs);
-#endif
}
dev->data->rx_queues = rxq;
@@ -909,19 +884,6 @@ rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
dev->data->nb_tx_queues = 0;
return -(ENOMEM);
}
-#ifdef RTE_ETHDEV_RXTX_CALLBACKS
- dev->pre_tx_burst_cbs = rte_zmalloc(
- "ethdev->pre_tx_burst_cbs",
- sizeof(*dev->pre_tx_burst_cbs) * nb_queues,
- RTE_CACHE_LINE_SIZE);
- if (dev->pre_tx_burst_cbs == NULL) {
- rte_free(dev->data->tx_queues);
- dev->data->tx_queues = NULL;
- dev->data->nb_tx_queues = 0;
- return -ENOMEM;
- }
-#endif
-
} else { /* re-configure */
FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
@@ -933,22 +895,10 @@ rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
RTE_CACHE_LINE_SIZE);
if (txq == NULL)
return -ENOMEM;
-#ifdef RTE_ETHDEV_RXTX_CALLBACKS
- dev->pre_tx_burst_cbs = rte_realloc(
- dev->pre_tx_burst_cbs,
- sizeof(*dev->pre_tx_burst_cbs) *
- nb_queues, RTE_CACHE_LINE_SIZE);
- if (dev->pre_tx_burst_cbs == NULL)
- return -ENOMEM;
-#endif
if (nb_queues > old_nb_queues) {
uint16_t new_qs = nb_queues - old_nb_queues;
memset(txq + old_nb_queues, 0,
sizeof(txq[0]) * new_qs);
-#ifdef RTE_ETHDEV_RXTX_CALLBACKS
- memset(dev->pre_tx_burst_cbs + old_nb_queues, 0,
- sizeof(dev->pre_tx_burst_cbs[0]) * new_qs);
-#endif
}
dev->data->tx_queues = txq;
@@ -1164,6 +1114,20 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
return (-EINVAL);
}
+ if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
+ PMD_DEBUG_TRACE(
+ "Number of RX queues requested (%u) is greater than max supported(%d)\n",
+ nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
+ return (-EINVAL);
+ }
+
+ if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
+ PMD_DEBUG_TRACE(
+ "Number of TX queues requested (%u) is greater than max supported(%d)\n",
+ nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
+ return (-EINVAL);
+ }
+
dev = &rte_eth_devices[port_id];
FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 21aa359..725321a 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1458,12 +1458,12 @@ struct rte_eth_dev {
* User-supplied functions called from rx_burst to post-process
* received packets before passing them to the user
*/
- struct rte_eth_rxtx_callback **post_rx_burst_cbs;
+ struct rte_eth_rxtx_callback *post_rx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
/**
* User-supplied functions called from tx_burst to pre-process
* received packets before passing them to the driver for transmission.
*/
- struct rte_eth_rxtx_callback **pre_tx_burst_cbs;
+ struct rte_eth_rxtx_callback *pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
uint8_t attached; /**< Flag indicating the port is attached */
enum rte_eth_dev_type dev_type; /**< Flag indicating the device type */
};
--
2.1.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH] ethdev: fix crash with multiprocess
2015-03-26 17:02 [dpdk-dev] [PATCH] ethdev: fix crash with multiprocess Bruce Richardson
@ 2015-03-26 17:36 ` De Lara Guarch, Pablo
2015-03-27 10:05 ` Thomas Monjalon
2015-03-27 12:27 ` Mcnamara, John
1 sibling, 1 reply; 4+ messages in thread
From: De Lara Guarch, Pablo @ 2015-03-26 17:36 UTC (permalink / raw)
To: Richardson, Bruce, dev
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Bruce Richardson
> Sent: Thursday, March 26, 2015 5:03 PM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH] ethdev: fix crash with multiprocess
>
> The data structure for the rx and tx callbacks is local to each process
> since it contains function pointers and cannot be shared between
> different unique binaries. However, because it is not in
> rte_eth_dev_data structure, the array is not getting initialized for
> secondary processes - neither is it getting appropriately resized if the
> number of RX/TX queues changes. This causes crashes in secondary
> processes as they dereference a null pointer in struct rte_eth_dev.
>
> This patch fixes this by introducing an upper-bound on the number of
> queues per port that can be configured, and then uses this to make the
> array statically sized, thereby avoiding the crashes.
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Tested-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH] ethdev: fix crash with multiprocess
2015-03-26 17:36 ` De Lara Guarch, Pablo
@ 2015-03-27 10:05 ` Thomas Monjalon
0 siblings, 0 replies; 4+ messages in thread
From: Thomas Monjalon @ 2015-03-27 10:05 UTC (permalink / raw)
To: Richardson, Bruce; +Cc: dev
2015-03-26 17:36, De Lara Guarch, Pablo:
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Bruce Richardson
> > The data structure for the rx and tx callbacks is local to each process
> > since it contains function pointers and cannot be shared between
> > different unique binaries. However, because it is not in
> > rte_eth_dev_data structure, the array is not getting initialized for
> > secondary processes - neither is it getting appropriately resized if the
> > number of RX/TX queues changes. This causes crashes in secondary
> > processes as they dereference a null pointer in struct rte_eth_dev.
> >
> > This patch fixes this by introducing an upper-bound on the number of
> > queues per port that can be configured, and then uses this to make the
> > array statically sized, thereby avoiding the crashes.
> >
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
>
> Tested-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Fixes: 4dc294158cac ("ethdev: support optional Rx and Tx callbacks")
Acked-by: Thomas Monjalon <thomas.monjalon@6wind.com>
Applied, thanks
The multiprocess design is difficult to maintain.
It would be better to have someone registered as maintainer of this part.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH] ethdev: fix crash with multiprocess
2015-03-26 17:02 [dpdk-dev] [PATCH] ethdev: fix crash with multiprocess Bruce Richardson
2015-03-26 17:36 ` De Lara Guarch, Pablo
@ 2015-03-27 12:27 ` Mcnamara, John
1 sibling, 0 replies; 4+ messages in thread
From: Mcnamara, John @ 2015-03-27 12:27 UTC (permalink / raw)
To: Richardson, Bruce, dev
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Bruce Richardson
> Sent: Thursday, March 26, 2015 5:03 PM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH] ethdev: fix crash with multiprocess
Acked-by: John McNamara <john.mcnamara@intel.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-03-27 12:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-26 17:02 [dpdk-dev] [PATCH] ethdev: fix crash with multiprocess Bruce Richardson
2015-03-26 17:36 ` De Lara Guarch, Pablo
2015-03-27 10:05 ` Thomas Monjalon
2015-03-27 12:27 ` Mcnamara, John
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).