From patchwork Tue Aug 7 16:10:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1286831 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 876ACDF280 for ; Tue, 7 Aug 2012 16:22:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755604Ab2HGQVI (ORCPT ); Tue, 7 Aug 2012 12:21:08 -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 S1755573Ab2HGQVF (ORCPT ); Tue, 7 Aug 2012 12:21:05 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr13so4529963pbb.19 for ; Tue, 07 Aug 2012 09:21:05 -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=F++DzT/HtL1iXa4AROtTLngSTdoTMVCFlTjehGaQ0lQ=; b=EeivqKxmACbtRlI/QizFCAg4UbzU+QBqaCo4uh7FNot9/8rXXqAGeMWi6BUvEsc9cD 1Ij6LuyRj13DAi6IdIbNOh/pYgjnb1XbEqHRXe1jJRkK+Dr1JvmA8T8CnQVJlCNd/Fti 5s1WqCi9ux+uPgzh8OwtpixyxH/c4K76voHMkcH0U9/NKtcu1wJImKqLUgH6eVWOaVKy INQq1q7F+VwbPdMKZgJ3/ZGiJHYZ2I74SblyCCt20hWDv1/IhxdS+u+CHMMojW0Yzw6d GLpGPFwBEiSm2TB+V0gF0y1bgbTRcJFLriIjAT8cpekq873JQ8zFoEkKHVz4V1rm6EyU JEWg== Received: by 10.68.200.98 with SMTP id jr2mr28810933pbc.81.1344356465608; Tue, 07 Aug 2012 09:21:05 -0700 (PDT) Received: from localhost.localdomain ([58.250.81.2]) by mx.google.com with ESMTPS id pt2sm11429362pbb.58.2012.08.07.09.20.58 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 07 Aug 2012 09:21:05 -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, Jiang Liu Subject: [RFC PATCH v1 17/22] PCI/pciehp: use PCI bus lock to avoid race conditions Date: Wed, 8 Aug 2012 00:10:57 +0800 Message-Id: <1344355862-2726-18-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 This patch uses PCI bus lock mechanism to avoid race conditions when doing PCI device hotplug by pciehp driver. Signed-off-by: Jiang Liu --- drivers/pci/hotplug/pciehp_pci.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c index 09cecaf..9536a9e 100644 --- a/drivers/pci/hotplug/pciehp_pci.c +++ b/drivers/pci/hotplug/pciehp_pci.c @@ -42,18 +42,25 @@ int pciehp_configure_device(struct slot *p_slot) int num, fn; struct controller *ctrl = p_slot->ctrl; + if (pci_bus_lock_states(parent, PCI_BUS_STATE_WORKING) < 0) { + ctrl_dbg(ctrl, "Port has been removed\n"); + return -EINVAL; + } + dev = pci_get_slot(parent, PCI_DEVFN(0, 0)); if (dev) { ctrl_err(ctrl, "Device %s already exists " "at %04x:%02x:00, cannot hot-add\n", pci_name(dev), pci_domain_nr(parent), parent->number); pci_dev_put(dev); + pci_bus_unlock(parent); return -EINVAL; } num = pci_scan_slot(parent, PCI_DEVFN(0, 0)); if (num == 0) { ctrl_err(ctrl, "No new device found\n"); + pci_bus_unlock(parent); return -ENODEV; } @@ -82,6 +89,7 @@ int pciehp_configure_device(struct slot *p_slot) } pci_bus_add_devices(parent); + pci_bus_unlock(parent); return 0; } @@ -96,6 +104,11 @@ int pciehp_unconfigure_device(struct slot *p_slot) u16 command; struct controller *ctrl = p_slot->ctrl; + if (pci_bus_lock_states(parent, PCI_BUS_STATE_WORKING) < 0) { + ctrl_dbg(ctrl, "Port has been removed\n"); + return -EINVAL; + } + ctrl_dbg(ctrl, "%s: domain:bus:dev = %04x:%02x:00\n", __func__, pci_domain_nr(parent), parent->number); ret = pciehp_get_adapter_status(p_slot, &presence); @@ -131,5 +144,7 @@ int pciehp_unconfigure_device(struct slot *p_slot) pci_dev_put(temp); } + pci_bus_unlock(parent); + return rc; }