linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ethernet: ftgmac100: Fix DMA coherency issue with SW checksum
@ 2019-10-25  2:47 Benjamin Herrenschmidt
  2019-10-25 19:11 ` Vijay Khemka
  2019-10-28 23:24 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Benjamin Herrenschmidt @ 2019-10-25  2:47 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, linux-kernel, Vijay Khemka, openbmc, Joel Stanley, linux-aspeed

We are calling the checksum helper after the dma_map_single()
call to map the packet. This is incorrect as the checksumming
code will touch the packet from the CPU. This means the cache
won't be properly flushes (or the bounce buffering will leave
us with the unmodified packet to DMA).

This moves the calculation of the checksum & vlan tags to
before the DMA mapping.

This also has the side effect of fixing another bug: If the
checksum helper fails, we goto "drop" to drop the packet, which
will not unmap the DMA mapping.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Fixes: 05690d633f30 ftgmac100: Upgrade to NETIF_F_HW_CSUM
CC: stable@vger.kernel.org [v4.12+]
---
 drivers/net/ethernet/faraday/ftgmac100.c | 25 ++++++++++++------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index 9b7af94a40bb..96e9565f1e08 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -727,6 +727,18 @@ static netdev_tx_t ftgmac100_hard_start_xmit(struct sk_buff *skb,
 	 */
 	nfrags = skb_shinfo(skb)->nr_frags;
 
+	/* Setup HW checksumming */
+	csum_vlan = 0;
+	if (skb->ip_summed == CHECKSUM_PARTIAL &&
+	    !ftgmac100_prep_tx_csum(skb, &csum_vlan))
+		goto drop;
+
+	/* Add VLAN tag */
+	if (skb_vlan_tag_present(skb)) {
+		csum_vlan |= FTGMAC100_TXDES1_INS_VLANTAG;
+		csum_vlan |= skb_vlan_tag_get(skb) & 0xffff;
+	}
+
 	/* Get header len */
 	len = skb_headlen(skb);
 
@@ -753,19 +765,6 @@ static netdev_tx_t ftgmac100_hard_start_xmit(struct sk_buff *skb,
 	if (nfrags == 0)
 		f_ctl_stat |= FTGMAC100_TXDES0_LTS;
 	txdes->txdes3 = cpu_to_le32(map);
-
-	/* Setup HW checksumming */
-	csum_vlan = 0;
-	if (skb->ip_summed == CHECKSUM_PARTIAL &&
-	    !ftgmac100_prep_tx_csum(skb, &csum_vlan))
-		goto drop;
-
-	/* Add VLAN tag */
-	if (skb_vlan_tag_present(skb)) {
-		csum_vlan |= FTGMAC100_TXDES1_INS_VLANTAG;
-		csum_vlan |= skb_vlan_tag_get(skb) & 0xffff;
-	}
-
 	txdes->txdes1 = cpu_to_le32(csum_vlan);
 
 	/* Next descriptor */



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: ethernet: ftgmac100: Fix DMA coherency issue with SW checksum
  2019-10-25  2:47 [PATCH] net: ethernet: ftgmac100: Fix DMA coherency issue with SW checksum Benjamin Herrenschmidt
@ 2019-10-25 19:11 ` Vijay Khemka
  2019-10-28 23:24 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: Vijay Khemka @ 2019-10-25 19:11 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, David S. Miller
  Cc: netdev, linux-kernel, openbmc, Joel Stanley, linux-aspeed

Looks good to me. And I have tested it. It works perfectly fine.

Reviewed-by: Vijay Khemka <vijaykhemka@fb.com>
Tested-by: Vijay Khemka <vijaykhemka@fb.com>

On 10/24/19, 7:47 PM, "Benjamin Herrenschmidt" <benh@kernel.crashing.org> wrote:

    We are calling the checksum helper after the dma_map_single()
    call to map the packet. This is incorrect as the checksumming
    code will touch the packet from the CPU. This means the cache
    won't be properly flushes (or the bounce buffering will leave
    us with the unmodified packet to DMA).
    
    This moves the calculation of the checksum & vlan tags to
    before the DMA mapping.
    
    This also has the side effect of fixing another bug: If the
    checksum helper fails, we goto "drop" to drop the packet, which
    will not unmap the DMA mapping.
    
    Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
    Fixes: 05690d633f30 ftgmac100: Upgrade to NETIF_F_HW_CSUM
    CC: stable@vger.kernel.org [v4.12+]
    ---
     drivers/net/ethernet/faraday/ftgmac100.c | 25 ++++++++++++------------
     1 file changed, 12 insertions(+), 13 deletions(-)
    
    diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
    index 9b7af94a40bb..96e9565f1e08 100644
    --- a/drivers/net/ethernet/faraday/ftgmac100.c
    +++ b/drivers/net/ethernet/faraday/ftgmac100.c
    @@ -727,6 +727,18 @@ static netdev_tx_t ftgmac100_hard_start_xmit(struct sk_buff *skb,
     	 */
     	nfrags = skb_shinfo(skb)->nr_frags;
     
    +	/* Setup HW checksumming */
    +	csum_vlan = 0;
    +	if (skb->ip_summed == CHECKSUM_PARTIAL &&
    +	    !ftgmac100_prep_tx_csum(skb, &csum_vlan))
    +		goto drop;
    +
    +	/* Add VLAN tag */
    +	if (skb_vlan_tag_present(skb)) {
    +		csum_vlan |= FTGMAC100_TXDES1_INS_VLANTAG;
    +		csum_vlan |= skb_vlan_tag_get(skb) & 0xffff;
    +	}
    +
     	/* Get header len */
     	len = skb_headlen(skb);
     
    @@ -753,19 +765,6 @@ static netdev_tx_t ftgmac100_hard_start_xmit(struct sk_buff *skb,
     	if (nfrags == 0)
     		f_ctl_stat |= FTGMAC100_TXDES0_LTS;
     	txdes->txdes3 = cpu_to_le32(map);
    -
    -	/* Setup HW checksumming */
    -	csum_vlan = 0;
    -	if (skb->ip_summed == CHECKSUM_PARTIAL &&
    -	    !ftgmac100_prep_tx_csum(skb, &csum_vlan))
    -		goto drop;
    -
    -	/* Add VLAN tag */
    -	if (skb_vlan_tag_present(skb)) {
    -		csum_vlan |= FTGMAC100_TXDES1_INS_VLANTAG;
    -		csum_vlan |= skb_vlan_tag_get(skb) & 0xffff;
    -	}
    -
     	txdes->txdes1 = cpu_to_le32(csum_vlan);
     
     	/* Next descriptor */
    
    
    


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: ethernet: ftgmac100: Fix DMA coherency issue with SW checksum
  2019-10-25  2:47 [PATCH] net: ethernet: ftgmac100: Fix DMA coherency issue with SW checksum Benjamin Herrenschmidt
  2019-10-25 19:11 ` Vijay Khemka
@ 2019-10-28 23:24 ` David Miller
  2019-10-30  1:53   ` Benjamin Herrenschmidt
  1 sibling, 1 reply; 4+ messages in thread
From: David Miller @ 2019-10-28 23:24 UTC (permalink / raw)
  To: benh; +Cc: netdev, linux-kernel, vijaykhemka, openbmc, joel, linux-aspeed

From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: Fri, 25 Oct 2019 13:47:24 +1100

> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Fixes: 05690d633f30 ftgmac100: Upgrade to NETIF_F_HW_CSUM

Please put the commit header string inside double quotes and parenthesis
(" ")

> CC: stable@vger.kernel.org [v4.12+]

Do not CC: stable for networking submissions as per the netdev FAQ.

All fixed up, and queued up for -stable, thanks Ben.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: ethernet: ftgmac100: Fix DMA coherency issue with SW checksum
  2019-10-28 23:24 ` David Miller
@ 2019-10-30  1:53   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 4+ messages in thread
From: Benjamin Herrenschmidt @ 2019-10-30  1:53 UTC (permalink / raw)
  To: David Miller
  Cc: netdev, linux-kernel, vijaykhemka, openbmc, joel, linux-aspeed

On Mon, 2019-10-28 at 16:24 -0700, David Miller wrote:
> From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Date: Fri, 25 Oct 2019 13:47:24 +1100
> 
> > Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> > Fixes: 05690d633f30 ftgmac100: Upgrade to NETIF_F_HW_CSUM
> 
> Please put the commit header string inside double quotes and
> parenthesis
> (" ")

Will do next time, I had just copy/pasted the git shortlog :-)

> > CC: stable@vger.kernel.org [v4.12+]
> 
> Do not CC: stable for networking submissions as per the netdev FAQ.

Ah oops, learned.

> All fixed up, and queued up for -stable, thanks Ben.

Thanks.

Cheers,
Ben.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-30  1:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-25  2:47 [PATCH] net: ethernet: ftgmac100: Fix DMA coherency issue with SW checksum Benjamin Herrenschmidt
2019-10-25 19:11 ` Vijay Khemka
2019-10-28 23:24 ` David Miller
2019-10-30  1:53   ` Benjamin Herrenschmidt

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).