Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp579106img; Fri, 22 Mar 2019 04:26:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqy7yv2Z2/ryL94foaQexk9ylGVDCLwOqOa2OPFmAzFFCW7FBoMU3J3tBWBuGcaHPv5wOzJj X-Received: by 2002:a63:181a:: with SMTP id y26mr8529816pgl.268.1553254010734; Fri, 22 Mar 2019 04:26:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553254010; cv=none; d=google.com; s=arc-20160816; b=QnH+9nnfeB3AQ+H+LR4NOEB0/IdLZl+bzu8WW93Ei7s3y6AjIOd8GXPAAw4pqji1yP Of9ATI1hH5mYSFxzXGYlylQa7iKTSX+TQ74VDeIBPwA09yKj8kBQ4hWFifv8Fik8k1ca A3eWxQHSQREo8Poqu6cXEy0lFjKqV6ceAYyf8xIGSnKsVNyjJCtRF8qBj0LxAhvI4uP2 6j0Ns3UCtwmerU2pcybUA+4ZSjZzamcCtZn6acKFYto6BOG/OEeTQ31EvfaKZvrzMK32 IGSDsY0qaAOI0FubhVq/Vb8jRwLL31FSxP5gJogxdzZX8IKrsllsklzTvpEcpUZuOVIx AATQ== 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=R8OhFQZIpRaz7y9KVkLM6QyZZsCetx8IN83ZjPyYBt0=; b=ANjsBgk78IeuywjITiaRRsSIonQQSu239mk2gPrkcEOCsj+e0g426JunEPd16s29zN bd6QgH/3LbZcwptrC0NK6Wf0Gd6FP3l4G570FoqI6Xc0wbNozE6apEPn6I4xJh3buw3g KbThmxnR4TFcZH8ItnzddSvCwt/km8ZzxiMDdT9K3m296hu3I0CcMzbvIcgCcm8Ha4xK ppW2nPaSGfHPzH3Uy0X4Sq66U4ggLwFjnWD0nRWlQilPsrD47LPzA3qAwaFDjxuGzApL dIn/2NexRsw7JfkwPdYvLOKHv1oavChGBQGoWWsp6ofLCsgM8b6qI8bOL/fzWFlH+SkD Xn2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KUxGooFF; 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 z8si6258523pgu.224.2019.03.22.04.26.33; Fri, 22 Mar 2019 04:26:50 -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=KUxGooFF; 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 S1729172AbfCVLYm (ORCPT + 99 others); Fri, 22 Mar 2019 07:24:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:51774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728619AbfCVLYm (ORCPT ); Fri, 22 Mar 2019 07:24:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 0AD3720657; Fri, 22 Mar 2019 11:24:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553253881; bh=IeLcEfEH7otdVJcucPdaRb0gmbbyvnSwRT4531AhZC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KUxGooFFRub+fAzEqYLjVsozOB/0+CdzN4/QQ6lu+VqHjDlvVZoDZEFDvgmtT0Qzr A+tu+7Q6OunKLwGKxCU4SSekAsOBx8uMCbb7joqflhRAZ7CGiaWLViu0FzajSia9Lz u+/+oYOGqWN9RMyP23aTtrPrhuDNVt/BosaTT9iU= 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 3.18 085/134] net/mlx4_core: Fix qp mtt size calculation Date: Fri, 22 Mar 2019 12:14:58 +0100 Message-Id: <20190322111216.265681642@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111210.465931067@linuxfoundation.org> References: <20190322111210.465931067@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 3.18-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 @@ -2474,13 +2474,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; }