qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Akihiko Odaki <akihiko.odaki@daynix.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Cédric Le Goater" <clg@kaod.org>
Subject: Re: [PATCH] pcie: Release references of virtual functions
Date: Tue, 11 Apr 2023 20:05:28 +0900	[thread overview]
Message-ID: <3f1c3aeb-22fb-1349-08a6-a6fa55019e37@daynix.com> (raw)
In-Reply-To: <44853d32-38cc-eec0-c96f-31c898104e7d@linaro.org>

On 2023/04/11 19:11, Philippe Mathieu-Daudé wrote:
> On 11/4/23 11:04, Akihiko Odaki wrote:
>> pci_new() automatically retains a reference to a virtual function when
>> registering it so we need to release the reference when unregistering.
>>
>> Fixes: 7c0fa8dff8 ("pcie: Add support for Single Root I/O 
>> Virtualization (SR/IOV)")
>> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
>> ---
>>   hw/pci/pcie_sriov.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c
>> index aa5a757b11..76a3b6917e 100644
>> --- a/hw/pci/pcie_sriov.c
>> +++ b/hw/pci/pcie_sriov.c
>> @@ -211,6 +211,7 @@ static void unregister_vfs(PCIDevice *dev)
>>               error_free(local_err);
>>           }
>>           object_unparent(OBJECT(vf));
>> +        object_unref(OBJECT(vf));
>>       }
>>       g_free(dev->exp.sriov_pf.vf);
>>       dev->exp.sriov_pf.vf = NULL;
> 
> It feels the issue is at the device creation.

I added object_unref() to unregister_vfs() because dev->exp.sriov_pf.vf 
actually holds the reference. Practically there should be no difference 
as the parent bus also keeps the reference until unregister_vfs() calls 
object_unparent(), but I think it is semantically more correct to 
object_unref() in unregister_vfs().

> 
> [/me looking at the code]
> 
> What about:
> 
> -- >8 --
> diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c
> index aa5a757b11..fca3bf6e72 100644
> --- a/hw/pci/pcie_sriov.c
> +++ b/hw/pci/pcie_sriov.c
> @@ -150,7 +150,7 @@ static PCIDevice *register_vf(PCIDevice *pf, int 
> devfn, const char *name,
>       PCIBus *bus = pci_get_bus(pf);
>       Error *local_err = NULL;
> 
> -    qdev_realize(&dev->qdev, &bus->qbus, &local_err);
> +    pci_realize_and_unref(dev, bus, &local_err);
>       if (local_err) {
>           error_report_err(local_err);
>           return NULL;
> ---


  reply	other threads:[~2023-04-11 11:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-11  9:04 [PATCH] pcie: Release references of virtual functions Akihiko Odaki
2023-04-11  9:07 ` Cédric Le Goater
2023-04-11 10:11 ` Philippe Mathieu-Daudé
2023-04-11 11:05   ` Akihiko Odaki [this message]
2023-04-21  8:09   ` Michael S. Tsirkin
2023-07-01  6:19     ` Akihiko Odaki
2023-07-02 11:21       ` Philippe Mathieu-Daudé

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=3f1c3aeb-22fb-1349-08a6-a6fa55019e37@daynix.com \
    --to=akihiko.odaki@daynix.com \
    --cc=clg@kaod.org \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).