From patchwork Mon Apr 16 16:28: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: 152928 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 75947B7018 for ; Tue, 17 Apr 2012 02:32:37 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753332Ab2DPQch (ORCPT ); Mon, 16 Apr 2012 12:32:37 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:52165 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752265Ab2DPQcg (ORCPT ); Mon, 16 Apr 2012 12:32:36 -0400 Received: by mail-pb0-f46.google.com with SMTP id un15so6539626pbc.19 for ; Mon, 16 Apr 2012 09:32:36 -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=bKMm2hwoYUD0dfeOzFgw8O28uHbmm1vSmjT0DMKaaM4=; b=k+98Qse8GTTeBgHu5nteyBek23ODXlVwV3UOJkjxBizcj6RZAhO+cGSuLEIwOm2NvI DSkDb/t+tgDzhPColGeYU8SD/7vxPE7gvWvVUApv2UkGR8TvTt1uMbgQjF+RCuiWUNEf vi94UIjTB0Jg9wQchKDW8tUBsWK2sEYj3w7kDlc/YBZNcopBuEeglSzJdZZUs8z6TOBH rTut4jcC+jaJ32IiBs/sy2BD9+9Ltln8qlOL6Cgxm4R2IxRSCA8MBVMsr2Q+VlfoComJ 6T+KvpgwJAz7qNcM3l+LNyuSTYPrJrtL3iRGQRgYtKd5Fa7FM38dnx5KihKtB7Y+On+w +pvQ== Received: by 10.68.132.232 with SMTP id ox8mr28716905pbb.145.1334593956270; Mon, 16 Apr 2012 09:32:36 -0700 (PDT) Received: from localhost.localdomain ([221.221.22.162]) by mx.google.com with ESMTPS id v1sm18106794pbk.10.2012.04.16.09.32.28 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 Apr 2012 09:32:35 -0700 (PDT) From: Jiang Liu To: Yinghai Lu , Kenji Kaneshige , Bjorn Helgaas , Greg Kroah-Hartman , Scott Murray Cc: Jiang Liu , Jiang Liu , Keping Chen , linux-pci@vger.kernel.org Subject: [PATCH RFC 04/17] PCI: serialize hotplug operations triggered by PCI hotplug sysfs interfaces Date: Tue, 17 Apr 2012 00:28:58 +0800 Message-Id: <1334593751-5916-5-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1334593751-5916-1-git-send-email-jiang.liu@huawei.com> References: <1334593751-5916-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 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);