From patchwork Sun Jul 22 11:21:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Conole X-Patchwork-Id: 43260 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 89ED02BD2; Sun, 22 Jul 2018 13:21:19 +0200 (CEST) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by dpdk.org (Postfix) with ESMTP id B33F31B53 for ; Sun, 22 Jul 2018 13:21:18 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 482E07A7E0; Sun, 22 Jul 2018 11:21:18 +0000 (UTC) Received: from dhcp-25.97.bos.redhat.com (ovpn-120-39.rdu2.redhat.com [10.10.120.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id AECF92026D66; Sun, 22 Jul 2018 11:21:17 +0000 (UTC) From: Aaron Conole To: dev@dpdk.org Cc: Ferruh Yigit , Marcelo Leitner Date: Sun, 22 Jul 2018 07:21:16 -0400 Message-Id: <20180722112116.8419-1-aconole@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Sun, 22 Jul 2018 11:21:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Sun, 22 Jul 2018 11:21:18 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'aconole@redhat.com' RCPT:'' Subject: [dpdk-dev] [PATCH] ethdev: move sanity checks to non-debug paths 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" These checks would have prevented a reported crash in the field. If a user builds without ETHDEV_DEBUG, it should make their application more stable, not less. Many of these functions immediately dereference arrays based on the passed in values, so the sanity checks are quite important. The logs are left as DEBUG only. Cc: Marcelo Leitner Signed-off-by: Aaron Conole --- lib/librte_ethdev/rte_ethdev.h | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index f5f593b31..bfd6a3406 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -3805,15 +3805,16 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id, struct rte_eth_dev *dev = &rte_eth_devices[port_id]; uint16_t nb_rx; -#ifdef RTE_LIBRTE_ETHDEV_DEBUG RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0); RTE_FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0); if (queue_id >= dev->data->nb_rx_queues) { +#ifdef RTE_LIBRTE_ETHDEV_DEBUG RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id); +#endif return 0; } -#endif + nb_rx = (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id], rx_pkts, nb_pkts); @@ -3928,14 +3929,12 @@ rte_eth_rx_descriptor_status(uint16_t port_id, uint16_t queue_id, struct rte_eth_dev *dev; void *rxq; -#ifdef RTE_LIBRTE_ETHDEV_DEBUG RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); -#endif dev = &rte_eth_devices[port_id]; -#ifdef RTE_LIBRTE_ETHDEV_DEBUG + if (queue_id >= dev->data->nb_rx_queues) return -ENODEV; -#endif + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_status, -ENOTSUP); rxq = dev->data->rx_queues[queue_id]; @@ -3985,14 +3984,12 @@ static inline int rte_eth_tx_descriptor_status(uint16_t port_id, struct rte_eth_dev *dev; void *txq; -#ifdef RTE_LIBRTE_ETHDEV_DEBUG RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); -#endif dev = &rte_eth_devices[port_id]; -#ifdef RTE_LIBRTE_ETHDEV_DEBUG + if (queue_id >= dev->data->nb_tx_queues) return -ENODEV; -#endif + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_descriptor_status, -ENOTSUP); txq = dev->data->tx_queues[queue_id]; @@ -4071,15 +4068,15 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id, { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; -#ifdef RTE_LIBRTE_ETHDEV_DEBUG RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0); RTE_FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0); if (queue_id >= dev->data->nb_tx_queues) { +#ifdef RTE_LIBRTE_ETHDEV_DEBUG RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id); +#endif return 0; } -#endif #ifdef RTE_ETHDEV_RXTX_CALLBACKS struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id]; @@ -4160,23 +4157,23 @@ rte_eth_tx_prepare(uint16_t port_id, uint16_t queue_id, { struct rte_eth_dev *dev; -#ifdef RTE_LIBRTE_ETHDEV_DEBUG if (!rte_eth_dev_is_valid_port(port_id)) { +#ifdef RTE_LIBRTE_ETHDEV_DEBUG RTE_ETHDEV_LOG(ERR, "Invalid TX port_id=%u\n", port_id); +#endif rte_errno = -EINVAL; return 0; } -#endif dev = &rte_eth_devices[port_id]; -#ifdef RTE_LIBRTE_ETHDEV_DEBUG if (queue_id >= dev->data->nb_tx_queues) { +#ifdef RTE_LIBRTE_ETHDEV_DEBUG RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id); +#endif rte_errno = -EINVAL; return 0; } -#endif if (!dev->tx_pkt_prepare) return nb_pkts;