net: openvswitch: use core API for updating TX stats
Subsystems (3)
PATCH 2/3 net: openvswitch: use core API for updating TX stats
Commit d3fd65484c781 ("net: core: add dev_sw_netstats_tx_add") has added function "dev_sw_netstats_tx_add()" to update net device per-cpu TX stats.
Use this function instead of own code. While on it, replace "len" variable with "skb->len".
--- net/openvswitch/vport-internal_dev.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
net/openvswitch/vport-internal_dev.c +5 -11
@@ -33,23 +33,17 @@ static struct internal_dev *internal_dev_priv(struct net_device *netdev)static netdev_tx_t internal_dev_xmit (struct sk_buff *skb,struct net_device *netdev) { -int len, err; +int err; - len = skb->len;rcu_read_lock (); err =ovs_vport_receive (internal_dev_priv (netdev)->vport, skb,NULL );rcu_read_unlock (); -if (likely (!err)) { -struct pcpu_sw_netstats *tstats =this_cpu_ptr (netdev->tstats); - -u64_stats_update_begin (&tstats->syncp); - tstats->tx_bytes += len; - tstats->tx_packets++; -u64_stats_update_end (&tstats->syncp); - }else { +if (likely (!err)) +dev_sw_netstats_tx_add (netdev,1 , skb->len); +else netdev->stats.tx_errors++; - } +return NETDEV_TX_OK ; }
Signature · 1 line
2.25.1
Am 12.11.2020 um 12:11 schrieb Lev Stipakov:
Quoted 7 lines
Commit
d3fd65484c781("net: core: adddev_sw_netstats_tx_add") has added function "dev_sw_netstats_tx_add()" to update net device per-cpu TX stats.Use this function instead of own code. While on it, replace "len" variable with "
skb->len".
Using dev_sw_netstats_tx_add() is fine, however you have to keep variable len, see remark in the code.
In addition you can replace internal_get_stats() with dev_get_tstats64().
Quoted 10 lines
Signed-off-by Lev Stipakov <[email protected]>--- net/openvswitch/vport-internal_dev.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)net/openvswitch/vport-internal_dev.c +0
-0
net/openvswitch/vport-internal_dev.c static struct internal_dev *internal_dev_priv(struct net_device *netdev) · line 39
Quoted 9 lines
net/openvswitch/vport-internal_dev.c +1
-2@@ -33,23 +33,17 @@ static struct internal_dev *internal_dev_priv(struct net_device *netdev)static netdev_tx_t internal_dev_xmit (struct sk_buff *skb,struct net_device *netdev) { -int len, err; +int err; - len = skb->len;rcu_read_lock (); err =ovs_vport_receive (internal_dev_priv (netdev)->vport, skb,NULL );
We would have a well-hidden problem here. ovs_vport_receive() calls function ovs_dp_process_packet() that frees the skb under certain circumstances. Note that the skb can be freed even if ovs_vport_receive() returns OK. Using skb->len after calling ovs_vport_receive() could result in a use-after-free therefore. So you have to keep variable len.
Quoted 20 lines
net/openvswitch/vport-internal_dev.c +4
-9rcu_read_unlock (); -if (likely (!err)) { -struct pcpu_sw_netstats *tstats =this_cpu_ptr (netdev->tstats); - -u64_stats_update_begin (&tstats->syncp); - tstats->tx_bytes += len; - tstats->tx_packets++; -u64_stats_update_end (&tstats->syncp); - }else { +if (likely (!err)) +dev_sw_netstats_tx_add (netdev,1 , skb->len); +else netdev->stats.tx_errors++; - } +return NETDEV_TX_OK ; }
PATCH v2 2/3 net: openvswitch: use core API to update/provide stats
Commit d3fd65484c781 ("net: core: add dev_sw_netstats_tx_add") has added function "dev_sw_netstats_tx_add()" to update net device per-cpu TX stats.
Use this function instead of own code.
While on it, remove internal_get_stats() and replace it with dev_get_tstats64().
---
v2:
- do not delete len variable and add comment why
- replace internal_get_stats() vs dev_get_tstats64()
net/openvswitch/vport-internal_dev.c | 29 +++++++--------------------- 1 file changed, 7 insertions(+), 22 deletions(-)
net/openvswitch/vport-internal_dev.c +7 -22
@@ -35,21 +35,18 @@ internal_dev_xmit(struct sk_buff *skb, struct net_device *netdev) {int len, err; +/* store len value because skb can be freed inside ovs_vport_receive() */ len = skb->len; +rcu_read_lock (); err =ovs_vport_receive (internal_dev_priv (netdev)->vport, skb,NULL );rcu_read_unlock (); -if (likely (!err)) { -struct pcpu_sw_netstats *tstats =this_cpu_ptr (netdev->tstats); - -u64_stats_update_begin (&tstats->syncp); - tstats->tx_bytes += len; - tstats->tx_packets++; -u64_stats_update_end (&tstats->syncp); - }else { +if (likely (!err)) +dev_sw_netstats_tx_add (netdev,1 , len); +else netdev->stats.tx_errors++; - } +return NETDEV_TX_OK ; }
@@ -83,24 +80,12 @@ static void internal_dev_destructor(struct net_device *dev)ovs_vport_free (vport); } -static void -internal_get_stats (struct net_device *dev,struct rtnl_link_stats64 *stats) -{ -memset (stats,0 ,sizeof (*stats)); - stats->rx_errors = dev->stats.rx_errors; - stats->tx_errors = dev->stats.tx_errors; - stats->tx_dropped = dev->stats.tx_dropped; - stats->rx_dropped = dev->stats.rx_dropped; - -dev_fetch_sw_netstats (stats, dev->tstats); -} -static const struct net_device_ops internal_dev_netdev_ops = { .ndo_open = internal_dev_open, .ndo_stop = internal_dev_stop, .ndo_start_xmit = internal_dev_xmit, .ndo_set_mac_address = eth_mac_addr, - .ndo_get_stats64 = internal_get_stats, + .ndo_get_stats64 = dev_get_tstats64, };static struct rtnl_link_ops internal_dev_link_ops__read_mostly = {
Signature · 1 line
2.25.1
Re: [PATCH v2 2/3] net: openvswitch: use core API to update/provide stats
Am 13.11.2020 um 10:02 schrieb Lev Stipakov:
Quoted 9 lines
Commit
d3fd65484c781("net: core: adddev_sw_netstats_tx_add") has added function "dev_sw_netstats_tx_add()" to update net device per-cpu TX stats.Use this function instead of own code.
While on it, remove
internal_get_stats()and replace it withdev_get_tstats64().
Quoted 7 lines
Signed-off-by Lev Stipakov <[email protected]>---
v2:
- do not delete len variable and add comment why
- replaceinternal_get_stats()vsdev_get_tstats64()
PATCH v3 1/1 net: openvswitch: use core API to update/provide stats
Commit d3fd65484c781 ("net: core: add dev_sw_netstats_tx_add") has added function "dev_sw_netstats_tx_add()" to update net device per-cpu TX stats.
Use this function instead of own code.
While on it, remove internal_get_stats() and replace it with dev_get_tstats64().
---
v3: no code changes, just send separate patch instead of series as
requested
v2:
- do not delete len variable and add comment why
- replace internal_get_stats() vs dev_get_tstats64()
net/openvswitch/vport-internal_dev.c | 29 +++++++--------------------- 1 file changed, 7 insertions(+), 22 deletions(-)
net/openvswitch/vport-internal_dev.c +7 -22
@@ -35,21 +35,18 @@ internal_dev_xmit(struct sk_buff *skb, struct net_device *netdev) {int len, err; +/* store len value because skb can be freed inside ovs_vport_receive() */ len = skb->len; +rcu_read_lock (); err =ovs_vport_receive (internal_dev_priv (netdev)->vport, skb,NULL );rcu_read_unlock (); -if (likely (!err)) { -struct pcpu_sw_netstats *tstats =this_cpu_ptr (netdev->tstats); - -u64_stats_update_begin (&tstats->syncp); - tstats->tx_bytes += len; - tstats->tx_packets++; -u64_stats_update_end (&tstats->syncp); - }else { +if (likely (!err)) +dev_sw_netstats_tx_add (netdev,1 , len); +else netdev->stats.tx_errors++; - } +return NETDEV_TX_OK ; }
@@ -83,24 +80,12 @@ static void internal_dev_destructor(struct net_device *dev)ovs_vport_free (vport); } -static void -internal_get_stats (struct net_device *dev,struct rtnl_link_stats64 *stats) -{ -memset (stats,0 ,sizeof (*stats)); - stats->rx_errors = dev->stats.rx_errors; - stats->tx_errors = dev->stats.tx_errors; - stats->tx_dropped = dev->stats.tx_dropped; - stats->rx_dropped = dev->stats.rx_dropped; - -dev_fetch_sw_netstats (stats, dev->tstats); -} -static const struct net_device_ops internal_dev_netdev_ops = { .ndo_open = internal_dev_open, .ndo_stop = internal_dev_stop, .ndo_start_xmit = internal_dev_xmit, .ndo_set_mac_address = eth_mac_addr, - .ndo_get_stats64 = internal_get_stats, + .ndo_get_stats64 = dev_get_tstats64, };static struct rtnl_link_ops internal_dev_link_ops__read_mostly = {
Signature · 1 line
2.25.1
Re: [PATCH v3] net: openvswitch: use core API to update/provide stats
This patch was applied to netdev/net-next.git (refs/heads/master):
Hello:
This patch was applied to netdev/net-next.git (refs/heads/master):
Quoted 10 lines · On Fri, 13 Nov 2020 23:53:36 +0200 you wrote:
Commit
d3fd65484c781("net: core: adddev_sw_netstats_tx_add") has added function "dev_sw_netstats_tx_add()" to update net device per-cpu TX stats.Use this function instead of own code.
While on it, remove
internal_get_stats()and replace it withdev_get_tstats64().[...]
Here is the summary with links:
- [v3] net: openvswitch: use core API to update/provide stats
https://git.kernel.org/netdev/net-next/c/865e6ae02dd7
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html