From patchwork Wed Feb 26 19:37:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 3728161 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 339609F2F7 for ; Wed, 26 Feb 2014 19:41:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5E7D0201F9 for ; Wed, 26 Feb 2014 19:41:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6CDF620127 for ; Wed, 26 Feb 2014 19:40:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754128AbaBZTiB (ORCPT ); Wed, 26 Feb 2014 14:38:01 -0500 Received: from mail-ie0-f171.google.com ([209.85.223.171]:47674 "EHLO mail-ie0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754146AbaBZTh7 (ORCPT ); Wed, 26 Feb 2014 14:37:59 -0500 Received: by mail-ie0-f171.google.com with SMTP id to1so1123186ieb.30 for ; Wed, 26 Feb 2014 11:37:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:to:from:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; bh=G1YvdGbOupqQIEoy0yMj9kdsrkt/ncngDiaixgB50y0=; b=hmo0GEZREZ5cIcrEu2Nd7CpRbm4+kOXAead5roU0OG+4wrzMgY9G4cjnLoglPJrT8z +QdkbYpUmVtjT0q2tjev79aRKf5YXM5aN1gVr8X/jKQtWYOEi7I3L0OelYjVKGGyycAM AqbTL/YcyirYmRKXRkDS1G4GeDlTjbzTzR2f86gKLEzjkJVXM2sm3si9AuC68ZQaxB91 FXKHGPXDra5l52M8dxZOogrrowf9h+XwNtghMIkC7Zk4tyTnWXT4tAGih1yCOp+H0Q0Y R1f9FYbDqFzIxJNSbjBwJw7wlHL2HYhSb4y3aVOqWV7qsppWt1pDtBwr8JnpCOnk9bgy R4Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:from:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding; bh=G1YvdGbOupqQIEoy0yMj9kdsrkt/ncngDiaixgB50y0=; b=QtnKNXianpliyIAncQtA2Bsp2yUxfWqMGokhBC15lVqfr6SeuVJiKZd9QETYHoUuCk 3botTWxV7++j57vTQji+QNKBHKKSFzZx6VfH4hDU0OWdaPlhQuBEt2+qul7WxzHDFhCS py2ER8W9cGSNbD/n+ijS9LMVRBtlJpGTBkiGjY67IMdv6dFmIPjdxVWWf+JbdHBv1Icd sJEC/2Q6ylWGbjt0U2VEXF2wMSJr/omM2DvAtV69+9O+kAqaVTRjF0MgM+w1PJciMar+ qdMrnumkHZ+2T0/kQrfjKl8Y+Ll1ySh+cPZV/GzhbVNp38T5ZPkXQLYWALsVZp7JKFIy VmCg== X-Gm-Message-State: ALoCoQkkiie00fCji49jyLKHO79Uld5nOPYMzJoPglf8EQFF/UAa1bsI2vPrEVjFCHt9EfUHgr7WCgripFxKKuBZCXJnTTv+CmVofm5J2YlJ/uwpW5qqb54bAZHW+2D+S09GG8Bs7f9faF1uMdt/RVKYMc8ks/pv7fz63l9f4SoPxeFlxy1aOL1SB0LBgchYsiTvVLsUbMeJOM8YSCx5ihsuA0Gu4Qi/3KU9zj2SUeZIEWypdgqMGdM= X-Received: by 10.43.163.2 with SMTP id mm2mr1218469icc.20.1393443479313; Wed, 26 Feb 2014 11:37:59 -0800 (PST) Received: from localhost ([172.16.49.60]) by mx.google.com with ESMTPSA id rj10sm51435071igc.8.2014.02.26.11.37.58 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 26 Feb 2014 11:37:58 -0800 (PST) Subject: [PATCH 8/9] PCI: Ignore BAR contents when firmware left decoding disabled To: linux-pci@vger.kernel.org From: Bjorn Helgaas Cc: linux-kernel@vger.kernel.org Date: Wed, 26 Feb 2014 12:37:57 -0700 Message-ID: <20140226193757.10125.81865.stgit@bhelgaas-glaptop.roam.corp.google.com> In-Reply-To: <20140226192614.10125.68711.stgit@bhelgaas-glaptop.roam.corp.google.com> References: <20140226192614.10125.68711.stgit@bhelgaas-glaptop.roam.corp.google.com> User-Agent: StGit/0.16 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Don't rely on BAR contents when the command register says the BAR is disabled. If we receive a PCI device from firmware (or a hot-added device that was just powered up) with the MEMORY or IO enable bits in the PCI command register cleared, there's no reason to believe the BARs contain valid addresses. In that case, we still know the type and size of the BAR, but this patch marks the resource as "unset" so we have a chance to reassign it. Historically, we often used "BAR == 0" to decide the BAR is invalid. But 0 is a legal BAR value, especially if the host bridge translates addresses, so I think it's better to decide based on the PCI command register, and store the conclusion in the IORESOURCE_UNSET bit. Reference: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=679545 Reference: https://bugzilla.kernel.org/show_bug.cgi?id=48451 Signed-off-by: Bjorn Helgaas --- drivers/pci/probe.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 6e34498ec9f0..02654b5ec1b9 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -177,9 +177,10 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, mask = type ? PCI_ROM_ADDRESS_MASK : ~0; + pci_read_config_word(dev, PCI_COMMAND, &orig_cmd); + /* No printks while decoding is disabled! */ if (!dev->mmio_always_on) { - pci_read_config_word(dev, PCI_COMMAND, &orig_cmd); if (orig_cmd & PCI_COMMAND_DECODE_ENABLE) { pci_write_config_word(dev, PCI_COMMAND, orig_cmd & ~PCI_COMMAND_DECODE_ENABLE); @@ -215,9 +216,13 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, if (res->flags & IORESOURCE_IO) { l &= PCI_BASE_ADDRESS_IO_MASK; mask = PCI_BASE_ADDRESS_IO_MASK & (u32) IO_SPACE_LIMIT; + if (!(orig_cmd & PCI_COMMAND_IO)) + res->flags |= IORESOURCE_UNSET; } else { l &= PCI_BASE_ADDRESS_MEM_MASK; mask = (u32)PCI_BASE_ADDRESS_MEM_MASK; + if (!(orig_cmd & PCI_COMMAND_MEMORY)) + res->flags |= IORESOURCE_UNSET; } } else { res->flags |= (l & IORESOURCE_ROM_ENABLE); @@ -252,6 +257,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, /* Address above 32-bit boundary; disable the BAR */ pci_write_config_dword(dev, pos, 0); pci_write_config_dword(dev, pos + 4, 0); + res->flags |= IORESOURCE_UNSET; region.start = 0; region.end = sz64; bar_disabled = true;