Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934119AbdCWWK4 (ORCPT ); Thu, 23 Mar 2017 18:10:56 -0400 Received: from a2nlsmtp01-02.prod.iad2.secureserver.net ([198.71.225.36]:34074 "EHLO a2nlsmtp01-02.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933828AbdCWWKv (ORCPT ); Thu, 23 Mar 2017 18:10:51 -0400 X-Greylist: delayed 681 seconds by postgrey-1.27 at vger.kernel.org; Thu, 23 Mar 2017 18:10:49 EDT x-originating-ip: 107.180.71.197 From: Long Li To: "K. Y. Srinivasan" , Haiyang Zhang , Bjorn Helgaas , Stephen Hemminger , devel@linuxdriverproject.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Long Li Subject: [PATCH 2/2 v5] pci-hyperv: lock pci bus on device eject Date: Thu, 23 Mar 2017 14:58:32 -0700 Message-Id: <1490306312-6417-1-git-send-email-longli@exchange.microsoft.com> X-Mailer: git-send-email 1.7.1 X-CMAE-Envelope: MS4wfLxb/cpnw1Y1GRch/ezGm3ROH92mjlLCSbnbGa+dg7fyKR8y+TvtFgWU/LX3REBGCIX6+XVRZsvTXqEpgkpOWnkk9tD0nJE44KkIP8OtJb7QL1nugdr4 tB1hoKYQc+QR/FAB6KvQs24N6Jjq86whMkMI9Hm/HTDUMptwtxFACuByssMsbw+9I5ltRUDLreXxjB+6GQ5Uv+r/qlH3CN8ep/2l3xnTT0/fmOU+IbpsrvS5 c9X0VXSMbjRR5kcgtRJC3mWgGHZIJFT9Qa/aQY+KN15IlAyJhJsc2J3N9hNRWf9t624sS7APNo9XialGpuCtTir8QQiwsdM8w4eU2puY0ExFtiFIew4tdGUq ce1CKBiIT20ydkxa/ozI4HXnTL0Bgzv2TOP8u6jGvFSLdm8TOTRuNBhOKHtUBH/p6qqozQ3v2vN9syHWiDLFA3MgsEl9IA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1606 Lines: 48 From: Long Li A PCI_EJECT message can arrive at the same time we are calling pci_scan_child_bus in the workqueue for the previous PCI_BUS_RELATIONS message or in create_root_hv_pci_bus(), in this case we could potentially modify the bus from multiple places. Properly lock the bus access. Thanks Dexuan Cui for pointing out the race condition in create_root_hv_pci_bus(). Signed-off-by: Long Li Reported-by: Xiaofeng Wang Acked-by: K. Y. Srinivasan --- drivers/pci/host/pci-hyperv.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 39fafda..a1b3c19 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -1209,9 +1209,11 @@ static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus) hbus->pci_bus->msi = &hbus->msi_chip; hbus->pci_bus->msi->dev = &hbus->hdev->device; + pci_lock_rescan_remove(); pci_scan_child_bus(hbus->pci_bus); pci_bus_assign_resources(hbus->pci_bus); pci_bus_add_devices(hbus->pci_bus); + pci_unlock_rescan_remove(); hbus->state = hv_pcibus_installed; return 0; } @@ -1612,8 +1614,10 @@ static void hv_eject_device_work(struct work_struct *work) pdev = pci_get_domain_bus_and_slot(hpdev->hbus->sysdata.domain, 0, wslot); if (pdev) { + pci_lock_rescan_remove(); pci_stop_and_remove_bus_device(pdev); pci_dev_put(pdev); + pci_unlock_rescan_remove(); } spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags); -- 2.7.4