Skip to content

Commit

Permalink
Resource: fix wrong resource window calculation
Browse files Browse the repository at this point in the history
__find_resource() incorrectly returns a resource window which overlaps
an existing allocated window.  This happens when the parent's
resource-window spans 0x00000000 to 0xffffffff and is entirely allocated
to all its children resource-windows.

__find_resource() looks for gaps in resource allocation among the
children resource windows.  When it encounters the last child window it
blindly tries the range next to one allocated to the last child.  Since
the last child's window ends at 0xffffffff the calculation overflows,
leading the algorithm to believe that any window in the range 0x0000000
to 0xfffffff is available for allocation.  This leads to a conflicting
window allocation.

Michal Ludvig reported this issue seen on his platform.  The following
patch fixes the problem and has been verified by Michal.  I believe this
bug has been there for ages.  It got exposed by git commit 2bbc694
("PCI : ability to relocate assigned pci-resources")

Signed-off-by: Ram Pai <[email protected]>
Tested-by: Michal Ludvig <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Ram Pai authored and torvalds committed Sep 30, 2011
1 parent 92bb062 commit 47ea91b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion kernel/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ static int __find_resource(struct resource *root, struct resource *old,
else
tmp.end = root->end;

if (tmp.end < tmp.start)
goto next;

resource_clip(&tmp, constraint->min, constraint->max);
arch_remove_reservations(&tmp);

Expand All @@ -436,8 +439,10 @@ static int __find_resource(struct resource *root, struct resource *old,
return 0;
}
}
if (!this)

next: if (!this || this->end == root->end)
break;

if (this != old)
tmp.start = this->end + 1;
this = this->sibling;
Expand Down

0 comments on commit 47ea91b

Please sign in to comment.