Make .ndo_get_stats64 sleepable
Subsystems (83)
v6 cover Make .ndo_get_stats64 sleepable
From: Vladimir Oltean <[email protected]>
There is a desire to standardize the counters that have previously been reported through ethtool statistics into something that can be more uniformly queried from user space. The ndo_get_stats64 are a good candidate to keep standardized counters, as well as add new ones (like RMON MIBs) but unfortunately, as things stand, migration will not be smooth sailing if the ndo_get_stats64 does not offer the same calling context as ethtool does. Namely, currently ndo_get_stats64 assumes atomic context, and this series would like to change that.
The reason why sleeping while retrieving counters would be desirable in the first place is that if we have hardware that needs to be accessed through a slow bus like SPI, or through a firmware. Today we cannot do that directly in .ndo_get_stats64, so we would have to poll counters periodically and return a cached (not up to date) copy in the atomic NDO callback. This is undesirable on both ends: more work than strictly needed is being done, and the end result is also worse (not guaranteed to be up to date). Also, retrieving counters from the hardware rather than software counters incremented by the driver is more compatible with the concept of interfaces with offload for L2 or L3 forwarding, where the CPU otherwise never has a chance to keep accurate counters for most of the traffic.
Changes in v6:
- Rebase on top of Jakub's patch 9f9d41f03bb0 ("docs: net: fix documentation on .ndo_get_stats").
- s/break/return -ENOMEM/ in bond_get_slaves.
- Fixed rtnetlink incorrectly returning 0 in rtnl_fill_ifinfo on nla_put_failure and causing "ip a" to not show any interfaces.
- Squashed the patch to propagate errors with the one to terminate them.
- Removed the unused "int err" in __bond_release_one from patch 08 and added it in the patch it belongs to.
Changes in v5:
- Changed bonding and net_failover to use rcu_read_lock().
- Actually propagating errors from bond_get_stats now.
Changes in v4:
- Propagated errors from ndo_get_stats64.
Changes in v3:
- Resolved some memory leak issues in the bonding patch 10/12.
Changes in v2:
- Addressed the recursion issues in .ndo_get_stats64 from bonding and net_failover.
- Renamed netdev_lists_lock to netif_lists_lock
- Stopped taking netif_lists_lock from drivers as much as possible. *** SUBJECT HERE ***
*** BLURB HERE ***
Vladimir Oltean (15):
net: mark dev_base_lock for deprecation
net: introduce a mutex for the netns interface lists
net: procfs: hold netif_lists_lock when retrieving device statistics
net: sysfs: don't hold dev_base_lock while retrieving device
statistics
s390/appldata_net_sum: hold the netdev lists lock when retrieving
device statistics
parisc/led: hold the netdev lists lock when retrieving device
statistics
net: remove return value from dev_get_stats
net: allow ndo_get_stats64 to return an int error code
scsi: fcoe: propagate errors from dev_get_stats
net: openvswitch: propagate errors from dev_get_stats
net: catch errors from dev_get_stats
net: openvswitch: ensure dev_get_stats can sleep
net: net_failover: ensure .ndo_get_stats64 can sleep
net: bonding: ensure .ndo_get_stats64 can sleep
net: mark ndo_get_stats64 as being able to sleep
Documentation/networking/netdevices.rst | 8 +- Documentation/networking/statistics.rst | 9 +- arch/s390/appldata/appldata_net_sum.c | 41 +++--- drivers/infiniband/hw/hfi1/vnic_main.c | 6 +- drivers/infiniband/ulp/ipoib/ipoib_main.c | 9 +- .../infiniband/ulp/opa_vnic/opa_vnic_netdev.c | 9 +- drivers/leds/trigger/ledtrig-netdev.c | 16 ++- drivers/net/bonding/bond_main.c | 135 ++++++++++-------- drivers/net/dummy.c | 6 +- drivers/net/ethernet/alacritech/slicoss.c | 6 +- drivers/net/ethernet/amazon/ena/ena_netdev.c | 8 +- drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 6 +- drivers/net/ethernet/apm/xgene-v2/main.c | 6 +- .../ethernet/apm/xgene/xgene_enet_ethtool.c | 9 +- .../net/ethernet/apm/xgene/xgene_enet_main.c | 7 +- drivers/net/ethernet/atheros/alx/main.c | 6 +- drivers/net/ethernet/broadcom/b44.c | 6 +- drivers/net/ethernet/broadcom/bcmsysport.c | 6 +- drivers/net/ethernet/broadcom/bnx2.c | 5 +- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 6 +- drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c | 4 +- drivers/net/ethernet/broadcom/tg3.c | 8 +- drivers/net/ethernet/brocade/bna/bnad.c | 4 +- drivers/net/ethernet/calxeda/xgmac.c | 4 +- .../net/ethernet/cavium/liquidio/lio_main.c | 6 +- .../ethernet/cavium/liquidio/lio_vf_main.c | 6 +- .../net/ethernet/cavium/liquidio/lio_vf_rep.c | 8 +- .../net/ethernet/cavium/thunder/nicvf_main.c | 5 +- .../net/ethernet/chelsio/cxgb4/cxgb4_main.c | 8 +- drivers/net/ethernet/cisco/enic/enic_main.c | 8 +- drivers/net/ethernet/cortina/gemini.c | 6 +- drivers/net/ethernet/ec_bhf.c | 4 +- drivers/net/ethernet/emulex/benet/be_main.c | 6 +- .../net/ethernet/freescale/dpaa/dpaa_eth.c | 6 +- .../net/ethernet/freescale/dpaa2/dpaa2-eth.c | 6 +- drivers/net/ethernet/google/gve/gve_main.c | 4 +- drivers/net/ethernet/hisilicon/hns/hns_enet.c | 6 +- .../net/ethernet/hisilicon/hns/hns_ethtool.c | 56 ++++---- .../net/ethernet/hisilicon/hns3/hns3_enet.c | 8 +- .../net/ethernet/huawei/hinic/hinic_main.c | 6 +- drivers/net/ethernet/ibm/ehea/ehea_main.c | 6 +- drivers/net/ethernet/intel/e1000e/e1000.h | 4 +- drivers/net/ethernet/intel/e1000e/ethtool.c | 9 +- drivers/net/ethernet/intel/e1000e/netdev.c | 6 +- .../net/ethernet/intel/fm10k/fm10k_netdev.c | 6 +- drivers/net/ethernet/intel/i40e/i40e_main.c | 10 +- drivers/net/ethernet/intel/ice/ice_main.c | 6 +- drivers/net/ethernet/intel/igb/igb_main.c | 10 +- drivers/net/ethernet/intel/igc/igc_main.c | 6 +- .../net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 14 +- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 6 +- drivers/net/ethernet/intel/ixgbevf/ethtool.c | 14 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 6 +- drivers/net/ethernet/marvell/mvneta.c | 4 +- .../net/ethernet/marvell/mvpp2/mvpp2_main.c | 4 +- .../marvell/octeontx2/nic/otx2_common.c | 6 +- .../marvell/octeontx2/nic/otx2_common.h | 4 +- .../ethernet/marvell/prestera/prestera_main.c | 6 +- drivers/net/ethernet/marvell/sky2.c | 6 +- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 6 +- drivers/net/ethernet/mediatek/mtk_star_emac.c | 6 +- .../net/ethernet/mellanox/mlx4/en_netdev.c | 4 +- drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 4 +- .../net/ethernet/mellanox/mlx5/core/en_rep.c | 4 +- .../ethernet/mellanox/mlx5/core/ipoib/ipoib.c | 4 +- .../ethernet/mellanox/mlx5/core/ipoib/ipoib.h | 2 +- .../net/ethernet/mellanox/mlxsw/spectrum.c | 4 +- .../net/ethernet/mellanox/mlxsw/switchx2.c | 4 +- drivers/net/ethernet/microchip/lan743x_main.c | 6 +- drivers/net/ethernet/mscc/ocelot_net.c | 6 +- .../net/ethernet/myricom/myri10ge/myri10ge.c | 12 +- .../net/ethernet/neterion/vxge/vxge-main.c | 4 +- .../ethernet/netronome/nfp/nfp_net_common.c | 6 +- .../net/ethernet/netronome/nfp/nfp_net_repr.c | 6 +- drivers/net/ethernet/nvidia/forcedeth.c | 4 +- .../net/ethernet/pensando/ionic/ionic_lif.c | 6 +- .../net/ethernet/pensando/ionic/ionic_lif.h | 4 +- .../ethernet/qlogic/netxen/netxen_nic_main.c | 10 +- drivers/net/ethernet/qlogic/qede/qede_main.c | 6 +- drivers/net/ethernet/qualcomm/emac/emac.c | 6 +- .../net/ethernet/qualcomm/rmnet/rmnet_vnd.c | 8 +- drivers/net/ethernet/realtek/8139too.c | 8 +- drivers/net/ethernet/realtek/r8169_main.c | 4 +- .../net/ethernet/samsung/sxgbe/sxgbe_main.c | 6 +- drivers/net/ethernet/sfc/efx_common.c | 4 +- drivers/net/ethernet/sfc/efx_common.h | 2 +- drivers/net/ethernet/sfc/falcon/efx.c | 6 +- drivers/net/ethernet/socionext/sni_ave.c | 6 +- drivers/net/ethernet/sun/niu.c | 6 +- .../net/ethernet/synopsys/dwc-xlgmac-net.c | 6 +- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 6 +- drivers/net/ethernet/ti/netcp_core.c | 4 +- drivers/net/ethernet/via/via-rhine.c | 8 +- drivers/net/fjes/fjes_main.c | 6 +- drivers/net/hyperv/netvsc_drv.c | 6 +- drivers/net/ifb.c | 5 +- drivers/net/ipvlan/ipvlan_main.c | 6 +- drivers/net/loopback.c | 6 +- drivers/net/macsec.c | 8 +- drivers/net/macvlan.c | 6 +- drivers/net/mhi_net.c | 6 +- drivers/net/net_failover.c | 96 +++++++++---- drivers/net/netdevsim/netdev.c | 4 +- drivers/net/nlmon.c | 4 +- drivers/net/ppp/ppp_generic.c | 4 +- drivers/net/slip/slip.c | 4 +- drivers/net/team/team.c | 4 +- drivers/net/thunderbolt.c | 6 +- drivers/net/tun.c | 4 +- drivers/net/veth.c | 6 +- drivers/net/virtio_net.c | 6 +- drivers/net/vmxnet3/vmxnet3_ethtool.c | 4 +- drivers/net/vmxnet3/vmxnet3_int.h | 4 +- drivers/net/vrf.c | 6 +- drivers/net/vsockmon.c | 4 +- drivers/net/xen-netfront.c | 6 +- drivers/parisc/led.c | 42 +++--- drivers/s390/net/qeth_core.h | 2 +- drivers/s390/net/qeth_core_main.c | 4 +- drivers/scsi/fcoe/fcoe_sysfs.c | 9 +- drivers/scsi/fcoe/fcoe_transport.c | 28 ++-- drivers/scsi/libfc/fc_rport.c | 5 +- drivers/staging/fsl-dpaa2/ethsw/ethsw.c | 8 +- drivers/staging/netlogic/xlr_net.c | 4 +- drivers/usb/gadget/function/rndis.c | 47 +++--- include/linux/netdevice.h | 22 ++- include/net/bonding.h | 53 +++++++ include/net/net_namespace.h | 6 + include/scsi/fcoe_sysfs.h | 12 +- include/scsi/libfc.h | 2 +- include/scsi/libfcoe.h | 8 +- net/8021q/vlan_dev.c | 6 +- net/8021q/vlanproc.c | 20 +-- net/core/dev.c | 79 ++++++---- net/core/net-procfs.c | 62 ++++---- net/core/net-sysfs.c | 12 +- net/core/rtnetlink.c | 23 ++- net/l2tp/l2tp_eth.c | 6 +- net/mac80211/iface.c | 4 +- net/openvswitch/datapath.c | 63 ++++---- net/openvswitch/vport.c | 35 +++-- net/openvswitch/vport.h | 2 +- net/sched/sch_teql.c | 6 +- 144 files changed, 1016 insertions(+), 567 deletions(-)
Signature · 1 line
2.25.1
PATCH v6 1/15 net: mark dev_base_lock for deprecation
From: Vladimir Oltean <[email protected]>
There is a movement to eliminate the usage of dev_base_lock, which exists since as far as I could track the kernel history down (the "7a2deb329241 Import changeset" commit from the bitkeeper branch).
The dev_base_lock approach has multiple issues:
- It is global and not per netns.
- Its meaning has mutated over the years and the vast majority of current users is using it to protect against changes of network device state, as opposed to changes of the interface list.
- It is overlapping with other protection mechanisms introduced in the meantime, which have higher performance for readers, like RCU introduced in 2009 by Eric Dumazet for kernel 2.6.
The old comment that I just deleted made this distinction: writers protect only against readers by holding dev_base_lock, whereas they need to protect against other writers by holding the RTNL mutex. This is slightly confusing/incorrect, since a rwlock_t cannot have more than one concurrently running writer, so that explanation does not justify why the RTNL mutex would be necessary.
Instead, Stephen Hemminger makes this clarification here:
https://lore.kernel.org/netdev/[email protected]/T/#u
| There are really two different domains being covered by locks here. | | The first area is change of state of network devices. This has traditionally | been covered by RTNL because there are places that depend on coordinating | state between multiple devices. RTNL is too big and held too long but getting | rid of it is hard because there are corner cases (like state changes from userspace | for VPN devices). | | The other area is code that wants to do read access to look at list of devices. | These pure readers can/should be converted to RCU by now. Writers should hold RTNL.
This patch edits the comment for dev_base_lock, minimizing its role in the protection of network interface lists, and clarifies that it is has other purposes as well.
---
Changes in v6:
None.
Changes in v5:
None.
Changes in v4:
None.
Changes in v3:
None.
Changes in v2:
None.
net/core/dev.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
net/core/dev.c +16 -17
@@ -169,23 +169,22 @@ static int call_netdevice_notifiers_extack(unsigned long val,static struct napi_struct *napi_by_id (unsigned int napi_id);/* -* The @dev_base_head list is protected by @dev_base_lock and the rtnl -* semaphore. -* -* Pure readers hold dev_base_lock for reading, or rcu_read_lock() -* -* Writers must hold the rtnl semaphore while they loop through the -* dev_base_head list, and hold dev_base_lock for writing when they do the -* actual updates. This allows pure readers to access the list even -* while a writer is preparing to update it. -* -* To put it another way, dev_base_lock is held for writing only to -* protect against pure readers; the rtnl semaphore provides the -* protection against other writers. -* -* See, for example usages, register_netdevice() and -* unregister_netdevice(), which must be called with the rtnl -* semaphore held. +* The network interface list of a netns (@net->dev_base_head) and the hash +* tables per ifindex (@net->dev_index_head) and per name (@net->dev_name_head) +* are protected using the following rules: +* +* Pure readers should hold rcu_read_lock() which should protect them against +* concurrent changes to the interface lists made by the writers. Pure writers +* must serialize by holding the RTNL mutex while they loop through the list +* and make changes to it. +* +* It is also possible to hold the global rwlock_t @dev_base_lock for +* protection (holding its read side as an alternative to rcu_read_lock, and +* its write side as an alternative to the RTNL mutex), however this should not +* be done in new code, since it is deprecated and pending removal. +* +* One other role of @dev_base_lock is to protect against changes in the +* operational state of a network interface. */ DEFINE_RWLOCK (dev_base_lock);EXPORT_SYMBOL (dev_base_lock);
Signature · 1 line
2.25.1
PATCH v6 2/15 net: introduce a mutex for the netns interface lists
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Currently, any writer that wants to alter the lists of network interfaces (either the plain list net->dev_base_head, or the hash tables net->dev_index_head and net->dev_name_head) can keep other writers at bay using the RTNL mutex.
However, the RTNL mutex has become a very contended resource over the years, so there is a movement to do finer grained locking.
This patch adds one more way for writers to the network interface lists to serialize themselves. We assume that all writers to the network interface lists are easily identifiable because the write side of dev_base_lock also needs to be held (note that some instances of that were deliberately skipped, since they only dealt with protecting the operational state of the netdev).
Holding the RTNL mutex is now optional for new code that alters the lists, since all relevant writers were made to also hold the new lock.
---
Changes in v6:
None.
Changes in v5:
None.
Changes in v4:
None.
Changes in v3:
None.
include/linux/netdevice.h | 10 +++++++++ include/net/net_namespace.h | 6 +++++ net/core/dev.c | 44 +++++++++++++++++++++++++------------ 3 files changed, 46 insertions(+), 14 deletions(-)
include/linux/netdevice.h +10 -0
@@ -4376,6 +4376,16 @@ static inline void netif_addr_unlock_bh(struct net_device *dev)spin_unlock_bh (&dev->addr_list_lock); } +static inline void netif_lists_lock (struct net *net) +{ +mutex_lock (&net->netif_lists_lock); +} + +static inline void netif_lists_unlock (struct net *net) +{ +mutex_unlock (&net->netif_lists_lock); +} +/* * dev_addrs walker. Should be used only for read access. Call with * rcu_read_lock held.
include/net/net_namespace.h +6 -0
@@ -183,6 +183,12 @@ struct net {struct sock *crypto_nlsk;#endif struct sock *diag_nlsk; + +/* Serializes writers to @dev_base_head, @dev_name_head and +* @dev_index_head. It does _not_ protect the netif adjacency lists +* (struct net_device::adj_list). +*/ +struct mutex netif_lists_lock; } __randomize_layout;#include <linux/seq_file_net.h>
net/core/dev.c +30 -14
119 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v6 3/15 net: procfs: hold netif_lists_lock when retrieving device statistics
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
In the effort of making .ndo_get_stats64 be able to sleep, we need to ensure the callers of dev_get_stats do not use atomic context.
The /proc/net/dev file uses an RCU read-side critical section to ensure the integrity of the list of network interfaces, because it iterates through all net devices in the netns to show their statistics.
To offer the equivalent protection against an interface registering or deregistering, while also remaining in sleepable context, we can use the netns mutex for the interface lists.
---
Changes in v6:
None.
Changes in v5:
None.
Changes in v4:
None.
Changes in v3:
None.
Changes in v2:
None.
net/core/net-procfs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
net/core/net-procfs.c +8 -5
@@ -21,7 +21,7 @@ static inline struct net_device *dev_from_same_bucket(struct seq_file *seq, loffunsigned int count =0 , offset =get_offset (*pos); h = &net->dev_index_head[get_bucket (*pos)]; -hlist_for_each_entry_rcu (dev, h, index_hlist) { +hlist_for_each_entry (dev, h, index_hlist) {if (++count == offset)return dev; }
@@ -51,9 +51,11 @@ static inline struct net_device *dev_from_bucket(struct seq_file *seq, loff_t *p* in detail. */ static void *dev_seq_start (struct seq_file *seq,loff_t *pos) -__acquires (RCU ) { -rcu_read_lock (); +struct net *net =seq_file_net (seq); + +netif_lists_lock (net); +if (!*pos)return SEQ_START_TOKEN ;
@@ -70,9 +72,10 @@ static void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) }static void dev_seq_stop (struct seq_file *seq,void *v) -__releases (RCU ) { -rcu_read_unlock (); +struct net *net =seq_file_net (seq); + +netif_lists_unlock (net); }static void dev_seq_printf_stats (struct seq_file *seq,struct net_device *dev)
Signature · 1 line
2.25.1
Re: [PATCH v6 net-next 03/15] net: procfs: hold netif_lists_lock when retrieving device statistics
Quoted 54 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
In the effort of making .ndo_get_stats64 be able to sleep, we need to ensure the callers of
dev_get_statsdo not use atomic context.The
/proc/net/devfile uses an RCU read-side critical section to ensure
the integrity of the list of network interfaces, because it iterates through all net devices in the netns to show their statistics.To offer the equivalent protection against an interface registering or
deregistering, while also remaining in sleepable context, we can use the
netns mutex for the interface lists.Cc Cong Wang <[email protected]>Cc Eric Dumazet <[email protected]>Signed-off-by Vladimir Oltean <[email protected]>---
Changes in v6:
None.Changes in v5:
None.Changes in v4:
None.Changes in v3:
None.Changes in v2:
None.net/core/net-procfs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)net/core/net-procfs.c +1
-1@@ -21,7 +21,7 @@ static inline struct net_device *dev_from_same_bucket(struct seq_file *seq, loff unsigned int count = 0, offset = get_offset(*pos); h = &net->dev_index_head[get_bucket (*pos)]; -hlist_for_each_entry_rcu (dev, h, index_hlist) { +hlist_for_each_entry (dev, h, index_hlist) {if (++count == offset)return dev;net/core/net-procfs.c +0
-0}@@ -51,9 +51,11 @@ static inline struct net_device *dev_from_bucket(struct seq_file *seq, loff_t *p
net/core/net-procfs.c static inline struct net_device · line 59
Quoted 10 lines
net/core/net-procfs.c +4
-2* in detail. */ static void *dev_seq_start (struct seq_file *seq,loff_t *pos) -__acquires (RCU ) { -rcu_read_lock (); +struct net *net =seq_file_net (seq); + +netif_lists_lock (net); +
This can be very costly, holding a mutex while traversing the whole netedv lists and reading their stats, we need to at least allow multiple readers to enter as it was before, so maybe you want to use rw_semaphore instead of the mutex.
or just have a unified approach of rcu+refcnt/dev_hold as you did for bonding and failover patches #13..#14, I used the same approach to achieve the same for sysfs and procfs more than 2 years ago, you are welcome to use my patches:
https://lore.kernel.org/netdev/[email protected]/
Quoted 18 lines
net/core/net-procfs.c +3
-2if (!*pos)return SEQ_START_TOKEN ;@@ -70,9 +72,10 @@ static void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) }static void dev_seq_stop (struct seq_file *seq,void *v) -__releases (RCU ) { -rcu_read_unlock (); +struct net *net =seq_file_net (seq); + +netif_lists_unlock (net); }static void dev_seq_printf_stats(struct
seq_file*seq, structnet_device*dev)
Re: [PATCH v6 net-next 03/15] net: procfs: hold netif_lists_lock when retrieving device statistics
Quoted 10 lines · Saeed Mahameed
This can be very costly, holding a mutex while traversing the whole netedv lists and reading their stats, we need to at least allow multiple readers to enter as it was before, so maybe you want to use
rw_semaphoreinstead of the mutex.or just have a unified approach of rcu+refcnt/dev_hold as you did for bonding and failover patches #13..#14, I used the same approach to achieve the same for sysfs and procfs more than 2 years ago, you are welcome to use my patches:
https://lore.kernel.org/netdev/[email protected]/
Ok, what mail address do you want me to keep for your sign off?
Re: [PATCH v6 net-next 03/15] net: procfs: hold netif_lists_lock when retrieving device statistics
Quoted 15 lines · Vladimir Oltean
Quoted 6 lines · Saeed Mahameed
This can be very costly, holding a mutex while traversing the whole netedv lists and reading their stats, we need to at least allow multiple readers to enter as it was before, so maybe you want to use
rw_semaphoreinstead of the mutex.Quoted 7 lines
or just have a unified approach of rcu+refcnt/dev_hold as you did for
bonding and failover patches #13..#14, I used the same approach to achieve the same for sysfs and procfs more than 2 years ago, you are
welcome to use my patches:
https://lore.kernel.org/netdev/[email protected]/
Quoted 1 line
Ok, what mail address do you want me to keep for your sign off?
Either is fine. Just make sure author and signed-off are the same :). Thanks!
PATCH v6 4/15 net: sysfs: don't hold dev_base_lock while retrieving device statistics
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
In the effort of making .ndo_get_stats64 be able to sleep, we need to ensure the callers of dev_get_stats do not use atomic context.
I need to preface this by saying that I have no idea why netstat_show takes the dev_base_lock rwlock. Two things can be observed:
(a) it does not appear to be due to dev_isalive requiring it for some reason, because broadcast_show() also calls dev_isalive() and has had no problem existing since the beginning of git.
(b) the dev_get_stats function definitely does not need dev_base_lock protection either. In fact, holding the dev_base_lock is the entire problem here, because we want to make dev_get_stats sleepable, and holding a rwlock gives us atomic context.
So since no protection seems to be necessary, just run unlocked while retrieving the /sys/class/net/eth0/statistics/* values.
---
Changes in v6:
None.
Changes in v5:
None.
Changes in v4:
None.
Changes in v3:
None.
Changes in v2:
None.
net/core/net-sysfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/core/net-sysfs.c +1 -2
@@ -585,14 +585,13 @@ static ssize_t netstat_show(const struct device *d,WARN_ON (offset >sizeof (struct rtnl_link_stats64 ) || offset %sizeof (u64) !=0 ); -read_lock (&dev_base_lock);if (dev_isalive (dev)) {struct rtnl_link_stats64 temp;const struct rtnl_link_stats64 *stats =dev_get_stats (dev, &temp); ret =sprintf (buf, fmt_u64, *(u64 *)(((u8 *)stats) + offset)); } -read_unlock (&dev_base_lock); +return ret; }
Signature · 1 line
2.25.1
PATCH v6 5/15 s390/appldata_net_sum: hold the netdev lists lock when retrieving device statistics
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
In the effort of making .ndo_get_stats64 be able to sleep, we need to ensure the callers of dev_get_stats do not use atomic context.
In the case of the appldata driver, an RCU read-side critical section is used to ensure the integrity of the list of network interfaces, because the driver iterates through all net devices in the netns to aggregate statistics. We still need some protection against an interface registering or deregistering, and the writer-side lock, the netns's mutex, is fine for that, because it offers sleepable context.
The ops->callback function is called from under appldata_ops_mutex protection, so this is proof that the context is sleepable and holding a mutex is therefore fine.
---
Changes in v6:
None.
Changes in v5:
None.
Changes in v4:
None.
Changes in v3:
None.
Changes in v2:
None.
arch/s390/appldata/appldata_net_sum.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
arch/s390/appldata/appldata_net_sum.c +5 -3
@@ -78,8 +78,9 @@ static void appldata_get_net_sum_data(void *data) tx_dropped =0 ; collisions =0 ; -rcu_read_lock (); -for_each_netdev_rcu (&init_net, dev) { +netif_lists_lock (&init_net); + +for_each_netdev (&init_net, dev) {const struct rtnl_link_stats64 *stats;struct rtnl_link_stats64 temp;
@@ -95,7 +96,8 @@ static void appldata_get_net_sum_data(void *data) collisions += stats->collisions; i++; } -rcu_read_unlock (); + +netif_lists_unlock (&init_net); net_data->nr_interfaces = i; net_data->rx_packets = rx_packets;
Signature · 1 line
2.25.1
PATCH v6 6/15 parisc/led: hold the netdev lists lock when retrieving device statistics
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
In the effort of making .ndo_get_stats64 be able to sleep, we need to ensure the callers of dev_get_stats do not use atomic context.
The LED driver for HP-PARISC workstations uses a workqueue to periodically check for updates in network interface statistics, and flicker when those have changed (i.e. there has been activity on the line). Ignoring the fact that this driver is completely duplicating drivers/leds/trigger/ledtrig-netdev.c, there is an even bigger problem. Now, the dev_get_stats call can sleep, and iterating through the list of network interfaces still needs to ensure the integrity of list of network interfaces. So that leaves us only one locking option given the current design of the network stack, and that is the netns mutex.
This patch also reindents the code that gathers device statistics, since the standard in the Linux kernel is to use one tab character per indentation level.
---
Changes in v6:
None.
Changes in v5:
Squashed with the reindenting of the code.
Changes in v4:
None.
Changes in v3:
None.
Changes in v2:
None.
drivers/parisc/led.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)
drivers/parisc/led.c +22 -16
@@ -38,7 +38,6 @@#include <linux/ctype.h> #include <linux/blkdev.h> #include <linux/workqueue.h> -#include <linux/rcupdate.h> #include <asm/io.h> #include <asm/processor.h> #include <asm/hardware.h>
@@ -355,22 +354,29 @@ static __inline__ int led_get_net_activity(void)int retval; rx_total = tx_total =0 ; - -/* we are running as a workqueue task, so we can use an RCU lookup */ -rcu_read_lock (); -for_each_netdev_rcu (&init_net, dev) { -const struct rtnl_link_stats64 *stats; -struct rtnl_link_stats64 temp; -struct in_device *in_dev =__in_dev_get_rcu (dev); -if (!in_dev || !in_dev->ifa_list) -continue ; -if (ipv4_is_loopback (in_dev->ifa_list->ifa_local)) -continue ; - stats =dev_get_stats (dev, &temp); - rx_total += stats->rx_packets; - tx_total += stats->tx_packets; + +/* we are running as a workqueue task, so we can sleep */ +netif_lists_lock (&init_net); + +for_each_netdev (&init_net, dev) { +struct in_device *in_dev =in_dev_get (dev); +const struct rtnl_link_stats64 *stats; +struct rtnl_link_stats64 temp; + +if (!in_dev || !in_dev->ifa_list || +ipv4_is_loopback (in_dev->ifa_list->ifa_local)) { +in_dev_put (in_dev); +continue ; + } + +in_dev_put (in_dev); + + stats =dev_get_stats (dev, &temp); + rx_total += stats->rx_packets; + tx_total += stats->tx_packets; } -rcu_read_unlock (); + +netif_lists_unlock (&init_net); retval =0 ;
Signature · 1 line
2.25.1
PATCH v6 7/15 net: remove return value from dev_get_stats
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
After commit 28172739f0a2 ("net: fix 64 bit counters on 32 bit arches"), dev_get_stats got an additional argument for storage of statistics. At this point, dev_get_stats could return either the passed "storage" argument, or the output of .ndo_get_stats64.
Then commit caf586e5f23c ("net: add a core netdev->rx_dropped counter") came, and the output of .ndo_get_stats64 (still returning a pointer to struct rtnl_link_stats64) started being ignored.
Then came commit bc1f44709cf2 ("net: make ndo_get_stats64 a void function") which made .ndo_get_stats64 stop returning anything.
So now, dev_get_stats always reports the "storage" pointer received as argument. This is useless. Some drivers are dealing with unnecessary complexity due to this, using another pointer to poke around the returned statistics, when they can do that directly through the stack-allocated struct rtnl_link_stats64.
Refactor these callers to ignore the return value completely and just access the values from their struct rtnl_link_stats64 local variable.
---
Changes in v6:
None.
Changes in v5:
- Renamed "stats" to "dev_stats" in fcoe_transport.c.
- Slightly reworded the commit title and message.
Changes in v4:
None.
Changes in v3:
None.
Changes in v2:
Patch is new.
arch/s390/appldata/appldata_net_sum.c | 25 +++++---- drivers/leds/trigger/ledtrig-netdev.c | 9 ++-- drivers/net/bonding/bond_main.c | 7 ++- .../net/ethernet/hisilicon/hns/hns_ethtool.c | 51 +++++++++---------- .../net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 7 ++- drivers/net/ethernet/intel/ixgbevf/ethtool.c | 7 ++- drivers/net/net_failover.c | 13 +++-- drivers/parisc/led.c | 9 ++-- drivers/scsi/fcoe/fcoe_transport.c | 6 +-- drivers/usb/gadget/function/rndis.c | 45 ++++++---------- include/linux/netdevice.h | 3 +- net/8021q/vlanproc.c | 15 +++--- net/core/dev.c | 6 +-- net/core/net-procfs.c | 35 ++++++------- net/core/net-sysfs.c | 7 +-- net/openvswitch/vport.c | 25 +++++---- 16 files changed, 123 insertions(+), 147 deletions(-)
arch/s390/appldata/appldata_net_sum.c +12 -13
@@ -81,19 +81,18 @@ static void appldata_get_net_sum_data(void *data)netif_lists_lock (&init_net);for_each_netdev (&init_net, dev) { -const struct rtnl_link_stats64 *stats; -struct rtnl_link_stats64 temp; - - stats =dev_get_stats (dev, &temp); - rx_packets += stats->rx_packets; - tx_packets += stats->tx_packets; - rx_bytes += stats->rx_bytes; - tx_bytes += stats->tx_bytes; - rx_errors += stats->rx_errors; - tx_errors += stats->tx_errors; - rx_dropped += stats->rx_dropped; - tx_dropped += stats->tx_dropped; - collisions += stats->collisions; +struct rtnl_link_stats64 stats; + +dev_get_stats (dev, &stats); + rx_packets += stats.rx_packets; + tx_packets += stats.tx_packets; + rx_bytes += stats.rx_bytes; + tx_bytes += stats.tx_bytes; + rx_errors += stats.rx_errors; + tx_errors += stats.tx_errors; + rx_dropped += stats.rx_dropped; + tx_dropped += stats.tx_dropped; + collisions += stats.collisions; i++; }
drivers/leds/trigger/ledtrig-netdev.c +4 -5
@@ -347,9 +347,8 @@ static void netdev_trig_work(struct work_struct *work) {struct led_netdev_data *trigger_data = container_of(work, struct led_netdev_data, work.work); -struct rtnl_link_stats64 *dev_stats; +struct rtnl_link_stats64 dev_stats;unsigned int new_activity; -struct rtnl_link_stats64 temp;unsigned long interval;int invert;
@@ -364,12 +363,12 @@ static void netdev_trig_work(struct work_struct *work) !test_bit(NETDEV_LED_RX, &trigger_data->mode)) return; - dev_stats =dev_get_stats (trigger_data->net_dev, &temp); +dev_get_stats (trigger_data->net_dev, &dev_stats); new_activity = (test_bit (NETDEV_LED_TX , &trigger_data->mode) ? - dev_stats->tx_packets :0 ) + + dev_stats.tx_packets :0 ) + (test_bit (NETDEV_LED_RX , &trigger_data->mode) ? - dev_stats->rx_packets :0 ); + dev_stats.rx_packets :0 );if (trigger_data->last_activity != new_activity) {led_stop_software_blink (trigger_data->led_cdev);
drivers/net/bonding/bond_main.c +3 -4
@@ -3753,13 +3753,12 @@ static void bond_get_stats(struct net_device *bond_dev,memcpy (stats, &bond->bond_stats,sizeof (*stats));bond_for_each_slave_rcu (bond, slave, iter) { -const struct rtnl_link_stats64 *new = -dev_get_stats (slave->dev, &temp); +dev_get_stats (slave->dev, &temp); -bond_fold_stats (stats, new, &slave->slave_stats); +bond_fold_stats (stats, &temp, &slave->slave_stats);/* save off the slave stats for the next run */ -memcpy (&slave->slave_stats, new,sizeof (*new)); +memcpy (&slave->slave_stats, &temp,sizeof (temp)); }memcpy (&bond->bond_stats, stats,sizeof (*stats));
drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +25 -26
65 lines not on this page · raw message
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +3 -4
@@ -1295,19 +1295,18 @@ static void ixgbe_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats, u64 *data) { struct ixgbe_adapter *adapter = netdev_priv(netdev); -struct rtnl_link_stats64 temp; -const struct rtnl_link_stats64 *net_stats; +struct rtnl_link_stats64 net_stats;unsigned int start;struct ixgbe_ring *ring;int i, j;char *p =NULL ;ixgbe_update_stats (adapter); - net_stats =dev_get_stats (netdev, &temp); +dev_get_stats (netdev, &net_stats);for (i =0 ; i <IXGBE_GLOBAL_STATS_LEN ; i++) {switch (ixgbe_gstrings_stats[i].type) {case NETDEV_STATS : - p = (char *) net_stats + + p = (char *) &net_stats + ixgbe_gstrings_stats[i].stat_offset;break ;case IXGBE_STATS :
drivers/net/ethernet/intel/ixgbevf/ethtool.c +3 -4
@@ -420,19 +420,18 @@ static void ixgbevf_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats, u64 *data) { struct ixgbevf_adapter *adapter = netdev_priv(netdev); -struct rtnl_link_stats64 temp; -const struct rtnl_link_stats64 *net_stats; +struct rtnl_link_stats64 net_stats;unsigned int start;struct ixgbevf_ring *ring;int i, j;char *p;ixgbevf_update_stats (adapter); - net_stats =dev_get_stats (netdev, &temp); +dev_get_stats (netdev, &net_stats);for (i =0 ; i <IXGBEVF_GLOBAL_STATS_LEN ; i++) {switch (ixgbevf_gstrings_stats[i].type) {case NETDEV_STATS : - p = (char *)net_stats + + p = (char *)&net_stats + ixgbevf_gstrings_stats[i].stat_offset;break ;case IXGBEVF_STATS :
drivers/net/net_failover.c +6 -7
@@ -183,7 +183,6 @@ static void net_failover_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats) {struct net_failover_info *nfo_info =netdev_priv (dev); -const struct rtnl_link_stats64 *new;struct rtnl_link_stats64 temp;struct net_device *slave_dev;
@@ -194,16 +193,16 @@ static void net_failover_get_stats(struct net_device *dev, slave_dev =rcu_dereference (nfo_info->primary_dev);if (slave_dev) { - new =dev_get_stats (slave_dev, &temp); -net_failover_fold_stats (stats, new, &nfo_info->primary_stats); -memcpy (&nfo_info->primary_stats, new,sizeof (*new)); +dev_get_stats (slave_dev, &temp); +net_failover_fold_stats (stats, &temp, &nfo_info->primary_stats); +memcpy (&nfo_info->primary_stats, &temp,sizeof (temp)); } slave_dev =rcu_dereference (nfo_info->standby_dev);if (slave_dev) { - new =dev_get_stats (slave_dev, &temp); -net_failover_fold_stats (stats, new, &nfo_info->standby_stats); -memcpy (&nfo_info->standby_stats, new,sizeof (*new)); +dev_get_stats (slave_dev, &temp); +net_failover_fold_stats (stats, &temp, &nfo_info->standby_stats); +memcpy (&nfo_info->standby_stats, &temp,sizeof (temp)); }rcu_read_unlock ();
drivers/parisc/led.c +4 -5
@@ -360,8 +360,7 @@ static __inline__ int led_get_net_activity(void)for_each_netdev (&init_net, dev) {struct in_device *in_dev =in_dev_get (dev); -const struct rtnl_link_stats64 *stats; -struct rtnl_link_stats64 temp; +struct rtnl_link_stats64 stats;if (!in_dev || !in_dev->ifa_list ||ipv4_is_loopback (in_dev->ifa_list->ifa_local)) {
@@ -371,9 +370,9 @@ static __inline__ int led_get_net_activity(void)in_dev_put (in_dev); - stats =dev_get_stats (dev, &temp); - rx_total += stats->rx_packets; - tx_total += stats->tx_packets; +dev_get_stats (dev, &stats); + rx_total += stats.rx_packets; + tx_total += stats.tx_packets; }netif_lists_unlock (&init_net);
drivers/scsi/fcoe/fcoe_transport.c +3 -3
@@ -170,11 +170,11 @@ void __fcoe_get_lesb(struct fc_lport *lport,struct fc_els_lesb *fc_lesb, struct net_device *netdev) { + struct rtnl_link_stats64 dev_stats;unsigned int cpu;u32 lfc, vlfc, mdac;struct fc_stats *stats;struct fcoe_fc_els_lesb *lesb; -struct rtnl_link_stats64 temp; lfc =0 ; vlfc =0 ;
@@ -190,8 +190,8 @@ void __fcoe_get_lesb(struct fc_lport *lport, lesb->lesb_link_fail =htonl (lfc); lesb->lesb_vlink_fail =htonl (vlfc); lesb->lesb_miss_fka =htonl (mdac); - lesb->lesb_fcs_error = -htonl (dev_get_stats (netdev, &temp)->rx_crc_errors); +dev_get_stats (netdev, &dev_stats); + lesb->lesb_fcs_error =htonl (dev_stats.rx_crc_errors); }EXPORT_SYMBOL_GPL (__fcoe_get_lesb);
drivers/usb/gadget/function/rndis.c +16 -29
98 lines not on this page · raw message
include/linux/netdevice.h +1 -2
@@ -4545,8 +4545,7 @@ void netdev_notify_peers(struct net_device *dev);void netdev_features_change (struct net_device *dev);/* Load a device via the kmod */ void dev_load (struct net *net,const char *name); -struct rtnl_link_stats64 *dev_get_stats (struct net_device *dev, -struct rtnl_link_stats64 *storage); +void dev_get_stats (struct net_device *dev,struct rtnl_link_stats64 *storage);void netdev_stats_to_stats64 (struct rtnl_link_stats64 *stats64,const struct net_device_stats *netdev_stats); void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s,
net/8021q/vlanproc.c +7 -8
@@ -242,26 +242,25 @@ static int vlandev_seq_show(struct seq_file *seq, void *offset) {struct net_device *vlandev = (struct net_device *) seq->private;const struct vlan_dev_priv *vlan =vlan_dev_priv (vlandev); -struct rtnl_link_stats64 temp; -const struct rtnl_link_stats64 *stats;static const char fmt64[] ="%30s %12llu\n" ; +struct rtnl_link_stats64 stats;int i;if (!is_vlan_dev (vlandev))return 0 ; - stats =dev_get_stats (vlandev, &temp); +dev_get_stats (vlandev, &stats);seq_printf (seq,"%s VID: %d REORDER_HDR: %i dev->priv_flags: %hx\n" , vlandev->name, vlan->vlan_id, (int )(vlan->flags &1 ), vlandev->priv_flags); -seq_printf (seq, fmt64,"total frames received" , stats->rx_packets); -seq_printf (seq, fmt64,"total bytes received" , stats->rx_bytes); -seq_printf (seq, fmt64,"Broadcast/Multicast Rcvd" , stats->multicast); +seq_printf (seq, fmt64,"total frames received" , stats.rx_packets); +seq_printf (seq, fmt64,"total bytes received" , stats.rx_bytes); +seq_printf (seq, fmt64,"Broadcast/Multicast Rcvd" , stats.multicast);seq_puts (seq,"\n" ); -seq_printf (seq, fmt64,"total frames transmitted" , stats->tx_packets); -seq_printf (seq, fmt64,"total bytes transmitted" , stats->tx_bytes); +seq_printf (seq, fmt64,"total frames transmitted" , stats.tx_packets); +seq_printf (seq, fmt64,"total bytes transmitted" , stats.tx_bytes);seq_printf (seq,"Device: %s" , vlan->real_dev->name);/* now show all PRIORITY mappings relating to this VLAN */ seq_printf(seq, "\nINGRESS priority mappings: "
net/core/dev.c +2 -4
@@ -10398,13 +10398,12 @@ EXPORT_SYMBOL(netdev_stats_to_stats64);* @dev: device to get statistics from * @storage: place to store stats * -* Get network statistics from device. Return @storage. +* Get network statistics from device. * The device driver may provide its own method by setting * dev->netdev_ops->get_stats64 or dev->netdev_ops->get_stats; * otherwise the internal statistics structure is used. */ -struct rtnl_link_stats64 *dev_get_stats (struct net_device *dev, -struct rtnl_link_stats64 *storage) +void dev_get_stats (struct net_device *dev,struct rtnl_link_stats64 *storage) {const struct net_device_ops *ops = dev->netdev_ops;
@@ -10419,7 +10418,6 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev, storage->rx_dropped += (unsigned long )atomic_long_read (&dev->rx_dropped); storage->tx_dropped += (unsigned long )atomic_long_read (&dev->tx_dropped); storage->rx_nohandler += (unsigned long )atomic_long_read (&dev->rx_nohandler); -return storage; }EXPORT_SYMBOL (dev_get_stats);
net/core/net-procfs.c +18 -17
@@ -80,26 +80,27 @@ static void dev_seq_stop(struct seq_file *seq, void *v)static void dev_seq_printf_stats (struct seq_file *seq,struct net_device *dev) { -struct rtnl_link_stats64 temp; -const struct rtnl_link_stats64 *stats =dev_get_stats (dev, &temp); +struct rtnl_link_stats64 stats; + +dev_get_stats (dev, &stats);seq_printf (seq,"%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu " "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n" , - dev->name, stats->rx_bytes, stats->rx_packets, - stats->rx_errors, - stats->rx_dropped + stats->rx_missed_errors, - stats->rx_fifo_errors, - stats->rx_length_errors + stats->rx_over_errors + - stats->rx_crc_errors + stats->rx_frame_errors, - stats->rx_compressed, stats->multicast, - stats->tx_bytes, stats->tx_packets, - stats->tx_errors, stats->tx_dropped, - stats->tx_fifo_errors, stats->collisions, - stats->tx_carrier_errors + - stats->tx_aborted_errors + - stats->tx_window_errors + - stats->tx_heartbeat_errors, - stats->tx_compressed); + dev->name, stats.rx_bytes, stats.rx_packets, + stats.rx_errors, + stats.rx_dropped + stats.rx_missed_errors, + stats.rx_fifo_errors, + stats.rx_length_errors + stats.rx_over_errors + + stats.rx_crc_errors + stats.rx_frame_errors, + stats.rx_compressed, stats.multicast, + stats.tx_bytes, stats.tx_packets, + stats.tx_errors, stats.tx_dropped, + stats.tx_fifo_errors, stats.collisions, + stats.tx_carrier_errors + + stats.tx_aborted_errors + + stats.tx_window_errors + + stats.tx_heartbeat_errors, + stats.tx_compressed); }/*
net/core/net-sysfs.c +4 -3
@@ -586,10 +586,11 @@ static ssize_t netstat_show(const struct device *d, offset % sizeof(u64) != 0);if (dev_isalive (dev)) { -struct rtnl_link_stats64 temp; -const struct rtnl_link_stats64 *stats =dev_get_stats (dev, &temp); +struct rtnl_link_stats64 stats; - ret =sprintf (buf, fmt_u64, *(u64 *)(((u8 *)stats) + offset)); +dev_get_stats (dev, &stats); + + ret =sprintf (buf, fmt_u64, *(u64 *)(((u8 *)&stats) + offset)); }return ret;
net/openvswitch/vport.c +12 -13
@@ -269,19 +269,18 @@ void ovs_vport_del(struct vport *vport)*/ void ovs_vport_get_stats (struct vport *vport,struct ovs_vport_stats *stats) { -const struct rtnl_link_stats64 *dev_stats; -struct rtnl_link_stats64 temp; - - dev_stats =dev_get_stats (vport->dev, &temp); - 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; - - stats->rx_bytes = dev_stats->rx_bytes; - stats->rx_packets = dev_stats->rx_packets; - stats->tx_bytes = dev_stats->tx_bytes; - stats->tx_packets = dev_stats->tx_packets; +struct rtnl_link_stats64 dev_stats; + +dev_get_stats (vport->dev, &dev_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; + + stats->rx_bytes = dev_stats.rx_bytes; + stats->rx_packets = dev_stats.rx_packets; + stats->tx_bytes = dev_stats.tx_bytes; + stats->tx_packets = dev_stats.tx_packets; }/**
Signature · 1 line
2.25.1
Re: [PATCH v6 net-next 07/15] net: remove return value from dev_get_stats
Quoted 25 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
After commit
28172739f0a2("net: fix 64 bit counters on 32 bit arches"),dev_get_statsgot an additional argument for storage of statistics. At
this point,dev_get_statscould return either the passed "storage" argument, or the output of .ndo_get_stats64.Then commit
caf586e5f23c("net: add a corenetdev->rx_droppedcounter")
came, and the output of .ndo_get_stats64 (still returning a pointer to
structrtnl_link_stats64) started being ignored.Then came commit
bc1f44709cf2("net: makendo_get_stats64a void function") which made .ndo_get_stats64 stop returning anything.So now,
dev_get_statsalways reports the "storage" pointer received as
argument. This is useless. Some drivers are dealing with unnecessary complexity due to this, using another pointer to poke around the returned statistics, when they can do that directly through the stack-allocated structrtnl_link_stats64.
Quoted 5 lines
Refactor these callers to ignore the return value completely and just access the values from their struct
rtnl_link_stats64local variable.Signed-off-by Vladimir Oltean <[email protected]>
PATCH v6 8/15 net: allow ndo_get_stats64 to return an int error code
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Some drivers need to do special tricks to comply with the new policy of ndo_get_stats64 being sleepable. For example, the bonding driver, which derives its stats from its lower interfaces, must recurse with dev_get_stats into its lowers with no locks held. But for that to work, it needs to dynamically allocate some memory for a refcounted copy of its array of slave interfaces (because recursing unlocked means that the original one is subject to disappearing). And since memory allocation can fail under pressure, we should not let it go unnoticed, but instead propagate the error code.
This patch converts all implementations of .ndo_get_stats64 to return int, and propagates that to the dev_get_stats calling site. Error checking will be done in further patches.
---
Changes in v6:
Remove the unused "int err" from __bond_release_one and add it in the patch it belongs to.
Changes in v5:
None.
Changes in v4:
Patch is new (Eric's suggestion).
drivers/infiniband/hw/hfi1/vnic_main.c | 6 ++++-- drivers/infiniband/ulp/ipoib/ipoib_main.c | 9 ++++++--- drivers/infiniband/ulp/opa_vnic/opa_vnic_netdev.c | 9 ++++++--- drivers/net/bonding/bond_main.c | 10 ++++++---- drivers/net/dummy.c | 6 ++++-- drivers/net/ethernet/alacritech/slicoss.c | 6 ++++-- drivers/net/ethernet/amazon/ena/ena_netdev.c | 8 +++++--- drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 6 ++++-- drivers/net/ethernet/apm/xgene-v2/main.c | 6 ++++-- drivers/net/ethernet/apm/xgene/xgene_enet_main.c | 7 ++++--- drivers/net/ethernet/atheros/alx/main.c | 6 ++++-- drivers/net/ethernet/broadcom/b44.c | 6 ++++-- drivers/net/ethernet/broadcom/bcmsysport.c | 6 ++++-- drivers/net/ethernet/broadcom/bnx2.c | 5 +++-- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 6 ++++-- drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c | 4 +++- drivers/net/ethernet/broadcom/tg3.c | 8 +++++--- drivers/net/ethernet/brocade/bna/bnad.c | 4 +++- drivers/net/ethernet/calxeda/xgmac.c | 4 +++- drivers/net/ethernet/cavium/liquidio/lio_main.c | 6 ++++-- drivers/net/ethernet/cavium/liquidio/lio_vf_main.c | 6 ++++-- drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c | 8 +++++--- drivers/net/ethernet/cavium/thunder/nicvf_main.c | 5 +++-- drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 8 +++++--- drivers/net/ethernet/cisco/enic/enic_main.c | 8 +++++--- drivers/net/ethernet/cortina/gemini.c | 6 ++++-- drivers/net/ethernet/ec_bhf.c | 4 +++- drivers/net/ethernet/emulex/benet/be_main.c | 6 ++++-- drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 6 ++++-- drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 6 ++++-- drivers/net/ethernet/google/gve/gve_main.c | 4 +++- drivers/net/ethernet/hisilicon/hns/hns_enet.c | 6 ++++-- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 8 +++++--- drivers/net/ethernet/huawei/hinic/hinic_main.c | 6 ++++-- drivers/net/ethernet/ibm/ehea/ehea_main.c | 6 ++++-- drivers/net/ethernet/intel/e1000e/e1000.h | 4 ++-- drivers/net/ethernet/intel/e1000e/netdev.c | 6 ++++-- drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 6 ++++-- drivers/net/ethernet/intel/i40e/i40e_main.c | 10 ++++++---- drivers/net/ethernet/intel/ice/ice_main.c | 6 ++++-- drivers/net/ethernet/intel/igb/igb_main.c | 10 ++++++---- drivers/net/ethernet/intel/igc/igc_main.c | 6 ++++-- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 6 ++++-- drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 6 ++++-- drivers/net/ethernet/marvell/mvneta.c | 4 +++- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 4 +++- .../net/ethernet/marvell/octeontx2/nic/otx2_common.c | 6 ++++-- .../net/ethernet/marvell/octeontx2/nic/otx2_common.h | 4 ++-- .../net/ethernet/marvell/prestera/prestera_main.c | 6 ++++-- drivers/net/ethernet/marvell/sky2.c | 6 ++++-- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 6 ++++-- drivers/net/ethernet/mediatek/mtk_star_emac.c | 6 ++++-- drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 4 +++- drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 4 +++- drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 4 +++- .../net/ethernet/mellanox/mlx5/core/ipoib/ipoib.c | 4 +++- .../net/ethernet/mellanox/mlx5/core/ipoib/ipoib.h | 2 +- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 4 +++- drivers/net/ethernet/mellanox/mlxsw/switchx2.c | 4 +++- drivers/net/ethernet/microchip/lan743x_main.c | 6 ++++-- drivers/net/ethernet/mscc/ocelot_net.c | 6 ++++-- drivers/net/ethernet/myricom/myri10ge/myri10ge.c | 12 +++++++----- drivers/net/ethernet/neterion/vxge/vxge-main.c | 4 +++- drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 6 ++++-- drivers/net/ethernet/netronome/nfp/nfp_net_repr.c | 6 ++++-- drivers/net/ethernet/nvidia/forcedeth.c | 4 +++- drivers/net/ethernet/pensando/ionic/ionic_lif.c | 6 ++++-- drivers/net/ethernet/pensando/ionic/ionic_lif.h | 4 ++-- drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c | 10 ++++++---- drivers/net/ethernet/qlogic/qede/qede_main.c | 6 ++++-- drivers/net/ethernet/qualcomm/emac/emac.c | 6 ++++-- drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c | 8 +++++--- drivers/net/ethernet/realtek/8139too.c | 8 +++++--- drivers/net/ethernet/realtek/r8169_main.c | 4 +++- drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 6 ++++-- drivers/net/ethernet/sfc/efx_common.c | 4 +++- drivers/net/ethernet/sfc/efx_common.h | 2 +- drivers/net/ethernet/sfc/falcon/efx.c | 6 ++++-- drivers/net/ethernet/socionext/sni_ave.c | 6 ++++-- drivers/net/ethernet/sun/niu.c | 6 ++++-- drivers/net/ethernet/synopsys/dwc-xlgmac-net.c | 6 ++++-- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 6 ++++-- drivers/net/ethernet/ti/netcp_core.c | 4 +++- drivers/net/ethernet/via/via-rhine.c | 8 +++++--- drivers/net/fjes/fjes_main.c | 6 ++++-- drivers/net/hyperv/netvsc_drv.c | 6 ++++-- drivers/net/ifb.c | 5 +++-- drivers/net/ipvlan/ipvlan_main.c | 6 ++++-- drivers/net/loopback.c | 6 ++++-- drivers/net/macsec.c | 8 +++++--- drivers/net/macvlan.c | 6 ++++-- drivers/net/mhi_net.c | 6 ++++-- drivers/net/net_failover.c | 6 ++++-- drivers/net/netdevsim/netdev.c | 4 +++- drivers/net/nlmon.c | 4 +++- drivers/net/ppp/ppp_generic.c | 4 +++- drivers/net/slip/slip.c | 4 +++- drivers/net/team/team.c | 4 +++- drivers/net/thunderbolt.c | 6 ++++-- drivers/net/tun.c | 4 +++- drivers/net/veth.c | 6 ++++-- drivers/net/virtio_net.c | 6 ++++-- drivers/net/vmxnet3/vmxnet3_ethtool.c | 4 +++- drivers/net/vmxnet3/vmxnet3_int.h | 4 ++-- drivers/net/vrf.c | 6 ++++-- drivers/net/vsockmon.c | 4 +++- drivers/net/xen-netfront.c | 6 ++++-- drivers/s390/net/qeth_core.h | 2 +- drivers/s390/net/qeth_core_main.c | 4 +++- drivers/staging/fsl-dpaa2/ethsw/ethsw.c | 8 +++----- drivers/staging/netlogic/xlr_net.c | 4 +++- include/linux/netdevice.h | 10 +++++----- net/8021q/vlan_dev.c | 6 ++++-- net/core/dev.c | 11 ++++++++--- net/l2tp/l2tp_eth.c | 6 ++++-- net/mac80211/iface.c | 4 +++- net/sched/sch_teql.c | 6 ++++-- 118 files changed, 449 insertions(+), 234 deletions(-)
drivers/infiniband/hw/hfi1/vnic_main.c +4 -2
@@ -220,13 +220,15 @@ static void hfi1_vnic_update_rx_counters(struct hfi1_vnic_vport_info *vinfo, }/* This function is overloaded for opa_vnic specific implementation */ -static void hfi1_vnic_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int hfi1_vnic_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct opa_vnic_stats *vstats = (struct opa_vnic_stats *)stats;struct hfi1_vnic_vport_info *vinfo =opa_vnic_dev_priv (netdev);hfi1_vnic_update_stats (vinfo, vstats); + +return 0 ; }static u64 create_bypass_pbc (u32 vl,u32 dw_len)
drivers/infiniband/ulp/ipoib/ipoib_main.c +6 -3
@@ -268,15 +268,18 @@ static int ipoib_change_mtu(struct net_device *dev, int new_mtu)return ret; } -static void ipoib_get_stats (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int ipoib_get_stats (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct ipoib_dev_priv *priv =ipoib_priv (dev); +int err =0 ;if (priv->rn_ops->ndo_get_stats64) - priv->rn_ops->ndo_get_stats64 (dev, stats); + err = priv->rn_ops->ndo_get_stats64 (dev, stats);else netdev_stats_to_stats64 (stats, &dev->stats); + +return err; }/* Called with an RCU read lock taken */
drivers/infiniband/ulp/opa_vnic/opa_vnic_netdev.c +6 -3
@@ -62,17 +62,20 @@ALIGN ((OPA_VNIC_HDR_LEN +OPA_VNIC_SKB_MDATA_LEN ),8 ) /* This function is overloaded for opa_vnic specific implementation */ -static void opa_vnic_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int opa_vnic_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct opa_vnic_adapter *adapter =opa_vnic_priv (netdev);struct opa_vnic_stats vstats; +int err;memset (&vstats,0 ,sizeof (vstats));spin_lock (&adapter->stats_lock); - adapter->rn_ops->ndo_get_stats64 (netdev, &vstats.netstats); + err = adapter->rn_ops->ndo_get_stats64 (netdev, &vstats.netstats);spin_unlock (&adapter->stats_lock);memcpy (stats, &vstats.netstats,sizeof (*stats)); + +return err; }/* opa_netdev_start_xmit - transmit function */
drivers/net/bonding/bond_main.c +6 -4
@@ -252,8 +252,8 @@ static struct flow_dissector flow_keys_bonding __read_mostly;static int bond_init (struct net_device *bond_dev);static void bond_uninit (struct net_device *bond_dev); -static void bond_get_stats (struct net_device *bond_dev, -struct rtnl_link_stats64 *stats); +static int bond_get_stats (struct net_device *bond_dev, +struct rtnl_link_stats64 *stats);static void bond_slave_arr_handler (struct work_struct *work);static bool bond_time_in_interval (struct bonding *bond,unsigned long last_act,int mod);
@@ -3734,8 +3734,8 @@ static int bond_get_lowest_level_rcu(struct net_device *dev) }#endif -static void bond_get_stats (struct net_device *bond_dev, -struct rtnl_link_stats64 *stats) +static int bond_get_stats (struct net_device *bond_dev, +struct rtnl_link_stats64 *stats) {struct bonding *bond =netdev_priv (bond_dev);struct rtnl_link_stats64 temp;
@@ -3764,6 +3764,8 @@ static void bond_get_stats(struct net_device *bond_dev,memcpy (&bond->bond_stats, stats,sizeof (*stats));spin_unlock (&bond->stats_lock);rcu_read_unlock (); + +return 0 ; }static int bond_do_ioctl (struct net_device *bond_dev,struct ifreq *ifr,int cmd)
drivers/net/dummy.c +4 -2
@@ -50,10 +50,12 @@ static void set_multicast_list(struct net_device *dev) { } -static void dummy_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int dummy_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {dev_lstats_read (dev, &stats->tx_packets, &stats->tx_bytes); + +return 0 ; }static netdev_tx_t dummy_xmit (struct sk_buff *skb,struct net_device *dev)
drivers/net/ethernet/alacritech/slicoss.c +4 -2
@@ -1457,8 +1457,8 @@ static netdev_tx_t slic_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } -static void slic_get_stats (struct net_device *dev, -struct rtnl_link_stats64 *lst) +static int slic_get_stats (struct net_device *dev, +struct rtnl_link_stats64 *lst) {struct slic_device *sdev =netdev_priv (dev);struct slic_stats *stats = &sdev->stats;
@@ -1475,6 +1475,8 @@ static void slic_get_stats(struct net_device *dev,SLIC_GET_STATS_COUNTER (lst->rx_crc_errors, stats, rx_crc);SLIC_GET_STATS_COUNTER (lst->rx_fifo_errors, stats, rx_oflow802);SLIC_GET_STATS_COUNTER (lst->tx_carrier_errors, stats, tx_carrier); + +return 0 ; }static int slic_get_sset_count (struct net_device *dev,int sset)
drivers/net/ethernet/amazon/ena/ena_netdev.c +5 -3
@@ -3229,8 +3229,8 @@ int ena_update_hw_stats(struct ena_adapter *adapter)return 0 ; } -static void ena_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int ena_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct ena_adapter *adapter =netdev_priv (netdev);struct ena_ring *rx_ring, *tx_ring;
@@ -3240,7 +3240,7 @@ static void ena_get_stats64(struct net_device *netdev,int i;if (!test_bit (ENA_FLAG_DEV_UP , &adapter->flags)) -return ; +return 0 ;for (i =0 ; i < adapter->num_io_queues; i++) {u64 bytes, packets;
@@ -3289,6 +3289,8 @@ static void ena_get_stats64(struct net_device *netdev, stats->rx_errors =0 ; stats->tx_errors =0 ; + +return 0 ; }static const struct net_device_ops ena_netdev_ops = {
drivers/net/ethernet/amd/xgbe/xgbe-drv.c +4 -2
@@ -2074,8 +2074,8 @@ static void xgbe_tx_timeout(struct net_device *netdev, unsigned int txqueue)schedule_work (&pdata->restart_work); } -static void xgbe_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *s) +static int xgbe_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *s) {struct xgbe_prv_data *pdata =netdev_priv (netdev);struct xgbe_mmc_stats *pstats = &pdata->mmc_stats;
@@ -2101,6 +2101,8 @@ static void xgbe_get_stats64(struct net_device *netdev, s->tx_dropped = netdev->stats.tx_dropped;DBGPR ("<--%s\n" , __func__); + +return 0 ; } static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
drivers/net/ethernet/apm/xgene-v2/main.c +4 -2
@@ -606,8 +606,8 @@ static void xge_timeout(struct net_device *ndev, unsigned int txqueue)rtnl_unlock (); } -static void xge_get_stats64 (struct net_device *ndev, -struct rtnl_link_stats64 *storage) +static int xge_get_stats64 (struct net_device *ndev, +struct rtnl_link_stats64 *storage) {struct xge_pdata *pdata =netdev_priv (ndev);struct xge_stats *stats = &pdata->stats;
@@ -618,6 +618,8 @@ static void xge_get_stats64(struct net_device *ndev, storage->rx_packets += stats->rx_packets; storage->rx_bytes += stats->rx_bytes; storage->rx_errors += stats->rx_errors; + +return 0 ; }static const struct net_device_ops xgene_ndev_ops = {
drivers/net/ethernet/apm/xgene/xgene_enet_main.c +4 -3
@@ -1465,9 +1465,8 @@ static int xgene_enet_create_desc_rings(struct net_device *ndev)return ret; } -static void xgene_enet_get_stats64 ( -struct net_device *ndev, -struct rtnl_link_stats64 *stats) +static int xgene_enet_get_stats64 (struct net_device *ndev, +struct rtnl_link_stats64 *stats) {struct xgene_enet_pdata *pdata =netdev_priv (ndev);struct xgene_enet_desc_ring *ring;
@@ -1500,6 +1499,8 @@ static void xgene_enet_get_stats64( stats->rx_fifo_errors += ring->rx_fifo_errors; } } + +return 0 ; }static int xgene_enet_set_mac_address (struct net_device *ndev,void *addr)
drivers/net/ethernet/atheros/alx/main.c +4 -2
@@ -1624,8 +1624,8 @@ static void alx_poll_controller(struct net_device *netdev) }#endif -static void alx_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *net_stats) +static int alx_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *net_stats) {struct alx_priv *alx =netdev_priv (dev);struct alx_hw_stats *hw_stats = &alx->hw.stats;
@@ -1669,6 +1669,8 @@ static void alx_get_stats64(struct net_device *dev, net_stats->rx_packets = hw_stats->rx_ok + net_stats->rx_errors;spin_unlock (&alx->stats_lock); + +return 0 ; }static const struct net_device_ops alx_netdev_ops = {
drivers/net/ethernet/broadcom/b44.c +4 -2
@@ -1670,8 +1670,8 @@ static int b44_close(struct net_device *dev)return 0 ; } -static void b44_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *nstat) +static int b44_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *nstat) {struct b44 *bp =netdev_priv (dev);struct b44_hw_stats *hwstat = &bp->hw_stats;
@@ -1714,6 +1714,8 @@ static void b44_get_stats64(struct net_device *dev,#endif }while (u64_stats_fetch_retry_irq (&hwstat->syncp, start)); +return 0 ; + }static int __b44_load_mcast (struct b44 *bp,struct net_device *dev)
drivers/net/ethernet/broadcom/bcmsysport.c +4 -2
@@ -1859,8 +1859,8 @@ static int bcm_sysport_change_mac(struct net_device *dev, void *p)return 0 ; } -static void bcm_sysport_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int bcm_sysport_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct bcm_sysport_priv *priv =netdev_priv (dev);struct bcm_sysport_stats64 *stats64 = &priv->stats64;
@@ -1876,6 +1876,8 @@ static void bcm_sysport_get_stats64(struct net_device *dev, stats->rx_packets = stats64->rx_packets; stats->rx_bytes = stats64->rx_bytes; }while (u64_stats_fetch_retry_irq (&priv->syncp, start)); + +return 0 ; }static void bcm_sysport_netif_start (struct net_device *dev)
drivers/net/ethernet/broadcom/bnx2.c +3 -2
@@ -6812,13 +6812,13 @@ bnx2_save_stats(struct bnx2 *bp) (unsigned long ) (bp->stats_blk->ctr + \ bp->temp_stats_blk->ctr) -static void +static int bnx2_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *net_stats) {struct bnx2 *bp =netdev_priv (dev);if (!bp->stats_blk) -return ; +return 0 ; net_stats->rx_packets = GET_64BIT_NET_STATS(stat_IfHCInUcastPkts) +
@@ -6882,6 +6882,7 @@ bnx2_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)GET_32BIT_NET_STATS (stat_IfInMBUFDiscards) +GET_32BIT_NET_STATS (stat_FwRxDrop); +return 0 ; }/* All ethtool functions called with rtnl_lock */
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4 -2
@@ -10096,7 +10096,7 @@ static void bnxt_add_prev_stats(struct bnxt *bp, stats->tx_dropped += prev_stats->tx_dropped; } -static void +static int bnxt_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct bnxt *bp =netdev_priv (dev);
@@ -10109,7 +10109,7 @@ bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)if (!test_bit (BNXT_STATE_OPEN , &bp->state)) {clear_bit (BNXT_STATE_READ_STATS , &bp->state); *stats = bp->net_stats_prev; -return ; +return 0 ; }bnxt_get_ring_stats (bp, stats);
@@ -10138,6 +10138,8 @@ bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) stats->tx_errors =BNXT_GET_TX_PORT_STATS64 (tx, tx_err); }clear_bit (BNXT_STATE_READ_STATS , &bp->state); + +return 0 ; }static bool bnxt_mc_list_updated (struct bnxt *bp,u32 *rx_mask)
drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c +3 -1
@@ -129,7 +129,7 @@ static netdev_tx_t bnxt_vf_rep_xmit(struct sk_buff *skb,return rc; } -static void +static int bnxt_vf_rep_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {
@@ -139,6 +139,8 @@ bnxt_vf_rep_get_stats64(struct net_device *dev, stats->rx_bytes = vf_rep->rx_stats.bytes; stats->tx_packets = vf_rep->tx_stats.packets; stats->tx_bytes = vf_rep->tx_stats.bytes; + +return 0 ; } static int bnxt_vf_rep_setup_tc_block_cb(enum tc_setup_type type,
drivers/net/ethernet/broadcom/tg3.c +5 -3
@@ -14201,8 +14201,8 @@ static const struct ethtool_ops tg3_ethtool_ops = { .set_link_ksettings = tg3_set_link_ksettings, }; -static void tg3_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int tg3_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct tg3 *tp =netdev_priv (dev);
@@ -14210,11 +14210,13 @@ static void tg3_get_stats64(struct net_device *dev,if (!tp->hw_stats || !tg3_flag (tp,INIT_COMPLETE )) { *stats = tp->net_stats_prev;spin_unlock_bh (&tp->lock); -return ; +return 0 ; }tg3_get_nstats (tp, stats);spin_unlock_bh (&tp->lock); + +return 0 ; }static void tg3_set_rx_mode (struct net_device *dev)
drivers/net/ethernet/brocade/bna/bnad.c +3 -1
@@ -3096,7 +3096,7 @@ bnad_start_xmit(struct sk_buff *skb, struct net_device *netdev)* Used spin_lock to synchronize reading of stats structures, which * is written by BNA under the same lock. */ -static void +static int bnad_get_stats64 (struct net_device *netdev,struct rtnl_link_stats64 *stats) {struct bnad *bnad =netdev_priv (netdev);
@@ -3108,6 +3108,8 @@ bnad_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)bnad_netdev_hwstats_fill (bnad, stats);spin_unlock_irqrestore (&bnad->bna_lock, flags); + +return 0 ; } static void
drivers/net/ethernet/calxeda/xgmac.c +3 -1
@@ -1438,7 +1438,7 @@ static void xgmac_poll_controller(struct net_device *dev) }#endif -static void +static int xgmac_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *storage) {
@@ -1468,6 +1468,8 @@ xgmac_get_stats64(struct net_device *dev,writel (0 , base +XGMAC_MMC_CTRL );spin_unlock_bh (&priv->stats_lock); + +return 0 ; }static int xgmac_set_mac_address (struct net_device *dev,void *p)
drivers/net/ethernet/cavium/liquidio/lio_main.c +4 -2
@@ -2021,7 +2021,7 @@ static int liquidio_set_mac(struct net_device *netdev, void *p)return 0 ; } -static void +static int liquidio_get_stats64 (struct net_device *netdev,struct rtnl_link_stats64 *lstats) {
@@ -2035,7 +2035,7 @@ liquidio_get_stats64(struct net_device *netdev, oct = lio->oct_dev;if (ifstate_check (lio,LIO_IFSTATE_RESETTING )) -return ; +return 0 ;for (i =0 ; i < oct->num_iqs; i++) { iq_no = lio->linfo.txpciq[i].s.q_no;
@@ -2091,6 +2091,8 @@ liquidio_get_stats64(struct net_device *netdev, lstats->tx_errors = lstats->tx_aborted_errors + lstats->tx_carrier_errors + lstats->tx_fifo_errors; + +return 0 ; }/**
drivers/net/ethernet/cavium/liquidio/lio_vf_main.c +4 -2
@@ -1161,7 +1161,7 @@ static int liquidio_set_mac(struct net_device *netdev, void *p)return 0 ; } -static void +static int liquidio_get_stats64 (struct net_device *netdev,struct rtnl_link_stats64 *lstats) {
@@ -1175,7 +1175,7 @@ liquidio_get_stats64(struct net_device *netdev, oct = lio->oct_dev;if (ifstate_check (lio,LIO_IFSTATE_RESETTING )) -return ; +return 0 ;for (i =0 ; i < oct->num_iqs; i++) { iq_no = lio->linfo.txpciq[i].s.q_no;
@@ -1226,6 +1226,8 @@ liquidio_get_stats64(struct net_device *netdev, lstats->tx_errors = lstats->tx_aborted_errors + lstats->tx_carrier_errors; + +return 0 ; }/**
drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c +5 -3
@@ -34,8 +34,8 @@ static netdev_tx_t lio_vf_rep_pkt_xmit(struct sk_buff *skb,static void lio_vf_rep_tx_timeout (struct net_device *netdev,unsigned int txqueue);static int lio_vf_rep_phys_port_name (struct net_device *dev,char *buf,size_t len); -static void lio_vf_rep_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats64); +static int lio_vf_rep_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats64);static int lio_vf_rep_change_mtu (struct net_device *ndev,int new_mtu);static int lio_vf_get_port_parent_id (struct net_device *dev,struct netdev_phys_item_id *ppid);
@@ -179,7 +179,7 @@ lio_vf_rep_tx_timeout(struct net_device *ndev, unsigned int txqueue)netif_wake_queue (ndev); } -static void +static int lio_vf_rep_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats64) {
@@ -193,6 +193,8 @@ lio_vf_rep_get_stats64(struct net_device *dev, stats64->rx_packets = vf_rep->stats.tx_packets; stats64->rx_bytes = vf_rep->stats.tx_bytes; stats64->rx_dropped = vf_rep->stats.tx_dropped; + +return 0 ; } static int
drivers/net/ethernet/cavium/thunder/nicvf_main.c +3 -2
@@ -1720,8 +1720,8 @@ void nicvf_update_stats(struct nicvf *nic)nicvf_update_sq_stats (nic, qidx); } -static void nicvf_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int nicvf_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct nicvf *nic =netdev_priv (netdev);struct nicvf_hw_stats *hw_stats = &nic->hw_stats;
@@ -1737,6 +1737,7 @@ static void nicvf_get_stats64(struct net_device *netdev, stats->tx_packets = hw_stats->tx_frames; stats->tx_dropped = hw_stats->tx_drops; +return 0 ; }static void nicvf_tx_timeout (struct net_device *dev,unsigned int txqueue)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +5 -3
@@ -2999,8 +2999,8 @@ int cxgb4_remove_server_filter(const struct net_device *dev, unsigned int stid, }EXPORT_SYMBOL (cxgb4_remove_server_filter); -static void cxgb_get_stats (struct net_device *dev, -struct rtnl_link_stats64 *ns) +static int cxgb_get_stats (struct net_device *dev, +struct rtnl_link_stats64 *ns) {struct port_stats stats;struct port_info *p =netdev_priv (dev);
@@ -3013,7 +3013,7 @@ static void cxgb_get_stats(struct net_device *dev,spin_lock (&adapter->stats_lock);if (!netif_device_present (dev)) {spin_unlock (&adapter->stats_lock); -return ; +return 0 ; }t4_get_port_stats_offset (adapter, p->tx_chan, &stats, &p->stats_base);
@@ -3047,6 +3047,8 @@ static void cxgb_get_stats(struct net_device *dev, ns->tx_errors = stats.tx_error_frames; ns->rx_errors = stats.rx_symbol_err + stats.rx_fcs_err + ns->rx_length_errors + stats.rx_len_err + ns->rx_fifo_errors; + +return 0 ; }static int cxgb_ioctl (struct net_device *dev,struct ifreq *req,int cmd)
drivers/net/ethernet/cisco/enic/enic_main.c +5 -3
@@ -871,8 +871,8 @@ static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb, }/* dev_base_lock rwlock held, nominally process context */ -static void enic_get_stats (struct net_device *netdev, -struct rtnl_link_stats64 *net_stats) +static int enic_get_stats (struct net_device *netdev, +struct rtnl_link_stats64 *net_stats) {struct enic *enic =netdev_priv (netdev);struct vnic_stats *stats;
@@ -884,7 +884,7 @@ static void enic_get_stats(struct net_device *netdev,* recorded stats. */ if (err == -ENOMEM ) -return ; +return 0 ; net_stats->tx_packets = stats->tx.tx_frames_ok; net_stats->tx_bytes = stats->tx.tx_bytes_ok;
@@ -898,6 +898,8 @@ static void enic_get_stats(struct net_device *netdev, net_stats->rx_over_errors = enic->rq_truncated_pkts; net_stats->rx_crc_errors = enic->rq_bad_fcs; net_stats->rx_dropped = stats->rx.rx_no_bufs + stats->rx.rx_drop; + +return 0 ; }static int enic_mc_sync (struct net_device *netdev,const u8 *mc_addr)
drivers/net/ethernet/cortina/gemini.c +4 -2
@@ -1907,8 +1907,8 @@ static void gmac_clear_hw_stats(struct net_device *netdev)readl (port->gmac_base +GMAC_IN_MAC2 ); } -static void gmac_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int gmac_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct gemini_ethernet_port *port =netdev_priv (netdev);unsigned int start;
@@ -1954,6 +1954,8 @@ static void gmac_get_stats64(struct net_device *netdev, }while (u64_stats_fetch_retry (&port->tx_stats_syncp, start)); stats->rx_dropped += stats->rx_missed_errors; + +return 0 ; }static int gmac_change_mtu (struct net_device *netdev,int new_mtu)
drivers/net/ethernet/ec_bhf.c +3 -1
@@ -448,7 +448,7 @@ static int ec_bhf_stop(struct net_device *net_dev)return 0 ; } -static void +static int ec_bhf_get_stats (struct net_device *net_dev,struct rtnl_link_stats64 *stats) {
@@ -463,6 +463,8 @@ ec_bhf_get_stats(struct net_device *net_dev, stats->tx_bytes = priv->stat_tx_bytes; stats->rx_bytes = priv->stat_rx_bytes; + +return 0 ; }static const struct net_device_ops ec_bhf_netdev_ops = {
drivers/net/ethernet/emulex/benet/be_main.c +4 -2
@@ -650,8 +650,8 @@ void be_parse_stats(struct be_adapter *adapter) } } -static void be_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int be_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct be_adapter *adapter =netdev_priv (netdev);struct be_drv_stats *drvs = &adapter->drv_stats;
@@ -715,6 +715,8 @@ static void be_get_stats64(struct net_device *netdev, stats->rx_fifo_errors = drvs->rxpp_fifo_overflow_drop + drvs->rx_input_fifo_overflow_drop + drvs->rx_drops_no_pbuf; + +return 0 ; }void be_link_status_update (struct be_adapter *adapter,u8 link_status)
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +4 -2
@@ -350,8 +350,8 @@ static void dpaa_tx_timeout(struct net_device *net_dev, unsigned int txqueue)/* Calculates the statistics for the given device by adding the statistics * collected by each CPU. */ -static void dpaa_get_stats64 (struct net_device *net_dev, -struct rtnl_link_stats64 *s) +static int dpaa_get_stats64 (struct net_device *net_dev, +struct rtnl_link_stats64 *s) {int numstats =sizeof (struct rtnl_link_stats64 ) /sizeof (u64);struct dpaa_priv *priv =netdev_priv (net_dev);
@@ -369,6 +369,8 @@ static void dpaa_get_stats64(struct net_device *net_dev,for (j =0 ; j < numstats; j++) netstats[j] += cpustats[j]; } + +return 0 ; } static int dpaa_setup_tc(struct net_device *net_dev, enum tc_setup_type type,
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +4 -2
@@ -1896,8 +1896,8 @@ static int dpaa2_eth_set_addr(struct net_device *net_dev, void *addr)/** Fill in counters maintained by the GPP driver. These may be different from * the hardware counters obtained by ethtool. */ -static void dpaa2_eth_get_stats (struct net_device *net_dev, -struct rtnl_link_stats64 *stats) +static int dpaa2_eth_get_stats (struct net_device *net_dev, +struct rtnl_link_stats64 *stats) {struct dpaa2_eth_priv *priv =netdev_priv (net_dev);struct rtnl_link_stats64 *percpu_stats;
@@ -1912,6 +1912,8 @@ static void dpaa2_eth_get_stats(struct net_device *net_dev,for (j =0 ; j < num; j++) netstats[j] += cpustats[j]; } + +return 0 ; }/* Copy mac unicast addresses from @net_dev to @priv.
drivers/net/ethernet/google/gve/gve_main.c +3 -1
@@ -26,7 +26,7 @@const char gve_version_str[] =GVE_VERSION ;static const char gve_version_prefix[] =GVE_VERSION_PREFIX ; -static void gve_get_stats (struct net_device *dev,struct rtnl_link_stats64 *s) +static int gve_get_stats (struct net_device *dev,struct rtnl_link_stats64 *s) {struct gve_priv *priv =netdev_priv (dev);unsigned int start;
@@ -54,6 +54,8 @@ static void gve_get_stats(struct net_device *dev, struct rtnl_link_stats64 *s) start)); } } + +return 0 ; }static int gve_alloc_counter_array (struct gve_priv *priv)
drivers/net/ethernet/hisilicon/hns/hns_enet.c +4 -2
@@ -1876,8 +1876,8 @@ static void hns_nic_set_rx_mode(struct net_device *ndev)netdev_err (ndev,"sync uc address fail\n" ); } -static void hns_nic_get_stats64 (struct net_device *ndev, -struct rtnl_link_stats64 *stats) +static int hns_nic_get_stats64 (struct net_device *ndev, +struct rtnl_link_stats64 *stats) {int idx =0 ;u64 tx_bytes =0 ;
@@ -1919,6 +1919,8 @@ static void hns_nic_get_stats64(struct net_device *ndev, stats->tx_window_errors = ndev->stats.tx_window_errors; stats->rx_compressed = ndev->stats.rx_compressed; stats->tx_compressed = ndev->stats.tx_compressed; + +return 0 ; } static u16
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +5 -3
@@ -1710,8 +1710,8 @@ static netdev_features_t hns3_features_check(struct sk_buff *skb,return features; } -static void hns3_nic_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int hns3_nic_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct hns3_nic_priv *priv =netdev_priv (netdev);int queue_num = priv->ae_handle->kinfo.num_tqps;
@@ -1732,7 +1732,7 @@ static void hns3_nic_get_stats64(struct net_device *netdev,u64 rx_drop =0 ;if (test_bit (HNS3_NIC_STATE_DOWN , &priv->state)) -return ; +return 0 ; handle->ae_algo->ops->update_stats (handle, &netdev->stats);
@@ -1795,6 +1795,8 @@ static void hns3_nic_get_stats64(struct net_device *netdev, stats->tx_window_errors = netdev->stats.tx_window_errors; stats->rx_compressed = netdev->stats.rx_compressed; stats->tx_compressed = netdev->stats.tx_compressed; + +return 0 ; }static int hns3_setup_tc (struct net_device *netdev,void *type_data)
drivers/net/ethernet/huawei/hinic/hinic_main.c +4 -2
@@ -854,8 +854,8 @@ static void hinic_tx_timeout(struct net_device *netdev, unsigned int txqueue) } } -static void hinic_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int hinic_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct hinic_dev *nic_dev =netdev_priv (netdev);struct hinic_rxq_stats *nic_rx_stats;
@@ -878,6 +878,8 @@ static void hinic_get_stats64(struct net_device *netdev, stats->tx_bytes = nic_tx_stats->bytes; stats->tx_packets = nic_tx_stats->pkts; stats->tx_errors = nic_tx_stats->tx_dropped; + +return 0 ; } static int hinic_set_features(struct net_device *netdev,
drivers/net/ethernet/ibm/ehea/ehea_main.c +4 -2
@@ -314,8 +314,8 @@ static void ehea_update_bcmc_registrations(void)spin_unlock_irqrestore (&ehea_bcmc_regs.lock, flags); } -static void ehea_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int ehea_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct ehea_port *port =netdev_priv (dev);u64 rx_packets =0 , tx_packets =0 , rx_bytes =0 , tx_bytes =0 ;
@@ -338,6 +338,8 @@ static void ehea_get_stats64(struct net_device *dev, stats->multicast = port->stats.multicast; stats->rx_errors = port->stats.rx_errors; + +return 0 ; }static void ehea_update_stats (struct work_struct *work)
drivers/net/ethernet/intel/e1000e/e1000.h +2 -2
@@ -476,8 +476,8 @@ int e1000e_setup_rx_resources(struct e1000_ring *ring);int e1000e_setup_tx_resources (struct e1000_ring *ring);void e1000e_free_rx_resources (struct e1000_ring *ring);void e1000e_free_tx_resources (struct e1000_ring *ring); -void e1000e_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats); +int e1000e_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats);void e1000e_set_interrupt_capability (struct e1000_adapter *adapter);void e1000e_reset_interrupt_capability (struct e1000_adapter *adapter);void e1000e_get_hw_control (struct e1000_adapter *adapter);
drivers/net/ethernet/intel/e1000e/netdev.c +4 -2
@@ -5992,8 +5992,8 @@ static void e1000_reset_task(struct work_struct *work)* * Returns the address of the device statistics structure. **/ -void e1000e_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +int e1000e_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct e1000_adapter *adapter =netdev_priv (netdev);
@@ -6029,6 +6029,8 @@ void e1000e_get_stats64(struct net_device *netdev,/* Tx Dropped needs to be maintained elsewhere */ spin_unlock (&adapter->stats64_lock); + +return 0 ; }/**
drivers/net/ethernet/intel/fm10k/fm10k_netdev.c +4 -2
@@ -1212,8 +1212,8 @@ void fm10k_reset_rx_state(struct fm10k_intfc *interface)* Obtain 64bit statistics in a way that is safe for both 32bit and 64bit * architectures. */ -static void fm10k_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int fm10k_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct fm10k_intfc *interface =netdev_priv (netdev);struct fm10k_ring *ring;
@@ -1258,6 +1258,8 @@ static void fm10k_get_stats64(struct net_device *netdev,/* following stats updated by fm10k_service_task() */ stats->rx_missed_errors = netdev->stats.rx_missed_errors; + +return 0 ; }int fm10k_setup_tc (struct net_device *dev,u8 tc)
drivers/net/ethernet/intel/i40e/i40e_main.c +6 -4
@@ -407,8 +407,8 @@ static void i40e_get_netdev_stats_struct_tx(struct i40e_ring *ring,* Returns the address of the device statistics structure. * The statistics are actually updated from the service task. **/ -static void i40e_get_netdev_stats_struct (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int i40e_get_netdev_stats_struct (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct i40e_netdev_priv *np =netdev_priv (netdev);struct i40e_vsi *vsi = np->vsi;
@@ -417,10 +417,10 @@ static void i40e_get_netdev_stats_struct(struct net_device *netdev,int i;if (test_bit (__I40E_VSI_DOWN, vsi->state)) -return ; +return 0 ;if (!vsi->tx_rings) -return ; +return 0 ;rcu_read_lock ();for (i =0 ; i < vsi->num_queue_pairs; i++) {
@@ -462,6 +462,8 @@ static void i40e_get_netdev_stats_struct(struct net_device *netdev, stats->rx_dropped = vsi_stats->rx_dropped; stats->rx_crc_errors = vsi_stats->rx_crc_errors; stats->rx_length_errors = vsi_stats->rx_length_errors; + +return 0 ; }/**
drivers/net/ethernet/intel/ice/ice_main.c +4 -2
@@ -5539,7 +5539,7 @@ void ice_update_pf_stats(struct ice_pf *pf)* @stats: main device statistics structure */ static -void ice_get_stats64 (struct net_device *netdev,struct rtnl_link_stats64 *stats) +int ice_get_stats64 (struct net_device *netdev,struct rtnl_link_stats64 *stats) {struct ice_netdev_priv *np =netdev_priv (netdev);struct rtnl_link_stats64 *vsi_stats;
@@ -5548,7 +5548,7 @@ void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats) vsi_stats = &vsi->net_stats;if (!vsi->num_txq || !vsi->num_rxq) -return ; +return 0 ;/* netdev packet/byte stats come from ring counter. These are obtained * by summing up ring counters (done by ice_update_vsi_ring_stats).
@@ -5573,6 +5573,8 @@ void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats) stats->rx_dropped = vsi_stats->rx_dropped; stats->rx_crc_errors = vsi_stats->rx_crc_errors; stats->rx_length_errors = vsi_stats->rx_length_errors; + +return 0 ; }/**
drivers/net/ethernet/intel/igb/igb_main.c +6 -4
@@ -124,8 +124,8 @@ static void igb_update_phy_info(struct timer_list *);static void igb_watchdog (struct timer_list *);static void igb_watchdog_task (struct work_struct *);static netdev_tx_t igb_xmit_frame (struct sk_buff *skb,struct net_device *); -static void igb_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats); +static int igb_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats);static int igb_change_mtu (struct net_device *,int );static int igb_set_mac (struct net_device *,void *);static void igb_set_uta (struct igb_adapter *adapter,bool set);
@@ -6479,8 +6479,8 @@ static void igb_reset_task(struct work_struct *work)* @netdev: network interface device structure * @stats: rtnl_link_stats64 pointer **/ -static void igb_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int igb_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct igb_adapter *adapter =netdev_priv (netdev);
@@ -6488,6 +6488,8 @@ static void igb_get_stats64(struct net_device *netdev,igb_update_stats (adapter);memcpy (stats, &adapter->stats64,sizeof (*stats));spin_unlock (&adapter->stats64_lock); + +return 0 ; }/**
drivers/net/ethernet/intel/igc/igc_main.c +4 -2
@@ -3899,8 +3899,8 @@ static int igc_change_mtu(struct net_device *netdev, int new_mtu)* Returns the address of the device statistics structure. * The statistics are updated here and also from the timer callback. */ -static void igc_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int igc_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct igc_adapter *adapter =netdev_priv (netdev);
@@ -3909,6 +3909,8 @@ static void igc_get_stats64(struct net_device *netdev,igc_update_stats (adapter);memcpy (stats, &adapter->stats64,sizeof (*stats));spin_unlock (&adapter->stats64_lock); + +return 0 ; } static netdev_features_t igc_fix_features(struct net_device *netdev,
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +4 -2
@@ -8926,8 +8926,8 @@ static void ixgbe_get_ring_stats64(struct rtnl_link_stats64 *stats, } } -static void ixgbe_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int ixgbe_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct ixgbe_adapter *adapter =netdev_priv (netdev);int i;
@@ -8967,6 +8967,8 @@ static void ixgbe_get_stats64(struct net_device *netdev, stats->rx_length_errors = netdev->stats.rx_length_errors; stats->rx_crc_errors = netdev->stats.rx_crc_errors; stats->rx_missed_errors = netdev->stats.rx_missed_errors; + +return 0 ; }#ifdef CONFIG_IXGBE_DCB
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +4 -2
@@ -4357,8 +4357,8 @@ static void ixgbevf_get_tx_ring_stats(struct rtnl_link_stats64 *stats, } } -static void ixgbevf_get_stats (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int ixgbevf_get_stats (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct ixgbevf_adapter *adapter =netdev_priv (netdev);unsigned int start;
@@ -4392,6 +4392,8 @@ static void ixgbevf_get_stats(struct net_device *netdev,ixgbevf_get_tx_ring_stats (stats, ring); }rcu_read_unlock (); + +return 0 ; }#define IXGBEVF_MAX_MAC_HDR_LEN 127
drivers/net/ethernet/marvell/mvneta.c +3 -1
@@ -760,7 +760,7 @@ static void mvneta_mib_counters_clear(struct mvneta_port *pp) }/* Get System Network Statistics */ -static void +static int mvneta_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {
@@ -797,6 +797,8 @@ mvneta_get_stats64(struct net_device *dev, } stats->tx_dropped = dev->stats.tx_dropped; + +return 0 ; }/* Rx descriptors helper methods */
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +3 -1
@@ -4701,7 +4701,7 @@ static int mvpp2_check_pagepool_dma(struct mvpp2_port *port)return err; } -static void +static int mvpp2_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct mvpp2_port *port =netdev_priv (dev);
@@ -4733,6 +4733,8 @@ mvpp2_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) stats->rx_errors = dev->stats.rx_errors; stats->rx_dropped = dev->stats.rx_dropped; stats->tx_dropped = dev->stats.tx_dropped; + +return 0 ; }static int mvpp2_set_ts_config (struct mvpp2_port *port,struct ifreq *ifr)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +4 -2
@@ -110,8 +110,8 @@ void otx2_get_dev_stats(struct otx2_nic *pfvf) dev_stats->tx_ucast_frames; } -void otx2_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +int otx2_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct otx2_nic *pfvf =netdev_priv (netdev);struct otx2_dev_stats *dev_stats;
@@ -127,6 +127,8 @@ void otx2_get_stats64(struct net_device *netdev, stats->tx_bytes = dev_stats->tx_bytes; stats->tx_packets = dev_stats->tx_frames; stats->tx_dropped = dev_stats->tx_drops; + +return 0 ; }EXPORT_SYMBOL (otx2_get_stats64);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +2 -2
@@ -665,8 +665,8 @@ void mbox_handler_nix_bp_enable(struct otx2_nic *pfvf,/* Device stats APIs */ void otx2_get_dev_stats (struct otx2_nic *pfvf); -void otx2_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats); +int otx2_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats);void otx2_update_lmac_stats (struct otx2_nic *pfvf);int otx2_update_rq_stats (struct otx2_nic *pfvf,int qidx);int otx2_update_sq_stats (struct otx2_nic *pfvf,int qidx);
drivers/net/ethernet/marvell/prestera/prestera_main.c +4 -2
@@ -152,8 +152,8 @@ static int prestera_port_change_mtu(struct net_device *dev, int mtu)return 0 ; } -static void prestera_port_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int prestera_port_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct prestera_port *port =netdev_priv (dev);struct prestera_port_stats *port_stats = &port->cached_hw_stats.stats;
@@ -180,6 +180,8 @@ static void prestera_port_get_stats64(struct net_device *dev, stats->collisions = port_stats->excessive_collision; stats->rx_crc_errors = port_stats->bad_crc; + +return 0 ; }static void prestera_port_get_hw_stats (struct prestera_port *port)
drivers/net/ethernet/marvell/sky2.c +4 -2
@@ -3883,8 +3883,8 @@ static void sky2_set_multicast(struct net_device *dev)gma_write16 (hw, port,GM_RX_CTRL , reg); } -static void sky2_get_stats (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int sky2_get_stats (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct sky2_port *sky2 =netdev_priv (dev);struct sky2_hw *hw = sky2->hw;
@@ -3924,6 +3924,8 @@ static void sky2_get_stats(struct net_device *dev, stats->rx_dropped = dev->stats.rx_dropped; stats->rx_fifo_errors = dev->stats.rx_fifo_errors; stats->tx_fifo_errors = dev->stats.tx_fifo_errors; + +return 0 ; }/* Can have one global because blinking is controlled by
drivers/net/ethernet/mediatek/mtk_eth_soc.c +4 -2
@@ -722,8 +722,8 @@ static void mtk_stats_update(struct mtk_eth *eth) } } -static void mtk_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *storage) +static int mtk_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *storage) {struct mtk_mac *mac =netdev_priv (dev);struct mtk_hw_stats *hw_stats = mac->hw_stats;
@@ -754,6 +754,8 @@ static void mtk_get_stats64(struct net_device *dev, storage->tx_errors = dev->stats.tx_errors; storage->rx_dropped = dev->stats.rx_dropped; storage->tx_dropped = dev->stats.tx_dropped; + +return 0 ; }static inline int mtk_max_frag_size (int mtu)
drivers/net/ethernet/mediatek/mtk_star_emac.c +4 -2
@@ -1104,14 +1104,16 @@ static void mtk_star_tx_complete_all(struct mtk_star_priv *priv)spin_unlock (&priv->lock); } -static void mtk_star_netdev_get_stats64 (struct net_device *ndev, -struct rtnl_link_stats64 *stats) +static int mtk_star_netdev_get_stats64 (struct net_device *ndev, +struct rtnl_link_stats64 *stats) {struct mtk_star_priv *priv =netdev_priv (ndev);mtk_star_update_stats (priv);memcpy (stats, &priv->stats,sizeof (*stats)); + +return 0 ; }static void mtk_star_set_rx_mode (struct net_device *ndev)
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +3 -1
@@ -1385,7 +1385,7 @@ static void mlx4_en_tx_timeout(struct net_device *dev, unsigned int txqueue) } -static void +static int mlx4_en_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct mlx4_en_priv *priv =netdev_priv (dev);
@@ -1394,6 +1394,8 @@ mlx4_en_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)mlx4_en_fold_software_stats (dev);netdev_stats_to_stats64 (stats, &dev->stats);spin_unlock_bh (&priv->stats_lock); + +return 0 ; }static void mlx4_en_set_default_moderation (struct mlx4_en_priv *priv)
drivers/net/ethernet/mellanox/mlx5/core/en.h +1 -1
@@ -895,7 +895,7 @@ bool mlx5e_check_fragmented_striding_rq_cap(struct mlx5_core_dev *mdev);bool mlx5e_striding_rq_possible (struct mlx5_core_dev *mdev,struct mlx5e_params *params); -void mlx5e_get_stats (struct net_device *dev,struct rtnl_link_stats64 *stats); +int mlx5e_get_stats (struct net_device *dev,struct rtnl_link_stats64 *stats);void mlx5e_fold_sw_stats64 (struct mlx5e_priv *priv,struct rtnl_link_stats64 *s);void mlx5e_init_l2_addr (struct mlx5e_priv *priv);
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +3 -1
@@ -3678,7 +3678,7 @@ void mlx5e_fold_sw_stats64(struct mlx5e_priv *priv, struct rtnl_link_stats64 *s) } } -void +int mlx5e_get_stats (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct mlx5e_priv *priv =netdev_priv (dev);
@@ -3716,6 +3716,8 @@ mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats) stats->rx_errors = stats->rx_length_errors + stats->rx_crc_errors + stats->rx_frame_errors; stats->tx_errors = stats->tx_aborted_errors + stats->tx_carrier_errors; + +return 0 ; }static void mlx5e_set_rx_mode (struct net_device *dev)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +3 -1
@@ -554,7 +554,7 @@ static int mlx5e_rep_get_offload_stats(int attr_id, const struct net_device *devreturn -EINVAL ; } -static void +static int mlx5e_rep_get_stats (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct mlx5e_priv *priv =netdev_priv (dev);
@@ -562,6 +562,8 @@ mlx5e_rep_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)/* update HW stats in background for next time */ mlx5e_queue_update_stats (priv);memcpy (stats, &priv->stats.vf_vport,sizeof (*stats)); + +return 0 ; }static int mlx5e_rep_change_mtu (struct net_device *netdev,int new_mtu)
drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.c +3 -1
@@ -142,7 +142,7 @@ static void mlx5i_grp_sw_update_stats(struct mlx5e_priv *priv)memcpy (&priv->stats.sw, &s,sizeof (s)); } -void mlx5i_get_stats (struct net_device *dev,struct rtnl_link_stats64 *stats) +int mlx5i_get_stats (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct mlx5e_priv *priv =mlx5i_epriv (dev);struct mlx5e_sw_stats *sstats = &priv->stats.sw;
@@ -154,6 +154,8 @@ void mlx5i_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats) stats->tx_packets = sstats->tx_packets; stats->tx_bytes = sstats->tx_bytes; stats->tx_dropped = sstats->tx_queue_dropped; + +return 0 ; }int mlx5i_init_underlay_qp (struct mlx5e_priv *priv)
drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.h +1 -1
@@ -118,7 +118,7 @@ struct mlx5i_tx_wqe {void mlx5i_sq_xmit (struct mlx5e_txqsq *sq,struct sk_buff *skb,struct mlx5_av *av,u32 dqpn,u32 dqkey,bool xmit_more); -void mlx5i_get_stats (struct net_device *dev,struct rtnl_link_stats64 *stats); +int mlx5i_get_stats (struct net_device *dev,struct rtnl_link_stats64 *stats);#endif /* CONFIG_MLX5_CORE_IPOIB */ #endif /* __MLX5E_IPOB_H__ */
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +3 -1
@@ -834,13 +834,15 @@ static void update_stats_cache(struct work_struct *work)/* Return the stats from a cache that is updated periodically, * as this function might get called in an atomic context. */ -static void +static int mlxsw_sp_port_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct mlxsw_sp_port *mlxsw_sp_port =netdev_priv (dev);memcpy (stats, &mlxsw_sp_port->periodic_hw_stats.stats,sizeof (*stats)); + +return 0 ; } static int __mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port,
drivers/net/ethernet/mellanox/mlxsw/switchx2.c +3 -1
@@ -346,7 +346,7 @@ static int mlxsw_sx_port_change_mtu(struct net_device *dev, int mtu)return 0 ; } -static void +static int mlxsw_sx_port_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {
@@ -375,6 +375,8 @@ mlxsw_sx_port_get_stats64(struct net_device *dev, tx_dropped += p->tx_dropped; } stats->tx_dropped = tx_dropped; + +return 0 ; } static struct devlink_port *
drivers/net/ethernet/microchip/lan743x_main.c +4 -2
@@ -2605,8 +2605,8 @@ static int lan743x_netdev_change_mtu(struct net_device *netdev, int new_mtu)return ret; } -static void lan743x_netdev_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int lan743x_netdev_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct lan743x_adapter *adapter =netdev_priv (netdev);
@@ -2650,6 +2650,8 @@ static void lan743x_netdev_get_stats64(struct net_device *netdev, STAT_TX_MULTIPLE_COLLISIONS) +lan743x_csr_read (adapter,STAT_TX_LATE_COLLISIONS ); + +return 0 ; } static int lan743x_netdev_set_mac_address(struct net_device *netdev,
drivers/net/ethernet/mscc/ocelot_net.c +4 -2
@@ -556,8 +556,8 @@ static int ocelot_port_set_mac_address(struct net_device *dev, void *p)return 0 ; } -static void ocelot_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int ocelot_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct ocelot_port_private *priv =netdev_priv (dev);struct ocelot *ocelot = priv->port.ocelot;
@@ -593,6 +593,8 @@ static void ocelot_get_stats64(struct net_device *dev, stats->tx_dropped =ocelot_read (ocelot,SYS_COUNT_TX_DROPS ) +ocelot_read (ocelot,SYS_COUNT_TX_AGING ); stats->collisions =ocelot_read (ocelot,SYS_COUNT_TX_COLLISION ); + +return 0 ; } static int ocelot_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
drivers/net/ethernet/myricom/myri10ge/myri10ge.c +7 -5
@@ -362,8 +362,8 @@ static inline void put_be32(__be32 val, __be32 __iomem * p)__raw_writel ((__force __u32 ) val, (__force void __iomem *)p); } -static void myri10ge_get_stats (struct net_device *dev, -struct rtnl_link_stats64 *stats); +static int myri10ge_get_stats (struct net_device *dev, +struct rtnl_link_stats64 *stats);static void set_fw_name (struct myri10ge_priv *mgp,char *name,bool allocated) {
@@ -1790,7 +1790,7 @@ myri10ge_get_ethtool_stats(struct net_device *netdev,/* force stats update */ memset (&link_stats,0 ,sizeof (link_stats)); - (void )myri10ge_get_stats (netdev, &link_stats); +myri10ge_get_stats (netdev, &link_stats);for (i =0 ; i <MYRI10GE_NET_STATS_LEN ; i++) data[i] = ((u64 *)&link_stats)[i];
@@ -2914,8 +2914,8 @@ static netdev_tx_t myri10ge_sw_tso(struct sk_buff *skb,return NETDEV_TX_OK ; } -static void myri10ge_get_stats (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int myri10ge_get_stats (struct net_device *dev, +struct rtnl_link_stats64 *stats) {const struct myri10ge_priv *mgp =netdev_priv (dev);const struct myri10ge_slice_netstats *slice_stats;
@@ -2930,6 +2930,8 @@ static void myri10ge_get_stats(struct net_device *dev, stats->rx_dropped += slice_stats->rx_dropped; stats->tx_dropped += slice_stats->tx_dropped; } + +return 0 ; }static void myri10ge_set_multicast_list (struct net_device *dev)
drivers/net/ethernet/neterion/vxge/vxge-main.c +3 -1
@@ -3100,7 +3100,7 @@ static int vxge_change_mtu(struct net_device *dev, int new_mtu)* @net_stats: pointer to struct rtnl_link_stats64 * */ -static void +static int vxge_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *net_stats) {struct vxgedev *vdev =netdev_priv (dev);
@@ -3139,6 +3139,8 @@ vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats) net_stats->tx_bytes += bytes; net_stats->tx_errors += txstats->tx_errors; } + +return 0 ; }static enum vxge_hw_status vxge_timestamp_config (struct __vxge_hw_device *devh)
drivers/net/ethernet/netronome/nfp/nfp_net_common.c +4 -2
@@ -3360,8 +3360,8 @@ nfp_net_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)return nfp_net_mbox_reconfig_and_unlock (nn, cmd); } -static void nfp_net_stat64 (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int nfp_net_stat64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct nfp_net *nn =netdev_priv (netdev);int r;
@@ -3400,6 +3400,8 @@ static void nfp_net_stat64(struct net_device *netdev, stats->tx_dropped +=nn_readq (nn,NFP_NET_CFG_STATS_TX_DISCARDS ); stats->tx_errors +=nn_readq (nn,NFP_NET_CFG_STATS_TX_ERRORS ); + +return 0 ; } static int nfp_net_set_features(struct net_device *netdev,
drivers/net/ethernet/netronome/nfp/nfp_net_repr.c +4 -2
@@ -86,13 +86,13 @@ nfp_repr_vnic_get_stats64(struct nfp_port *port, stats->rx_dropped =readq (port->vnic +NFP_NET_CFG_STATS_TX_DISCARDS ); } -static void +static int nfp_repr_get_stats64 (struct net_device *netdev,struct rtnl_link_stats64 *stats) {struct nfp_repr *repr =netdev_priv (netdev);if (WARN_ON (!repr->port)) -return ; +return 0 ;switch (repr->port->type) {case NFP_PORT_PHYS_PORT :
@@ -106,6 +106,8 @@ nfp_repr_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)default :break ; } + +return 0 ; } static bool
drivers/net/ethernet/nvidia/forcedeth.c +3 -1
@@ -1764,7 +1764,7 @@ static void nv_get_stats(int cpu, struct fe_priv *np,* Called with read_lock(&dev_base_lock) held for read - * only synchronized against unregister_netdevice. */ -static void +static int nv_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *storage) __acquires(&netdev_priv(dev)->hwstats_lock) __releases(&netdev_priv(dev)->hwstats_lock)
@@ -1812,6 +1812,8 @@ nv_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *storage)spin_unlock_bh (&np->hwstats_lock); } + +return 0 ; }/*
drivers/net/ethernet/pensando/ionic/ionic_lif.c +4 -2
@@ -904,8 +904,8 @@ static int ionic_adminq_napi(struct napi_struct *napi, int budget)return work_done; } -void ionic_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *ns) +int ionic_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *ns) {struct ionic_lif *lif =netdev_priv (netdev);struct ionic_lif_stats *ls;
@@ -955,6 +955,8 @@ void ionic_get_stats64(struct net_device *netdev, ns->rx_missed_errors; ns->tx_errors = ns->tx_aborted_errors; + +return 0 ; }static int ionic_lif_addr_add (struct ionic_lif *lif,const u8 *addr)
drivers/net/ethernet/pensando/ionic/ionic_lif.h +2 -2
@@ -252,8 +252,8 @@ static inline u32 ionic_coal_usec_to_hw(struct ionic *ionic, u32 usecs)typedef void (*ionic_reset_cb )(struct ionic_lif *lif,void *arg);void ionic_link_status_check_request (struct ionic_lif *lif,bool can_sleep); -void ionic_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *ns); +int ionic_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *ns);void ionic_lif_deferred_enqueue (struct ionic_deferred *def,struct ionic_deferred_work *work);int ionic_lif_alloc (struct ionic *ionic);
drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c +6 -4
@@ -71,8 +71,8 @@ static irqreturn_t netxen_msix_intr(int irq, void *data);static void netxen_free_ip_list (struct netxen_adapter *,bool );static void netxen_restore_indev_addr (struct net_device *dev,unsigned long ); -static void netxen_nic_get_stats (struct net_device *dev, -struct rtnl_link_stats64 *stats); +static int netxen_nic_get_stats (struct net_device *dev, +struct rtnl_link_stats64 *stats);static int netxen_nic_set_mac (struct net_device *netdev,void *p);/* PCI Device ID Table */
@@ -2269,8 +2269,8 @@ static void netxen_tx_timeout_task(struct work_struct *work)clear_bit (__NX_RESETTING, &adapter->state); } -static void netxen_nic_get_stats (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int netxen_nic_get_stats (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct netxen_adapter *adapter =netdev_priv (netdev);
@@ -2280,6 +2280,8 @@ static void netxen_nic_get_stats(struct net_device *netdev, stats->tx_bytes = adapter->stats.txbytes; stats->rx_dropped = adapter->stats.rxdropped; stats->tx_dropped = adapter->stats.txdropped; + +return 0 ; }static irqreturn_t netxen_intr (int irq,void *data)
drivers/net/ethernet/qlogic/qede/qede_main.c +4 -2
@@ -412,8 +412,8 @@ void qede_fill_by_demand_stats(struct qede_dev *edev) } } -static void qede_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int qede_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct qede_dev *edev =netdev_priv (dev);struct qede_stats_common *p_common;
@@ -440,6 +440,8 @@ static void qede_get_stats64(struct net_device *dev, stats->collisions = edev->stats.bb.tx_total_collisions; stats->rx_crc_errors = p_common->rx_crc_errors; stats->rx_frame_errors = p_common->rx_align_errors; + +return 0 ; }#ifdef CONFIG_QED_SRIOV
drivers/net/ethernet/qualcomm/emac/emac.c +4 -2
@@ -332,8 +332,8 @@ void emac_update_hw_stats(struct emac_adapter *adpt) }/* Provide network statistics info for the interface */ -static void emac_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *net_stats) +static int emac_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *net_stats) {struct emac_adapter *adpt =netdev_priv (netdev);struct emac_stats *stats = &adpt->stats;
@@ -368,6 +368,8 @@ static void emac_get_stats64(struct net_device *netdev, net_stats->tx_window_errors = stats->tx_late_col;spin_unlock (&stats->lock); + +return 0 ; }static const struct net_device_ops emac_netdev_ops = {
drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c +5 -3
@@ -122,8 +122,8 @@ static void rmnet_vnd_uninit(struct net_device *dev)free_percpu (priv->pcpu_stats); } -static void rmnet_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *s) +static int rmnet_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *s) {struct rmnet_priv *priv =netdev_priv (dev);struct rmnet_vnd_stats total_stats;
@@ -151,6 +151,8 @@ static void rmnet_get_stats64(struct net_device *dev, s->tx_packets = total_stats.tx_pkts; s->tx_bytes = total_stats.tx_bytes; s->tx_dropped = total_stats.tx_drops; + +return 0 ; }static const struct net_device_ops rmnet_vnd_ops = {
@@ -354,4 +356,4 @@ int rmnet_vnd_update_dev_mtu(struct rmnet_port *port, }return 0 ; -} +}
drivers/net/ethernet/realtek/8139too.c +5 -3
@@ -654,8 +654,8 @@ static int rtl8139_poll(struct napi_struct *napi, int budget);static irqreturn_t rtl8139_interrupt (int irq,void *dev_instance);static int rtl8139_close (struct net_device *dev);static int netdev_ioctl (struct net_device *dev,struct ifreq *rq,int cmd); -static void rtl8139_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats); +static int rtl8139_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats);static void rtl8139_set_rx_mode (struct net_device *dev);static void __set_rx_mode (struct net_device *dev);static void rtl8139_hw_start (struct net_device *dev);
@@ -2513,7 +2513,7 @@ static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) } -static void +static int rtl8139_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct rtl8139_private *tp =netdev_priv (dev);
@@ -2541,6 +2541,8 @@ rtl8139_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) stats->tx_packets = tp->tx_stats.packets; stats->tx_bytes = tp->tx_stats.bytes; }while (u64_stats_fetch_retry_irq (&tp->tx_stats.syncp, start)); + +return 0 ; }/* Set or clear the multicast filter for this adaptor.
drivers/net/ethernet/realtek/r8169_main.c +3 -1
@@ -4733,7 +4733,7 @@ static int rtl_open(struct net_device *dev) goto out; } -static void +static int rtl8169_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct rtl8169_private *tp =netdev_priv (dev);
@@ -4766,6 +4766,8 @@ rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)le16_to_cpu (tp->tc_offset.rx_missed);pm_runtime_put_noidle (&pdev->dev); + +return 0 ; }static void rtl8169_net_suspend (struct rtl8169_private *tp)
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +4 -2
@@ -1708,8 +1708,8 @@ static inline u64 sxgbe_get_stat64(void __iomem *ioaddr, int reg_lo, int reg_hi)* executed to see device statistics. Statistics are number of * bytes sent or received, errors occurred etc. */ -static void sxgbe_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int sxgbe_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct sxgbe_priv_data *priv =netdev_priv (dev);void __iomem *ioaddr = priv->ioaddr;
@@ -1760,6 +1760,8 @@ static void sxgbe_get_stats64(struct net_device *dev, SXGBE_MMC_TXUFLWHI_GBCNT_REG);writel (0 , ioaddr +SXGBE_MMC_CTL_REG );spin_unlock (&priv->stats_lock); + +return 0 ; }/* sxgbe_set_features - entry point to set offload features of the device.
drivers/net/ethernet/sfc/efx_common.c +3 -1
@@ -597,13 +597,15 @@ void efx_stop_all(struct efx_nic *efx) }/* Context: process, dev_base_lock or RTNL held, non-blocking. */ -void efx_net_stats (struct net_device *net_dev,struct rtnl_link_stats64 *stats) +int efx_net_stats (struct net_device *net_dev,struct rtnl_link_stats64 *stats) {struct efx_nic *efx =netdev_priv (net_dev);spin_lock_bh (&efx->stats_lock);efx_nic_update_stats_atomic (efx,NULL , stats);spin_unlock_bh (&efx->stats_lock); + +return 0 ; }/* Push loopback/power/transmit disable settings to the PHY, and reconfigure
drivers/net/ethernet/sfc/efx_common.h +1 -1
@@ -31,7 +31,7 @@ void efx_link_set_wanted_fc(struct efx_nic *efx, u8);void efx_start_all (struct efx_nic *efx);void efx_stop_all (struct efx_nic *efx); -void efx_net_stats (struct net_device *net_dev,struct rtnl_link_stats64 *stats); +int efx_net_stats (struct net_device *net_dev,struct rtnl_link_stats64 *stats);int efx_create_reset_workqueue (void );void efx_queue_reset_work (struct efx_nic *efx);
drivers/net/ethernet/sfc/falcon/efx.c +4 -2
@@ -2097,14 +2097,16 @@ int ef4_net_stop(struct net_device *net_dev) }/* Context: process, dev_base_lock or RTNL held, non-blocking. */ -static void ef4_net_stats (struct net_device *net_dev, -struct rtnl_link_stats64 *stats) +static int ef4_net_stats (struct net_device *net_dev, +struct rtnl_link_stats64 *stats) {struct ef4_nic *efx =netdev_priv (net_dev);spin_lock_bh (&efx->stats_lock); efx->type->update_stats (efx,NULL , stats);spin_unlock_bh (&efx->stats_lock); + +return 0 ; }/* Context: netif_tx_lock held, BHs disabled. */
drivers/net/ethernet/socionext/sni_ave.c +4 -2
@@ -1499,8 +1499,8 @@ static void ave_set_rx_mode(struct net_device *ndev) } } -static void ave_get_stats64 (struct net_device *ndev, -struct rtnl_link_stats64 *stats) +static int ave_get_stats64 (struct net_device *ndev, +struct rtnl_link_stats64 *stats) {struct ave_private *priv =netdev_priv (ndev);unsigned int start;
@@ -1523,6 +1523,8 @@ static void ave_get_stats64(struct net_device *ndev, stats->tx_dropped = priv->stats_tx.dropped; stats->rx_fifo_errors = priv->stats_rx.fifo_errors; stats->collisions = priv->stats_tx.collisions; + +return 0 ; }static int ave_set_mac_address (struct net_device *ndev,void *p)
drivers/net/ethernet/sun/niu.c +4 -2
@@ -6274,8 +6274,8 @@ static void niu_get_tx_stats(struct niu *np, stats->tx_errors = errors; } -static void niu_get_stats (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int niu_get_stats (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct niu *np =netdev_priv (dev);
@@ -6283,6 +6283,8 @@ static void niu_get_stats(struct net_device *dev,niu_get_rx_stats (np, stats);niu_get_tx_stats (np, stats); } + +return 0 ; }static void niu_load_hash_xmac (struct niu *np,u16 *hash)
drivers/net/ethernet/synopsys/dwc-xlgmac-net.c +4 -2
@@ -764,8 +764,8 @@ static netdev_tx_t xlgmac_xmit(struct sk_buff *skb, struct net_device *netdev)return NETDEV_TX_OK ; } -static void xlgmac_get_stats64 (struct net_device *netdev, -struct rtnl_link_stats64 *s) +static int xlgmac_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *s) {struct xlgmac_pdata *pdata =netdev_priv (netdev);struct xlgmac_stats *pstats = &pdata->stats;
@@ -787,6 +787,8 @@ static void xlgmac_get_stats64(struct net_device *netdev, s->tx_bytes = pstats->txoctetcount_gb; s->tx_errors = pstats->txframecount_gb - pstats->txframecount_g; s->tx_dropped = netdev->stats.tx_dropped; + +return 0 ; }static int xlgmac_set_mac_address (struct net_device *netdev,void *addr)
drivers/net/ethernet/ti/am65-cpsw-nuss.c +4 -2
@@ -1407,8 +1407,8 @@ static int am65_cpsw_nuss_ndo_slave_ioctl(struct net_device *ndev,return phy_mii_ioctl (port->slave.phy, req, cmd); } -static void am65_cpsw_nuss_ndo_get_stats (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int am65_cpsw_nuss_ndo_get_stats (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct am65_cpsw_ndev_priv *ndev_priv =netdev_priv (dev);unsigned int start;
@@ -1439,6 +1439,8 @@ static void am65_cpsw_nuss_ndo_get_stats(struct net_device *dev, stats->rx_errors = dev->stats.rx_errors; stats->rx_dropped = dev->stats.rx_dropped; stats->tx_dropped = dev->stats.tx_dropped; + +return 0 ; }static const struct net_device_ops am65_cpsw_nuss_netdev_ops = {
drivers/net/ethernet/ti/netcp_core.c +3 -1
@@ -1908,7 +1908,7 @@ static int netcp_setup_tc(struct net_device *dev, enum tc_setup_type type,return 0 ; } -static void +static int netcp_get_stats (struct net_device *ndev,struct rtnl_link_stats64 *stats) {struct netcp_intf *netcp =netdev_priv (ndev);
@@ -1937,6 +1937,8 @@ netcp_get_stats(struct net_device *ndev, struct rtnl_link_stats64 *stats) stats->rx_errors = p->rx_errors; stats->rx_dropped = p->rx_dropped; stats->tx_dropped = p->tx_dropped; + +return 0 ; }static const struct net_device_ops netcp_netdev_ops = {
drivers/net/ethernet/via/via-rhine.c +5 -3
@@ -507,8 +507,8 @@ static irqreturn_t rhine_interrupt(int irq, void *dev_instance);static void rhine_tx (struct net_device *dev);static int rhine_rx (struct net_device *dev,int limit);static void rhine_set_rx_mode (struct net_device *dev); -static void rhine_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats); +static int rhine_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats);static int netdev_ioctl (struct net_device *dev,struct ifreq *rq,int cmd);static const struct ethtool_ops netdev_ethtool_ops;static int rhine_close (struct net_device *dev);
@@ -2207,7 +2207,7 @@ static void rhine_slow_event_task(struct work_struct *work)mutex_unlock (&rp->task_lock); } -static void +static int rhine_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct rhine_private *rp =netdev_priv (dev);
@@ -2230,6 +2230,8 @@ rhine_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) stats->tx_packets = rp->tx_stats.packets; stats->tx_bytes = rp->tx_stats.bytes; }while (u64_stats_fetch_retry_irq (&rp->tx_stats.syncp, start)); + +return 0 ; }static void rhine_set_rx_mode (struct net_device *dev)
drivers/net/fjes/fjes_main.c +4 -2
@@ -44,7 +44,7 @@ static void fjes_raise_intr_rxdata_task(struct work_struct *);static void fjes_tx_stall_task (struct work_struct *);static void fjes_force_close_task (struct work_struct *);static irqreturn_t fjes_intr (int ,void *); -static void fjes_get_stats64 (struct net_device *,struct rtnl_link_stats64 *); +static int fjes_get_stats64 (struct net_device *,struct rtnl_link_stats64 *);static int fjes_change_mtu (struct net_device *,int );static int fjes_vlan_rx_add_vid (struct net_device *,__be16 proto,u16 );static int fjes_vlan_rx_kill_vid (struct net_device *,__be16 proto,u16 );
@@ -802,12 +802,14 @@ static void fjes_tx_retry(struct net_device *netdev, unsigned int txqueue)netif_tx_wake_queue (queue); } -static void +static int fjes_get_stats64 (struct net_device *netdev,struct rtnl_link_stats64 *stats) {struct fjes_adapter *adapter =netdev_priv (netdev);memcpy (stats, &adapter->stats64,sizeof (struct rtnl_link_stats64 )); + +return 0 ; }static int fjes_change_mtu (struct net_device *netdev,int new_mtu)
drivers/net/hyperv/netvsc_drv.c +4 -2
@@ -1357,8 +1357,8 @@ static void netvsc_get_pcpu_stats(struct net_device *net, } } -static void netvsc_get_stats64 (struct net_device *net, -struct rtnl_link_stats64 *t) +static int netvsc_get_stats64 (struct net_device *net, +struct rtnl_link_stats64 *t) {struct net_device_context *ndev_ctx =netdev_priv (net);struct netvsc_device *nvdev;
@@ -1410,6 +1410,8 @@ static void netvsc_get_stats64(struct net_device *net, } out:rcu_read_unlock (); + +return 0 ; }static int netvsc_set_mac_addr (struct net_device *ndev,void *p)
drivers/net/ifb.c +3 -2
@@ -123,8 +123,7 @@ static void ifb_ri_tasklet(unsigned long _txp) } -static void ifb_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int ifb_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct ifb_dev_private *dp =netdev_priv (dev);struct ifb_q_private *txp = dp->tx_private;
@@ -151,6 +150,8 @@ static void ifb_stats64(struct net_device *dev, } stats->rx_dropped = dev->stats.rx_dropped; stats->tx_dropped = dev->stats.tx_dropped; + +return 0 ; }static int ifb_dev_init (struct net_device *dev)
drivers/net/ipvlan/ipvlan_main.c +4 -2
@@ -286,8 +286,8 @@ static void ipvlan_set_multicast_mac_filter(struct net_device *dev)dev_mc_sync (ipvlan->phy_dev, dev); } -static void ipvlan_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *s) +static int ipvlan_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *s) {struct ipvl_dev *ipvlan =netdev_priv (dev);
@@ -324,6 +324,8 @@ static void ipvlan_get_stats64(struct net_device *dev, s->rx_dropped = rx_errs; s->tx_dropped = tx_drps; } + +return 0 ; }static int ipvlan_vlan_rx_add_vid (struct net_device *dev,__be16 proto,u16 vid)
drivers/net/loopback.c +4 -2
@@ -115,8 +115,8 @@ void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes) }EXPORT_SYMBOL (dev_lstats_read); -static void loopback_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int loopback_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {u64 packets, bytes;
@@ -126,6 +126,8 @@ static void loopback_get_stats64(struct net_device *dev, stats->tx_packets = packets; stats->rx_bytes = bytes; stats->tx_bytes = bytes; + +return 0 ; }static u32 always_on (struct net_device *dev)
drivers/net/macsec.c +5 -3
@@ -3645,16 +3645,18 @@ static int macsec_change_mtu(struct net_device *dev, int new_mtu)return 0 ; } -static void macsec_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *s) +static int macsec_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *s) {if (!dev->tstats) -return ; +return 0 ;dev_fetch_sw_netstats (s, dev->tstats); s->rx_dropped = dev->stats.rx_dropped; s->tx_dropped = dev->stats.tx_dropped; + +return 0 ; }static int macsec_get_iflink (const struct net_device *dev)
drivers/net/macvlan.c +4 -2
@@ -927,8 +927,8 @@ static void macvlan_uninit(struct net_device *dev)macvlan_port_destroy (port->dev); } -static void macvlan_dev_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int macvlan_dev_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct macvlan_dev *vlan =netdev_priv (dev);
@@ -965,6 +965,8 @@ static void macvlan_dev_get_stats64(struct net_device *dev, stats->rx_dropped = rx_errors; stats->tx_dropped = tx_dropped; } + +return 0 ; } static int macvlan_vlan_rx_add_vid(struct net_device *dev,
drivers/net/mhi_net.c +4 -2
@@ -89,8 +89,8 @@ static int mhi_ndo_xmit(struct sk_buff *skb, struct net_device *ndev)return NETDEV_TX_OK ; } -static void mhi_ndo_get_stats64 (struct net_device *ndev, -struct rtnl_link_stats64 *stats) +static int mhi_ndo_get_stats64 (struct net_device *ndev, +struct rtnl_link_stats64 *stats) {struct mhi_net_dev *mhi_netdev =netdev_priv (ndev);unsigned int start;
@@ -110,6 +110,8 @@ static void mhi_ndo_get_stats64(struct net_device *ndev, stats->tx_errors =u64_stats_read (&mhi_netdev->stats.tx_errors); stats->tx_dropped =u64_stats_read (&mhi_netdev->stats.tx_dropped); }while (u64_stats_fetch_retry_irq (&mhi_netdev->stats.tx_syncp, start)); + +return 0 ; }static const struct net_device_ops mhi_netdev_ops = {
drivers/net/net_failover.c +4 -2
@@ -179,8 +179,8 @@ static void net_failover_fold_stats(struct rtnl_link_stats64 *_res, } } -static void net_failover_get_stats (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int net_failover_get_stats (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct net_failover_info *nfo_info =netdev_priv (dev);struct rtnl_link_stats64 temp;
@@ -209,6 +209,8 @@ static void net_failover_get_stats(struct net_device *dev,memcpy (&nfo_info->failover_stats, stats,sizeof (*stats));spin_unlock (&nfo_info->stats_lock); + +return 0 ; }static int net_failover_change_mtu (struct net_device *dev,int new_mtu)
drivers/net/netdevsim/netdev.c +3 -1
@@ -60,7 +60,7 @@ static int nsim_change_mtu(struct net_device *dev, int new_mtu)return 0 ; } -static void +static int nsim_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct netdevsim *ns =netdev_priv (dev);
@@ -71,6 +71,8 @@ nsim_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) stats->tx_bytes = ns->tx_bytes; stats->tx_packets = ns->tx_packets; }while (u64_stats_fetch_retry (&ns->syncp, start)); + +return 0 ; } static int
drivers/net/nlmon.c +3 -1
@@ -48,7 +48,7 @@ static int nlmon_close(struct net_device *dev)return netlink_remove_tap (&nlmon->nt); } -static void +static int nlmon_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {u64 packets, bytes;
@@ -60,6 +60,8 @@ nlmon_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) stats->rx_bytes = bytes; stats->tx_bytes =0 ; + +return 0 ; }static u32 always_on (struct net_device *dev)
drivers/net/ppp/ppp_generic.c +3 -1
@@ -1488,7 +1488,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)return err; } -static void +static int ppp_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats64) {struct ppp *ppp =netdev_priv (dev);
@@ -1508,6 +1508,8 @@ ppp_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats64) stats64->rx_dropped = dev->stats.rx_dropped; stats64->tx_dropped = dev->stats.tx_dropped; stats64->rx_length_errors = dev->stats.rx_length_errors; + +return 0 ; }static int ppp_dev_init (struct net_device *dev)
drivers/net/slip/slip.c +3 -1
@@ -570,7 +570,7 @@ static int sl_change_mtu(struct net_device *dev, int new_mtu)/* Netdevice get statistics request */ -static void +static int sl_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct net_device_stats *devstats = &dev->stats;
@@ -601,6 +601,8 @@ sl_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) stats->collisions += comp->sls_o_misses; }#endif + +return 0 ; }/* Netdevice register callback */
drivers/net/team/team.c +3 -1
@@ -1835,7 +1835,7 @@ static int team_change_mtu(struct net_device *dev, int new_mtu)return err; } -static void +static int team_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct team *team =netdev_priv (dev);
@@ -1872,6 +1872,8 @@ team_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) stats->rx_dropped = rx_dropped; stats->tx_dropped = tx_dropped; stats->rx_nohandler = rx_nohandler; + +return 0 ; }static int team_vlan_rx_add_vid (struct net_device *dev,__be16 proto,u16 vid)
drivers/net/thunderbolt.c +4 -2
@@ -1144,8 +1144,8 @@ static netdev_tx_t tbnet_start_xmit(struct sk_buff *skb,return NETDEV_TX_OK ; } -static void tbnet_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int tbnet_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct tbnet *net =netdev_priv (dev);
@@ -1161,6 +1161,8 @@ static void tbnet_get_stats64(struct net_device *dev, stats->rx_over_errors = net->stats.rx_over_errors; stats->rx_crc_errors = net->stats.rx_crc_errors; stats->rx_missed_errors = net->stats.rx_missed_errors; + +return 0 ; }static const struct net_device_ops tbnet_netdev_ops = {
drivers/net/tun.c +3 -1
@@ -1089,7 +1089,7 @@ static void tun_set_headroom(struct net_device *dev, int new_hr) tun->align = new_hr; } -static void +static int tun_net_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct tun_struct *tun =netdev_priv (dev);
@@ -1098,6 +1098,8 @@ tun_net_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) stats->rx_frame_errors += (unsigned long )atomic_long_read (&tun->rx_frame_errors); + +return 0 ; } static int tun_xdp_set(struct net_device *dev, struct bpf_prog *prog,
drivers/net/veth.c +4 -2
@@ -361,8 +361,8 @@ static void veth_stats_rx(struct veth_stats *result, struct net_device *dev) } } -static void veth_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *tot) +static int veth_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *tot) {struct veth_priv *priv =netdev_priv (dev);struct net_device *peer;
@@ -393,6 +393,8 @@ static void veth_get_stats64(struct net_device *dev, tot->tx_packets += rx.xdp_packets; }rcu_read_unlock (); + +return 0 ; }/* fake multicast ability */
drivers/net/virtio_net.c +4 -2
@@ -1741,8 +1741,8 @@ static int virtnet_set_mac_address(struct net_device *dev, void *p)return ret; } -static void virtnet_stats (struct net_device *dev, -struct rtnl_link_stats64 *tot) +static int virtnet_stats (struct net_device *dev, +struct rtnl_link_stats64 *tot) {struct virtnet_info *vi =netdev_priv (dev);unsigned int start;
@@ -1777,6 +1777,8 @@ static void virtnet_stats(struct net_device *dev, tot->tx_fifo_errors = dev->stats.tx_fifo_errors; tot->rx_length_errors = dev->stats.rx_length_errors; tot->rx_frame_errors = dev->stats.rx_frame_errors; + +return 0 ; }static void virtnet_ack_link_announce (struct virtnet_info *vi)
drivers/net/vmxnet3/vmxnet3_ethtool.c +3 -1
@@ -113,7 +113,7 @@ vmxnet3_global_stats[] = { }; -void +int vmxnet3_get_stats64 (struct net_device *netdev,struct rtnl_link_stats64 *stats) {
@@ -160,6 +160,8 @@ vmxnet3_get_stats64(struct net_device *netdev, stats->rx_dropped += drvRxStats->drop_total; stats->multicast += devRxStats->mcastPktsRxOK; } + +return 0 ; } static int
drivers/net/vmxnet3/vmxnet3_int.h +2 -2
@@ -484,8 +484,8 @@ vmxnet3_create_queues(struct vmxnet3_adapter *adapter,void vmxnet3_set_ethtool_ops (struct net_device *netdev); -void vmxnet3_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats); +int vmxnet3_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats);extern char vmxnet3_driver_name[];#endif
drivers/net/vrf.c +4 -2
@@ -145,8 +145,8 @@ static void vrf_tx_error(struct net_device *vrf_dev, struct sk_buff *skb)kfree_skb (skb); } -static void vrf_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int vrf_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {int i;
@@ -170,6 +170,8 @@ static void vrf_get_stats64(struct net_device *dev, stats->rx_bytes += rbytes; stats->rx_packets += rpkts; } + +return 0 ; }static struct vrf_map *netns_vrf_map (struct net *net)
drivers/net/vsockmon.c +3 -1
@@ -55,13 +55,15 @@ static netdev_tx_t vsockmon_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } -static void +static int vsockmon_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {dev_lstats_read (dev, &stats->rx_packets, &stats->rx_bytes); stats->tx_packets =0 ; stats->tx_bytes =0 ; + +return 0 ; }static int vsockmon_is_valid_mtu (int new_mtu)
drivers/net/xen-netfront.c +4 -2
@@ -1247,8 +1247,8 @@ static int xennet_change_mtu(struct net_device *dev, int mtu)return 0 ; } -static void xennet_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *tot) +static int xennet_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *tot) {struct netfront_info *np =netdev_priv (dev);int cpu;
@@ -1279,6 +1279,8 @@ static void xennet_get_stats64(struct net_device *dev, tot->rx_errors = dev->stats.rx_errors; tot->tx_dropped = dev->stats.tx_dropped; + +return 0 ; }static void xennet_release_tx_bufs (struct netfront_queue *queue)
drivers/s390/net/qeth_core.h +1 -1
@@ -1136,7 +1136,7 @@ netdev_features_t qeth_fix_features(struct net_device *, netdev_features_t);netdev_features_t qeth_features_check (struct sk_buff *skb,struct net_device *dev,netdev_features_t features); -void qeth_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats); +int qeth_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats);int qeth_set_real_num_tx_queues (struct qeth_card *card,unsigned int count);u16 qeth_iqd_select_queue (struct net_device *dev,struct sk_buff *skb,u8 cast_type,struct net_device *sb_dev);
drivers/s390/net/qeth_core_main.c +3 -1
@@ -7141,7 +7141,7 @@ netdev_features_t qeth_features_check(struct sk_buff *skb, }EXPORT_SYMBOL_GPL (qeth_features_check); -void qeth_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) +int qeth_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {struct qeth_card *card = dev->ml_priv;struct qeth_qdio_out_q *queue;
@@ -7170,6 +7170,8 @@ void qeth_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) stats->tx_errors += queue->stats.tx_errors; stats->tx_dropped += queue->stats.tx_dropped; } + +return 0 ; }EXPORT_SYMBOL_GPL (qeth_get_stats64);
drivers/staging/fsl-dpaa2/ethsw/ethsw.c +3 -5
@@ -358,8 +358,8 @@ static int dpaa2_switch_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], addr); } -static void dpaa2_switch_port_get_stats (struct net_device *netdev, -struct rtnl_link_stats64 *stats) +static int dpaa2_switch_port_get_stats (struct net_device *netdev, +struct rtnl_link_stats64 *stats) {struct ethsw_port_priv *port_priv =netdev_priv (netdev);u64 tmp;
@@ -418,10 +418,8 @@ static void dpaa2_switch_port_get_stats(struct net_device *netdev,if (err) goto error; -return ; - error: -netdev_err (netdev,"dpsw_if_get_counter err %d\n" , err); +return err; } static bool dpaa2_switch_port_has_offload_stats(const struct net_device *netdev,
drivers/staging/netlogic/xlr_net.c +3 -1
@@ -317,7 +317,7 @@ static void xlr_set_rx_mode(struct net_device *ndev)xlr_nae_wreg (priv->base_addr,R_MAC_FILTER_CONFIG , regval); } -static void xlr_stats (struct net_device *ndev,struct rtnl_link_stats64 *stats) +static int xlr_stats (struct net_device *ndev,struct rtnl_link_stats64 *stats) {struct xlr_net_priv *priv =netdev_priv (ndev);
@@ -360,6 +360,8 @@ static void xlr_stats(struct net_device *ndev, struct rtnl_link_stats64 *stats) TX_DROP_FRAME_COUNTER); stats->tx_fifo_errors =xlr_nae_rdreg (priv->base_addr,TX_DROP_FRAME_COUNTER ); + +return 0 ; }static const struct net_device_ops xlr_netdev_ops = {
include/linux/netdevice.h +5 -5
@@ -1039,8 +1039,8 @@ struct netdev_net_notifier {* Callback used when the transmitter has not made any progress * for dev->watchdog ticks. * -* void (*ndo_get_stats64)(struct net_device *dev, -* struct rtnl_link_stats64 *storage); +* int (*ndo_get_stats64)(struct net_device *dev, +* struct rtnl_link_stats64 *storage); * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev); * Called when a user wants to get the network device usage * statistics. Drivers must do one of the following:
@@ -1304,7 +1304,7 @@ struct net_device_ops {void (*ndo_tx_timeout) (struct net_device *dev,unsigned int txqueue); -void (*ndo_get_stats64)(struct net_device *dev, +int (*ndo_get_stats64)(struct net_device *dev,struct rtnl_link_stats64 *storage);bool (*ndo_has_offload_stats)(const struct net_device *dev,int attr_id); int (*ndo_get_offload_stats)(int attr_id,
@@ -4545,12 +4545,12 @@ void netdev_notify_peers(struct net_device *dev);void netdev_features_change (struct net_device *dev);/* Load a device via the kmod */ void dev_load (struct net *net,const char *name); -void dev_get_stats (struct net_device *dev,struct rtnl_link_stats64 *storage); +int dev_get_stats (struct net_device *dev,struct rtnl_link_stats64 *storage);void netdev_stats_to_stats64 (struct rtnl_link_stats64 *stats64,const struct net_device_stats *netdev_stats);void dev_fetch_sw_netstats (struct rtnl_link_stats64 *s,const struct pcpu_sw_netstats __percpu *netstats); -void dev_get_tstats64 (struct net_device *dev,struct rtnl_link_stats64 *s); +int dev_get_tstats64 (struct net_device *dev,struct rtnl_link_stats64 *s);extern int netdev_max_backlog;extern int netdev_tstamp_prequeue;
net/8021q/vlan_dev.c +4 -2
@@ -683,8 +683,8 @@ static int vlan_ethtool_get_ts_info(struct net_device *dev,return 0 ; } -static void vlan_dev_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int vlan_dev_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct vlan_pcpu_stats *p;u32 rx_errors =0 , tx_dropped =0 ;
@@ -715,6 +715,8 @@ static void vlan_dev_get_stats64(struct net_device *dev, } stats->rx_errors = rx_errors; stats->tx_dropped = tx_dropped; + +return 0 ; }#ifdef CONFIG_NET_POLL_CONTROLLER
net/core/dev.c +8 -3
@@ -10403,13 +10403,14 @@ EXPORT_SYMBOL(netdev_stats_to_stats64);* dev->netdev_ops->get_stats64 or dev->netdev_ops->get_stats; * otherwise the internal statistics structure is used. */ -void dev_get_stats (struct net_device *dev,struct rtnl_link_stats64 *storage) +int dev_get_stats (struct net_device *dev,struct rtnl_link_stats64 *storage) {const struct net_device_ops *ops = dev->netdev_ops; +int err =0 ;if (ops->ndo_get_stats64) {memset (storage,0 ,sizeof (*storage)); - ops->ndo_get_stats64 (dev, storage); + err = ops->ndo_get_stats64 (dev, storage); }else if (ops->ndo_get_stats) {netdev_stats_to_stats64 (storage, ops->ndo_get_stats (dev)); }else {
@@ -10418,6 +10419,8 @@ void dev_get_stats(struct net_device *dev, struct rtnl_link_stats64 *storage) storage->rx_dropped += (unsigned long )atomic_long_read (&dev->rx_dropped); storage->tx_dropped += (unsigned long )atomic_long_read (&dev->tx_dropped); storage->rx_nohandler += (unsigned long )atomic_long_read (&dev->rx_nohandler); + +return err; }EXPORT_SYMBOL (dev_get_stats);
@@ -10463,10 +10466,12 @@ EXPORT_SYMBOL_GPL(dev_fetch_sw_netstats);* Populate @s from dev->stats and dev->tstats. Can be used as * ndo_get_stats64() callback. */ -void dev_get_tstats64 (struct net_device *dev,struct rtnl_link_stats64 *s) +int dev_get_tstats64 (struct net_device *dev,struct rtnl_link_stats64 *s) {netdev_stats_to_stats64 (s, &dev->stats);dev_fetch_sw_netstats (s, dev->tstats); + +return 0 ; }EXPORT_SYMBOL_GPL (dev_get_tstats64);
net/l2tp/l2tp_eth.c +4 -2
@@ -87,8 +87,8 @@ static netdev_tx_t l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *devreturn NETDEV_TX_OK ; } -static void l2tp_eth_get_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int l2tp_eth_get_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct l2tp_eth *priv =netdev_priv (dev);
@@ -98,6 +98,8 @@ static void l2tp_eth_get_stats64(struct net_device *dev, stats->rx_bytes = (unsigned long )atomic_long_read (&priv->rx_bytes); stats->rx_packets = (unsigned long )atomic_long_read (&priv->rx_packets); stats->rx_errors = (unsigned long )atomic_long_read (&priv->rx_errors); + +return 0 ; }static const struct net_device_ops l2tp_eth_netdev_ops = {
net/mac80211/iface.c +3 -1
@@ -698,10 +698,12 @@ static u16 ieee80211_netdev_select_queue(struct net_device *dev,return ieee80211_select_queue (IEEE80211_DEV_TO_SUB_IF (dev), skb); } -static void +static int ieee80211_get_stats64 (struct net_device *dev,struct rtnl_link_stats64 *stats) {dev_fetch_sw_netstats (stats, dev->tstats); + +return 0 ; }static const struct net_device_ops ieee80211_dataif_ops = {
net/sched/sch_teql.c +4 -2
@@ -398,8 +398,8 @@ static int teql_master_close(struct net_device *dev)return 0 ; } -static void teql_master_stats64 (struct net_device *dev, -struct rtnl_link_stats64 *stats) +static int teql_master_stats64 (struct net_device *dev, +struct rtnl_link_stats64 *stats) {struct teql_master *m =netdev_priv (dev);
@@ -407,6 +407,8 @@ static void teql_master_stats64(struct net_device *dev, stats->tx_bytes = m->tx_bytes; stats->tx_errors = m->tx_errors; stats->tx_dropped = m->tx_dropped; + +return 0 ; }static int teql_master_mtu (struct net_device *dev,int new_mtu)
Signature · 1 line
2.25.1
Re: [PATCH v6 net-next 08/15] net: allow ndo_get_stats64 to return an int error code
Quoted 27 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
Some drivers need to do special tricks to comply with the new policy of
ndo_get_stats64being sleepable. For example, the bonding driver, which
derives its stats from its lower interfaces, must recurse withdev_get_statsinto its lowers with no locks held. But for that to work,
it needs to dynamically allocate some memory for a refcounted copy of its array of slave interfaces (because recursing unlocked means that the
original one is subject to disappearing). And since memory allocation can fail under pressure, we should not let it go unnoticed, but instead
propagate the error code.This patch converts all implementations of .ndo_get_stats64 to return int, and propagates that to the
dev_get_statscalling site. Error checking will be done in further patches.Signed-off-by Vladimir Oltean <[email protected]>---
Changes in v6:
Remove the unused "int err" from__bond_release_oneand add it in the patch it belongs to.
Quoted 6 lines
Changes in v5:
None.Changes in v4:
Patch is new (Eric's suggestion).
Just Give Eric the proper credit and add:
[...]
drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c int rmnet_vnd_update_dev_mtu(struct rmnet_port · line 359
Quoted 8 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c +1
-1@@ -354,4 +356,4 @@ int rmnet_vnd_update_dev_mtu(struct rmnet_port *port, }return 0 ; -} +}
Not related?
[...]
Quoted 24 lines
-void
dev_get_stats(struct net_device *dev, struct rtnl_link_stats64 *storage)
+intdev_get_stats(struct net_device *dev, struct rtnl_link_stats64 *storage)
{net/core/dev.c +2
-1const struct net_device_ops *ops = dev->netdev_ops; +int err =0 ;if (ops->ndo_get_stats64) {memset (storage,0 ,sizeof (*storage)); - ops->ndo_get_stats64 (dev, storage); + err = ops->ndo_get_stats64 (dev, storage); }else if (ops->ndo_get_stats) { netdev_stats_to_stats64(storage, ops-Quoted 1 line
ndo_get_stats(dev));net/core/dev.c +0
-0}else {@@ -10418,6 +10419,8 @@ void dev_get_stats(struct net_device *dev, struct rtnl_link_stats64 *storage) storage->rx_dropped += (unsigned long)atomic_long_read(&dev- >rx_dropped); storage->tx_dropped += (unsigned long )atomic_long_read (&dev- >tx_dropped); storage->rx_nohandler += (unsigned long)atomic_long_read(&dev-
Quoted 1 line
Quoted 1 line
rx_nohandler);
Must be consistent here, if there was an error you should abort without touching the caller provided storage, even if you can for some stats.
Quoted 5 lines
net/core/dev.c +2
-0+ +return err; }EXPORT_SYMBOL (dev_get_stats);
Re: [PATCH v6 net-next 08/15] net: allow ndo_get_stats64 to return an int error code
In reply to Vladimir OlteanQuoted 17 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
Some drivers need to do special tricks to comply with the new policy of
ndo_get_stats64being sleepable. For example, the bonding driver, which
derives its stats from its lower interfaces, must recurse withdev_get_statsinto its lowers with no locks held. But for that to work,
it needs to dynamically allocate some memory for a refcounted copy of its array of slave interfaces (because recursing unlocked means that the
original one is subject to disappearing). And since memory allocation can fail under pressure, we should not let it go unnoticed, but instead
propagate the error code.
Quoted 5 lines
This patch converts all implementations of .ndo_get_stats64 to return int, and propagates that to the
dev_get_statscalling site. Error checking will be done in further patches.
My only concern about this patch is userland apps who never expected this to fail, they might crash when this eventually returns an err under stress, so maybe for user facing APIs,
always return 0? mainly it is procfs, others netlink/sysfs might already fail for other reasons, i think ..
PATCH v6 9/15 scsi: fcoe: propagate errors from dev_get_stats
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The FCoE callback for the Link Error Status Block retrieves the FCS error count using dev_get_stats. This function can now return errors. Propagate these all the way to the sysfs device attributes.
---
Changes in v6:
None.
Changes in v5:
None.
Changes in v4:
Patch is new (Eric's suggestion).
drivers/scsi/fcoe/fcoe_sysfs.c | 9 +++++++-- drivers/scsi/fcoe/fcoe_transport.c | 24 +++++++++++++++--------- drivers/scsi/libfc/fc_rport.c | 5 ++++- include/scsi/fcoe_sysfs.h | 12 ++++++------ include/scsi/libfc.h | 2 +- include/scsi/libfcoe.h | 8 ++++---- 6 files changed, 37 insertions(+), 23 deletions(-)
drivers/scsi/fcoe/fcoe_sysfs.c +7 -2
@@ -139,8 +139,13 @@ static ssize_t show_fcoe_ctlr_device_##field(struct device *dev, \ char *buf) \ { \struct fcoe_ctlr_device *ctlr =dev_to_ctlr (dev); \ - if (ctlr->f->get_fcoe_ctlr_##field) \ - ctlr->f->get_fcoe_ctlr_##field(ctlr); \ +int err; \ + \ + if (ctlr->f->get_fcoe_ctlr_##field) { \ + err = ctlr->f->get_fcoe_ctlr_##field(ctlr); \ + if (err) \ + return err; \ + } \ return snprintf(buf, sz, format_string, \ cast fcoe_ctlr_##field(ctlr)); \ }
drivers/scsi/fcoe/fcoe_transport.c +15 -9
@@ -166,15 +166,16 @@ EXPORT_SYMBOL_GPL(fcoe_link_speed_update);* Note, the Link Error Status Block (LESB) for FCoE is defined in FC-BB-6 * Clause 7.11 in v1.04. */ -void __fcoe_get_lesb (struct fc_lport *lport, -struct fc_els_lesb *fc_lesb, -struct net_device *netdev) +int __fcoe_get_lesb (struct fc_lport *lport, +struct fc_els_lesb *fc_lesb, +struct net_device *netdev) {struct rtnl_link_stats64 dev_stats;unsigned int cpu;u32 lfc, vlfc, mdac;struct fc_stats *stats;struct fcoe_fc_els_lesb *lesb; +int err; lfc =0 ; vlfc =0 ;
@@ -190,8 +191,14 @@ void __fcoe_get_lesb(struct fc_lport *lport, lesb->lesb_link_fail =htonl (lfc); lesb->lesb_vlink_fail =htonl (vlfc); lesb->lesb_miss_fka =htonl (mdac); -dev_get_stats (netdev, &dev_stats); + + err =dev_get_stats (netdev, &dev_stats); +if (err) +return err; + lesb->lesb_fcs_error =htonl (dev_stats.rx_crc_errors); + +return 0 ; }EXPORT_SYMBOL_GPL (__fcoe_get_lesb);
@@ -200,12 +207,11 @@ EXPORT_SYMBOL_GPL(__fcoe_get_lesb);* @lport: the local port * @fc_lesb: the link error status block */ -void fcoe_get_lesb (struct fc_lport *lport, -struct fc_els_lesb *fc_lesb) +int fcoe_get_lesb (struct fc_lport *lport,struct fc_els_lesb *fc_lesb) {struct net_device *netdev =fcoe_get_netdev (lport); -__fcoe_get_lesb (lport, fc_lesb, netdev); +return __fcoe_get_lesb (lport, fc_lesb, netdev); }EXPORT_SYMBOL_GPL (fcoe_get_lesb);
@@ -215,14 +221,14 @@ EXPORT_SYMBOL_GPL(fcoe_get_lesb);* @ctlr_dev: The given fcoe controller device * */ -void fcoe_ctlr_get_lesb (struct fcoe_ctlr_device *ctlr_dev) +int fcoe_ctlr_get_lesb (struct fcoe_ctlr_device *ctlr_dev) {struct fcoe_ctlr *fip =fcoe_ctlr_device_priv (ctlr_dev);struct net_device *netdev =fcoe_get_netdev (fip->lp);struct fc_els_lesb *fc_lesb; fc_lesb = (struct fc_els_lesb *)(&ctlr_dev->lesb); -__fcoe_get_lesb (fip->lp, fc_lesb, netdev); +return __fcoe_get_lesb (fip->lp, fc_lesb, netdev); }EXPORT_SYMBOL_GPL (fcoe_ctlr_get_lesb);
drivers/scsi/libfc/fc_rport.c +4 -1
@@ -1633,6 +1633,7 @@ static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata,struct fc_els_lesb *lesb;struct fc_seq_els_data rjt_data;struct fc_host_statistics *hst; +int err;lockdep_assert_held (&rdata->rp_mutex);
@@ -1659,7 +1660,9 @@ static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata, lesb = &rsp->rls_lesb;if (lport->tt.get_lesb) {/* get LESB from LLD if it supports it */ - lport->tt.get_lesb (lport, lesb); + err = lport->tt.get_lesb (lport, lesb); +if (err) + goto out_rjt; }else {fc_get_host_stats (lport->host); hst = &lport->host_stats;
include/scsi/fcoe_sysfs.h +6 -6
@@ -16,12 +16,12 @@ struct fcoe_ctlr_device;struct fcoe_fcf_device ;struct fcoe_sysfs_function_template { -void (*get_fcoe_ctlr_link_fail)(struct fcoe_ctlr_device *); -void (*get_fcoe_ctlr_vlink_fail)(struct fcoe_ctlr_device *); -void (*get_fcoe_ctlr_miss_fka)(struct fcoe_ctlr_device *); -void (*get_fcoe_ctlr_symb_err)(struct fcoe_ctlr_device *); -void (*get_fcoe_ctlr_err_block)(struct fcoe_ctlr_device *); -void (*get_fcoe_ctlr_fcs_error)(struct fcoe_ctlr_device *); +int (*get_fcoe_ctlr_link_fail)(struct fcoe_ctlr_device *); +int (*get_fcoe_ctlr_vlink_fail)(struct fcoe_ctlr_device *); +int (*get_fcoe_ctlr_miss_fka)(struct fcoe_ctlr_device *); +int (*get_fcoe_ctlr_symb_err)(struct fcoe_ctlr_device *); +int (*get_fcoe_ctlr_err_block)(struct fcoe_ctlr_device *); +int (*get_fcoe_ctlr_fcs_error)(struct fcoe_ctlr_device *);void (*set_fcoe_ctlr_mode)(struct fcoe_ctlr_device *);int (*set_fcoe_ctlr_enabled)(struct fcoe_ctlr_device *);void (*get_fcoe_fcf_selected)(struct fcoe_fcf_device *);
include/scsi/libfc.h +1 -1
@@ -501,7 +501,7 @@ struct libfc_function_template {* * STATUS: OPTIONAL */ -void (*get_lesb)(struct fc_lport *,struct fc_els_lesb *lesb); +int (*get_lesb)(struct fc_lport *,struct fc_els_lesb *lesb);/* * Reset an exchange manager, completing all sequences and exchanges.
include/scsi/libfcoe.h +4 -4
@@ -255,13 +255,13 @@ int fcoe_libfc_config(struct fc_lport *, struct fcoe_ctlr *,u32 fcoe_fc_crc (struct fc_frame *fp);int fcoe_start_io (struct sk_buff *skb);int fcoe_get_wwn (struct net_device *netdev,u64 *wwn,int type); -void __fcoe_get_lesb (struct fc_lport *lport,struct fc_els_lesb *fc_lesb, -struct net_device *netdev); +int __fcoe_get_lesb (struct fc_lport *lport,struct fc_els_lesb *fc_lesb, +struct net_device *netdev);void fcoe_wwn_to_str (u64 wwn,char *buf,int len);int fcoe_validate_vport_create (struct fc_vport *vport);int fcoe_link_speed_update (struct fc_lport *); -void fcoe_get_lesb (struct fc_lport *,struct fc_els_lesb *); -void fcoe_ctlr_get_lesb (struct fcoe_ctlr_device *ctlr_dev); +int fcoe_get_lesb (struct fc_lport *,struct fc_els_lesb *); +int fcoe_ctlr_get_lesb (struct fcoe_ctlr_device *ctlr_dev);/** * is_fip_mode() - returns true if FIP mode selected.
Signature · 1 line
2.25.1
PATCH v6 10/15 net: openvswitch: propagate errors from dev_get_stats
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The dev_get_stats function can now return an error code, so the code that retrieves vport statistics and sends them through netlink needs to propagate that error code.
Modify the drastic BUG_ON checks to operate only on the -EMSGSIZE error code (the only error code previously possible), and not crash the kernel in case dev_get_stats fails. This is in line with what rtnetlink.c does.
---
Changes in v6:
None.
Changes in v5:
Still keeping the BUG_ON condition except for the output of ovs_vport_get_stats.
Changes in v4:
Patch is new (Eric's suggestion).
net/openvswitch/datapath.c | 25 +++++++++++++++++++------ net/openvswitch/vport.c | 10 ++++++++-- net/openvswitch/vport.h | 2 +- 3 files changed, 28 insertions(+), 9 deletions(-)
net/openvswitch/datapath.c +19 -6
@@ -1987,7 +1987,10 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb, goto nla_put_failure; } -ovs_vport_get_stats (vport, &vport_stats); + err =ovs_vport_get_stats (vport, &vport_stats); +if (err) + goto error; +if (nla_put_64bit (skb,OVS_VPORT_ATTR_STATS ,sizeof (struct ovs_vport_stats ), &vport_stats,OVS_VPORT_ATTR_PAD ))
@@ -2028,7 +2031,9 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net, retval =ovs_vport_cmd_fill_info (vport, skb, net, portid, seq,0 , cmd,GFP_KERNEL ); -BUG_ON (retval <0 ); +BUG_ON (retval == -EMSGSIZE ); +if (retval) +return ERR_PTR (retval);return skb; }
@@ -2173,6 +2178,9 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info) err =ovs_vport_cmd_fill_info (vport, reply,genl_info_net (info), info->snd_portid, info->snd_seq,0 ,OVS_VPORT_CMD_NEW ,GFP_KERNEL ); +BUG_ON (err == -EMSGSIZE ); +if (err) + goto exit_unlock_free; new_headroom =netdev_get_fwd_headroom (vport->dev);
@@ -2181,7 +2189,6 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)else netdev_set_rx_headroom (vport->dev, dp->max_headroom); -BUG_ON (err <0 );ovs_unlock ();ovs_notify (&dp_vport_genl_family, reply, info);
@@ -2234,7 +2241,9 @@ static int ovs_vport_cmd_set(struct sk_buff *skb, struct genl_info *info) err =ovs_vport_cmd_fill_info (vport, reply,genl_info_net (info), info->snd_portid, info->snd_seq,0 ,OVS_VPORT_CMD_SET ,GFP_KERNEL ); -BUG_ON (err <0 ); +BUG_ON (err == -EMSGSIZE ); +if (err) + goto exit_unlock_free;ovs_unlock ();ovs_notify (&dp_vport_genl_family, reply, info);
@@ -2274,7 +2283,9 @@ static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info) err =ovs_vport_cmd_fill_info (vport, reply,genl_info_net (info), info->snd_portid, info->snd_seq,0 ,OVS_VPORT_CMD_DEL ,GFP_KERNEL ); -BUG_ON (err <0 ); +BUG_ON (err == -EMSGSIZE ); +if (err) + goto exit_unlock_free;/* the vport deletion may trigger dp headroom update */ dp = vport->dp;
@@ -2321,7 +2332,9 @@ static int ovs_vport_cmd_get(struct sk_buff *skb, struct genl_info *info) err =ovs_vport_cmd_fill_info (vport, reply,genl_info_net (info), info->snd_portid, info->snd_seq,0 ,OVS_VPORT_CMD_GET ,GFP_ATOMIC ); -BUG_ON (err <0 ); +BUG_ON (err == -EMSGSIZE ); +if (err) + goto exit_unlock_free;rcu_read_unlock ();return genlmsg_reply (reply, info);
net/openvswitch/vport.c +8 -2
@@ -267,11 +267,15 @@ void ovs_vport_del(struct vport *vport)* * Must be called with ovs_mutex or rcu_read_lock. */ -void ovs_vport_get_stats (struct vport *vport,struct ovs_vport_stats *stats) +int ovs_vport_get_stats (struct vport *vport,struct ovs_vport_stats *stats) {struct rtnl_link_stats64 dev_stats; +int err; + + err =dev_get_stats (vport->dev, &dev_stats); +if (err) +return err; -dev_get_stats (vport->dev, &dev_stats); stats->rx_errors = dev_stats.rx_errors; stats->tx_errors = dev_stats.tx_errors; stats->tx_dropped = dev_stats.tx_dropped;
@@ -281,6 +285,8 @@ void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats) stats->rx_packets = dev_stats.rx_packets; stats->tx_bytes = dev_stats.tx_bytes; stats->tx_packets = dev_stats.tx_packets; + +return 0 ; }/**
net/openvswitch/vport.h +1 -1
@@ -30,7 +30,7 @@ void ovs_vport_del(struct vport *);struct vport *ovs_vport_locate (const struct net *net,const char *name); -void ovs_vport_get_stats (struct vport *,struct ovs_vport_stats *); +int ovs_vport_get_stats (struct vport *,struct ovs_vport_stats *);int ovs_vport_set_options (struct vport *,struct nlattr *options);int ovs_vport_get_options (const struct vport *,struct sk_buff *);
Signature · 1 line
2.25.1
PATCH v6 11/15 net: catch errors from dev_get_stats
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
dev_get_stats can now return error codes. Convert all remaining call sites to look at that error code and stop processing.
The effects of simulating a kernel error (returning -ENOMEM) upon existing programs or kernel interfaces:
- ifconfig and "cat /proc/net/dev" print up until the interface that failed, and there they return:
cat: read error: Cannot allocate memory
- ifstat and "ip -s -s link show":
RTNETLINK answers: Cannot allocate memory
Dump terminated
Some call sites are coming from a context that returns void (ethtool stats, workqueue context). So since we can't report to the upper layer, do the next best thing: print an error to the console.
This patch wraps up the conversion of existing dev_get_stats callers, so we can add the __must_check attribute now to ensure that future callers keep doing this too.
---
Changes in v6:
- Fixed rtnetlink incorrectly returning 0 in rtnl_fill_ifinfo on nla_put_failure and causing "ip a" to not show any interfaces.
- Squashed the patch to propagate errors with the one to terminate them.
Changes in v5:
- Actually propagate errors from bonding and net_failover from within this patch.
- Properly propagating the dev_get_stats() error code from rtnl_fill_stats now, and not -EMSGSIZE.
Changes in v4:
Patch is new (Eric's suggestion).
arch/s390/appldata/appldata_net_sum.c | 10 ++++-- drivers/leds/trigger/ledtrig-netdev.c | 9 ++++- drivers/net/bonding/bond_main.c | 29 ++++++++++++---- .../ethernet/apm/xgene/xgene_enet_ethtool.c | 9 +++-- .../net/ethernet/hisilicon/hns/hns_ethtool.c | 7 +++- drivers/net/ethernet/intel/e1000e/ethtool.c | 9 +++-- .../net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 9 +++-- drivers/net/ethernet/intel/ixgbevf/ethtool.c | 9 +++-- drivers/net/net_failover.c | 33 ++++++++++++++----- drivers/parisc/led.c | 7 +++- drivers/usb/gadget/function/rndis.c | 4 ++- include/linux/netdevice.h | 3 +- net/8021q/vlanproc.c | 7 ++-- net/core/dev.c | 3 +- net/core/net-procfs.c | 16 ++++++--- net/core/net-sysfs.c | 4 ++- net/core/rtnetlink.c | 23 +++++++++---- 17 files changed, 147 insertions(+), 44 deletions(-)
arch/s390/appldata/appldata_net_sum.c +8 -2
@@ -58,11 +58,11 @@ struct appldata_net_sum_data {*/ static void appldata_get_net_sum_data (void *data) { -int i;struct appldata_net_sum_data *net_data;struct net_device *dev;unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors, tx_errors, rx_dropped, tx_dropped, collisions; +int ret, i; net_data = data; net_data->sync_count_1++;
@@ -83,7 +83,13 @@ static void appldata_get_net_sum_data(void *data)for_each_netdev (&init_net, dev) {struct rtnl_link_stats64 stats; -dev_get_stats (dev, &stats); + ret =dev_get_stats (dev, &stats); +if (ret) { +netif_lists_unlock (&init_net); +netdev_err (dev,"dev_get_stats returned %d\n" , ret); +return ; + } + rx_packets += stats.rx_packets; tx_packets += stats.tx_packets; rx_bytes += stats.rx_bytes;
drivers/leds/trigger/ledtrig-netdev.c +8 -1
@@ -351,6 +351,7 @@ static void netdev_trig_work(struct work_struct *work)unsigned int new_activity;unsigned long interval;int invert; +int err;/* If we dont have a device, insure we are off */ if (!trigger_data->net_dev) {
@@ -363,7 +364,13 @@ static void netdev_trig_work(struct work_struct *work) !test_bit(NETDEV_LED_RX, &trigger_data->mode)) return; -dev_get_stats (trigger_data->net_dev, &dev_stats); + err =dev_get_stats (trigger_data->net_dev, &dev_stats); +if (err) { +netdev_err (trigger_data->net_dev, +"dev_get_stats returned %d\n" , err); +return ; + } + new_activity = (test_bit (NETDEV_LED_TX , &trigger_data->mode) ? dev_stats.tx_packets : 0) +
drivers/net/bonding/bond_main.c +22 -7
@@ -1757,7 +1757,12 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, slave_dev->priv_flags |=IFF_BONDING ;/* initialize slave stats */ -dev_get_stats (new_slave->dev, &new_slave->slave_stats); + res =dev_get_stats (new_slave->dev, &new_slave->slave_stats); +if (res) { +slave_err (bond_dev, slave_dev,"dev_get_stats returned %d\n" , + res); + goto err_close; + }if (bond_is_lb (bond)) {/* bond_alb_init_slave() must be called before all other stages since
@@ -2070,6 +2075,7 @@ static int __bond_release_one(struct net_device *bond_dev,struct sockaddr_storage ss;int old_flags = bond_dev->flags;netdev_features_t old_features = bond_dev->features; +int err;/* slave is not a slave or master is not master of this slave */ if (!(slave_dev->flags & IFF_SLAVE) ||
@@ -2088,13 +2094,19 @@ static int __bond_release_one(struct net_device *bond_dev,return -EINVAL ; } +/* recompute stats just before removing the slave */ + err =bond_get_stats (bond->dev, &bond->bond_stats); +if (err) { +slave_info (bond_dev, slave_dev,"dev_get_stats returned %d\n" , + err); +unblock_netpoll_tx (); +return err; + } +bond_set_slave_inactive_flags (slave,BOND_SLAVE_NOTIFY_NOW );bond_sysfs_slave_del (slave); -/* recompute stats just before removing the slave */ -bond_get_stats (bond->dev, &bond->bond_stats); -bond_upper_dev_unlink (bond, slave);/* unregister rx_handler early so bond_handle_frame wouldn't be called * for this slave anymore.
@@ -3742,7 +3754,7 @@ static int bond_get_stats(struct net_device *bond_dev,struct list_head *iter;struct slave *slave;int nest_level =0 ; - +int res =0 ;rcu_read_lock ();#ifdef CONFIG_LOCKDEP
@@ -3753,7 +3765,9 @@ static int bond_get_stats(struct net_device *bond_dev,memcpy (stats, &bond->bond_stats,sizeof (*stats));bond_for_each_slave_rcu (bond, slave, iter) { -dev_get_stats (slave->dev, &temp); + res =dev_get_stats (slave->dev, &temp); +if (res) + goto out;bond_fold_stats (stats, &temp, &slave->slave_stats);
@@ -3762,10 +3776,11 @@ static int bond_get_stats(struct net_device *bond_dev, }memcpy (&bond->bond_stats, stats,sizeof (*stats)); +out:spin_unlock (&bond->stats_lock);rcu_read_unlock (); -return 0 ; +return res; }static int bond_do_ioctl (struct net_device *bond_dev,struct ifreq *ifr,int cmd)
drivers/net/ethernet/apm/xgene/xgene_enet_ethtool.c +7 -2
@@ -266,9 +266,14 @@ static void xgene_get_ethtool_stats(struct net_device *ndev, {struct xgene_enet_pdata *pdata =netdev_priv (ndev);struct rtnl_link_stats64 stats; -int i; +int err, i; + + err =dev_get_stats (ndev, &stats); +if (err) { +netdev_err (ndev,"dev_get_stats returned %d\n" , err); +return ; + } -dev_get_stats (ndev, &stats);for (i =0 ; i <XGENE_STATS_LEN ; i++) data[i] = *(u64 *)((char *)&stats + gstrings_stats[i].offset);
drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +6 -1
@@ -840,6 +840,7 @@ static void hns_get_ethtool_stats(struct net_device *netdev,struct hns_nic_priv *priv =netdev_priv (netdev);struct hnae_handle *h = priv->ae_handle;struct rtnl_link_stats64 net_stats; +int err;if (!h->dev->ops->get_stats || !h->dev->ops->update_stats) {netdev_err (netdev,"get_stats or update_stats is null!\n" );
@@ -848,7 +849,11 @@ static void hns_get_ethtool_stats(struct net_device *netdev, h->dev->ops->update_stats (h, &netdev->stats); -dev_get_stats (netdev, &net_stats); + err =dev_get_stats (netdev, &net_stats); +if (err) { +netdev_err (netdev,"dev_get_stats returned %d\n" , err); +return ; + }/* get netdev statistics */ p[0 ] = net_stats.rx_packets;
drivers/net/ethernet/intel/e1000e/ethtool.c +7 -2
@@ -2060,15 +2060,20 @@ static void e1000_get_ethtool_stats(struct net_device *netdev, {struct e1000_adapter *adapter =netdev_priv (netdev);struct rtnl_link_stats64 net_stats; -int i;char *p =NULL ; +int err, i;pm_runtime_get_sync (netdev->dev.parent); -dev_get_stats (netdev, &net_stats); + err =dev_get_stats (netdev, &net_stats);pm_runtime_put_sync (netdev->dev.parent); +if (err) { +netdev_err (netdev,"dev_get_stats returned %d\n" , err); +return ; + } +for (i =0 ; i <E1000_GLOBAL_STATS_LEN ; i++) {switch (e1000_gstrings_stats[i].type) {case NETDEV_STATS :
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +7 -2
@@ -1298,11 +1298,16 @@ static void ixgbe_get_ethtool_stats(struct net_device *netdev,struct rtnl_link_stats64 net_stats;unsigned int start;struct ixgbe_ring *ring; -int i, j;char *p =NULL ; +int err, i, j;ixgbe_update_stats (adapter); -dev_get_stats (netdev, &net_stats); + err =dev_get_stats (netdev, &net_stats); +if (err) { +netdev_err (netdev,"dev_get_stats returned %d\n" , err); +return ; + } +for (i =0 ; i <IXGBE_GLOBAL_STATS_LEN ; i++) {switch (ixgbe_gstrings_stats[i].type) {case NETDEV_STATS :
drivers/net/ethernet/intel/ixgbevf/ethtool.c +7 -2
@@ -423,11 +423,16 @@ static void ixgbevf_get_ethtool_stats(struct net_device *netdev,struct rtnl_link_stats64 net_stats;unsigned int start;struct ixgbevf_ring *ring; -int i, j; +int err, i, j;char *p;ixgbevf_update_stats (adapter); -dev_get_stats (netdev, &net_stats); + err =dev_get_stats (netdev, &net_stats); +if (err) { +netdev_err (netdev,"dev_get_stats returned %d\n" , err); +return ; + } +for (i =0 ; i <IXGBEVF_GLOBAL_STATS_LEN ; i++) {switch (ixgbevf_gstrings_stats[i].type) {case NETDEV_STATS :
drivers/net/net_failover.c +25 -8
@@ -185,6 +185,7 @@ static int net_failover_get_stats(struct net_device *dev,struct net_failover_info *nfo_info =netdev_priv (dev);struct rtnl_link_stats64 temp;struct net_device *slave_dev; +int err =0 ;spin_lock (&nfo_info->stats_lock);memcpy (stats, &nfo_info->failover_stats,sizeof (*stats));
@@ -193,24 +194,29 @@ static int net_failover_get_stats(struct net_device *dev, slave_dev =rcu_dereference (nfo_info->primary_dev);if (slave_dev) { -dev_get_stats (slave_dev, &temp); + err =dev_get_stats (slave_dev, &temp); +if (err) + goto out;net_failover_fold_stats (stats, &temp, &nfo_info->primary_stats);memcpy (&nfo_info->primary_stats, &temp,sizeof (temp)); } slave_dev =rcu_dereference (nfo_info->standby_dev);if (slave_dev) { -dev_get_stats (slave_dev, &temp); + err =dev_get_stats (slave_dev, &temp); +if (err) + goto out;net_failover_fold_stats (stats, &temp, &nfo_info->standby_stats);memcpy (&nfo_info->standby_stats, &temp,sizeof (temp)); } +out:rcu_read_unlock ();memcpy (&nfo_info->failover_stats, stats,sizeof (*stats));spin_unlock (&nfo_info->stats_lock); -return 0 ; +return err; }static int net_failover_change_mtu (struct net_device *dev,int new_mtu)
@@ -545,11 +551,15 @@ static int net_failover_slave_register(struct net_device *slave_dev,if (slave_is_standby) {rcu_assign_pointer (nfo_info->standby_dev, slave_dev); standby_dev = slave_dev; -dev_get_stats (standby_dev, &nfo_info->standby_stats); + err =dev_get_stats (standby_dev, &nfo_info->standby_stats); +if (err) + goto err_stats_get; }else {rcu_assign_pointer (nfo_info->primary_dev, slave_dev); primary_dev = slave_dev; -dev_get_stats (primary_dev, &nfo_info->primary_stats); + err =dev_get_stats (primary_dev, &nfo_info->primary_stats); +if (err) + goto err_stats_get; failover_dev->min_mtu = slave_dev->min_mtu; failover_dev->max_mtu = slave_dev->max_mtu; }
@@ -564,6 +574,8 @@ static int net_failover_slave_register(struct net_device *slave_dev,return 0 ; +err_stats_get: +vlan_vids_del_by_dev (slave_dev, failover_dev); err_vlan_add:dev_uc_unsync (slave_dev, failover_dev);dev_mc_unsync (slave_dev, failover_dev);
@@ -597,6 +609,7 @@ static int net_failover_slave_unregister(struct net_device *slave_dev,struct net_device *standby_dev, *primary_dev;struct net_failover_info *nfo_info;bool slave_is_standby; +int err; nfo_info =netdev_priv (failover_dev); primary_dev =rtnl_dereference (nfo_info->primary_dev);
@@ -611,7 +624,8 @@ static int net_failover_slave_unregister(struct net_device *slave_dev,dev_close (slave_dev); nfo_info =netdev_priv (failover_dev); -dev_get_stats (failover_dev, &nfo_info->failover_stats); +/* Proceed with the deregistration anyway */ + err =dev_get_stats (failover_dev, &nfo_info->failover_stats); slave_is_standby = slave_dev->dev.parent == failover_dev->dev.parent;if (slave_is_standby) {
@@ -631,7 +645,7 @@ static int net_failover_slave_unregister(struct net_device *slave_dev,netdev_info (failover_dev,"failover %s slave:%s unregistered\n" , slave_is_standby ?"standby" :"primary" , slave_dev->name); -return 0 ; +return err; } static int net_failover_slave_link_change(struct net_device *slave_dev,
@@ -639,6 +653,7 @@ static int net_failover_slave_link_change(struct net_device *slave_dev, {struct net_device *primary_dev, *standby_dev;struct net_failover_info *nfo_info; +int err; nfo_info =netdev_priv (failover_dev);
@@ -653,7 +668,9 @@ static int net_failover_slave_link_change(struct net_device *slave_dev,netif_carrier_on (failover_dev);netif_tx_wake_all_queues (failover_dev); }else { -dev_get_stats (failover_dev, &nfo_info->failover_stats); + err =dev_get_stats (failover_dev, &nfo_info->failover_stats); +if (err) +return err;netif_carrier_off (failover_dev);netif_tx_stop_all_queues (failover_dev); }
drivers/parisc/led.c +6 -1
@@ -370,7 +370,12 @@ static __inline__ int led_get_net_activity(void)in_dev_put (in_dev); -dev_get_stats (dev, &stats); + retval =dev_get_stats (dev, &stats); +if (retval) { +netif_lists_unlock (&init_net); +return retval; + } + rx_total += stats.rx_packets; tx_total += stats.tx_packets; }
drivers/usb/gadget/function/rndis.c +3 -1
@@ -198,7 +198,9 @@ static int gen_ndis_query_resp(struct rndis_params *params, u32 OID, u8 *buf, resp->InformationBufferOffset =cpu_to_le32 (16 ); net = params->dev; -dev_get_stats (net, &stats); + retval =dev_get_stats (net, &stats); +if (retval) +return retval;switch (OID ) {
include/linux/netdevice.h +2 -1
@@ -4545,7 +4545,8 @@ void netdev_notify_peers(struct net_device *dev);void netdev_features_change (struct net_device *dev);/* Load a device via the kmod */ void dev_load (struct net *net,const char *name); -int dev_get_stats (struct net_device *dev,struct rtnl_link_stats64 *storage); +int __must_check dev_get_stats (struct net_device *dev, +struct rtnl_link_stats64 *storage);void netdev_stats_to_stats64 (struct rtnl_link_stats64 *stats64,const struct net_device_stats *netdev_stats); void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s,
net/8021q/vlanproc.c +5 -2
@@ -244,12 +244,15 @@ static int vlandev_seq_show(struct seq_file *seq, void *offset)const struct vlan_dev_priv *vlan =vlan_dev_priv (vlandev);static const char fmt64[] ="%30s %12llu\n" ;struct rtnl_link_stats64 stats; -int i; +int err, i;if (!is_vlan_dev (vlandev))return 0 ; -dev_get_stats (vlandev, &stats); + err =dev_get_stats (vlandev, &stats); +if (err) +return err; + seq_printf(seq, "%s VID: %d REORDER_HDR: %i dev->priv_flags: %hx\n", vlandev->name, vlan->vlan_id,
net/core/dev.c +2 -1
@@ -10403,7 +10403,8 @@ EXPORT_SYMBOL(netdev_stats_to_stats64);* dev->netdev_ops->get_stats64 or dev->netdev_ops->get_stats; * otherwise the internal statistics structure is used. */ -int dev_get_stats (struct net_device *dev,struct rtnl_link_stats64 *storage) +int __must_check dev_get_stats (struct net_device *dev, +struct rtnl_link_stats64 *storage) {const struct net_device_ops *ops = dev->netdev_ops;int err =0 ;
net/core/net-procfs.c +12 -4
@@ -78,11 +78,14 @@ static void dev_seq_stop(struct seq_file *seq, void *v)netif_lists_unlock (net); } -static void dev_seq_printf_stats (struct seq_file *seq,struct net_device *dev) +static int dev_seq_printf_stats (struct seq_file *seq,struct net_device *dev) {struct rtnl_link_stats64 stats; +int err; -dev_get_stats (dev, &stats); + err =dev_get_stats (dev, &stats); +if (err) +return err; seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu " "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
@@ -101,6 +104,8 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev) stats.tx_window_errors + stats.tx_heartbeat_errors, stats.tx_compressed); + +return 0 ; }/*
@@ -109,6 +114,8 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)*/ static int dev_seq_show (struct seq_file *seq,void *v) { +int err =0 ; +if (v ==SEQ_START_TOKEN )seq_puts (seq,"Inter-| Receive " " | Transmit\n"
@@ -116,8 +123,9 @@ static int dev_seq_show(struct seq_file *seq, void *v)"compressed multicast|bytes packets errs " "drop fifo colls carrier compressed\n"); else -dev_seq_printf_stats (seq ,v ); -return 0 ; + err =dev_seq_printf_stats (seq, v); + +return err; }static u32 softnet_backlog_len (struct softnet_data *sd)
net/core/net-sysfs.c +3 -1
@@ -588,7 +588,9 @@ static ssize_t netstat_show(const struct device *d,if (dev_isalive (dev)) {struct rtnl_link_stats64 stats; -dev_get_stats (dev, &stats); + ret =dev_get_stats (dev, &stats); +if (ret) +return ret; ret =sprintf (buf, fmt_u64, *(u64 *)(((u8 *)&stats) + offset)); }
net/core/rtnetlink.c +17 -6
@@ -1201,6 +1201,7 @@ static noinline_for_stack int rtnl_fill_stats(struct sk_buff *skb, {struct rtnl_link_stats64 *sp;struct nlattr *attr; +int err; attr =nla_reserve_64bit (skb,IFLA_STATS64 ,sizeof (struct rtnl_link_stats64 ),IFLA_PAD );
@@ -1208,7 +1209,9 @@ static noinline_for_stack int rtnl_fill_stats(struct sk_buff *skb,return -EMSGSIZE ; sp =nla_data (attr); -dev_get_stats (dev, sp); + err =dev_get_stats (dev, sp); +if (err) +return err; attr =nla_reserve (skb,IFLA_STATS ,sizeof (struct rtnl_link_stats ));
@@ -1707,6 +1710,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, {struct ifinfomsg *ifm;struct nlmsghdr *nlh; +int err;ASSERT_RTNL (); nlh =nlmsg_put (skb, pid, seq, type,sizeof (*ifm), flags);
@@ -1780,8 +1784,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,if (rtnl_phys_switch_id_fill (skb, dev)) goto nla_put_failure; -if (rtnl_fill_stats (skb, dev)) - goto nla_put_failure; + err =rtnl_fill_stats (skb, dev); +if (err) + goto get_stats_failure;if (rtnl_fill_vf (skb, dev, ext_filter_mask)) goto nla_put_failure;
@@ -1825,8 +1830,10 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, nla_put_failure_rcu:rcu_read_unlock (); nla_put_failure: + err = -EMSGSIZE ; +get_stats_failure:nlmsg_cancel (skb, nlh); -return -EMSGSIZE ; +return err; }static const struct nla_policy ifla_policy[IFLA_MAX +1 ] = {
@@ -5135,7 +5142,9 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev, goto nla_put_failure; sp =nla_data (attr); -dev_get_stats (dev, sp); + err =dev_get_stats (dev, sp); +if (err) + goto get_stats_failure; }if (stats_attr_valid (filter_mask,IFLA_STATS_LINK_XSTATS , *idxattr)) {
@@ -5242,13 +5251,15 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,return 0 ; nla_put_failure: + err = -EMSGSIZE ; +get_stats_failure:/* not a multi message or no progress mean a real error */ if (!(flags &NLM_F_MULTI ) || s_prividx == *prividx)nlmsg_cancel (skb, nlh);else nlmsg_end (skb, nlh); -return -EMSGSIZE ; +return err; } static size_t if_nlmsg_stats_size(const struct net_device *dev,
Signature · 1 line
2.25.1
Re: [PATCH v6 net-next 11/15] net: catch errors from dev_get_stats
Quoted 12 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
dev_get_statscan now return error codes. Convert all remaining call sites to look at that error code and stop processing.The effects of simulating a kernel error (returning
-ENOMEM) upon existing programs or kernel interfaces:- ifconfig and "cat
/proc/net/dev" print up until the interface that failed, and there they return:
cat: read error: Cannot allocate memory
Quoted 9 lines
- ifstat and "ip -s -s link show":
RTNETLINK answers: Cannot allocate memory
Dump terminatedSome call sites are coming from a context that returns void (ethtool stats, workqueue context). So since we can't report to the upper layer,
do the next best thing: print an error to the console.
another concern, one buggy netdev driver in a system will cause unnecessary global failures when reading stats via netlink/procfs for all the netdev in a netns, when other drivers will be happy to report.
can't we just show a message in that driver's stats line about the occurred err ? and show the normal stats line of all others ?
Quoted 7 lines
This patch wraps up the conversion of existing
dev_get_statscallers, so
we can add the__must_checkattribute now to ensure that future callers
keep doing this too.
Re: [PATCH v6 net-next 11/15] net: catch errors from dev_get_stats
Quoted 23 lines · Saeed Mahameed
Quoted 12 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
dev_get_statscan now return error codes. Convert all remaining call sites to look at that error code and stop processing.The effects of simulating a kernel error (returning
-ENOMEM) upon existing programs or kernel interfaces:- ifconfig and "cat
/proc/net/dev" print up until the interface that failed, and there they return:
cat: read error: Cannot allocate memoryQuoted 9 lines
- ifstat and "ip -s -s link show":
RTNETLINK answers: Cannot allocate memory
Dump terminatedSome call sites are coming from a context that returns void (ethtool stats, workqueue context). So since we can't report to the upper layer,
do the next best thing: print an error to the console.
Quoted 6 lines
another concern, one buggy netdev driver in a system will cause unnecessary global failures when reading stats via netlink/procfs for all the netdev in a netns, when other drivers will be happy to report.
can't we just show a message in that driver's stats line about the occurred err ? and show the normal stats line of all others ?
So you're worried that user space apps won't handle an error code when reading from a file, but you're not worried that they'll start scraping junk from procfs when we print this?
cat /proc/net/dev
Inter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
bond0: Cannot allocate memory
sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Re: [PATCH v6 net-next 11/15] net: catch errors from dev_get_stats
Quoted 33 lines · Vladimir Oltean
Quoted 32 lines · Saeed Mahameed
Quoted 18 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
dev_get_statscan now return error codes. Convert all remaining call
sites to look at that error code and stop processing.The effects of simulating a kernel error (returning
-ENOMEM) upon existing programs or kernel interfaces:- ifconfig and "cat
/proc/net/dev" print up until the interface that
failed, and there they return:
cat: read error: Cannot allocate memory- ifstat and "ip -s -s link show":
RTNETLINK answers: Cannot allocate memory
Dump terminatedQuoted 6 lines
Some call sites are coming from a context that returns void (ethtool
stats, workqueue context). So since we can't report to the upper layer,
do the next best thing: print an error to the console.another concern, one buggy netdev driver in a system will cause unnecessary global failures when reading stats via netlink/procfs for
all the netdev in a netns, when other drivers will be happy to report.
Quoted 9 lines
Quoted 2 lines
can't we just show a message in that driver's stats line about the occurred err ? and show the normal stats line of all others ?
So you're worried that user space apps won't handle an error code when
reading from a file, but you're not worried that they'll start scraping
junk from procfs when we print this?
both are equivalently concerning.
to avoid any user crashes, we can just toss failed netdevs out from the output.
Quoted 12 lines
cat
/proc/net/dev
Inter-
| Receive | Transmi
t
face |bytes packets errs drop fifo frame compressed
multicast|bytes packets errs drop fifo colls carrier compressedlo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0bond0: Cannot allocate memory
sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Re: [PATCH v6 net-next 11/15] net: catch errors from dev_get_stats
Quoted 32 lines · Saeed Mahameed
Quoted 31 lines · Vladimir Oltean
Quoted 29 lines · Saeed Mahameed
Quoted 12 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
dev_get_statscan now return error codes. Convert all remaining call sites to look at that error code and stop processing.The effects of simulating a kernel error (returning
-ENOMEM) upon existing programs or kernel interfaces:- ifconfig and "cat
/proc/net/dev" print up until the interface that failed, and there they return:
cat: read error: Cannot allocate memoryQuoted 8 lines
- ifstat and "ip -s -s link show":
RTNETLINK answers: Cannot allocate memory
Dump terminatedSome call sites are coming from a context that returns void (ethtool stats, workqueue context). So since we can't report to the upper layer, do the next best thing: print an error to the console.
another concern, one buggy netdev driver in a system will cause unnecessary global failures when reading stats via netlink/procfs for all the netdev in a netns, when other drivers will be happy to report.
can't we just show a message in that driver's stats line about the occurred err ? and show the normal stats line of all others ?
Quoted 7 lines
Quoted 3 lines
So you're worried that user space apps won't handle an error code when reading from a file, but you're not worried that they'll start scraping junk from procfs when we print this?
both are equivalently concerning.
to avoid any user crashes, we can just toss failed netdevs out from the output.
I'm not sure I'm on the same page here, basically I churned through the whole kernel to propagate the error code from dev_get_stats, just to not report it anywhere?
PATCH v6 12/15 net: openvswitch: ensure dev_get_stats can sleep
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
There is an effort to convert .ndo_get_stats64 to sleepable context, and for that to work, we need to prevent callers of dev_get_stats from using atomic locking.
The OVS vport driver calls ovs_vport_get_stats from ovs_vport_cmd_fill_info, a function with 7 callers: 5 under ovs_lock() and 2 under rcu_read_lock(). The RCU-protected callers are the doit and dumpit callbacks of the OVS_VPORT_CMD_GET genetlink event. Things have been this way ever since the OVS introduction in commit ccb1352e76cf ("net: Add Open vSwitch kernel components."), probably so that OVS_PORT_CMD_GET doesn't have to serialize with all the others through ovs_mutex. Sadly, now they do have to, otherwise we don't have protection while accessing the datapath and vport structures.
Convert all callers of ovs_vport_cmd_fill_info to assume ovs_mutex protection. This means that we can get rid of the gfp argument, since all callers are now sleepable, we can just use GFP_KERNEL for memory allocation.
---
Changes in v6:
None.
Changes in v5:
None.
Changes in v4:
Patch is new.
net/openvswitch/datapath.c | 38 ++++++++++++++++++-------------------- net/openvswitch/vport.c | 2 +- 2 files changed, 19 insertions(+), 21 deletions(-)
net/openvswitch/datapath.c +18 -20
@@ -1957,10 +1957,10 @@ static struct genl_family dp_datapath_genl_family __ro_after_init = { .module = THIS_MODULE, }; -/* Called with ovs_mutex or RCU read lock. */ +/* Called with ovs_mutex */ static int ovs_vport_cmd_fill_info (struct vport *vport,struct sk_buff *skb,struct net *net,u32 portid,u32 seq, -u32 flags,u8 cmd,gfp_t gfp) +u32 flags,u8 cmd) {struct ovs_header *ovs_header;struct ovs_vport_stats vport_stats;
@@ -1981,7 +1981,7 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb, goto nla_put_failure;if (!net_eq (net,dev_net (vport->dev))) { -int id =peernet2id_alloc (net,dev_net (vport->dev), gfp); +int id =peernet2id_alloc (net,dev_net (vport->dev),GFP_KERNEL );if (nla_put_s32 (skb,OVS_VPORT_ATTR_NETNSID , id)) goto nla_put_failure;
@@ -2029,8 +2029,7 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net,if (!skb)return ERR_PTR (-ENOMEM ); - retval =ovs_vport_cmd_fill_info (vport, skb, net, portid, seq,0 , cmd, -GFP_KERNEL ); + retval =ovs_vport_cmd_fill_info (vport, skb, net, portid, seq,0 , cmd);BUG_ON (retval == -EMSGSIZE );if (retval)return ERR_PTR (retval);
@@ -2038,7 +2037,7 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net,return skb; } -/* Called with ovs_mutex or RCU read lock. */ +/* Called with ovs_mutex */ static struct vport *lookup_vport (struct net *net,const struct ovs_header *ovs_header,struct nlattr *a[OVS_VPORT_ATTR_MAX +1 ])
@@ -2177,7 +2176,7 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info) err =ovs_vport_cmd_fill_info (vport, reply,genl_info_net (info), info->snd_portid, info->snd_seq,0 , -OVS_VPORT_CMD_NEW ,GFP_KERNEL ); +OVS_VPORT_CMD_NEW );BUG_ON (err == -EMSGSIZE );if (err) goto exit_unlock_free;
@@ -2240,7 +2239,7 @@ static int ovs_vport_cmd_set(struct sk_buff *skb, struct genl_info *info) err =ovs_vport_cmd_fill_info (vport, reply,genl_info_net (info), info->snd_portid, info->snd_seq,0 , -OVS_VPORT_CMD_SET ,GFP_KERNEL ); +OVS_VPORT_CMD_SET );BUG_ON (err == -EMSGSIZE );if (err) goto exit_unlock_free;
@@ -2282,7 +2281,7 @@ static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info) err =ovs_vport_cmd_fill_info (vport, reply,genl_info_net (info), info->snd_portid, info->snd_seq,0 , -OVS_VPORT_CMD_DEL ,GFP_KERNEL ); +OVS_VPORT_CMD_DEL );BUG_ON (err == -EMSGSIZE );if (err) goto exit_unlock_free;
@@ -2324,23 +2323,23 @@ static int ovs_vport_cmd_get(struct sk_buff *skb, struct genl_info *info)if (!reply)return -ENOMEM ; -rcu_read_lock (); +ovs_lock (); vport =lookup_vport (sock_net (skb->sk), ovs_header, a); err =PTR_ERR (vport);if (IS_ERR (vport)) goto exit_unlock_free; err =ovs_vport_cmd_fill_info (vport, reply,genl_info_net (info), info->snd_portid, info->snd_seq,0 , -OVS_VPORT_CMD_GET ,GFP_ATOMIC ); +OVS_VPORT_CMD_GET );BUG_ON (err == -EMSGSIZE );if (err) goto exit_unlock_free; -rcu_read_unlock (); +ovs_unlock ();return genlmsg_reply (reply, info); exit_unlock_free: -rcu_read_unlock (); +ovs_unlock ();kfree_skb (reply);return err; }
@@ -2352,25 +2351,24 @@ static int ovs_vport_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)int bucket = cb->args[0 ], skip = cb->args[1 ];int i, j =0 ; -rcu_read_lock (); - dp =get_dp_rcu (sock_net (skb->sk), ovs_header->dp_ifindex); +ovs_lock (); + dp =get_dp (sock_net (skb->sk), ovs_header->dp_ifindex);if (!dp) { -rcu_read_unlock (); +ovs_unlock ();return -ENODEV ; }for (i = bucket; i <DP_VPORT_HASH_BUCKETS ; i++) {struct vport *vport; j =0 ; -hlist_for_each_entry_rcu (vport, &dp->ports[i], dp_hash_node) { +hlist_for_each_entry (vport, &dp->ports[i], dp_hash_node) {if (j >= skip &&ovs_vport_cmd_fill_info (vport, skb,sock_net (skb->sk),NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq,NLM_F_MULTI , -OVS_VPORT_CMD_GET , -GFP_ATOMIC ) <0 ) +OVS_VPORT_CMD_GET ) <0 ) goto out; j++;
@@ -2378,7 +2376,7 @@ static int ovs_vport_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb) skip =0 ; } out: -rcu_read_unlock (); +ovs_unlock (); cb->args[0 ] = i; cb->args[1 ] = j;
net/openvswitch/vport.c +1 -1
@@ -265,7 +265,7 @@ void ovs_vport_del(struct vport *vport)* * Retrieves transmit, receive, and error stats for the given device. * -* Must be called with ovs_mutex or rcu_read_lock. +* Must be called with ovs_mutex. */ int ovs_vport_get_stats (struct vport *vport,struct ovs_vport_stats *stats) {
Signature · 1 line
2.25.1
PATCH v6 13/15 net: net_failover: ensure .ndo_get_stats64 can sleep
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The failover framework sets up a virtio_net interface [ when it has the VIRTIO_NET_F_STANDBY feature ] and a VF interface, having the same MAC address, in a standby/active relationship. When the active VF is unplugged, the standby virtio_net temporarily kicks in.
The failover framework registers a common upper for the active and the standby interface, which is what the application layer uses. This is similar to bonding/team. The statistics of the upper interface are the sum of the statistics of the active and of the standby interface.
There is an effort to convert .ndo_get_stats64 to sleepable context, and for that to work, we need to prevent callers of dev_get_stats from using atomic locking. The failover driver needs protection via an RCU read-side critical section to access the standby and the active interface. This is ok because it is reentrant, and generally speaking, dev_get_stats is recursive. But it is also not ok, because holding rcu_read_lock() while calling dev_get_stats will incur atomic context upon it, and that needs to change.
The existing logic can be rehashed just a little bit such that the recursive dev_get_stats call will not be under any lock. We can achieve that by "cheating" a little bit and use dev_hold() to take a reference on the active and backup interfaces, and netdev_wait_allrefs() will just have to wait until dev_get_stats() finishes.
---
Changes in v6:
Slightly touch up the commit message.
Changes in v5:
Use rcu_read_lock() and do not change the locking architecture of the driver.
Changes in v4:
Now there is code to propagate errors.
Changes in v3:
None.
Changes in v2:
Switched to the new scheme of holding just a refcnt to the slave interfaces while recursing with dev_get_stats.
drivers/net/net_failover.c | 64 ++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 17 deletions(-)
drivers/net/net_failover.c +47 -17
@@ -183,38 +183,64 @@ static int net_failover_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats) {struct net_failover_info *nfo_info =netdev_priv (dev); -struct rtnl_link_stats64 temp; -struct net_device *slave_dev; +struct rtnl_link_stats64 primary_stats; +struct rtnl_link_stats64 standby_stats; +struct net_device *primary_dev; +struct net_device *standby_dev;int err =0 ; -spin_lock (&nfo_info->stats_lock); -memcpy (stats, &nfo_info->failover_stats,sizeof (*stats)); -rcu_read_lock (); - slave_dev =rcu_dereference (nfo_info->primary_dev); -if (slave_dev) { - err =dev_get_stats (slave_dev, &temp); + primary_dev =rcu_dereference (nfo_info->primary_dev); +if (primary_dev) +dev_hold (primary_dev); + + standby_dev =rcu_dereference (nfo_info->standby_dev); +if (standby_dev) +dev_hold (standby_dev); + +rcu_read_unlock (); + +/* Don't hold rcu_read_lock while calling dev_get_stats, just a +* reference to ensure they won't get unregistered. +*/ +if (primary_dev) { + err =dev_get_stats (primary_dev, &primary_stats);if (err) goto out; -net_failover_fold_stats (stats, &temp, &nfo_info->primary_stats); -memcpy (&nfo_info->primary_stats, &temp,sizeof (temp)); } - slave_dev =rcu_dereference (nfo_info->standby_dev); -if (slave_dev) { - err =dev_get_stats (slave_dev, &temp); +if (standby_dev) { + err =dev_get_stats (standby_dev, &standby_stats);if (err) goto out; -net_failover_fold_stats (stats, &temp, &nfo_info->standby_stats); -memcpy (&nfo_info->standby_stats, &temp,sizeof (temp)); } -out: -rcu_read_unlock (); +spin_lock (&nfo_info->stats_lock); + +memcpy (stats, &nfo_info->failover_stats,sizeof (*stats)); + +if (primary_dev) { +net_failover_fold_stats (stats, &primary_stats, + &nfo_info->primary_stats); +memcpy (&nfo_info->primary_stats, &primary_stats, +sizeof (primary_stats)); + } +if (standby_dev) { +net_failover_fold_stats (stats, &standby_stats, + &nfo_info->standby_stats); +memcpy (&nfo_info->standby_stats, &standby_stats, +sizeof (standby_stats)); + }memcpy (&nfo_info->failover_stats, stats,sizeof (*stats)); +spin_unlock (&nfo_info->stats_lock); +out: +if (primary_dev) +dev_put (primary_dev); +if (standby_dev) +dev_put (standby_dev);return err; }
@@ -728,6 +754,7 @@ static struct failover_ops net_failover_ops = {struct failover *net_failover_create (struct net_device *standby_dev) {struct device *dev = standby_dev->dev.parent; +struct net_failover_info *nfo_info;struct net_device *failover_dev;struct failover *failover;int err;
@@ -772,6 +799,9 @@ struct failover *net_failover_create(struct net_device *standby_dev) failover_dev->min_mtu = standby_dev->min_mtu; failover_dev->max_mtu = standby_dev->max_mtu; + nfo_info =netdev_priv (failover_dev); +spin_lock_init (&nfo_info->stats_lock); + err =register_netdev (failover_dev);if (err) {dev_err (dev,"Unable to register failover_dev!\n" );
Signature · 1 line
2.25.1
PATCH v6 14/15 net: bonding: ensure .ndo_get_stats64 can sleep
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
There is an effort to convert .ndo_get_stats64 to sleepable context, and for that to work, we need to prevent callers of dev_get_stats from using atomic locking.
The bonding driver retrieves its statistics recursively from its lower interfaces, with additional care to only count packets sent/received while those lowers were actually enslaved to the bond - see commit 5f0c5f73e5ef ("bonding: make global bonding stats more reliable").
Since commit 87163ef9cda7 ("bonding: remove last users of bond->lock and bond->lock itself"), the bonding driver uses the following protection for its array of slaves: RCU for readers and rtnl_mutex for updaters.
The aforementioned commit removed an interesting comment:
/* [...] we can't hold bond->lock [...] because we'll
* deadlock. The only solution is to rely on the fact
* that we're under rtnl_lock here, and the slaves
* list won't change. This doesn't solve the problem
* of setting the slave's MTU while it is
* transmitting, but the assumption is that the base
* driver can handle that.
*
* TODO: figure out a way to safely iterate the slaves
* list, but without holding a lock around the actual
* call to the base driver.
*/
The above summarizes pretty well the challenges we have with nested bonding interfaces (bond over bond over bond over...) and locking for their slaves.
To solve the nesting problem, the simple way is to not hold any locks when recursing into the slave netdev operation. We can "cheat" and use dev_hold to take a reference on the slave net_device, which is enough to ensure that netdev_wait_allrefs() waits until we finish, and the kernel won't fault.
However, the slave structure might no longer be valid, just its associated net_device. So we need to do some more work to ensure that the slave exists after we took the statistics, and if it still does, reapply the logic from Andy's commit 5f0c5f73e5ef.
Tested using the following two scripts running in parallel:
#!/bin/bash while :; do ip link del bond0 ip link del bond1 ip link add bond0 type bond mode 802.3ad ip link add bond1 type bond mode 802.3ad ip link set sw0p1 down && ip link set sw0p1 master bond0 && ip link set sw0p1 up ip link set sw0p2 down && ip link set sw0p2 master bond0 && ip link set sw0p2 up ip link set sw0p3 down && ip link set sw0p3 master bond0 && ip link set sw0p3 up ip link set bond0 down && ip link set bond0 master bond1 && ip link set bond0 up ip link set sw1p1 down && ip link set sw1p1 master bond1 && ip link set sw1p1 up ip link set bond1 up ip -s -s link show cat /sys/class/net/bond1/statistics/* done #!/bin/bash while :; do echo spi2.0 > /sys/bus/spi/drivers/sja1105/unbind echo spi2.0 > /sys/bus/spi/drivers/sja1105/bind sleep 30 done
where the sja1105 driver was explicitly modified for the purpose of this test to have a msleep(500) in its .ndo_get_stats64 method, to catch some more potential races.
---
Changes in v6:
s/break/return -ENOMEM/ in bond_get_slaves.
Changes in v5:
- Use rcu_read_lock() and do not change the locking architecture of the driver.
- Gave some details on my testing procedure.
Changes in v4:
Now there is code to propagate errors.
Changes in v3:
- Added kfree(dev_stats);
- Removed the now useless stats_lock (bond->bond_stats and slave->slave_stats are now protected by bond->slaves_lock)
Changes in v2:
Switched to the new scheme of holding just a refcnt to the slave interfaces while recursing with dev_get_stats.
drivers/net/bonding/bond_main.c | 113 +++++++++++++++----------------- include/net/bonding.h | 53 +++++++++++++++ 2 files changed, 107 insertions(+), 59 deletions(-)
drivers/net/bonding/bond_main.c +54 -59
@@ -3705,80 +3705,75 @@ static void bond_fold_stats(struct rtnl_link_stats64 *_res, } } -#ifdef CONFIG_LOCKDEP -static int bond_get_lowest_level_rcu (struct net_device *dev) -{ -struct net_device *ldev, *next, *now, *dev_stack[MAX_NEST_DEV +1 ]; -struct list_head *niter, *iter, *iter_stack[MAX_NEST_DEV +1 ]; -int cur =0 , max =0 ; - - now = dev; - iter = &dev->adj_list.lower; - -while (1 ) { - next =NULL ; -while (1 ) { - ldev =netdev_next_lower_dev_rcu (now, &iter); -if (!ldev) -break ; - - next = ldev; - niter = &ldev->adj_list.lower; - dev_stack[cur] = now; - iter_stack[cur++] = iter; -if (max <= cur) - max = cur; -break ; - } - -if (!next) { -if (!cur) -return max; - next = dev_stack[--cur]; - niter = iter_stack[cur]; - } - - now = next; - iter = niter; - } - -return max; -} -#endif -static int bond_get_stats (struct net_device *bond_dev,struct rtnl_link_stats64 *stats) {struct bonding *bond =netdev_priv (bond_dev); -struct rtnl_link_stats64 temp; -struct list_head *iter; -struct slave *slave; -int nest_level =0 ; -int res =0 ; +struct rtnl_link_stats64 *dev_stats; +struct bonding_slave_dev *s; +struct list_head slaves; +int res, num_slaves; +int i =0 ; -rcu_read_lock (); -#ifdef CONFIG_LOCKDEP - nest_level =bond_get_lowest_level_rcu (bond_dev); -#endif + res =bond_get_slaves (bond, &slaves, &num_slaves); +if (res) +return res; -spin_lock_nested (&bond->stats_lock, nest_level); -memcpy (stats, &bond->bond_stats,sizeof (*stats)); + dev_stats =kcalloc (num_slaves,sizeof (*dev_stats),GFP_KERNEL ); +if (!dev_stats) { +bond_put_slaves (&slaves); +return -ENOMEM ; + } -bond_for_each_slave_rcu (bond, slave, iter) { - res =dev_get_stats (slave->dev, &temp); +/* Recurse with no locks taken */ +list_for_each_entry (s, &slaves, list) { + res =dev_get_stats (s->ndev, &dev_stats[i]);if (res) goto out; + i++; + } + +spin_lock (&bond->stats_lock); + +memcpy (stats, &bond->bond_stats,sizeof (*stats)); + +/* Because we released the RCU lock in bond_get_slaves, the new slave +* array might be different from the original one, so we need to take +* it again and only update the stats of the slaves that still exist. +*/ +rcu_read_lock (); + + i =0 ; + +list_for_each_entry (s, &slaves, list) { +struct list_head *iter; +struct slave *slave; -bond_fold_stats (stats, &temp, &slave->slave_stats); +bond_for_each_slave_rcu (bond, slave, iter) { +if (slave->dev != s->ndev) +continue ; -/* save off the slave stats for the next run */ -memcpy (&slave->slave_stats, &temp,sizeof (temp)); +bond_fold_stats (stats, &dev_stats[i], + &slave->slave_stats); + +/* save off the slave stats for the next run */ +memcpy (&slave->slave_stats, &dev_stats[i], +sizeof (dev_stats[i])); +break ; + } + + i++; } +rcu_read_unlock (); +memcpy (&bond->bond_stats, stats,sizeof (*stats)); -out: +spin_unlock (&bond->stats_lock); -rcu_read_unlock (); + +out: +kfree (dev_stats); +bond_put_slaves (&slaves);return res; }
include/net/bonding.h +53 -0
59 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v6 net-next 14/15] net: bonding: ensure .ndo_get_stats64 can sleep
Quoted 93 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
There is an effort to convert .ndo_get_stats64 to sleepable context, and
for that to work, we need to prevent callers ofdev_get_statsfrom using
atomic locking.The bonding driver retrieves its statistics recursively from its lower
interfaces, with additional care to only count packets sent/received while those lowers were actually enslaved to the bond - see commit5f0c5f73e5ef("bonding: make global bonding stats more reliable").Since commit
87163ef9cda7("bonding: remove last users ofbond->lockandbond->lockitself"), the bonding driver uses the following protection for its array of slaves: RCU for readers andrtnl_mutexfor updaters.The aforementioned commit removed an interesting comment:
/* [...] we can't hold
bond->lock[...] because we'll
* deadlock. The only solution is to rely on the fact
* that we're underrtnl_lockhere, and the slaves
* list won't change. This doesn't solve the problem
* of setting the slave's MTU while it is
* transmitting, but the assumption is that the base
* driver can handle that.
*
* TODO: figure out a way to safely iterate the slaves
* list, but without holding a lock around the actual
* call to the base driver.
*/The above summarizes pretty well the challenges we have with nested bonding interfaces (bond over bond over bond over...) and locking for their slaves.
To solve the nesting problem, the simple way is to not hold any locks when recursing into the slave netdev operation. We can "cheat" and use
dev_holdto take a reference on the slavenet_device, which is enough to
ensure thatnetdev_wait_allrefs()waits until we finish, and the kernel
won't fault.However, the slave structure might no longer be valid, just its associated
net_device. So we need to do some more work to ensure that the slave exists after we took the statistics, and if it still does, reapply the logic from Andy's commit5f0c5f73e5ef.Tested using the following two scripts running in parallel:
#!/bin/bash
while :; do
ip link del bond0
ip link del bond1
ip link add bond0 type bond mode 802.3ad ip link add bond1 type bond mode 802.3ad ip link set sw0p1 down && ip link set sw0p1 master
bond0 && ip link set sw0p1 upip link set sw0p2 down && ip link set sw0p2 master bond0 && ip link set sw0p2 up ip link set sw0p3 down && ip link set sw0p3 master bond0 && ip link set sw0p3 up ip link set bond0 down && ip link set bond0 master bond1 && ip link set bond0 up ip link set sw1p1 down && ip link set sw1p1 master bond1 && ip link set sw1p1 up ip link set bond1 up ip -s -s link show cat /sys/class/net/bond1/statistics/* done #!/bin/bash while :; do echo spi2.0 > /sys/bus/spi/drivers/sja1105/unbind echo spi2.0 > /sys/bus/spi/drivers/sja1105/bind sleep 30 donewhere the sja1105 driver was explicitly modified for the purpose of this
test to have a msleep(500) in its .ndo_get_stats64 method, to catch some
more potential races.Signed-off-by Vladimir Oltean <[email protected]>---
[...]
Quoted 29 lines
+/* Helpers for reference counting the struct
net_devicebehind the bond slaves.
+ * These can be used to propagate thenet_device_opsfrom the bond to the
+ * slaves while not holdingrcu_read_lock()or thertnl_mutex.
+ */include/net/bonding.h +22
-0+struct bonding_slave_dev { +struct net_device *ndev; +struct list_head list; +}; + +static inline void bond_put_slaves (struct list_head *slaves) +{ +struct bonding_slave_dev *s, *tmp; + +list_for_each_entry_safe (s, tmp, slaves, list) { +dev_put (s->ndev); +list_del (&s->list); +kfree (s); + } +} + +static inline int bond_get_slaves (struct bonding *bond, +struct list_head *slaves, +int *num_slaves) +{ +struct list_head *iter; +struct slave *slave;
include/net/bonding.h static inline void bond_hw_addr_copy(u8 *dst, const u8 *src, unsigned int len) · line 487
Quoted 10 lines
include/net/bonding.h +10
-0+ +INIT_LIST_HEAD (slaves); + *num_slaves =0 ; + +rcu_read_lock (); + +bond_for_each_slave_rcu (bond, slave, iter) { +struct bonding_slave_dev *s; + + s =kzalloc (sizeof (*s),GFP_ATOMIC );
GFP_ATOMIC is a little bit aggressive especially when user daemons are periodically reading stats. This can be avoided.
You can pre-allocate with GFP_KERNEL an array with an "approximate" size.
then fill the array up with whatever slaves the the bond has at that moment, num_of_slaves can be less, equal or more than the array you just allocated but we shouldn't care ..
something like:rcu_read_lock()
nslaves = bond_get_num_slaves();rcu_read_unlock()
sarray = kcalloc(nslaves, sizeof(struct bonding_slave_dev), GFP_KERNEL);rcu_read_lock();bond_fill_slaves_array(bond, sarray); // also do: dev_hold() rcu_read_unlock();
bond_get_slaves_array_stats(sarray);
bond_put_slaves_array(sarray);
Quoted 20 lines
include/net/bonding.h +17
-0+if (!s) { +rcu_read_unlock (); +bond_put_slaves (slaves); +return -ENOMEM ; + } + + s->ndev = slave->dev; +dev_hold (s->ndev); +list_add_tail (&s->list, slaves); + (*num_slaves)++; + } + +rcu_read_unlock (); + +return 0 ; +} +#define BOND_PRI_RESELECT_ALWAYS 0#define BOND_PRI_RESELECT_BETTER 1#define BOND_PRI_RESELECT_FAILURE 2
Re: [PATCH v6 net-next 14/15] net: bonding: ensure .ndo_get_stats64 can sleep
Quoted 20 lines · Saeed Mahameed
GFP_ATOMICis a little bit aggressive especially when user daemons are periodically reading stats. This can be avoided.You can pre-allocate with
GFP_KERNELan array with an "approximate" size.
then fill the array up with whatever slaves the the bond has at that moment,num_of_slavescan be less, equal or more than the array you just allocated but we shouldn't care ..something like:
rcu_read_lock()
nslaves =bond_get_num_slaves();rcu_read_unlock()
sarray =kcalloc(nslaves, sizeof(struct bonding_slave_dev), GFP_KERNEL);rcu_read_lock();bond_fill_slaves_array(bond, sarray); // also do:dev_hold()rcu_read_unlock();
Quoted 3 lines
bond_get_slaves_array_stats(sarray);
bond_put_slaves_array(sarray);
I don't know what to say about acquiring RCU read lock twice and traversing the list of interfaces three or four times.
On the other hand, what's the worst that can happen if the GFP_ATOMIC memory allocation fails. It's not like there is any data loss. User space will retry when there is less memory pressure.
Re: [PATCH v6 net-next 14/15] net: bonding: ensure .ndo_get_stats64 can sleep
Quoted 24 lines · Vladimir Oltean
Quoted 23 lines · Saeed Mahameed
GFP_ATOMICis a little bit aggressive especially when user daemons are
periodically reading stats. This can be avoided.You can pre-allocate with
GFP_KERNELan array with an "approximate" size.
then fill the array up with whatever slaves the the bond has at that
moment,num_of_slavescan be less, equal or more than the array you
just allocated but we shouldn't care ..something like:
rcu_read_lock()
nslaves =bond_get_num_slaves();rcu_read_unlock()
sarray =kcalloc(nslaves, sizeof(struct bonding_slave_dev), GFP_KERNEL);rcu_read_lock();bond_fill_slaves_array(bond, sarray); // also do:dev_hold()rcu_read_unlock();
Quoted 6 lines
Quoted 3 lines
bond_get_slaves_array_stats(sarray);
bond_put_slaves_array(sarray);I don't know what to say about acquiring RCU read lock twice and traversing the list of interfaces three or four times.
You can optimize this by tracking #num_slaves.
Quoted 3 lines
On the other hand, what's the worst that can happen if the
GFP_ATOMICmemory allocation fails. It's not like there is any data loss. User space will retry when there is less memory pressure.
Anyway Up to you, i just don't like it when we use GFP_ATOMIC when it can be avoided, especially for periodic jobs, like stats polling..
Re: [PATCH v6 net-next 14/15] net: bonding: ensure .ndo_get_stats64 can sleep
Quoted 14 lines · Saeed Mahameed
Quoted 13 lines · Vladimir Oltean
Quoted 12 lines · Saeed Mahameed
GFP_ATOMICis a little bit aggressive especially when user daemons are
periodically reading stats. This can be avoided.You can pre-allocate with
GFP_KERNELan array with an "approximate" size.
then fill the array up with whatever slaves the the bond has at that
moment,num_of_slavescan be less, equal or more than the array you
just allocated but we shouldn't care ..
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
something like:
rcu_read_lock()
nslaves =bond_get_num_slaves();rcu_read_unlock()
Can be nslaves = READ_ONCE(bond->slave_cnt), or, for just active
slaves:
struct bond_up_slave *slaves; slaves = rcu_dereference(bond->slave_arr); nslaves = slaves ? READ_ONCE(slaves->count) : 0;
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
sarray =
kcalloc(nslaves, sizeof(struct bonding_slave_dev), GFP_KERNEL);rcu_read_lock();bond_fill_slaves_array(bond, sarray); // also do:dev_hold()rcu_read_unlock();
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
bond_get_slaves_array_stats(sarray);
bond_put_slaves_array(sarray);I don't know what to say about acquiring RCU read lock twice and traversing the list of interfaces three or four times.
You can optimize this by tracking #num_slaves.
I think that the set of active slaves changing between the two
calls will be a rare exception, and that the number of slaves is generally small (more than 2 is uncommon in my experience).
Quoted 6 lines
Quoted 3 lines
On the other hand, what's the worst that can happen if the
GFP_ATOMICmemory allocation fails. It's not like there is any data loss. User space will retry when there is less memory pressure.Anyway Up to you, i just don't like it when we use
GFP_ATOMICwhen it can be avoided, especially for periodic jobs, like stats polling..
And, for the common case, I suspect that an array allocation
will have lower overhead than a loop that allocates once per slave.
-J
---
-Jay Vosburgh, [email protected]
PATCH v6 15/15 net: mark ndo_get_stats64 as being able to sleep
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Now that all callers have been converted to not use atomic context when calling dev_get_stats, it is time to update the documentation and put a notice in the function that it expects process context.
---
Changes in v6:
Rebase on top of Jakub's patch 9f9d41f03bb0 ("docs: net: fix documentation on .ndo_get_stats").
Changes in v5:
None.
Changes in v4:
None.
Changes in v3:
None.
Changes in v2:
Updated the documentation.
Documentation/networking/netdevices.rst | 8 ++++++-- Documentation/networking/statistics.rst | 9 ++++----- net/core/dev.c | 2 ++ 3 files changed, 12 insertions(+), 7 deletions(-)
Documentation/networking/netdevices.rst +6 -2
@@ -64,8 +64,12 @@ ndo_do_ioctl: Context: process ndo_get_stats: - Synchronization: rtnl_lock() semaphore, dev_base_lock rwlock, or RCU. - Context: atomic (can't sleep under rwlock or RCU) + Synchronization: + none. netif_lists_lock(net) might be held, but not guaranteed. + It is illegal to hold rtnl_lock() in this method, since it will + cause a lock inversion with netif_lists_lock and a deadlock. + Context: + process ndo_start_xmit: Synchronization: __netif_tx_lock spinlock.
Documentation/networking/statistics.rst +4 -5
@@ -155,11 +155,10 @@ Drivers must ensure best possible compliance with Please note for example that detailed error statistics must be added into the general `rx_error` / `tx_error` counters. -The `.ndo_get_stats64` callback can not sleep because of accesses -via `/proc/net/dev`. If driver may sleep when retrieving the statistics -from the device it should do so periodically asynchronously and only return -a recent copy from `.ndo_get_stats64`. Ethtool interrupt coalescing interface -allows setting the frequency of refreshing statistics, if needed. +Drivers may sleep when retrieving the statistics from the device, or they might +read the counters periodically and only return in `.ndo_get_stats64` a recent +copy collected asynchronously. In the latter case, the ethtool interrupt +coalescing interface allows setting the frequency of refreshing statistics. Retrieving ethtool statistics is a multi-syscall process, drivers are advised to keep the number of statistics constant to avoid race conditions with
net/core/dev.c +2 -0
@@ -10409,6 +10409,8 @@ int __must_check dev_get_stats(struct net_device *dev,const struct net_device_ops *ops = dev->netdev_ops;int err =0 ; +might_sleep (); +if (ops->ndo_get_stats64) {memset (storage,0 ,sizeof (*storage)); err = ops->ndo_get_stats64 (dev, storage);
Signature · 1 line
2.25.1