Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3378036ybp; Sun, 6 Oct 2019 10:36:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwd2k7sRqmzVVY9rMeHDN2sUg8g4afKV0msLXooOSigAxC1aivmwAnNvDL5JOSdzRQfYfq X-Received: by 2002:a05:6402:13c2:: with SMTP id a2mr25055149edx.21.1570383402370; Sun, 06 Oct 2019 10:36:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570383402; cv=none; d=google.com; s=arc-20160816; b=pCupZAGi3axssbeIFiRcmNPNPgs9yhUXBgXmPEhJtR4OO3a0oSV5q14jV7s3sd5Ao+ 891FlgR9yQ2CHO65PRM/jEOefwvEQb6Kb5nThdAP5e2DDTB9rTnFhewxeQwiXg3L0IA0 nQOtz6UysgXviWU5DiUK+Xd82UkaU0EhX1qFVjXp72J5mC6WolB1ReDfXqQwXaGHWHlp ZYV4I4WjnTBJojAG6SjU2881fW3bXwI10mnufsxD17uZeTuoYZGFeBqB3MX1QNQL+T72 o/hurVxV0PXGliChninYKTH7bzU57vVQBaFWKFvLeY+xu5YcdvSpIg1UmED8R54viLAf w9Ng== 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=Ed1+o9TE/UlypylaKvAjvBTDT13aKURW9M8tohhpBvI=; b=HGVqveLXbyesLhlDsbv1ugKDHnJ5YPG/cW0TUYN0T62rdkmCcXCeU1n+E3PoZjykxK 7py4hln7cjQhvc/oGhjuTngRVL2KlB65baP9UM+0ONfoS2QSwJCl//bxISOPpoy+F3bH Asl7D4oKjP2Gku0QZ4n3jDdhHZkJXG0MdSKydeUbc8nWMrocT15ItSzZg3di/QC75tzc 1rrKQ6N/c6LRIYmFRYBgQqfnx/82TsRtuXTuvTVAp30XeSBioGTqc98ia0zG6wcGZZGb jDS5wnbDGUefnmqUNynCYo0zqjzZfTIqGrihJfAL/XLZ5HXKBzDrzhZd2tUqisPE00cb hNNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NAmkEkP2; 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 v39si7557686edc.234.2019.10.06.10.36.18; Sun, 06 Oct 2019 10:36:42 -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=NAmkEkP2; 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 S1727407AbfJFRep (ORCPT + 99 others); Sun, 6 Oct 2019 13:34:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:33262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728329AbfJFRek (ORCPT ); Sun, 6 Oct 2019 13:34:40 -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 68AFC21479; Sun, 6 Oct 2019 17:34:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383278; bh=V5BW3Dan/eBvQD7BOHMpiAzvf6bQmdaJ66dFqU73JmY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NAmkEkP2JGNKKfhePfJ8GUctyD1ZHI7upJZtGYBV9sSyuw996xPIYtgoTx5CfaDg/ 66LoEHzB7sVCF/8hUzjcJBoaJ9O6AyTZqQXNIOX1Ir7hv8vAS+AtNlvW7oS50GTzpK UKewNthnCNx8XeQ8/wNBhYfNfU2it8FnyNU1IcAo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bayan Zabihiyan , Aric Cyr , Leo Li , Alex Deucher , Sasha Levin Subject: [PATCH 5.2 046/137] drm/amd/display: Fix frames_to_insert math Date: Sun, 6 Oct 2019 19:20:30 +0200 Message-Id: <20191006171212.732095091@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171209.403038733@linuxfoundation.org> References: <20191006171209.403038733@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Bayan Zabihiyan [ Upstream commit a463b263032f7c98c5912207db43be1aa34a6438 ] [Why] The math on deciding on how many "frames to insert" sometimes sent us over the max refresh rate. Also integer overflow can occur if we have high refresh rates. [How] Instead of clipping the frame duration such that it doesn’t go below the min, just remove a frame from the number of frames to insert. + Use unsigned long long for intermediate calculations to prevent integer overflow. Signed-off-by: Bayan Zabihiyan Reviewed-by: Aric Cyr Acked-by: Leo Li Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- .../amd/display/modules/freesync/freesync.c | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/amd/display/modules/freesync/freesync.c b/drivers/gpu/drm/amd/display/modules/freesync/freesync.c index 19b1eaebe4840..000a9db9dad82 100644 --- a/drivers/gpu/drm/amd/display/modules/freesync/freesync.c +++ b/drivers/gpu/drm/amd/display/modules/freesync/freesync.c @@ -433,6 +433,12 @@ static void apply_below_the_range(struct core_freesync *core_freesync, /* Either we've calculated the number of frames to insert, * or we need to insert min duration frames */ + if (last_render_time_in_us / frames_to_insert < + in_out_vrr->min_duration_in_us){ + frames_to_insert -= (frames_to_insert > 1) ? + 1 : 0; + } + if (frames_to_insert > 0) inserted_frame_duration_in_us = last_render_time_in_us / frames_to_insert; @@ -885,8 +891,8 @@ void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync, struct core_freesync *core_freesync = NULL; unsigned long long nominal_field_rate_in_uhz = 0; unsigned int refresh_range = 0; - unsigned int min_refresh_in_uhz = 0; - unsigned int max_refresh_in_uhz = 0; + unsigned long long min_refresh_in_uhz = 0; + unsigned long long max_refresh_in_uhz = 0; if (mod_freesync == NULL) return; @@ -913,7 +919,7 @@ void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync, min_refresh_in_uhz = nominal_field_rate_in_uhz; if (!vrr_settings_require_update(core_freesync, - in_config, min_refresh_in_uhz, max_refresh_in_uhz, + in_config, (unsigned int)min_refresh_in_uhz, (unsigned int)max_refresh_in_uhz, in_out_vrr)) return; @@ -929,15 +935,15 @@ void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync, return; } else { - in_out_vrr->min_refresh_in_uhz = min_refresh_in_uhz; + in_out_vrr->min_refresh_in_uhz = (unsigned int)min_refresh_in_uhz; in_out_vrr->max_duration_in_us = calc_duration_in_us_from_refresh_in_uhz( - min_refresh_in_uhz); + (unsigned int)min_refresh_in_uhz); - in_out_vrr->max_refresh_in_uhz = max_refresh_in_uhz; + in_out_vrr->max_refresh_in_uhz = (unsigned int)max_refresh_in_uhz; in_out_vrr->min_duration_in_us = calc_duration_in_us_from_refresh_in_uhz( - max_refresh_in_uhz); + (unsigned int)max_refresh_in_uhz); refresh_range = in_out_vrr->max_refresh_in_uhz - in_out_vrr->min_refresh_in_uhz; @@ -948,17 +954,18 @@ void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync, in_out_vrr->fixed.ramping_active = in_config->ramping; in_out_vrr->btr.btr_enabled = in_config->btr; + if (in_out_vrr->max_refresh_in_uhz < 2 * in_out_vrr->min_refresh_in_uhz) in_out_vrr->btr.btr_enabled = false; + in_out_vrr->btr.btr_active = false; in_out_vrr->btr.inserted_duration_in_us = 0; in_out_vrr->btr.frames_to_insert = 0; in_out_vrr->btr.frame_counter = 0; in_out_vrr->btr.mid_point_in_us = - in_out_vrr->min_duration_in_us + - (in_out_vrr->max_duration_in_us - - in_out_vrr->min_duration_in_us) / 2; + (in_out_vrr->min_duration_in_us + + in_out_vrr->max_duration_in_us) / 2; if (in_out_vrr->state == VRR_STATE_UNSUPPORTED) { in_out_vrr->adjust.v_total_min = stream->timing.v_total; -- 2.20.1