From patchwork Fri Nov 23 21:26:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Stojaczyk, Dariusz" X-Patchwork-Id: 48332 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 E651B1B5E7; Fri, 23 Nov 2018 22:38:19 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 05B2D1B5BD for ; Fri, 23 Nov 2018 22:38:17 +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 fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Nov 2018 13:38:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,271,1539673200"; d="scan'208";a="110648301" Received: from violet.igk.intel.com ([10.102.54.137]) by fmsmga001.fm.intel.com with ESMTP; 23 Nov 2018 13:38:15 -0800 From: Darek Stojaczyk To: dev@dpdk.org Cc: thomas@monjalon.net, Darek Stojaczyk , qi.z.zhang@intel.com Date: Fri, 23 Nov 2018 22:26:40 +0100 Message-Id: <20181123212640.111642-1-dariusz.stojaczyk@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181123144506.95367-1-dariusz.stojaczyk@intel.com> References: <20181123144506.95367-1-dariusz.stojaczyk@intel.com> Subject: [dpdk-dev] [PATCH v2] dev: fix attach rollback of a device that was already attached 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" When primary process receives an IPC attach request of a device that's already locally-attached, it doesn't setup its variables properly and is prone to segfaulting on a subsequent rollback. `ret = local_dev_probe(req->devargs, &dev)` The above function will set `dev` pointer to the proper device *unless* it returns with error. One of those errors is -EEXIST, which the hotplug function explicitly ignores. For -EEXIST, it proceeds with attaching the device and expects the dev pointer to be valid. This patch makes `local_dev_probe` set the dev pointer even if it returns -EEXIST. Fixes: ac9e4a17370f ("eal: support attach/detach shared device from secondary") Cc: qi.z.zhang@intel.com Signed-off-by: Darek Stojaczyk --- Changes since v1: * attempt to detach the device in primary process (Qi) lib/librte_eal/common/eal_common_dev.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 1fdc9ab17..a08dc085f 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -168,16 +168,14 @@ 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 */ + if (ret && !rte_dev_is_probed(dev)) { /* if hasn't ever succeeded */ RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", dev->name); goto err_devarg; } *new_dev = dev; - return 0; + return ret; err_devarg: if (rte_devargs_remove(da) != 0) {