net: tuntap: Leverage core stats allocator
authorBreno Leitao <leitao@debian.org>
Mon, 4 Mar 2024 18:38:07 +0000 (10:38 -0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 6 Mar 2024 02:32:33 +0000 (18:32 -0800)
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>
Link: https://lore.kernel.org/r/20240304183810.1474883-1-leitao@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/tun.c

index be37235..6c594a3 100644 (file)
@@ -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);