Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH] vfio/pds: Release migration files on allocation failure
@ 2026-11-12  2:31 Zhu Jun
  2026-12-01 21:19 ` Alex Williamson
  0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-12  2:31 UTC (permalink / raw)
  To: brett.creeley
  Cc: jgg, yishaih, skolothumtho, kevin.tian, alex, kvm, linux-kernel,
	Zhu Jun

pds_vfio_get_lm_file() takes an extra file reference before allocating its
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@cmss.chinamobile.com>
---
 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);
 
-- 
2.51.0




^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-01 22:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12  2:31 [PATCH] vfio/pds: Release migration files on allocation failure Zhu Jun
2026-12-01 21:19 ` Alex Williamson
2026-12-01 21:25   ` Creeley, Brett
2026-12-01 22:03   ` Creeley, Brett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox