From patchwork Wed Nov 21 19:38:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Stojaczyk, Dariusz" X-Patchwork-Id: 48231 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 [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 249061B12B; Wed, 21 Nov 2018 20:49:59 +0100 (CET) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 883B71B123 for ; Wed, 21 Nov 2018 20:49:57 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2018 11:49:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,262,1539673200"; d="scan'208";a="110100702" Received: from violet.igk.intel.com ([10.102.54.137]) by fmsmga001.fm.intel.com with ESMTP; 21 Nov 2018 11:49:55 -0800 From: Darek Stojaczyk To: dev@dpdk.org Cc: Darek Stojaczyk , gaetan.rivet@6wind.com, thomas@monjalon.net Date: Wed, 21 Nov 2018 20:38:27 +0100 Message-Id: <20181121193827.62540-1-dariusz.stojaczyk@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181121183750.33796-1-dariusz.stojaczyk@intel.com> References: <20181121183750.33796-1-dariusz.stojaczyk@intel.com> Subject: [dpdk-dev] [PATCH v2] dev: don't remove devargs that are still referenced 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" Even if a device failed to plug, it's still a device object that references the devargs. Those devargs will be freed automatically together with the device, but freeing them any earlier - like it's done in the hotplug error handling path right now - will give us a dangling pointer and a segfault scenario. Consider the following case: * secondary process receives the hotplug request IPC message * devargs are either created or updated * the bus is scanned * a new device object is created with the latest devargs * the device can't be plugged for whatever reason, bus->plug returns error * the devargs are freed, even though they're still referenced by the device object on the bus For PCI devices, the generic device name comes from a buffer within the devargs. Freeing those will make EAL segfault whenever the device name is checked. This patch just prevents the hotplug error handling path from removing the devargs when there's a device that references them. This is done by simply exiting early from the hotplug function. As mentioned in the beginning, those devargs will be freed later, together with the device itself. Fixes: 7e8b26650146 ("eal: fix hotplug add / remove") Cc: gaetan.rivet@6wind.com Cc: thomas@monjalon.net Signed-off-by: Darek Stojaczyk --- lib/librte_eal/common/eal_common_dev.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 1fdc9ab17..b6fc5e437 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -169,11 +169,10 @@ local_dev_probe(const char *devargs, struct rte_device **new_dev) ret = dev->bus->plug(dev); if (ret) { - if (rte_dev_is_probed(dev)) /* if already succeeded earlier */ - return ret; /* no rollback */ - RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", - dev->name); - goto err_devarg; + if (!rte_dev_is_probed(dev)) /* if hasn't succeeded earlier */ + RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", + dev->name); + return ret; } *new_dev = dev;