From patchwork Thu Mar 9 13:57:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Stokes, Ian" X-Patchwork-Id: 736996 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vfBmT5skdz9s7c for ; Fri, 10 Mar 2017 00:57:45 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 90D77955; Thu, 9 Mar 2017 13:57:41 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 28400305 for ; Thu, 9 Mar 2017 13:57:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id BC05718A for ; Thu, 9 Mar 2017 13:57:39 +0000 (UTC) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP; 09 Mar 2017 05:57:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,268,1486454400"; d="scan'208";a="832745750" Received: from sivswdev01.ir.intel.com (HELO localhost.localdomain) ([10.237.217.45]) by FMSMGA003.fm.intel.com with ESMTP; 09 Mar 2017 05:57:38 -0800 From: Ian Stokes To: dev@openvswitch.org Date: Thu, 9 Mar 2017 13:57:37 +0000 Message-Id: <1489067857-32213-1-git-send-email-ian.stokes@intel.com> X-Mailer: git-send-email 1.7.0.7 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v3] netdev-dpdk: Fix mempool segfault. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org The dpdk_mp_get() function can return a NULL pointer which leads to a segfault when a mempool cannot be created. The lack of a return value check for the function netdev_dpdk_mempool_configure() when called in netdev_dpdk_reconfigure() can result in a segfault also as a NULL pointer for the mempool will be passed to rte_eth_rx_queue_setup(). Fix this by adding appropriate NULL pointer and return value checks to dpdk_mp_get(), netdev_dpdk_reconfigure() and dpdk_vhost_reconfigure_helper(). Signed-off-by: Ian Stokes Fixes: 2ae3d542 ("netdev-dpdk: Refactor dpdk_mp_get().") Fixes: 0072e931 ("netdev-dpdk: add support for jumbo frames") CC: Daniele Di Proietto CC: Mark Kavanagh --- v3 * Remove assignments within if conditions for netdev_dpdk_reconfigure(), netdev_vhost_reconfigure_helper() and dpdk_mp_get() v2 * Remove extra VLOG_ERR in netdev_dpdk_reconfigure() * Remove extra VLOG_ERR in netdev_vhost_reconfigure_helper() * Remove check for NULL mempool in netdev_vhost_reconfigure_helper() as netdev_dpdk_mempool_configure() already checks and returns ENOMEM error for this case. v1 * Add NULL pointer check to dpdk_mp_get() when calling dpdk_mp_create(). * Add return type check when calling netdev_dpdk_mempool_configure() in netdev_dpdk_reconfigure(). * Add return type check when calling netdev_dpdk_mempool_configure() in netdev_vhost_reconfigure_helper() --- lib/netdev-dpdk.c | 20 +++++++++++++------- 1 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index ee53c4c..67905c4 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -530,7 +530,9 @@ dpdk_mp_get(int socket_id, int mtu) } dmp = dpdk_mp_create(socket_id, mtu); - ovs_list_push_back(&dpdk_mp_list, &dmp->list_node); + if (dmp) { + ovs_list_push_back(&dpdk_mp_list, &dmp->list_node); + } out: ovs_mutex_unlock(&dpdk_mp_mutex); @@ -3131,7 +3133,10 @@ netdev_dpdk_reconfigure(struct netdev *netdev) if (dev->mtu != dev->requested_mtu || dev->socket_id != dev->requested_socket_id) { - netdev_dpdk_mempool_configure(dev); + err = netdev_dpdk_mempool_configure(dev); + if (err) { + goto out; + } } netdev->n_txq = dev->requested_n_txq; @@ -3160,6 +3165,7 @@ dpdk_vhost_reconfigure_helper(struct netdev_dpdk *dev) { dev->up.n_txq = dev->requested_n_txq; dev->up.n_rxq = dev->requested_n_rxq; + int err; /* Enable TX queue 0 by default if it wasn't disabled. */ if (dev->tx_q[0].map == OVS_VHOST_QUEUE_MAP_UNKNOWN) { @@ -3170,15 +3176,15 @@ dpdk_vhost_reconfigure_helper(struct netdev_dpdk *dev) if (dev->requested_socket_id != dev->socket_id || dev->requested_mtu != dev->mtu) { - if (!netdev_dpdk_mempool_configure(dev)) { + err = netdev_dpdk_mempool_configure(dev); + if (err) { + return err; + } + else { netdev_change_seq_changed(&dev->up); } } - if (!dev->dpdk_mp) { - return ENOMEM; - } - if (netdev_dpdk_get_vid(dev) >= 0) { dev->vhost_reconfigured = true; }