diff mbox

[Regression] PCI resources allocation problem on HP nx6325

Message ID 20090802171550.GC3711@parisc-linux.org (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Matthew Wilcox Aug. 2, 2009, 5:15 p.m. UTC
On Sun, Aug 02, 2009 at 09:39:58AM -0700, Linus Torvalds wrote:
> Ooh, interesting. I thought that patch was a functionally equivalent 
> cleanup of
> 
> 	pr = pci_find_parent_resource(dev, r);
> 	if (!pr || request_resource(pr, r) < 0) {
> 
> to
> 
> 	if (pci_claim_resource(dev, idx) < 0) {
> 
> but yeah, it's not exactly the same. pci_claim_resource() uses 
> 'insert_resource()' rather than 'request_resource()'.

Yeah, I thought it was going to be the same too.  One way in which it
will differ is if the BIOS has assigned two resources which conflict in
such a way that they will nest if we call insert_resource twice.  I guess
if we fail the allocation, it will get reallocated by the driver later.

> We could certainly revert the commit, but I also wonder whether we should 
> just change 'pci_claim_resource()' to use request_resource() instead.
> 
> I _think_ the use of "insert_resource()" is purely historical, and is 
> because that broken function _used_ to not look up the parent, but instead 
> do that crazy "pcibios_select_root()" thing, and then it really does need 
> to recurse down and "insert" the resource in the right place.
> 
> We should no longer _need_ to do the "insert_resource()" thing, since we 
> are inserting it into the exact parent that we want (as of commit 
> cebd78a8c: "Fix pci_claim_resource").
> 
> And if that "insert_resource()" in pci_claim_resource() ever does anything 
> fancier than the raw "request_resource()", then that's a problem anyway.
> 
> Willy, comments? x86 historically has never used pci_claim_resource() at 
> all (it always open-coded the above) except for some quirk handling. So 
> I'm pretty sure that a patch like the below should be safe and correct. 
> But it's parisc machines that always seem to break.

Oh, parisc won't break on this.  This is a part of the PCI resource
allocation; the parisc problem comes further up in the hierarchy while
we're still dealing with parisc devices.  Something like this:

f0800000 - f08fffff Bus 8
  f0800000 - f08fffff Bus 8/2
    f0800000 - f08fffff PCI Root 8/2/0
      f0800000 - f080ffff PCI Device 0000:0a:1.0

So once we find the PCI Root in pci_claim_resource (and we will), we
don't have to worry about using insert_resource vs request_resource.

Now, I do worry about there being resources requested by some other bit of
code (say ACPI or PNP or something) which will cause failures, when what
should happen is that it should be reparented to the new PCI resource.
But since x86 has never done this, it shouldn't be a problem on x86.
Will it be a problem on any other architecture?  No idea.  But it won't
be a problem on parisc -- all the PCI devices are subordinate to or
disjoint from parisc resources.

> Added Andrew Patterson to the Cc, because his report was what caused us to 
> originally look at pci_claim_resource() and make it use 
> "pci_find_parent_resource()". We just never went whole hog, and we left 
> that broken "insert_resource()" around.
> 
> So Rafael and AndrewP, does this work for you? (I also moved the "dtype" 
> thing around, it bothered me).

It *might* break HP's ia64 machines.  I have this feeling that the serial
ports may be claimed in the resource tree before the PCI resources are
claimed (and then they need to nest under a PCI bus).

How about this variant which will insert_resource for _bus_ resources,
but request_resource for _device_ resources?

(I also got rid of the spurious 'of' in the dev_err message)

Comments

Linus Torvalds Aug. 2, 2009, 5:19 p.m. UTC | #1
On Sun, 2 Aug 2009, Matthew Wilcox wrote:
> 
> It *might* break HP's ia64 machines.  I have this feeling that the serial
> ports may be claimed in the resource tree before the PCI resources are
> claimed (and then they need to nest under a PCI bus).
> 
> How about this variant which will insert_resource for _bus_ resources,
> but request_resource for _device_ resources?

Ugh. Please no. Hackery like this will just lead to unmaintainable crud in 
the long run. Can you just fix ia64 instead? The firmware resources should 
be added _after_ the PCI resource tree has been walked, not before.

		Linus
--
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
Matthew Wilcox Aug. 2, 2009, 5:25 p.m. UTC | #2
On Sun, Aug 02, 2009 at 10:19:42AM -0700, Linus Torvalds wrote:
> On Sun, 2 Aug 2009, Matthew Wilcox wrote:
> > 
> > It *might* break HP's ia64 machines.  I have this feeling that the serial
> > ports may be claimed in the resource tree before the PCI resources are
> > claimed (and then they need to nest under a PCI bus).
> > 
> > How about this variant which will insert_resource for _bus_ resources,
> > but request_resource for _device_ resources?
> 
> Ugh. Please no. Hackery like this will just lead to unmaintainable crud in 
> the long run. Can you just fix ia64 instead? The firmware resources should 
> be added _after_ the PCI resource tree has been walked, not before.

I'll take a look later if Andrew doesn't beat me to it.  I still happen
to have two of those machines in my basement.  But my wife is hassling
me to go out now (it's not crazy 40C in Ottawa ...)
diff mbox

Patch

diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index ec80b88..8384cb3 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -100,17 +100,21 @@  int pci_claim_resource(struct pci_dev *dev, int resource)
 {
 	struct resource *res = &dev->resource[resource];
 	struct resource *root;
-	char *dtype = resource < PCI_BRIDGE_RESOURCES ? "device" : "bridge";
 	int err;
 
 	root = pci_find_parent_resource(dev, res);
 
 	err = -EINVAL;
-	if (root != NULL)
-		err = insert_resource(root, res);
+	if (root != NULL) {
+		if (resource < PCI_BRIDGE_RESOURCES)
+			err = request_resource(root, res);
+		else
+			err = insert_resource(root, res);
+	}
 
 	if (err) {
-		dev_err(&dev->dev, "BAR %d: %s of %s %pR\n",
+		const char *dtype = resource < PCI_BRIDGE_RESOURCES ? "device" : "bridge";
+		dev_err(&dev->dev, "BAR %d: %s %s %pR\n",
 			resource,
 			root ? "address space collision on" :
 				"no parent found for",