From: Eric Dumazet <eric.dumazet@gmail.com>
To: Amir Vadai <amirv@mellanox.com>
Cc: netdev@vger.kernel.org, Or Gerlitz <ogerlitz@mellanox.com>,
Eugenia Emantayev <eugenia@mellanox.com>,
Eric Dumazet <edumazet@google.com>
Subject: Re: [PATCH net] net/mlx4_en: Fix pages never dma unmapped on rx
Date: Sun, 06 Oct 2013 07:22:52 -0700 [thread overview]
Message-ID: <1381069372.3564.68.camel@edumazet-glaptop.roam.corp.google.com> (raw)
In-Reply-To: <1381064240-12902-1-git-send-email-amirv@mellanox.com>
On Sun, 2013-10-06 at 14:57 +0200, Amir Vadai wrote:
> This patch fixes a bug introduced by commit 51151a16 (mlx4: allow
> order-0 memory allocations in RX path).
>
> dma_unmap_page never reached because condition to detect last fragment
> in page is wrong. offset+frag_stride can't be greater than size, need to
> make sure no additional frag will fit in page => compare offset +
> frag_stride + next_frag_size instead.
> next_frag_size could be next frag in the same skb, or the first frag in
> the next.
>
> CC: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Amir Vadai <amirv@mellanox.com>
> ---
> drivers/net/ethernet/mellanox/mlx4/en_rx.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
> index dec455c..44d8865 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
> @@ -131,8 +131,11 @@ static void mlx4_en_free_frag(struct mlx4_en_priv *priv,
> int i)
> {
> const struct mlx4_en_frag_info *frag_info = &priv->frag_info[i];
> + u16 next_frag_end = frags[i].offset + frag_info->frag_stride;
>
Hmm, could you make this an u32 ?
frags[i].offset and frags[i].size are u32
Maybe some folks want to use PAGE_SIZE=65536 or whatever high order
allocs
> - if (frags[i].offset + frag_info->frag_stride > frags[i].size)
> + next_frag_end += frags[(i + 1) % priv->num_frags].size;
> +
> + if (next_frag_end > frags[i].size)
> dma_unmap_page(priv->ddev, frags[i].dma, frags[i].size,
> PCI_DMA_FROMDEVICE);
>
Not sure I understand how this can work. How was this tested ?
frags[i + 1].size is the size of the page containing next fragment,
so now test should _always_ trigger.
(We could rename @size to @page_size to avoid confusion)
I think you meant to add the size of the next fragment ?
What about following instead (I also removed the divide operation)
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index dec455c..22444de 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -131,10 +131,17 @@ static void mlx4_en_free_frag(struct mlx4_en_priv *priv,
int i)
{
const struct mlx4_en_frag_info *frag_info = &priv->frag_info[i];
+ u32 next_frag_end = frags[i].offset + frag_info->frag_stride;
- if (frags[i].offset + frag_info->frag_stride > frags[i].size)
+ frag_info++;
+ if (i + 1 == priv->num_frags)
+ frag_info = &priv->frag_info[0];
+
+ next_frag_end += frag_info->frag_stride;
+
+ if (next_frag_end > frags[i].size)
dma_unmap_page(priv->ddev, frags[i].dma, frags[i].size,
- PCI_DMA_FROMDEVICE);
+ PCI_DMA_FROMDEVICE);
if (frags[i].page)
put_page(frags[i].page);
next prev parent reply other threads:[~2013-10-06 14:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-06 12:57 [PATCH net] net/mlx4_en: Fix pages never dma unmapped on rx Amir Vadai
2013-10-06 14:22 ` Eric Dumazet [this message]
2013-10-06 15:05 ` Amir Vadai
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=1381069372.3564.68.camel@edumazet-glaptop.roam.corp.google.com \
--to=eric.dumazet@gmail.com \
--cc=amirv@mellanox.com \
--cc=edumazet@google.com \
--cc=eugenia@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=ogerlitz@mellanox.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