From patchwork Tue Aug 7 16:10:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 175706 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id DAD022C00A3 for ; Wed, 8 Aug 2012 02:22:33 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755721Ab2HGQVT (ORCPT ); Tue, 7 Aug 2012 12:21:19 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:51364 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755678Ab2HGQVO (ORCPT ); Tue, 7 Aug 2012 12:21:14 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr13so4529963pbb.19 for ; Tue, 07 Aug 2012 09:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=O578ZmviEXDHwxUIYpfOtzqC0Ad1lwDw9CIYrlZ6Z0Q=; b=YqarPLKwtDXXlq1tD3Xgrl5HqDEJUq+OVqkSC9ADGH+VBJIW3YNEAaOGEhsMQQVE5d ulJxIbyl9aaJ3rtgSXWTKaG1ip3qlXwn4zEQo2DeCS5eyv3N5ZFWBBlBJ9tHTFvk+6Ky VTopvy5pu57O8T7dSnu24D0RkhLjzD/Y/LB/bZM2sz4TmIAzQKhpXQPXF78d0na2JqeK ULShEweP9VLGrkETJYAGFri41fJRG3Xlwfbsdi+35HpFFgUISbgGRc+dcRkVmv+XYig1 2H2Ba6WyZaivaflTxNMeZ1G+fJytwNAXhSvXEUSSb2NZS64EVwRNW9GTPtbIpYKN0HMD ukZA== Received: by 10.68.194.168 with SMTP id hx8mr28863474pbc.36.1344356474003; Tue, 07 Aug 2012 09:21:14 -0700 (PDT) Received: from localhost.localdomain ([58.250.81.2]) by mx.google.com with ESMTPS id pt2sm11429362pbb.58.2012.08.07.09.21.06 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 07 Aug 2012 09:21:13 -0700 (PDT) From: Jiang Liu To: Bjorn Helgaas , Don Dutile , Yinghai Lu , Greg KH , Kenji Kaneshige Cc: Jiang Liu , Taku Izumi , "Rafael J . Wysocki" , Yijing Wang , Xinwei Hu , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [RFC PATCH v1 18/22] PCI/acpiphp: use PCI bus lock to avoid race conditions Date: Wed, 8 Aug 2012 00:10:58 +0800 Message-Id: <1344355862-2726-19-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1344355862-2726-1-git-send-email-jiang.liu@huawei.com> References: <1344355862-2726-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 From: Jiang Liu This patch uses PCI bus lock mechanism to avoid race conditions when doing PCI device/host bridge hotplug by acpiphp driver. Signed-off-by: Jiang Liu --- drivers/pci/hotplug/acpiphp_glue.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 73af337..0ea7ab1 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -800,11 +800,14 @@ static int __ref enable_device(struct acpiphp_slot *slot) if (slot->flags & SLOT_ENABLED) goto err_exit; + if (pci_bus_lock_states(bus, PCI_BUS_STATE_WORKING) < 0) + return -EINVAL; + num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0)); 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); @@ -862,8 +865,10 @@ static int __ref enable_device(struct acpiphp_slot *slot) pci_dev_put(dev); } +out_unlock: + pci_bus_unlock(bus); - err_exit: +err_exit: return retval; } @@ -906,6 +911,9 @@ static int disable_device(struct acpiphp_slot *slot) struct pci_dev *pdev; struct pci_bus *bus = slot->bridge->pci_bus; + if (pci_bus_lock_states(bus, PCI_BUS_STATE_WORKING) < 0) + goto err_exit; + /* The slot will be enabled when func 0 is added, so check func 0 before disable the slot. */ pdev = pci_get_slot(bus, PCI_DEVFN(slot->device, 0)); @@ -943,6 +951,7 @@ static int disable_device(struct acpiphp_slot *slot) } slot->flags &= (~SLOT_ENABLED); + pci_bus_unlock(bus); err_exit: return 0;