From patchwork Wed Apr 30 00:59:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 4089961 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 05A229F39D for ; Wed, 30 Apr 2014 00:59:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3B60F2021B for ; Wed, 30 Apr 2014 00:59:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9B52520218 for ; Wed, 30 Apr 2014 00:59:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753857AbaD3A7u (ORCPT ); Tue, 29 Apr 2014 20:59:50 -0400 Received: from mail-ie0-f181.google.com ([209.85.223.181]:52934 "EHLO mail-ie0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752836AbaD3A7r (ORCPT ); Tue, 29 Apr 2014 20:59:47 -0400 Received: by mail-ie0-f181.google.com with SMTP id y20so1062816ier.26 for ; Tue, 29 Apr 2014 17:59:46 -0700 (PDT) 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=P78r9pv3FNCB4hLz4uzqfXg2NDFrpw6XOLqKL4lHafE=; b=bHPveSPuA9KcrisVuJx6lawTonmIE0hSIyiIQ5o446cjqlk2ES01DVJxqFITtP4fOy L0YxCkZTnLY9aDo8uj2K9P7QUlZTjuFuefag9fFb7ezDqZH84oiD/adWJ/JgNm7OOr5O LAh/NUWZVgN5wT4lNK7ywOn5KEytZsN4tJK1HeOfi9jY3pW0TuFPX+BFemwilTL8lGAZ JK6UF/8LRC/ZdyVSu7WJvWkhv2DEd8Q6fLz/gvUEuZcfDvPsnQo/YjkbN3kCxKm81+Qv XVKiqvGHnbTENO+qRUM/47TnxhJozB3q1Wh69SFNVUXb+PvqVOCzfJ+nGAusFs8cFbxD 3xAA== 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=P78r9pv3FNCB4hLz4uzqfXg2NDFrpw6XOLqKL4lHafE=; b=jNTMIX1LWnESKCqwY8HkrPLM5rsH4lXwtmT0uTrd3Ut4nk8n/re5PkfFD2dRX5klA4 VQc2YFUS1J3WtC4wu+1ejYNozUm3W1SNueRqa5dpsALbCBg/3AtNo8y/co2GH1AnkR2M 17Psgwb5g03EQ1JEQtgqzdAIhxW1aeZSu9X3KcDlWELzaS7ZLYBGp9g8UQLc0GfYassX 4WC/t268V2+9epsW8oc+oayIGsmfQmka9CFCXrpnWj6RAWr9qMHNTQbvySnofxvmtuRK K1+RYM8AA5+CSWK/t3vEu3LJOpWwI1z7tKEz6eFkfiXVWO/zUz3wnNavfH0EP+xXbKql RrPg== X-Gm-Message-State: ALoCoQkNradKPTwonU9Z/YuGxAqOuVjr03p05+EO//a0v/uGv2acb6EyqCGNkPc6MvHVN9TSL+JCJ0NRgsvUlvESB40yhMKAlGNTqXtivSXXdYT6MI3ViJuTpKJG0tPQjd5eFe0kYALuZFwx2+Wa6WDobXXHc2xB5c5V9M82/icY0FdYPUJ73pdQGzrjptPKOY3dhfFYp/uXjAMiEJmnN8jCjtO3EDuhaT17WnJxBaTgcMxtFhSJPoE= X-Received: by 10.50.138.72 with SMTP id qo8mr1292131igb.26.1398819586760; Tue, 29 Apr 2014 17:59:46 -0700 (PDT) Received: from localhost ([172.16.51.53]) by mx.google.com with ESMTPSA id kr5sm58718igb.9.2014.04.29.17.59.46 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 29 Apr 2014 17:59:46 -0700 (PDT) Subject: [PATCH 1/7] PCI: Fail safely if we can't handle BARs larger than 4GB To: linux-pci@vger.kernel.org From: Bjorn Helgaas Cc: linux-kernel@vger.kernel.org Date: Tue, 29 Apr 2014 18:59:45 -0600 Message-ID: <20140430005944.13138.29465.stgit@bhelgaas-glaptop.roam.corp.google.com> In-Reply-To: <20140430005642.13138.99577.stgit@bhelgaas-glaptop.roam.corp.google.com> References: <20140430005642.13138.99577.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=-7.4 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 We can only handle BARs larger than 4GB if both dma_addr_t and resource_size_t are 64 bits wide. If dma_addr_t is 32 bits, we can't represent all the bus addresses, and if resource_size_t is 32 bits, we can't represent all the CPU addresses. Previously we cleared res->flags (at "fail:") for resources that were too large. That means we think the BAR doesn't exist at all, which in turn means that we could enable the device even though we can't keep track of where the BAR is and we can't make sure it doesn't overlap something else. This preserves the type flags (MEM/IO) so we can keep from enabling the device. Signed-off-by: Bjorn Helgaas --- drivers/pci/probe.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) -- 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 ef09f5f2fe6c..c7f8b717c2e7 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -171,6 +171,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, struct resource *res, unsigned int pos) { u32 l, sz, mask; + u64 l64, sz64, mask64; u16 orig_cmd; struct pci_bus_region region, inverted_region; bool bar_too_big = false, bar_disabled = false; @@ -226,9 +227,9 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, } if (res->flags & IORESOURCE_MEM_64) { - u64 l64 = l; - u64 sz64 = sz; - u64 mask64 = mask | (u64)~0 << 32; + l64 = l; + sz64 = sz; + mask64 = mask | (u64)~0 << 32; pci_read_config_dword(dev, pos + 4, &l); pci_write_config_dword(dev, pos + 4, ~0); @@ -243,9 +244,13 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, if (!sz64) goto fail; - if ((sizeof(resource_size_t) < 8) && (sz64 > 0x100000000ULL)) { + if ((sizeof(dma_addr_t) < 8 || sizeof(resource_size_t) < 8) && + sz64 > 0x100000000ULL) { + res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED; + res->start = 0; + res->end = 0; bar_too_big = true; - goto fail; + goto out; } if ((sizeof(resource_size_t) < 8) && l) { @@ -303,7 +308,8 @@ out: pci_write_config_word(dev, PCI_COMMAND, orig_cmd); if (bar_too_big) - dev_err(&dev->dev, "reg 0x%x: can't handle 64-bit BAR\n", pos); + dev_err(&dev->dev, "reg 0x%x: can't handle BAR larger than 4GB (size %#010llx)\n", + pos, (unsigned long long) sz64); if (res->flags && !bar_disabled) dev_printk(KERN_DEBUG, &dev->dev, "reg 0x%x: %pR\n", pos, res);