Skip to contentSkip to conversation

vdpa/mlx5: Fix double release of debugfs entry

PATCH In review Dragos Tatulea 2 participants 3 messages Aug 29, 2023 – Sep 15, 2023

Subsystems (2)
lore
Share & tools
lore

Dragos Tatulea

author maintainer
#0 lore raw

PATCH 1/1 vdpa/mlx5: Fix double release of debugfs entry

The error path in setup_driver deletes the debugfs entry but doesn't clear the pointer. During .dev_del the invalid pointer will be released again causing a crash.

This patch fixes the issue by always clearing the debugfs entry in mlx5_vdpa_remove_debugfs. Also, stop removing the debugfs entry in .dev_del op: the debugfs entry is already handled within the setup_driver/teardown_driver scope.

Fixes f0417e72add5 ("vdpa/mlx5: Add and remove debugfs in setup/teardown driver")
---
 drivers/vdpa/mlx5/net/debug.c     | 5 +++--
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 7 ++-----
 drivers/vdpa/mlx5/net/mlx5_vnet.h | 2 +-
 3 files changed, 6 insertions(+), 8 deletions(-)
drivers/vdpa/mlx5/net/debug.c +3 -2
index 60d6ac68cdc4..9c85162c19fc 100644
@@ -146,7 +146,8 @@ void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev)
 		ndev->rx_dent = debugfs_create_dir("rx", ndev->debugfs);
 }
 
-void mlx5_vdpa_remove_debugfs(struct dentry *dbg)
+void mlx5_vdpa_remove_debugfs(struct mlx5_vdpa_net *ndev)
 {
-	debugfs_remove_recursive(dbg);
+	debugfs_remove_recursive(ndev->debugfs);
+	ndev->debugfs = NULL;
 }
drivers/vdpa/mlx5/net/mlx5_vnet.c +2 -5
index 37be945a0230..f91c938b4be1 100644
@@ -2713,7 +2713,7 @@ static int setup_driver(struct mlx5_vdpa_dev *mvdev)
 err_rqt:
 	teardown_virtqueues(ndev);
 err_setup:
-	mlx5_vdpa_remove_debugfs(ndev->debugfs);
+	mlx5_vdpa_remove_debugfs(ndev);
 out:
 	return err;
 }
@@ -2727,8 +2727,7 @@ static void teardown_driver(struct mlx5_vdpa_net *ndev)
 	if (!ndev->setup)
 		return;
 
-	mlx5_vdpa_remove_debugfs(ndev->debugfs);
-	ndev->debugfs = NULL;
+	mlx5_vdpa_remove_debugfs(ndev);
 	teardown_steering(ndev);
 	destroy_tir(ndev);
 	destroy_rqt(ndev);
@@ -3489,8 +3488,6 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
 	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
 	struct workqueue_struct *wq;
 
-	mlx5_vdpa_remove_debugfs(ndev->debugfs);
-	ndev->debugfs = NULL;
 	unregister_link_notifier(ndev);
 	_vdpa_unregister_device(dev);
 	wq = mvdev->wq;
drivers/vdpa/mlx5/net/mlx5_vnet.h +1 -1
index 36c44d9fdd16..60cdbc903037 100644
@@ -88,7 +88,7 @@ struct macvlan_node {
 };
 
 void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev);
-void mlx5_vdpa_remove_debugfs(struct dentry *dbg);
+void mlx5_vdpa_remove_debugfs(struct mlx5_vdpa_net *ndev);
 void mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net *ndev);
 void mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net *ndev);
 void mlx5_vdpa_add_tirn(struct mlx5_vdpa_net *ndev);
Signature · 6 lines
2.41.0

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
author maintainer
#1 lore raw
Quoted 9 lines · Dragos Tatulea

The error path in setup_driver deletes the debugfs entry but doesn't clear the pointer. During .dev_del the invalid pointer will be released again causing a crash.

This patch fixes the issue by always clearing the debugfs entry in mlx5_vdpa_remove_debugfs. Also, stop removing the debugfs entry in .dev_del op: the debugfs entry is already handled within the setup_driver/teardown_driver scope.

Quoted 4 lines
Fixes f0417e72add5 ("vdpa/mlx5: Add and remove debugfs in setup/teardown

driver")

Gentle ping. Are there any comments on this patch?

Thanks,
Dragos

Quoted 66 lines

---
 drivers/vdpa/mlx5/net/debug.c     | 5 +++--
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 7 ++-----
 drivers/vdpa/mlx5/net/mlx5_vnet.h | 2 +-

 3 files changed, 6 insertions(+), 8 deletions(-)
drivers/vdpa/mlx5/net/debug.c +0 -0
index 60d6ac68cdc4..9c85162c19fc 100644
@@ -146,7 +146,8 @@ void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev)
                 ndev->rx_dent = debugfs_create_dir("rx", ndev->debugfs);
  }

drivers/vdpa/mlx5/net/debug.c +1 -1
-void mlx5_vdpa_remove_debugfs(struct dentry *dbg)
+void mlx5_vdpa_remove_debugfs(struct mlx5_vdpa_net *ndev)

 {
-       debugfs_remove_recursive(dbg);
+       debugfs_remove_recursive(ndev->debugfs);
+       ndev->debugfs = NULL;
 }

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index 37be945a0230..f91c938b4be1 100644
@@ -2713,7 +2713,7 @@ static int setup_driver(struct mlx5_vdpa_dev *mvdev)

 err_rqt:
        teardown_virtqueues(ndev);
 err_setup:
-       mlx5_vdpa_remove_debugfs(ndev->debugfs);
+       mlx5_vdpa_remove_debugfs(ndev);
 out:
        return err;
 }

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -2727,8 +2727,7 @@ static void teardown_driver(struct mlx5_vdpa_net *ndev)
         if (!ndev->setup)
                 return;


-       mlx5_vdpa_remove_debugfs(ndev->debugfs);
-       ndev->debugfs = NULL;
+       mlx5_vdpa_remove_debugfs(ndev);
        teardown_steering(ndev);
        destroy_tir(ndev);
        destroy_rqt(ndev);

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -3489,8 +3488,6 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev
 *v_mdev, struct vdpa_device *
         struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
         struct workqueue_struct *wq;


-       mlx5_vdpa_remove_debugfs(ndev->debugfs);
-       ndev->debugfs = NULL;
        unregister_link_notifier(ndev);
        _vdpa_unregister_device(dev);
        wq = mvdev->wq;

drivers/vdpa/mlx5/net/mlx5_vnet.h +0 -0
index 36c44d9fdd16..60cdbc903037 100644
@@ -88,7 +88,7 @@ struct macvlan_node {
  };


 void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev);

drivers/vdpa/mlx5/net/mlx5_vnet.h +1 -1
-void mlx5_vdpa_remove_debugfs(struct dentry *dbg);
+void mlx5_vdpa_remove_debugfs(struct mlx5_vdpa_net *ndev);
Quoted 3 lines

 void mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net *ndev); void mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net *ndev); void mlx5_vdpa_add_tirn(struct mlx5_vdpa_net *ndev);

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Acked-by on v1 1/1
#2 lore raw
In reply to Dragos Tatulea
Quoted 5 lines · Dragos Tatulea

The error path in setup_driver deletes the debugfs entry but doesn't clear the pointer. During .dev_del the invalid pointer will be released again causing a crash.

Quoted 8 lines

This patch fixes the issue by always clearing the debugfs entry in mlx5_vdpa_remove_debugfs. Also, stop removing the debugfs entry in .dev_del op: the debugfs entry is already handled within the setup_driver/teardown_driver scope.

Fixes f0417e72add5 ("vdpa/mlx5: Add and remove debugfs in setup/teardown driver")

Thanks

Quoted 67 lines
---
 drivers/vdpa/mlx5/net/debug.c     | 5 +++--
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 7 ++-----
 drivers/vdpa/mlx5/net/mlx5_vnet.h | 2 +-
 3 files changed, 6 insertions(+), 8 deletions(-)
drivers/vdpa/mlx5/net/debug.c +3 -2
index 60d6ac68cdc4..9c85162c19fc 100644
@@ -146,7 +146,8 @@ void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev)
                ndev->rx_dent = debugfs_create_dir("rx", ndev->debugfs);
 }
 
-void mlx5_vdpa_remove_debugfs(struct dentry *dbg)
+void mlx5_vdpa_remove_debugfs(struct mlx5_vdpa_net *ndev)
 {
-       debugfs_remove_recursive(dbg);
+       debugfs_remove_recursive(ndev->debugfs);
+       ndev->debugfs = NULL;
 }
drivers/vdpa/mlx5/net/mlx5_vnet.c +2 -5
index 37be945a0230..f91c938b4be1 100644
@@ -2713,7 +2713,7 @@ static int setup_driver(struct mlx5_vdpa_dev *mvdev)
 err_rqt:
        teardown_virtqueues(ndev);
 err_setup:
-       mlx5_vdpa_remove_debugfs(ndev->debugfs);
+       mlx5_vdpa_remove_debugfs(ndev);
 out:
        return err;
 }
@@ -2727,8 +2727,7 @@ static void teardown_driver(struct mlx5_vdpa_net *ndev)
        if (!ndev->setup)
                return;
 
-       mlx5_vdpa_remove_debugfs(ndev->debugfs);
-       ndev->debugfs = NULL;
+       mlx5_vdpa_remove_debugfs(ndev);
        teardown_steering(ndev);
        destroy_tir(ndev);
        destroy_rqt(ndev);
@@ -3489,8 +3488,6 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
        struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
        struct workqueue_struct *wq;
 
-       mlx5_vdpa_remove_debugfs(ndev->debugfs);
-       ndev->debugfs = NULL;
        unregister_link_notifier(ndev);
        _vdpa_unregister_device(dev);
        wq = mvdev->wq;
drivers/vdpa/mlx5/net/mlx5_vnet.h +1 -2
index 36c44d9fdd16..60cdbc903037 100644
@@ -88,7 +88,7 @@ struct macvlan_node {
 };
 
 void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev);
-void mlx5_vdpa_remove_debugfs(struct dentry *dbg);
+void mlx5_vdpa_remove_debugfs(struct mlx5_vdpa_net *ndev);
 void mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net *ndev);
 void mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net *ndev);
 void mlx5_vdpa_add_tirn(struct mlx5_vdpa_net *ndev);
--
Quoted 2 lines

2.41.0

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization