From: "Cédric Le Goater" <clg@redhat.com>
To: Joao Martins <joao.m.martins@oracle.com>,
Zhenzhong Duan <zhenzhong.duan@intel.com>,
qemu-devel@nongnu.org
Cc: alex.williamson@redhat.com, avihaih@nvidia.com, chao.p.peng@intel.com
Subject: Re: [PATCH v4 4/5] vfio/pci: Free resources when vfio_migration_realize fails
Date: Thu, 29 Jun 2023 17:23:44 +0200 [thread overview]
Message-ID: <553e8105-2b44-e16b-8630-26678dddecd8@redhat.com> (raw)
In-Reply-To: <346b1c73-0efb-e339-dbbf-c4ae41e85861@oracle.com>
On 6/29/23 13:45, Joao Martins wrote:
> On 29/06/2023 09:40, Zhenzhong Duan wrote:
>> When vfio_realize() succeeds, hot unplug will call vfio_exitfn()
>> to free resources allocated in vfio_realize(); when vfio_realize()
>> fails, vfio_exitfn() is never called and we need to free resources
>> in vfio_realize().
>>
>> In the case that vfio_migration_realize() fails,
>> e.g: with -only-migratable & enable-migration=off, we see below:
>>
>> (qemu) device_add vfio-pci,host=81:11.1,id=vfio1,bus=root1,enable-migration=off
>> 0000:81:11.1: Migration disabled
>> Error: disallowing migration blocker (--only-migratable) for: 0000:81:11.1: Migration is disabled for VFIO device
>>
>> If we hotplug again we should see same log as above, but we see:
>> (qemu) device_add vfio-pci,host=81:11.1,id=vfio1,bus=root1,enable-migration=off
>> Error: vfio 0000:81:11.1: device is already attached
>>
>> That's because some references to VFIO device isn't released,
>> we should check return value of vfio_migration_realize() and
>> release the references, then VFIO device will be truely
>> released when hotplug fails.
>>
>> Fixes: a22651053b59 ("vfio: Make vfio-pci device migration capable")
>> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>> ---
>> hw/vfio/pci.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
>> index 54a8179d1c64..dc69d3031b24 100644
>> --- a/hw/vfio/pci.c
>> +++ b/hw/vfio/pci.c
>> @@ -3210,6 +3210,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
>> ret = vfio_migration_realize(vbasedev, errp);
>> if (ret) {
>> error_report("%s: Migration disabled", vbasedev->name);
>> + goto out_vfio_migration;
>> }
>> }
>>
>> @@ -3219,6 +3220,8 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
>>
>> return;
>>
>> +out_vfio_migration:
>> + vfio_migration_exit(vbasedev);
>> out_deregister:
>> vfio_disable_interrupts(vdev);
>> out_intx_disable:
>
> I agree with the general sentiment behind the change.
> Clearly vfio::migration and vfio::migration_blocker are leaking from inside the
> migration_realize() function.
>
> But it is kinda awkward semantic that vfio_migration_realize() (or any realize)
> failures need to be accompanied with a vfio_migration_exit() that tears down
> state *leaked* by its realize() failure.
>
> It sounds to me that this should be inside the vfio_migration_realize() not on
> the caller? Unless QEMU ::realize() is expected to do this.
>
I agree. vfio_migration_realize() should handle the cleanup of the resources
it allocated if there is a failure.
Thanks
C.
next prev parent reply other threads:[~2023-06-29 15:24 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-29 8:40 [PATCH v4 0/5] VFIO migration related refactor and bug fix Zhenzhong Duan
2023-06-29 8:40 ` [PATCH v4 1/5] vfio/pci: Fix a segfault in vfio_realize Zhenzhong Duan
2023-06-29 10:57 ` Joao Martins
2023-06-29 13:06 ` Cédric Le Goater
2023-06-29 8:40 ` [PATCH v4 2/5] vfio/pci: Free leaked timer in vfio_realize error path Zhenzhong Duan
2023-06-29 10:59 ` Joao Martins
2023-06-29 13:09 ` Cédric Le Goater
2023-06-29 8:40 ` [PATCH v4 3/5] vfio/pci: Disable INTx " Zhenzhong Duan
2023-06-29 11:24 ` Joao Martins
2023-06-29 15:13 ` Cédric Le Goater
2023-06-29 15:33 ` Joao Martins
2023-06-30 1:19 ` Duan, Zhenzhong
2023-06-29 8:40 ` [PATCH v4 4/5] vfio/pci: Free resources when vfio_migration_realize fails Zhenzhong Duan
2023-06-29 11:45 ` Joao Martins
2023-06-29 15:23 ` Cédric Le Goater [this message]
2023-06-30 1:23 ` Duan, Zhenzhong
2023-06-29 8:40 ` [PATCH v4 5/5] vfio/migration: Refactor and fix print of "Migration disabled" Zhenzhong Duan
2023-06-29 12:44 ` Joao Martins
2023-06-29 15:20 ` Avihai Horon
2023-06-29 15:42 ` Joao Martins
2023-06-29 22:12 ` Alex Williamson
2023-06-30 1:38 ` Duan, Zhenzhong
2023-06-29 16:40 ` Cédric Le Goater
2023-06-30 1:40 ` Duan, Zhenzhong
2023-06-30 6:01 ` [PATCH v4 0/5] VFIO migration related refactor and bug fix Cédric Le Goater
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=553e8105-2b44-e16b-8630-26678dddecd8@redhat.com \
--to=clg@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=avihaih@nvidia.com \
--cc=chao.p.peng@intel.com \
--cc=joao.m.martins@oracle.com \
--cc=qemu-devel@nongnu.org \
--cc=zhenzhong.duan@intel.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.