Skip to content

Commit cc51a66

Browse files
dtatuleamstsirkin
authored andcommitted
vdpa/mlx5: Fix release of uninitialized resources on error path
The commit in the fixes tag made sure that mlx5_vdpa_free() is the single entrypoint for removing the vdpa device resources added in mlx5_vdpa_dev_add(), even in the cleanup path of mlx5_vdpa_dev_add(). This means that all functions from mlx5_vdpa_free() should be able to handle uninitialized resources. This was not the case though: mlx5_vdpa_destroy_mr_resources() and mlx5_cmd_cleanup_async_ctx() were not able to do so. This caused the splat below when adding a vdpa device without a MAC address. This patch fixes these remaining issues: - Makes mlx5_vdpa_destroy_mr_resources() return early if called on uninitialized resources. - Moves mlx5_cmd_init_async_ctx() early on during device addition because it can't fail. This means that mlx5_cmd_cleanup_async_ctx() also can't fail. To mirror this, move the call site of mlx5_cmd_cleanup_async_ctx() in mlx5_vdpa_free(). An additional comment was added in mlx5_vdpa_free() to document the expectations of functions called from this context. Splat: mlx5_core 0000:b5:03.2: mlx5_vdpa_dev_add:3950:(pid 2306) warning: No mac address provisioned? ------------[ cut here ]------------ WARNING: CPU: 13 PID: 2306 at kernel/workqueue.c:4207 __flush_work+0x9a/0xb0 [...] Call Trace: <TASK> ? __try_to_del_timer_sync+0x61/0x90 ? __timer_delete_sync+0x2b/0x40 mlx5_vdpa_destroy_mr_resources+0x1c/0x40 [mlx5_vdpa] mlx5_vdpa_free+0x45/0x160 [mlx5_vdpa] vdpa_release_dev+0x1e/0x50 [vdpa] device_release+0x31/0x90 kobject_cleanup+0x37/0x130 mlx5_vdpa_dev_add+0x327/0x890 [mlx5_vdpa] vdpa_nl_cmd_dev_add_set_doit+0x2c1/0x4d0 [vdpa] genl_family_rcv_msg_doit+0xd8/0x130 genl_family_rcv_msg+0x14b/0x220 ? __pfx_vdpa_nl_cmd_dev_add_set_doit+0x10/0x10 [vdpa] genl_rcv_msg+0x47/0xa0 ? __pfx_genl_rcv_msg+0x10/0x10 netlink_rcv_skb+0x53/0x100 genl_rcv+0x24/0x40 netlink_unicast+0x27b/0x3b0 netlink_sendmsg+0x1f7/0x430 __sys_sendto+0x1fa/0x210 ? ___pte_offset_map+0x17/0x160 ? next_uptodate_folio+0x85/0x2b0 ? percpu_counter_add_batch+0x51/0x90 ? filemap_map_pages+0x515/0x660 __x64_sys_sendto+0x20/0x30 do_syscall_64+0x7b/0x2c0 ? do_read_fault+0x108/0x220 ? do_pte_missing+0x14a/0x3e0 ? __handle_mm_fault+0x321/0x730 ? count_memcg_events+0x13f/0x180 ? handle_mm_fault+0x1fb/0x2d0 ? do_user_addr_fault+0x20c/0x700 ? syscall_exit_work+0x104/0x140 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x7f0c25b0feca [...] ---[ end trace 0000000000000000 ]--- Signed-off-by: Dragos Tatulea <[email protected]> Fixes: 83e445e ("vdpa/mlx5: Fix error path during device add") Reported-by: Wenli Quan <[email protected]> Closes: https://lore.kernel.org/virtualization/CADZSLS0r78HhZAStBaN1evCSoPqRJU95Lt8AqZNJ6+wwYQ6vPQ@mail.gmail.com/ Reviewed-by: Tariq Toukan <[email protected]> Reviewed-by: Cosmin Ratiu <[email protected]> Message-Id: <[email protected]> Tested-by: Wenli Quan <[email protected]> Acked-by: Jason Wang <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 400cad5 commit cc51a66

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

drivers/vdpa/mlx5/core/mr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,9 @@ void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev)
908908
{
909909
struct mlx5_vdpa_mr_resources *mres = &mvdev->mres;
910910

911+
if (!mres->wq_gc)
912+
return;
913+
911914
atomic_set(&mres->shutdown, 1);
912915

913916
flush_delayed_work(&mres->gc_dwork_ent);

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,15 +3432,17 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev)
34323432

34333433
ndev = to_mlx5_vdpa_ndev(mvdev);
34343434

3435+
/* Functions called here should be able to work with
3436+
* uninitialized resources.
3437+
*/
34353438
free_fixed_resources(ndev);
34363439
mlx5_vdpa_clean_mrs(mvdev);
34373440
mlx5_vdpa_destroy_mr_resources(&ndev->mvdev);
3438-
mlx5_cmd_cleanup_async_ctx(&mvdev->async_ctx);
3439-
34403441
if (!is_zero_ether_addr(ndev->config.mac)) {
34413442
pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
34423443
mlx5_mpfs_del_mac(pfmdev, ndev->config.mac);
34433444
}
3445+
mlx5_cmd_cleanup_async_ctx(&mvdev->async_ctx);
34443446
mlx5_vdpa_free_resources(&ndev->mvdev);
34453447
free_irqs(ndev);
34463448
kfree(ndev->event_cbs);
@@ -3888,6 +3890,8 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
38883890
mvdev->actual_features =
38893891
(device_features & BIT_ULL(VIRTIO_F_VERSION_1));
38903892

3893+
mlx5_cmd_init_async_ctx(mdev, &mvdev->async_ctx);
3894+
38913895
ndev->vqs = kcalloc(max_vqs, sizeof(*ndev->vqs), GFP_KERNEL);
38923896
ndev->event_cbs = kcalloc(max_vqs + 1, sizeof(*ndev->event_cbs), GFP_KERNEL);
38933897
if (!ndev->vqs || !ndev->event_cbs) {
@@ -3960,8 +3964,6 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
39603964
ndev->rqt_size = 1;
39613965
}
39623966

3963-
mlx5_cmd_init_async_ctx(mdev, &mvdev->async_ctx);
3964-
39653967
ndev->mvdev.mlx_features = device_features;
39663968
mvdev->vdev.dma_dev = &mdev->pdev->dev;
39673969
err = mlx5_vdpa_alloc_resources(&ndev->mvdev);

0 commit comments

Comments
 (0)