All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Creeley, Brett" <bcreeley@amd.com>
To: Alex Williamson <alex@shazbot.org>,
	Zhu Jun <zhujun2@cmss.chinamobile.com>
Cc: brett.creeley@amd.com, jgg@ziepe.ca, yishaih@nvidia.com,
	skolothumtho@nvidia.com, kevin.tian@intel.com,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vfio/pds: Release migration files on allocation failure
Date: Tue, 1 Dec 2026 13:25:40 -0800	[thread overview]
Message-ID: <b0aedc0d-cc50-4b6f-b9f3-5e4b2f050cd2@amd.com> (raw)
In-Reply-To: <20261201141919.0ea34e1b@shazbot.org>



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@cmss.chinamobile.com> wrote:
>
>> 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);
>>
> I might opt to do the lm_file free+return in the anon_inode_getfile()
> 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 meant to get back to this, thanks for the reminder. I had some changes 
I was working on and our local Sashiko complained about this. Let me 
look what I ended up doing there and get back to you on this.

Thanks,

Brett

>
> Alex


  reply	other threads:[~2026-12-01 21:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-12-01 22:03   ` Creeley, Brett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b0aedc0d-cc50-4b6f-b9f3-5e4b2f050cd2@amd.com \
    --to=bcreeley@amd.com \
    --cc=alex@shazbot.org \
    --cc=brett.creeley@amd.com \
    --cc=jgg@ziepe.ca \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=skolothumtho@nvidia.com \
    --cc=yishaih@nvidia.com \
    --cc=zhujun2@cmss.chinamobile.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.