Commit 067d6ec
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>1 parent a847234 commit 067d6ec
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 | | |
| |||
2605 | 2608 | | |
2606 | 2609 | | |
2607 | 2610 | | |
| 2611 | + | |
| 2612 | + | |
2608 | 2613 | | |
2609 | 2614 | | |
2610 | 2615 | | |
| |||
2686 | 2691 | | |
2687 | 2692 | | |
2688 | 2693 | | |
| 2694 | + | |
| 2695 | + | |
2689 | 2696 | | |
2690 | 2697 | | |
2691 | 2698 | | |
| |||
2834 | 2841 | | |
2835 | 2842 | | |
2836 | 2843 | | |
| 2844 | + | |
| 2845 | + | |
2837 | 2846 | | |
2838 | 2847 | | |
2839 | 2848 | | |
| |||
2870 | 2879 | | |
2871 | 2880 | | |
2872 | 2881 | | |
| 2882 | + | |
| 2883 | + | |
2873 | 2884 | | |
2874 | 2885 | | |
2875 | 2886 | | |
| |||
3636 | 3647 | | |
3637 | 3648 | | |
3638 | 3649 | | |
| 3650 | + | |
3639 | 3651 | | |
3640 | 3652 | | |
3641 | 3653 | | |
| |||
3745 | 3757 | | |
3746 | 3758 | | |
3747 | 3759 | | |
| 3760 | + | |
| 3761 | + | |
3748 | 3762 | | |
3749 | 3763 | | |
3750 | | - | |
| 3764 | + | |
3751 | 3765 | | |
3752 | 3766 | | |
3753 | 3767 | | |
| |||
3765 | 3779 | | |
3766 | 3780 | | |
3767 | 3781 | | |
| 3782 | + | |
3768 | 3783 | | |
3769 | 3784 | | |
3770 | 3785 | | |
3771 | 3786 | | |
3772 | 3787 | | |
3773 | 3788 | | |
| 3789 | + | |
| 3790 | + | |
3774 | 3791 | | |
3775 | 3792 | | |
3776 | 3793 | | |
| |||
4020 | 4037 | | |
4021 | 4038 | | |
4022 | 4039 | | |
| 4040 | + | |
| 4041 | + | |
4023 | 4042 | | |
4024 | 4043 | | |
4025 | | - | |
| 4044 | + | |
4026 | 4045 | | |
4027 | 4046 | | |
4028 | 4047 | | |
4029 | | - | |
| 4048 | + | |
4030 | 4049 | | |
4031 | 4050 | | |
4032 | 4051 | | |
4033 | 4052 | | |
4034 | 4053 | | |
4035 | 4054 | | |
| 4055 | + | |
4036 | 4056 | | |
| 4057 | + | |
| 4058 | + | |
| 4059 | + | |
4037 | 4060 | | |
4038 | 4061 | | |
4039 | 4062 | | |
| |||
0 commit comments