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 6522BA0C43; Wed, 20 Oct 2021 12:47:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E5E1240687; Wed, 20 Oct 2021 12:47:23 +0200 (CEST) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id 9558640142 for ; Wed, 20 Oct 2021 12:47:22 +0200 (CEST) Received: by shelob.oktetlabs.ru (Postfix, from userid 122) id 3487C7F5F5; Wed, 20 Oct 2021 13:47:22 +0300 (MSK) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shelob.oktetlabs.ru X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=ALL_TRUSTED, DKIM_ADSP_DISCARD, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from aros.oktetlabs.ru (aros.oktetlabs.ru [192.168.38.17]) by shelob.oktetlabs.ru (Postfix) with ESMTP id 73A677F504; Wed, 20 Oct 2021 13:47:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru 73A677F504 Authentication-Results: shelob.oktetlabs.ru/73A677F504; dkim=none; dkim-atps=neutral From: Andrew Rybchenko To: Thomas Monjalon , Ferruh Yigit Cc: dev@dpdk.org, Ivan Ilchenko , Maxime Coquelin , Chenbo Xia Date: Wed, 20 Oct 2021 13:47:14 +0300 Message-Id: <20211020104715.2526074-1-andrew.rybchenko@oktetlabs.ru> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] ethdev: stop the device before close 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 Sender: "dev" From: Ivan Ilchenko In drivers important cleanup could happen on the device stop. Do stop in the rte_eth_dev_close() function for robustness and to simplify drivers code. Signed-off-by: Ivan Ilchenko Signed-off-by: Andrew Rybchenko --- In fact the patch is required to fix segfault in the case of net/virtio on close without stop after Rx interrupts enabled. I believe that the right way to address the problem is automated stop from close, but I guess it cannot not be backported and may be fix in a different way required in stable branches. lib/ethdev/rte_ethdev.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index a151c05849..b9f0938f20 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -1894,6 +1894,17 @@ rte_eth_dev_close(uint16_t port_id) dev = &rte_eth_devices[port_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP); + + if (dev->data->dev_started) { + *lasterr = rte_eth_dev_stop(port_id); + if (*lasterr != 0) { + RTE_ETHDEV_LOG(ERR, + "Failed to stop device (port %u) before close: %s - ignore\n", + port_id, rte_strerror(-*lasterr)); + lasterr = &binerr; + } + } + *lasterr = (*dev->dev_ops->dev_close)(dev); if (*lasterr != 0) lasterr = &binerr; -- 2.30.2