Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1206350ybf; Thu, 27 Feb 2020 06:48:33 -0800 (PST) X-Google-Smtp-Source: APXvYqznWF/Ewj3zZpZ0riu99fNO3yRTFciOwNydQ+Da0tNUWeDsjKkzFb79WDw84H86wjF1nfCg X-Received: by 2002:a9d:63c6:: with SMTP id e6mr3500686otl.365.1582814913150; Thu, 27 Feb 2020 06:48:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582814913; cv=none; d=google.com; s=arc-20160816; b=npnZgCLeHYcR0p35y57tM8eon9e+ZrA76j6q9Fz9++2fkq4GLoBamJHNX4cbBbFdU5 nL/SrVR/o0wSKpFUWNyYXkPrt0PXqT1bF9n87E6xr4ZC2rQk/EmC0O3mnqphmdgpBNTO r0/WWFoIXFLwZ+yeKIkDjmeaC6bA8NqyRG4+H+dYllekanv44L9AV4sThcEtHoWHEcnR azFX/nRY/DIuJtnPMxsPDh1cLPiY3e8rXU5MIOBDHnrVlcSVS1IiMTbpovChoRov2Nbo /eJuBiAwmbcGAz4blj68CI5IOcZkUi/BpKZgw5klmbMaMkpKYlyZ63vI9u+qFUm+1oer anFg== 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=pgwmReS/TDRlvYH5cYvxrSkAFbNPh3AYgTC3vwRZHhA=; b=qtaZsZBGtsuRSAQqNlhO0+deIfnKRuLbCbs57IDVIGgINuGU1luUs61sF2VRtVzbCj TyxQml9eD3svG/GB0h7fm1sVIO79LOkePg/Y+Hrm7qZVMMzYaeYUsK1Ci3YjW8DXH3kt 65a9jBV9s4DiHk2sVSDPmkYQDoEiQng/ODv6ZcJH3DGfc7NxxJNgkL4koVRMEW8EsIEU 9QeBS4foo8WX8JbtvF3KFcEFyCEy3o5aZ+BRlWotYm6LlL5yOlJNvy6wLnJo2rdQoyO+ Mavqk4iomvyGRY5+UT0JG4Tnzhu+t9O7HbrLwBgqCD28z1FNYHwyd2X38fYmhN+wHCUt LkHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ypLKyzXN; 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 j17si1711093otl.278.2020.02.27.06.48.20; Thu, 27 Feb 2020 06:48:33 -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=ypLKyzXN; 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 S1730150AbgB0NoI (ORCPT + 99 others); Thu, 27 Feb 2020 08:44:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:39508 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730139AbgB0NoH (ORCPT ); Thu, 27 Feb 2020 08:44:07 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 B516120578; Thu, 27 Feb 2020 13:44:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582811045; bh=VbA5W/1MQw39uQmgUFgE7TT+W50DNHyHc3w7JLP4rPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ypLKyzXNwgSCRa9rHkRsGPvdOfK7fwFDAiNSLvsGaVGrRcbBPGIFOL0L13TrUkLoA a8wLJnfLlzmjWHitOsqMHkgla6t/5SrT2zskA5mzdo0sVTCVI+SYPn+evxTaqi0bLF Nxgo83QIqGaFks3czV2LZqEYV7nCzbv6+Uqu/STE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kit Chow , Logan Gunthorpe , Bjorn Helgaas , Sasha Levin Subject: [PATCH 4.4 058/113] PCI: Dont disable bridge BARs when assigning bus resources Date: Thu, 27 Feb 2020 14:36:14 +0100 Message-Id: <20200227132221.014026556@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132211.791484803@linuxfoundation.org> References: <20200227132211.791484803@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Logan Gunthorpe [ Upstream commit 9db8dc6d0785225c42a37be7b44d1b07b31b8957 ] Some PCI bridges implement BARs in addition to bridge windows. For example, here's a PLX switch: 04:00.0 PCI bridge: PLX Technology, Inc. PEX 8724 24-Lane, 6-Port PCI Express Gen 3 (8 GT/s) Switch, 19 x 19mm FCBGA (rev ca) (prog-if 00 [Normal decode]) Flags: bus master, fast devsel, latency 0, IRQ 30, NUMA node 0 Memory at 90a00000 (32-bit, non-prefetchable) [size=256K] Bus: primary=04, secondary=05, subordinate=0a, sec-latency=0 I/O behind bridge: 00002000-00003fff Memory behind bridge: 90000000-909fffff Prefetchable memory behind bridge: 0000380000800000-0000380000bfffff Previously, when the kernel assigned resource addresses (with the pci=realloc command line parameter, for example) it could clear the struct resource corresponding to the BAR. When this happened, lspci would report this BAR as "ignored": Region 0: Memory at (32-bit, non-prefetchable) [size=256K] This is because the kernel reports a zero start address and zero flags in the corresponding sysfs resource file and in /proc/bus/pci/devices. Investigation with 'lspci -x', however, shows the BIOS-assigned address will still be programmed in the device's BAR registers. It's clearly a bug that the kernel lost track of the BAR value, but in most cases, this still won't result in a visible issue because nothing uses the memory, so nothing is affected. However, when an IOMMU is in use, it will not reserve this space in the IOVA because the kernel no longer thinks the range is valid. (See dmar_init_reserved_ranges() for the Intel implementation of this.) Without the proper reserved range, a DMA mapping may allocate an IOVA that matches a bridge BAR, which results in DMA accesses going to the BAR instead of the intended RAM. The problem was in pci_assign_unassigned_root_bus_resources(). When any resource from a bridge device fails to get assigned, the code set the resource's flags to zero. This makes sense for bridge windows, as they will be re-enabled later, but for regular BARs, it makes the kernel permanently lose track of the fact that they decode address space. Change pci_assign_unassigned_root_bus_resources() and pci_assign_unassigned_bridge_resources() so they only clear "res->flags" for bridge *windows*, not bridge BARs. Fixes: da7822e5ad71 ("PCI: update bridge resources to get more big ranges when allocating space (again)") Link: https://lore.kernel.org/r/20200108213208.4612-1-logang@deltatee.com [bhelgaas: commit log, check for pci_is_bridge()] Reported-by: Kit Chow Signed-off-by: Logan Gunthorpe Signed-off-by: Bjorn Helgaas Signed-off-by: Sasha Levin --- drivers/pci/setup-bus.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 1723ac1b30e10..fe2865a0da395 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1760,12 +1760,18 @@ again: /* restore size and flags */ list_for_each_entry(fail_res, &fail_head, list) { struct resource *res = fail_res->res; + int idx; res->start = fail_res->start; res->end = fail_res->end; res->flags = fail_res->flags; - if (fail_res->dev->subordinate) - res->flags = 0; + + if (pci_is_bridge(fail_res->dev)) { + idx = res - &fail_res->dev->resource[0]; + if (idx >= PCI_BRIDGE_RESOURCES && + idx <= PCI_BRIDGE_RESOURCE_END) + res->flags = 0; + } } free_list(&fail_head); @@ -1826,12 +1832,18 @@ again: /* restore size and flags */ list_for_each_entry(fail_res, &fail_head, list) { struct resource *res = fail_res->res; + int idx; res->start = fail_res->start; res->end = fail_res->end; res->flags = fail_res->flags; - if (fail_res->dev->subordinate) - res->flags = 0; + + if (pci_is_bridge(fail_res->dev)) { + idx = res - &fail_res->dev->resource[0]; + if (idx >= PCI_BRIDGE_RESOURCES && + idx <= PCI_BRIDGE_RESOURCE_END) + res->flags = 0; + } } free_list(&fail_head); -- 2.20.1