Skip to content

Commit f46dc15

Browse files
Jack Morgensteingregkh
authored andcommitted
net/mlx4_core: Fix qp mtt size calculation
[ Upstream commit 8511a65 ] Calculation of qp mtt size (in function mlx4_RST2INIT_wrapper) ultimately depends on function roundup_pow_of_two. If the amount of memory required by the QP is less than one page, roundup_pow_of_two is called with argument zero. In this case, the roundup_pow_of_two result is undefined. Calling roundup_pow_of_two with a zero argument resulted in the following stack trace: UBSAN: Undefined behaviour in ./include/linux/log2.h:61:13 shift exponent 64 is too large for 64-bit type 'long unsigned int' CPU: 4 PID: 26939 Comm: rping Tainted: G OE 4.19.0-rc1 Hardware name: Supermicro X9DR3-F/X9DR3-F, BIOS 3.2a 07/09/2015 Call Trace: dump_stack+0x9a/0xeb ubsan_epilogue+0x9/0x7c __ubsan_handle_shift_out_of_bounds+0x254/0x29d ? __ubsan_handle_load_invalid_value+0x180/0x180 ? debug_show_all_locks+0x310/0x310 ? sched_clock+0x5/0x10 ? sched_clock+0x5/0x10 ? sched_clock_cpu+0x18/0x260 ? find_held_lock+0x35/0x1e0 ? mlx4_RST2INIT_QP_wrapper+0xfb1/0x1440 [mlx4_core] mlx4_RST2INIT_QP_wrapper+0xfb1/0x1440 [mlx4_core] Fix this by explicitly testing for zero, and returning one if the argument is zero (assuming that the next higher power of 2 in this case should be one). Fixes: c82e9aa ("mlx4_core: resource tracking for HCA resources used by guests") Signed-off-by: Jack Morgenstein <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 038a48c commit f46dc15

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/net/ethernet/mellanox/mlx4/resource_tracker.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,13 +2677,13 @@ static int qp_get_mtt_size(struct mlx4_qp_context *qpc)
26772677
int total_pages;
26782678
int total_mem;
26792679
int page_offset = (be32_to_cpu(qpc->params2) >> 6) & 0x3f;
2680+
int tot;
26802681

26812682
sq_size = 1 << (log_sq_size + log_sq_sride + 4);
26822683
rq_size = (srq|rss|xrc) ? 0 : (1 << (log_rq_size + log_rq_stride + 4));
26832684
total_mem = sq_size + rq_size;
2684-
total_pages =
2685-
roundup_pow_of_two((total_mem + (page_offset << 6)) >>
2686-
page_shift);
2685+
tot = (total_mem + (page_offset << 6)) >> page_shift;
2686+
total_pages = !tot ? 1 : roundup_pow_of_two(tot);
26872687

26882688
return total_pages;
26892689
}

0 commit comments

Comments
 (0)