[v2] ethdev: do not allow to close started device

Message ID 20211020131540.2957180-1-andrew.rybchenko@oktetlabs.ru (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v2] ethdev: do not allow to close started device |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/Intel-compilation warning apply issues
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Andrew Rybchenko Oct. 20, 2021, 1:15 p.m. UTC
  Ethernet device must be stopped first before close in accordance
with the documentation.

Fixes: 980995f8cc56 ("ethdev: improve API comments of close and detach functions")
Cc: stable@dpdk.org

Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
In fact the patch is required to fix segfault in the case of
net/virtio on close without stop after Rx interrupts enabled.

 lib/ethdev/rte_ethdev.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Thomas Monjalon Oct. 20, 2021, 1:36 p.m. UTC | #1
20/10/2021 15:15, Andrew Rybchenko:
> Ethernet device must be stopped first before close in accordance
> with the documentation.
> 
> Fixes: 980995f8cc56 ("ethdev: improve API comments of close and detach functions")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

Acked-by: Thomas Monjalon <thomas@monjalon.net>
  
Ajit Khaparde Oct. 20, 2021, 4:22 p.m. UTC | #2
On Wed, Oct 20, 2021 at 6:37 AM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> 20/10/2021 15:15, Andrew Rybchenko:
> > Ethernet device must be stopped first before close in accordance
> > with the documentation.
> >
> > Fixes: 980995f8cc56 ("ethdev: improve API comments of close and detach functions")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>
> Acked-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>

>
>
  
Ferruh Yigit Oct. 20, 2021, 5:25 p.m. UTC | #3
On 10/20/2021 5:22 PM, Ajit Khaparde wrote:
> On Wed, Oct 20, 2021 at 6:37 AM Thomas Monjalon <thomas@monjalon.net> wrote:
>>
>> 20/10/2021 15:15, Andrew Rybchenko:
>>> Ethernet device must be stopped first before close in accordance
>>> with the documentation.
>>>
>>> Fixes: 980995f8cc56 ("ethdev: improve API comments of close and detach functions")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>>
>> Acked-by: Thomas Monjalon <thomas@monjalon.net>
> Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
> 

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 3b8ef9ef22..f981e0226a 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -1893,6 +1893,12 @@  rte_eth_dev_close(uint16_t port_id)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
+	if (dev->data->dev_started) {
+		RTE_ETHDEV_LOG(ERR, "Cannot close started device (port %u)\n",
+			       port_id);
+		return -EINVAL;
+	}
+
 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP);
 	*lasterr = (*dev->dev_ops->dev_close)(dev);
 	if (*lasterr != 0)