]> Git Repo - linux.git/commitdiff
cxl/region:Fix overflow issue in alloc_hpa()
authorQuanquan Cao <[email protected]>
Wed, 24 Jan 2024 09:15:26 +0000 (17:15 +0800)
committerDan Williams <[email protected]>
Thu, 25 Jan 2024 05:03:03 +0000 (21:03 -0800)
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: 23a22cd1c98b ("cxl/region: Allocate HPA capacity to regions")
Cc: <[email protected]>
Signed-off-by: Dan Williams <[email protected]>
drivers/cxl/core/region.c

index 0f05692bfec3946841a766c8583bc1a3b526073e..ce0e2d82bb2b4cfdc61761d5e32a8c91cc121d82 100644 (file)
@@ -525,7 +525,7 @@ static int alloc_hpa(struct cxl_region *cxlr, resource_size_t size)
        struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent);
        struct cxl_region_params *p = &cxlr->params;
        struct resource *res;
-       u32 remainder = 0;
+       u64 remainder = 0;
 
        lockdep_assert_held_write(&cxl_region_rwsem);
 
@@ -545,7 +545,7 @@ static int alloc_hpa(struct cxl_region *cxlr, resource_size_t size)
            (cxlr->mode == CXL_DECODER_PMEM && uuid_is_null(&p->uuid)))
                return -ENXIO;
 
-       div_u64_rem(size, SZ_256M * p->interleave_ways, &remainder);
+       div64_u64_rem(size, (u64)SZ_256M * p->interleave_ways, &remainder);
        if (remainder)
                return -EINVAL;
 
This page took 0.058972 seconds and 4 git commands to generate.