Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp268507img; Mon, 18 Mar 2019 02:42:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1pqsAWrpVjjEMJfdfKxeexzD1tPyl1kHEHHpTr9Iy6sTTkcbIeCn1NaZqhaEuhlec5dMm X-Received: by 2002:a17:902:6b08:: with SMTP id o8mr18813371plk.105.1552902125910; Mon, 18 Mar 2019 02:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552902125; cv=none; d=google.com; s=arc-20160816; b=PiyEgII9wedeAb8d9KuCD0VsRjaFCsuWjIJpupX7O8iEPS9rTQZK2A+M8yaXDk1pef vmwRk4U/2ogMPurDthEMFumOJxBz7jYuT10Q0M9F3MUH6dEitKBUrgk6PWFFlA6wCtEK rNXQK4CTE2gT2ZYGc4tnmaZWWnc/fql77bWq6IiTmpEMsghzb19enXUpIe/QmSTmTVHV B6wYa1rPmpmGZVItN4ENZltlyy+bTcDlxxbzIg0Gp/BDQGM4MMhPnNUhoQCtcMRF1lAz MIgc/RlNXdwOk2EkBWheep/+YKLtBb+WuFdiy6CjXDehoZFHlOsvkG1QC8zLgQ6RjfwU abuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=d8xbWD261u9qr36dDSCVyuAnw+dzASFXqcpWKbGJpro=; b=GcrcP3k21RXIa1b5Px5dCYGomKUWJKMin50pwkCUMad+PMzfxz98hpJkcN5J+isiCR U3KQ4j9fHmxxASx8jmsamJbQasx308DsTJCUfhlZK+JJdyPyMHW4LSJPny1Dr+RNjmGz +v62naWD4mR2QcqV2+0hqmN6jE2avnbyeNqSU6jlz415q4OJ/Joa6NmqWwI2WAwpoy2W cn6+rYl2fwKjN2nvP+KO1Wh+HNGdcw8gcEdYJTHAcbTNMSiXUVGxQw3Cvpft35W7MtGF SzxzSEfDt9lMyACN4aud0w2RO1xCEE62EGB+yzfQzeIemFT0mgw7QwL4a8+9DVxnzcjw GzZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b2T06KH5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q23si370090pgj.320.2019.03.18.02.41.51; Mon, 18 Mar 2019 02:42:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b2T06KH5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728779AbfCRJfF (ORCPT + 99 others); Mon, 18 Mar 2019 05:35:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:43390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387417AbfCRJfB (ORCPT ); Mon, 18 Mar 2019 05:35:01 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 67CAA2075C; Mon, 18 Mar 2019 09:35:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901700; bh=h3bzZbFLs64EJcYIAhL1DXrSYCci1cQ0HOMENtEtEC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b2T06KH5qsY79W5IcsqOc6gr+vtz+EdI2feQq1c8F+cqlMS14emTIfe38el6mx0r5 Q9B8ccYoJiD1myD+4VZDscY6S0qQVWz56HEe4d/Q0CbKqj4M467r0q7KcuQK4D/o7h I28uRzSQk5Dcm9VA4MxMwlOKgjrEf0BY3TdNhPG8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jack Morgenstein , Tariq Toukan , "David S. Miller" Subject: [PATCH 4.14 21/34] net/mlx4_core: Fix qp mtt size calculation Date: Mon, 18 Mar 2019 10:25:45 +0100 Message-Id: <20190318084147.644306736@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318084144.657740413@linuxfoundation.org> References: <20190318084144.657740413@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jack Morgenstein [ Upstream commit 8511a653e9250ef36b95803c375a7be0e2edb628 ] 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: c82e9aa0a8bc ("mlx4_core: resource tracking for HCA resources used by guests") Signed-off-by: Jack Morgenstein Signed-off-by: Tariq Toukan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlx4/resource_tracker.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c +++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c @@ -2717,13 +2717,13 @@ static int qp_get_mtt_size(struct mlx4_q int total_pages; int total_mem; int page_offset = (be32_to_cpu(qpc->params2) >> 6) & 0x3f; + int tot; sq_size = 1 << (log_sq_size + log_sq_sride + 4); rq_size = (srq|rss|xrc) ? 0 : (1 << (log_rq_size + log_rq_stride + 4)); total_mem = sq_size + rq_size; - total_pages = - roundup_pow_of_two((total_mem + (page_offset << 6)) >> - page_shift); + tot = (total_mem + (page_offset << 6)) >> page_shift; + total_pages = !tot ? 1 : roundup_pow_of_two(tot); return total_pages; }