{"id":818660,"url":"http://patchwork.ozlabs.org/api/patches/818660/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/patch/20170926141720.25067-8-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-8-mika.westerberg@linux.intel.com>","list_archive_url":null,"date":"2017-09-26T14:17:20","name":"[7/7] PCI: pciehp: Check that the device is really present before touching it","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"f31f387c0b207c4971848ca8a7e4113938d13999","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-8-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/818660/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/818660/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 3y1jk55jZTz9t43\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 27 Sep 2017 00:18:53 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1030952AbdIZORb (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tTue, 26 Sep 2017 10:17:31 -0400","from mga05.intel.com ([192.55.52.43]:35551 \"EHLO mga05.intel.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1030458AbdIZOR2 (ORCPT <rfc822;linux-pci@vger.kernel.org>);\n\tTue, 26 Sep 2017 10:17:28 -0400","from orsmga003.jf.intel.com ([10.7.209.27])\n\tby fmsmga105.fm.intel.com with ESMTP; 26 Sep 2017 07:17:27 -0700","from black.fi.intel.com ([10.237.72.28])\n\tby orsmga003.jf.intel.com with ESMTP; 26 Sep 2017 07:17:24 -0700","by black.fi.intel.com (Postfix, from userid 1001)\n\tid 98EA74B8; 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=\"1018582900\"","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 7/7] PCI: pciehp: Check that the device is really present\n\tbefore touching it","Date":"Tue, 26 Sep 2017 17:17:20 +0300","Message-Id":"<20170926141720.25067-8-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":"During surprise hot-unplug the device is not there anymore. When that\nhappens we read 0xffffffff from the registers and pciehp_unconfigure_device()\ninadvertently thinks the device is a display device because bridge\ncontrol register returns 0xff refusing to remove it:\n\n  pciehp 0000:00:1c.0:pcie004: Slot(0): Link Down\n  pciehp 0000:00:1c.0:pcie004: Slot(0): Card present\n  pciehp 0000:00:1c.0:pcie004: Cannot remove display device 0000:01:00.0\n\nThis causes the hotplug functionality to leave the hierarcy untouched\npreventing further hotplug operations.\n\nTo fix this verify presence of a device by calling pci_device_is_present()\nfor it before we touch it any further.\n\nSigned-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>\n---\n drivers/pci/hotplug/pciehp_pci.c | 12 +++++++++---\n 1 file changed, 9 insertions(+), 3 deletions(-)","diff":"diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c\nindex b31702f76149..2a3a62393ba9 100644\n--- a/drivers/pci/hotplug/pciehp_pci.c\n+++ b/drivers/pci/hotplug/pciehp_pci.c\n@@ -101,8 +101,14 @@ int pciehp_unconfigure_device(struct slot *p_slot)\n \t */\n \tlist_for_each_entry_safe_reverse(dev, temp, &parent->devices,\n \t\t\t\t\t bus_list) {\n+\t\tbool present;\n+\n \t\tpci_dev_get(dev);\n-\t\tif (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE && presence) {\n+\n+\t\t/* Check if the device is really there anymore */\n+\t\tpresent = presence ? pci_device_is_present(dev) : false;\n+\n+\t\tif (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE && present) {\n \t\t\tpci_read_config_byte(dev, PCI_BRIDGE_CONTROL, &bctl);\n \t\t\tif (bctl & PCI_BRIDGE_CTL_VGA) {\n \t\t\t\tctrl_err(ctrl,\n@@ -113,7 +119,7 @@ int pciehp_unconfigure_device(struct slot *p_slot)\n \t\t\t\tbreak;\n \t\t\t}\n \t\t}\n-\t\tif (!presence) {\n+\t\tif (!present) {\n \t\t\tpci_dev_set_disconnected(dev, NULL);\n \t\t\tif (pci_has_subordinate(dev))\n \t\t\t\tpci_walk_bus(dev->subordinate,\n@@ -124,7 +130,7 @@ int pciehp_unconfigure_device(struct slot *p_slot)\n \t\t * Ensure that no new Requests will be generated from\n \t\t * the device.\n \t\t */\n-\t\tif (presence) {\n+\t\tif (present) {\n \t\t\tpci_read_config_word(dev, PCI_COMMAND, &command);\n \t\t\tcommand &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_SERR);\n \t\t\tcommand |= PCI_COMMAND_INTX_DISABLE;\n","prefixes":["7/7"]}