Re: [PATCH] vfio/pds: Release migration files on allocation failure
From: Creeley, Brett
Date: Tue Dec 01 2026 - 17:03:25 EST
On 12/1/2026 1:19 PM, Alex Williamson wrote:
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
On Thu, 12 Nov 2026 10:31:01 +0800
Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx> wrote:
pds_vfio_get_lm_file() takes an extra file reference before allocating itsI might opt to do the lm_file free+return in the anon_inode_getfile()
backing storage. If an allocation fails, the error path drops only one
reference and frees the private data, leaving the anonymous file leaked.
Take the extra reference only after all allocations succeed. On failure,
drop the initial reference and let the file's release callback destroy the
mutex and free the private data.
OpenAI Codex assisted with analysis and patch preparation.
Fixes: bb500dbe2ac6 ("vfio/pds: Add VFIO live migration support")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
drivers/vfio/pci/pds/lm.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/vfio/pci/pds/lm.c b/drivers/vfio/pci/pds/lm.c
index 08487eab11b0..d96ec77402c0 100644
--- a/drivers/vfio/pci/pds/lm.c
+++ b/drivers/vfio/pci/pds/lm.c
@@ -37,9 +37,6 @@ pds_vfio_get_lm_file(const struct file_operations *fops, int flags, u64 size)
stream_open(lm_file->filep->f_inode, lm_file->filep);
mutex_init(&lm_file->lock);
- /* prevent file from being released before we are done with it */
- get_file(lm_file->filep);
-
/* Allocate memory for file pages */
npages = DIV_ROUND_UP_ULL(size, PAGE_SIZE);
pages = kmalloc_objs(*pages, npages);
@@ -73,6 +70,9 @@ pds_vfio_get_lm_file(const struct file_operations *fops, int flags, u64 size)
lm_file->page_mem = page_mem;
lm_file->alloc_size = npages * PAGE_SIZE;
+ /* prevent file from being released before we are done with it */
+ get_file(lm_file->filep);
+
return lm_file;
out_free_page_mem:
@@ -81,7 +81,8 @@ pds_vfio_get_lm_file(const struct file_operations *fops, int flags, u64 size)
kfree(pages);
out_put_file:
fput(lm_file->filep);
- mutex_destroy(&lm_file->lock);
+ return NULL;
+
out_free_file:
kfree(lm_file);
error branch, rather than create this split unwind chain. There's a
natural inflection after that where we rely on the release callback for
the final cleanup anyway. The change itself looks correct as is to me
otherwise. Brett? Thanks,
I agree that you should do the restructure based on Alex's comment. Please submit a v2 based on his suggestion and I will be happy to add my Reviewed-by on that one.
Thanks for the fix,
Brett
Alex