From f574ed8116e39588dcc1b1bef8dd7b96e8d431bb Mon Sep 17 00:00:00 2001 From: Bruce Richardson Date: Thu, 10 Sep 2020 15:36:06 +0100 Subject: [PATCH] rawdev: add private data size to queue config inputs The queue setup and queue defaults query functions take a void * parameter as configuration data, preventing any compile-time checking of the parameters and limiting runtime checks. Adding in the length of the expected structure provides a measure of typechecking, and can also be used for ABI compatibility in future, since ABI changes involving structs almost always involve a change in size. Signed-off-by: Bruce Richardson Acked-by: Nipun Gupta --- doc/guides/rel_notes/release_20_11.rst | 1 + drivers/raw/ntb/ntb.c | 25 ++++++++++++++++----- drivers/raw/skeleton/skeleton_rawdev.c | 12 ++++++---- drivers/raw/skeleton/skeleton_rawdev_test.c | 8 +++---- examples/ntb/ntb_fwd.c | 3 ++- lib/librte_rawdev/rte_rawdev.c | 12 ++++++---- lib/librte_rawdev/rte_rawdev.h | 10 +++++++-- lib/librte_rawdev/rte_rawdev_pmd.h | 6 +++-- 8 files changed, 54 insertions(+), 23 deletions(-) diff --git a/doc/guides/rel_notes/release_20_11.rst b/doc/guides/rel_notes/release_20_11.rst index 9543e7e98b..e79b88641b 100644 --- a/doc/guides/rel_notes/release_20_11.rst +++ b/doc/guides/rel_notes/release_20_11.rst @@ -85,6 +85,7 @@ API Changes ======================================================= * rawdev: Added a structure size parameter to the functions + ``rte_rawdev_queue_setup()``, ``rte_rawdev_queue_conf_get()``, ``rte_rawdev_info_get()`` and ``rte_rawdev_configure()``, allowing limited driver type-checking and ABI compatibility. diff --git a/drivers/raw/ntb/ntb.c b/drivers/raw/ntb/ntb.c index 7f6b835a4b..ad10857991 100644 --- a/drivers/raw/ntb/ntb.c +++ b/drivers/raw/ntb/ntb.c @@ -249,11 +249,15 @@ ntb_dev_intr_handler(void *param) static void ntb_queue_conf_get(struct rte_rawdev *dev, uint16_t queue_id, - rte_rawdev_obj_t queue_conf) + rte_rawdev_obj_t queue_conf, + size_t conf_size) { struct ntb_queue_conf *q_conf = queue_conf; struct ntb_hw *hw = dev->dev_private; + if (conf_size != sizeof(*q_conf)) + return; + q_conf->tx_free_thresh = hw->tx_queues[queue_id]->tx_free_thresh; q_conf->nb_desc = hw->rx_queues[queue_id]->nb_rx_desc; q_conf->rx_mp = hw->rx_queues[queue_id]->mpool; @@ -294,12 +298,16 @@ ntb_rxq_release(struct ntb_rx_queue *rxq) static int ntb_rxq_setup(struct rte_rawdev *dev, uint16_t qp_id, - rte_rawdev_obj_t queue_conf) + rte_rawdev_obj_t queue_conf, + size_t conf_size) { struct ntb_queue_conf *rxq_conf = queue_conf; struct ntb_hw *hw = dev->dev_private; struct ntb_rx_queue *rxq; + if (conf_size != sizeof(*rxq_conf)) + return -EINVAL; + /* Allocate the rx queue data structure */ rxq = rte_zmalloc_socket("ntb rx queue", sizeof(struct ntb_rx_queue), @@ -375,13 +383,17 @@ ntb_txq_release(struct ntb_tx_queue *txq) static int ntb_txq_setup(struct rte_rawdev *dev, uint16_t qp_id, - rte_rawdev_obj_t queue_conf) + rte_rawdev_obj_t queue_conf, + size_t conf_size) { struct ntb_queue_conf *txq_conf = queue_conf; struct ntb_hw *hw = dev->dev_private; struct ntb_tx_queue *txq; uint16_t i, prev; + if (conf_size != sizeof(*txq_conf)) + return -EINVAL; + /* Allocate the TX queue data structure. */ txq = rte_zmalloc_socket("ntb tx queue", sizeof(struct ntb_tx_queue), @@ -439,7 +451,8 @@ ntb_txq_setup(struct rte_rawdev *dev, static int ntb_queue_setup(struct rte_rawdev *dev, uint16_t queue_id, - rte_rawdev_obj_t queue_conf) + rte_rawdev_obj_t queue_conf, + size_t conf_size) { struct ntb_hw *hw = dev->dev_private; int ret; @@ -447,11 +460,11 @@ ntb_queue_setup(struct rte_rawdev *dev, if (queue_id >= hw->queue_pairs) return -EINVAL; - ret = ntb_txq_setup(dev, queue_id, queue_conf); + ret = ntb_txq_setup(dev, queue_id, queue_conf, conf_size); if (ret < 0) return ret; - ret = ntb_rxq_setup(dev, queue_id, queue_conf); + ret = ntb_rxq_setup(dev, queue_id, queue_conf, conf_size); return ret; } diff --git a/drivers/raw/skeleton/skeleton_rawdev.c b/drivers/raw/skeleton/skeleton_rawdev.c index 531d0450c8..801c707fb9 100644 --- a/drivers/raw/skeleton/skeleton_rawdev.c +++ b/drivers/raw/skeleton/skeleton_rawdev.c @@ -222,14 +222,16 @@ static int skeleton_rawdev_reset(struct rte_rawdev *dev) static void skeleton_rawdev_queue_def_conf(struct rte_rawdev *dev, uint16_t queue_id, - rte_rawdev_obj_t queue_conf) + rte_rawdev_obj_t queue_conf, + size_t conf_size) { struct skeleton_rawdev *skeldev; struct skeleton_rawdev_queue *skelq; SKELETON_PMD_FUNC_TRACE(); - if (!dev || !queue_conf) + if (!dev || !queue_conf || + conf_size != sizeof(struct skeleton_rawdev_queue)) return; skeldev = skeleton_rawdev_get_priv(dev); @@ -252,7 +254,8 @@ clear_queue_bufs(int queue_id) static int skeleton_rawdev_queue_setup(struct rte_rawdev *dev, uint16_t queue_id, - rte_rawdev_obj_t queue_conf) + rte_rawdev_obj_t queue_conf, + size_t conf_size) { int ret = 0; struct skeleton_rawdev *skeldev; @@ -260,7 +263,8 @@ static int skeleton_rawdev_queue_setup(struct rte_rawdev *dev, SKELETON_PMD_FUNC_TRACE(); - if (!dev || !queue_conf) + if (!dev || !queue_conf || + conf_size != sizeof(struct skeleton_rawdev_queue)) return -EINVAL; skeldev = skeleton_rawdev_get_priv(dev); diff --git a/drivers/raw/skeleton/skeleton_rawdev_test.c b/drivers/raw/skeleton/skeleton_rawdev_test.c index 7dc7c76847..bb4b6efe40 100644 --- a/drivers/raw/skeleton/skeleton_rawdev_test.c +++ b/drivers/raw/skeleton/skeleton_rawdev_test.c @@ -185,7 +185,7 @@ test_rawdev_queue_default_conf_get(void) * depth = DEF_DEPTH */ for (i = 0; i < rdev_conf_get.num_queues; i++) { - rte_rawdev_queue_conf_get(test_dev_id, i, &q); + rte_rawdev_queue_conf_get(test_dev_id, i, &q, sizeof(q)); RTE_TEST_ASSERT_EQUAL(q.depth, SKELETON_QUEUE_DEF_DEPTH, "Invalid default depth of queue (%d)", q.depth); @@ -235,11 +235,11 @@ test_rawdev_queue_setup(void) /* Modify the queue depth for Queue 0 and attach it */ qset.depth = 15; qset.state = SKELETON_QUEUE_ATTACH; - ret = rte_rawdev_queue_setup(test_dev_id, 0, &qset); + ret = rte_rawdev_queue_setup(test_dev_id, 0, &qset, sizeof(qset)); RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup queue (%d)", ret); /* Now, fetching the queue 0 should show depth as 15 */ - ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget); + ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget, sizeof(qget)); RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret); RTE_TEST_ASSERT_EQUAL(qset.depth, qget.depth, @@ -263,7 +263,7 @@ test_rawdev_queue_release(void) RTE_TEST_ASSERT_SUCCESS(ret, "Failed to release queue 0; (%d)", ret); /* Now, fetching the queue 0 should show depth as default */ - ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget); + ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget, sizeof(qget)); RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret); RTE_TEST_ASSERT_EQUAL(qget.depth, SKELETON_QUEUE_DEF_DEPTH, diff --git a/examples/ntb/ntb_fwd.c b/examples/ntb/ntb_fwd.c index 656f736594..5a8439b8d3 100644 --- a/examples/ntb/ntb_fwd.c +++ b/examples/ntb/ntb_fwd.c @@ -1411,7 +1411,8 @@ main(int argc, char **argv) ntb_q_conf.rx_mp = mbuf_pool; for (i = 0; i < num_queues; i++) { /* Setup rawdev queue */ - ret = rte_rawdev_queue_setup(dev_id, i, &ntb_q_conf); + ret = rte_rawdev_queue_setup(dev_id, i, &ntb_q_conf, + sizeof(ntb_q_conf)); if (ret < 0) rte_exit(EXIT_FAILURE, "Failed to setup ntb queue %u.\n", i); diff --git a/lib/librte_rawdev/rte_rawdev.c b/lib/librte_rawdev/rte_rawdev.c index 6c4d783cc5..f48d8cf10b 100644 --- a/lib/librte_rawdev/rte_rawdev.c +++ b/lib/librte_rawdev/rte_rawdev.c @@ -137,7 +137,8 @@ rte_rawdev_configure(uint16_t dev_id, struct rte_rawdev_info *dev_conf, int rte_rawdev_queue_conf_get(uint16_t dev_id, uint16_t queue_id, - rte_rawdev_obj_t queue_conf) + rte_rawdev_obj_t queue_conf, + size_t queue_conf_size) { struct rte_rawdev *dev; @@ -145,14 +146,16 @@ rte_rawdev_queue_conf_get(uint16_t dev_id, dev = &rte_rawdevs[dev_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_def_conf, -ENOTSUP); - (*dev->dev_ops->queue_def_conf)(dev, queue_id, queue_conf); + (*dev->dev_ops->queue_def_conf)(dev, queue_id, queue_conf, + queue_conf_size); return 0; } int rte_rawdev_queue_setup(uint16_t dev_id, uint16_t queue_id, - rte_rawdev_obj_t queue_conf) + rte_rawdev_obj_t queue_conf, + size_t queue_conf_size) { struct rte_rawdev *dev; @@ -160,7 +163,8 @@ rte_rawdev_queue_setup(uint16_t dev_id, dev = &rte_rawdevs[dev_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_setup, -ENOTSUP); - return (*dev->dev_ops->queue_setup)(dev, queue_id, queue_conf); + return (*dev->dev_ops->queue_setup)(dev, queue_id, queue_conf, + queue_conf_size); } int diff --git a/lib/librte_rawdev/rte_rawdev.h b/lib/librte_rawdev/rte_rawdev.h index 1720f1dd6b..14e8eb972f 100644 --- a/lib/librte_rawdev/rte_rawdev.h +++ b/lib/librte_rawdev/rte_rawdev.h @@ -146,6 +146,8 @@ rte_rawdev_configure(uint16_t dev_id, struct rte_rawdev_info *dev_conf, * previously supplied to rte_rawdev_configure(). * @param[out] queue_conf * The pointer to the default raw queue configuration data. + * @param queue_conf_size + * The size of the structure pointed to by queue_conf * @return * - 0: Success, driver updates the default raw queue configuration data. * - <0: Error code returned by the driver info get function. @@ -156,7 +158,8 @@ rte_rawdev_configure(uint16_t dev_id, struct rte_rawdev_info *dev_conf, int rte_rawdev_queue_conf_get(uint16_t dev_id, uint16_t queue_id, - rte_rawdev_obj_t queue_conf); + rte_rawdev_obj_t queue_conf, + size_t queue_conf_size); /** * Allocate and set up a raw queue for a raw device. @@ -169,6 +172,8 @@ rte_rawdev_queue_conf_get(uint16_t dev_id, * @param queue_conf * The pointer to the configuration data to be used for the raw queue. * NULL value is allowed, in which case default configuration used. + * @param queue_conf_size + * The size of the structure pointed to by queue_conf * * @see rte_rawdev_queue_conf_get() * @@ -179,7 +184,8 @@ rte_rawdev_queue_conf_get(uint16_t dev_id, int rte_rawdev_queue_setup(uint16_t dev_id, uint16_t queue_id, - rte_rawdev_obj_t queue_conf); + rte_rawdev_obj_t queue_conf, + size_t queue_conf_size); /** * Release and deallocate a raw queue from a raw device. diff --git a/lib/librte_rawdev/rte_rawdev_pmd.h b/lib/librte_rawdev/rte_rawdev_pmd.h index 050f8b0292..34eb667f62 100644 --- a/lib/librte_rawdev/rte_rawdev_pmd.h +++ b/lib/librte_rawdev/rte_rawdev_pmd.h @@ -218,7 +218,8 @@ typedef int (*rawdev_reset_t)(struct rte_rawdev *dev); */ typedef void (*rawdev_queue_conf_get_t)(struct rte_rawdev *dev, uint16_t queue_id, - rte_rawdev_obj_t queue_conf); + rte_rawdev_obj_t queue_conf, + size_t queue_conf_size); /** * Setup an raw queue. @@ -235,7 +236,8 @@ typedef void (*rawdev_queue_conf_get_t)(struct rte_rawdev *dev, */ typedef int (*rawdev_queue_setup_t)(struct rte_rawdev *dev, uint16_t queue_id, - rte_rawdev_obj_t queue_conf); + rte_rawdev_obj_t queue_conf, + size_t queue_conf_size); /** * Release resources allocated by given raw queue. -- 2.20.1