From: "Michael S. Tsirkin" <mst@redhat.com>
To: Michael Dalton <mwdalton@google.com>
Cc: netdev@vger.kernel.org,
virtualization@lists.linux-foundation.org,
Eric Dumazet <edumazet@google.com>,
Ben Hutchings <bhutchings@solarflare.com>,
"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH net-next v4 5/6] lib: Ensure EWMA does not store wrong intermediate values
Date: Thu, 16 Jan 2014 22:25:22 +0200 [thread overview]
Message-ID: <20140116202522.GJ29522@redhat.com> (raw)
In-Reply-To: <1389901950-3854-5-git-send-email-mwdalton@google.com>
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@gmail.com>
> Signed-off-by: Michael Dalton <mwdalton@google.com>
Acked-by: Michael S. Tsirkin <mst@redhat.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
next prev parent reply other threads:[~2014-01-16 20:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-16 19:52 [PATCH net-next v4 1/6] net: allow > 0 order atomic page alloc in skb_page_frag_refill Michael Dalton
2014-01-16 19:52 ` [PATCH net-next v4 2/6] virtio-net: use per-receive queue page frag alloc for mergeable bufs Michael Dalton
2014-01-16 20:24 ` Michael S. Tsirkin
2014-01-16 19:52 ` [PATCH net-next v4 3/6] virtio-net: auto-tune mergeable rx buffer size for improved performance Michael Dalton
2014-01-16 20:24 ` Michael S. Tsirkin
2014-01-16 19:52 ` [PATCH net-next v4 4/6] net-sysfs: add support for device-specific rx queue sysfs attributes Michael Dalton
2014-01-16 20:25 ` Michael S. Tsirkin
2014-01-16 19:52 ` [PATCH net-next v4 5/6] lib: Ensure EWMA does not store wrong intermediate values Michael Dalton
2014-01-16 20:08 ` Eric Dumazet
2014-01-16 20:25 ` Michael S. Tsirkin [this message]
2014-01-16 19:52 ` [PATCH net-next v4 6/6] virtio-net: initial rx sysfs support, export mergeable rx buffer size Michael Dalton
2014-01-16 20:25 ` Michael S. Tsirkin
2014-01-16 23:28 ` [PATCH net-next v4 1/6] net: allow > 0 order atomic page alloc in skb_page_frag_refill David Miller
2014-01-16 23:30 ` David Miller
2014-01-17 0:30 ` Michael Dalton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140116202522.GJ29522@redhat.com \
--to=mst@redhat.com \
--cc=bhutchings@solarflare.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=mwdalton@google.com \
--cc=netdev@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).