Commit f118487
committed
PCI: hv: Add a per-bus mutex state_lock
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2182619
commit 067d6ec
Author: Dexuan Cui <decui@microsoft.com>
Date: Wed Jun 14 21:44:51 2023 -0700
PCI: hv: Add a per-bus mutex state_lock
In the case of fast device addition/removal, it's possible that
hv_eject_device_work() can start to run before create_root_hv_pci_bus()
starts to run; as a result, the pci_get_domain_bus_and_slot() in
hv_eject_device_work() can return a 'pdev' of NULL, and
hv_eject_device_work() can remove the 'hpdev', and immediately send a
message PCI_EJECTION_COMPLETE to the host, and the host immediately
unassigns the PCI device from the guest; meanwhile,
create_root_hv_pci_bus() and the PCI device driver can be probing the
dead PCI device and reporting timeout errors.
Fix the issue by adding a per-bus mutex 'state_lock' and grabbing the
mutex before powering on the PCI bus in hv_pci_enter_d0(): when
hv_eject_device_work() starts to run, it's able to find the 'pdev' and call
pci_stop_and_remove_bus_device(pdev): if the PCI device driver has
loaded, the PCI device driver's probe() function is already called in
create_root_hv_pci_bus() -> pci_bus_add_devices(), and now
hv_eject_device_work() -> pci_stop_and_remove_bus_device() is able
to call the PCI device driver's remove() function and remove the device
reliably; if the PCI device driver hasn't loaded yet, the function call
hv_eject_device_work() -> pci_stop_and_remove_bus_device() is able to
remove the PCI device reliably and the PCI device driver's probe()
function won't be called; if the PCI device driver's probe() is already
running (e.g., systemd-udev is loading the PCI device driver), it must
be holding the per-device lock, and after the probe() finishes and releases
the lock, hv_eject_device_work() -> pci_stop_and_remove_bus_device() is
able to proceed to remove the device reliably.
Fixes: 4daace0 ("PCI: hv: Add paravirtual PCI front-end for Microsoft Hyper-V VMs")
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Acked-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20230615044451.5580-6-decui@microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>1 parent ab1b2ab commit f118487
1 file changed
+26
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
489 | 489 | | |
490 | 490 | | |
491 | 491 | | |
| 492 | + | |
| 493 | + | |
492 | 494 | | |
| 495 | + | |
493 | 496 | | |
494 | 497 | | |
495 | 498 | | |
| |||
2512 | 2515 | | |
2513 | 2516 | | |
2514 | 2517 | | |
| 2518 | + | |
| 2519 | + | |
2515 | 2520 | | |
2516 | 2521 | | |
2517 | 2522 | | |
| |||
2593 | 2598 | | |
2594 | 2599 | | |
2595 | 2600 | | |
| 2601 | + | |
| 2602 | + | |
2596 | 2603 | | |
2597 | 2604 | | |
2598 | 2605 | | |
| |||
2741 | 2748 | | |
2742 | 2749 | | |
2743 | 2750 | | |
| 2751 | + | |
| 2752 | + | |
2744 | 2753 | | |
2745 | 2754 | | |
2746 | 2755 | | |
| |||
2777 | 2786 | | |
2778 | 2787 | | |
2779 | 2788 | | |
| 2789 | + | |
| 2790 | + | |
2780 | 2791 | | |
2781 | 2792 | | |
2782 | 2793 | | |
| |||
3567 | 3578 | | |
3568 | 3579 | | |
3569 | 3580 | | |
| 3581 | + | |
3570 | 3582 | | |
3571 | 3583 | | |
3572 | 3584 | | |
| |||
3675 | 3687 | | |
3676 | 3688 | | |
3677 | 3689 | | |
| 3690 | + | |
| 3691 | + | |
3678 | 3692 | | |
3679 | 3693 | | |
3680 | | - | |
| 3694 | + | |
3681 | 3695 | | |
3682 | 3696 | | |
3683 | 3697 | | |
| |||
3695 | 3709 | | |
3696 | 3710 | | |
3697 | 3711 | | |
| 3712 | + | |
3698 | 3713 | | |
3699 | 3714 | | |
3700 | 3715 | | |
3701 | 3716 | | |
3702 | 3717 | | |
3703 | 3718 | | |
| 3719 | + | |
| 3720 | + | |
3704 | 3721 | | |
3705 | 3722 | | |
3706 | 3723 | | |
| |||
3950 | 3967 | | |
3951 | 3968 | | |
3952 | 3969 | | |
| 3970 | + | |
| 3971 | + | |
3953 | 3972 | | |
3954 | 3973 | | |
3955 | | - | |
| 3974 | + | |
3956 | 3975 | | |
3957 | 3976 | | |
3958 | 3977 | | |
3959 | | - | |
| 3978 | + | |
3960 | 3979 | | |
3961 | 3980 | | |
3962 | 3981 | | |
3963 | 3982 | | |
3964 | 3983 | | |
3965 | 3984 | | |
| 3985 | + | |
3966 | 3986 | | |
| 3987 | + | |
| 3988 | + | |
| 3989 | + | |
3967 | 3990 | | |
3968 | 3991 | | |
3969 | 3992 | | |
| |||
0 commit comments