From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A8C08A0544; Mon, 10 Oct 2022 21:49:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8B88440143; Mon, 10 Oct 2022 21:49:53 +0200 (CEST) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by mails.dpdk.org (Postfix) with ESMTP id D9D8540041 for ; Mon, 10 Oct 2022 21:49:52 +0200 (CEST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 001CC5C0079; Mon, 10 Oct 2022 15:49:49 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 10 Oct 2022 15:49:50 -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=fm3; t=1665431389; x= 1665517789; bh=RlvMhDEgMB/zk+aHs6FKGyTo9YDqL8DlsKAek9UWvL0=; b=W 1y3dY02M6RT4SC/fP+Jb98GFulnzBSFprD25XMtRVqnY6nC0QgAM2bvi2mzFTyVE oyk4NM1yRf76eO1NuRomy0gWpLl8Qb3IiERrKCY2g2WUisjzu3NjJhD2VfayK6OT qukKTHLqbMS11z3GjTQjqr0Jihhl+Tqq6K+PlZl29Ie5fEn+Q4YG29py0Xvxwo4t nSZiy9Lmoy93OnKZFXANgU42Bu3/G9RyoW3hOfzruvQltUd/wGhOtdNPVMIr8Ey4 TMCRgWRaBBulM0otA5/Gy5/smlnUbsnGfFBYIF3VR6tmCnB0cYe15e9SBrnAJIlg Fuio1Kb6iTUo/eFOB4LOw== 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=fm3; t=1665431389; x= 1665517789; bh=RlvMhDEgMB/zk+aHs6FKGyTo9YDqL8DlsKAek9UWvL0=; b=b qtKRUzruXbEXC39P6QJNLFveXAJuJPtZzY2Htk6giDNEHFpyyCyXouDtgi2N2FFh S3QTt4POGgnDAfyTeEnn4hhSiozjlvRnWR13Al9q6VO4+gATJpywl1SWHoWSqrfH 8n2vPCJDwPqaHtxWEMlynLsSpXUwVWAB1Kcqgka2wQ1DRSp9U8o3BFTH11btCdfa HWLuXi+afdqG8fD2302keEFKeg3ghsQCTLm+YsBPQcpXsngoXhzGYVHqmIvts1d9 XcfF4fBBw6vJW+e39d9ea6zwCGtOFi2sn7wqWNQYoFNeYuyLw5tC8KtRJex9GvqH xbh9mu83RqPuzQvZu0XIA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeejgedgudefhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttddvnecuhfhrohhmpefvhhho mhgrshcuofhonhhjrghlohhnuceothhhohhmrghssehmohhnjhgrlhhonhdrnhgvtheqne cuggftrfgrthhtvghrnheptdejieeifeehtdffgfdvleetueeffeehueejgfeuteeftddt ieekgfekudehtdfgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepthhhohhmrghssehmohhnjhgrlhhonhdrnhgvth X-ME-Proxy: Feedback-ID: i47234305:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 10 Oct 2022 15:49:48 -0400 (EDT) From: Thomas Monjalon To: Huisong Li Cc: dev@dpdk.org, ferruh.yigit@xilinx.com, andrew.rybchenko@oktetlabs.ru, huangdaode@huawei.com, david.marchand@redhat.com Subject: Re: [PATCH V2 1/6] bus/pci: fix a segfault when call callback Date: Mon, 10 Oct 2022 21:49:46 +0200 Message-ID: <11178860.MucGe3eQFb@thomas> In-Reply-To: <20220915124522.5407-2-lihuisong@huawei.com> References: <20220825024425.10534-1-lihuisong@huawei.com> <20220915124522.5407-1-lihuisong@huawei.com> <20220915124522.5407-2-lihuisong@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 15/09/2022 14:45, Huisong Li: > After the driver probe is executed, the callback in application will > be called. The callback in application may call some APIs which access the > rte_pci_driver::driver by the device::driver pointer to get driver > information. If the rte_pci_device::device::driver pointer isn't pointed to > rte_pci_driver::driver in rte_pci_probe_one_driver, a segfault will occur. > For example, when ethdev driver probe completes, the callback in > application call rte_eth_dev_info_get which use dev->device->driver->name. > So rte_pci_device::device::driver should point to rte_pci_driver::driver > before executing the driver probe. > > Fixes: c752998b5e2e ("pci: introduce library and driver") > Cc: stable@dpdk.org To be more precise, it is reverting 391797f04208 ("drivers/bus: move driver assignment to end of probing") dev->device.driver is used by rte_dev_is_probed(): int rte_dev_is_probed(const struct rte_device *dev) { /* The field driver should be set only when the probe is successful. */ return dev->driver != NULL; } And the field comment is clear in rte_device: const struct rte_driver *driver; /**< Driver assigned after probing */ That's why I am not enthusiastic about setting this pointer before probing. I understand it is more convenient to use this pointer in a probing callback. We need to check it is not breaking rte_dev_is_probed() usage. It may be OK if there is no parallel probing, and rte_dev_is_probed() is not called inside probing. At the very minimum, we need to update some comments in the code, to mention that the pointer is set before probing, and reset if probing failed.