net: fec: add wmb to ensure correct descriptor values
Shenwei Wang
reviewerPATCH v2 1/1 net: fec: add wmb to ensure correct descriptor values
Two wmb() are added in the XDP TX path to ensure proper ordering of descriptor and buffer updates:
1. A wmb() is added after updating the last BD to make sure the updates to rest of the descriptor are visible before transferring ownership to FEC.
2. A wmb() is also added after updating the tx_skbuff and bdp to ensure these updates are visible before updating txq->bd.cur.
3. Start the xmit of the frame immediately right after configuring the tx descriptor.
---
v2:
- update the inline comments for 2nd wmb per Wei Fang's review.
drivers/net/ethernet/freescale/fec_main.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +11 -6
@@ -3834,6 +3834,11 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, index =fec_enet_get_bd_index (last_bdp, &txq->bd); txq->tx_skbuff[index] =NULL ; +/* Make sure the updates to rest of the descriptor are performed before +* transferring ownership. +*/ +wmb (); +/* Send it on its way. Tell FEC it's ready, interrupt when done, * it's the last BD of the frame, and to put the CRC on the end. */
@@ -3843,8 +3848,14 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep,/* If this was the last BD in the ring, start at the beginning again. */ bdp =fec_enet_get_nextdesc (last_bdp, &txq->bd); +/* Make sure the update to bdp are performed before txq->bd.cur. */ +wmb (); + txq->bd.cur = bdp; +/* Trigger transmission start */ +writel (0 , txq->bd.reg_desc_active); +return 0 ; }
@@ -3873,12 +3884,6 @@ static int fec_enet_xdp_xmit(struct net_device *dev, sent_frames++; } -/* Make sure the update to bdp and tx_skbuff are performed. */ -wmb (); - -/* Trigger transmission start */ -writel (0 , txq->bd.reg_desc_active); -__netif_tx_unlock (nq);return sent_frames;
--
2.34.1
Quoted 36 lines · Shenwei Wang
Two
wmb()are added in the XDP TX path to ensure proper ordering of descriptor and buffer updates:
1. Awmb()is added after updating the last BD to make sure the updates to rest of the descriptor are visible before transferring ownership to FEC.
2. Awmb()is also added after updating thetx_skbuffand bdp to ensure these updates are visible before updatingtxq->bd.cur.
3. Start the xmit of the frame immediately right after configuring the tx descriptor.Fixes 6d6b39f180b8 ("net: fec: add initial XDP support")Signed-off-by Shenwei Wang <[email protected]>---
v2:
- update the inline comments for 2nd wmb per Wei Fang's review.drivers/net/ethernet/freescale/fec_main.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)drivers/net/ethernet/freescale/fec_main.c +5
-0@@ -3834,6 +3834,11 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, index =fec_enet_get_bd_index (last_bdp, &txq->bd); txq->tx_skbuff[index] =NULL ; +/* Make sure the updates to rest of the descriptor are performed before +* transferring ownership. +*/ +wmb (); +/* Send it on its way. Tell FEC it's ready, interrupt when done, * it's the last BD of the frame, and to put the CRC on the end. */
drivers/net/ethernet/freescale/fec_main.c static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, · line 3853
Quoted 6 lines
drivers/net/ethernet/freescale/fec_main.c +3
-0@@ -3843,8 +3848,14 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep,/* If this was the last BD in the ring, start at the beginning again. */ bdp =fec_enet_get_nextdesc (last_bdp, &txq->bd); +/* Make sure the update to bdp are performed before txq->bd.cur. */ +wmb (); +
Do you really need wmb() here or would a more light-weight smp_wmb() or dma_wmb() be sufficient?
Quoted 25 lines
drivers/net/ethernet/freescale/fec_main.c +3
-7txq->bd.cur = bdp; +/* Trigger transmission start */ +writel (0 , txq->bd.reg_desc_active); +return 0 ; }@@ -3873,12 +3884,6 @@ static int fec_enet_xdp_xmit(struct net_device *dev, sent_frames++; } -/* Make sure the update to bdp and tx_skbuff are performed. */ -wmb (); - -/* Trigger transmission start */ -writel (0 , txq->bd.reg_desc_active); -__netif_tx_unlock (nq);return sent_frames; --2.34.1
Shenwei Wang
reviewerQuoted 63 lines
-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: Wednesday, May 17, 2023 2:14 PM
To: Shenwei Wang <[email protected]>; Wei Fang <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Simon Horman <[email protected]>; Horatiu Vultur <[email protected]>
Cc: Clark Wang <[email protected]>; dl-linux-imx <[email protected]>; [email protected]; [email protected]
Subject: [EXT] Re: [PATCH v2 net] net: fec: add wmb to ensure correct descriptor valuesCaution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button
drivers/net/ethernet/freescale/fec_main.c static int fec_enet_txq_xmit_frame(struct
Quoted 25 lines · Shenwei Wang
Two
wmb()are added in the XDP TX path to ensure proper ordering of descriptor and buffer updates:
1. Awmb()is added after updating the last BD to make sure the updates to rest of the descriptor are visible before transferring ownership to FEC.
2. Awmb()is also added after updating thetx_skbuffand bdp to ensure these updates are visible before updatingtxq->bd.cur.
3. Start the xmit of the frame immediately right after configuring the tx descriptor.Fixes 6d6b39f180b8 ("net: fec: add initial XDP support")Signed-off-by Shenwei Wang <[email protected]>---
v2:
- update the inline comments for 2nd wmb per Wei Fang's review.drivers/net/ethernet/freescale/fec_main.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)drivers/net/ethernet/freescale/fec_main.c +0
-0@@ -3834,6 +3834,11 @@ static int fec_enet_txq_xmit_frame(struct
fec_enet_private*fep,drivers/net/ethernet/freescale/fec_main.c static int fec_enet_txq_xmit_frame(struct
Quoted 12 lines
drivers/net/ethernet/freescale/fec_main.c +5
-0index =fec_enet_get_bd_index (last_bdp, &txq->bd); txq->tx_skbuff[index] =NULL ; +/* Make sure the updates to rest of the descriptor are performed before +* transferring ownership. +*/ +wmb (); +/* Send it on its way. Tell FEC it's ready, interrupt when done, * it's the last BD of the frame, and to put the CRC on the end. */ @@ -3843,8 +3848,14 @@ static int fec_enet_txq_xmit_frame(struct
fec_enet_private*fep,Quoted 3 lines
drivers/net/ethernet/freescale/fec_main.c +0
-0/* If this was the last BD in the ring, start at the beginning again. */ bdp =fec_enet_get_nextdesc (last_bdp, &txq->bd);
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, · line 3853
Quoted 3 lines
drivers/net/ethernet/freescale/fec_main.c +3
-0+/* Make sure the update to bdp are performed before txq->bd.cur. */ +wmb (); +Do you really need
wmb()here or would a more light-weightsmp_wmb()ordma_wmb()be sufficient?
In this case, both wmb should be changed to dma_wmb.
Regards,
Shenwei
Quoted 26 lines
drivers/net/ethernet/freescale/fec_main.c static int fec_enet_xdp_xmit(struct net_device
Quoted 9 lines
drivers/net/ethernet/freescale/fec_main.c +3
-0txq->bd.cur = bdp; +/* Trigger transmission start */ +writel (0 , txq->bd.reg_desc_active); +return 0 ; }@@ -3873,12 +3884,6 @@ static int fec_enet_xdp_xmit(struct net_device*dev,
Quoted 16 lines
drivers/net/ethernet/freescale/fec_main.c +0
-7sent_frames++; } -/* Make sure the update to bdp and tx_skbuff are performed. */ -wmb (); - -/* Trigger transmission start */ -writel (0 , txq->bd.reg_desc_active); -__netif_tx_unlock (nq);return sent_frames; --2.34.1