From: Bjorn Helgaas <bhelgaas@google.com>
To: Ming Lei <tom.leiming@gmail.com>
Cc: "linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Rusty Russell <rusty@rustcorp.com.au>
Subject: Re: [PATCH 8/9] PCI: Ignore BAR contents when firmware left decoding disabled
Date: Mon, 17 Mar 2014 18:27:00 -0600 [thread overview]
Message-ID: <20140318002700.GA22356@google.com> (raw)
In-Reply-To: <CACVXFVMz+6DaSgT0EHeVfyBOsXfWDYnZQ0wy7pwcey5ahM6rUA@mail.gmail.com>
On Fri, Mar 14, 2014 at 09:48:35AM +0800, Ming Lei wrote:
> On Fri, Mar 14, 2014 at 12:08 AM, Bjorn Helgaas <bhelgaas@google.com> wrote:
> > On Thu, Mar 13, 2014 at 2:51 AM, Ming Lei <tom.leiming@gmail.com> wrote:
> >> Hi Bjorn,
> >>
> >> I found this patch broke virtio-pci devices.
> >
> > Thanks a lot for testing this.
> >
> >> On Thu, Feb 27, 2014 at 3:37 AM, Bjorn Helgaas <bhelgaas@google.com> wrote:
> >>> 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.
> >>
> >> From PCI LOCAL BUS SPECIFICATION, REV. 3.0, both
> >> PCI_COMMAND_IO and PCI_COMMAND_MEM should be
> >> cleared after reset, so looks the patch sets IORESOURCE_UNSET
> >> too early because PCI drivers may call pci_enable_device()
> >> (->pci_enable_resources()) to enable the two bits of
> >> PCI_COMMAND explicitly.
> >
> > The point is that it's not safe to enable those two bits unless we're
> > certain that the BARs they control contain valid values that don't
> > conflict with anything else in the system.
> >
> > Maybe we should only set IORESOURCE_UNSET when we find a conflict or a
> > BAR that's not contained by an upstream bridge window, and we should
> > try to reallocate then. I'm pretty sure we do that at least in some
> > cases, but it would probably simplify things if we did it more
> > consistently, and maybe we shouldn't set it at all here in
> > __pci_read_base().
>
> I think so because __pci_read_base() is called in device emulation
> path.
Which path is this? I don't know anything about virtio-pci, and I only see
calls to __pci_read_base() from:
sriov_init()
pci_sriov_resource_alignment()
pci_read_bases()
> > But I'd like to understand your situation better, so can you provide
> > more details, please? Complete before/after dmesg logs would go a
> > long way toward illustrating the problem you're seeing.
>
> Please see the two attachment log. The memory allocation failure
> is caused by mistaken value read from pci address after the device
> is failed to enable.
Your logs are harder than necessary to compare because one has a lot more
debug turned on than the other.
In the failing case, we ignore all the initial BAR values, but we do assign
values to all of them later:
pci 0000:00:00.0: can't claim BAR 0 [mem size 0x00000400]: no address assigned
pci 0000:00:00.0: can't claim BAR 1 [io size 0x0400]: no address assigned
...
pci 0000:00:00.0: BAR 0: assigned [mem 0x40000000-0x400003ff]
pci 0000:00:00.0: BAR 1: assigned [io 0x1000-0x13ff]
...
The newly-assigned values look valid, and as far as I can tell, they should
work. Do you know why they don't? Is there an assumption somewhere that
we never change BAR values?
Even if we don't need to ignore BAR values in as many cases as we do, it
should be legal to ignore them and reassign them, so I want to understand
what's going on here before reverting this.
Is there an easy way I can reproduce the problem on my own box?
Bjorn
next prev parent reply other threads:[~2014-03-18 0:27 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-26 19:37 [PATCH 0/9] PCI: Use IORESOURCE_UNSET for unassigned BARs Bjorn Helgaas
2014-02-26 19:37 ` [PATCH 1/9] resource: Add resource_contains() Bjorn Helgaas
2014-02-26 19:37 ` [PATCH 2/9] vsprintf: Add support for IORESOURCE_UNSET in %pR Bjorn Helgaas
2014-02-26 19:37 ` [PATCH 3/9] PCI: Remove pci_find_parent_resource() use for allocation Bjorn Helgaas
2014-02-26 19:37 ` [PATCH 4/9] PCI: Mark resources as IORESOURCE_UNSET if we can't assign them Bjorn Helgaas
2014-02-26 19:37 ` [PATCH 5/9] PCI: Don't clear IORESOURCE_UNSET when updating BAR Bjorn Helgaas
2014-02-26 19:37 ` [PATCH 6/9] PCI: Check IORESOURCE_UNSET before " Bjorn Helgaas
2014-02-26 19:37 ` [PATCH 7/9] PCI: Don't try to claim IORESOURCE_UNSET resources Bjorn Helgaas
2014-02-26 19:37 ` [PATCH 8/9] PCI: Ignore BAR contents when firmware left decoding disabled Bjorn Helgaas
2014-03-13 8:51 ` Ming Lei
2014-03-13 16:08 ` Bjorn Helgaas
2014-03-14 1:48 ` Ming Lei
2014-03-18 0:27 ` Bjorn Helgaas [this message]
2014-03-19 3:32 ` Ming Lei
2014-03-19 4:52 ` Ming Lei
2014-03-19 16:45 ` Bjorn Helgaas
2014-03-20 1:32 ` Ming Lei
2014-03-21 20:07 ` Bjorn Helgaas
2014-03-21 20:25 ` Sasha Levin
2014-03-21 20:40 ` Bjorn Helgaas
2014-03-19 18:54 ` Bjorn Helgaas
2014-03-19 21:16 ` Bjorn Helgaas
2014-03-19 21:23 ` Sasha Levin
2014-02-26 19:38 ` [PATCH 9/9] PCI: Don't enable decoding if BAR hasn't been assigned an address Bjorn Helgaas
2014-03-04 20:53 ` [PATCH 0/9] PCI: Use IORESOURCE_UNSET for unassigned BARs 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=20140318002700.GA22356@google.com \
--to=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=tom.leiming@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.