From patchwork Tue Jun 13 05:17:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 9783127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2A0CC60325 for ; Tue, 13 Jun 2017 05:18:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C20B26D05 for ; Tue, 13 Jun 2017 05:18:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E669284DA; Tue, 13 Jun 2017 05:18:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A5ED526D05 for ; Tue, 13 Jun 2017 05:18:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 02B896E22F; Tue, 13 Jun 2017 05:18:15 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 93F176E22A; Tue, 13 Jun 2017 05:18:13 +0000 (UTC) Received: by mail-wr0-x243.google.com with SMTP id g76so26508230wrd.2; Mon, 12 Jun 2017 22:18:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=14hHqIwXIQ8xJJ6d1RFhzLeTX1vzIXM2iWltSuO36+Y=; b=GDHT6bCItGpQZuspS/C89b7lOT0cQWK/zMHjMi1tuLs3WZD2B9Lzt/9qFhjghCFoX0 wVJ4uu5X/PrBSin9FOXkF8Y6xfwif0NRyUCPMPlv0BwdX/7PGMa5PAyBRqP6Xzbte94/ +ojUmYi6Yg5iSEhzm4T9lyjJCx2uM0sY/z++hIdopBrGsacmR2gFidgYMZfrPtobvQJT Tax0J+LIvWDsMSBKIVQTfzx/Pymz6teEIZFxmTpZjkHlBOFLkLmSv3Lfk3xTg6C+5W/J Rex6O06yd6sSf9IiuppOpnvwHU7VrZFPab8qhurE6VqEGSc9jHWmx5HPpQQNX2HsRz6U GFUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=14hHqIwXIQ8xJJ6d1RFhzLeTX1vzIXM2iWltSuO36+Y=; b=F6mJFOEM1am7nQReA5Yfd6BZgQDVI87yhA/ZmHXdecn7XdJ1/9hVhncxAUzyNGVJN8 Bl1XS6j72wuxmnJMOe9uNcEZxLPanJ99KFeH5Uh8xFVUeYD9z11NQZdgID/Hk/lCtW9Y tXYK9GdjDLyqRvMPnA8Q9EZcNwXXeHa0WvYiQQTzXH+M8ylt2yHdy66GHzyvkJdVjs2l YCl9Uufp7vW4h2/U0ZZ++DpQDTVfYPm28dfRrvLtxOyAtHZkhENDILL7PSHHX/RGjIBx 337MY9r4P0FpbC0sfz1z7xQgJoIHm1byXUjkBtc4uLnt46ydP+BFOS/0B3TWHtcRaJS0 7+sA== X-Gm-Message-State: AKS2vOwlQdbXRWSE7eLR3lKXBxIZuQiBMBG/EgUYHAbbaO3gTkOgqkK9 k+BhDMHfvUd8+3S+ X-Received: by 10.28.150.136 with SMTP id y130mr2070835wmd.108.1497331091909; Mon, 12 Jun 2017 22:18:11 -0700 (PDT) Received: from twisty.cin.medizin.uni-tuebingen.de (cin-11.medizin.uni-tuebingen.de. [134.2.118.242]) by smtp.gmail.com with ESMTPSA id v13sm2559211wmd.5.2017.06.12.22.18.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Jun 2017 22:18:11 -0700 (PDT) From: Mario Kleiner To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] drm/radeon: Fix overflow of watermark calcs at > 4k resolutions. Date: Tue, 13 Jun 2017 07:17:11 +0200 Message-Id: <20170613051711.16372-2-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 2.13.0.rc1.294.g07d810a77f In-Reply-To: <20170613051711.16372-1-mario.kleiner.de@gmail.com> References: <20170613051711.16372-1-mario.kleiner.de@gmail.com> Cc: Alex Deucher , stable@vger.kernel.org, Ben Hutchings , amd-gfx@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Commit e6b9a6c84b93 ("drm/radeon: Make display watermark calculations more accurate") made watermark calculations more accurate, but not for > 4k resolutions on 32-Bit architectures, as it introduced an integer overflow for those setups and resolutions. Fix this by proper u64 casting and division. Signed-off-by: Mario Kleiner Reported-by: Ben Hutchings Fixes: e6b9a6c84b93 ("drm/radeon: Make display watermark calculations more accurate") Cc: Ben Hutchings Cc: Alex Deucher Cc: stable@vger.kernel.org --- drivers/gpu/drm/radeon/cik.c | 7 +++++-- drivers/gpu/drm/radeon/evergreen.c | 7 +++++-- drivers/gpu/drm/radeon/si.c | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c index 2589121..667c21a 100644 --- a/drivers/gpu/drm/radeon/cik.c +++ b/drivers/gpu/drm/radeon/cik.c @@ -9267,8 +9267,11 @@ static void dce8_program_watermarks(struct radeon_device *rdev, u32 tmp, wm_mask; if (radeon_crtc->base.enabled && num_heads && mode) { - active_time = 1000000UL * (u32)mode->crtc_hdisplay / (u32)mode->clock; - line_time = min((u32) (1000000UL * (u32)mode->crtc_htotal / (u32)mode->clock), (u32)65535); + active_time = (u32) div_u64((u64)mode->crtc_hdisplay * 1000000, + (u32)mode->clock); + line_time = (u32) div_u64((u64)mode->crtc_htotal * 1000000, + (u32)mode->clock); + line_time = min(line_time, (u32)65535); /* watermark for high clocks */ if ((rdev->pm.pm_method == PM_METHOD_DPM) && diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c index 0bf1035..5346372 100644 --- a/drivers/gpu/drm/radeon/evergreen.c +++ b/drivers/gpu/drm/radeon/evergreen.c @@ -2266,8 +2266,11 @@ static void evergreen_program_watermarks(struct radeon_device *rdev, fixed20_12 a, b, c; if (radeon_crtc->base.enabled && num_heads && mode) { - active_time = 1000000UL * (u32)mode->crtc_hdisplay / (u32)mode->clock; - line_time = min((u32) (1000000UL * (u32)mode->crtc_htotal / (u32)mode->clock), (u32)65535); + active_time = (u32) div_u64((u64)mode->crtc_hdisplay * 1000000, + (u32)mode->clock); + line_time = (u32) div_u64((u64)mode->crtc_htotal * 1000000, + (u32)mode->clock); + line_time = min(line_time, (u32)65535); priority_a_cnt = 0; priority_b_cnt = 0; dram_channels = evergreen_get_number_of_dram_channels(rdev); diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c index 76d1888..5303f25 100644 --- a/drivers/gpu/drm/radeon/si.c +++ b/drivers/gpu/drm/radeon/si.c @@ -2284,8 +2284,11 @@ static void dce6_program_watermarks(struct radeon_device *rdev, fixed20_12 a, b, c; if (radeon_crtc->base.enabled && num_heads && mode) { - active_time = 1000000UL * (u32)mode->crtc_hdisplay / (u32)mode->clock; - line_time = min((u32) (1000000UL * (u32)mode->crtc_htotal / (u32)mode->clock), (u32)65535); + active_time = (u32) div_u64((u64)mode->crtc_hdisplay * 1000000, + (u32)mode->clock); + line_time = (u32) div_u64((u64)mode->crtc_htotal * 1000000, + (u32)mode->clock); + line_time = min(line_time, (u32)65535); priority_a_cnt = 0; priority_b_cnt = 0;