LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 1/2] net: tuntap: Leverage core stats allocator
@ 2024-03-04 18:38 Breno Leitao
  2024-03-04 18:38 ` [PATCH net-next 2/2] net: tap: Remove generic .ndo_get_stats64 Breno Leitao
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Breno Leitao @ 2024-03-04 18:38 UTC (permalink / raw
  To: kuba, davem, pabeni, edumazet, Willem de Bruijn, Jason Wang
  Cc: netdev, linux-kernel, horms, dsahern

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 tun/tap driver and leverage the network
core allocation instead.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 drivers/net/tun.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index be37235af55d..6c594a3c2c37 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -977,20 +977,15 @@ static int tun_net_init(struct net_device *dev)
 	struct ifreq *ifr = tun->ifr;
 	int err;
 
-	dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
-	if (!dev->tstats)
-		return -ENOMEM;
-
 	spin_lock_init(&tun->lock);
 
 	err = security_tun_dev_alloc_security(&tun->security);
-	if (err < 0) {
-		free_percpu(dev->tstats);
+	if (err < 0)
 		return err;
-	}
 
 	tun_flow_init(tun);
 
+	dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
 	dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST |
 			   TUN_USER_FEATURES | NETIF_F_HW_VLAN_CTAG_TX |
 			   NETIF_F_HW_VLAN_STAG_TX;
@@ -1008,7 +1003,6 @@ static int tun_net_init(struct net_device *dev)
 	if (err < 0) {
 		tun_flow_uninit(tun);
 		security_tun_dev_free_security(tun->security);
-		free_percpu(dev->tstats);
 		return err;
 	}
 	return 0;
@@ -2317,7 +2311,6 @@ static void tun_free_netdev(struct net_device *dev)
 
 	BUG_ON(!(list_empty(&tun->disabled)));
 
-	free_percpu(dev->tstats);
 	tun_flow_uninit(tun);
 	security_tun_dev_free_security(tun->security);
 	__tun_set_ebpf(tun, &tun->steering_prog, NULL);
-- 
2.43.0


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

* [PATCH net-next 2/2] net: tap: Remove generic .ndo_get_stats64
  2024-03-04 18:38 [PATCH net-next 1/2] net: tuntap: Leverage core stats allocator Breno Leitao
@ 2024-03-04 18:38 ` Breno Leitao
  2024-03-05  9:21   ` Willem de Bruijn
  2024-03-05  9:20 ` [PATCH net-next 1/2] net: tuntap: Leverage core stats allocator Willem de Bruijn
  2024-03-06  2:40 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 5+ messages in thread
From: Breno Leitao @ 2024-03-04 18:38 UTC (permalink / raw
  To: kuba, davem, pabeni, edumazet, Willem de Bruijn, Jason Wang
  Cc: netdev, linux-kernel, horms, dsahern

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.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 drivers/net/tun.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 6c594a3c2c37..8d258e263f54 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1338,7 +1338,6 @@ static const struct net_device_ops tap_netdev_ops = {
 	.ndo_select_queue	= tun_select_queue,
 	.ndo_features_check	= passthru_features_check,
 	.ndo_set_rx_headroom	= tun_set_headroom,
-	.ndo_get_stats64	= dev_get_tstats64,
 	.ndo_bpf		= tun_xdp,
 	.ndo_xdp_xmit		= tun_xdp_xmit,
 	.ndo_change_carrier	= tun_net_change_carrier,
-- 
2.43.0


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

* Re: [PATCH net-next 1/2] net: tuntap: Leverage core stats allocator
  2024-03-04 18:38 [PATCH net-next 1/2] net: tuntap: Leverage core stats allocator Breno Leitao
  2024-03-04 18:38 ` [PATCH net-next 2/2] net: tap: Remove generic .ndo_get_stats64 Breno Leitao
@ 2024-03-05  9:20 ` Willem de Bruijn
  2024-03-06  2:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: Willem de Bruijn @ 2024-03-05  9:20 UTC (permalink / raw
  To: Breno Leitao, kuba, davem, pabeni, edumazet, Willem de Bruijn,
	Jason Wang
  Cc: netdev, linux-kernel, horms, dsahern

Breno Leitao 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.
> 
> Remove the allocation in the tun/tap driver and leverage the network
> core allocation instead.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>

Reviewed-by: Willem de Bruijn <willemb@google.com>

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

* Re: [PATCH net-next 2/2] net: tap: Remove generic .ndo_get_stats64
  2024-03-04 18:38 ` [PATCH net-next 2/2] net: tap: Remove generic .ndo_get_stats64 Breno Leitao
@ 2024-03-05  9:21   ` Willem de Bruijn
  0 siblings, 0 replies; 5+ messages in thread
From: Willem de Bruijn @ 2024-03-05  9:21 UTC (permalink / raw
  To: Breno Leitao, kuba, davem, pabeni, edumazet, Willem de Bruijn,
	Jason Wang
  Cc: netdev, linux-kernel, horms, dsahern

Breno Leitao wrote:
> 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.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>

Reviewed-by: Willem de Bruijn <willemb@google.com>

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

* Re: [PATCH net-next 1/2] net: tuntap: Leverage core stats allocator
  2024-03-04 18:38 [PATCH net-next 1/2] net: tuntap: Leverage core stats allocator Breno Leitao
  2024-03-04 18:38 ` [PATCH net-next 2/2] net: tap: Remove generic .ndo_get_stats64 Breno Leitao
  2024-03-05  9:20 ` [PATCH net-next 1/2] net: tuntap: Leverage core stats allocator Willem de Bruijn
@ 2024-03-06  2:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-03-06  2:40 UTC (permalink / raw
  To: Breno Leitao
  Cc: kuba, davem, pabeni, edumazet, willemdebruijn.kernel, jasowang,
	netdev, linux-kernel, horms, dsahern

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  4 Mar 2024 10:38:07 -0800 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] net: tuntap: Leverage core stats allocator
    https://git.kernel.org/netdev/net-next/c/46f480ec1458
  - [net-next,2/2] net: tap: Remove generic .ndo_get_stats64
    https://git.kernel.org/netdev/net-next/c/4166204d7ec2

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2024-03-06  2:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-04 18:38 [PATCH net-next 1/2] net: tuntap: Leverage core stats allocator Breno Leitao
2024-03-04 18:38 ` [PATCH net-next 2/2] net: tap: Remove generic .ndo_get_stats64 Breno Leitao
2024-03-05  9:21   ` Willem de Bruijn
2024-03-05  9:20 ` [PATCH net-next 1/2] net: tuntap: Leverage core stats allocator Willem de Bruijn
2024-03-06  2:40 ` patchwork-bot+netdevbpf

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 read-only IMAP folder(s) and NNTP newsgroup(s).