Skip to content

Commit

Permalink
kernel/resource: Increment by align value in get_free_mem_region()
Browse files Browse the repository at this point in the history
Currently get_free_mem_region() searches for available capacity
in increments equal to the region size being requested. This can
cause the search to take giant steps through the resource leaving
needless gaps and missing available space.

Specifically 'cxl create-region' fails with ERANGE even though capacity
of the given size and CXL's expected 256M x InterleaveWays alignment can
be satisfied.

Replace the total-request-size increment with a next alignment increment
so that the next possible address is always examined for availability.

Fixes: 14b8058 ("resource: Introduce alloc_free_mem_region()")
Reported-by: Dmytro Adamenko <[email protected]>
Reported-by: Dan Williams <[email protected]>
Signed-off-by: Alison Schofield <[email protected]>
Reviewed-by: Dave Jiang <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Cc: Jason Gunthorpe <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Dan Williams <[email protected]>
  • Loading branch information
AlisonSchofield authored and djbw committed Dec 5, 2023
1 parent e05501e commit 659aa05
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kernel/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -1844,8 +1844,8 @@ get_free_mem_region(struct device *dev, struct resource *base,

write_lock(&resource_lock);
for (addr = gfr_start(base, size, align, flags);
gfr_continue(base, addr, size, flags);
addr = gfr_next(addr, size, flags)) {
gfr_continue(base, addr, align, flags);
addr = gfr_next(addr, align, flags)) {
if (__region_intersects(base, addr, size, 0, IORES_DESC_NONE) !=
REGION_DISJOINT)
continue;
Expand Down

0 comments on commit 659aa05

Please sign in to comment.