Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3427728imu; Sun, 11 Nov 2018 14:52:21 -0800 (PST) X-Google-Smtp-Source: AJdET5czuTvqJf9+MYtBE1Dr6NY5i+mLeqDhkSIfleSgfxeNGdo02FCZkMAZG/f/R7M/an1njWKV X-Received: by 2002:a17:902:3e3:: with SMTP id d90-v6mr17545845pld.118.1541976740987; Sun, 11 Nov 2018 14:52:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541976740; cv=none; d=google.com; s=arc-20160816; b=enWUQJVIZRK4PwdZJJ2/LtkG7IMGneuFVpH7XruW/JR/Jrod9sH2rI6PQsLzoQUNH5 7dO/ZB4WXIutsfXVTHQR4zZQQSiT97uyrRft25kJoYdaLsxv6BGIMJ3QnlwupihC+vjy CAKFKTcom/wRtnLjtVXaANcHhfsU31B2LcKHS4t7IEEV1+P/y6YhYocmGWvfcXtAVnQg Kpny/ZKNXLlWsLVzSi8z1UePyjX8Vrkov+vFAqOd5YKFo3zDpIS5AGkxkZ51xcnNP+7Y G91LuKj1WEB/DO5E35MDhYyLx0+ykqoQWPRoJ6zXeaiHAVGNCbQ2LlwgYIdJ2wQ3xRPF DLKg== 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=WH8j2l2DJUtNS2demjR2s+NBiLuVfh7exmyWdWk3Nvk=; b=xg2lH+D7UEjLzqh2sT3zjVjwOfhSbt2AlFD0yJ35OKwd3T0AkB6XUAigP/lqsvvBJW B8auEJrRJdR6yDHn+vzztQNn95bvQ08CgAxHpkFxNWQRvG66sNtp/CqLJycnianX1VxG NnvfiTNxPW2pVg8YegEVtgD0NKYfIYUHRAiAl314JzwHhhrDzhYd1A/P1NSjZiskrHz2 yT15uAxOB7UFsznDvdT8oQi91KhFZm2Zq5U/eKaEzIUn1S0z6M/E84P4KyjV0egQdPAm Mclpi08cnjsrGbDQOGDmkvzbdt6QHsVZ58itev7IfdOB++bGocB9mb+famyOxNKiNsGq VzAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iMuJqQVx; 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 a5-v6si11303356plh.157.2018.11.11.14.52.06; Sun, 11 Nov 2018 14:52:20 -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=iMuJqQVx; 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 S2404148AbeKLIXF (ORCPT + 99 others); Mon, 12 Nov 2018 03:23:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:54620 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389887AbeKLIXB (ORCPT ); Mon, 12 Nov 2018 03:23:01 -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 B1AA32250E; Sun, 11 Nov 2018 22:33:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975583; bh=/rd+IKbkarMCXF+v81Us0V9+IeEe3k1zRTnvT+49ekw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iMuJqQVxSCL1XYxPSaJ3ZzAH1EWU736d9L8qodbu/HgXwkHHLNTn/T1InplnGrgQr oTLW6IKAcBJow1xbWWYcl7xWIj1oNqOSQtxr6K3v14kSq4uYD0TBbhXJ5yl8s5++Q4 SYqC2EEyh5SRx5jxDcPt9lMYiYXUC7U/XcFO942o= 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.14 146/222] PCI/ASPM: Fix link_state teardown on device removal Date: Sun, 11 Nov 2018 14:24:03 -0800 Message-Id: <20181111221700.497369160@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@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.14-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 @@ -937,7 +937,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 @@ -24,9 +24,6 @@ static void pci_stop_dev(struct pci_dev pci_remove_sysfs_dev_files(dev); dev->is_added = 0; } - - if (dev->bus->self) - pcie_aspm_exit_link_state(dev); } static void pci_destroy_dev(struct pci_dev *dev) @@ -40,6 +37,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);