From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 17503A00C4;
	Mon, 30 May 2022 10:28:12 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id F07FE42B75;
	Mon, 30 May 2022 10:28:11 +0200 (CEST)
Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com
 [66.111.4.29]) by mails.dpdk.org (Postfix) with ESMTP id 9D8D140A8A;
 Mon, 30 May 2022 10:28:10 +0200 (CEST)
Received: from compute2.internal (compute2.nyi.internal [10.202.2.46])
 by mailout.nyi.internal (Postfix) with ESMTP id 540995C019B;
 Mon, 30 May 2022 04:28:08 -0400 (EDT)
Received: from mailfrontend1 ([10.202.2.162])
 by compute2.internal (MEProxy); Mon, 30 May 2022 04:28:08 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h=
 cc:cc:content-transfer-encoding:content-type:date:date:from:from
 :in-reply-to:in-reply-to:message-id:mime-version:references
 :reply-to:sender:subject:subject:to:to; s=fm1; t=1653899288; x=
 1653985688; bh=ad2mX9HUme3/rYzvNbf1Nd+6cD6TIRScENU5ZobUih4=; b=t
 7Mnt8+/KU4JlR87k9/gRiAmxq85+hFz/6qKdgFk9BDMux5V6wdf9lZRj5RgZ/CzJ
 bwi2tcRRoFVr+o3Gr1rP4T0tykZmmKSCLjN25Mkes1zyytkDKzUW80gOZejHPYLy
 nL+POUz541l9aZLiMNMrG3vt6dP0YBddY/XDqoCpD2MoZoTH7SCCFy80xrlEjA5z
 ZxKLvRUJ3++GGF1dSVwU72yjRC1ne77/dD3fCR8HR+a+Q1RvZ6nwYv9u86bmAt4V
 KFQLjmKTDtcjmzWGuVysWVlwA2SO+P9gEQVZudZOLJGlzFPu2tHJqXAiV9oEwyvk
 lUsgeCLYtJ013+pVPbaLA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:cc:content-transfer-encoding
 :content-type:date:date:feedback-id:feedback-id:from:from
 :in-reply-to:in-reply-to:message-id:mime-version:references
 :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy
 :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1653899288; x=
 1653985688; bh=ad2mX9HUme3/rYzvNbf1Nd+6cD6TIRScENU5ZobUih4=; b=S
 vdMRhEbkk/hGGhYjvUjuEgFQ5Ri7BbAs6U5ud4pv9bk9aVLi3LGjEt3tSsJBaSEm
 yk2Ah3wNs/8zVl3gjMTxd7mjjzCLL4ueFbFOLk1ZewKIdCILIWAWPYWU6QN6rQCv
 9I7c2t7tbI1o69OwecgYM/htDtvi9bV202DFZtCUw26q2fvfRoV7/EuP5+IdulAy
 UFHOpcYCF9QZmidb+cXxfLMVQHbKxQgeSr6ClCdtAsMeys842lUeA9V3cqNHWvrK
 dUuW7GiTEVBSyw5AGPso3XvT22KxLTfp7C2hcHCvcsy8RxQYmd6JYD7tsAgmp+PS
 rLmj3o5t4ehFqbpWZxpxg==
X-ME-Sender: <xms:F4CUYtOgicB9P_NpWQ3F4ZsUYjCcPCMydKlV9ifwAHMQiMmCx3Tb6A>
 <xme:F4CUYv8nkSUiDy9rrklOe-teBf2MiVIcUwhTqcEda1MhjggNUu-yeevmElAhFjMAX
 Zm62SuJ4jbC-1WXBw>
X-ME-Received: <xmr:F4CUYsR5MWHxZIa-WJDKDg6HcSHxvjtvFlZFvaOdc2FF7m01vYl6eSAH82vTiDoJxsHwxfH-KQBiRF7zryoKe-A>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrkeeigddtfecutefuodetggdotefrodftvf
 curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu
 uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc
 fjughrpefhvfevufffkfgjfhgggfgtsehtqhertddttdejnecuhfhrohhmpefvhhhomhgr
 shcuofhonhhjrghlohhnuceothhhohhmrghssehmohhnjhgrlhhonhdrnhgvtheqnecugg
 ftrfgrthhtvghrnhepgedttdeljeejgeffkeekkedtjeevtdehvedtkeeivdeuuedviedu
 vdelveejueejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh
 homhepthhhohhmrghssehmohhnjhgrlhhonhdrnhgvth
X-ME-Proxy: <xmx:F4CUYptcClPEUhEiv6lylfC9-e7082HEnskYKpA5nQ4QhxOfCRflig>
 <xmx:F4CUYld0xK9P_1uTsRHk4zn7tnV29K8wbYP56a-wI2cLpKCmAbr-Tw>
 <xmx:F4CUYl1PRoqVLO04FtbXGUYiohn7zT6ImqCt8d83QiCfnOlGdd83mg>
 <xmx:GICUYtTgPKEleDTgRZ6_EVExnczR_u76JhdXg7FHYSgwh1KomsAljA>
Feedback-ID: i47234305:Fastmail
Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon,
 30 May 2022 04:28:05 -0400 (EDT)
From: Thomas Monjalon <thomas@monjalon.net>
To: "Min Hu (Connor)" <humin29@huawei.com>,
 Ferruh Yigit <ferruh.yigit@intel.com>,
 Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
 David Marchand <david.marchand@redhat.com>,
 "lihuisong (C)" <lihuisong@huawei.com>
Cc: dev <dev@dpdk.org>, dpdk stable <stable@dpdk.org>,
 Bruce Richardson <bruce.richardson@intel.com>
Subject: Re: [PATCH] ethdev: fix push new event
Date: Mon, 30 May 2022 10:28:03 +0200
Message-ID: <11986117.O9o76ZdvQC@thomas>
In-Reply-To: <3a28b653-b83a-6cb5-bf5a-a04c144ba497@huawei.com>
References: <20220521065549.33451-1-humin29@huawei.com>
 <2199956.o7ts2hSHzF@thomas> <3a28b653-b83a-6cb5-bf5a-a04c144ba497@huawei.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="UTF-8"
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

28/05/2022 10:53, lihuisong (C):
>=20
> =E5=9C=A8 2022/5/23 22:36, Thomas Monjalon =E5=86=99=E9=81=93:
> > 23/05/2022 11:51, David Marchand:
> >> On Sat, May 21, 2022 at 8:57 AM Min Hu (Connor)<humin29@huawei.com>  w=
rote:
> >>> From: Huisong Li<lihuisong@huawei.com>
> >>>
> >>> The 'state' in struct rte_eth_dev may be used to update some informat=
ion
> >>> when app receive these events. For example, when app receives a new e=
vent,
> >>> app may get the socket id of this port by calling rte_eth_dev_socket_=
id to
> >>> setup the attached port. The 'state' is used in rte_eth_dev_socket_id.
> >>>
> >>> If the state isn't modified to RTE_ETH_DEV_ATTACHED before pushing th=
e new
> >>> event, app will get the socket id failed. So this patch moves pushing=
 event
> >>> operation after the state updated.
> >>>
> >>> Fixes: 99a2dd955fba ("lib: remove librte_ prefix from directory names=
")
> >> A patch moving code is unlikely to be at fault.
> >>
> >>
> >> Looking at the patch which moved those notifications in this point of
> >> the code, the state update was pushed after the notification on
> >> purpose.
> >> See be8cd210379a ("ethdev: fix port probing notification")
> >>
> >>      ethdev: fix port probing notification
> >>
> >>      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 do=
ne
> >>      by the PMD, but before the state is changed, in order to let
> >>      notified entities taking ownership before general availability.
> >>
> >>
> >> Do we need an intermediate state during probing?
> > Possibly. Currently we have only 3 states:
> > 	RTE_ETH_DEV_UNUSED
> > 	RTE_ETH_DEV_ATTACHED
> > 	RTE_ETH_DEV_REMOVED
> >
> > We may add RTE_ETH_DEV_ALLOCATED just before calling
> > 	rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_NEW, NULL);
> > Then we would need to check against RTE_ETH_DEV_ALLOCATED
> > in some ethdev functions.
> >
> Hi, Thomas,
>=20
> Do you mean that we need to modify some funcions like following?
>=20
> int rte_eth_dev_is_valid_port(uint16_t port_id)
> {
>      if (port_id >=3D RTE_MAX_ETHPORTS ||
>          (rte_eth_devices[port_id].state !=3D *RTE_ETH_DEV_ALLOCATED*))
>          return 0;
>      else
>          return 1;
> }
>=20
> uint16_t rte_eth_find_next(uint16_t port_id)
> {
>      while (port_id < RTE_MAX_ETHPORTS &&
>              rte_eth_devices[port_id].state !=3D *RTE_ETH_DEV_ALLOCATED*)
>          port_id++;
>=20
>      if (port_id >=3D RTE_MAX_ETHPORTS)
>          return RTE_MAX_ETHPORTS;
>=20
>      return port_id;
> }

Yes this is what I mean.