From patchwork Thu May 16 15:50:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 2578631 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 26F8B3FE37 for ; Thu, 16 May 2013 15:53:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753978Ab3EPPv5 (ORCPT ); Thu, 16 May 2013 11:51:57 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:34568 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754806Ab3EPPvz (ORCPT ); Thu, 16 May 2013 11:51:55 -0400 Received: by mail-pd0-f176.google.com with SMTP id x10so2458187pdj.35 for ; Thu, 16 May 2013 08:51:54 -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=rBbuiNHWGCE9WVwC4vh562nA2PxmW4e9ontseeMEdmU=; b=vTowdb04PEN+HpeZrgIXzkKqAL845sxdbUYxHjwekxXgH2szeNoqKtmBYJ/28MM6Kw wzNcasUz78u9Fe76e3QAPra8yLt2aosv+kvWxYvl6n8ieInzIEB7WvCXatbBBhooPZuA LSnt7Cxxx0A7JeAIzqZOa8sBiruEdhz3PPFGJLgKn8yOXCt4RZ+xcWUhZ9073FvCo6bB +tsJXjSukaou7X5qe3P53aLYySxAfTMRH1/iXVV+me2sueHb9BricsoIvlNLyjNAetIm pUx01NznkO2TsHxLHgj34UtqtAWlDy9n4gMSHxhbyfNKnR1oSecoKiwlZui3EeuD3W4N wc8g== X-Received: by 10.68.237.106 with SMTP id vb10mr37763716pbc.131.1368719514318; Thu, 16 May 2013 08:51:54 -0700 (PDT) Received: from localhost.localdomain ([120.196.98.100]) by mx.google.com with ESMTPSA id ea15sm8026701pad.16.2013.05.16.08.51.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 16 May 2013 08:51:53 -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, "Rafael J. Wysocki" Subject: [RFC PATCH v2, part3 09/11] PCI, acpiphp: use PCI bus lock to protect PCI device hotplug Date: Thu, 16 May 2013 23:50:57 +0800 Message-Id: <1368719459-24800-10-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: Yinghai Lu Cc: "Rafael J. Wysocki" Cc: Yijing Wang Cc: linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/pci/hotplug/acpiphp_glue.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index e330331..d105dcd 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -674,6 +674,9 @@ static int __ref enable_device(struct acpiphp_slot *slot) if (slot->flags & SLOT_ENABLED) goto err_exit; + if (pci_bus_lock(bus, PCI_BUS_STATE_STOPPING - 1, true) < 0) + goto err_exit; + list_for_each_entry(func, &slot->funcs, sibling) acpiphp_bus_add(func); @@ -681,7 +684,7 @@ static int __ref enable_device(struct acpiphp_slot *slot) if (num == 0) { /* Maybe only part of funcs are added. */ dbg("No new device found\n"); - goto err_exit; + goto out_unlock; } max = acpiphp_max_busnr(bus); @@ -726,8 +729,9 @@ static int __ref enable_device(struct acpiphp_slot *slot) } } - - err_exit: +out_unlock: + pci_bus_unlock(bus, true); +err_exit: return 0; } @@ -757,7 +761,10 @@ static int disable_device(struct acpiphp_slot *slot) { struct acpiphp_func *func; struct pci_dev *pdev; + struct pci_bus *bus = slot->bridge->pci_bus; + if (pci_bus_lock(bus, PCI_BUS_STATE_STOPPING - 1, true) < 0) + return -EBUSY; /* * enable_device() enumerates all functions in this device via * pci_scan_slot(), whether they have associated ACPI hotplug @@ -768,6 +775,7 @@ static int disable_device(struct acpiphp_slot *slot) pci_stop_and_remove_bus_device(pdev); pci_dev_put(pdev); } + pci_bus_unlock(bus, true); list_for_each_entry(func, &slot->funcs, sibling) { acpiphp_bus_trim(func->handle);