From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <thomas@monjalon.net>
Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com
 [66.111.4.25]) by dpdk.org (Postfix) with ESMTP id 379861B795
 for <dev@dpdk.org>; Thu, 10 May 2018 00:43:29 +0200 (CEST)
Received: from compute1.internal (compute1.nyi.internal [10.202.2.41])
 by mailout.nyi.internal (Postfix) with ESMTP id C32DB2281B;
 Wed,  9 May 2018 18:43:27 -0400 (EDT)
Received: from mailfrontend1 ([10.202.2.162])
 by compute1.internal (MEProxy); Wed, 09 May 2018 18:43:27 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h=
 date:from:in-reply-to:message-id:references:subject:to
 :x-me-sender:x-me-sender:x-sasl-enc; s=mesmtp; bh=RdDl1NLVjl/H0M
 TmfQW1pPUqlzWVD9r6AN5h9Q4Ymyw=; b=F9YNGB4JHcNgodPOTrImr1huebNaYl
 ZVHQFVsKK4PHYTcqtcFYmSr6dQcI7TVRNc+PdYqV1J5uPBv2+77yjNIXOuiNMJdT
 6rbsby5qBCcHAUK6iKT7RIM+Krxb+PvsrThomQcuxuCbFJdd5fhdPN58tKvsxNYV
 SzNVj5Sf3V/Ww=
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=date:from:in-reply-to:message-id
 :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=
 fm2; bh=RdDl1NLVjl/H0MTmfQW1pPUqlzWVD9r6AN5h9Q4Ymyw=; b=a5TU6JnB
 tu0+msTGrem5MF4TVOfOyzK0kIlBsPhbXaeK3bEY0J36GwpNv8FiygSRJO7KsZcG
 2XUBevAk/WEDs4G6Xj+S4GsCJogChMoa3EfSxkdWywfDuAvbxYjNREVhMwbWGm9B
 Z9aul5k81b2KKon9k4IKKqgpLoMR2BpAVAwd9DTwdDO0zq3RxLxdt1MiSXJdReEJ
 96P+dC86DTF8Pwy7NIIwy9ZeC4nmXb7QDaXjqs3ScFRnH/MxmDHsUFBPU5GTB7pb
 ZYL3CdpeuOsBosjz1Eg0KoP3TCAbFrCM06alrE46kew425GLhh1fX/PssTa7nGpW
 4swmvnYsMzlK5Q==
X-ME-Sender: <xms:j3nzWs3hGhPCdKkqFedN0GVwjDAIolcN6hMSX63PgiUVnyCZlEsodA>
Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184])
 by mail.messagingengine.com (Postfix) with ESMTPA id 4E037E4B94
 for <dev@dpdk.org>; Wed,  9 May 2018 18:43:27 -0400 (EDT)
From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Date: Thu, 10 May 2018 00:43:11 +0200
Message-Id: <20180509224313.27289-10-thomas@monjalon.net>
X-Mailer: git-send-email 2.16.2
In-Reply-To: <20180509224313.27289-1-thomas@monjalon.net>
References: <20180509094337.26112-1-thomas@monjalon.net>
 <20180509224313.27289-1-thomas@monjalon.net>
Subject: [dpdk-dev] [PATCH v2 09/11] ethdev: fix port probing notification
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 09 May 2018 22:43:29 -0000

The new device was notified as soon as it was allocated.
It leads to use a device which is not yet initialized.

The notification must be published after the initialization is done
by the PMD, but before the state is changed, in order to let
notified entities taking ownership before general availability.

Fixes: 29aa41e36de7 ("ethdev: add notifications for probing and removal")
Cc: stable@dpdk.org

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_ethdev/rte_ethdev.c        | 5 ++---
 lib/librte_ethdev/rte_ethdev_driver.h | 2 ++
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index c5d9c7fe4..023e31d88 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -315,9 +315,6 @@ rte_eth_dev_allocate(const char *name)
 unlock:
 	rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
 
-	if (eth_dev != NULL)
-		_rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_NEW, NULL);
-
 	return eth_dev;
 }
 
@@ -3386,6 +3383,8 @@ rte_eth_dev_probing_finish(struct rte_eth_dev *dev)
 	if (dev == NULL)
 		return;
 
+	_rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_NEW, NULL);
+
 	dev->state = RTE_ETH_DEV_ATTACHED;
 }
 
diff --git a/lib/librte_ethdev/rte_ethdev_driver.h b/lib/librte_ethdev/rte_ethdev_driver.h
index 3640dff68..c9c825e3f 100644
--- a/lib/librte_ethdev/rte_ethdev_driver.h
+++ b/lib/librte_ethdev/rte_ethdev_driver.h
@@ -106,6 +106,8 @@ int _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
  * This is the last step of device probing.
  * It must be called after a port is allocated and initialized successfully.
  *
+ * The notification RTE_ETH_EVENT_NEW is sent to other entities
+ * (libraries and applications).
  * The state is set as RTE_ETH_DEV_ATTACHED.
  *
  * @param dev
-- 
2.16.2