Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3476163imu; Sun, 11 Nov 2018 15:59:40 -0800 (PST) X-Google-Smtp-Source: AJdET5dOcQ7x0Ez+wsWOZ7sGVbp9lDOQ+XTGOQMTiCyHVQdqLmHZdcG82ubXtrrqSExN65bH98ys X-Received: by 2002:a63:f652:: with SMTP id u18-v6mr15706498pgj.267.1541980780391; Sun, 11 Nov 2018 15:59:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980780; cv=none; d=google.com; s=arc-20160816; b=UEB4nTh+iObRr/bCeIlsAbHOuMOS9Zjtn6oQ+ZNyRzkF/pvNgBJbMpvbhdZYOczApz yDA2Wl4yJWpRTavv6ONbRMZK8wr2IWcSBy6zx+cm7PeQh/krF5LPEkHUWPdTvL1ooaQM oxpdW457ohZC3IuGeXpbLQ6mQ13f5Tt2KcLPkaQkJX7LSE34DAwxDR6zQv1LwwcTi/i1 BqaLgtUx6Xt7H1a1YkvDZx2m7+7RseH80Pvu9d6cBZXbduwVvpb+feDjFp9jgJDEpVBp wjZd8XYxAOjZquAdBEbDSCO8FDezG927zxmK0RM27V0MhXPPbrCN1Ij2gDVw9P1coSMp txcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bJ/ByMbsp2Iz8+zaQM79ekDyH/xoCEHQdxjKaL1ZlWY=; b=WIEtJbCGuC4JWmZZBq1Mdj+856zhY2BRe+lBzGQ4gJkZHVczOzehCyTEe1kckZZsgx 12X95Cie2jn42d8IpJ52iDIjqLAhq/SgKn8tE67oFVsGIcwywH1s7FNKeO2Pif6Y7t6H mSPa4E/3RJ0tQyalCZ+1uBUkebeWcClfSlK06GjUGc0OuHw3R37YdS5lC5Gi39IDVVOO 9DpADRkkZozcFTfBkiFuDNHBJLIwMvo83rmD6dpA8La/I4oxXveYtN5XpUmGu4c+rCKI 2y/aQ9i6pUBYChNQ3Jj4LStRWObuKYe0mWIfXu8BEUo+cwHZqU8EZmon3daneTqSae/R /wRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="h2JOnAy/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id az12-v6si15315219plb.166.2018.11.11.15.59.25; Sun, 11 Nov 2018 15:59:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="h2JOnAy/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732724AbeKLJsS (ORCPT + 99 others); Mon, 12 Nov 2018 04:48:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:35336 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732467AbeKLISJ (ORCPT ); Mon, 12 Nov 2018 03:18:09 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7161E208A3; Sun, 11 Nov 2018 22:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975293; bh=n7+d+zR3PAgJsrHyuA0KUI+cQ1PaGtTC/avjnm5Ye7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h2JOnAy/uAVc5VyZfudJTzlbiPK9xT69s548LdhoXeD58bHDub0vpiLY1ag+Q2FNs prvGF8DqhIQgvOz9xtSq4N8kX6OMrU8Jas7kIsc4xQ1xHouJIHD/F+KePUEhdU3Hth 7NCQvhogQFsq+TwB/WbtBDVPmk8sd//czmMIWu1o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Bjorn Helgaas , Shaohua Li Subject: [PATCH 4.19 238/361] PCI/ASPM: Fix link_state teardown on device removal Date: Sun, 11 Nov 2018 14:19:45 -0800 Message-Id: <20181111221652.101627674@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lukas Wunner commit aeae4f3e5c38d47bdaef50446dc0ec857307df68 upstream. Upon removal of the last device on a bus, the link_state of the bridge leading to that bus is sought to be torn down by having pci_stop_dev() call pcie_aspm_exit_link_state(). When ASPM was originally introduced by commit 7d715a6c1ae5 ("PCI: add PCI Express ASPM support"), it determined whether the device being removed is the last one by calling list_empty() on the bridge's subordinate devices list. That didn't work because the device is only removed from the list slightly later in pci_destroy_dev(). Commit 3419c75e15f8 ("PCI: properly clean up ASPM link state on device remove") attempted to fix it by calling list_is_last(), but that's not correct either because it checks whether the device is at the *end* of the list, not whether it's the last one *left* in the list. If the user removes the device which happens to be at the end of the list via sysfs but other devices are preceding the device in the list, the link_state is torn down prematurely. The real fix is to move the invocation of pcie_aspm_exit_link_state() to pci_destroy_dev() and reinstate the call to list_empty(). Remove a duplicate check for dev->bus->self because pcie_aspm_exit_link_state() already contains an identical check. Fixes: 7d715a6c1ae5 ("PCI: add PCI Express ASPM support") Signed-off-by: Lukas Wunner Signed-off-by: Bjorn Helgaas Cc: Shaohua Li Cc: stable@vger.kernel.org # v2.6.26 Signed-off-by: Greg Kroah-Hartman --- drivers/pci/pcie/aspm.c | 2 +- drivers/pci/remove.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -991,7 +991,7 @@ void pcie_aspm_exit_link_state(struct pc * All PCIe functions are in one slot, remove one function will remove * the whole slot, so just wait until we are the last function left. */ - if (!list_is_last(&pdev->bus_list, &parent->subordinate->devices)) + if (!list_empty(&parent->subordinate->devices)) goto out; link = parent->link_state; --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -25,9 +25,6 @@ static void pci_stop_dev(struct pci_dev pci_dev_assign_added(dev, false); } - - if (dev->bus->self) - pcie_aspm_exit_link_state(dev); } static void pci_destroy_dev(struct pci_dev *dev) @@ -41,6 +38,7 @@ static void pci_destroy_dev(struct pci_d list_del(&dev->bus_list); up_write(&pci_bus_sem); + pcie_aspm_exit_link_state(dev); pci_bridge_d3_update(dev); pci_free_resources(dev); put_device(&dev->dev);