* [PATCH] PCI: hv: fix wslot_to_devfn()
@ 2017-02-07 9:00 Dexuan Cui
2017-02-07 16:17 ` Haiyang Zhang
2017-02-10 21:19 ` Bjorn Helgaas
0 siblings, 2 replies; 3+ messages in thread
From: Dexuan Cui @ 2017-02-07 9:00 UTC (permalink / raw)
To: Bjorn Helgaas, linux-pci, devel, Jake Oshins
Cc: KY Srinivasan, Stephen Hemminger, Haiyang Zhang, olaf, gregkh,
linux-kernel, apw, jasowang, Vitaly Kuznetsov
The devfn of 00:02.0 is 0x10.
devfn_to_wslot(0x10) =3D=3D 0x2, and wslot_to_devfn(0x2) should be 0x10,
while it's 0x2 in the current code.
Due to this, hv_eject_device_work() -> pci_get_domain_bus_and_slot()
returns NULL and pci_stop_and_remove_bus_device() is not called.
Later when the real device driver's .remove() is invoked by
hv_pci_remove() -> pci_stop_root_bus(), some warnings can be noticed
because the VM has lost the access to the underlying device at that
time.
Signed-off-by: Jake Oshins <jakeo@microsoft.com>
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Cc: stable@vger.kernel.org
Cc: K. Y. Srinivasan <kys@microsoft.com>
CC: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
---
drivers/pci/host/pci-hyperv.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
The patch is co-made by Jake and me.
diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
index 3efcc7b..cd114c6 100644
--- a/drivers/pci/host/pci-hyperv.c
+++ b/drivers/pci/host/pci-hyperv.c
@@ -130,7 +130,8 @@ enum pci_message_type {
*/
union win_slot_encoding {
struct {
- u32 func:8;
+ u32 dev:5;
+ u32 func:3;
u32 reserved:24;
} bits;
u32 slot;
@@ -485,7 +486,8 @@ static u32 devfn_to_wslot(int devfn)
union win_slot_encoding wslot;
=20
wslot.slot =3D 0;
- wslot.bits.func =3D PCI_SLOT(devfn) | (PCI_FUNC(devfn) << 5);
+ wslot.bits.dev =3D PCI_SLOT(devfn);
+ wslot.bits.func =3D PCI_FUNC(devfn);
=20
return wslot.slot;
}
@@ -503,7 +505,7 @@ static int wslot_to_devfn(u32 wslot)
union win_slot_encoding slot_no;
=20
slot_no.slot =3D wslot;
- return PCI_DEVFN(0, slot_no.bits.func);
+ return PCI_DEVFN(slot_no.bits.dev, slot_no.bits.func);
}
=20
/*
--=20
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH] PCI: hv: fix wslot_to_devfn()
2017-02-07 9:00 [PATCH] PCI: hv: fix wslot_to_devfn() Dexuan Cui
@ 2017-02-07 16:17 ` Haiyang Zhang
2017-02-10 21:19 ` Bjorn Helgaas
1 sibling, 0 replies; 3+ messages in thread
From: Haiyang Zhang @ 2017-02-07 16:17 UTC (permalink / raw)
To: Dexuan Cui, Bjorn Helgaas, linux-pci, devel, Jake Oshins
Cc: KY Srinivasan, Stephen Hemminger, olaf, gregkh, linux-kernel,
apw, jasowang, Vitaly Kuznetsov
> -----Original Message-----
> From: Dexuan Cui
> Sent: Tuesday, February 7, 2017 4:00 AM
> To: Bjorn Helgaas <bhelgaas@google.com>; linux-pci@vger.kernel.org;
> devel@linuxdriverproject.org; Jake Oshins <jakeo@microsoft.com>
> Cc: KY Srinivasan <kys@microsoft.com>; Stephen Hemminger
> <sthemmin@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>;
> olaf@aepfle.de; gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org;
> apw@canonical.com; jasowang@redhat.com; Vitaly Kuznetsov
> <vkuznets@redhat.com>
> Subject: [PATCH] PCI: hv: fix wslot_to_devfn()
>=20
> The devfn of 00:02.0 is 0x10.
> devfn_to_wslot(0x10) =3D=3D 0x2, and wslot_to_devfn(0x2) should be 0x10,
> while it's 0x2 in the current code.
>=20
> Due to this, hv_eject_device_work() -> pci_get_domain_bus_and_slot()
> returns NULL and pci_stop_and_remove_bus_device() is not called.
>=20
> Later when the real device driver's .remove() is invoked by
> hv_pci_remove() -> pci_stop_root_bus(), some warnings can be noticed
> because the VM has lost the access to the underlying device at that time.
>=20
> Signed-off-by: Jake Oshins <jakeo@microsoft.com>
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> Cc: stable@vger.kernel.org
> Cc: K. Y. Srinivasan <kys@microsoft.com>
> CC: Haiyang Zhang <haiyangz@microsoft.com>
> Cc: Stephen Hemminger <sthemmin@microsoft.com>
> ---
> drivers/pci/host/pci-hyperv.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>=20
> The patch is co-made by Jake and me.
I think this line should be put together with other comments.
Thanks.
Acked-by: Haiyang Zhang <haiyangz@microsoft.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PCI: hv: fix wslot_to_devfn()
2017-02-07 9:00 [PATCH] PCI: hv: fix wslot_to_devfn() Dexuan Cui
2017-02-07 16:17 ` Haiyang Zhang
@ 2017-02-10 21:19 ` Bjorn Helgaas
1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2017-02-10 21:19 UTC (permalink / raw)
To: Dexuan Cui
Cc: Bjorn Helgaas, linux-pci, devel, Jake Oshins, KY Srinivasan,
Stephen Hemminger, Haiyang Zhang, olaf, gregkh, linux-kernel,
apw, jasowang, Vitaly Kuznetsov
On Tue, Feb 07, 2017 at 09:00:10AM +0000, Dexuan Cui wrote:
> The devfn of 00:02.0 is 0x10.
> devfn_to_wslot(0x10) == 0x2, and wslot_to_devfn(0x2) should be 0x10,
> while it's 0x2 in the current code.
>
> Due to this, hv_eject_device_work() -> pci_get_domain_bus_and_slot()
> returns NULL and pci_stop_and_remove_bus_device() is not called.
>
> Later when the real device driver's .remove() is invoked by
> hv_pci_remove() -> pci_stop_root_bus(), some warnings can be noticed
> because the VM has lost the access to the underlying device at that
> time.
>
> Signed-off-by: Jake Oshins <jakeo@microsoft.com>
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> Cc: stable@vger.kernel.org
> Cc: K. Y. Srinivasan <kys@microsoft.com>
> CC: Haiyang Zhang <haiyangz@microsoft.com>
> Cc: Stephen Hemminger <sthemmin@microsoft.com>
Applied with Haiyang's ack to pci/host-hv for v4.11, thanks!
> ---
> drivers/pci/host/pci-hyperv.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> The patch is co-made by Jake and me.
>
> diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
> index 3efcc7b..cd114c6 100644
> --- a/drivers/pci/host/pci-hyperv.c
> +++ b/drivers/pci/host/pci-hyperv.c
> @@ -130,7 +130,8 @@ enum pci_message_type {
> */
> union win_slot_encoding {
> struct {
> - u32 func:8;
> + u32 dev:5;
> + u32 func:3;
> u32 reserved:24;
> } bits;
> u32 slot;
> @@ -485,7 +486,8 @@ static u32 devfn_to_wslot(int devfn)
> union win_slot_encoding wslot;
>
> wslot.slot = 0;
> - wslot.bits.func = PCI_SLOT(devfn) | (PCI_FUNC(devfn) << 5);
> + wslot.bits.dev = PCI_SLOT(devfn);
> + wslot.bits.func = PCI_FUNC(devfn);
>
> return wslot.slot;
> }
> @@ -503,7 +505,7 @@ static int wslot_to_devfn(u32 wslot)
> union win_slot_encoding slot_no;
>
> slot_no.slot = wslot;
> - return PCI_DEVFN(0, slot_no.bits.func);
> + return PCI_DEVFN(slot_no.bits.dev, slot_no.bits.func);
> }
>
> /*
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-02-10 21:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-07 9:00 [PATCH] PCI: hv: fix wslot_to_devfn() Dexuan Cui
2017-02-07 16:17 ` Haiyang Zhang
2017-02-10 21:19 ` Bjorn Helgaas
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).