]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net/mlx5: SD, Keep multi-pf debugfs entries on primary
authorShay Drory <shayd@nvidia.com>
Mon, 4 May 2026 18:02:04 +0000 (21:02 +0300)
committerJakub Kicinski <kuba@kernel.org>
Wed, 6 May 2026 02:13:09 +0000 (19:13 -0700)
mlx5_sd_init() creates the "multi-pf" debugfs directory under the
primary device debugfs root, but stored the dentry in the calling
device's sd struct. When sd_cleanup() run on a different PF,
this leads to using the wrong sd->dfs for removing entries, which
results in memory leak and an error in when re-creating the SD.[1]

Fix it by explicitly storing the debugfs dentry in the primary
device sd struct and use it for all per-group files.

[1]
debugfs: 'multi-pf' already exists in '0000:08:00.1'

Fixes: 4375130bf527 ("net/mlx5: SD, Add debugfs")
Signed-off-by: Shay Drory <shayd@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260504180206.268568-3-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c

index ec42685bdece6dbb4e4f78c8851888a065deebd8..89b7e4d67303c041019cfc1fbd884b19ade776ba 100644 (file)
@@ -463,9 +463,13 @@ int mlx5_sd_init(struct mlx5_core_dev *dev)
        if (err)
                goto err_sd_unregister;
 
-       sd->dfs = debugfs_create_dir("multi-pf", mlx5_debugfs_get_dev_root(primary));
-       debugfs_create_x32("group_id", 0400, sd->dfs, &sd->group_id);
-       debugfs_create_file("primary", 0400, sd->dfs, primary, &dev_fops);
+       primary_sd->dfs =
+               debugfs_create_dir("multi-pf",
+                                  mlx5_debugfs_get_dev_root(primary));
+       debugfs_create_x32("group_id", 0400, primary_sd->dfs,
+                          &primary_sd->group_id);
+       debugfs_create_file("primary", 0400, primary_sd->dfs, primary,
+                           &dev_fops);
 
        mlx5_sd_for_each_secondary(i, primary, pos) {
                char name[32];
@@ -475,7 +479,8 @@ int mlx5_sd_init(struct mlx5_core_dev *dev)
                        goto err_unset_secondaries;
 
                snprintf(name, sizeof(name), "secondary_%d", i - 1);
-               debugfs_create_file(name, 0400, sd->dfs, pos, &dev_fops);
+               debugfs_create_file(name, 0400, primary_sd->dfs, pos,
+                                   &dev_fops);
 
        }
 
@@ -493,7 +498,8 @@ err_unset_secondaries:
        mlx5_sd_for_each_secondary_to(i, primary, to, pos)
                sd_cmd_unset_secondary(pos);
        sd_cmd_unset_primary(primary);
-       debugfs_remove_recursive(sd->dfs);
+       debugfs_remove_recursive(primary_sd->dfs);
+       primary_sd->dfs = NULL;
 err_sd_unregister:
        mlx5_sd_for_each_secondary(i, primary, pos) {
                struct mlx5_sd *peer_sd = mlx5_get_sd(pos);
@@ -535,7 +541,8 @@ void mlx5_sd_cleanup(struct mlx5_core_dev *dev)
        mlx5_sd_for_each_secondary(i, primary, pos)
                sd_cmd_unset_secondary(pos);
        sd_cmd_unset_primary(primary);
-       debugfs_remove_recursive(sd->dfs);
+       debugfs_remove_recursive(primary_sd->dfs);
+       primary_sd->dfs = NULL;
 
        sd_info(primary, "group id %#x, uncombined\n", sd->group_id);
        primary_sd->state = MLX5_SD_STATE_DOWN;