Netdev List
 help / color / mirror / Atom feed
* [NET]: Get rid of NETIF_F_INTERNAL_STATS
@ 2007-04-11  7:56 Herbert Xu
  2007-04-11 12:15 ` Rusty Russell
  0 siblings, 1 reply; 7+ messages in thread
From: Herbert Xu @ 2007-04-11  7:56 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev, Rusty Russell, Jeff Garzik

Hi:

[NET]: Get rid of NETIF_F_INTERNAL_STATS

The recently added NETIF_F_INTERNAL_STATS isn't very useful.  If the
device driver needs to set it then it can always override get_stats
instead.  All existing drivers that have stats (which should be every
one) will override get_stats anyway.  Those that don't have stats
(if there are any) wouldn't hurt from having a get_stats that just
returns zeros everywhere.

So we can simply get rid of this flag.

This also fixes a potential crash in those get_stats callers that
don't check for a NULL return value (e.g., /proc/net/dev).

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 71fc8ff..9c52652 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -323,7 +323,6 @@ struct net_device
 #define NETIF_F_VLAN_CHALLENGED	1024	/* Device cannot handle VLAN packets */
 #define NETIF_F_GSO		2048	/* Enable software GSO. */
 #define NETIF_F_LLTX		4096	/* LockLess TX */
-#define NETIF_F_INTERNAL_STATS	8192	/* Use stats structure in net_device */
 
 	/* Segmentation offload features */
 #define NETIF_F_GSO_SHIFT	16
diff --git a/net/core/dev.c b/net/core/dev.c
index c484fcf..5791021 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3289,11 +3289,9 @@ out:
 	mutex_unlock(&net_todo_run_mutex);
 }
 
-static struct net_device_stats *maybe_internal_stats(struct net_device *dev)
+static struct net_device_stats *get_internal_stats(struct net_device *dev)
 {
-	if (dev->features & NETIF_F_INTERNAL_STATS)
-		return &dev->stats;
-	return NULL;
+	return &dev->stats;
 }
 
 /**
@@ -3331,7 +3329,7 @@ struct net_device *alloc_netdev(int sizeof_priv, const char *name,
 	if (sizeof_priv)
 		dev->priv = netdev_priv(dev);
 
-	dev->get_stats = maybe_internal_stats;
+	dev->get_stats = get_internal_stats;
 	setup(dev);
 	strcpy(dev->name, name);
 	return dev;

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

* Re: [NET]: Get rid of NETIF_F_INTERNAL_STATS
  2007-04-11  7:56 [NET]: Get rid of NETIF_F_INTERNAL_STATS Herbert Xu
@ 2007-04-11 12:15 ` Rusty Russell
  2007-04-11 12:23   ` Herbert Xu
  0 siblings, 1 reply; 7+ messages in thread
From: Rusty Russell @ 2007-04-11 12:15 UTC (permalink / raw)
  To: Herbert Xu; +Cc: David S. Miller, netdev, Jeff Garzik

On Wed, 2007-04-11 at 17:56 +1000, Herbert Xu wrote:
> Hi:
> 
> [NET]: Get rid of NETIF_F_INTERNAL_STATS
> 
> The recently added NETIF_F_INTERNAL_STATS isn't very useful.  If the
> device driver needs to set it then it can always override get_stats
> instead.  All existing drivers that have stats (which should be every
> one) will override get_stats anyway.  Those that don't have stats
> (if there are any) wouldn't hurt from having a get_stats that just
> returns zeros everywhere.

Actually, I did this precisely because I really didn't want to start
exposing bogus stats in /proc/net/dev.  An audit might clarify if this
is an actual issue.

> So we can simply get rid of this flag.
> 
> This also fixes a potential crash in those get_stats callers that
> don't check for a NULL return value (e.g., /proc/net/dev).

Hmm, I thought it did that in my original patch?

Rusty.



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

* Re: [NET]: Get rid of NETIF_F_INTERNAL_STATS
  2007-04-11 12:15 ` Rusty Russell
@ 2007-04-11 12:23   ` Herbert Xu
  2007-04-13 23:19     ` David Miller
  2007-04-28  5:46     ` Rusty Russell
  0 siblings, 2 replies; 7+ messages in thread
From: Herbert Xu @ 2007-04-11 12:23 UTC (permalink / raw)
  To: Rusty Russell; +Cc: David S. Miller, netdev, Jeff Garzik

On Wed, Apr 11, 2007 at 10:15:51PM +1000, Rusty Russell wrote:
> 
> Actually, I did this precisely because I really didn't want to start
> exposing bogus stats in /proc/net/dev.  An audit might clarify if this
> is an actual issue.

Fair enough.  Still returning zeros when get_stats isn't available
would seem safe enough.  I wasn't able to find any drivers which
didn't have get_stats.

> > This also fixes a potential crash in those get_stats callers that
> > don't check for a NULL return value (e.g., /proc/net/dev).
> 
> Hmm, I thought it did that in my original patch?

Sorry, I was looking at the wrong tree.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [NET]: Get rid of NETIF_F_INTERNAL_STATS
  2007-04-11 12:23   ` Herbert Xu
@ 2007-04-13 23:19     ` David Miller
  2007-04-28  5:46     ` Rusty Russell
  1 sibling, 0 replies; 7+ messages in thread
From: David Miller @ 2007-04-13 23:19 UTC (permalink / raw)
  To: herbert; +Cc: rusty, netdev, jgarzik

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Wed, 11 Apr 2007 22:23:17 +1000

> On Wed, Apr 11, 2007 at 10:15:51PM +1000, Rusty Russell wrote:
> > 
> > Actually, I did this precisely because I really didn't want to start
> > exposing bogus stats in /proc/net/dev.  An audit might clarify if this
> > is an actual issue.
> 
> Fair enough.  Still returning zeros when get_stats isn't available
> would seem safe enough.  I wasn't able to find any drivers which
> didn't have get_stats.

Given this, I'll drop Herbert's patch for now.

Let me know if I should apply something, in fact send it to me :)

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

* Re: [NET]: Get rid of NETIF_F_INTERNAL_STATS
  2007-04-11 12:23   ` Herbert Xu
  2007-04-13 23:19     ` David Miller
@ 2007-04-28  5:46     ` Rusty Russell
  2007-04-28  5:52       ` Herbert Xu
  1 sibling, 1 reply; 7+ messages in thread
From: Rusty Russell @ 2007-04-28  5:46 UTC (permalink / raw)
  To: Herbert Xu; +Cc: David S. Miller, netdev, Jeff Garzik, buytenh

On Wed, 2007-04-11 at 22:23 +1000, Herbert Xu wrote:
> On Wed, Apr 11, 2007 at 10:15:51PM +1000, Rusty Russell wrote:
> > 
> > Actually, I did this precisely because I really didn't want to start
> > exposing bogus stats in /proc/net/dev.  An audit might clarify if this
> > is an actual issue.
> 
> Fair enough.  Still returning zeros when get_stats isn't available
> would seem safe enough.  I wasn't able to find any drivers which
> didn't have get_stats.

OK, I did a quick check, and the only one I could find was br_if.c which
calls register_netdevice() and doesn't set get_stats.  I don't think
that zeroes in this case matters.

So here's a patch inspired by Herbert's patch, but also gets all those
places which I modified previously to check for get_stats returning
NULL.
==
Remove NETIF_F_INTERNAL_STATS: default to internal stats.

Herbert Xu conviced me that a new flag was overkill; every driver
currently overrides get_stats, so we might as well make the internal
one the default.  If someone did fail to set get_stats, they would now
get all 0 stats instead of "No statistics available".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff -r ceab3c131ee5 arch/s390/appldata/appldata_net_sum.c
--- a/arch/s390/appldata/appldata_net_sum.c	Sat Apr 28 14:39:41 2007 +1000
+++ b/arch/s390/appldata/appldata_net_sum.c	Sat Apr 28 15:09:46 2007 +1000
@@ -109,9 +109,6 @@ static void appldata_get_net_sum_data(vo
 	read_lock(&dev_base_lock);
 	for (dev = dev_base; dev != NULL; dev = dev->next) {
 		stats = dev->get_stats(dev);
-		if (stats == NULL) {
-			continue;
-		}
 		rx_packets += stats->rx_packets;
 		tx_packets += stats->tx_packets;
 		rx_bytes   += stats->rx_bytes;
diff -r ceab3c131ee5 drivers/net/bonding/bond_main.c
--- a/drivers/net/bonding/bond_main.c	Sat Apr 28 14:39:41 2007 +1000
+++ b/drivers/net/bonding/bond_main.c	Sat Apr 28 15:10:24 2007 +1000
@@ -1360,13 +1360,6 @@ int bond_enslave(struct net_device *bond
 		goto err_undo_flags;
 	}
 
-	if (slave_dev->get_stats == NULL) {
-		printk(KERN_NOTICE DRV_NAME
-			": %s: the driver for slave device %s does not provide "
-			"get_stats function, network statistics will be "
-			"inaccurate.\n", bond_dev->name, slave_dev->name);
-	}
-
 	new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL);
 	if (!new_slave) {
 		res = -ENOMEM;
@@ -3641,33 +3634,31 @@ static struct net_device_stats *bond_get
 
 	bond_for_each_slave(bond, slave, i) {
 		sstats = slave->dev->get_stats(slave->dev);
-		if (sstats) {
-			stats->rx_packets += sstats->rx_packets;
-			stats->rx_bytes += sstats->rx_bytes;
-			stats->rx_errors += sstats->rx_errors;
-			stats->rx_dropped += sstats->rx_dropped;
-
-			stats->tx_packets += sstats->tx_packets;
-			stats->tx_bytes += sstats->tx_bytes;
-			stats->tx_errors += sstats->tx_errors;
-			stats->tx_dropped += sstats->tx_dropped;
-
-			stats->multicast += sstats->multicast;
-			stats->collisions += sstats->collisions;
-
-			stats->rx_length_errors += sstats->rx_length_errors;
-			stats->rx_over_errors += sstats->rx_over_errors;
-			stats->rx_crc_errors += sstats->rx_crc_errors;
-			stats->rx_frame_errors += sstats->rx_frame_errors;
-			stats->rx_fifo_errors += sstats->rx_fifo_errors;
-			stats->rx_missed_errors += sstats->rx_missed_errors;
-
-			stats->tx_aborted_errors += sstats->tx_aborted_errors;
-			stats->tx_carrier_errors += sstats->tx_carrier_errors;
-			stats->tx_fifo_errors += sstats->tx_fifo_errors;
-			stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors;
-			stats->tx_window_errors += sstats->tx_window_errors;
-		}
+		stats->rx_packets += sstats->rx_packets;
+		stats->rx_bytes += sstats->rx_bytes;
+		stats->rx_errors += sstats->rx_errors;
+		stats->rx_dropped += sstats->rx_dropped;
+
+		stats->tx_packets += sstats->tx_packets;
+		stats->tx_bytes += sstats->tx_bytes;
+		stats->tx_errors += sstats->tx_errors;
+		stats->tx_dropped += sstats->tx_dropped;
+
+		stats->multicast += sstats->multicast;
+		stats->collisions += sstats->collisions;
+
+		stats->rx_length_errors += sstats->rx_length_errors;
+		stats->rx_over_errors += sstats->rx_over_errors;
+		stats->rx_crc_errors += sstats->rx_crc_errors;
+		stats->rx_frame_errors += sstats->rx_frame_errors;
+		stats->rx_fifo_errors += sstats->rx_fifo_errors;
+		stats->rx_missed_errors += sstats->rx_missed_errors;
+
+		stats->tx_aborted_errors += sstats->tx_aborted_errors;
+		stats->tx_carrier_errors += sstats->tx_carrier_errors;
+		stats->tx_fifo_errors += sstats->tx_fifo_errors;
+		stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors;
+		stats->tx_window_errors += sstats->tx_window_errors;
 	}
 
 	read_unlock_bh(&bond->lock);
diff -r ceab3c131ee5 drivers/parisc/led.c
--- a/drivers/parisc/led.c	Sat Apr 28 14:39:41 2007 +1000
+++ b/drivers/parisc/led.c	Sat Apr 28 15:09:36 2007 +1000
@@ -373,8 +373,6 @@ static __inline__ int led_get_net_activi
 	    if (LOOPBACK(in_dev->ifa_list->ifa_local))
 		continue;
 	    stats = dev->get_stats(dev);
-	    if (!stats)
-		continue;
 	    rx_total += stats->rx_packets;
 	    tx_total += stats->tx_packets;
 	}
diff -r ceab3c131ee5 include/linux/netdevice.h
--- a/include/linux/netdevice.h	Sat Apr 28 14:39:41 2007 +1000
+++ b/include/linux/netdevice.h	Sat Apr 28 15:09:13 2007 +1000
@@ -325,7 +325,6 @@ struct net_device
 #define NETIF_F_VLAN_CHALLENGED	1024	/* Device cannot handle VLAN packets */
 #define NETIF_F_GSO		2048	/* Enable software GSO. */
 #define NETIF_F_LLTX		4096	/* LockLess TX */
-#define NETIF_F_INTERNAL_STATS	8192	/* Use stats structure in net_device */
 
 	/* Segmentation offload features */
 #define NETIF_F_GSO_SHIFT	16
diff -r ceab3c131ee5 net/core/dev.c
--- a/net/core/dev.c	Sat Apr 28 14:39:41 2007 +1000
+++ b/net/core/dev.c	Sat Apr 28 15:09:02 2007 +1000
@@ -2105,26 +2105,23 @@ static void dev_seq_printf_stats(struct 
 {
 	struct net_device_stats *stats = dev->get_stats(dev);
 
-	if (stats) {
-		seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
-				"%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\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);
-	} else
-		seq_printf(seq, "%6s: No statistics available.\n", dev->name);
+	seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
+		   "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\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);
 }
 
 /*
@@ -3287,11 +3284,9 @@ out:
 	mutex_unlock(&net_todo_run_mutex);
 }
 
-static struct net_device_stats *maybe_internal_stats(struct net_device *dev)
-{
-	if (dev->features & NETIF_F_INTERNAL_STATS)
-		return &dev->stats;
-	return NULL;
+static struct net_device_stats *internal_stats(struct net_device *dev)
+{
+	return &dev->stats;
 }
 
 /**
@@ -3329,7 +3324,7 @@ struct net_device *alloc_netdev(int size
 	if (sizeof_priv)
 		dev->priv = netdev_priv(dev);
 
-	dev->get_stats = maybe_internal_stats;
+	dev->get_stats = internal_stats;
 	setup(dev);
 	strcpy(dev->name, name);
 	return dev;



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

* Re: [NET]: Get rid of NETIF_F_INTERNAL_STATS
  2007-04-28  5:46     ` Rusty Russell
@ 2007-04-28  5:52       ` Herbert Xu
  2007-04-29  4:04         ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Herbert Xu @ 2007-04-28  5:52 UTC (permalink / raw)
  To: Rusty Russell; +Cc: David S. Miller, netdev, Jeff Garzik, buytenh

On Sat, Apr 28, 2007 at 03:46:01PM +1000, Rusty Russell wrote:
> 
> OK, I did a quick check, and the only one I could find was br_if.c which
> calls register_netdevice() and doesn't set get_stats.  I don't think
> that zeroes in this case matters.

Thanks for following up on this Rusty!

Actually I just had a look at br_if.c and it seems that it does set
get_stats through br_dev_setup to br_dev_get_stats.

> ==
> Remove NETIF_F_INTERNAL_STATS: default to internal stats.
> 
> Herbert Xu conviced me that a new flag was overkill; every driver
> currently overrides get_stats, so we might as well make the internal
> one the default.  If someone did fail to set get_stats, they would now
> get all 0 stats instead of "No statistics available".
> 
> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

Looks good to me.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [NET]: Get rid of NETIF_F_INTERNAL_STATS
  2007-04-28  5:52       ` Herbert Xu
@ 2007-04-29  4:04         ` David Miller
  0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2007-04-29  4:04 UTC (permalink / raw)
  To: herbert; +Cc: rusty, netdev, jgarzik, buytenh

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Sat, 28 Apr 2007 15:52:46 +1000

> > ==
> > Remove NETIF_F_INTERNAL_STATS: default to internal stats.
> > 
> > Herbert Xu conviced me that a new flag was overkill; every driver
> > currently overrides get_stats, so we might as well make the internal
> > one the default.  If someone did fail to set get_stats, they would now
> > get all 0 stats instead of "No statistics available".
> > 
> > Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
> 
> Looks good to me.

Applied, thanks everyone.

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

end of thread, other threads:[~2007-04-29  4:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-11  7:56 [NET]: Get rid of NETIF_F_INTERNAL_STATS Herbert Xu
2007-04-11 12:15 ` Rusty Russell
2007-04-11 12:23   ` Herbert Xu
2007-04-13 23:19     ` David Miller
2007-04-28  5:46     ` Rusty Russell
2007-04-28  5:52       ` Herbert Xu
2007-04-29  4:04         ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox