From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7CB3FA0528; Thu, 9 Jul 2020 17:21:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 88DE41E87B; Thu, 9 Jul 2020 17:21:16 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 3CA1C1E869 for ; Thu, 9 Jul 2020 17:21:15 +0200 (CEST) IronPort-SDR: vE3vD4d74LEU1m4WzpyWodHeYE12fG70hkWh9kmhbsuaelq3w2Cw+eovxD/s8GJCW7prjAOMxX CoxsT+9KNwDA== X-IronPort-AV: E=McAfee;i="6000,8403,9677"; a="209546654" X-IronPort-AV: E=Sophos;i="5.75,331,1589266800"; d="scan'208";a="209546654" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jul 2020 08:21:14 -0700 IronPort-SDR: QPCj+t55Of735rgPNnVVwwVnjzyzjXZX+kXPBCXLeuiAmiV7P9InX/miawucCO3i7IULezLxNw dsHwoiDC9qQA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,331,1589266800"; d="scan'208";a="483835589" Received: from silpixa00399126.ir.intel.com ([10.237.222.36]) by fmsmga006.fm.intel.com with ESMTP; 09 Jul 2020 08:21:12 -0700 From: Bruce Richardson To: Nipun Gupta , Hemant Agrawal Cc: dev@dpdk.org, Rosen Xu , Tianfei zhang , Xiaoyun Li , Jingjing Wu , Satha Rao , Mahipal Challa , Jerin Jacob , Bruce Richardson Date: Thu, 9 Jul 2020 16:20:46 +0100 Message-Id: <20200709152047.167730-5-bruce.richardson@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200709152047.167730-1-bruce.richardson@intel.com> References: <20200709152047.167730-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 20.11 4/5] rawdev: add private data length parameter to queue fns X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- drivers/raw/ntb/ntb.c | 25 ++++++++++++++++----- drivers/raw/skeleton/skeleton_rawdev.c | 10 +++++---- drivers/raw/skeleton/skeleton_rawdev_test.c | 8 +++---- examples/ntb/ntb_fwd.c | 3 ++- lib/librte_rawdev/rte_rawdev.c | 10 +++++---- lib/librte_rawdev/rte_rawdev.h | 10 +++++++-- lib/librte_rawdev/rte_rawdev_pmd.h | 6 +++-- 7 files changed, 49 insertions(+), 23 deletions(-) diff --git a/drivers/raw/ntb/ntb.c b/drivers/raw/ntb/ntb.c index c181094d5..7c15e204c 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 531d0450c..f109e4d2c 100644 --- a/drivers/raw/skeleton/skeleton_rawdev.c +++ b/drivers/raw/skeleton/skeleton_rawdev.c @@ -222,14 +222,15 @@ 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 +253,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 +262,7 @@ 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 7dc7c7684..bb4b6efe4 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 656f73659..5a8439b8d 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 6c4d783cc..8965f2ce3 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,15 @@ 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 +162,7 @@ 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 73e3bd5ae..bbd63913a 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 050f8b029..34eb667f6 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.25.1