net: enetc: fix some issues of XDP
Subsystems (6)
Wei Fang
maintainercover net: enetc: fix some issues of XDP
We found some bugs when testing the XDP function of enetc driver, and these bugs are easy to reproduce. This is not only causes XDP to not work, but also the network cannot be restored after exiting the XDP program. So the patch set is mainly to fix these bugs. For details, please see the commit message of each patch.
Wei Fang (3):
net: enetc: remove xdp_drops statistic from enetc_xdp_drop()
net: enetc: fix the issues of XDP_REDIRECT feature
net: enetc: reset xdp_tx_in_flight when updating bpf program
drivers/net/ethernet/freescale/enetc/enetc.c | 46 +++++++++++++++----- drivers/net/ethernet/freescale/enetc/enetc.h | 1 + 2 files changed, 37 insertions(+), 10 deletions(-)
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH 1/3 net: enetc: remove xdp_drops statistic from enetc_xdp_drop()
The xdp_drops statistic indicates the number of XDP frames dropped in the Rx direction. However, enetc_xdp_drop() is also used in XDP_TX and XDP_REDIRECT actions. If frame loss occurs in these two actions, the frames loss count should not be included in xdp_drops, because there are already xdp_tx_drops and xdp_redirect_failures to count the frame loss of these two actions, so it's better to remove xdp_drops statistic from enetc_xdp_drop() and increase xdp_drops in XDP_DROP action.
--- drivers/net/ethernet/freescale/enetc/enetc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/freescale/enetc/enetc.c +1 -1
@@ -1521,7 +1521,6 @@ static void enetc_xdp_drop(struct enetc_bdr *rx_ring, int rx_ring_first, &rx_ring->rx_swbd[rx_ring_first]);enetc_bdr_idx_inc (rx_ring, &rx_ring_first); } - rx_ring->stats.xdp_drops++; } static int enetc_clean_rx_ring_xdp(struct enetc_bdr *rx_ring,
@@ -1586,6 +1585,7 @@ static int enetc_clean_rx_ring_xdp(struct enetc_bdr *rx_ring, fallthrough;case XDP_DROP :enetc_xdp_drop (rx_ring, orig_i, i); + rx_ring->stats.xdp_drops++;break ;case XDP_PASS : rxbd = orig_rxbd;
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH net 1/3] net: enetc: remove xdp_drops statistic from enetc_xdp_drop()
FYI: kernel test robot notices the stable kernel rule is not satisfied.
Hi,
Thanks for your patch.
FYI: kernel test robot notices the stable kernel rule is not satisfied.
The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1
Rule: add the tag "Cc: [email protected]" in the sign-off area to have the patch automatically included in the stable tree.
Subject: [PATCH net 1/3] net: enetc: remove xdp_drops statistic from enetc_xdp_drop()
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH net 1/3] net: enetc: remove xdp_drops statistic from enetc_xdp_drop()
In reply to Wei FangQuoted 10 lines · Wei Fang
The
xdp_dropsstatistic indicates the number of XDP frames dropped in the Rx direction. However,enetc_xdp_drop()is also used inXDP_TXandXDP_REDIRECTactions. If frame loss occurs in these two actions, the frames loss count should not be included inxdp_drops, because there are alreadyxdp_tx_dropsandxdp_redirect_failuresto count the frame loss of these two actions, so it's better to removexdp_dropsstatistic fromenetc_xdp_drop()and increasexdp_dropsinXDP_DROPaction.Fixes 7ed2bc80074e ("net: enetc: add support for XDP_TX")Signed-off-by Wei Fang <[email protected]>
Quoted 28 lines
--- drivers/net/ethernet/freescale/enetc/enetc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/freescale/enetc/enetc.c +1
-1@@ -1521,7 +1521,6 @@ static void enetc_xdp_drop(struct enetc_bdr *rx_ring, int rx_ring_first, &rx_ring->rx_swbd[rx_ring_first]);enetc_bdr_idx_inc (rx_ring, &rx_ring_first); } - rx_ring->stats.xdp_drops++; } static int enetc_clean_rx_ring_xdp(struct enetc_bdr *rx_ring,@@ -1586,6 +1585,7 @@ static int enetc_clean_rx_ring_xdp(struct enetc_bdr *rx_ring, fallthrough;case XDP_DROP :enetc_xdp_drop (rx_ring, orig_i, i); + rx_ring->stats.xdp_drops++;break ;case XDP_PASS : rxbd = orig_rxbd;Signature · 1 line
2.34.1
Re: [PATCH net 1/3] net: enetc: remove xdp_drops statistic from enetc_xdp_drop()
In reply to Wei FangQuoted 7 lines · Wei Fang
The
xdp_dropsstatistic indicates the number of XDP frames dropped in the Rx direction. However,enetc_xdp_drop()is also used inXDP_TXandXDP_REDIRECTactions. If frame loss occurs in these two actions, the frames loss count should not be included inxdp_drops, because there are alreadyxdp_tx_dropsandxdp_redirect_failuresto count the frame loss of these two actions, so it's better to removexdp_dropsstatistic fromenetc_xdp_drop()and increasexdp_dropsinXDP_DROPaction.
nit: s/xdp_drops/xdp_rx_drops would be appropriate as you have xdp_tx_drops and xdp_redirect_failures.
Wei Fang
maintainerRE: [PATCH net 1/3] net: enetc: remove xdp_drops statistic from enetc_xdp_drop()
Quoted 21 lines
-----Original Message-----
From: Ratheesh Kannoth <[email protected]>
Sent: 2024年9月23日 13:03
To: Wei Fang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net 1/3] net: enetc: removexdp_dropsstatistic fromenetc_xdp_drop()Quoted 7 lines · Wei Fang
The
xdp_dropsstatistic indicates the number of XDP frames dropped in the Rx direction. However,enetc_xdp_drop()is also used inXDP_TXandXDP_REDIRECTactions. If frame loss occurs in these two actions, the frames loss count should not be included inxdp_drops, because there are alreadyxdp_tx_dropsandxdp_redirect_failuresto count the frame loss of these two actions, so it's better to removexdp_dropsstatistic fromenetc_xdp_drop()and increasexdp_dropsinXDP_DROPaction.
Quoted 3 lines
nit: s/xdp_drops/xdp_rx_drops would be appropriate as you have
xdp_tx_dropsandxdp_redirect_failures.
Sorry, I don't quite understand what you mean.
Vladimir Oltean
maintainerRe: [PATCH net 1/3] net: enetc: remove xdp_drops statistic from enetc_xdp_drop()
Quoted 21 lines · Wei Fang
Quoted 21 lines
-----Original Message-----
From: Ratheesh Kannoth <[email protected]>
Sent: 2024年9月23日 13:03
To: Wei Fang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net 1/3] net: enetc: removexdp_dropsstatistic fromenetc_xdp_drop()Quoted 7 lines · Wei Fang
The
xdp_dropsstatistic indicates the number of XDP frames dropped in the Rx direction. However,enetc_xdp_drop()is also used inXDP_TXandXDP_REDIRECTactions. If frame loss occurs in these two actions, the frames loss count should not be included inxdp_drops, because there are alreadyxdp_tx_dropsandxdp_redirect_failuresto count the frame loss of these two actions, so it's better to removexdp_dropsstatistic fromenetc_xdp_drop()and increasexdp_dropsinXDP_DROPaction.
Quoted 5 lines
Quoted 3 lines
nit: s/xdp_drops/xdp_rx_drops would be appropriate as you have
xdp_tx_dropsandxdp_redirect_failures.Sorry, I don't quite understand what you mean.
I don't understand what he means either. I guess he didn't realize you aren't proposing any new name, just working with existing concepts in the driver. Anyway, an ack about this from Ratheesh would be great, to not leave us hanging.
Wei Fang
maintainerPATCH 2/3 net: enetc: fix the issues of XDP_REDIRECT feature
In reply to Wei FangWhen testing the XDP_REDIRECT function on the LS1028A platform, we found a very reproducible issue that the Tx frames can no longer be sent out even if XDP_REDIRECT is turned off. Specifically, if there is a lot of traffic on Rx direction, when XDP_REDIRECT is turned on, the console may display some warnings like "timeout for tx ring #6 clear", and all redirected frames will be dropped, the detaild log is as follows.
root@ls1028ardb:~# ./xdp-bench redirect eno0 eno2 Redirecting from eno0 (ifindex 3; driver fsl_enetc) to eno2 (ifindex 4; driver fsl_enetc) [203.849809] fsl_enetc 0000:00:00.2 eno2: timeout for tx ring #5 clear [204.006051] fsl_enetc 0000:00:00.2 eno2: timeout for tx ring #6 clear [204.161944] fsl_enetc 0000:00:00.2 eno2: timeout for tx ring #7 clear eno0->eno2 1420505 rx/s 1420590 err,drop/s 0 xmit/s xmit eno0->eno2 0 xmit/s 1420590 drop/s 0 drv_err/s 15.71 bulk-avg eno0->eno2 1420484 rx/s 1420485 err,drop/s 0 xmit/s xmit eno0->eno2 0 xmit/s 1420485 drop/s 0 drv_err/s 15.71 bulk-avg
By analyzing the XDP_REDIRECT implementation of enetc driver, we found two problems. First, enetc driver will reconfigure Tx and Rx BD rings when a bpf program is installed or uninstalled, but there is no mechanisms to block the redirected frames when enetc driver reconfigures BD rings. So introduce ENETC_TX_DOWN flag to prevent the redirected frames to be attached to Tx BD rings.
Second, Tx BD rings are disabled first in enetc_stop() and then wait for empty. This operation is not safe while the Tx BD ring is actively transmitting frames, and will cause the ring to not be empty and hardware exception. As described in the block guide of LS1028A NETC, software should only disable an active ring after all pending ring entries have been consumed (i.e. when PI = CI). Disabling a transmit ring that is actively processing BDs risks a HW-SW race hazard whereby a hardware resource becomes assigned to work on one or more ring entries only to have those entries be removed due to the ring becoming disabled. So the correct behavior is that the software stops putting frames on the Tx BD rings (this is what ENETC_TX_DOWN does), then waits for the Tx BD rings to be empty, and finally disables the Tx BD rings.
--- drivers/net/ethernet/freescale/enetc/enetc.c | 43 ++++++++++++++++---- drivers/net/ethernet/freescale/enetc/enetc.h | 1 + 2 files changed, 35 insertions(+), 9 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +34 -9
@@ -902,6 +902,7 @@ static bool enetc_clean_tx_ring(struct enetc_bdr *tx_ring, int napi_budget)if (unlikely (tx_frm_cnt &&netif_carrier_ok (ndev) &&__netif_subqueue_stopped (ndev, tx_ring->index) && + !test_bit (ENETC_TX_DOWN , &priv->flags) && (enetc_bd_unused (tx_ring) >=ENETC_TXBDS_MAX_NEEDED ))) {netif_wake_subqueue (ndev, tx_ring->index); }
@@ -1377,6 +1378,9 @@ int enetc_xdp_xmit(struct net_device *ndev, int num_frames,int xdp_tx_bd_cnt, i, k;int xdp_tx_frm_cnt =0 ; +if (unlikely (test_bit (ENETC_TX_DOWN , &priv->flags))) +return -ENETDOWN ; +enetc_lock_mdio (); tx_ring = priv->xdp_tx_ring[smp_processor_id ()];
@@ -2223,18 +2227,24 @@ static void enetc_enable_rxbdr(struct enetc_hw *hw, struct enetc_bdr *rx_ring)enetc_rxbdr_wr (hw, idx,ENETC_RBMR , rbmr); } -static void enetc_enable_bdrs (struct enetc_ndev_priv *priv) +static void enetc_enable_rx_bdrs (struct enetc_ndev_priv *priv) {struct enetc_hw *hw = &priv->si->hw;int i; -for (i =0 ; i < priv->num_tx_rings; i++) -enetc_enable_txbdr (hw, priv->tx_ring[i]); -for (i =0 ; i < priv->num_rx_rings; i++)enetc_enable_rxbdr (hw, priv->rx_ring[i]); } +static void enetc_enable_tx_bdrs (struct enetc_ndev_priv *priv) +{ +struct enetc_hw *hw = &priv->si->hw; +int i; + +for (i =0 ; i < priv->num_tx_rings; i++) +enetc_enable_txbdr (hw, priv->tx_ring[i]); +} +static void enetc_disable_rxbdr (struct enetc_hw *hw,struct enetc_bdr *rx_ring) {int idx = rx_ring->index;
@@ -2251,7 +2261,16 @@ static void enetc_disable_txbdr(struct enetc_hw *hw, struct enetc_bdr *rx_ring)enetc_txbdr_wr (hw, idx,ENETC_TBMR ,0 ); } -static void enetc_disable_bdrs (struct enetc_ndev_priv *priv) +static void enetc_disable_rx_bdrs (struct enetc_ndev_priv *priv) +{ +struct enetc_hw *hw = &priv->si->hw; +int i; + +for (i =0 ; i < priv->num_rx_rings; i++) +enetc_disable_rxbdr (hw, priv->rx_ring[i]); +} + +static void enetc_disable_tx_bdrs (struct enetc_ndev_priv *priv) {struct enetc_hw *hw = &priv->si->hw;int i;
@@ -2259,8 +2278,6 @@ static void enetc_disable_bdrs(struct enetc_ndev_priv *priv)for (i =0 ; i < priv->num_tx_rings; i++)enetc_disable_txbdr (hw, priv->tx_ring[i]); -for (i =0 ; i < priv->num_rx_rings; i++) -enetc_disable_rxbdr (hw, priv->rx_ring[i]); }static void enetc_wait_txbdr (struct enetc_hw *hw,struct enetc_bdr *tx_ring)
@@ -2452,6 +2469,8 @@ void enetc_start(struct net_device *ndev)enetc_setup_interrupts (priv); +enetc_enable_tx_bdrs (priv); +for (i =0 ; i < priv->bdr_int_num; i++) {int irq =pci_irq_vector (priv->si->pdev,ENETC_BDR_INT_BASE_IDX + i);
@@ -2460,9 +2479,11 @@ void enetc_start(struct net_device *ndev)enable_irq (irq); } -enetc_enable_bdrs (priv); +enetc_enable_rx_bdrs (priv);netif_tx_start_all_queues (ndev); + +clear_bit (ENETC_TX_DOWN , &priv->flags); }EXPORT_SYMBOL_GPL (enetc_start);
@@ -2520,9 +2541,11 @@ void enetc_stop(struct net_device *ndev)struct enetc_ndev_priv *priv =netdev_priv (ndev);int i; +set_bit (ENETC_TX_DOWN , &priv->flags); +netif_tx_stop_all_queues (ndev); -enetc_disable_bdrs (priv); +enetc_disable_rx_bdrs (priv);for (i =0 ; i < priv->bdr_int_num; i++) { int irq = pci_irq_vector(priv->si->pdev,
@@ -2535,6 +2558,8 @@ void enetc_stop(struct net_device *ndev)enetc_wait_bdrs (priv); +enetc_disable_tx_bdrs (priv); +enetc_clear_interrupts (priv); }EXPORT_SYMBOL_GPL (enetc_stop);
drivers/net/ethernet/freescale/enetc/enetc.h +1 -0
@@ -325,6 +325,7 @@ enum enetc_active_offloads {enum enetc_flags_bit {ENETC_TX_ONESTEP_TSTAMP_IN_PROGRESS =0 , +ENETC_TX_DOWN , };/* interrupt coalescing modes */
Signature · 1 line
2.34.1
Re: [PATCH net 2/3] net: enetc: fix the issues of XDP_REDIRECT feature
Quoted 39 lines · Wei Fang
When testing the
XDP_REDIRECTfunction on the LS1028A platform, we found a very reproducible issue that the Tx frames can no longer be sent out even ifXDP_REDIRECTis turned off. Specifically, if there is a lot of traffic on Rx direction, whenXDP_REDIRECTis turned on, the console may display some warnings like "timeout for tx ring #6 clear", and all redirected frames will be dropped, the detaild log is as follows.root@ls1028ardb:~# ./xdp-bench redirect eno0 eno2 Redirecting from eno0 (ifindex 3; driver fsl_enetc) to eno2 (ifindex 4; driver fsl_enetc) [203.849809] fsl_enetc 0000:00:00.2 eno2: timeout for tx ring #5 clear [204.006051] fsl_enetc 0000:00:00.2 eno2: timeout for tx ring #6 clear [204.161944] fsl_enetc 0000:00:00.2 eno2: timeout for tx ring #7 clear eno0->eno2 1420505 rx/s 1420590 err,drop/s 0 xmit/s xmit eno0->eno2 0 xmit/s 1420590 drop/s 0 drv_err/s 15.71 bulk-avg eno0->eno2 1420484 rx/s 1420485 err,drop/s 0 xmit/s xmit eno0->eno2 0 xmit/s 1420485 drop/s 0 drv_err/s 15.71 bulk-avgBy analyzing the
XDP_REDIRECTimplementation of enetc driver, we found two problems. First, enetc driver will reconfigure Tx and Rx BD rings when a bpf program is installed or uninstalled, but there is no mechanisms to block the redirected frames when enetc driver reconfigures BD rings. So introduceENETC_TX_DOWNflag to prevent the redirected frames to be attached to Tx BD rings.Second, Tx BD rings are disabled first in
enetc_stop()and then wait for empty. This operation is not safe while the Tx BD ring is actively transmitting frames, and will cause the ring to not be empty and hardware exception. As described in the block guide of LS1028A NETC, software should only disable an active ring after all pending ring entries have been consumed (i.e. when PI = CI). Disabling a transmit ring that is actively processing BDs risks a HW-SW race hazard whereby a hardware resource becomes assigned to work on one or more ring entries only to have those entries be removed due to the ring becoming disabled. So the correct behavior is that the software stops putting frames on the Tx BD rings (this is whatENETC_TX_DOWNdoes), then waits for the Tx BD rings to be empty, and finally disables the Tx BD rings.
Quoted 3 lines
Fixes c33bfaf91c4c ("net: enetc: set up XDP program under enetc_reconfigure()")Signed-off-by Wei Fang <[email protected]>
Quoted 143 lines
--- drivers/net/ethernet/freescale/enetc/enetc.c | 43 ++++++++++++++++---- drivers/net/ethernet/freescale/enetc/enetc.h | 1 + 2 files changed, 35 insertions(+), 9 deletions(-)drivers/net/ethernet/freescale/enetc/enetc.c +34
-9@@ -902,6 +902,7 @@ static bool enetc_clean_tx_ring(struct enetc_bdr *tx_ring, int napi_budget)if (unlikely (tx_frm_cnt &&netif_carrier_ok (ndev) &&__netif_subqueue_stopped (ndev, tx_ring->index) && + !test_bit (ENETC_TX_DOWN , &priv->flags) && (enetc_bd_unused (tx_ring) >=ENETC_TXBDS_MAX_NEEDED ))) {netif_wake_subqueue (ndev, tx_ring->index); }@@ -1377,6 +1378,9 @@ int enetc_xdp_xmit(struct net_device *ndev, int num_frames,int xdp_tx_bd_cnt, i, k;int xdp_tx_frm_cnt =0 ; +if (unlikely (test_bit (ENETC_TX_DOWN , &priv->flags))) +return -ENETDOWN ; +enetc_lock_mdio (); tx_ring = priv->xdp_tx_ring[smp_processor_id ()];@@ -2223,18 +2227,24 @@ static void enetc_enable_rxbdr(struct enetc_hw *hw, struct enetc_bdr *rx_ring)enetc_rxbdr_wr (hw, idx,ENETC_RBMR , rbmr); } -static void enetc_enable_bdrs (struct enetc_ndev_priv *priv) +static void enetc_enable_rx_bdrs (struct enetc_ndev_priv *priv) {struct enetc_hw *hw = &priv->si->hw;int i; -for (i =0 ; i < priv->num_tx_rings; i++) -enetc_enable_txbdr (hw, priv->tx_ring[i]); -for (i =0 ; i < priv->num_rx_rings; i++)enetc_enable_rxbdr (hw, priv->rx_ring[i]); } +static void enetc_enable_tx_bdrs (struct enetc_ndev_priv *priv) +{ +struct enetc_hw *hw = &priv->si->hw; +int i; + +for (i =0 ; i < priv->num_tx_rings; i++) +enetc_enable_txbdr (hw, priv->tx_ring[i]); +} +static void enetc_disable_rxbdr (struct enetc_hw *hw,struct enetc_bdr *rx_ring) {int idx = rx_ring->index;@@ -2251,7 +2261,16 @@ static void enetc_disable_txbdr(struct enetc_hw *hw, struct enetc_bdr *rx_ring)enetc_txbdr_wr (hw, idx,ENETC_TBMR ,0 ); } -static void enetc_disable_bdrs (struct enetc_ndev_priv *priv) +static void enetc_disable_rx_bdrs (struct enetc_ndev_priv *priv) +{ +struct enetc_hw *hw = &priv->si->hw; +int i; + +for (i =0 ; i < priv->num_rx_rings; i++) +enetc_disable_rxbdr (hw, priv->rx_ring[i]); +} + +static void enetc_disable_tx_bdrs (struct enetc_ndev_priv *priv) {struct enetc_hw *hw = &priv->si->hw;int i;@@ -2259,8 +2278,6 @@ static void enetc_disable_bdrs(struct enetc_ndev_priv *priv)for (i =0 ; i < priv->num_tx_rings; i++)enetc_disable_txbdr (hw, priv->tx_ring[i]); -for (i =0 ; i < priv->num_rx_rings; i++) -enetc_disable_rxbdr (hw, priv->rx_ring[i]); }static void enetc_wait_txbdr (struct enetc_hw *hw,struct enetc_bdr *tx_ring)@@ -2452,6 +2469,8 @@ void enetc_start(struct net_device *ndev)enetc_setup_interrupts (priv); +enetc_enable_tx_bdrs (priv); +for (i =0 ; i < priv->bdr_int_num; i++) {int irq =pci_irq_vector (priv->si->pdev,ENETC_BDR_INT_BASE_IDX + i);@@ -2460,9 +2479,11 @@ void enetc_start(struct net_device *ndev)enable_irq (irq); } -enetc_enable_bdrs (priv); +enetc_enable_rx_bdrs (priv);netif_tx_start_all_queues (ndev); + +clear_bit (ENETC_TX_DOWN , &priv->flags); }EXPORT_SYMBOL_GPL (enetc_start);@@ -2520,9 +2541,11 @@ void enetc_stop(struct net_device *ndev)struct enetc_ndev_priv *priv =netdev_priv (ndev);int i; +set_bit (ENETC_TX_DOWN , &priv->flags); +netif_tx_stop_all_queues (ndev); -enetc_disable_bdrs (priv); +enetc_disable_rx_bdrs (priv);for (i =0 ; i < priv->bdr_int_num; i++) { int irq = pci_irq_vector(priv->si->pdev,@@ -2535,6 +2558,8 @@ void enetc_stop(struct net_device *ndev)enetc_wait_bdrs (priv); +enetc_disable_tx_bdrs (priv); +enetc_clear_interrupts (priv); }EXPORT_SYMBOL_GPL (enetc_stop);drivers/net/ethernet/freescale/enetc/enetc.h +1
-0@@ -325,6 +325,7 @@ enum enetc_active_offloads {enum enetc_flags_bit {ENETC_TX_ONESTEP_TSTAMP_IN_PROGRESS =0 , +ENETC_TX_DOWN , };/* interrupt coalescing modes */ Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH net 2/3] net: enetc: fix the issues of XDP_REDIRECT feature
In reply to Wei FangQuoted 19 lines · Wei Fang
drivers/net/ethernet/freescale/enetc/enetc.c +10
-1@@ -2251,7 +2261,16 @@ static void enetc_disable_txbdr(struct enetc_hw *hw, struct enetc_bdr *rx_ring)enetc_txbdr_wr (hw, idx,ENETC_TBMR ,0 ); } -static void enetc_disable_bdrs (struct enetc_ndev_priv *priv) +static void enetc_disable_rx_bdrs (struct enetc_ndev_priv *priv) +{ +struct enetc_hw *hw = &priv->si->hw; +int i; + +for (i =0 ; i < priv->num_rx_rings; i++) +enetc_disable_rxbdr (hw, priv->rx_ring[i]); +} + +static void enetc_disable_tx_bdrs (struct enetc_ndev_priv *priv) {struct enetc_hw *hw = &priv->si->hw;int i;
drivers/net/ethernet/freescale/enetc/enetc.c static void enetc_disable_bdrs(struct enetc_ndev_priv *priv) · line 2280
Quoted 3 lines
drivers/net/ethernet/freescale/enetc/enetc.c +0
-0@@ -2259,8 +2278,6 @@ static void enetc_disable_bdrs(struct enetc_ndev_priv *priv)for (i =0 ; i < priv->num_tx_rings; i++)enetc_disable_txbdr (hw, priv->tx_ring[i]);
Please do not leave a blank line here. In the git tree after applying this patch, that blank line appears at the end of enetc_disable_tx_bdrs().
Quoted 3 lines
drivers/net/ethernet/freescale/enetc/enetc.c +0
-2-for (i =0 ; i < priv->num_rx_rings; i++) -enetc_disable_rxbdr (hw, priv->rx_ring[i]); }
Wei Fang
maintainerRE: [PATCH net 2/3] net: enetc: fix the issues of XDP_REDIRECT feature
Quoted 34 lines
-----Original Message-----
From: Vladimir Oltean <[email protected]>
Sent: 2024年9月27日 22:42
To: Wei Fang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net 2/3] net: enetc: fix the issues ofXDP_REDIRECTfeatureReview static void enetc_disable_txbdr(struct enetc_hw
Quoted 1 line · Wei Fang
(quoted diff) +0
-0@@ -2251,7 +2261,16 @@ static void enetc_disable_txbdr(struct enetc_hw*hw, struct
enetc_bdr*rx_ring)drivers/net/ethernet/freescale/enetc/enetc.c static void enetc_disable_bdrs(struct
Quoted 18 lines
drivers/net/ethernet/freescale/enetc/enetc.c +10
-1enetc_txbdr_wr (hw, idx,ENETC_TBMR ,0 ); } -static void enetc_disable_bdrs (struct enetc_ndev_priv *priv) +static void enetc_disable_rx_bdrs (struct enetc_ndev_priv *priv) +{ +struct enetc_hw *hw = &priv->si->hw; +int i; + +for (i =0 ; i < priv->num_rx_rings; i++) +enetc_disable_rxbdr (hw, priv->rx_ring[i]); +} + +static void enetc_disable_tx_bdrs (struct enetc_ndev_priv *priv) {struct enetc_hw *hw = &priv->si->hw;int i;@@ -2259,8 +2278,6 @@ static void enetc_disable_bdrs(struct
enetc_ndev_priv*priv)
Quoted 7 lines
drivers/net/ethernet/freescale/enetc/enetc.c static void enetc_disable_bdrs(struct enetc_ndev_priv *priv) · line 2280
Quoted 3 lines
drivers/net/ethernet/freescale/enetc/enetc.c +0
-0for (i =0 ; i < priv->num_tx_rings; i++)enetc_disable_txbdr (hw, priv->tx_ring[i]);Please do not leave a blank line here. In the git tree after applying this patch, that blank line appears at the end of
enetc_disable_tx_bdrs().
Thanks for reminder, it's weird that the checkpatch.pl did not raise a warning here.
Wei Fang
maintainerPATCH 3/3 net: enetc: reset xdp_tx_in_flight when updating bpf program
In reply to Wei FangWhen running "xdp-bench tx eno0" to test the XDP_TX feature of ENETC on LS1028A, it was found that if the command was re-run multiple times, Rx could not receive the frames, and the result of xdo-bench showed that the rx rate was 0.
root@ls1028ardb:~# ./xdp-bench tx eno0 Hairpinning (XDP_TX) packets on eno0 (ifindex 3; driver fsl_enetc) Summary 2046 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/s
By observing the Rx PIR and CIR registers, we found that CIR is always equal to 0x7FF and PIR is always 0x7FE, which means that the Rx ring is full and can no longer accommodate other Rx frames. Therefore, it is obvious that the RX BD ring has not been cleaned up.
Further analysis of the code revealed that the Rx BD ring will only be cleaned if the "cleaned_cnt > xdp_tx_in_flight" condition is met. Therefore, some debug logs were added to the driver and the current values of cleaned_cnt and xdp_tx_in_flight were printed when the Rx BD ring was full. The logs are as follows.
[ 178.762419] [XDP TX] >> cleaned_cnt:1728, xdp_tx_in_flight:2140 [ 178.771387] [XDP TX] >> cleaned_cnt:1941, xdp_tx_in_flight:2110 [ 178.776058] [XDP TX] >> cleaned_cnt:1792, xdp_tx_in_flight:2110
From the results, we can see that the maximum value of xdp_tx_in_flight has reached 2140. However, the size of the Rx BD ring is only 2048. This is incredible, so checked the code again and found that the driver did not reset xdp_tx_in_flight when installing or uninstalling bpf program, resulting in xdp_tx_in_flight still retaining the value after the last command was run.
--- drivers/net/ethernet/freescale/enetc/enetc.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/freescale/enetc/enetc.c +1 -0
@@ -2769,6 +2769,7 @@ static int enetc_reconfigure_xdp_cb(struct enetc_ndev_priv *priv, void *ctx)for (i =0 ; i < priv->num_rx_rings; i++) {struct enetc_bdr *rx_ring = priv->rx_ring[i]; + rx_ring->xdp.xdp_tx_in_flight =0 ; rx_ring->xdp.prog = prog;if (prog)
Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH net 3/3] net: enetc: reset xdp_tx_in_flight when updating bpf program
Quoted 27 lines · Wei Fang
When running "xdp-bench tx eno0" to test the
XDP_TXfeature of ENETC on LS1028A, it was found that if the command was re-run multiple times, Rx could not receive the frames, and the result of xdo-bench showed that the rx rate was 0.root@ls1028ardb:~# ./xdp-bench tx eno0 Hairpinning (XDP_TX) packets on eno0 (ifindex 3; driver fsl_enetc) Summary 2046 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/sBy observing the Rx PIR and CIR registers, we found that CIR is always equal to
0x7FFand PIR is always0x7FE, which means that the Rx ring is full and can no longer accommodate other Rx frames. Therefore, it is obvious that the RX BD ring has not been cleaned up.Further analysis of the code revealed that the Rx BD ring will only be cleaned if the "
cleaned_cnt>xdp_tx_in_flight" condition is met. Therefore, some debug logs were added to the driver and the current values ofcleaned_cntandxdp_tx_in_flightwere printed when the Rx BD ring was full. The logs are as follows.[ 178.762419] [XDP TX] >> cleaned_cnt:1728, xdp_tx_in_flight:2140 [ 178.771387] [XDP TX] >> cleaned_cnt:1941, xdp_tx_in_flight:2110 [ 178.776058] [XDP TX] >> cleaned_cnt:1792, xdp_tx_in_flight:2110
Quoted 8 lines
From the results, we can see that the maximum value of
xdp_tx_in_flighthas reached 2140. However, the size of the Rx BD ring is only 2048. This is incredible, so checked the code again and found that the driver did not resetxdp_tx_in_flightwhen installing or uninstalling bpf program, resulting inxdp_tx_in_flightstill retaining the value after the last command was run.Fixes c33bfaf91c4c ("net: enetc: set up XDP program under enetc_reconfigure()")
This does not explain why enetc_recycle_xdp_tx_buff(), which decreases xdp_tx_in_flight, does not get called?
In patch 2/3 you wrote:
| Tx BD rings are disabled first in enetc_stop() and then | wait for empty. This operation is not safe while the Tx BD ring | is actively transmitting frames, and will cause the ring to not | be empty and hardware exception. As described in the block guide | of LS1028A NETC, software should only disable an active ring after | all pending ring entries have been consumed (i.e. when PI = CI). | Disabling a transmit ring that is actively processing BDs risks | a HW-SW race hazard whereby a hardware resource becomes assigned | to work on one or more ring entries only to have those entries be | removed due to the ring becoming disabled. So the correct behavior | is that the software stops putting frames on the Tx BD rings (this | is what ENETC_TX_DOWN does), then waits for the Tx BD rings to be | empty, and finally disables the Tx BD rings.
I'm surprised that after fixing that, this change would still be needed, rather than xdp_tx_in_flight naturally dropping down to 0 when stopping NAPI. Why doesn't that happen, and what happens to the pending XDP_TX buffers?
Wei Fang
maintainerRE: [PATCH net 3/3] net: enetc: reset xdp_tx_in_flight when updating bpf program
Quoted 74 lines
-----Original Message-----
From: Vladimir Oltean <[email protected]>
Sent: 2024年9月19日 21:22
To: Wei Fang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net 3/3] net: enetc: resetxdp_tx_in_flightwhen updating bpf programQuoted 8 lines · Wei Fang
When running "xdp-bench tx eno0" to test the
XDP_TXfeature of ENETC on LS1028A, it was found that if the command was re-run multiple times, Rx could not receive the frames, and the result of xdo-bench showed that the rx rate was 0.root@ls1028ardb:~# ./xdp-bench tx eno0 Hairpinning (XDP_TX) packets on eno0 (ifindex 3; driver fsl_enetc) Summary 2046 rx/s 0err,drop/s
Quoted 1 line
Summary 0 rx/s 0
err,drop/s
Quoted 1 line
Summary 0 rx/s 0
err,drop/s
Quoted 1 line
Summary 0 rx/s 0
err,drop/s
Quoted 23 lines
By observing the Rx PIR and CIR registers, we found that CIR is always equal to
0x7FFand PIR is always0x7FE, which means that the Rx ring is full and can no longer accommodate other Rx frames. Therefore, it is obvious that the RX BD ring has not been cleaned up.Further analysis of the code revealed that the Rx BD ring will only be cleaned if the "
cleaned_cnt>xdp_tx_in_flight" condition is met. Therefore, some debug logs were added to the driver and the current values ofcleaned_cntandxdp_tx_in_flightwere printed when the Rx BD ring was full. The logs are as follows.[ 178.762419] [XDP TX] >> cleaned_cnt:1728, xdp_tx_in_flight:2140 [178.771387] [XDP TX] >> cleaned_cnt:1941, xdp_tx_in_flight:2110 [ 178.776058] [XDP TX] >> cleaned_cnt:1792, xdp_tx_in_flight:2110
From the results, we can see that the maximum value of
xdp_tx_in_flighthas reached 2140. However, the size of the Rx BD ring is only 2048. This is incredible, so checked the code again and found that the driver did not resetxdp_tx_in_flightwhen installing or uninstalling bpf program, resulting inxdp_tx_in_flightstill retaining the value after the last command was run.Quoted 2 lines
Fixes c33bfaf91c4c ("net: enetc: set up XDP program under
enetc_reconfigure()")This does not explain why
enetc_recycle_xdp_tx_buff(), which decreasesxdp_tx_in_flight, does not get called?In patch 2/3 you wrote:
| Tx BD rings are disabled first in enetc_stop() and then wait for | empty. This operation is not safe while the Tx BD ring is actively | transmitting frames, and will cause the ring to not be empty and | hardware exception. As described in the block guide of LS1028A NETC, | software should only disable an active ring after all pending ring | entries have been consumed (i.e. when PI = CI). | Disabling a transmit ring that is actively processing BDs risks a | HW-SW race hazard whereby a hardware resource becomes assigned to work | on one or more ring entries only to have those entries be removed due | to the ring becoming disabled. So the correct behavior is that the | software stops putting frames on the Tx BD rings (this is what | ENETC_TX_DOWN does), then waits for the Tx BD rings to be empty, and | finally disables the Tx BD rings.
Quoted 3 lines
I'm surprised that after fixing that, this change would still be needed, rather than
xdp_tx_in_flightnaturally dropping down to 0 when stopping NAPI. Why doesn't that happen, and what happens to the pendingXDP_TXbuffers?
The reason is that interrupt is disabled (disable_irq() is called in enetc_stop()) so enetc_recycle_xdp_tx_buff() will not be called. Actually all XDP_TX frames are sent out and XDP_TX buffers will be freed by enetc_free_rxtx_rings(). So there is no noticeable impact.
Another solution is that move disable_irq() to the end of enetc_stop(), so that the IRQ is still active until the Tx is finished. In this case, the xdp_tx_in_flight will naturally drop down to 0 as you expect.
Re: [PATCH net 3/3] net: enetc: reset xdp_tx_in_flight when updating bpf program
Quoted 2 lines · Wei Fang
enetc_recycle_xdp_tx_buff()will not be called. Actually allXDP_TXframes are sent out andXDP_TXbuffers will be freed byenetc_free_rxtx_rings().
why didn't you choose enetc_free_rxtx_rings() to reset inflight count to 0 ?
Wei Fang
maintainerRE: [PATCH net 3/3] net: enetc: reset xdp_tx_in_flight when updating bpf program
Quoted 13 lines
-----Original Message-----
From: Ratheesh Kannoth <[email protected]>
Sent: 2024年9月23日 12:56
To: Wei Fang <[email protected]>
Cc: Vladimir Oltean <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net 3/3] net: enetc: resetxdp_tx_in_flightwhen updating bpf program
Quoted 5 lines
Quoted 2 lines · Wei Fang
enetc_recycle_xdp_tx_buff()will not be called. Actually allXDP_TXframes are sent out andXDP_TXbuffers will be freed by
enetc_free_rxtx_rings().
why didn't you chooseenetc_free_rxtx_rings()to reset inflight count to 0 ?
IMO, I think enetc_reconfigure_xdp_cb() is more appropriate to reset xdp_tx_in_flight than enetc_free_rxtx_rings().
Re: [PATCH net 3/3] net: enetc: reset xdp_tx_in_flight when updating bpf program
In reply to Wei FangQuoted 46 lines · Wei Fang
When running "xdp-bench tx eno0" to test the
XDP_TXfeature of ENETC on LS1028A, it was found that if the command was re-run multiple times, Rx could not receive the frames, and the result of xdo-bench showed that the rx rate was 0.root@ls1028ardb:~# ./xdp-bench tx eno0 Hairpinning (XDP_TX) packets on eno0 (ifindex 3; driver fsl_enetc) Summary 2046 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/sBy observing the Rx PIR and CIR registers, we found that CIR is always equal to
0x7FFand PIR is always0x7FE, which means that the Rx ring is full and can no longer accommodate other Rx frames. Therefore, it is obvious that the RX BD ring has not been cleaned up.Further analysis of the code revealed that the Rx BD ring will only be cleaned if the "
cleaned_cnt>xdp_tx_in_flight" condition is met. Therefore, some debug logs were added to the driver and the current values ofcleaned_cntandxdp_tx_in_flightwere printed when the Rx BD ring was full. The logs are as follows.[ 178.762419] [XDP TX] >> cleaned_cnt:1728, xdp_tx_in_flight:2140 [ 178.771387] [XDP TX] >> cleaned_cnt:1941, xdp_tx_in_flight:2110 [ 178.776058] [XDP TX] >> cleaned_cnt:1792, xdp_tx_in_flight:2110From the results, we can see that the maximum value of
xdp_tx_in_flighthas reached 2140. However, the size of the Rx BD ring is only 2048. This is incredible, so checked the code again and found that the driver did not resetxdp_tx_in_flightwhen installing or uninstalling bpf program, resulting inxdp_tx_in_flightstill retaining the value after the last command was run.Fixes c33bfaf91c4c ("net: enetc: set up XDP program under enetc_reconfigure()")Signed-off-by Wei Fang <[email protected]>--- drivers/net/ethernet/freescale/enetc/enetc.c | 1 + 1 file changed, 1 insertion(+)drivers/net/ethernet/freescale/enetc/enetc.c +0
-0
drivers/net/ethernet/freescale/enetc/enetc.c static int enetc_reconfigure_xdp_cb(struct enetc_ndev_priv *priv, void *ctx) · line 2772
Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc.c +1
-0@@ -2769,6 +2769,7 @@ static int enetc_reconfigure_xdp_cb(struct enetc_ndev_priv *priv, void *ctx)for (i =0 ; i < priv->num_rx_rings; i++) {struct enetc_bdr *rx_ring = priv->rx_ring[i]; + rx_ring->xdp.xdp_tx_in_flight =0 ;
zero init is good but shouldn't you be draining these buffers when removing XDP resources at least? what happens with DMA mappings that are related to these cached buffers?
Quoted 7 lines
drivers/net/ethernet/freescale/enetc/enetc.c +0
-0rx_ring->xdp.prog = prog;if (prog)Signature · 1 line
2.34.1
Wei Fang
maintainerRE: [PATCH net 3/3] net: enetc: reset xdp_tx_in_flight when updating bpf program
Quoted 67 lines
-----Original Message-----
From: Maciej Fijalkowski <[email protected]>
Sent: 2024年9月20日 21:05
To: Wei Fang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; Vladimir Oltean <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net 3/3] net: enetc: resetxdp_tx_in_flightwhen updating bpf programQuoted 8 lines · Wei Fang
When running "xdp-bench tx eno0" to test the
XDP_TXfeature of ENETC on LS1028A, it was found that if the command was re-run multiple times, Rx could not receive the frames, and the result of xdo-bench showed that the rx rate was 0.root@ls1028ardb:~# ./xdp-bench tx eno0 Hairpinning (XDP_TX) packets on eno0 (ifindex 3; driver fsl_enetc) Summary 2046 rx/s 0err,drop/s
Quoted 1 line
Summary 0 rx/s 0
err,drop/s
Quoted 1 line
Summary 0 rx/s 0
err,drop/s
Quoted 1 line
Summary 0 rx/s 0
err,drop/s
drivers/net/ethernet/freescale/enetc/enetc.c static int enetc_reconfigure_xdp_cb(struct
Quoted 37 lines
By observing the Rx PIR and CIR registers, we found that CIR is always equal to
0x7FFand PIR is always0x7FE, which means that the Rx ring is full and can no longer accommodate other Rx frames. Therefore, it is obvious that the RX BD ring has not been cleaned up.Further analysis of the code revealed that the Rx BD ring will only be cleaned if the "
cleaned_cnt>xdp_tx_in_flight" condition is met. Therefore, some debug logs were added to the driver and the current values ofcleaned_cntandxdp_tx_in_flightwere printed when the Rx BD ring was full. The logs are as follows.[ 178.762419] [XDP TX] >> cleaned_cnt:1728, xdp_tx_in_flight:2140 [178.771387] [XDP TX] >> cleaned_cnt:1941, xdp_tx_in_flight:2110 [ 178.776058] [XDP TX] >> cleaned_cnt:1792, xdp_tx_in_flight:2110
From the results, we can see that the maximum value of
xdp_tx_in_flighthas reached 2140. However, the size of the Rx BD ring is only 2048. This is incredible, so checked the code again and found that the driver did not resetxdp_tx_in_flightwhen installing or uninstalling bpf program, resulting inxdp_tx_in_flightstill retaining the value after the last command was run.Fixes c33bfaf91c4c ("net: enetc: set up XDP program under
enetc_reconfigure()")Signed-off-by Wei Fang <[email protected]>--- drivers/net/ethernet/freescale/enetc/enetc.c | 1 + 1 file changed, 1 insertion(+)drivers/net/ethernet/freescale/enetc/enetc.c +0
-0@@ -2769,6 +2769,7 @@ static int enetc_reconfigure_xdp_cb(struct
enetc_ndev_priv*priv, void *ctx)
Quoted 9 lines
drivers/net/ethernet/freescale/enetc/enetc.c static int enetc_reconfigure_xdp_cb(struct enetc_ndev_priv *priv, void *ctx) · line 2772
Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc.c +1
-0for (i =0 ; i < priv->num_rx_rings; i++) {struct enetc_bdr *rx_ring = priv->rx_ring[i]; + rx_ring->xdp.xdp_tx_in_flight =0 ;zero init is good but shouldn't you be draining these buffers when removing XDP resources at least? what happens with DMA mappings that are related to these cached buffers?
All the buffers will be freed and DMA will be unmapped when XDP program is installed. I am thinking that another solution may be better, which is mentioned in another thread replying to Vladimir, so that xdp_tx_in_flight will naturally drop to 0, and the TX-related statistics will be more accurate.
Vladimir Oltean
maintainerRe: [PATCH net 3/3] net: enetc: reset xdp_tx_in_flight when updating bpf program
Quoted 7 lines · Wei Fang
Quoted 4 lines
zero init is good but shouldn't you be draining these buffers when removing XDP resources at least? what happens with DMA mappings that are related to these cached buffers?
All the buffers will be freed and DMA will be unmapped when XDP program is installed.
There is still a problem with the patch you proposed here, which is that enetc_reconfigure() has one more call site, from enetc_hwtstamp_set(). If enetc_free_rxtx_rings() is the one that gets rid of the stale buffers, it should also be the one that resets xdp_tx_in_flight, otherwise you will still leave the problem unsolved where XDP_TX can be interrupted by a change in hwtstamping state, and the software "in flight" counter gets out of sync with the ring state.
Also, I suspect that the blamed commit is wrong. Also the normal netdev close path should be susceptible to this issue, not just enetc_reconfigure(). Maybe something like ff58fda09096 ("net: enetc: prioritize ability to go down over packet processing"). That's when we started rushing the NAPI poll routing to finish. I don't think it was possible, before that, to close the netdev while there were XDP_TX frames pending to be recycled.
Quoted 3 lines
I am thinking that another solution may be better, which is mentioned in another thread replying to Vladimir, so that
xdp_tx_in_flightwill naturally drop to 0, and the TX-related statistics will be more accurate.
Please give me some more time to analyze the flow after just your patch 2/3. I have a draft reply, but I would still like to test some things.
Vladimir Oltean
maintainerRe: [PATCH net 3/3] net: enetc: reset xdp_tx_in_flight when updating bpf program
Quoted 1 line · Vladimir Oltean
That's when we started rushing the NAPI poll routing to finish.
routine*
Wei Fang
maintainerRE: [PATCH net 3/3] net: enetc: reset xdp_tx_in_flight when updating bpf program
In reply to Vladimir OlteanQuoted 24 lines
-----Original Message-----
From: Vladimir Oltean <[email protected]>
Sent: 2024年9月20日 22:25
To: Wei Fang <[email protected]>
Cc: Maciej Fijalkowski <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Claudiu Manoil <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net 3/3] net: enetc: resetxdp_tx_in_flightwhen updating bpf programQuoted 2 lines · Wei Fang
Quoted 2 lines
zero init is good but shouldn't you be draining these buffers when removing XDP resources at least? what happens with DMA mappings that are related
to
Quoted 4 lines
Quoted 2 lines
these cached buffers?
All the buffers will be freed and DMA will be unmapped when XDP program
is
Quoted 1 line
installed.
Quoted 7 lines
There is still a problem with the patch you proposed here, which is that
enetc_reconfigure()has one more call site, fromenetc_hwtstamp_set(). Ifenetc_free_rxtx_rings()is the one that gets rid of the stale buffers, it should also be the one that resetsxdp_tx_in_flight, otherwise you will still leave the problem unsolved whereXDP_TXcan be interrupted by a change in hwtstamping state, and the software "in flight" counter gets out of sync with the ring state.
Yes, you are right. It's a potential issue if RX_TSTAMP is set when XDP is also enabled.
Quoted 5 lines
Also, I suspect that the blamed commit is wrong. Also the normal netdev close path should be susceptible to this issue, not just
enetc_reconfigure(). Maybe something likeff58fda09096("net: enetc: prioritize ability to go down over packet processing").
Thanks for the reminder, I will change the blamed commit in next version
Quoted 11 lines
That's when we started rushing the NAPI
poll routing to finish. I don't think it was possible, before that, to close the netdev while there wereXDP_TXframes pending to be recycled.Quoted 2 lines
I am thinking that another solution may be better, which is mentioned in another thread replying to Vladimir, so that
xdp_tx_in_flightwill naturallydrop
Quoted 1 line
to 0, and the TX-related statistics will be more accurate.
Please give me some more time to analyze the flow after just your patch 2/3. I have a draft reply, but I would still like to test some things.
Okay, I have tested this solution (see changes below), and from what I observed, the xdp_tx_in_flight can naturally drop to 0 in every test. So if there are no other risks, the next version will use this solution.
@@ -2467,10 +2469,6 @@ void enetc_start(struct net_device *ndev)
struct enetc_ndev_priv *priv = netdev_priv(ndev);
int i;- enetc_setup_interrupts(priv);
-
- enetc_enable_tx_bdrs(priv);
-
for (i = 0; i < priv->bdr_int_num; i++) {
int irq = pci_irq_vector(priv->si->pdev,
ENETC_BDR_INT_BASE_IDX + i);
@@ -2479,6 +2477,10 @@ void enetc_start(struct net_device *ndev)
enable_irq(irq);
}+ enetc_setup_interrupts(priv);
+
+ enetc_enable_tx_bdrs(priv);
+
enetc_enable_rx_bdrs(priv);
netif_tx_start_all_queues(ndev);@@ -2547,6 +2549,12 @@ void enetc_stop(struct net_device *ndev)
enetc_disable_rx_bdrs(priv);
+ enetc_wait_bdrs(priv);
+
+ enetc_disable_tx_bdrs(priv);
+
+ enetc_clear_interrupts(priv);
+
for (i = 0; i < priv->bdr_int_num; i++) {
int irq = pci_irq_vector(priv->si->pdev,
ENETC_BDR_INT_BASE_IDX + i);
@@ -2555,12 +2563,6 @@ void enetc_stop(struct net_device *ndev)
napi_synchronize(&priv->int_vector[i]->napi);
napi_disable(&priv->int_vector[i]->napi);
}-
- enetc_wait_bdrs(priv);
-
- enetc_disable_tx_bdrs(priv);
-
- enetc_clear_interrupts(priv);
}
EXPORT_SYMBOL_GPL(enetc_stop);
Vladimir Oltean
maintainerRe: [PATCH net 3/3] net: enetc: reset xdp_tx_in_flight when updating bpf program
Hi Wei,
Quoted 4 lines · Wei Fang
Okay, I have tested this solution (see changes below), and from what I observed, the
xdp_tx_in_flightcan naturally drop to 0 in every test. So if there are no other risks, the next version will use this solution.
Sorry for the delay. I have tested this variant and it works. Just one thing below.
Quoted 23 lines
(quoted diff) +4
-4@@ -2467,10 +2469,6 @@ void enetc_start(struct net_device *ndev) struct enetc_ndev_priv *priv = netdev_priv(ndev); int i; - enetc_setup_interrupts(priv); - - enetc_enable_tx_bdrs(priv); - for (i = 0; i < priv->bdr_int_num; i++) { int irq = pci_irq_vector(priv->si->pdev, ENETC_BDR_INT_BASE_IDX + i);@@ -2479,6 +2477,10 @@ void enetc_start(struct net_device *ndev) enable_irq(irq); } + enetc_setup_interrupts(priv); + + enetc_enable_tx_bdrs(priv); + enetc_enable_rx_bdrs(priv); netif_tx_start_all_queues(ndev);
Review void enetc_stop(struct net_device *ndev) · line 2556
Quoted 8 lines
(quoted diff) +5
-0@@ -2547,6 +2549,12 @@ void enetc_stop(struct net_device *ndev) enetc_disable_rx_bdrs(priv); + enetc_wait_bdrs(priv); + + enetc_disable_tx_bdrs(priv); + + enetc_clear_interrupts(priv);
Here, NAPI may still be scheduled. So if you clear interrupts, enetc_poll() on another CPU might still have time to re-enable them. This makes the call pointless.
Please move the enetc_clear_interrupts() call after the for() loop below (AKA leave it where it is).
Quoted 6 lines
(quoted diff) +1
-0+ for (i = 0; i < priv->bdr_int_num; i++) { int irq = pci_irq_vector(priv->si->pdev, ENETC_BDR_INT_BASE_IDX + i);@@ -2555,12 +2563,6 @@ void enetc_stop(struct net_device *ndev) napi_synchronize(&priv->int_vector[i]->napi);
Review void enetc_stop(struct net_device *ndev) · line 2567
Quoted 10 lines
(quoted diff) +0
-6napi_disable(&priv->int_vector[i]->napi); } - - enetc_wait_bdrs(priv); - - enetc_disable_tx_bdrs(priv); - - enetc_clear_interrupts(priv); } EXPORT_SYMBOL_GPL(enetc_stop);
FWIW, there are at least 2 other valid ways of solving this problem. One has already been mentioned (reset the counter in enetc_free_rx_ring()):
@@ -2014,6 +2015,8 @@ static void enetc_free_rx_ring(struct enetc_bdr *rx_ring)
__free_page(rx_swbd->page);
rx_swbd->page = NULL;
}
+
+ rx_ring->xdp.xdp_tx_in_flight = 0;
}
static void enetc_free_rxtx_rings(struct enetc_ndev_priv *priv)
And the other would be to keep rescheduling NAPI until there are no more pending XDP_TX frames.
drivers/net/ethernet/freescale/enetc/enetc.c +1 -1
@@ -1689,6 +1689,7 @@ static int enetc_poll(struct napi_struct *napi, int budget) work_done =enetc_clean_rx_ring_xdp (rx_ring, napi, budget, prog); else work_done =enetc_clean_rx_ring (rx_ring, napi, budget); -if (work_done == budget) +if (work_done == budget || rx_ring->xdp.xdp_tx_in_flight) complete = false;if (work_done)
But I like your second proposal the best. It doesn't involve adding an unnecessary extra test in the fast path.
Wei Fang
maintainerRE: [PATCH net 3/3] net: enetc: reset xdp_tx_in_flight when updating bpf program
Quoted 50 lines
Hi Wei,
Quoted 1 line · Wei Fang
Okay, I have tested this solution (see changes below), and from what I
observed,
Quoted 1 line
the
xdp_tx_in_flightcan naturally drop to 0 in every test. So if there are noother
Quoted 2 lines
risks, the next version will use this solution.
Sorry for the delay. I have tested this variant and it works. Just one thing below.
Review void enetc_start(struct net_device *ndev) · line 2474
Quoted 11 lines
(quoted diff) +0
-4@@ -2467,10 +2469,6 @@ void enetc_start(struct net_device *ndev) struct enetc_ndev_priv *priv = netdev_priv(ndev); int i; - enetc_setup_interrupts(priv); - - enetc_enable_tx_bdrs(priv); - for (i = 0; i < priv->bdr_int_num; i++) { int irq = pci_irq_vector(priv->si->pdev,
ENETC_BDR_INT_BASE_IDX+ i);Quoted 12 lines
(quoted diff) +4
-0@@ -2479,6 +2477,10 @@ void enetc_start(struct net_device *ndev) enable_irq(irq); } + enetc_setup_interrupts(priv); + + enetc_enable_tx_bdrs(priv); + enetc_enable_rx_bdrs(priv); netif_tx_start_all_queues(ndev);Review void enetc_stop(struct net_device *ndev) · line 2556
Quoted 8 lines
(quoted diff) +5
-0@@ -2547,6 +2549,12 @@ void enetc_stop(struct net_device *ndev) enetc_disable_rx_bdrs(priv); + enetc_wait_bdrs(priv); + + enetc_disable_tx_bdrs(priv); + + enetc_clear_interrupts(priv);Here, NAPI may still be scheduled. So if you clear interrupts,
enetc_poll()on another CPU might still have time to re-enable them. This makes the call pointless.
Quoted 2 lines
Please move the
enetc_clear_interrupts()call after thefor()loop below (AKA leave it where it is).
Okay, I will, thanks.
Quoted 53 lines
Review void enetc_stop(struct net_device *ndev) · line 2560
Quoted 5 lines
(quoted diff) +1
-0+ for (i = 0; i < priv->bdr_int_num; i++) { int irq = pci_irq_vector(priv->si->pdev,
ENETC_BDR_INT_BASE_IDX+ i);Review void enetc_stop(struct net_device *ndev) · line 2567
Quoted 12 lines
(quoted diff) +0
-6@@ -2555,12 +2563,6 @@ void enetc_stop(struct net_device *ndev) napi_synchronize(&priv->int_vector[i]->napi); napi_disable(&priv->int_vector[i]->napi); } - - enetc_wait_bdrs(priv); - - enetc_disable_tx_bdrs(priv); - - enetc_clear_interrupts(priv); } EXPORT_SYMBOL_GPL(enetc_stop);FWIW, there are at least 2 other valid ways of solving this problem. One has already been mentioned (reset the counter in
enetc_free_rx_ring()):(quoted diff) +2
-0@@ -2014,6 +2015,8 @@ static void enetc_free_rx_ring(struct enetc_bdr *rx_ring) __free_page(rx_swbd->page); rx_swbd->page = NULL; } + + rx_ring->xdp.xdp_tx_in_flight = 0; }static void
enetc_free_rxtx_rings(struct enetc_ndev_priv *priv)And the other would be to keep rescheduling NAPI until there are no more pending
XDP_TXframes.drivers/net/ethernet/freescale/enetc/enetc.c +1
-1@@ -1689,6 +1689,7 @@ static int enetc_poll(struct napi_struct *napi, int budget) work_done =enetc_clean_rx_ring_xdp (rx_ring, napi, budget, prog); else work_done =enetc_clean_rx_ring (rx_ring, napi, budget); -if (work_done == budget) +if (work_done == budget || rx_ring->xdp.xdp_tx_in_flight) complete = false;if (work_done)But I like your second proposal the best. It doesn't involve adding an unnecessary extra test in the fast path.
Vladimir Oltean
maintainerRe: [PATCH net 3/3] net: enetc: reset xdp_tx_in_flight when updating bpf program
In reply to Wei FangQuoted 12 lines · Wei Fang
When running "xdp-bench tx eno0" to test the
XDP_TXfeature of ENETC on LS1028A, it was found that if the command was re-run multiple times, Rx could not receive the frames, and the result of xdo-bench showed that the rx rate was 0.root@ls1028ardb:~# ./xdp-bench tx eno0 Hairpinning (XDP_TX) packets on eno0 (ifindex 3; driver fsl_enetc) Summary 2046 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/s
Quoted 4 lines
By observing the Rx PIR and CIR registers, we found that CIR is always equal to
0x7FFand PIR is always0x7FE, which means that the Rx ring is full and can no longer accommodate other Rx frames. Therefore, it is obvious that the RX BD ring has not been cleaned up.
I wouldn't call "obvious" something that you had to go and put debug prints for. There's nothing obvious about the manifestation of the issue.
Quoted 11 lines
Further analysis of the code revealed that the Rx BD ring will only be cleaned if the "
cleaned_cnt>xdp_tx_in_flight" condition is met. Therefore, some debug logs were added to the driver and the current values ofcleaned_cntandxdp_tx_in_flightwere printed when the Rx BD ring was full. The logs are as follows.[ 178.762419] [XDP TX] >> cleaned_cnt:1728, xdp_tx_in_flight:2140 [ 178.771387] [XDP TX] >> cleaned_cnt:1941, xdp_tx_in_flight:2110 [ 178.776058] [XDP TX] >> cleaned_cnt:1792, xdp_tx_in_flight:2110
Quoted 6 lines
From the results, we can see that the maximum value of
xdp_tx_in_flighthas reached 2140. However, the size of the Rx BD ring is only 2048. This is incredible, so checked the code again and found that the driver did not resetxdp_tx_in_flightwhen installing or uninstalling bpf program, resulting inxdp_tx_in_flightstill retaining the value after the last command was run.
When you resubmit, please be careful to readjust the commit message to the new patch. Especially this paragraph, but also the title.
Quoted 5 lines
Fixes c33bfaf91c4c ("net: enetc: set up XDP program under enetc_reconfigure()")Signed-off-by Wei Fang <[email protected]>---