From patchwork Tue Nov 18 11:31:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 5327821 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 91C5E9F462 for ; Tue, 18 Nov 2014 11:31:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7868B20172 for ; Tue, 18 Nov 2014 11:31:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3FE76200D0 for ; Tue, 18 Nov 2014 11:31:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753460AbaKRLbR (ORCPT ); Tue, 18 Nov 2014 06:31:17 -0500 Received: from down.free-electrons.com ([37.187.137.238]:57270 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753305AbaKRLbR (ORCPT ); Tue, 18 Nov 2014 06:31:17 -0500 Received: by mail.free-electrons.com (Postfix, from userid 106) id 6EF6E73F; Tue, 18 Nov 2014 12:31:24 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost (col31-4-88-188-83-94.fbx.proxad.net [88.188.83.94]) by mail.free-electrons.com (Postfix) with ESMTPSA id 1BF2673A; Tue, 18 Nov 2014 12:31:24 +0100 (CET) From: Thomas Petazzoni To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Kevin Hilman , Jason Cooper , Andrew Lunn , Sebastian Hesselbarth , Gregory Clement , Ezequiel Garcia , Tawfik Bayouk , Nadav Haklai , Lior Amsalem , Myron Stowe , Thomas Petazzoni Subject: [PATCH] PCI: fixup __pci_read_base() after refactoring Date: Tue, 18 Nov 2014 12:31:11 +0100 Message-Id: <1416310271-4423-1-git-send-email-thomas.petazzoni@free-electrons.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <20141118105542.457d7863@free-electrons.com> References: <20141118105542.457d7863@free-electrons.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In commit 7ea945f0bb49 ("PCI: Shrink decoding-disabled window while sizing BARs"), Myron Stowe refactored the code of __pci_read_base() in order to reduce the amount of time spent with decoding disabled. However, contrary to what was said in the commit log, the commit does introduce some functional change: the pci_size() function that used to be called *before* the BAR size check is done is now called *after* the BAR size check is done. This causes some failures on certain platforms (namely ARM Marvell EBU platforms, equipped for example with a PCIe SATA card, or a PCIe USB3 XHCI controller): pci 0000:03:00.0: reg 0x10: can't handle BAR larger than 4GB (size 0xfffffffffff00000) This problem didn't exist before this commit, due to pci_size() being called before doing the PCI BAR size check. Therefore, this commit fixes the problem by restoring the initial order of the operation, by calling pci_size() before doing the PCI BAR size check. Signed-off-by: Thomas Petazzoni Fixes: 7ea945f0bb49 ("PCI: Shrink decoding-disabled window while sizing BARs") Tested-by: Thierry Reding Tested-by: Kevin Hilman Reported-by: Kevin Hilman --- Note: this fix has been tested to work correctly for me, and the PCI messages I get are now identical to the ones I was getting with 3.18-rc5. However, please review my patch carefully, as I must admit I do not fully understand all the implications of the change as well as the code in __pci_read_base(). Applies on top of pci/next Signed-off-by: Thomas Petazzoni --- drivers/pci/probe.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index db16678..6168ca1 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -246,6 +246,14 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, if (!sz64) goto fail; + sz64 = pci_size(l64, sz64, mask64); + + if (!sz64) { + dev_info(&dev->dev, "%sreg 0x%x: invalid BAR (can't size)\n", + FW_BUG, pos); + goto fail; + } + if (res->flags & IORESOURCE_MEM_64) { if ((sizeof(dma_addr_t) < 8 || sizeof(resource_size_t) < 8) && sz64 > 0x100000000ULL) { @@ -268,14 +276,6 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, } } - sz64 = pci_size(l64, sz64, mask64); - - if (!sz64) { - dev_info(&dev->dev, "%sreg 0x%x: invalid BAR (can't size)\n", - FW_BUG, pos); - goto fail; - } - region.start = l64; region.end = l64 + sz64;