* [PATCH] VFIO: PCI: eliminate unnecessary overhead in vfio_pci_reflck_find
@ 2019-10-30 10:57 linmiaohe
2019-11-05 19:24 ` Alex Williamson
0 siblings, 1 reply; 3+ messages in thread
From: linmiaohe @ 2019-10-30 10:57 UTC (permalink / raw)
To: alex.williamson, cohuck, eric.auger, aik, mpe, bhelgaas, tglx, hexin.op
Cc: linmiaohe, kvm, linux-kernel
From: Miaohe Lin <linmiaohe@huawei.com>
The driver of the pci device may not equal to vfio_pci_driver,
but we fetch vfio_device from pci_dev unconditionally in func
vfio_pci_reflck_find. This overhead, such as the competition
of vfio.group_lock, can be eliminated by check pci_dev_driver
with vfio_pci_driver first.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
drivers/vfio/pci/vfio_pci.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index 379a02c36e37..1e21970543a6 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -1466,15 +1466,14 @@ static int vfio_pci_reflck_find(struct pci_dev *pdev, void *data)
struct vfio_device *device;
struct vfio_pci_device *vdev;
- device = vfio_device_get_from_dev(&pdev->dev);
- if (!device)
- return 0;
-
if (pci_dev_driver(pdev) != &vfio_pci_driver) {
- vfio_device_put(device);
return 0;
}
+ device = vfio_device_get_from_dev(&pdev->dev);
+ if (!device)
+ return 0;
+
vdev = vfio_device_data(device);
if (vdev->reflck) {
--
2.19.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] VFIO: PCI: eliminate unnecessary overhead in vfio_pci_reflck_find
2019-10-30 10:57 [PATCH] VFIO: PCI: eliminate unnecessary overhead in vfio_pci_reflck_find linmiaohe
@ 2019-11-05 19:24 ` Alex Williamson
0 siblings, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2019-11-05 19:24 UTC (permalink / raw)
To: linmiaohe
Cc: cohuck, eric.auger, aik, mpe, bhelgaas, tglx, hexin.op, kvm,
linux-kernel
On Wed, 30 Oct 2019 18:57:10 +0800
linmiaohe <linmiaohe@huawei.com> wrote:
> From: Miaohe Lin <linmiaohe@huawei.com>
>
> The driver of the pci device may not equal to vfio_pci_driver,
> but we fetch vfio_device from pci_dev unconditionally in func
> vfio_pci_reflck_find. This overhead, such as the competition
> of vfio.group_lock, can be eliminated by check pci_dev_driver
> with vfio_pci_driver first.
>
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
> drivers/vfio/pci/vfio_pci.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> index 379a02c36e37..1e21970543a6 100644
> --- a/drivers/vfio/pci/vfio_pci.c
> +++ b/drivers/vfio/pci/vfio_pci.c
> @@ -1466,15 +1466,14 @@ static int vfio_pci_reflck_find(struct pci_dev *pdev, void *data)
> struct vfio_device *device;
> struct vfio_pci_device *vdev;
>
> - device = vfio_device_get_from_dev(&pdev->dev);
> - if (!device)
> - return 0;
> -
> if (pci_dev_driver(pdev) != &vfio_pci_driver) {
> - vfio_device_put(device);
> return 0;
> }
>
> + device = vfio_device_get_from_dev(&pdev->dev);
> + if (!device)
> + return 0;
> +
> vdev = vfio_device_data(device);
>
> if (vdev->reflck) {
I believe this introduces a race. When we hold a reference to the vfio
device, an unbind from a vfio bus driver will be blocked in
vfio_del_group_dev(). Therefore if we test the driver is vfio-pci
while holding this reference, we know that it cannot be released and
the device_data is a valid vfio_pci_device. Testing the driver prior
to acquiring a vfio device reference is meaningless as we have no
guarantee that the driver has not changed by the time we acquire a
reference. Are you actually seeing contention here or was this a code
inspection optimization? Thanks,
Alex
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] VFIO: PCI: eliminate unnecessary overhead in vfio_pci_reflck_find
@ 2019-11-06 2:02 linmiaohe
0 siblings, 0 replies; 3+ messages in thread
From: linmiaohe @ 2019-11-06 2:02 UTC (permalink / raw)
To: Alex Williamson
Cc: cohuck, eric.auger, aik, mpe, bhelgaas, tglx, hexin.op, kvm,
linux-kernel
On Wed, 6 Nov 2019 03:25
Alex Williamson wrote
>> From: Miaohe Lin <linmiaohe@huawei.com>
>>
>> The driver of the pci device may not equal to vfio_pci_driver, but we
>> fetch vfio_device from pci_dev unconditionally in func
>> vfio_pci_reflck_find. This overhead, such as the competition of
>> vfio.group_lock, can be eliminated by check pci_dev_driver with
>> vfio_pci_driver first.
>>
>
>I believe this introduces a race. When we hold a reference to the vfio device, an unbind from a vfio bus driver will be blocked in vfio_del_group_dev(). Therefore if we test the driver is vfio-pci while holding this reference, we know that it cannot be released and the device_data is a valid vfio_pci_device. Testing the driver prior to acquiring a vfio device reference is meaningless as we have no guarantee that the driver has not changed by the time we acquire a reference. Are you actually seeing contention here or was this a code inspection optimization? Thanks,
>
>Alex
Thanks for your reply and patient explanation. It was a code inspection optimization, and obviously, I missed something. I'm really sorry about that.
Best wishes.
Have a nice day.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-11-06 2:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-30 10:57 [PATCH] VFIO: PCI: eliminate unnecessary overhead in vfio_pci_reflck_find linmiaohe
2019-11-05 19:24 ` Alex Williamson
2019-11-06 2:02 linmiaohe
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).