From patchwork Mon Jul 3 06:37:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianfeng Tan X-Patchwork-Id: 26232 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 41BA3374F; Mon, 3 Jul 2017 08:36:41 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 083372E83; Mon, 3 Jul 2017 08:36:38 +0200 (CEST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jul 2017 23:36:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,301,1496127600"; d="scan'208";a="122121417" Received: from dpdk06.sh.intel.com ([10.67.111.82]) by fmsmga006.fm.intel.com with ESMTP; 02 Jul 2017 23:36:34 -0700 From: Jianfeng Tan To: dev@dpdk.org Cc: thomas@monjalon.net, yuanhan.liu@linux.intel.com, maxime.coquelin@redhat.com, Jianfeng Tan , stable@dpdk.org Date: Mon, 3 Jul 2017 06:37:31 +0000 Message-Id: <1499063851-10209-1-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496420451-104928-1-git-send-email-jianfeng.tan@intel.com> References: <1496420451-104928-1-git-send-email-jianfeng.tan@intel.com> Subject: [dpdk-dev] [PATCH v2] eal: fix secondary process segfault on multipe virtio devices 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" Suppose we have 2 virtio devices for a VM, with only the first one, virtio0, binding to igb_uio. Start a primary DPDK process, driving only virtio0. Then start a secondary DPDK process, it encounters segfault at eth_virtio_dev_init() because hw is NULL, when trying to initialize the 2nd virtio devices. 1539 if (!hw->virtio_user_dev) { We could add a precheck to return error when hw is NULL. But the root cause is that virtio devices which are not driven by the primary process are not exluded by secondary eal probe function. To support legacy virtio devices bound to none kernel driver, we removed RTE_PCI_DRV_NEED_MAPPING in commit 962cf902e6eb ("pci: export device mapping functions"). At the boot of primary process, ether dev is allocated in rte_eth_devices array, rte_eth_dev_data is also allocated in rte_eth_dev_data array; then probe function fails; and ether dev is released. However, the entry in rte_eth_dev_data array is not cleared. Then we start secondary process, and try to attach the virtio device that not used in primary process, the field, dev_private (or hw), in rte_eth_dev_data, is NULL. To fail the dev attach, we need to clear the field, name, when we release any ether devices in primary, so that below loop in rte_eth_dev_attach_secondary() will not find any matched names. for (i = 0; i < RTE_MAX_ETHPORTS; i++) { if (strcmp(rte_eth_dev_data[i].name, name) == 0) break; } Fixes: 6d890f8ab512 ("Fixes: net/virtio: fix multiple process support") Cc: stable@dpdk.org Reported-by: Reshma Pattan Signed-off-by: Jianfeng Tan --- v2: - Assign '\0' to first char of name instead of memset as per Thomas's advice. lib/librte_ether/rte_ethdev_pci.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/librte_ether/rte_ethdev_pci.h b/lib/librte_ether/rte_ethdev_pci.h index 69aab03..0e7d7a9 100644 --- a/lib/librte_ether/rte_ethdev_pci.h +++ b/lib/librte_ether/rte_ethdev_pci.h @@ -133,6 +133,12 @@ rte_eth_dev_pci_release(struct rte_eth_dev *eth_dev) eth_dev->data->dev_private = NULL; + /* Secondary process will use the field, name, for secondary + * attach, clear this field to avoid attaching any released + * ports in secondary processes. + */ + eth_dev->data->name[0] = '\0'; + eth_dev->device = NULL; eth_dev->intr_handle = NULL; }