cxl/region:Fix overflow issue in alloc_hpa()
authorQuanquan Cao <caoqq@fujitsu.com>
Wed, 24 Jan 2024 09:15:26 +0000 (17:15 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 1 Feb 2024 00:19:13 +0000 (16:19 -0800)
commit40cb184ec84e24f1e2082e083749dbc7a0d4ca57
treee73c32f13129dbb2171b9e132297089d5af0fd1b
parent099fee35bb09e851a4a84ea589fde4c83ffe0d4b
cxl/region:Fix overflow issue in alloc_hpa()

commit d76779dd3681c01a4c6c3cae4d0627c9083e0ee6 upstream.

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 <caoqq@fujitsu.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Fixes: 23a22cd1c98b ("cxl/region: Allocate HPA capacity to regions")
Cc: <stable@vger.kernel.org>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/cxl/core/region.c