Commit 5a5ec83d authored by Andreas Gruenbacher's avatar Andreas Gruenbacher

gfs2: Fix sign extension bug in gfs2_update_stats

Commit 4d207133 changed the types of the statistic values in struct
gfs2_lkstats from s64 to u64.  Because of that, what should be a signed
value in gfs2_update_stats turned into an unsigned value.  When shifted
right, we end up with a large positive value instead of a small negative
value, which results in an incorrect variance estimate.

Fixes: 4d207133 ("gfs2: Make statistics unsigned, suitable for use with do_div()")
Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
Cc: stable@vger.kernel.org # v4.4+
parent a188339c
...@@ -31,9 +31,10 @@ ...@@ -31,9 +31,10 @@
* @delta is the difference between the current rtt sample and the * @delta is the difference between the current rtt sample and the
* running average srtt. We add 1/8 of that to the srtt in order to * running average srtt. We add 1/8 of that to the srtt in order to
* update the current srtt estimate. The variance estimate is a bit * update the current srtt estimate. The variance estimate is a bit
* more complicated. We subtract the abs value of the @delta from * more complicated. We subtract the current variance estimate from
* the current variance estimate and add 1/4 of that to the running * the abs value of the @delta and add 1/4 of that to the running
* total. * total. That's equivalent to 3/4 of the current variance
* estimate plus 1/4 of the abs of @delta.
* *
* Note that the index points at the array entry containing the smoothed * Note that the index points at the array entry containing the smoothed
* mean value, and the variance is always in the following entry * mean value, and the variance is always in the following entry
...@@ -49,7 +50,7 @@ static inline void gfs2_update_stats(struct gfs2_lkstats *s, unsigned index, ...@@ -49,7 +50,7 @@ static inline void gfs2_update_stats(struct gfs2_lkstats *s, unsigned index,
s64 delta = sample - s->stats[index]; s64 delta = sample - s->stats[index];
s->stats[index] += (delta >> 3); s->stats[index] += (delta >> 3);
index++; index++;
s->stats[index] += ((abs(delta) - s->stats[index]) >> 2); s->stats[index] += (s64)(abs(delta) - s->stats[index]) >> 2;
} }
/** /**
......
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