]> Git Repo - J-linux.git/commitdiff
vfio/mlx5: Fix an unwind issue in mlx5vf_add_migration_pages()
authorYishai Hadas <[email protected]>
Thu, 14 Nov 2024 09:53:17 +0000 (11:53 +0200)
committerAlex Williamson <[email protected]>
Thu, 14 Nov 2024 18:42:17 +0000 (11:42 -0700)
Fix an unwind issue in mlx5vf_add_migration_pages().

If a set of pages is allocated but fails to be added to the SG table,
they need to be freed to prevent a memory leak.

Any pages successfully added to the SG table will be freed as part of
mlx5vf_free_data_buffer().

Fixes: 6fadb021266d ("vfio/mlx5: Implement vfio_pci driver for mlx5 devices")
Signed-off-by: Yishai Hadas <[email protected]>
Reviewed-by: Jason Gunthorpe <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alex Williamson <[email protected]>
drivers/vfio/pci/mlx5/cmd.c

index 41a4b0cf429756b6e72f476ba794ad6b3baaf65e..7527e277c89897430dc0a2fb1353f7c356447105 100644 (file)
@@ -423,6 +423,7 @@ static int mlx5vf_add_migration_pages(struct mlx5_vhca_data_buffer *buf,
        unsigned long filled;
        unsigned int to_fill;
        int ret;
+       int i;
 
        to_fill = min_t(unsigned int, npages, PAGE_SIZE / sizeof(*page_list));
        page_list = kvzalloc(to_fill * sizeof(*page_list), GFP_KERNEL_ACCOUNT);
@@ -443,7 +444,7 @@ static int mlx5vf_add_migration_pages(struct mlx5_vhca_data_buffer *buf,
                        GFP_KERNEL_ACCOUNT);
 
                if (ret)
-                       goto err;
+                       goto err_append;
                buf->allocated_length += filled * PAGE_SIZE;
                /* clean input for another bulk allocation */
                memset(page_list, 0, filled * sizeof(*page_list));
@@ -454,6 +455,9 @@ static int mlx5vf_add_migration_pages(struct mlx5_vhca_data_buffer *buf,
        kvfree(page_list);
        return 0;
 
+err_append:
+       for (i = filled - 1; i >= 0; i--)
+               __free_page(page_list[i]);
 err:
        kvfree(page_list);
        return ret;
This page took 0.057166 seconds and 4 git commands to generate.