From patchwork Thu May 16 15:50:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 2578621 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 0C5243FE1F for ; Thu, 16 May 2013 15:53:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754803Ab3EPPvx (ORCPT ); Thu, 16 May 2013 11:51:53 -0400 Received: from mail-da0-f54.google.com ([209.85.210.54]:33738 "EHLO mail-da0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754769Ab3EPPvu (ORCPT ); Thu, 16 May 2013 11:51:50 -0400 Received: by mail-da0-f54.google.com with SMTP id z17so1743865dal.13 for ; Thu, 16 May 2013 08:51:50 -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=cwwdl9bZhxwji1hQaldhRH+EdmbGw56Bb0nqCTqjrPc=; b=lbipu1u4o43XbDOdnkyw9g42Y+hlxhB/CxcjIPhQ9lWU5pFKmCgZv11VPV4FJUe6pM 0BI1E2C5/3sJ+jkiJqammJGks1KHr+HJkg+GuDIVGMnWDAjnhQNGck1AlbjCUTnQAL/e YNnkjBnDEAOO2uqZuuO/TiCGeJW9MgRtVHJta6fIAT1rNkZ/PCcKbpNJUOrwKt7jmY7v DUeg8EjQqEWEMEJVfrlLLmoiLSepzCBra9Zw1tv3TiwETB8Cagw5WwxKqAzwKdIi5jit XCv4PdDSxhDcVLKkszfhNbloRgB6/h4MiA6nf25OuYuP4GH4P0Vo5cPj1dXLjDT3EC4y 4kOg== X-Received: by 10.68.0.66 with SMTP id 2mr15749005pbc.15.1368719510095; Thu, 16 May 2013 08:51:50 -0700 (PDT) Received: from localhost.localdomain ([120.196.98.100]) by mx.google.com with ESMTPSA id ea15sm8026701pad.16.2013.05.16.08.51.44 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 16 May 2013 08:51:48 -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, Konrad Rzeszutek Wilk , Jeremy Fitzhardinge , xen-devel@lists.xensource.com, virtualization@lists.linux-foundation.org Subject: [RFC PATCH v2, part3 08/11] PCI, xen-pcifront: use PCI bus lock to protect PCI device hotplug Date: Thu, 16 May 2013 23:50:56 +0800 Message-Id: <1368719459-24800-9-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: Konrad Rzeszutek Wilk Cc: Jeremy Fitzhardinge Cc: xen-devel@lists.xensource.com Cc: virtualization@lists.linux-foundation.org Cc: linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/pci/xen-pcifront.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c index 6aa2c0f..2b213b3 100644 --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -505,6 +505,7 @@ static int pcifront_scan_root(struct pcifront_device *pdev, /* Create SysFS and notify udev of the devices. Aka: "going live" */ pci_bus_add_devices(b); + pci_bus_unlock(b, true); return err; @@ -538,6 +539,11 @@ static int pcifront_rescan_root(struct pcifront_device *pdev, /* If the bus is unknown, create it. */ return pcifront_scan_root(pdev, domain, bus); + if (pci_bus_lock(b, PCI_BUS_STATE_STOPPING - 1, true) < 0) { + err = -EBUSY; + goto out; + } + err = pcifront_scan_bus(pdev, domain, bus, b); /* Claim resources before going "live" with our devices */ @@ -545,6 +551,9 @@ static int pcifront_rescan_root(struct pcifront_device *pdev, /* Create SysFS and notify udev of the devices. Aka: "going live" */ pci_bus_add_devices(b); + pci_bus_unlock(b, true); + +out: pci_bus_put(b); return err; @@ -559,8 +568,11 @@ static void pcifront_free_roots(struct pcifront_device *pdev) for_each_pci_root_bus(bus) { sd = bus->sysdata; - if (sd->pdev == pdev) { + if (sd->pdev != pdev) + continue; + if (pci_bus_lock(bus, PCI_BUS_STATE_REMOVED - 1, true) == 0) { pci_stop_root_bus(bus); + /* it also unlocks PCI buses */ pci_remove_root_bus(bus); } } @@ -1042,7 +1054,7 @@ static int pcifront_detach_devices(struct pcifront_device *pdev) domain, bus, slot, func); continue; } - pci_stop_and_remove_bus_device(pci_dev); + pci_stop_and_remove_device(pci_dev); pci_dev_put(pci_dev); dev_dbg(&pdev->xdev->dev,