From: Bjorn Helgaas <bhelgaas@google.com>
To: Yinghai Lu <yinghai@kernel.org>
Cc: "Thomas Petazzoni" <thomas.petazzoni@free-electrons.com>,
"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
"Myron Stowe" <myron.stowe@redhat.com>,
"Kevin Hilman" <khilman@kernel.org>,
"Jason Cooper" <jason@lakedaemon.net>,
"Andrew Lunn" <andrew@lunn.ch>,
"Sebastian Hesselbarth" <sebastian.hesselbarth@gmail.com>,
"Gregory Clément" <gregory.clement@free-electrons.com>,
"Ezequiel Garcia" <ezequiel.garcia@free-electrons.com>
Subject: Re: Regression caused by "PCI: Shrink decoding-disabled window while sizing BARs"
Date: Wed, 19 Nov 2014 14:22:29 -0700 [thread overview]
Message-ID: <20141119212229.GD23467@google.com> (raw)
In-Reply-To: <CAE9FiQXo3ctdFk2Z+duaq1wxSAVCA0tG5_f85-UaLk8+Dafhvg@mail.gmail.com>
On Tue, Nov 18, 2014 at 02:36:17PM -0800, Yinghai Lu wrote:
> On Tue, Nov 18, 2014 at 1:00 PM, Thomas Petazzoni
> <thomas.petazzoni@free-electrons.com> wrote:
> > Is a u64 cast really the appropriate solution here? Have you seen my
> > proposed fix "[PATCH] PCI: fix probe.c warning
> > on !CONFIG_ARCH_DMA_ADDR_T_64BIT platforms" ?
>
> Yes, that I saw your patch.
>
> We want to make that to be consistent with __pci_read_bases()
> and avoid MACRO.
>
> I think the warning is wrong. aka compile should omit out that branch.
> as sizeof(dma_addr_t) on !CONFIG_ARCH_DMA_ADDR_T_64BIT
> is 4 and it is smaller than 8. and those are const, so the compiler should
> not ...
>
> add the cast just shut off the compiler wrong warning.
>
> code segment:
>
> if (sizeof(dma_addr_t) < 8) {
> if (mem_base_hi || mem_limit_hi) {
> dev_err(&dev->dev, "can't
> handle 64-bit address space for bridge\n");
> return;
> }
> } else {
> base |= (dma_addr_t)(((u64)mem_base_hi)<<32);
> limit |= (dma_addr_t)(((u64)mem_limit_hi)<<32);
> }
>
>
I propose the following third alternative, which always computes full
64-bit base/limit, then casts them to the dma_addr_t size and compares to
see if anything got chopped off.
This is on top of pci/for-linus. Whatever we settle on, I'll fold it into
the original patch before asking Linus to pull it.
Bjorn
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 1c5b1ca53bcd..c8ca98c2b480 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -407,6 +407,7 @@ static void pci_read_bridge_mmio_pref(struct pci_bus *child)
{
struct pci_dev *dev = child->self;
u16 mem_base_lo, mem_limit_lo;
+ u64 base64, limit64;
dma_addr_t base, limit;
struct pci_bus_region region;
struct resource *res;
@@ -414,8 +415,8 @@ static void pci_read_bridge_mmio_pref(struct pci_bus *child)
res = child->resource[2];
pci_read_config_word(dev, PCI_PREF_MEMORY_BASE, &mem_base_lo);
pci_read_config_word(dev, PCI_PREF_MEMORY_LIMIT, &mem_limit_lo);
- base = ((dma_addr_t) mem_base_lo & PCI_PREF_RANGE_MASK) << 16;
- limit = ((dma_addr_t) mem_limit_lo & PCI_PREF_RANGE_MASK) << 16;
+ base64 = (mem_base_lo & PCI_PREF_RANGE_MASK) << 16;
+ limit64 = (mem_limit_lo & PCI_PREF_RANGE_MASK) << 16;
if ((mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64) {
u32 mem_base_hi, mem_limit_hi;
@@ -429,17 +430,20 @@ static void pci_read_bridge_mmio_pref(struct pci_bus *child)
* this, just assume they are not being used.
*/
if (mem_base_hi <= mem_limit_hi) {
- if (sizeof(dma_addr_t) < 8) {
- if (mem_base_hi || mem_limit_hi) {
- dev_err(&dev->dev, "can't handle 64-bit address space for bridge\n");
- return;
- }
- } else {
- base |= ((dma_addr_t) mem_base_hi) << 32;
- limit |= ((dma_addr_t) mem_limit_hi) << 32;
- }
+ base64 |= (u64) mem_base_hi << 32;
+ limit64 |= (u64) mem_limit_hi << 32;
}
}
+
+ base = (dma_addr_t) base64;
+ limit = (dma_addr_t) limit64;
+
+ if (base != base64) {
+ dev_err(&dev->dev, "can't handle bridge window above 4GB (bus address %#010llx)\n",
+ (unsigned long long) base64);
+ return;
+ }
+
if (base <= limit) {
res->flags = (mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) |
IORESOURCE_MEM | IORESOURCE_PREFETCH;
next prev parent reply other threads:[~2014-11-19 21:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-18 9:55 Regression caused by "PCI: Shrink decoding-disabled window while sizing BARs" Thomas Petazzoni
2014-11-18 9:58 ` Thomas Petazzoni
2014-11-18 11:34 ` Thomas Petazzoni
2014-11-18 14:27 ` Bjorn Helgaas
2014-11-18 14:45 ` [PATCH] PCI: fix probe.c warning on !CONFIG_ARCH_DMA_ADDR_T_64BIT platforms Thomas Petazzoni
2014-11-18 18:18 ` Regression caused by "PCI: Shrink decoding-disabled window while sizing BARs" Yinghai Lu
2014-11-18 21:00 ` Thomas Petazzoni
2014-11-18 22:36 ` Yinghai Lu
2014-11-19 21:22 ` Bjorn Helgaas [this message]
2014-11-19 23:31 ` Yinghai Lu
2014-11-18 11:31 ` [PATCH] PCI: fixup __pci_read_base() after refactoring Thomas Petazzoni
2014-11-18 16:31 ` Thierry Reding
2014-11-18 17:37 ` Kevin Hilman
2014-11-19 22:14 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141119212229.GD23467@google.com \
--to=bhelgaas@google.com \
--cc=andrew@lunn.ch \
--cc=ezequiel.garcia@free-electrons.com \
--cc=gregory.clement@free-electrons.com \
--cc=jason@lakedaemon.net \
--cc=khilman@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=myron.stowe@redhat.com \
--cc=sebastian.hesselbarth@gmail.com \
--cc=thomas.petazzoni@free-electrons.com \
--cc=yinghai@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).