Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7656C6FD1C for ; Tue, 14 Mar 2023 12:46:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232134AbjCNMqK (ORCPT ); Tue, 14 Mar 2023 08:46:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231544AbjCNMpL (ORCPT ); Tue, 14 Mar 2023 08:45:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C50841C5B6; Tue, 14 Mar 2023 05:44:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8949EB811F5; Tue, 14 Mar 2023 12:43:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AAE7C433D2; Tue, 14 Mar 2023 12:43:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678797824; bh=voqCg8hWNP7CnMJpCaiH8vm9+tbFEmkocUiBXj6O6sA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XhfvXTJXH+lcMMo77ss6tUQ3GR/VuTXu1JpN4cri2HzFo1fPQp58KW+RWFrRmSD6Y FhVEnhF3A2dDAp5OGzAbTkht9Uav278m/ArRY7NkI3z7RsHTU+dl7LF5rTz6fadjfA oLUT3jOzgvMYVTL8ZQEVnJetPtFJ4/uYFkNqKTJJ1JwXqo7yFF214CSDwhbSwyMMMP //W7yznGC/cLV5ZiA+th+75HNQAz8xi5H+FUZB0iht/m4NPXWFWwIVIkX/hzBw2qLC I962hYjrk13/whL/kLLLIT5RH90U19LxeA8kXDb7J0QZfAa+6O7jBN9/GDscWouV9i qa1j7ksxrsrwg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alex Hung , Jun Lei , Qingqing Zhuo , Daniel Wheeler , Alex Deucher , Sasha Levin , christian.koenig@amd.com, airlied@linux.ie, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 6.1 13/13] drm/amd/display: fix shift-out-of-bounds in CalculateVMAndRowBytes Date: Tue, 14 Mar 2023 08:43:25 -0400 Message-Id: <20230314124325.470931-13-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314124325.470931-1-sashal@kernel.org> References: <20230314124325.470931-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alex Hung [ Upstream commit 031f196d1b1b6d5dfcb0533b431e3ab1750e6189 ] [WHY] When PTEBufferSizeInRequests is zero, UBSAN reports the following warning because dml_log2 returns an unexpected negative value: shift exponent 4294966273 is too large for 32-bit type 'int' [HOW] In the case PTEBufferSizeInRequests is zero, skip the dml_log2() and assign the result directly. Reviewed-by: Jun Lei Acked-by: Qingqing Zhuo Signed-off-by: Alex Hung Tested-by: Daniel Wheeler Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- .../gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c b/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c index 479e2c1a13018..49da8119b28e9 100644 --- a/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c +++ b/drivers/gpu/drm/amd/display/dc/dml/dcn30/display_mode_vba_30.c @@ -1802,7 +1802,10 @@ static unsigned int CalculateVMAndRowBytes( } if (SurfaceTiling == dm_sw_linear) { - *dpte_row_height = dml_min(128, 1 << (unsigned int) dml_floor(dml_log2(PTEBufferSizeInRequests * *PixelPTEReqWidth / Pitch), 1)); + if (PTEBufferSizeInRequests == 0) + *dpte_row_height = 1; + else + *dpte_row_height = dml_min(128, 1 << (unsigned int) dml_floor(dml_log2(PTEBufferSizeInRequests * *PixelPTEReqWidth / Pitch), 1)); *dpte_row_width_ub = (dml_ceil(((double) SwathWidth - 1) / *PixelPTEReqWidth, 1) + 1) * *PixelPTEReqWidth; *PixelPTEBytesPerRow = *dpte_row_width_ub / *PixelPTEReqWidth * *PTERequestSize; } else if (ScanDirection != dm_vert) { -- 2.39.2