]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.9.164/net-mlx4_core-fix-qp-mtt-size-calculation.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.164 / net-mlx4_core-fix-qp-mtt-size-calculation.patch
CommitLineData
8cbcfc8d
GKH
1From foo@baz Fri Mar 15 21:00:09 PDT 2019
2From: Jack Morgenstein <jackm@dev.mellanox.co.il>
3Date: Tue, 12 Mar 2019 17:05:49 +0200
4Subject: net/mlx4_core: Fix qp mtt size calculation
5
6From: Jack Morgenstein <jackm@dev.mellanox.co.il>
7
8[ Upstream commit 8511a653e9250ef36b95803c375a7be0e2edb628 ]
9
10Calculation of qp mtt size (in function mlx4_RST2INIT_wrapper)
11ultimately depends on function roundup_pow_of_two.
12
13If the amount of memory required by the QP is less than one page,
14roundup_pow_of_two is called with argument zero. In this case, the
15roundup_pow_of_two result is undefined.
16
17Calling roundup_pow_of_two with a zero argument resulted in the
18following stack trace:
19
20UBSAN: Undefined behaviour in ./include/linux/log2.h:61:13
21shift exponent 64 is too large for 64-bit type 'long unsigned int'
22CPU: 4 PID: 26939 Comm: rping Tainted: G OE 4.19.0-rc1
23Hardware name: Supermicro X9DR3-F/X9DR3-F, BIOS 3.2a 07/09/2015
24Call Trace:
25dump_stack+0x9a/0xeb
26ubsan_epilogue+0x9/0x7c
27__ubsan_handle_shift_out_of_bounds+0x254/0x29d
28? __ubsan_handle_load_invalid_value+0x180/0x180
29? debug_show_all_locks+0x310/0x310
30? sched_clock+0x5/0x10
31? sched_clock+0x5/0x10
32? sched_clock_cpu+0x18/0x260
33? find_held_lock+0x35/0x1e0
34? mlx4_RST2INIT_QP_wrapper+0xfb1/0x1440 [mlx4_core]
35mlx4_RST2INIT_QP_wrapper+0xfb1/0x1440 [mlx4_core]
36
37Fix this by explicitly testing for zero, and returning one if the
38argument is zero (assuming that the next higher power of 2 in this case
39should be one).
40
41Fixes: c82e9aa0a8bc ("mlx4_core: resource tracking for HCA resources used by guests")
42Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
43Signed-off-by: Tariq Toukan <tariqt@mellanox.com>
44Signed-off-by: David S. Miller <davem@davemloft.net>
45Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
46---
47 drivers/net/ethernet/mellanox/mlx4/resource_tracker.c | 6 +++---
48 1 file changed, 3 insertions(+), 3 deletions(-)
49
50--- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
51+++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
52@@ -2677,13 +2677,13 @@ static int qp_get_mtt_size(struct mlx4_q
53 int total_pages;
54 int total_mem;
55 int page_offset = (be32_to_cpu(qpc->params2) >> 6) & 0x3f;
56+ int tot;
57
58 sq_size = 1 << (log_sq_size + log_sq_sride + 4);
59 rq_size = (srq|rss|xrc) ? 0 : (1 << (log_rq_size + log_rq_stride + 4));
60 total_mem = sq_size + rq_size;
61- total_pages =
62- roundup_pow_of_two((total_mem + (page_offset << 6)) >>
63- page_shift);
64+ tot = (total_mem + (page_offset << 6)) >> page_shift;
65+ total_pages = !tot ? 1 : roundup_pow_of_two(tot);
66
67 return total_pages;
68 }