Re: [PATCH] PCI: handle pci_sriov_set_totalvfs(dev, 0)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01/08/14 04:18, Ethan Zhao wrote:
> On Thu, Jul 31, 2014 at 11:56 PM, Edward Cree <ecree@xxxxxxxxxxxxxx> wrote:
>> Clearing dev->is_physfn in the driver probe routine isn't safe:
>> dev->sriov memory can get leaked, for example, as sriov_init will get
>> called at device add, but sriov_release won't be called at removal.
>>
>   I think this memory leak bug doesn't exist.
>
>   The dev->sriov memory was allocated when pci_device_add() called.
> whenever devices
>   were hot-pluged into system or built-in devices were scanned while booting.
>
>   The memory of dev->sriov is to be freed by kobject->kobject_release() when
> the device reference counter reaches zero when put_device() was called.
> for hot-plug, that is pciehp_unconfigure_device()....etc.  but not in
> driver->remove().
>
Yes, but the problem is in pci_iov_release(), not how it gets called;
its code is
    if (dev->is_physfn)
        sriov_release(dev);
So if the device driver clears dev->is_physfn, and later on the device
is hot-unplugged, pci_iov_release() won't call sriov_release().
Thus any device driver that changes dev->is_physfn will, if the device
is hot-unplugged, leak dev->sriov.
Fortunately a quick grep shows no drivers doing this, so there's no
actual bug in existing code.  It's just that we can't use this approach
to disable SR-IOV from the driver's probe routine.
-Edward
>      put_device()
>         kobject_put()
>            kobject_release()
>                kobject_cleanup()
>                    device_release()
>                        dev->release(dev)
>                              pci_release_dev()
>                                   pci_release_capabilities()
>                                      pci_iov_release()
>                                          sriov_release(dev);
>                                                kfree(dev->sriov);
The information contained in this message is confidential and is intended for the addressee(s) only. If you have received this message in error, please notify the sender immediately and delete the message. Unless you are an addressee (or authorized to receive for an addressee), you may not use, copy or disclose to anyone this message or any information contained in this message. The unauthorized use, disclosure, copying or alteration of this message is strictly prohibited.
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux