* [dpdk-dev] [PATCH] net/cxgbe: free resources in dev_uninit function
@ 2018-05-12 11:50 Rahul Lakkireddy
2018-05-14 12:19 ` Ferruh Yigit
0 siblings, 1 reply; 2+ messages in thread
From: Rahul Lakkireddy @ 2018-05-12 11:50 UTC (permalink / raw)
To: dev; +Cc: kumaras, nirranjan, indranil
Move freeing up resources from dev_close() to dev_uninit(). This fixes
NULL pointer de-reference when accessing adapter context needed by
other ports under same PF, but had been freed up by the first port.
This can happen if only the first port is started up and the check
to free up all resources is still satisfied. When dev_close is
called for other ports, adapter context is NULL since it was freed
up by the first port.
Thus, by moving to dev_uninit() all the ports can be teared down
safely without need for extra checks.
Fixes: 2195df6d11bd ("net/cxgbe: rework ethdev device allocation")
Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
Signed-off-by: Kumar Sanghvi <kumaras@chelsio.com>
---
drivers/net/cxgbe/cxgbe_ethdev.c | 29 +++++++++++------------------
1 file changed, 11 insertions(+), 18 deletions(-)
diff --git a/drivers/net/cxgbe/cxgbe_ethdev.c b/drivers/net/cxgbe/cxgbe_ethdev.c
index 14011bb..3ee7c44 100644
--- a/drivers/net/cxgbe/cxgbe_ethdev.c
+++ b/drivers/net/cxgbe/cxgbe_ethdev.c
@@ -256,7 +256,6 @@ void cxgbe_dev_close(struct rte_eth_dev *eth_dev)
{
struct port_info *pi = (struct port_info *)(eth_dev->data->dev_private);
struct adapter *adapter = pi->adapter;
- int i, dev_down = 0;
CXGBE_FUNC_TRACE();
@@ -270,22 +269,6 @@ void cxgbe_dev_close(struct rte_eth_dev *eth_dev)
* have been disabled
*/
t4_sge_eth_clear_queues(pi);
-
- /* See if all ports are down */
- for_each_port(adapter, i) {
- pi = adap2pinfo(adapter, i);
- /*
- * Skip first port of the adapter since it will be closed
- * by DPDK
- */
- if (i == 0)
- continue;
- dev_down += (pi->eth_dev->data->dev_started == 0) ? 1 : 0;
- }
-
- /* If rest of the ports are stopped, then free up resources */
- if (dev_down == (adapter->params.nports - 1))
- cxgbe_close(adapter);
}
/* Start the device.
@@ -1143,6 +1126,16 @@ static int eth_cxgbe_dev_init(struct rte_eth_dev *eth_dev)
return err;
}
+static int eth_cxgbe_dev_uninit(struct rte_eth_dev *eth_dev)
+{
+ struct port_info *pi = (struct port_info *)(eth_dev->data->dev_private);
+ struct adapter *adap = pi->adapter;
+
+ /* Free up other ports and all resources */
+ cxgbe_close(adap);
+ return 0;
+}
+
static int eth_cxgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
struct rte_pci_device *pci_dev)
{
@@ -1152,7 +1145,7 @@ static int eth_cxgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
static int eth_cxgbe_pci_remove(struct rte_pci_device *pci_dev)
{
- return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
+ return rte_eth_dev_pci_generic_remove(pci_dev, eth_cxgbe_dev_uninit);
}
static struct rte_pci_driver rte_cxgbe_pmd = {
--
2.5.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [dpdk-dev] [PATCH] net/cxgbe: free resources in dev_uninit function
2018-05-12 11:50 [dpdk-dev] [PATCH] net/cxgbe: free resources in dev_uninit function Rahul Lakkireddy
@ 2018-05-14 12:19 ` Ferruh Yigit
0 siblings, 0 replies; 2+ messages in thread
From: Ferruh Yigit @ 2018-05-14 12:19 UTC (permalink / raw)
To: Rahul Lakkireddy, dev; +Cc: kumaras, nirranjan, indranil
On 5/12/2018 12:50 PM, Rahul Lakkireddy wrote:
> Move freeing up resources from dev_close() to dev_uninit(). This fixes
> NULL pointer de-reference when accessing adapter context needed by
> other ports under same PF, but had been freed up by the first port.
> This can happen if only the first port is started up and the check
> to free up all resources is still satisfied. When dev_close is
> called for other ports, adapter context is NULL since it was freed
> up by the first port.
>
> Thus, by moving to dev_uninit() all the ports can be teared down
> safely without need for extra checks.
>
> Fixes: 2195df6d11bd ("net/cxgbe: rework ethdev device allocation")
> Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
> Signed-off-by: Kumar Sanghvi <kumaras@chelsio.com>
Applied to dpdk-next-net/master, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-05-14 12:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-12 11:50 [dpdk-dev] [PATCH] net/cxgbe: free resources in dev_uninit function Rahul Lakkireddy
2018-05-14 12:19 ` Ferruh Yigit
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).