Skip to content

Commit 19bb3c6

Browse files
paravmellanoxgregkh
authored andcommitted
net/mlx5: Fix vhca_id access call trace use before alloc
[ Upstream commit a8f930b ] HCA CAP structure is allocated in mlx5_hca_caps_alloc(). mlx5_mdev_init() mlx5_hca_caps_alloc() And HCA CAP is read from the device in mlx5_init_one(). The vhca_id's debugfs file is published even before above two operations are done. Due to this when user reads the vhca id before the initialization, following call trace is observed. Fix this by deferring debugfs publication until the HCA CAP is allocated and read from the device. BUG: kernel NULL pointer dereference, address: 0000000000000004 PGD 0 P4D 0 Oops: Oops: 0000 [#1] SMP PTI CPU: 23 UID: 0 PID: 6605 Comm: cat Kdump: loaded Not tainted 6.18.0-rc7-sf+ #110 PREEMPT(full) Hardware name: Supermicro SYS-6028U-TR4+/X10DRU-i+, BIOS 2.0b 08/09/2016 RIP: 0010:vhca_id_show+0x17/0x30 [mlx5_core] Code: cb 66 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 0f 1f 44 00 00 48 8b 47 70 48 c7 c6 45 f0 12 c1 48 8b 80 70 03 00 00 <8b> 50 04 0f ca 0f b7 d2 e8 8c 82 47 cb 31 c0 c3 cc cc cc cc 0f 1f RSP: 0018:ffffd37f4f337d40 EFLAGS: 00010203 RAX: 0000000000000000 RBX: ffff8f18445c9b40 RCX: 0000000000000001 RDX: ffff8f1109825180 RSI: ffffffffc112f045 RDI: ffff8f18445c9b40 RBP: 0000000000000000 R08: 0000645eac0d2928 R09: 0000000000000006 R10: ffffd37f4f337d48 R11: 0000000000000000 R12: ffffd37f4f337dd8 R13: ffffd37f4f337db0 R14: ffff8f18445c9b68 R15: 0000000000000001 FS: 00007f3eea099580(0000) GS:ffff8f2090f1f000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000004 CR3: 00000008b64e4006 CR4: 00000000003726f0 Call Trace: <TASK> seq_read_iter+0x11f/0x4f0 ? _raw_spin_unlock+0x15/0x30 ? do_anonymous_page+0x104/0x810 seq_read+0xf6/0x120 ? srso_alias_untrain_ret+0x1/0x10 full_proxy_read+0x5c/0x90 vfs_read+0xad/0x320 ? handle_mm_fault+0x1ab/0x290 ksys_read+0x52/0xd0 do_syscall_64+0x61/0x11e0 entry_SYSCALL_64_after_hwframe+0x76/0x7e Fixes: dd3dd72 ("net/mlx5: Expose vhca_id to debugfs") Signed-off-by: Parav Pandit <parav@nvidia.com> Reviewed-by: Shay Drori <shayd@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Link: https://patch.msgid.link/1769503961-124173-4-git-send-email-tariqt@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent fc3da14 commit 19bb3c6

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

drivers/net/ethernet/mellanox/mlx5/core/debugfs.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,3 +613,19 @@ void mlx5_debug_cq_remove(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq)
613613
cq->dbg = NULL;
614614
}
615615
}
616+
617+
static int vhca_id_show(struct seq_file *file, void *priv)
618+
{
619+
struct mlx5_core_dev *dev = file->private;
620+
621+
seq_printf(file, "0x%x\n", MLX5_CAP_GEN(dev, vhca_id));
622+
return 0;
623+
}
624+
625+
DEFINE_SHOW_ATTRIBUTE(vhca_id);
626+
627+
void mlx5_vhca_debugfs_init(struct mlx5_core_dev *dev)
628+
{
629+
debugfs_create_file("vhca_id", 0400, dev->priv.dbg.dbg_root, dev,
630+
&vhca_id_fops);
631+
}

drivers/net/ethernet/mellanox/mlx5/core/main.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,16 +1803,6 @@ static int mlx5_hca_caps_alloc(struct mlx5_core_dev *dev)
18031803
return -ENOMEM;
18041804
}
18051805

1806-
static int vhca_id_show(struct seq_file *file, void *priv)
1807-
{
1808-
struct mlx5_core_dev *dev = file->private;
1809-
1810-
seq_printf(file, "0x%x\n", MLX5_CAP_GEN(dev, vhca_id));
1811-
return 0;
1812-
}
1813-
1814-
DEFINE_SHOW_ATTRIBUTE(vhca_id);
1815-
18161806
static int mlx5_notifiers_init(struct mlx5_core_dev *dev)
18171807
{
18181808
int err;
@@ -1855,7 +1845,7 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)
18551845
priv->numa_node = dev_to_node(mlx5_core_dma_dev(dev));
18561846
priv->dbg.dbg_root = debugfs_create_dir(dev_name(dev->device),
18571847
mlx5_debugfs_root);
1858-
debugfs_create_file("vhca_id", 0400, priv->dbg.dbg_root, dev, &vhca_id_fops);
1848+
18591849
INIT_LIST_HEAD(&priv->traps);
18601850

18611851
err = mlx5_cmd_init(dev);
@@ -1993,6 +1983,8 @@ static int probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
19931983
goto err_init_one;
19941984
}
19951985

1986+
mlx5_vhca_debugfs_init(dev);
1987+
19961988
pci_save_state(pdev);
19971989
return 0;
19981990

drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ int mlx5_wait_for_pages(struct mlx5_core_dev *dev, int *pages);
258258
void mlx5_cmd_flush(struct mlx5_core_dev *dev);
259259
void mlx5_cq_debugfs_init(struct mlx5_core_dev *dev);
260260
void mlx5_cq_debugfs_cleanup(struct mlx5_core_dev *dev);
261+
void mlx5_vhca_debugfs_init(struct mlx5_core_dev *dev);
261262

262263
int mlx5_query_pcam_reg(struct mlx5_core_dev *dev, u32 *pcam, u8 feature_group,
263264
u8 access_reg_group);

drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ static int mlx5_sf_dev_probe(struct auxiliary_device *adev, const struct auxilia
7676
goto init_one_err;
7777
}
7878

79+
mlx5_vhca_debugfs_init(mdev);
7980
return 0;
8081

8182
init_one_err:

0 commit comments

Comments
 (0)