{"id":818661,"url":"http://patchwork.ozlabs.org/api/patches/818661/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/patch/20170926141720.25067-6-mika.westerberg@linux.intel.com/","project":{"id":28,"url":"http://patchwork.ozlabs.org/api/projects/28/?format=json","name":"Linux PCI development","link_name":"linux-pci","list_id":"linux-pci.vger.kernel.org","list_email":"linux-pci@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170926141720.25067-6-mika.westerberg@linux.intel.com>","list_archive_url":null,"date":"2017-09-26T14:17:18","name":"[5/7] PCI: pciehp: Fix race condition handling surprise link down","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"934e3810220ce99628d967cfadfa2b5e280f1a86","submitter":{"id":14534,"url":"http://patchwork.ozlabs.org/api/people/14534/?format=json","name":"Mika Westerberg","email":"mika.westerberg@linux.intel.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-pci/patch/20170926141720.25067-6-mika.westerberg@linux.intel.com/mbox/","series":[{"id":5151,"url":"http://patchwork.ozlabs.org/api/series/5151/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/list/?series=5151","date":"2017-09-26T14:17:19","name":"PCI: Improvements for native PCIe hotplug","version":1,"mbox":"http://patchwork.ozlabs.org/series/5151/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/818661/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/818661/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linux-pci-owner@vger.kernel.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=linux-pci-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3y1jkF4K0lz9t3B\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 27 Sep 2017 00:19:01 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1030496AbdIZORb (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tTue, 26 Sep 2017 10:17:31 -0400","from mga11.intel.com ([192.55.52.93]:56468 \"EHLO mga11.intel.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1030477AbdIZOR3 (ORCPT <rfc822;linux-pci@vger.kernel.org>);\n\tTue, 26 Sep 2017 10:17:29 -0400","from orsmga002.jf.intel.com ([10.7.209.21])\n\tby fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t26 Sep 2017 07:17:28 -0700","from black.fi.intel.com ([10.237.72.28])\n\tby orsmga002.jf.intel.com with ESMTP; 26 Sep 2017 07:17:23 -0700","by black.fi.intel.com (Postfix, from userid 1001)\n\tid 7C0473F2; Tue, 26 Sep 2017 17:17:20 +0300 (EEST)"],"X-ExtLoop1":"1","X-IronPort-AV":"E=Sophos;i=\"5.42,441,1500966000\"; d=\"scan'208\";a=\"139591601\"","From":"Mika Westerberg <mika.westerberg@linux.intel.com>","To":"Bjorn Helgaas <bhelgaas@google.com>","Cc":"Ashok Raj <ashok.raj@intel.com>, Keith Busch <keith.busch@intel.com>,\n\t\"Rafael J . Wysocki\" <rafael.j.wysocki@intel.com>,\n\tLukas Wunner <lukas@wunner.de>, Michael Jamet <michael.jamet@intel.com>,\n\tYehezkel Bernat <yehezkel.bernat@intel.com>, Mario.Limonciello@dell.com,\n\tMika Westerberg <mika.westerberg@linux.intel.com>,\n\tlinux-pci@vger.kernel.org, linux-kernel@vger.kernel.org","Subject":"[PATCH 5/7] PCI: pciehp: Fix race condition handling surprise link\n\tdown","Date":"Tue, 26 Sep 2017 17:17:18 +0300","Message-Id":"<20170926141720.25067-6-mika.westerberg@linux.intel.com>","X-Mailer":"git-send-email 2.14.1","In-Reply-To":"<20170926141720.25067-1-mika.westerberg@linux.intel.com>","References":"<20170926141720.25067-1-mika.westerberg@linux.intel.com>","Sender":"linux-pci-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<linux-pci.vger.kernel.org>","X-Mailing-List":"linux-pci@vger.kernel.org"},"content":"A surprise link down may retrain very quickly causing the same slot\ngenerate a link up event before handling the link down event completes.\n\nSince the link is active, the power off work queued from the first link\ndown will cause a second down event when power is disabled. However, the\nlink up event sets the slot state to POWERON_STATE before the event to\nhandle this is enqueued, making the second down event believe it needs\nto do something.\n\nThis creates constant link up and down event cycle.\n\nTo prevent this it is better to handle each event at the time in order\nit occurred, so change the driver to use ordered workqueue instead.\n\nA normal device hotplug triggers two events (presense detect and link\nup) that are already handled properly in the driver but we currently log\nan error if we find an existing device in the slot. Since this is not an\nerror change the log level to be debug instead to avoid scaring users.\n\nThis is based on the original work by Ashok Raj.\n\nLink: https://patchwork.kernel.org/patch/9469023\nSuggested-by: Bjorn Helgaas <bhelgaas@google.com>\nSigned-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>\n---\n drivers/pci/hotplug/pciehp_ctrl.c | 7 ++++---\n drivers/pci/hotplug/pciehp_hpc.c  | 2 +-\n drivers/pci/hotplug/pciehp_pci.c  | 6 +++++-\n 3 files changed, 10 insertions(+), 5 deletions(-)","diff":"diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c\nindex ec0b4c11ccd9..83f3d4af3677 100644\n--- a/drivers/pci/hotplug/pciehp_ctrl.c\n+++ b/drivers/pci/hotplug/pciehp_ctrl.c\n@@ -113,10 +113,11 @@ static int board_added(struct slot *p_slot)\n \n \tretval = pciehp_configure_device(p_slot);\n \tif (retval) {\n-\t\tctrl_err(ctrl, \"Cannot add device at %04x:%02x:00\\n\",\n-\t\t\t pci_domain_nr(parent), parent->number);\n-\t\tif (retval != -EEXIST)\n+\t\tif (retval != -EEXIST) {\n+\t\t\tctrl_err(ctrl, \"Cannot add device at %04x:%02x:00\\n\",\n+\t\t\t\t pci_domain_nr(parent), parent->number);\n \t\t\tgoto err_exit;\n+\t\t}\n \t}\n \n \tpciehp_green_led_on(p_slot);\ndiff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c\nindex e5d5ce9e3010..83c93f9da65a 100644\n--- a/drivers/pci/hotplug/pciehp_hpc.c\n+++ b/drivers/pci/hotplug/pciehp_hpc.c\n@@ -795,7 +795,7 @@ static int pcie_init_slot(struct controller *ctrl)\n \tif (!slot)\n \t\treturn -ENOMEM;\n \n-\tslot->wq = alloc_workqueue(\"pciehp-%u\", 0, 0, PSN(ctrl));\n+\tslot->wq = alloc_ordered_workqueue(\"pciehp-%u\", 0, PSN(ctrl));\n \tif (!slot->wq)\n \t\tgoto abort;\n \ndiff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c\nindex 19f30a9f461d..b31702f76149 100644\n--- a/drivers/pci/hotplug/pciehp_pci.c\n+++ b/drivers/pci/hotplug/pciehp_pci.c\n@@ -46,7 +46,11 @@ int pciehp_configure_device(struct slot *p_slot)\n \n \tdev = pci_get_slot(parent, PCI_DEVFN(0, 0));\n \tif (dev) {\n-\t\tctrl_err(ctrl, \"Device %s already exists at %04x:%02x:00, cannot hot-add\\n\",\n+\t\t/*\n+\t\t * The device is already there. Either configured by the\n+\t\t * boot firmware or a previous hotplug event.\n+\t\t */\n+\t\tctrl_dbg(ctrl, \"Device %s already exists at %04x:%02x:00, skipping hot-add\\n\",\n \t\t\t pci_name(dev), pci_domain_nr(parent), parent->number);\n \t\tpci_dev_put(dev);\n \t\tret = -EEXIST;\n","prefixes":["5/7"]}