Commit d08c4e23 authored by Ville Syrjälä's avatar Ville Syrjälä

drm/i915: Fix potential overflows in ilk ips calculations

A bunch of the ips calculations require 64bit math. In particular
'corr' and 'corr2' look like they can overflow on 32bit systems.
Switch to explicit u64 for those.
Signed-off-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20201021131443.25616-3-ville.syrjala@linux.intel.comReviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
parent e82351e7
...@@ -1281,8 +1281,9 @@ static unsigned long __ips_gfx_val(struct intel_ips *ips) ...@@ -1281,8 +1281,9 @@ static unsigned long __ips_gfx_val(struct intel_ips *ips)
{ {
struct intel_rps *rps = container_of(ips, typeof(*rps), ips); struct intel_rps *rps = container_of(ips, typeof(*rps), ips);
struct intel_uncore *uncore = rps_to_uncore(rps); struct intel_uncore *uncore = rps_to_uncore(rps);
unsigned long t, corr, state1, corr2, state2; unsigned int t, state1, state2;
u32 pxvid, ext_v; u32 pxvid, ext_v;
u64 corr, corr2;
lockdep_assert_held(&mchdev_lock); lockdep_assert_held(&mchdev_lock);
...@@ -1303,11 +1304,10 @@ static unsigned long __ips_gfx_val(struct intel_ips *ips) ...@@ -1303,11 +1304,10 @@ static unsigned long __ips_gfx_val(struct intel_ips *ips)
else /* < 50 */ else /* < 50 */
corr = t * 301 + 1004; corr = t * 301 + 1004;
corr = corr * 150142 * state1 / 10000 - 78642; corr = div_u64(corr * 150142 * state1, 10000) - 78642;
corr /= 100000; corr2 = div_u64(corr, 100000) * ips->corr;
corr2 = corr * ips->corr;
state2 = corr2 * state1 / 10000; state2 = div_u64(corr2 * state1, 10000);
state2 /= 100; /* convert to mW */ state2 /= 100; /* convert to mW */
__gen5_ips_update(ips); __gen5_ips_update(ips);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment