Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp131060imj; Thu, 14 Feb 2019 17:00:30 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ7gaXMxYtgZohmK0o0msNgYPCS92DwYAM+kcyg6H03/7ntwbF1pEjlJfnP/Bpug54bKEwT X-Received: by 2002:a63:4a21:: with SMTP id x33mr2791124pga.428.1550192430161; Thu, 14 Feb 2019 17:00:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550192430; cv=none; d=google.com; s=arc-20160816; b=zeVIm/drVFOS5MFvSzds/TsZUqC+wWya9Lkq2tLUAvYvMjJ0L+acSd4il3Yh2pt/zU Ffbll9YM8eo5otWqoBX3FWBnQmwNQXFXh7Sgdyh8r3FzBtPKowSLEw5QOwGBy9FZjnen aCaInU11N0A3QSgnMFOJDQyVAVnCJJXtDmT8fGIWTHuiGnvQMiHqyUnby2YD8UwDZ0Ay vrrGB2cf/DRYR03JD7ndjo+4b2hhu7gxv6nyEgxkMEYlAk3gVmcxKG4sikyYPDgph+U3 8wdQt2W7Jb3IHyMo9Uc8/Apvsjk6dTbqt3ogsGvvgzkOMw4oTorY3DvMyZmAjDCg+CmP yNxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:cc:to:from; bh=B8rNqhMgstZR2fG6I2PqjxxqxdNvEk96vKvEtyMUxvQ=; b=bGVY+WaDfupkz4iim/x81o4oJ5ctsh1jxPlQ+YsXJ3syZy6F7rtxlL5BV8KhKXtXXj m/yMlaWG+hMCZFrdgRwy/EifEzmpOc7PLd+AJ7GkF06bNDLYviAQIUduzrla7Kbl9oSS Ou/LAKz1G+hV2GxzY8y1lVYHoeCkPaEWa3rsjzfZPtXxF1LrUcka3FWiUzNUUQobKYbL d00U4Reo0QWhqXdN5gqq23xPS44d+9eibTB9xwOxpSVpn6HR4skvkkRP47+9jmoMTpGH SgxTtizqvd2QtmzUbbcklJ76jhDdX6MhhGt/cXtG7ldGRwJ4EMXlzdGBslJVEnIZYrAN Xkyg== 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 h3si3821667pls.376.2019.02.14.17.00.14; Thu, 14 Feb 2019 17:00:30 -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 S2395437AbfBNRAe (ORCPT + 99 others); Thu, 14 Feb 2019 12:00:34 -0500 Received: from ale.deltatee.com ([207.54.116.67]:36466 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394094AbfBNRAd (ORCPT ); Thu, 14 Feb 2019 12:00:33 -0500 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1guKNC-0004Pe-Uf; Thu, 14 Feb 2019 10:00:33 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.89) (envelope-from ) id 1guKNC-0007G9-Iy; Thu, 14 Feb 2019 10:00:30 -0700 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Bjorn Helgaas Cc: Kit Chow , Logan Gunthorpe , Yinghai Lu Date: Thu, 14 Feb 2019 10:00:28 -0700 Message-Id: <20190214170028.27862-2-logang@deltatee.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20190214170028.27862-1-logang@deltatee.com> References: <20190214170028.27862-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, bhelgaas@google.com, kchow@gigaio.com, logang@deltatee.com, yinghai@kernel.org X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.5 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,MYRULES_FREE,MYRULES_NO_TEXT autolearn=ham autolearn_force=no version=3.4.2 Subject: [PATCH 2/2] PCI: Fix disabling of bridge BARs when assigning bus resources X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org One odd quirk of PLX switches is that their upstream bridge port has 256K of space allocated behind its BAR0 (most other bridge implementations do not report any BAR space). The lspci for such device looks like: 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]) Physical Slot: 1 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 Kernel driver in use: pcieport It's not clear what the purpose of the memory at 0x90a00000 is, and currently the kernel never actually uses it for anything. In most cases, it's safely ignored and does not cause a problem. However, when the kernel assigns the resource addresses (with the pci=realloc command line parameter, for example) it can inadvertently disable the struct resource corresponding to the bar. When this happens, lspci will report this memory 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. In many cases, this still isn't a problem. Nothing uses the memory, so nothing is affected. However, a big problem shows up when an IOMMU is in use: the IOMMU 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, we have a situation where a DMA mapping may occasionally allocate an IOVA which the PCI bus will actually route to a BAR in the PLX switch. This will result in some random DMA writes not actually writing to the RAM they are supposed to, or random DMA reads returning all FFs from the PLX BAR when it's supposed to have read from RAM. The problem is caused in pci_assign_unassigned_root_bus_resources(). When any resource from a bridge device fails to get assigned, the code sets the resource's flags to zero. This makes sense for bridge resources, as they will be re-enabled later, but for regular BARs, it disables them permanently. To fix the problem, we only set the flags to zero for bridge resources and treat any other resources like non-bridge devices. Reported-by: Kit Chow Fixes: da7822e5ad71 ("PCI: update bridge resources to get more big ranges when allocating space (again)") Signed-off-by: Logan Gunthorpe Cc: Bjorn Helgaas Cc: Yinghai Lu --- drivers/pci/setup-bus.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 56b7077f37ff..3695edd9c256 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1821,11 +1821,16 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus) /* 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) + + idx = res - &fail_res->dev->resource[0]; + if (fail_res->dev->subordinate && + idx >= PCI_BRIDGE_RESOURCES && + idx <= PCI_BRIDGE_RESOURCE_END) res->flags = 0; } free_list(&fail_head); -- 2.19.0