Skip to contentSkip to conversation

vxlan: Do not alloc tstats manually

PATCH Applied Breno Leitao 3 participants 5 messages Mar 11, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 vxlan: Do not alloc tstats manually

With commit 34d21de99cea9 ("net: Move {l,t,d}stats allocation to core and convert veth & vrf"), stats allocation could be done on net core instead of in this driver.

With this new approach, the driver doesn't have to bother with error handling (allocation failure checking, making sure free happens in the right spot, etc). This is core responsibility now.

Remove the allocation in the vxlan driver and leverage the network core allocation instead.

---
 drivers/net/vxlan/vxlan_core.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/net/vxlan/vxlan_core.c +2 -11
index 386cbe4d3327..6f26003a3064 100644
@@ -2841,15 +2841,9 @@ static int vxlan_init(struct net_device *dev)
 	if (vxlan->cfg.flags & VXLAN_F_VNIFILTER)
 		vxlan_vnigroup_init(vxlan);
 
-	dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
-	if (!dev->tstats) {
-		err = -ENOMEM;
-		goto err_vnigroup_uninit;
-	}
-
 	err = gro_cells_init(&vxlan->gro_cells, dev);
 	if (err)
-		goto err_free_percpu;
+		goto err_vnigroup_uninit;
 
 	err = vxlan_mdb_init(vxlan);
 	if (err)
@@ -2860,8 +2854,6 @@ static int vxlan_init(struct net_device *dev)
 
 err_gro_cells_destroy:
 	gro_cells_destroy(&vxlan->gro_cells);
-err_free_percpu:
-	free_percpu(dev->tstats);
 err_vnigroup_uninit:
 	if (vxlan->cfg.flags & VXLAN_F_VNIFILTER)
 		vxlan_vnigroup_uninit(vxlan);
@@ -2892,8 +2884,6 @@ static void vxlan_uninit(struct net_device *dev)
 	gro_cells_destroy(&vxlan->gro_cells);
 
 	vxlan_fdb_delete_default(vxlan, vxlan->cfg.vni);
-
-	free_percpu(dev->tstats);
 }
 
 /* Start ageing timer and join group when device is brought up */
@@ -3316,6 +3306,7 @@ static void vxlan_setup(struct net_device *dev)
 	dev->min_mtu = ETH_MIN_MTU;
 	dev->max_mtu = ETH_MAX_MTU;
 
+	dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
 	INIT_LIST_HEAD(&vxlan->next);
 
 	timer_setup(&vxlan->age_timer, vxlan_cleanup, TIMER_DEFERRABLE);
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 vxlan: Remove generic .ndo_get_stats64

Commit 3e2f544dd8a33 ("net: get stats64 if device if driver is configured") moved the callback to dev_get_tstats64() to net core, so, unless the driver is doing some custom stats collection, it does not need to set .ndo_get_stats64.

Since this driver is now relying in NETDEV_PCPU_STAT_TSTATS, then, it doesn't need to set the dev_get_tstats64() generic .ndo_get_stats64 function pointer.

---
 drivers/net/vxlan/vxlan_core.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/vxlan/vxlan_core.c +0 -2
index 6f26003a3064..3495591a5c29 100644
@@ -3214,7 +3214,6 @@ static const struct net_device_ops vxlan_netdev_ether_ops = {
 	.ndo_open		= vxlan_open,
 	.ndo_stop		= vxlan_stop,
 	.ndo_start_xmit		= vxlan_xmit,
-	.ndo_get_stats64	= dev_get_tstats64,
 	.ndo_set_rx_mode	= vxlan_set_multicast_list,
 	.ndo_change_mtu		= vxlan_change_mtu,
 	.ndo_validate_addr	= eth_validate_addr,
@@ -3238,7 +3237,6 @@ static const struct net_device_ops vxlan_netdev_raw_ops = {
 	.ndo_open		= vxlan_open,
 	.ndo_stop		= vxlan_stop,
 	.ndo_start_xmit		= vxlan_xmit,
-	.ndo_get_stats64	= dev_get_tstats64,
 	.ndo_change_mtu		= vxlan_change_mtu,
 	.ndo_fill_metadata_dst	= vxlan_fill_metadata_dst,
 };
Signature · 1 line
2.43.0
Reviewed-by on v1 2/2
#2 lore raw

RE: [EXTERNAL] [PATCH net-next 2/2] vxlan: Remove generic .ndo_get_stats64

Quoted 22 lines

-----Original Message-----
From: Breno Leitao <[email protected]>
Sent: Monday, March 11, 2024 4:55 PM
To: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>
Cc: [email protected]; Ido Schimmel <[email protected]>; Nikolay Aleksandrov <[email protected]>; Amit Cohen <[email protected]>; Petr Machata <[email protected]>; Jiri Benc <[email protected]>; Beniamino Galvani <[email protected]>; Gavin Li <[email protected]>; open list:NETWORKING DRIVERS <[email protected]>; open list <linux- [email protected]>
Subject: [EXTERNAL] [PATCH net-next 2/2] vxlan: Remove generic .ndo_get_stats64

Commit 3e2f544dd8a33 ("net: get stats64 if device if driver is configured") moved the callback to dev_get_tstats64() to net core, so, unless the driver is doing some custom stats collection, it does not need to set .ndo_get_stats64.

Quoted 5 lines

Since this driver is now relying in NETDEV_PCPU_STAT_TSTATS, then, it doesn't need to set the dev_get_tstats64() generic .ndo_get_stats64 function pointer.

...

Reviewed-by on v1 1/2
#3 lore raw
In reply to Breno Leitao
Quoted 20 lines

-----Original Message-----
From: Breno Leitao <[email protected]>
Sent: Monday, March 11, 2024 4:55 PM
To: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>
Cc: [email protected]; Ido Schimmel <[email protected]>; Nikolay Aleksandrov <[email protected]>; Amit Cohen <[email protected]>; Petr Machata <[email protected]>; Jiri Benc <[email protected]>; Beniamino Galvani <[email protected]>; Gavin Li <[email protected]>; open list:NETWORKING DRIVERS <[email protected]>; open list <linux- [email protected]>
Subject: [EXTERNAL] [PATCH net-next 1/2] vxlan: Do not alloc tstats manually

With commit 34d21de99cea9 ("net: Move {l,t,d}stats allocation to core and convert veth & vrf"), stats allocation could be done on net core instead of in this driver.

Quoted 8 lines

With this new approach, the driver doesn't have to bother with error handling (allocation failure checking, making sure free happens in the right spot, etc). This is core responsibility now.

Remove the allocation in the vxlan driver and leverage the network core allocation instead.

Quoted 1 line

---

#4 lore raw
In reply to Breno Leitao
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Mon, 11 Mar 2024 04:24:30 -0700 you wrote:

With commit 34d21de99cea9 ("net: Move {l,t,d}stats allocation to core and convert veth & vrf"), stats allocation could be done on net core instead of in this driver.

With this new approach, the driver doesn't have to bother with error handling (allocation failure checking, making sure free happens in the right spot, etc). This is core responsibility now.

[...]

Here is the summary with links:
- [net-next,1/2] vxlan: Do not alloc tstats manually

    https://git.kernel.org/netdev/net-next/c/e28c5efc3139
  - [net-next,2/2] vxlan: Remove generic .ndo_get_stats64
    https://git.kernel.org/netdev/net-next/c/195f88c57737

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html