From patchwork Thu May 16 15:50:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 2578651 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 59D843FE1F for ; Thu, 16 May 2013 15:53:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754854Ab3EPPwI (ORCPT ); Thu, 16 May 2013 11:52:08 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:49572 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754847Ab3EPPwF (ORCPT ); Thu, 16 May 2013 11:52:05 -0400 Received: by mail-pa0-f54.google.com with SMTP id kx1so2650405pab.13 for ; Thu, 16 May 2013 08:52:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=Jq8YLjXiO77zWb9iHL33w0/5K+mf1agIAE89ko6oq20=; b=aOZn+Il4LK8cPctsb/i44IP4kiUOK+SqkTfCSeyGRoOYhR0t7n73XbUmMwbH41oMb9 P/oNEaL/Nl6ShqiHyUXLe3GeApjP1TzjcLNwy8WLx91cvUSOVt5hlE7RGTgcgRkXqHIk yw3OPm4T3x/PPNficEMBnSqh7mdKp6u4NGU2LwMuRyE1YCd9R+yel0XfjYWV3aBjm1wG /DeitqrI5xFrYWZNbYvKCxUVWC/irgmIXP5bPlnatbLwLqna/78/Ox1fy9Se9df6Wm21 ZcuEk6bRNNAUnsVBI+E7SJl8n3X+trN6wLHE2VUoQGBmy1lF1HEAShVZFydsM2LWC65p 1+kQ== X-Received: by 10.68.11.73 with SMTP id o9mr44195023pbb.18.1368719524344; Thu, 16 May 2013 08:52:04 -0700 (PDT) Received: from localhost.localdomain ([120.196.98.100]) by mx.google.com with ESMTPSA id ea15sm8026701pad.16.2013.05.16.08.51.58 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 16 May 2013 08:52:03 -0700 (PDT) From: Jiang Liu To: Bjorn Helgaas , Yinghai Lu Cc: Jiang Liu , "Rafael J . Wysocki" , Greg Kroah-Hartman , Gu Zheng , Toshi Kani , Myron Stowe , Yijing Wang , Jiang Liu , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Len Brown , Feng Tang , linux-acpi@vger.kernel.org Subject: [RFC PATCH v2, part3 11/11] PCI, ACPI, pci_root: use PCI bus lock to protect PCI device hotplug Date: Thu, 16 May 2013 23:50:59 +0800 Message-Id: <1368719459-24800-12-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1368719459-24800-1-git-send-email-jiang.liu@huawei.com> References: <1368719459-24800-1-git-send-email-jiang.liu@huawei.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Use PCI bus lock to protect concurrent PCI device hotplug operations. Signed-off-by: Jiang Liu Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: x86@kernel.org Cc: Len Brown Cc: "Rafael J. Wysocki" Cc: Yinghai Lu Cc: Feng Tang Cc: linux-kernel@vger.kernel.org Cc: linux-acpi@vger.kernel.org Acked-by: Rafael J. Wysocki --- arch/ia64/pci/pci.c | 2 +- arch/x86/pci/acpi.c | 3 ++- drivers/acpi/pci_root.c | 14 ++++++++------ drivers/pci/Kconfig | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/arch/ia64/pci/pci.c b/arch/ia64/pci/pci.c index de1474f..6e91e87 100644 --- a/arch/ia64/pci/pci.c +++ b/arch/ia64/pci/pci.c @@ -384,7 +384,7 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) } pci_scan_child_bus(pbus); - return pbus; + return pci_bus_get(pbus); out3: kfree(controller->window); diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c index b972f04..6dddc06 100644 --- a/arch/x86/pci/acpi.c +++ b/arch/x86/pci/acpi.c @@ -534,7 +534,7 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) */ memcpy(bus->sysdata, sd, sizeof(*sd)); kfree(info); - pci_bus_put(bus); + BUG_ON(pci_bus_lock(bus, PCI_BUS_STATE_REMOVED - 1, true) < 0); } else { probe_pci_root_info(info, device, busnum, domain); @@ -561,6 +561,7 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) pci_set_host_bridge_release( to_pci_host_bridge(bus->bridge), release_pci_root_info, info); + pci_bus_get(bus); } else { pci_free_resource_list(&resources); __release_pci_root_info(info); diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index 21dda5a..eb01cc7 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -535,6 +535,7 @@ static int acpi_pci_root_add(struct acpi_device *device, } pci_bus_add_devices(root->bus); + pci_bus_unlock(root->bus, true); return 1; end: @@ -546,13 +547,14 @@ static void acpi_pci_root_remove(struct acpi_device *device) { struct acpi_pci_root *root = acpi_driver_data(device); - pci_stop_root_bus(root->bus); - - device_set_run_wake(root->bus->bridge, false); - pci_acpi_remove_bus_pm_notifier(device); - - pci_remove_root_bus(root->bus); + if (pci_bus_lock(root->bus, PCI_BUS_STATE_REMOVED - 1, true) == 0) { + pci_stop_root_bus(root->bus); + device_set_run_wake(root->bus->bridge, false); + pci_acpi_remove_bus_pm_notifier(device); + pci_remove_root_bus(root->bus); + } + pci_bus_put(root->bus); kfree(root); } diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 92e69bd..5ae3504 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -121,4 +121,4 @@ config PCI_LABEL select NLS config PCI_BUS_LOCK - def_bool n + def_bool y if (X86 || IA64)