vdpa/mlx5: Fix double release of debugfs entry
authorDragos Tatulea <dtatulea@nvidia.com>
Tue, 29 Aug 2023 17:40:09 +0000 (20:40 +0300)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 18 Oct 2023 15:29:29 +0000 (11:29 -0400)
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.

Cc: stable@vger.kernel.org
Fixes: f0417e72add5 ("vdpa/mlx5: Add and remove debugfs in setup/teardown driver")
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Gal Pressman <gal@nvidia.com>
Message-Id: <20230829174014.928189-2-dtatulea@nvidia.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
drivers/vdpa/mlx5/net/debug.c
drivers/vdpa/mlx5/net/mlx5_vnet.c
drivers/vdpa/mlx5/net/mlx5_vnet.h

index 60d6ac6..9c85162 100644 (file)
@@ -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;
 }
index 40a03b0..2b7b900 100644 (file)
@@ -2713,7 +2713,7 @@ err_tir:
 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;
index 36c44d9..60cdbc9 100644 (file)
@@ -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);