netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org,
	Alexander Duyck <alexander.h.duyck@redhat.com>,
	Andres Lagar-Cavilla <andreslc@google.com>,
	Greg Thelen <gthelen@google.com>, Hugh Dickins <hughd@google.com>,
	David Rientjes <rientjes@google.com>,
	Eric Dumazet <edumazet@google.com>
Subject: [PATCH net 4/5] mlx4: fix race accessing page->_count
Date: Thu,  9 Oct 2014 22:24:53 -0700	[thread overview]
Message-ID: <1412918694-22882-5-git-send-email-edumazet@google.com> (raw)
In-Reply-To: <1412918694-22882-1-git-send-email-edumazet@google.com>

This is illegal to use atomic_set(&page->_count, ...) even if we 'own'
the page. Other entities in the kernel need to use get_page_unless_zero()
to get a reference to the page before testing page properties, so we could
loose a refcount increment.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 drivers/net/ethernet/mellanox/mlx4/en_rx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index a33048ee9621..01660c595f5c 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -76,10 +76,10 @@ static int mlx4_alloc_pages(struct mlx4_en_priv *priv,
 	page_alloc->dma = dma;
 	page_alloc->page_offset = frag_info->frag_align;
 	/* Not doing get_page() for each frag is a big win
-	 * on asymetric workloads.
+	 * on asymetric workloads. Note we can not use atomic_set().
 	 */
-	atomic_set(&page->_count,
-		   page_alloc->page_size / frag_info->frag_stride);
+	atomic_add(page_alloc->page_size / frag_info->frag_stride - 1,
+		   &page->_count);
 	return 0;
 }
 
-- 
2.1.0.rc2.206.gedb03e5

  parent reply	other threads:[~2014-10-10  5:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-10  5:24 [PATCH net 0/5] net: fix races accessing page->_count Eric Dumazet
2014-10-10  5:24 ` [PATCH net 1/5] fm10k: fix race " Eric Dumazet
2014-10-10  5:53   ` Jeff Kirsher
2014-10-10  5:24 ` [PATCH net 2/5] igb: " Eric Dumazet
2014-10-10  5:55   ` Jeff Kirsher
2014-10-10 11:47     ` Eric Dumazet
2014-10-10  5:24 ` [PATCH net 3/5] " Eric Dumazet
2014-10-10  5:54   ` Jeff Kirsher
2014-10-10  5:24 ` Eric Dumazet [this message]
2014-10-10  5:24 ` [PATCH net 5/5] net: fix races in page->_count manipulation Eric Dumazet
2014-10-10  5:37 ` [PATCH net 0/5] net: fix races accessing page->_count Jeff Kirsher
2014-10-10  5:42   ` Eric Dumazet
2014-10-10 10:02 ` David Laight
2014-10-10 11:37   ` Eric Dumazet

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=1412918694-22882-5-git-send-email-edumazet@google.com \
    --to=edumazet@google.com \
    --cc=alexander.h.duyck@redhat.com \
    --cc=andreslc@google.com \
    --cc=davem@davemloft.net \
    --cc=gthelen@google.com \
    --cc=hughd@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=rientjes@google.com \
    /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).