Skip to content

Commit d76779d

Browse files
notstudyingtodaydjbw
authored andcommitted
cxl/region:Fix overflow issue in alloc_hpa()
Creating a region with 16 memory devices caused a problem. The div_u64_rem function, used for dividing an unsigned 64-bit number by a 32-bit one, faced an issue when SZ_256M * p->interleave_ways. The result surpassed the maximum limit of the 32-bit divisor (4G), leading to an overflow and a remainder of 0. note: At this point, p->interleave_ways is 16, meaning 16 * 256M = 4G To fix this issue, I replaced the div_u64_rem function with div64_u64_rem and adjusted the type of the remainder. Signed-off-by: Quanquan Cao <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Fixes: 23a22cd ("cxl/region: Allocate HPA capacity to regions") Cc: <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent d72a4ca commit d76779d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/cxl/core/region.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ static int alloc_hpa(struct cxl_region *cxlr, resource_size_t size)
525525
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent);
526526
struct cxl_region_params *p = &cxlr->params;
527527
struct resource *res;
528-
u32 remainder = 0;
528+
u64 remainder = 0;
529529

530530
lockdep_assert_held_write(&cxl_region_rwsem);
531531

@@ -545,7 +545,7 @@ static int alloc_hpa(struct cxl_region *cxlr, resource_size_t size)
545545
(cxlr->mode == CXL_DECODER_PMEM && uuid_is_null(&p->uuid)))
546546
return -ENXIO;
547547

548-
div_u64_rem(size, SZ_256M * p->interleave_ways, &remainder);
548+
div64_u64_rem(size, (u64)SZ_256M * p->interleave_ways, &remainder);
549549
if (remainder)
550550
return -EINVAL;
551551

0 commit comments

Comments
 (0)