Skip to content

Commit 47ea91b

Browse files
Ram Paitorvalds
authored andcommitted
Resource: fix wrong resource window calculation
__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]>
1 parent 92bb062 commit 47ea91b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

kernel/resource.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ static int __find_resource(struct resource *root, struct resource *old,
419419
else
420420
tmp.end = root->end;
421421

422+
if (tmp.end < tmp.start)
423+
goto next;
424+
422425
resource_clip(&tmp, constraint->min, constraint->max);
423426
arch_remove_reservations(&tmp);
424427

@@ -436,8 +439,10 @@ static int __find_resource(struct resource *root, struct resource *old,
436439
return 0;
437440
}
438441
}
439-
if (!this)
442+
443+
next: if (!this || this->end == root->end)
440444
break;
445+
441446
if (this != old)
442447
tmp.start = this->end + 1;
443448
this = this->sibling;

0 commit comments

Comments
 (0)