From patchwork Fri Apr 27 15:16:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 155520 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 CF69AB6F9F for ; Sat, 28 Apr 2012 01:25:39 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760536Ab2D0PUh (ORCPT ); Fri, 27 Apr 2012 11:20:37 -0400 Received: from mail-pz0-f51.google.com ([209.85.210.51]:38951 "EHLO mail-pz0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760531Ab2D0PUf (ORCPT ); Fri, 27 Apr 2012 11:20:35 -0400 Received: by mail-pz0-f51.google.com with SMTP id z8so1147938dad.10 for ; Fri, 27 Apr 2012 08:20:34 -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=xyJz8wv61acy89FGZJRlawmD2tnkiZ15O+ZJTjQJrPY=; b=rblxGo2w55SBOGk7KzXQhtp72QnT067E1sWMCV/lM7Z54laINNqBfwTcGxwfin+5B6 E9+N/HwspQ5M0yAn6xUhMmSJhy/zwlItSRSYdt3MKhOUZVDbqIfM+gAO+qCmI9FO8WXv 9FZrSs1nC9bt7nwViwfVWDF7Dqup0HftKi3VInYfc3WjWBHyojno6RfO7f16aZN3Rg3b lgdE2MoCsF18FojElCgkJY0zyoAWz7uohNg8zcB3F8wfNhYejf3iQth2UkRNTYaV7tPT wx9vSnDrzYD1F0YugyOThDzwwCsXfFZjYqrBTHnKl8Nxc51Z8OwPof47oWcjJ4Sq1z6X uPGw== Received: by 10.68.189.1 with SMTP id ge1mr17402170pbc.19.1335540034952; Fri, 27 Apr 2012 08:20:34 -0700 (PDT) Received: from localhost.localdomain ([221.221.26.142]) by mx.google.com with ESMTPS id 2sm6743917pbw.57.2012.04.27.08.20.25 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Apr 2012 08:20:33 -0700 (PDT) From: Jiang Liu To: Yinghai Lu , Kenji Kaneshige , Bjorn Helgaas , Don Dutile , Greg KH Cc: Jiang Liu , Keping Chen , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Jiang Liu Subject: [PATCH v2 04/19] PCI: serialize hotplug operations triggered by PCI hotplug sysfs interfaces Date: Fri, 27 Apr 2012 23:16:45 +0800 Message-Id: <1335539820-11232-5-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1335539820-11232-1-git-send-email-jiang.liu@huawei.com> References: <1335539820-11232-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 Use PCI hotplug lock to globally serialize hotplug operations triggered by PCI hotplug sysfs interfaces. Signed-off-by: Jiang Liu --- drivers/pci/hotplug/pci_hotplug_core.c | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c index 1572665..9bbbe3e 100644 --- a/drivers/pci/hotplug/pci_hotplug_core.c +++ b/drivers/pci/hotplug/pci_hotplug_core.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include "../pci.h" @@ -121,6 +122,17 @@ static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf, retval = -ENODEV; goto exit; } + + /* Avoid deadlock with pci_hp_deregister() */ + while (!pci_hotplug_try_enter()) { + /* Check whether the slot has been deregistered. */ + if (list_empty(&slot->slot_list)) { + retval = -ENODEV; + goto exit_put; + } + msleep(1); + } + switch (power) { case 0: if (slot->ops->disable_slot) @@ -136,8 +148,10 @@ static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf, err ("Illegal value specified for power\n"); retval = -EINVAL; } - module_put(slot->ops->owner); + pci_hotplug_exit(); +exit_put: + module_put(slot->ops->owner); exit: if (retval) return retval; @@ -500,7 +514,7 @@ int pci_hp_deregister(struct hotplug_slot *hotplug) return -ENODEV; } - list_del(&hotplug->slot_list); + list_del_init(&hotplug->slot_list); slot = hotplug->pci_slot; fs_remove_slot(slot);