* [PATCH net 0/5] net: fix races accessing page->_count
@ 2014-10-10 5:24 Eric Dumazet
2014-10-10 5:24 ` [PATCH net 1/5] fm10k: fix race " Eric Dumazet
` (6 more replies)
0 siblings, 7 replies; 14+ messages in thread
From: Eric Dumazet @ 2014-10-10 5:24 UTC (permalink / raw)
To: David S. Miller
Cc: netdev, Alexander Duyck, Andres Lagar-Cavilla, Greg Thelen,
Hugh Dickins, David Rientjes, Eric Dumazet
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.
The only case it is valid is when page->_count is 0, we can use this in
__netdev_alloc_frag()
Note that I never seen crashes caused by these races, the issue was reported
by Andres Lagar-Cavilla and Hugh Dickins.
Eric Dumazet (5):
fm10k: fix race accessing page->_count
igb: fix race accessing page->_count
igb: fix race accessing page->_count
mlx4: fix race accessing page->_count
net: fix races in page->_count manipulation
drivers/net/ethernet/intel/fm10k/fm10k_main.c | 7 +++----
drivers/net/ethernet/intel/igb/igb_main.c | 7 +++----
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 8 +++-----
drivers/net/ethernet/mellanox/mlx4/en_rx.c | 6 +++---
net/core/skbuff.c | 25 ++++++++++++++++++-------
5 files changed, 30 insertions(+), 23 deletions(-)
--
2.1.0.rc2.206.gedb03e5
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net 1/5] fm10k: fix race accessing page->_count
2014-10-10 5:24 [PATCH net 0/5] net: fix races accessing page->_count Eric Dumazet
@ 2014-10-10 5:24 ` Eric Dumazet
2014-10-10 5:53 ` Jeff Kirsher
2014-10-10 5:24 ` [PATCH net 2/5] igb: " Eric Dumazet
` (5 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Eric Dumazet @ 2014-10-10 5:24 UTC (permalink / raw)
To: David S. Miller
Cc: netdev, Alexander Duyck, Andres Lagar-Cavilla, Greg Thelen,
Hugh Dickins, David Rientjes, Eric Dumazet
This is illegal to use atomic_set(&page->_count, 2) 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/intel/fm10k/fm10k_main.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_main.c b/drivers/net/ethernet/intel/fm10k/fm10k_main.c
index 6c800a330d66..9d7118a0d67a 100644
--- a/drivers/net/ethernet/intel/fm10k/fm10k_main.c
+++ b/drivers/net/ethernet/intel/fm10k/fm10k_main.c
@@ -219,11 +219,10 @@ static bool fm10k_can_reuse_rx_page(struct fm10k_rx_buffer *rx_buffer,
/* flip page offset to other buffer */
rx_buffer->page_offset ^= FM10K_RX_BUFSZ;
- /* since we are the only owner of the page and we need to
- * increment it, just set the value to 2 in order to avoid
- * an unnecessary locked operation
+ /* Even if we own the page, we are not allowed to use atomic_set()
+ * This would break get_page_unless_zero() users.
*/
- atomic_set(&page->_count, 2);
+ atomic_inc(&page->_count);
#else
/* move offset up to the next cache line */
rx_buffer->page_offset += truesize;
--
2.1.0.rc2.206.gedb03e5
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net 2/5] igb: fix race accessing page->_count
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:24 ` Eric Dumazet
2014-10-10 5:55 ` Jeff Kirsher
2014-10-10 5:24 ` [PATCH net 3/5] " Eric Dumazet
` (4 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Eric Dumazet @ 2014-10-10 5:24 UTC (permalink / raw)
To: David S. Miller
Cc: netdev, Alexander Duyck, Andres Lagar-Cavilla, Greg Thelen,
Hugh Dickins, David Rientjes, Eric Dumazet
This is illegal to use atomic_set(&page->_count, 2) 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/intel/igb/igb_main.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index ae59c0b108c5..a21b14495ebd 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -6545,11 +6545,10 @@ static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer,
/* flip page offset to other buffer */
rx_buffer->page_offset ^= IGB_RX_BUFSZ;
- /* since we are the only owner of the page and we need to
- * increment it, just set the value to 2 in order to avoid
- * an unnecessary locked operation
+ /* Even if we own the page, we are not allowed to use atomic_set()
+ * This would break get_page_unless_zero() users.
*/
- atomic_set(&page->_count, 2);
+ atomic_inc(&page->_count);
#else
/* move offset up to the next cache line */
rx_buffer->page_offset += truesize;
--
2.1.0.rc2.206.gedb03e5
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net 3/5] igb: fix race accessing page->_count
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:24 ` [PATCH net 2/5] igb: " Eric Dumazet
@ 2014-10-10 5:24 ` Eric Dumazet
2014-10-10 5:54 ` Jeff Kirsher
2014-10-10 5:24 ` [PATCH net 4/5] mlx4: " Eric Dumazet
` (3 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Eric Dumazet @ 2014-10-10 5:24 UTC (permalink / raw)
To: David S. Miller
Cc: netdev, Alexander Duyck, Andres Lagar-Cavilla, Greg Thelen,
Hugh Dickins, David Rientjes, Eric Dumazet
This is illegal to use atomic_set(&page->_count, 2) 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/intel/ixgbe/ixgbe_main.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index d677b5a23b58..fec5212d4337 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -1865,12 +1865,10 @@ static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
/* flip page offset to other buffer */
rx_buffer->page_offset ^= truesize;
- /*
- * since we are the only owner of the page and we need to
- * increment it, just set the value to 2 in order to avoid
- * an unecessary locked operation
+ /* Even if we own the page, we are not allowed to use atomic_set()
+ * This would break get_page_unless_zero() users.
*/
- atomic_set(&page->_count, 2);
+ atomic_inc(&page->_count);
#else
/* move offset up to the next cache line */
rx_buffer->page_offset += truesize;
--
2.1.0.rc2.206.gedb03e5
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net 4/5] mlx4: fix race accessing page->_count
2014-10-10 5:24 [PATCH net 0/5] net: fix races accessing page->_count Eric Dumazet
` (2 preceding siblings ...)
2014-10-10 5:24 ` [PATCH net 3/5] " Eric Dumazet
@ 2014-10-10 5:24 ` Eric Dumazet
2014-10-10 5:24 ` [PATCH net 5/5] net: fix races in page->_count manipulation Eric Dumazet
` (2 subsequent siblings)
6 siblings, 0 replies; 14+ messages in thread
From: Eric Dumazet @ 2014-10-10 5:24 UTC (permalink / raw)
To: David S. Miller
Cc: netdev, Alexander Duyck, Andres Lagar-Cavilla, Greg Thelen,
Hugh Dickins, David Rientjes, Eric Dumazet
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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net 5/5] net: fix races in page->_count manipulation
2014-10-10 5:24 [PATCH net 0/5] net: fix races accessing page->_count Eric Dumazet
` (3 preceding siblings ...)
2014-10-10 5:24 ` [PATCH net 4/5] mlx4: " Eric Dumazet
@ 2014-10-10 5:24 ` Eric Dumazet
2014-10-10 5:37 ` [PATCH net 0/5] net: fix races accessing page->_count Jeff Kirsher
2014-10-10 10:02 ` David Laight
6 siblings, 0 replies; 14+ messages in thread
From: Eric Dumazet @ 2014-10-10 5:24 UTC (permalink / raw)
To: David S. Miller
Cc: netdev, Alexander Duyck, Andres Lagar-Cavilla, Greg Thelen,
Hugh Dickins, David Rientjes, Eric Dumazet
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.
The only case it is valid is when page->_count is 0
Fixes: 540eb7bf0bbed ("net: Update alloc frag to reduce get/put page usage and recycle pages")
Signed-off-by: Eric Dumaze <edumazet@google.com>
---
net/core/skbuff.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index a30d750647e7..829d013745ab 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -360,18 +360,29 @@ refill:
goto end;
}
nc->frag.size = PAGE_SIZE << order;
-recycle:
- atomic_set(&nc->frag.page->_count, NETDEV_PAGECNT_MAX_BIAS);
+ /* Even if we own the page, we do not use atomic_set().
+ * This would break get_page_unless_zero() users.
+ */
+ atomic_add(NETDEV_PAGECNT_MAX_BIAS - 1,
+ &nc->frag.page->_count);
nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
nc->frag.offset = 0;
}
if (nc->frag.offset + fragsz > nc->frag.size) {
- /* avoid unnecessary locked operations if possible */
- if ((atomic_read(&nc->frag.page->_count) == nc->pagecnt_bias) ||
- atomic_sub_and_test(nc->pagecnt_bias, &nc->frag.page->_count))
- goto recycle;
- goto refill;
+ if (atomic_read(&nc->frag.page->_count) != nc->pagecnt_bias) {
+ if (!atomic_sub_and_test(nc->pagecnt_bias,
+ &nc->frag.page->_count))
+ goto refill;
+ /* OK, page count is 0, we can safely set it */
+ atomic_set(&nc->frag.page->_count,
+ NETDEV_PAGECNT_MAX_BIAS);
+ } else {
+ atomic_add(NETDEV_PAGECNT_MAX_BIAS - nc->pagecnt_bias,
+ &nc->frag.page->_count);
+ }
+ nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
+ nc->frag.offset = 0;
}
data = page_address(nc->frag.page) + nc->frag.offset;
--
2.1.0.rc2.206.gedb03e5
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH net 0/5] net: fix races accessing page->_count
2014-10-10 5:24 [PATCH net 0/5] net: fix races accessing page->_count Eric Dumazet
` (4 preceding siblings ...)
2014-10-10 5:24 ` [PATCH net 5/5] net: fix races in page->_count manipulation Eric Dumazet
@ 2014-10-10 5:37 ` Jeff Kirsher
2014-10-10 5:42 ` Eric Dumazet
2014-10-10 10:02 ` David Laight
6 siblings, 1 reply; 14+ messages in thread
From: Jeff Kirsher @ 2014-10-10 5:37 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, netdev, Alexander Duyck, Andres Lagar-Cavilla,
Greg Thelen, Hugh Dickins, David Rientjes
On Thu, Oct 9, 2014 at 10:24 PM, Eric Dumazet <edumazet@google.com> wrote:
> 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.
>
> The only case it is valid is when page->_count is 0, we can use this in
> __netdev_alloc_frag()
>
> Note that I never seen crashes caused by these races, the issue was reported
> by Andres Lagar-Cavilla and Hugh Dickins.
>
> Eric Dumazet (5):
> fm10k: fix race accessing page->_count
> igb: fix race accessing page->_count
> igb: fix race accessing page->_count
Looks like the ixgbe patch has the incorrect title, or you patch igb twice. :-)
> mlx4: fix race accessing page->_count
> net: fix races in page->_count manipulation
>
> drivers/net/ethernet/intel/fm10k/fm10k_main.c | 7 +++----
> drivers/net/ethernet/intel/igb/igb_main.c | 7 +++----
> drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 8 +++-----
> drivers/net/ethernet/mellanox/mlx4/en_rx.c | 6 +++---
> net/core/skbuff.c | 25 ++++++++++++++++++-------
> 5 files changed, 30 insertions(+), 23 deletions(-)
>
> --
> 2.1.0.rc2.206.gedb03e5
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Cheers,
Jeff
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net 0/5] net: fix races accessing page->_count
2014-10-10 5:37 ` [PATCH net 0/5] net: fix races accessing page->_count Jeff Kirsher
@ 2014-10-10 5:42 ` Eric Dumazet
0 siblings, 0 replies; 14+ messages in thread
From: Eric Dumazet @ 2014-10-10 5:42 UTC (permalink / raw)
To: Jeff Kirsher
Cc: Eric Dumazet, David S. Miller, netdev, Alexander Duyck,
Andres Lagar-Cavilla, Greg Thelen, Hugh Dickins, David Rientjes
On Thu, 2014-10-09 at 22:37 -0700, Jeff Kirsher wrote:
> Looks like the ixgbe patch has the incorrect title, or you patch igb twice. :-)
Yes, typo in the title, but content is OK, sorry.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net 1/5] fm10k: fix race accessing page->_count
2014-10-10 5:24 ` [PATCH net 1/5] fm10k: fix race " Eric Dumazet
@ 2014-10-10 5:53 ` Jeff Kirsher
0 siblings, 0 replies; 14+ messages in thread
From: Jeff Kirsher @ 2014-10-10 5:53 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, netdev, Alexander Duyck, Andres Lagar-Cavilla,
Greg Thelen, Hugh Dickins, David Rientjes
On Thu, Oct 9, 2014 at 10:24 PM, Eric Dumazet <edumazet@google.com> wrote:
> This is illegal to use atomic_set(&page->_count, 2) 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>
Acked-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Since this is apart of a series, if the changes to skbuff are ok, then
the changes to the Intel drivers are ok.
> ---
> drivers/net/ethernet/intel/fm10k/fm10k_main.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_main.c b/drivers/net/ethernet/intel/fm10k/fm10k_main.c
> index 6c800a330d66..9d7118a0d67a 100644
> --- a/drivers/net/ethernet/intel/fm10k/fm10k_main.c
> +++ b/drivers/net/ethernet/intel/fm10k/fm10k_main.c
> @@ -219,11 +219,10 @@ static bool fm10k_can_reuse_rx_page(struct fm10k_rx_buffer *rx_buffer,
> /* flip page offset to other buffer */
> rx_buffer->page_offset ^= FM10K_RX_BUFSZ;
>
> - /* since we are the only owner of the page and we need to
> - * increment it, just set the value to 2 in order to avoid
> - * an unnecessary locked operation
> + /* Even if we own the page, we are not allowed to use atomic_set()
> + * This would break get_page_unless_zero() users.
> */
> - atomic_set(&page->_count, 2);
> + atomic_inc(&page->_count);
> #else
> /* move offset up to the next cache line */
> rx_buffer->page_offset += truesize;
> --
> 2.1.0.rc2.206.gedb03e5
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Cheers,
Jeff
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net 3/5] igb: fix race accessing page->_count
2014-10-10 5:24 ` [PATCH net 3/5] " Eric Dumazet
@ 2014-10-10 5:54 ` Jeff Kirsher
0 siblings, 0 replies; 14+ messages in thread
From: Jeff Kirsher @ 2014-10-10 5:54 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, netdev, Alexander Duyck, Andres Lagar-Cavilla,
Greg Thelen, Hugh Dickins, David Rientjes
On Thu, Oct 9, 2014 at 10:24 PM, Eric Dumazet <edumazet@google.com> wrote:
> This is illegal to use atomic_set(&page->_count, 2) 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>
Change the title to :ixgbe: ...", then you have my ACK.
Acked-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Since this is apart of a series, if the changes to skbuff are ok, then
the changes to the Intel drivers are ok.
> ---
> drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> index d677b5a23b58..fec5212d4337 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> @@ -1865,12 +1865,10 @@ static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
> /* flip page offset to other buffer */
> rx_buffer->page_offset ^= truesize;
>
> - /*
> - * since we are the only owner of the page and we need to
> - * increment it, just set the value to 2 in order to avoid
> - * an unecessary locked operation
> + /* Even if we own the page, we are not allowed to use atomic_set()
> + * This would break get_page_unless_zero() users.
> */
> - atomic_set(&page->_count, 2);
> + atomic_inc(&page->_count);
> #else
> /* move offset up to the next cache line */
> rx_buffer->page_offset += truesize;
> --
> 2.1.0.rc2.206.gedb03e5
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Cheers,
Jeff
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net 2/5] igb: fix race accessing page->_count
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
0 siblings, 1 reply; 14+ messages in thread
From: Jeff Kirsher @ 2014-10-10 5:55 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, netdev, Alexander Duyck, Andres Lagar-Cavilla,
Greg Thelen, Hugh Dickins, David Rientjes
On Thu, Oct 9, 2014 at 10:24 PM, Eric Dumazet <edumazet@google.com> wrote:
> This is illegal to use atomic_set(&page->_count, 2) 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>
Acked-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Since this is apart of a series, if the changes to skbuff are ok, then
the changes to the Intel drivers are ok.
> ---
> drivers/net/ethernet/intel/igb/igb_main.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
> index ae59c0b108c5..a21b14495ebd 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -6545,11 +6545,10 @@ static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer,
> /* flip page offset to other buffer */
> rx_buffer->page_offset ^= IGB_RX_BUFSZ;
>
> - /* since we are the only owner of the page and we need to
> - * increment it, just set the value to 2 in order to avoid
> - * an unnecessary locked operation
> + /* Even if we own the page, we are not allowed to use atomic_set()
> + * This would break get_page_unless_zero() users.
> */
> - atomic_set(&page->_count, 2);
> + atomic_inc(&page->_count);
> #else
> /* move offset up to the next cache line */
> rx_buffer->page_offset += truesize;
> --
> 2.1.0.rc2.206.gedb03e5
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Cheers,
Jeff
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [PATCH net 0/5] net: fix races accessing page->_count
2014-10-10 5:24 [PATCH net 0/5] net: fix races accessing page->_count Eric Dumazet
` (5 preceding siblings ...)
2014-10-10 5:37 ` [PATCH net 0/5] net: fix races accessing page->_count Jeff Kirsher
@ 2014-10-10 10:02 ` David Laight
2014-10-10 11:37 ` Eric Dumazet
6 siblings, 1 reply; 14+ messages in thread
From: David Laight @ 2014-10-10 10:02 UTC (permalink / raw)
To: 'Eric Dumazet', David S. Miller
Cc: netdev@vger.kernel.org, Alexander Duyck, Andres Lagar-Cavilla,
Greg Thelen, Hugh Dickins, David Rientjes
From: Eric Dumazet
> 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.
Plausibly the atomic_inc() could be avoided by allocating the page
with multiple references, or by gabbing a lot of extra references
and keeping a local count of when they are 'used' (by passing
ownership onwards).
David
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net 0/5] net: fix races accessing page->_count
2014-10-10 10:02 ` David Laight
@ 2014-10-10 11:37 ` Eric Dumazet
0 siblings, 0 replies; 14+ messages in thread
From: Eric Dumazet @ 2014-10-10 11:37 UTC (permalink / raw)
To: David Laight
Cc: 'Eric Dumazet', David S. Miller, netdev@vger.kernel.org,
Alexander Duyck, Andres Lagar-Cavilla, Greg Thelen, Hugh Dickins,
David Rientjes
On Fri, 2014-10-10 at 10:02 +0000, David Laight wrote:
> From: Eric Dumazet
> > 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.
>
> Plausibly the atomic_inc() could be avoided by allocating the page
> with multiple references, or by gabbing a lot of extra references
> and keeping a local count of when they are 'used' (by passing
> ownership onwards).
Well, this is the idea already in place.
I assume you read __netdev_alloc_frag() ?
Note this is a fix, and a fix should be minimal and obvious.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net 2/5] igb: fix race accessing page->_count
2014-10-10 5:55 ` Jeff Kirsher
@ 2014-10-10 11:47 ` Eric Dumazet
0 siblings, 0 replies; 14+ messages in thread
From: Eric Dumazet @ 2014-10-10 11:47 UTC (permalink / raw)
To: Jeff Kirsher
Cc: Eric Dumazet, David S. Miller, netdev, Alexander Duyck,
Andres Lagar-Cavilla, Greg Thelen, Hugh Dickins, David Rientjes
On Thu, 2014-10-09 at 22:55 -0700, Jeff Kirsher wrote:
> On Thu, Oct 9, 2014 at 10:24 PM, Eric Dumazet <edumazet@google.com> wrote:
> > This is illegal to use atomic_set(&page->_count, 2) 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>
>
> Acked-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
>
> Since this is apart of a series, if the changes to skbuff are ok, then
> the changes to the Intel drivers are ok.
Thanks Jeff, I am sending v2 including your Acked-by and ixgbe title
fix.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2014-10-10 11:47 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH net 4/5] mlx4: " Eric Dumazet
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
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).