* [PATCH net-next 01/12] tg3: Enforce DMA mapping / skb assignment ordering
@ 2010-02-18 1:16 Matt Carlson
2010-02-18 1:27 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Matt Carlson @ 2010-02-18 1:16 UTC (permalink / raw)
To: davem; +Cc: netdev, andy, mcarlson, Michael Chan
Michael Chan noted that there is nothing in the code that would prevent
the compiler from delaying the access of the "mapping" member of the
newly arrived packet until much later. If this happened after the
skb = NULL assignment, it is possible for the driver to pass a bad
dma_addr value to pci_unmap_single(). To enforce this ordering, we need
a write memory barrier. The pairing read memory barrier already exists
in tg3_rx_prodring_xfer() under the comments starting with
"Ensure that updates to the...".
Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
Signed-off-by: Michael Chan <mchan@broadcom.com>
---
drivers/net/tg3.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 385434f..344490e 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -4659,11 +4659,16 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
if (skb_size < 0)
goto drop_it;
- ri->skb = NULL;
-
pci_unmap_single(tp->pdev, dma_addr, skb_size,
PCI_DMA_FROMDEVICE);
+ /* Ensure that the update to the skb happens
+ * after the usage of the old DMA mapping.
+ */
+ smp_wmb();
+
+ ri->skb = NULL;
+
skb_put(skb, len);
} else {
struct sk_buff *copy_skb;
--
1.6.4.4
---
drivers/net/tg3.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 385434f..344490e 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -4659,11 +4659,16 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
if (skb_size < 0)
goto drop_it;
- ri->skb = NULL;
-
pci_unmap_single(tp->pdev, dma_addr, skb_size,
PCI_DMA_FROMDEVICE);
+ /* Ensure that the update to the skb happens
+ * after the usage of the old DMA mapping.
+ */
+ smp_wmb();
+
+ ri->skb = NULL;
+
skb_put(skb, len);
} else {
struct sk_buff *copy_skb;
--
1.6.4.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next 01/12] tg3: Enforce DMA mapping / skb assignment ordering
2010-02-18 1:16 [PATCH net-next 01/12] tg3: Enforce DMA mapping / skb assignment ordering Matt Carlson
@ 2010-02-18 1:27 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2010-02-18 1:27 UTC (permalink / raw)
To: mcarlson; +Cc: netdev, andy, mchan
From: "Matt Carlson" <mcarlson@broadcom.com>
Date: Wed, 17 Feb 2010 17:16:54 -0800
You're providing the patch twice here:
> ---
> drivers/net/tg3.c | 9 +++++++--
> 1 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
> index 385434f..344490e 100644
> --- a/drivers/net/tg3.c
> +++ b/drivers/net/tg3.c
> @@ -4659,11 +4659,16 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
...
> --
> 1.6.4.4
...
> ---
> drivers/net/tg3.c | 9 +++++++--
> 1 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
> index 385434f..344490e 100644
> --- a/drivers/net/tg3.c
> +++ b/drivers/net/tg3.c
> @@ -4659,11 +4659,16 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
I'll fix this up but please make amends to ensure this doesn't
happen again.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-02-18 1:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-18 1:16 [PATCH net-next 01/12] tg3: Enforce DMA mapping / skb assignment ordering Matt Carlson
2010-02-18 1:27 ` David Miller
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).