Received: by 10.223.185.111 with SMTP id b44csp909113wrg; Fri, 9 Mar 2018 16:35:52 -0800 (PST) X-Google-Smtp-Source: AG47ELumCuJEvCy1PgT+loaADicQdkG817RxPgD9HEggQTZ7i1iTKjSG9sy+7g0AAAsnwhAw/4zi X-Received: by 10.99.151.74 with SMTP id d10mr302959pgo.350.1520642152558; Fri, 09 Mar 2018 16:35:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520642152; cv=none; d=google.com; s=arc-20160816; b=rBKYqH9cMCXhBW8sj872rXypMeX0TcyCmJ/vV0hSFLEDLYQY6UpWjTccWLPJejHt4M vq/OSlGTdfH2AkgzlqshWaxPYSQPL9FSBu3bJ2SLOLPxbj9KBgGbTQ5ma/p43DcGsYp6 7geZyk/UH1omoS1NhWfrCfCx9bFqQAz7a6qLXjI8/Ub/49xVhusgAHCJdLBdBCGs6+zk /7zdclfJ1RTCcDQcj1A3F2GFajiVVj4tU7X96iySSAylq8nJNw8PZI051Ib4qAyDMjmQ 2XNULaZs+3za20pJAjledZlD1S7K2Psrr5H0Rzizm80mLsCuSnD7U2gFic1KObiO4wvQ CwuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=cO3wMsrQzYabcGoct5HPdQUB6aDasaCGsYYVsECeYD0=; b=tP1JgVhWNJhHp6juT01vZaA03pr84MPHdYVaDE5+zUJ9KVtifB4XT+bNjMABAOdU/m bYIgKMe0LjcNMbnvMKybjhlIva68ca+Eey0VhfSiSEOa8MI95P1nqeiVXL7JdhaJKfqP RmSjLbtKzzA867u5ZjgEVsCiyxv/NG6wcD6qhGKCuMnz8eRy+HgB/n91comVoMtEwxJL YzP1l+UZaqYt7WrdcHcjb3zMC3nHUlqvrgok0zzvpSbXVUa8V54EyLQLDfsdWTja3esX RDOr8LXKi9jcaycKrqQRPnuBYABKMYrwBmscuIUpJo1TLdJJzggRvIMjDj97aBuZBKBI mr/Q== ARC-Authentication-Results: i=1; mx.google.com; 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 o1-v6si1741714pld.546.2018.03.09.16.35.38; Fri, 09 Mar 2018 16:35:52 -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; 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 S933843AbeCJAWL (ORCPT + 99 others); Fri, 9 Mar 2018 19:22:11 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:39874 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933511AbeCJAWH (ORCPT ); Fri, 9 Mar 2018 19:22:07 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BDC241172; Sat, 10 Mar 2018 00:22:06 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ard Biesheuvel , Bjorn Helgaas Subject: [PATCH 4.9 24/65] PCI/ASPM: Deal with missing root ports in link state handling Date: Fri, 9 Mar 2018 16:18:24 -0800 Message-Id: <20180310001826.826066317@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001824.927996722@linuxfoundation.org> References: <20180310001824.927996722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ard Biesheuvel commit ee8bdfb6568d86bb93f55f8d99c4c643e77304ee upstream. Even though it is unconventional, some PCIe host implementations omit the root ports entirely, and simply consist of a host bridge (which is not modeled as a device in the PCI hierarchy) and a link. When the downstream device is an endpoint, our current code does not seem to mind this unusual configuration. However, when PCIe switches are involved, the ASPM code assumes that any downstream switch port has a parent, and blindly dereferences the bus->parent->self field of the pci_dev struct to chain the downstream link state to the link state of the root port. Given that the root port is missing, the link is not modeled at all, and nor is the link state, and attempting to access it results in a NULL pointer dereference and a crash. Avoid this by allowing the link state chain to terminate at the downstream port if no root port exists. Signed-off-by: Ard Biesheuvel Signed-off-by: Bjorn Helgaas Signed-off-by: Greg Kroah-Hartman --- drivers/pci/pcie/aspm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -526,10 +526,14 @@ static struct pcie_link_state *alloc_pci /* * Root Ports and PCI/PCI-X to PCIe Bridges are roots of PCIe - * hierarchies. + * hierarchies. Note that some PCIe host implementations omit + * the root ports entirely, in which case a downstream port on + * a switch may become the root of the link state chain for all + * its subordinate endpoints. */ if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT || - pci_pcie_type(pdev) == PCI_EXP_TYPE_PCIE_BRIDGE) { + pci_pcie_type(pdev) == PCI_EXP_TYPE_PCIE_BRIDGE || + !pdev->bus->parent->self) { link->root = link; } else { struct pcie_link_state *parent;