[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140116202522.GJ29522@redhat.com>
Date: Thu, 16 Jan 2014 22:25:22 +0200
From: "Michael S. Tsirkin" <mst@...hat.com>
To: Michael Dalton <mwdalton@...gle.com>
Cc: "David S. Miller" <davem@...emloft.net>, netdev@...r.kernel.org,
Eric Dumazet <edumazet@...gle.com>,
Rusty Russell <rusty@...tcorp.com.au>,
Jason Wang <jasowang@...hat.com>,
Ben Hutchings <bhutchings@...arflare.com>,
virtualization@...ts.linux-foundation.org
Subject: Re: [PATCH net-next v4 5/6] lib: Ensure EWMA does not store wrong
intermediate values
On Thu, Jan 16, 2014 at 11:52:29AM -0800, Michael Dalton wrote:
> To ensure ewma_read() without a lock returns a valid but possibly
> out of date average, modify ewma_add() by using ACCESS_ONCE to prevent
> intermediate wrong values from being written to avg->internal.
>
> Suggested-by: Eric Dumazet <eric.dumazet@...il.com>
> Signed-off-by: Michael Dalton <mwdalton@...gle.com>
Acked-by: Michael S. Tsirkin <mst@...hat.com>
> ---
> lib/average.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/lib/average.c b/lib/average.c
> index 99a67e6..114d1be 100644
> --- a/lib/average.c
> +++ b/lib/average.c
> @@ -53,8 +53,10 @@ EXPORT_SYMBOL(ewma_init);
> */
> struct ewma *ewma_add(struct ewma *avg, unsigned long val)
> {
> - avg->internal = avg->internal ?
> - (((avg->internal << avg->weight) - avg->internal) +
> + unsigned long internal = ACCESS_ONCE(avg->internal);
> +
> + ACCESS_ONCE(avg->internal) = internal ?
> + (((internal << avg->weight) - internal) +
> (val << avg->factor)) >> avg->weight :
> (val << avg->factor);
> return avg;
> --
> 1.8.5.2
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists